mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-11 20:13:17 +00:00
[Task 57188] added the logic for the advanced place column calculation. Enforced that all virtual metadata are valid metadatafields
This commit is contained in:
@@ -12,6 +12,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
@@ -25,8 +26,10 @@ import org.dspace.content.authority.Choices;
|
||||
import org.dspace.content.authority.service.ChoiceAuthorityService;
|
||||
import org.dspace.content.authority.service.MetadataAuthorityService;
|
||||
import org.dspace.content.service.DSpaceObjectService;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.content.service.MetadataFieldService;
|
||||
import org.dspace.content.service.MetadataValueService;
|
||||
import org.dspace.content.service.RelationshipService;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.handle.service.HandleService;
|
||||
@@ -60,6 +63,10 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
protected MetadataFieldService metadataFieldService;
|
||||
@Autowired(required = true)
|
||||
protected MetadataAuthorityService metadataAuthorityService;
|
||||
@Autowired(required = true)
|
||||
protected ItemService itemService;
|
||||
@Autowired(required = true)
|
||||
protected RelationshipService relationshipService;
|
||||
|
||||
public DSpaceObjectServiceImpl() {
|
||||
|
||||
@@ -546,10 +553,28 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
*/
|
||||
// A map created to store the latest place for each metadata field
|
||||
Map<MetadataField, Integer> fieldToLastPlace = new HashMap<>();
|
||||
List<MetadataValue> metadataValues = dso.getMetadata();
|
||||
List<MetadataValue> metadataValues = new LinkedList<>();
|
||||
if (dso.getType() == Constants.ITEM) {
|
||||
metadataValues = itemService.getMetadata((Item) dso, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
||||
} else {
|
||||
metadataValues = dso.getMetadata();
|
||||
}
|
||||
for (MetadataValue metadataValue : metadataValues) {
|
||||
//Retrieve & store the place for each metadata value
|
||||
if (!StringUtils.startsWith(metadataValue.getAuthority(), "virtual::")) {
|
||||
if (StringUtils.startsWith(metadataValue.getAuthority(), "virtual::") && ((RelationshipMetadataValue) metadataValue).isUseForPlace()) {
|
||||
int mvPlace = getMetadataValuePlace(fieldToLastPlace, metadataValue);
|
||||
metadataValue.setPlace(mvPlace);
|
||||
String authority = metadataValue.getAuthority();
|
||||
String relationshipId = StringUtils.split(authority, "::")[1];
|
||||
Relationship relationship = relationshipService.find(context, Integer.parseInt(relationshipId));
|
||||
if (relationship.getLeftItem() == (Item) dso) {
|
||||
relationship.setLeftPlace(mvPlace);
|
||||
} else {
|
||||
relationship.setRightPlace(mvPlace);
|
||||
}
|
||||
relationshipService.update(context, relationship);
|
||||
|
||||
} else if (!StringUtils.startsWith(metadataValue.getAuthority(), "virtual::")) {
|
||||
int mvPlace = getMetadataValuePlace(fieldToLastPlace, metadataValue);
|
||||
metadataValue.setPlace(mvPlace);
|
||||
}
|
||||
@@ -569,7 +594,7 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
if (fieldToLastPlace.containsKey(metadataField)) {
|
||||
fieldToLastPlace.put(metadataField, fieldToLastPlace.get(metadataField) + 1);
|
||||
} else {
|
||||
// The metadata value place starts at 0
|
||||
// The metadata value place starts at 0q
|
||||
fieldToLastPlace.put(metadataField, 0);
|
||||
}
|
||||
return fieldToLastPlace.get(metadataField);
|
||||
|
Reference in New Issue
Block a user