DS-2374 authority indexing matching metadata by value

This commit is contained in:
Antoine Snyers
2014-12-19 09:01:39 +01:00
parent f424ac4b39
commit 67b957841e
4 changed files with 33 additions and 16 deletions

View File

@@ -871,7 +871,7 @@ public class MetadataImport
if (byValue.isEmpty()) {
String toGenerate = fromAuthority.generateString() + value;
String field = schema + "_" + element + (StringUtils.isNotBlank(qualifier) ? "_" + qualifier : "");
authorityValue = AuthorityValueGenerator.generate(toGenerate, value, field);
authorityValue = AuthorityValueGenerator.generate(c, toGenerate, value, field);
dcv.authority = toGenerate;
} else {
authorityValue = byValue.get(0);

View File

@@ -44,12 +44,16 @@ public class AuthorityValueFinder {
return findings.size() > 0 ? findings.get(0) : null;
}
public List<AuthorityValue> findByValue(Context context, String schema, String element, String qualifier, String value) {
String field = fieldParameter(schema, element, qualifier);
public List<AuthorityValue> findByValue(Context context, String field, String value) {
String queryString = "value:" + value + " AND field:" + field;
return find(context, queryString);
}
public List<AuthorityValue> findByValue(Context context, String schema, String element, String qualifier, String value) {
String field = fieldParameter(schema, element, qualifier);
return findByValue(context, field, qualifier);
}
public AuthorityValue findByOrcidID(Context context, String orcid_id) {
String queryString = "orcid_id:" + orcid_id;
List<AuthorityValue> findings = find(context, queryString);

View File

@@ -8,8 +8,10 @@
package org.dspace.authority;
import org.apache.commons.lang.StringUtils;
import org.dspace.core.Context;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -31,18 +33,29 @@ public class AuthorityValueGenerator {
public static final String GENERATE = "will be generated" + SPLIT;
public static AuthorityValue generate(String uid, String content, String field) {
public static AuthorityValue generate(Context context, String authorityKey, String content, String field) {
AuthorityValue nextValue = null;
nextValue = generateRaw(uid, content, field);
nextValue = generateRaw(authorityKey, content, field);
if (nextValue != null) {
//Only generate a new UUID if there isn't one offered OR if the identifier needs to be generated
if(StringUtils.isBlank(uid) || StringUtils.startsWith(uid, AuthorityValueGenerator.GENERATE)){
uid = UUID.randomUUID().toString();
if (StringUtils.isBlank(authorityKey)) {
// An existing metadata without authority is being indexed
// If there is an exact match in the index, reuse it before adding a new one.
AuthorityValueFinder authorityValueFinder = new AuthorityValueFinder();
List<AuthorityValue> byValue = authorityValueFinder.findByValue(context, field, content);
if (byValue != null && !byValue.isEmpty()) {
authorityKey = byValue.get(0).getId();
} else {
authorityKey = UUID.randomUUID().toString();
}
} else if (StringUtils.startsWith(authorityKey, AuthorityValueGenerator.GENERATE)) {
authorityKey = UUID.randomUUID().toString();
}
nextValue.setId(uid);
nextValue.setId(authorityKey);
nextValue.updateLastModifiedDate();
nextValue.setCreationDate(new Date());
nextValue.setField(field);
@@ -51,10 +64,10 @@ public class AuthorityValueGenerator {
return nextValue;
}
protected static AuthorityValue generateRaw(String uid, String content, String field) {
protected static AuthorityValue generateRaw(String authorityKey, String content, String field) {
AuthorityValue nextValue;
if (uid != null && uid.startsWith(AuthorityValueGenerator.GENERATE)) {
String[] split = StringUtils.split(uid, SPLIT);
if (authorityKey != null && authorityKey.startsWith(AuthorityValueGenerator.GENERATE)) {
String[] split = StringUtils.split(authorityKey, SPLIT);
String type = null, info = null;
if (split.length > 0) {
type = split[1];

View File

@@ -173,16 +173,16 @@ public class DSpaceAuthorityIndexer implements AuthorityIndexerInterface, Initia
nextValue = null;
String content = value.value;
String uid = value.authority;
String authorityKey = value.authority;
//We only want to update our item IF our UUID is not present or if we need to generate one.
boolean requiresItemUpdate = StringUtils.isBlank(uid) || StringUtils.startsWith(uid, AuthorityValueGenerator.GENERATE);
boolean requiresItemUpdate = StringUtils.isBlank(authorityKey) || StringUtils.startsWith(authorityKey, AuthorityValueGenerator.GENERATE);
if (StringUtils.isNotBlank(uid) && !uid.startsWith(AuthorityValueGenerator.GENERATE)) {
if (StringUtils.isNotBlank(authorityKey) && !authorityKey.startsWith(AuthorityValueGenerator.GENERATE)) {
// !uid.startsWith(AuthorityValueGenerator.GENERATE) is not strictly necessary here but it prevents exceptions in solr
nextValue = authorityValueFinder.findByUID(context, uid);
nextValue = authorityValueFinder.findByUID(context, authorityKey);
}
if (nextValue == null) {
nextValue = AuthorityValueGenerator.generate(uid, content, metadataField.replaceAll("\\.", "_"));
nextValue = AuthorityValueGenerator.generate(context, authorityKey, content, metadataField.replaceAll("\\.", "_"));
}
if (nextValue != null && requiresItemUpdate) {
nextValue.updateItem(currentItem, value);