forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support virtual metadata for authority-controlled fields
- Loading branch information
Showing
7 changed files
with
316 additions
and
2 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
dspace-api/src/main/java/org/dspace/content/AuthorityVirtualMetadataValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* 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; | ||
|
||
import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
import org.dspace.core.Constants; | ||
|
||
/** | ||
* Implementation of {@link VirtualMetadataValue} specifically for authority-based virtual metadata. | ||
* It is a more simple implementation than {@link RelationshipMetadataValue} as it doesn't have a way to calculate | ||
* relative place (place is set during value creation based on number of other values in the field) and does not | ||
* override {@link VirtualMetadataValue#getID()} | ||
* | ||
* @author Kim Shepherd | ||
*/ | ||
public class AuthorityVirtualMetadataValue extends VirtualMetadataValue { | ||
|
||
/** | ||
* Use authority key (URI, UUID, etc), value, metadatafield ID, and place number to generate hash code | ||
* @return unique hash code | ||
*/ | ||
@Override | ||
public int hashCode() { | ||
return new HashCodeBuilder().append(getAuthority() | ||
.substring(Constants.VIRTUAL_AUTHORITY_PREFIX.length())) | ||
.append(getMetadataFieldId()) | ||
.append(getValue()) | ||
.append(getPlace()).hashCode(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
dspace-api/src/main/java/org/dspace/content/VirtualMetadataValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* 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; | ||
|
||
/** | ||
* A simple abstraction to allow {@link RelationshipMetadataValue} and {@link AuthorityVirtualMetadataValue} | ||
* extend it while allowing reflection or instance checking for MetadataValue and VirtualMetadataValue | ||
* | ||
* @author Kim Shepherd | ||
*/ | ||
public class VirtualMetadataValue extends MetadataValue { | ||
|
||
/** | ||
* This is a bit of a hack, much like {@link RelationshipMetadataValue} - the ID is not something that corresponds | ||
* to a real metadata value, but instead the source object. Unfortunately metadata value and relationships both | ||
* use integers and not Strings like authority values. | ||
* Returning -1 guarantees that any erroneous calls to an AuthorityVirtualMetadataValue object will not send | ||
* the caller off to a real, unrelated MetadataValue, so this default behaviour is implemented | ||
* | ||
* @return integerised authority key | ||
*/ | ||
@Override | ||
public Integer getID() { | ||
return -1; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
dspace-api/src/main/java/org/dspace/content/virtual/AuthorityCollected.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* 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.virtual; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.dspace.authority.AuthorityValue; | ||
|
||
/** | ||
* Implements the {@link AuthorityVirtualMetadataConfiguration} interface to achieve the generation of Virtual | ||
* metadata for authority values, in a similar way to the entity-driven {@link VirtualMetadataConfiguration}. | ||
* The Collected bean will take all the Solr document values for the defined fields and create a list of | ||
* virtual metadata fields for use by the {@link AuthorityVirtualMetadataPopulator}. | ||
* | ||
* @author Kim Shepherd | ||
* | ||
*/ | ||
public class AuthorityCollected implements AuthorityVirtualMetadataConfiguration { | ||
/** | ||
* The field names to retrieve from the Authority Solr document - note these do NOT have to match | ||
* the field names of the resulting virtual metadata values - they are set as the key of the map that contains | ||
* this map. (e.g. 'dcterms.spatial -> ['my_solr_spatial_field' -> [x, y, z], 'another_field' -> [x, y, z]]) | ||
*/ | ||
private List<String> fields; | ||
|
||
/** | ||
* Generic getter for the fields property | ||
* @return The list of field names | ||
*/ | ||
public List<String> getFields() { | ||
return fields; | ||
} | ||
|
||
/** | ||
* Generic setter for the fields property | ||
* @param fields the list of field names | ||
*/ | ||
public void setFields(List<String> fields) { | ||
this.fields = fields; | ||
} | ||
|
||
/** | ||
* Retrieve the values from the given AuthorityValue "otherMetadataMap" for each configured fields property | ||
* and return as a list. The authority value is responsible for how to store and return this map. | ||
* | ||
* @param authorityValue The authority value from which to build the list of values | ||
* @return The String values for each field configured | ||
*/ | ||
public List<String> getValues(AuthorityValue authorityValue) { | ||
List<String> resultValues = new LinkedList<>(); | ||
List<String> fieldsToRetrieve = this.getFields(); | ||
Map<String, List<String>> metadataMap = authorityValue.getOtherMetadataMap(); | ||
for (String field : fieldsToRetrieve) { | ||
List<String> otherMetadata = metadataMap.get(field); | ||
if (otherMetadata != null) { | ||
resultValues.addAll(otherMetadata); | ||
} | ||
} | ||
return resultValues; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...e-api/src/main/java/org/dspace/content/virtual/AuthorityVirtualMetadataConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* 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.virtual; | ||
|
||
import java.util.List; | ||
|
||
import org.dspace.authority.AuthorityValue; | ||
|
||
/** | ||
* This interface describes beans to be used for the {@link AuthorityVirtualMetadataPopulator} implementation. | ||
* It achieves virtual metadata that looks and acts identical to the entity-driven {@link VirtualMetadataConfiguration} | ||
* but uses Authority values as the source for metadata values instead of a related DSpace Item | ||
* | ||
* Functionality like 'useNameVariants' and 'useForPlace' are not implemented as authority values typically don't | ||
* have enough information to derive this. | ||
* | ||
* @author Kim Shepherd | ||
*/ | ||
public interface AuthorityVirtualMetadataConfiguration { | ||
|
||
/** | ||
* Retrieve the values from the given AuthorityValue "otherMetadataMap" for each configured fields property | ||
* and return as a list. The authority value is responsible for how to store and return this map. | ||
* | ||
* @param authorityValue The authority value from which to build the list of values | ||
* @return The String values for each field configured | ||
*/ | ||
List<String> getValues(AuthorityValue authorityValue); | ||
} |
47 changes: 47 additions & 0 deletions
47
dspace-api/src/main/java/org/dspace/content/virtual/AuthorityVirtualMetadataPopulator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* 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.virtual; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* This class simply sets and gets maps of maps of string-{@link AuthorityVirtualMetadataConfiguration}s, where the key | ||
* is an authority-controlled metadata field like dc.subject, and the key in the value map is the virtual field name | ||
* to set / transform for a given set of values (e.g. dc.description, dcterms.spatial). | ||
* It operates in a similar way to entity {@link VirtualMetadataPopulator} | ||
* | ||
* @author Kim Shepherd | ||
*/ | ||
public class AuthorityVirtualMetadataPopulator { | ||
|
||
/** | ||
* The map of authority controlled field names, to a map of virtual metadata field names and configurations. | ||
*/ | ||
private Map<String, HashMap<String, AuthorityVirtualMetadataConfiguration>> map; | ||
|
||
/** | ||
* Sets the map of authority controlled field names to a map of virtual metadata field names and configurations. | ||
* The map is used for authority virtual metadata population. | ||
* | ||
* @param map the map of authority controlled field names to virtual metadata field names and configurations | ||
*/ | ||
public void setMap(Map<String, HashMap<String, AuthorityVirtualMetadataConfiguration>> map) { | ||
this.map = map; | ||
} | ||
|
||
/** | ||
* Retrieves the map of authority controlled field names to a map of virtual metadata field names and configurations. | ||
* | ||
* @return the map of authority controlled field names to virtual metadata field names and configurations | ||
*/ | ||
public Map<String, HashMap<String, AuthorityVirtualMetadataConfiguration>> getMap() { | ||
return map; | ||
} | ||
|
||
} |