[Task 57188] added the logic for the advanced place column calculation. Enforced that all virtual metadata are valid metadatafields

This commit is contained in:
Raf Ponsaerts
2018-11-20 14:32:12 +01:00
parent 0ba6d75a30
commit cfeabe349c
7 changed files with 206 additions and 25 deletions

View File

@@ -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);

View File

@@ -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) {
private RelationshipMetadataValue constructMetadataValue(Context context, String key) {
try {
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);
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;
}
}

View File

@@ -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);
}
}

View File

@@ -58,4 +58,11 @@
<qualifier>jobtitle</qualifier>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>person</schema>
<element>contributor</element>
<qualifier>other</qualifier>
<scope_note></scope_note>
</dc-type>
</dspace-dc-types>

View File

@@ -58,4 +58,18 @@
<qualifier>description</qualifier>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>project</schema>
<element>contributor</element>
<qualifier>other</qualifier>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>project</schema>
<element>contributor</element>
<qualifier>author</qualifier>
<scope_note></scope_note>
</dc-type>
</dspace-dc-types>

View File

@@ -9,6 +9,10 @@
<namespace>http://dspace.org/relationship</namespace>
</dc-schema>
<dc-schema>
<name>relation</name>
<namespace>http://dspace.org/relation</namespace>
</dc-schema>
<dc-type>
<schema>relationship</schema>
@@ -16,4 +20,105 @@
<scope_note>Metadata field used for the type of entity, stored in the item</scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isAuthorOfPublication</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isPublicationOfAuthor</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isProjectOfPublication</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isPublicationOfProject</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isOrgUnitOfPublication</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isPublicationOfOrgUnit</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isProjectOfPerson</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isPersonOfProject</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isOrgUnitOfPerson</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isPersonOfOrgUnit</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isOrgUnitOfProject</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isProjectOfOrgUnit</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isVolumeOfJournal</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isJournalOfVolume</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isIssueOfJournalVolume</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isJournalVolumeOfIssue</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isJournalOfPublication</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isJournalIssueOfPublication</element>
<scope_note></scope_note>
</dc-type>
<dc-type>
<schema>relation</schema>
<element>isPublicationOfJournalIssue</element>
<scope_note></scope_note>
</dc-type>
</dspace-dc-types>

View File

@@ -160,7 +160,7 @@
</bean>
<util:map id="isOrgUnitOfPublicationMap">
<entry key="dc_contributor_other" value-ref="publicationOrgUnit_name"/>
<entry key="dc.contributor.other" value-ref="publicationOrgUnit_name"/>
</util:map>
<bean class="org.dspace.content.virtual.Concatenate" id="publicationOrgUnit_name">
<property name="fields">
@@ -174,7 +174,7 @@
</bean>
<util:map id="isPersonOfProjectMap">
<entry key="project_contributor_author" value-ref="projectPerson_author"/>
<entry key="project.contributor.author" value-ref="projectPerson_author"/>
</util:map>
<bean class="org.dspace.content.virtual.Concatenate" id="projectPerson_author">
<property name="fields">
@@ -189,7 +189,7 @@
</bean>
<util:map id="isOrgUnitOfProjectMap">
<entry key="project_contributor_other" value-ref="projectOrgUnit_other"/>
<entry key="project.contributor.other" value-ref="projectOrgUnit_other"/>
</util:map>
<bean class="org.dspace.content.virtual.Concatenate" id="projectOrgUnit_other">
<property name="fields">
@@ -203,7 +203,7 @@
</bean>
<util:map id="isOrgUnitOfPersonMap">
<entry key="person_contributor_other" value-ref="personProject_other"/>
<entry key="person.contributor.other" value-ref="personProject_other"/>
</util:map>
<bean class="org.dspace.content.virtual.Concatenate" id="personProject_other">
<property name="fields">
@@ -272,7 +272,7 @@
</util:map>
<util:map id="isIssueOfJournalVolumeMap">
<entry key="journalissue_identifier_number" value-ref="journalIssue_number"/>
<entry key="journalissue.identifier.number" value-ref="journalIssue_number"/>
</util:map>
<bean class="org.dspace.content.virtual.Concatenate" id="journalIssue_number">
<property name="fields">
@@ -288,7 +288,7 @@
<util:map id="isJournalIssueOfPublicationMap">
<entry key="journal.identifier.issn" value-ref="issueVolumeJournal_issn_related"/>
<entry key="journal.title" value-ref="issueVolumeJournal_title_related"/>
<entry key="volume.title" value-ref="issueVolume_title_related"/>
<entry key="journalvolume.identifier.name" value-ref="issueVolume_title_related"/>
<entry key="relation.isJournalOfPublication" value-ref="issueVolumeJournal_uuid_related"/>
</util:map>
<bean class="org.dspace.content.virtual.Concatenate" id="issueVolume_title">