diff --git a/dspace-api/src/main/java/org/dspace/content/DSpaceObjectServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/DSpaceObjectServiceImpl.java index b0b3cea37f..8e30936bfd 100644 --- a/dspace-api/src/main/java/org/dspace/content/DSpaceObjectServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/DSpaceObjectServiceImpl.java @@ -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 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 implements */ // A map created to store the latest place for each metadata field Map fieldToLastPlace = new HashMap<>(); - List metadataValues = dso.getMetadata(); + List 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 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); diff --git a/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java index fe96d6539f..093e88ee51 100644 --- a/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java @@ -1365,7 +1365,8 @@ prevent the generation of resource policy entry values with null dspace_object a otherItem, relationName, relationship.getID())); } - resultingMetadataValueList.add(getRelationMetadataFromOtherItem(otherItem, relationName, relationship.getID())); + resultingMetadataValueList + .add(getRelationMetadataFromOtherItem(context, otherItem, relationName, relationship.getID())); return resultingMetadataValueList; } @@ -1380,7 +1381,7 @@ prevent the generation of resource policy entry values with null dspace_object a String key = entry.getKey(); VirtualBean virtualBean = entry.getValue(); - RelationshipMetadataValue metadataValue = constructMetadataValue(key); + RelationshipMetadataValue metadataValue = constructMetadataValue(context, key); metadataValue = constructResultingMetadataValue(context, item, otherItem, virtualBean, metadataValue, relationshipId); metadataValue.setUseForPlace(virtualBean.getUseForPlace()); @@ -1391,9 +1392,10 @@ prevent the generation of resource policy entry values with null dspace_object a return resultingMetadataValueList; } - private RelationshipMetadataValue getRelationMetadataFromOtherItem(Item otherItem, String relationName, + private RelationshipMetadataValue getRelationMetadataFromOtherItem(Context context, Item otherItem, + String relationName, Integer relationshipId) { - RelationshipMetadataValue metadataValue = constructMetadataValue("relation." + relationName); + RelationshipMetadataValue metadataValue = constructMetadataValue(context, "relation." + relationName); metadataValue.setAuthority("virtual::" + relationshipId); metadataValue.setValue(otherItem.getID().toString()); return metadataValue; @@ -1425,17 +1427,27 @@ prevent the generation of resource policy entry values with null dspace_object a return metadataValue; } - private RelationshipMetadataValue constructMetadataValue(String key) { - String[] splittedKey = key.split("\\."); - RelationshipMetadataValue metadataValue = new RelationshipMetadataValue(); - MetadataField metadataField = new MetadataField(); - MetadataSchema metadataSchema = new MetadataSchema(); - metadataSchema.setName(splittedKey.length > 0 ? splittedKey[0] : null); - metadataField.setMetadataSchema(metadataSchema); - metadataField.setElement(splittedKey.length > 1 ? splittedKey[1] : null); - metadataField.setQualifier(splittedKey.length > 2 ? splittedKey[2] : null); - metadataValue.setMetadataField(metadataField); - metadataValue.setLanguage(Item.ANY); - return metadataValue; + private RelationshipMetadataValue constructMetadataValue(Context context, String key) { + try { + String[] splittedKey = key.split("\\."); + RelationshipMetadataValue metadataValue = new RelationshipMetadataValue(); + String metadataSchema = splittedKey.length > 0 ? splittedKey[0] : null; + String metadataElement = splittedKey.length > 1 ? splittedKey[1] : null; + String metadataQualifier = splittedKey.length > 2 ? splittedKey[2] : null; + MetadataField metadataField = metadataFieldService + .findByElement(context, metadataSchema, metadataElement, metadataQualifier); + if (metadataField == null) { + log.error( + "A MetadataValue was attempted to construct with MetadataField for paremeters: metadataschema: " + + metadataSchema + ", metadataelement:" + metadataElement + ", metadataqualifier: " + metadataQualifier); + return null; + } + metadataValue.setMetadataField(metadataField); + metadataValue.setLanguage(Item.ANY); + return metadataValue; + } catch (SQLException e) { + log.error(e.getMessage(), e); + } + return null; } } \ No newline at end of file diff --git a/dspace-api/src/main/java/org/dspace/content/RelationshipMetadataValue.java b/dspace-api/src/main/java/org/dspace/content/RelationshipMetadataValue.java index 5c8daa0929..700b0fc21f 100644 --- a/dspace-api/src/main/java/org/dspace/content/RelationshipMetadataValue.java +++ b/dspace-api/src/main/java/org/dspace/content/RelationshipMetadataValue.java @@ -1,5 +1,7 @@ package org.dspace.content; +import org.hibernate.proxy.HibernateProxyHelper; + public class RelationshipMetadataValue extends MetadataValue { private boolean useForPlace; @@ -11,4 +13,20 @@ public class RelationshipMetadataValue extends MetadataValue { public void setUseForPlace(boolean useForPlace) { this.useForPlace = useForPlace; } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + Class objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj); + if (getClass() != objClass) { + return false; + } + final RelationshipMetadataValue other = (RelationshipMetadataValue) obj; + if (this.isUseForPlace() != other.isUseForPlace()) { + return false; + } + return super.equals(obj); + } } diff --git a/dspace/config/registries/person-types.xml b/dspace/config/registries/person-types.xml index 49e6880deb..63947ff366 100644 --- a/dspace/config/registries/person-types.xml +++ b/dspace/config/registries/person-types.xml @@ -58,4 +58,11 @@ jobtitle + + + person + contributor + other + + diff --git a/dspace/config/registries/project-types.xml b/dspace/config/registries/project-types.xml index 8ed1b84cf2..866bb85439 100644 --- a/dspace/config/registries/project-types.xml +++ b/dspace/config/registries/project-types.xml @@ -58,4 +58,18 @@ description + + + project + contributor + other + + + + + project + contributor + author + + diff --git a/dspace/config/registries/relationship-formats.xml b/dspace/config/registries/relationship-formats.xml index 00dd43d8a9..ddc8296ddb 100644 --- a/dspace/config/registries/relationship-formats.xml +++ b/dspace/config/registries/relationship-formats.xml @@ -9,6 +9,10 @@ http://dspace.org/relationship + + relation + http://dspace.org/relation + relationship @@ -16,4 +20,105 @@ Metadata field used for the type of entity, stored in the item + + relation + isAuthorOfPublication + + + + + relation + isPublicationOfAuthor + + + + relation + isProjectOfPublication + + + + relation + isPublicationOfProject + + + + relation + isOrgUnitOfPublication + + + + relation + isPublicationOfOrgUnit + + + + relation + isProjectOfPerson + + + + relation + isPersonOfProject + + + + relation + isOrgUnitOfPerson + + + + relation + isPersonOfOrgUnit + + + + relation + isOrgUnitOfProject + + + + relation + isProjectOfOrgUnit + + + + + + relation + isVolumeOfJournal + + + + relation + isJournalOfVolume + + + + relation + isIssueOfJournalVolume + + + + relation + isJournalVolumeOfIssue + + + + relation + isJournalOfPublication + + + + + relation + isJournalIssueOfPublication + + + + + + relation + isPublicationOfJournalIssue + + diff --git a/dspace/config/spring/api/core-services.xml b/dspace/config/spring/api/core-services.xml index 23a588b55c..4cabc4dcfb 100644 --- a/dspace/config/spring/api/core-services.xml +++ b/dspace/config/spring/api/core-services.xml @@ -160,7 +160,7 @@ - + @@ -174,7 +174,7 @@ - + @@ -189,7 +189,7 @@ - + @@ -203,7 +203,7 @@ - + @@ -272,7 +272,7 @@ - + @@ -288,7 +288,7 @@ - +