Merge branch 'feature-name-variants' of https://github.com/atmire/DSpace into feature-name-variants

# Conflicts:
#	dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java
#	dspace-api/src/main/java/org/dspace/content/RelationshipMetadataServiceImpl.java
This commit is contained in:
Jelle Pelgrims
2019-08-07 09:52:42 +02:00
6 changed files with 691 additions and 423 deletions

View File

@@ -1341,8 +1341,8 @@ prevent the generation of resource policy entry values with null dspace_object a
//except for relation.type which is the type of item in the model
if (StringUtils.equals(schema, MetadataSchemaEnum.RELATION.getName()) && !StringUtils.equals(element, "type")) {
List<RelationshipMetadataValue> relationMetadata =
relationshipMetadataService.getRelationshipMetadata(item, false);
List<RelationshipMetadataValue> relationMetadata = relationshipMetadataService
.getRelationshipMetadata(item, false);
List<MetadataValue> listToReturn = new LinkedList<>();
for (MetadataValue metadataValue : relationMetadata) {
if (StringUtils.equals(metadataValue.getMetadataField().getElement(), element)) {
@@ -1379,7 +1379,7 @@ 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
* @return The list sorted on those criteria
*/
private List<MetadataValue> sortMetadataValueList(List<MetadataValue> listToReturn) {
Comparator<MetadataValue> comparator = Comparator.comparing(
@@ -1398,6 +1398,4 @@ prevent the generation of resource policy entry values with null dspace_object a
}
}

View File

@@ -85,19 +85,21 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
String relationName;
Item otherItem;
int place = 0;
boolean isLeft;
boolean isLeftwards;
if (StringUtils.equals(relationshipType.getLeftType().getLabel(), entityType)) {
hashMaps = virtualMetadataPopulator.getMap().get(relationshipType.getLeftwardLabel());
otherItem = relationship.getRightItem();
relationName = relationship.getRelationshipType().getLeftwardLabel();
place = relationship.getLeftPlace();
isLeft = true;
isLeftwards = false; //if the current item is stored on the left,
// the name variant is retrieved from the rightwards label
} else if (StringUtils.equals(relationshipType.getRightType().getLabel(), entityType)) {
hashMaps = virtualMetadataPopulator.getMap().get(relationshipType.getRightwardLabel());
otherItem = relationship.getLeftItem();
relationName = relationship.getRelationshipType().getRightwardLabel();
place = relationship.getRightPlace();
isLeft = false;
isLeftwards = true; //if the current item is stored on the right,
// the name variant is retrieved from the leftwards label
} else {
//No virtual metadata can be created
return resultingMetadataValueList;
@@ -105,8 +107,8 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
if (hashMaps != null && enableVirtualMetadata) {
resultingMetadataValueList.addAll(handleRelationshipTypeMetadataMapping(context, item, hashMaps,
otherItem, relationName,
relationship, place, isLeft));
otherItem, relationName,
relationship, place, isLeftwards));
}
RelationshipMetadataValue relationMetadataFromOtherItem =
getRelationMetadataFromOtherItem(context, otherItem, relationName, relationship.getID(), place);
@@ -120,10 +122,8 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
//hashmaps parameter. The beans will be used to retrieve the values for the RelationshipMetadataValue objects
//and the keys of the hashmap will be used to construct the RelationshipMetadataValue object.
private List<RelationshipMetadataValue> handleRelationshipTypeMetadataMapping(Context context, Item item,
HashMap<String, VirtualMetadataConfiguration> hashMaps,
Item otherItem, String relationName,
Relationship relationship, int place,
boolean isLeft) throws SQLException {
HashMap<String, VirtualMetadataConfiguration> hashMaps, Item otherItem, String relationName,
Relationship relationship, int place, boolean isLeftwards) throws SQLException {
List<RelationshipMetadataValue> resultingMetadataValueList = new LinkedList<>();
for (Map.Entry<String, VirtualMetadataConfiguration> entry : hashMaps.entrySet()) {
@@ -131,20 +131,18 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
VirtualMetadataConfiguration virtualBean = entry.getValue();
if (virtualBean.getPopulateWithNameVariant()) {
String wardLabel = isLeft ? relationship.getLeftwardLabel() : relationship.getRightwardLabel();
String wardLabel = isLeftwards ? relationship.getLeftwardLabel() : relationship.getRightwardLabel();
if (wardLabel != null) {
resultingMetadataValueList.add(
constructRelationshipMetadataValue(
context, item, relationship.getID(), place, key, virtualBean, wardLabel
));
constructRelationshipMetadataValue(context, item, relationship.getID(), place, key, virtualBean,
wardLabel));
} else {
handleVirtualBeanValues(
context, item, otherItem, relationship, place, resultingMetadataValueList, key, virtualBean);
handleVirtualBeanValues(context, item, otherItem, relationship, place, resultingMetadataValueList,
key, virtualBean);
}
} else {
handleVirtualBeanValues(
context, item, otherItem, relationship, place, resultingMetadataValueList, key, virtualBean
);
handleVirtualBeanValues(context, item, otherItem, relationship, place, resultingMetadataValueList, key,
virtualBean);
}
}
return resultingMetadataValueList;
@@ -154,15 +152,20 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
int place, List<RelationshipMetadataValue> resultingMetadataValueList,
String key, VirtualMetadataConfiguration virtualBean) throws SQLException {
for (String value : virtualBean.getValues(context, otherItem)) {
resultingMetadataValueList.add(
constructRelationshipMetadataValue(context, item, relationship.getID(), place, key, virtualBean, value)
);
RelationshipMetadataValue relationshipMetadataValue = constructRelationshipMetadataValue(context, item,
relationship
.getID(),
place,
key, virtualBean,
value);
if (relationshipMetadataValue != null) {
resultingMetadataValueList.add(relationshipMetadataValue);
}
}
}
private RelationshipMetadataValue constructRelationshipMetadataValue(Context context, Item item,
Integer relationshipId,
int place,
Integer relationshipId, int place,
String key,
VirtualMetadataConfiguration virtualBean,
String value) {

View File

@@ -38,7 +38,7 @@ import org.dspace.eperson.Group;
* @author kevinvandevelde at atmire.com
*/
public interface ItemService
extends DSpaceObjectService<Item>, DSpaceObjectLegacySupportService<Item>, IndexableObjectService<Item, UUID> {
extends DSpaceObjectService<Item>, DSpaceObjectLegacySupportService<Item>, IndexableObjectService<Item, UUID> {
public Thumbnail getThumbnail(Context context, Item item, boolean requireOriginal) throws SQLException;
@@ -180,7 +180,7 @@ public interface ItemService
* @throws SQLException if database error
*/
public Iterator<Item> findInArchiveOrWithdrawnNonDiscoverableModifiedSince(Context context, Date since)
throws SQLException;
throws SQLException;
/**
* Get all the items (including private and withdrawn) in this collection. The order is indeterminate.

View File

@@ -84,4 +84,19 @@ public class RelationshipBuilder extends AbstractBuilder<Relationship, Relations
return this;
}
public RelationshipBuilder withLeftWardLabel(String leftWardLabel) throws SQLException {
relationship.setLeftwardLabel(leftWardLabel);
return this;
}
public RelationshipBuilder withRightWardLabel(String rightWardLabel) throws SQLException {
relationship.setRightwardLabel(rightWardLabel);
return this;
}
public RelationshipBuilder withLeftPlace(int leftPlace) {
relationship.setLeftPlace(leftPlace);
return this;
}
}

View File

@@ -8,7 +8,7 @@
package org.dspace.app.rest.matcher;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import org.hamcrest.Matcher;
@@ -18,7 +18,8 @@ import org.hamcrest.Matcher;
*/
public class MetadataMatcher {
private MetadataMatcher() { }
private MetadataMatcher() {
}
/**
* Gets a matcher to ensure a given value is present among all values for a given metadata key.
@@ -28,7 +29,7 @@ public class MetadataMatcher {
* @return the matcher.
*/
public static Matcher<? super Object> matchMetadata(String key, String value) {
return hasJsonPath("$.['" + key + "'][*].value", contains(value));
return hasJsonPath("$.['" + key + "'][*].value", hasItem(value));
}
/**