mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 21:43:11 +00:00
[DURACOM-125][#8736] Preserved order of modified MetadataValues
feat: - Introduced new Class with static methods usable to order `MetadataValue` lists; - Introduced ITs also for `PatchMetadata` replace operations; - Introduced new method `DspaceObject#getMetadataFieldId`. ref: - Replaced old sort method inside `ItemServiceImpl` with the new one
This commit is contained in:
@@ -12,7 +12,6 @@ import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
@@ -288,9 +287,10 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
||||
return itemDAO.findAll(context, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Item> findAllRegularItems(Context context) throws SQLException {
|
||||
return itemDAO.findAllRegularItems(context);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Item> findBySubmitter(Context context, EPerson eperson) throws SQLException {
|
||||
@@ -1054,7 +1054,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
||||
List<Collection> linkedCollections = item.getCollections();
|
||||
List<Collection> notLinkedCollections = new ArrayList<>(allCollections.size() - linkedCollections.size());
|
||||
|
||||
if ((allCollections.size() - linkedCollections.size()) == 0) {
|
||||
if (allCollections.size() - linkedCollections.size() == 0) {
|
||||
return notLinkedCollections;
|
||||
}
|
||||
for (Collection collection : allCollections) {
|
||||
@@ -1149,6 +1149,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
||||
* @return <code>true</code> if the item is an inprogress submission, i.e. a WorkspaceItem or WorkflowItem
|
||||
* @throws SQLException An exception that provides information on a database access error or other errors.
|
||||
*/
|
||||
@Override
|
||||
public boolean isInProgressSubmission(Context context, Item item) throws SQLException {
|
||||
return workspaceItemService.findByItem(context, item) != null
|
||||
|| workflowItemService.findByItem(context, item) != null;
|
||||
@@ -1179,8 +1180,8 @@ prevent the generation of resource policy entry values with null dspace_object a
|
||||
if (!authorizeService
|
||||
.isAnIdenticalPolicyAlreadyInPlace(context, dso, defaultPolicy.getGroup(), Constants.READ,
|
||||
defaultPolicy.getID()) &&
|
||||
((!appendMode && this.isNotAlreadyACustomRPOfThisTypeOnDSO(context, dso)) ||
|
||||
(appendMode && this.shouldBeAppended(context, dso, defaultPolicy)))) {
|
||||
(!appendMode && this.isNotAlreadyACustomRPOfThisTypeOnDSO(context, dso) ||
|
||||
appendMode && this.shouldBeAppended(context, dso, defaultPolicy))) {
|
||||
ResourcePolicy newPolicy = resourcePolicyService.clone(context, defaultPolicy);
|
||||
newPolicy.setdSpaceObject(dso);
|
||||
newPolicy.setAction(Constants.READ);
|
||||
@@ -1222,7 +1223,7 @@ prevent the generation of resource policy entry values with null dspace_object a
|
||||
* Check if the provided default policy should be appended or not to the final
|
||||
* item. If an item has at least one custom READ policy any anonymous READ
|
||||
* policy with empty start/end date should be skipped
|
||||
*
|
||||
*
|
||||
* @param context DSpace context
|
||||
* @param dso DSpace object to check for custom read RP
|
||||
* @param defaultPolicy The policy to check
|
||||
@@ -1611,7 +1612,7 @@ prevent the generation of resource policy entry values with null dspace_object a
|
||||
fullMetadataValueList.addAll(relationshipMetadataService.getRelationshipMetadata(item, true));
|
||||
fullMetadataValueList.addAll(dbMetadataValues);
|
||||
|
||||
item.setCachedMetadata(sortMetadataValueList(fullMetadataValueList));
|
||||
item.setCachedMetadata(MetadataValueComparators.sort(fullMetadataValueList));
|
||||
}
|
||||
|
||||
log.debug("Called getMetadata for " + item.getID() + " based on cache");
|
||||
@@ -1653,28 +1654,6 @@ prevent the generation of resource policy entry values with null dspace_object a
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will sort the List of MetadataValue objects based on the MetadataSchema, MetadataField Element,
|
||||
* MetadataField Qualifier and MetadataField Place in that order.
|
||||
* @param listToReturn The list to be sorted
|
||||
* @return The list sorted on those criteria
|
||||
*/
|
||||
private List<MetadataValue> sortMetadataValueList(List<MetadataValue> listToReturn) {
|
||||
Comparator<MetadataValue> comparator = Comparator.comparing(
|
||||
metadataValue -> metadataValue.getMetadataField().getMetadataSchema().getName(),
|
||||
Comparator.nullsFirst(Comparator.naturalOrder()));
|
||||
comparator = comparator.thenComparing(metadataValue -> metadataValue.getMetadataField().getElement(),
|
||||
Comparator.nullsFirst(Comparator.naturalOrder()));
|
||||
comparator = comparator.thenComparing(metadataValue -> metadataValue.getMetadataField().getQualifier(),
|
||||
Comparator.nullsFirst(Comparator.naturalOrder()));
|
||||
comparator = comparator.thenComparing(metadataValue -> metadataValue.getPlace(),
|
||||
Comparator.nullsFirst(Comparator.naturalOrder()));
|
||||
|
||||
Stream<MetadataValue> metadataValueStream = listToReturn.stream().sorted(comparator);
|
||||
listToReturn = metadataValueStream.collect(Collectors.toList());
|
||||
return listToReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataValue addMetadata(Context context, Item dso, String schema, String element, String qualifier,
|
||||
String lang, String value, String authority, int confidence, int place) throws SQLException {
|
||||
|
Reference in New Issue
Block a user