mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 13:33:08 +00:00
intermediary commit
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
package org.dspace.content;
|
package org.dspace.content;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@@ -1,3 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
package org.dspace.content;
|
package org.dspace.content;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@@ -78,16 +85,19 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
|
|||||||
String relationName;
|
String relationName;
|
||||||
Item otherItem;
|
Item otherItem;
|
||||||
int place = 0;
|
int place = 0;
|
||||||
|
boolean isLeft;
|
||||||
if (StringUtils.equals(relationshipType.getLeftType().getLabel(), entityType)) {
|
if (StringUtils.equals(relationshipType.getLeftType().getLabel(), entityType)) {
|
||||||
hashMaps = virtualMetadataPopulator.getMap().get(relationshipType.getLeftLabel());
|
hashMaps = virtualMetadataPopulator.getMap().get(relationshipType.getLeftLabel());
|
||||||
otherItem = relationship.getRightItem();
|
otherItem = relationship.getRightItem();
|
||||||
relationName = relationship.getRelationshipType().getLeftLabel();
|
relationName = relationship.getRelationshipType().getLeftLabel();
|
||||||
place = relationship.getLeftPlace();
|
place = relationship.getLeftPlace();
|
||||||
|
isLeft = true;
|
||||||
} else if (StringUtils.equals(relationshipType.getRightType().getLabel(), entityType)) {
|
} else if (StringUtils.equals(relationshipType.getRightType().getLabel(), entityType)) {
|
||||||
hashMaps = virtualMetadataPopulator.getMap().get(relationshipType.getRightLabel());
|
hashMaps = virtualMetadataPopulator.getMap().get(relationshipType.getRightLabel());
|
||||||
otherItem = relationship.getLeftItem();
|
otherItem = relationship.getLeftItem();
|
||||||
relationName = relationship.getRelationshipType().getRightLabel();
|
relationName = relationship.getRelationshipType().getRightLabel();
|
||||||
place = relationship.getRightPlace();
|
place = relationship.getRightPlace();
|
||||||
|
isLeft = false;
|
||||||
} else {
|
} else {
|
||||||
//No virtual metadata can be created
|
//No virtual metadata can be created
|
||||||
return resultingMetadataValueList;
|
return resultingMetadataValueList;
|
||||||
@@ -96,7 +106,7 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
|
|||||||
if (hashMaps != null && enableVirtualMetadata) {
|
if (hashMaps != null && enableVirtualMetadata) {
|
||||||
resultingMetadataValueList.addAll(handleRelationshipTypeMetadataMapping(context, item, hashMaps,
|
resultingMetadataValueList.addAll(handleRelationshipTypeMetadataMapping(context, item, hashMaps,
|
||||||
otherItem, relationName,
|
otherItem, relationName,
|
||||||
relationship.getID(), place));
|
relationship, place, isLeft));
|
||||||
}
|
}
|
||||||
RelationshipMetadataValue relationMetadataFromOtherItem =
|
RelationshipMetadataValue relationMetadataFromOtherItem =
|
||||||
getRelationMetadataFromOtherItem(context, otherItem, relationName, relationship.getID(), place);
|
getRelationMetadataFromOtherItem(context, otherItem, relationName, relationship.getID(), place);
|
||||||
@@ -110,27 +120,51 @@ public class RelationshipMetadataServiceImpl implements RelationshipMetadataServ
|
|||||||
//hashmaps parameter. The beans will be used to retrieve the values for the RelationshipMetadataValue objects
|
//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.
|
//and the keys of the hashmap will be used to construct the RelationshipMetadataValue object.
|
||||||
private List<RelationshipMetadataValue> handleRelationshipTypeMetadataMapping(Context context, Item item,
|
private List<RelationshipMetadataValue> handleRelationshipTypeMetadataMapping(Context context, Item item,
|
||||||
HashMap<String, VirtualMetadataConfiguration> hashMaps, Item otherItem, String relationName,
|
HashMap<String, VirtualMetadataConfiguration> hashMaps,
|
||||||
Integer relationshipId, int place) throws SQLException {
|
Item otherItem, String relationName,
|
||||||
|
Relationship relationship, int place,
|
||||||
|
boolean isLeft) throws SQLException {
|
||||||
|
|
||||||
List<RelationshipMetadataValue> resultingMetadataValueList = new LinkedList<>();
|
List<RelationshipMetadataValue> resultingMetadataValueList = new LinkedList<>();
|
||||||
for (Map.Entry<String, VirtualMetadataConfiguration> entry : hashMaps.entrySet()) {
|
for (Map.Entry<String, VirtualMetadataConfiguration> entry : hashMaps.entrySet()) {
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
VirtualMetadataConfiguration virtualBean = entry.getValue();
|
VirtualMetadataConfiguration virtualBean = entry.getValue();
|
||||||
|
|
||||||
|
if (virtualBean.getPopulateWithNameVariant()) {
|
||||||
|
String wardLabel = isLeft ? relationship.getLeftwardLabel() : relationship.getRightwardLabel();
|
||||||
|
if (wardLabel != null) {
|
||||||
|
resultingMetadataValueList.add(constructRelationshipMetadataValue(context, item, relationship.getID(), place, key, virtualBean, wardLabel));
|
||||||
|
} else {
|
||||||
|
handleVirtualBeanValues(context, item, otherItem, relationship, place, resultingMetadataValueList, key, virtualBean);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
handleVirtualBeanValues(context, item, otherItem, relationship, place, resultingMetadataValueList, key, virtualBean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultingMetadataValueList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleVirtualBeanValues(Context context, Item item, Item otherItem, Relationship relationship,
|
||||||
|
int place, List<RelationshipMetadataValue> resultingMetadataValueList,
|
||||||
|
String key, VirtualMetadataConfiguration virtualBean) throws SQLException {
|
||||||
for (String value : virtualBean.getValues(context, otherItem)) {
|
for (String value : virtualBean.getValues(context, otherItem)) {
|
||||||
|
resultingMetadataValueList.add(constructRelationshipMetadataValue(context, item, relationship.getID(), place, key, virtualBean, value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RelationshipMetadataValue constructRelationshipMetadataValue(Context context, Item item, Integer relationshipId, int place,
|
||||||
|
String key, VirtualMetadataConfiguration virtualBean,
|
||||||
|
String value) {
|
||||||
RelationshipMetadataValue metadataValue = constructMetadataValue(context, key);
|
RelationshipMetadataValue metadataValue = constructMetadataValue(context, key);
|
||||||
if (metadataValue != null) {
|
if (metadataValue != null) {
|
||||||
metadataValue = constructResultingMetadataValue(item, value, metadataValue, relationshipId);
|
metadataValue = constructResultingMetadataValue(item, value, metadataValue, relationshipId);
|
||||||
metadataValue.setUseForPlace(virtualBean.getUseForPlace());
|
metadataValue.setUseForPlace(virtualBean.getUseForPlace());
|
||||||
metadataValue.setPlace(place);
|
metadataValue.setPlace(place);
|
||||||
if (StringUtils.isNotBlank(metadataValue.getValue())) {
|
if (StringUtils.isNotBlank(metadataValue.getValue())) {
|
||||||
resultingMetadataValueList.add(metadataValue);
|
return metadataValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
}
|
|
||||||
return resultingMetadataValueList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//This method will construct a RelationshipMetadataValue object with proper schema, element and qualifier based
|
//This method will construct a RelationshipMetadataValue object with proper schema, element and qualifier based
|
||||||
|
@@ -77,6 +77,12 @@ public class Collected implements VirtualMetadataConfiguration {
|
|||||||
return useForPlace;
|
return useForPlace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPopulateWithNameVariant(boolean populateWithNameVariant) { }
|
||||||
|
|
||||||
|
public boolean getPopulateWithNameVariant() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this method will retrieve the metadata values from the given item for all the metadata fields listed
|
* this method will retrieve the metadata values from the given item for all the metadata fields listed
|
||||||
* in the fields property and it'll return all those values as a list
|
* in the fields property and it'll return all those values as a list
|
||||||
|
@@ -44,6 +44,7 @@ public class Concatenate implements VirtualMetadataConfiguration {
|
|||||||
*/
|
*/
|
||||||
private boolean useForPlace = false;
|
private boolean useForPlace = false;
|
||||||
|
|
||||||
|
private boolean populateWithNameVariant = false;
|
||||||
/**
|
/**
|
||||||
* Generic getter for the fields property
|
* Generic getter for the fields property
|
||||||
* @return The list of fields to be used in this bean
|
* @return The list of fields to be used in this bean
|
||||||
@@ -92,6 +93,14 @@ public class Concatenate implements VirtualMetadataConfiguration {
|
|||||||
return useForPlace;
|
return useForPlace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPopulateWithNameVariant(boolean populateWithNameVariant) {
|
||||||
|
this.populateWithNameVariant = populateWithNameVariant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getPopulateWithNameVariant() {
|
||||||
|
return populateWithNameVariant;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this method will retrieve the metadata values from the given item for all the metadata fields listed
|
* this method will retrieve the metadata values from the given item for all the metadata fields listed
|
||||||
* in the fields property and it'll concatenate all those values together with the separator specified
|
* in the fields property and it'll concatenate all those values together with the separator specified
|
||||||
|
@@ -132,6 +132,12 @@ public class Related implements VirtualMetadataConfiguration {
|
|||||||
return useForPlace;
|
return useForPlace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPopulateWithNameVariant(boolean populateWithNameVariant) { }
|
||||||
|
|
||||||
|
public boolean getPopulateWithNameVariant() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will find the correct Relationship from the given item to retrieve the other item from it
|
* This method will find the correct Relationship from the given item to retrieve the other item from it
|
||||||
* and pass this along to the next VirtualBean that's stored in this class.
|
* and pass this along to the next VirtualBean that's stored in this class.
|
||||||
|
@@ -38,4 +38,10 @@ public class UUIDValue implements VirtualMetadataConfiguration {
|
|||||||
public boolean getUseForPlace() {
|
public boolean getUseForPlace() {
|
||||||
return useForPlace;
|
return useForPlace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPopulateWithNameVariant(boolean populateWithNameVariant) { }
|
||||||
|
|
||||||
|
public boolean getPopulateWithNameVariant() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -42,4 +42,8 @@ public interface VirtualMetadataConfiguration {
|
|||||||
* @return The useForPlace to be used by this bean
|
* @return The useForPlace to be used by this bean
|
||||||
*/
|
*/
|
||||||
boolean getUseForPlace();
|
boolean getUseForPlace();
|
||||||
|
|
||||||
|
void setPopulateWithNameVariant(boolean populateWithNameVariant);
|
||||||
|
|
||||||
|
boolean getPopulateWithNameVariant();
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
package org.dspace.content;
|
package org.dspace.content;
|
||||||
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
@@ -59,6 +59,7 @@
|
|||||||
<value>, </value>
|
<value>, </value>
|
||||||
</property>
|
</property>
|
||||||
<property name="useForPlace" value="true"/>
|
<property name="useForPlace" value="true"/>
|
||||||
|
<property name="populateWithNameVariant" value="true"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- Config like this will tell our VirtualMetadataPopulator to include the virtual metadata field
|
<!-- Config like this will tell our VirtualMetadataPopulator to include the virtual metadata field
|
||||||
|
Reference in New Issue
Block a user