mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-11 20:13:17 +00:00
Fix dspace-api module per new code style
This commit is contained in:
@@ -36,15 +36,18 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Service implementation class for the DSpaceObject.
|
||||
* All DSpaceObject service classes should extend this class since it implements some basic methods which all DSpaceObjects
|
||||
* All DSpaceObject service classes should extend this class since it implements some basic methods which all
|
||||
* DSpaceObjects
|
||||
* are required to have.
|
||||
*
|
||||
* @author kevinvandevelde at atmire.com
|
||||
* @param <T> class type
|
||||
* @author kevinvandevelde at atmire.com
|
||||
*/
|
||||
public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements DSpaceObjectService<T> {
|
||||
|
||||
/** log4j category */
|
||||
/**
|
||||
* log4j category
|
||||
*/
|
||||
private static final Logger log = Logger.getLogger(DSpaceObjectServiceImpl.class);
|
||||
|
||||
@Autowired(required = true)
|
||||
@@ -58,8 +61,7 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
@Autowired(required = true)
|
||||
protected MetadataAuthorityService metadataAuthorityService;
|
||||
|
||||
public DSpaceObjectServiceImpl()
|
||||
{
|
||||
public DSpaceObjectServiceImpl() {
|
||||
|
||||
}
|
||||
|
||||
@@ -71,30 +73,25 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
|
||||
@Override
|
||||
public ArrayList<String> getIdentifiers(Context context, T dso) {
|
||||
ArrayList<String > identifiers = new ArrayList<>();
|
||||
ArrayList<String> identifiers = new ArrayList<>();
|
||||
|
||||
IdentifierService identifierService =
|
||||
new DSpace().getSingletonService(IdentifierService.class);
|
||||
new DSpace().getSingletonService(IdentifierService.class);
|
||||
|
||||
if (identifierService != null)
|
||||
{
|
||||
if (identifierService != null) {
|
||||
identifiers.addAll(identifierService.lookup(context, dso));
|
||||
} else {
|
||||
log.warn("No IdentifierService found, will return an list containing "
|
||||
+ "the Handle only.");
|
||||
if (dso.getHandle() != null)
|
||||
{
|
||||
+ "the Handle only.");
|
||||
if (dso.getHandle() != null) {
|
||||
identifiers.add(handleService.getCanonicalForm(dso.getHandle()));
|
||||
}
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
if (log.isDebugEnabled()) {
|
||||
StringBuilder dbgMsg = new StringBuilder();
|
||||
for (String id : identifiers)
|
||||
{
|
||||
if (dbgMsg.capacity() == 0)
|
||||
{
|
||||
for (String id : identifiers) {
|
||||
if (dbgMsg.capacity() == 0) {
|
||||
dbgMsg.append("This DSO's Identifiers are: ");
|
||||
} else {
|
||||
dbgMsg.append(", ");
|
||||
@@ -109,15 +106,13 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public DSpaceObject getParentObject(Context context, T dso) throws SQLException
|
||||
{
|
||||
public DSpaceObject getParentObject(Context context, T dso) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DSpaceObject getAdminObject(Context context, T dso, int action) throws SQLException {
|
||||
if (action == Constants.ADMIN)
|
||||
{
|
||||
if (action == Constants.ADMIN) {
|
||||
throw new IllegalArgumentException("Illegal call to the DSpaceObject.getAdminObject method");
|
||||
}
|
||||
return dso;
|
||||
@@ -132,10 +127,8 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
public List<MetadataValue> getMetadata(T dso, String schema, String element, String qualifier, String lang) {
|
||||
// Build up list of matching values
|
||||
List<MetadataValue> values = new ArrayList<MetadataValue>();
|
||||
for (MetadataValue dcv : dso.getMetadata())
|
||||
{
|
||||
if (match(schema, element, qualifier, lang, dcv))
|
||||
{
|
||||
for (MetadataValue dcv : dso.getMetadata()) {
|
||||
if (match(schema, element, qualifier, lang, dcv)) {
|
||||
values.add(dcv);
|
||||
}
|
||||
}
|
||||
@@ -145,14 +138,12 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MetadataValue> getMetadataByMetadataString(T dso, String mdString)
|
||||
{
|
||||
public List<MetadataValue> getMetadataByMetadataString(T dso, String mdString) {
|
||||
StringTokenizer dcf = new StringTokenizer(mdString, ".");
|
||||
|
||||
String[] tokens = { "", "", "" };
|
||||
String[] tokens = {"", "", ""};
|
||||
int i = 0;
|
||||
while(dcf.hasMoreTokens())
|
||||
{
|
||||
while (dcf.hasMoreTokens()) {
|
||||
tokens[i] = dcf.nextToken().trim();
|
||||
i++;
|
||||
}
|
||||
@@ -165,28 +156,23 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
return values;
|
||||
}
|
||||
|
||||
private List<MetadataValue> getMetadata(T dso, String schema, String element, String qualifier) {
|
||||
List<MetadataValue> values;
|
||||
if (Item.ANY.equals(qualifier))
|
||||
{
|
||||
private List<MetadataValue> getMetadata(T dso, String schema, String element, String qualifier) {
|
||||
List<MetadataValue> values;
|
||||
if (Item.ANY.equals(qualifier)) {
|
||||
values = getMetadata(dso, schema, element, Item.ANY, Item.ANY);
|
||||
}
|
||||
else if ("".equals(qualifier))
|
||||
{
|
||||
} else if ("".equals(qualifier)) {
|
||||
values = getMetadata(dso, schema, element, null, Item.ANY);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
values = getMetadata(dso, schema, element, qualifier, Item.ANY);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMetadata(T dso, String value) {
|
||||
List<MetadataValue> metadataValues = getMetadataByMetadataString(dso, value);
|
||||
|
||||
if(CollectionUtils.isNotEmpty(metadataValues)) {
|
||||
if (CollectionUtils.isNotEmpty(metadataValues)) {
|
||||
return metadataValues.iterator().next().getValue();
|
||||
}
|
||||
return null;
|
||||
@@ -199,7 +185,8 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MetadataValue> getMetadata(T dso, String schema, String element, String qualifier, String lang, String authority){
|
||||
public List<MetadataValue> getMetadata(T dso, String schema, String element, String qualifier, String lang,
|
||||
String authority) {
|
||||
List<MetadataValue> metadata = getMetadata(dso, schema, element, qualifier, lang);
|
||||
List<MetadataValue> result = new ArrayList<>(metadata);
|
||||
if (!authority.equals(Item.ANY)) {
|
||||
@@ -215,35 +202,42 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, List<String> values) throws SQLException {
|
||||
public void addMetadata(Context context, T dso, String schema, String element, String qualifier, String lang,
|
||||
List<String> values) throws SQLException {
|
||||
MetadataField metadataField = metadataFieldService.findByElement(context, schema, element, qualifier);
|
||||
if (metadataField == null) {
|
||||
throw new SQLException("bad_dublin_core schema=" + schema + "." + element + "." + qualifier + ". Metadata field does not exist!");
|
||||
throw new SQLException(
|
||||
"bad_dublin_core schema=" + schema + "." + element + "." + qualifier + ". Metadata field does not " +
|
||||
"exist!");
|
||||
}
|
||||
|
||||
addMetadata(context, dso, metadataField, lang, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, List<String> values, List<String> authorities, List<Integer> confidences) throws SQLException {
|
||||
public void addMetadata(Context context, T dso, String schema, String element, String qualifier, String lang,
|
||||
List<String> values, List<String> authorities, List<Integer> confidences)
|
||||
throws SQLException {
|
||||
// We will not verify that they are valid entries in the registry
|
||||
// until update() is called.
|
||||
MetadataField metadataField = metadataFieldService.findByElement(context, schema, element, qualifier);
|
||||
if (metadataField == null) {
|
||||
throw new SQLException("bad_dublin_core schema=" + schema + "." + element + "." + qualifier + ". Metadata field does not exist!");
|
||||
throw new SQLException(
|
||||
"bad_dublin_core schema=" + schema + "." + element + "." + qualifier + ". Metadata field does not " +
|
||||
"exist!");
|
||||
}
|
||||
addMetadata(context, dso, metadataField, lang, values, authorities, confidences);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMetadata(Context context, T dso, MetadataField metadataField, String lang, List<String> values, List<String> authorities, List<Integer> confidences) throws SQLException {
|
||||
public void addMetadata(Context context, T dso, MetadataField metadataField, String lang, List<String> values,
|
||||
List<String> authorities, List<Integer> confidences) throws SQLException {
|
||||
boolean authorityControlled = metadataAuthorityService.isAuthorityControlled(metadataField);
|
||||
boolean authorityRequired = metadataAuthorityService.isAuthorityRequired(metadataField);
|
||||
|
||||
// We will not verify that they are valid entries in the registry
|
||||
// until update() is called.
|
||||
for (int i = 0; i < values.size(); i++)
|
||||
{
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
|
||||
MetadataValue metadataValue = metadataValueService.create(context, dso, metadataField);
|
||||
metadataValue.setLanguage(lang == null ? null : lang.trim());
|
||||
@@ -251,47 +245,43 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
// Logic to set Authority and Confidence:
|
||||
// - normalize an empty string for authority to NULL.
|
||||
// - if authority key is present, use given confidence or NOVALUE if not given
|
||||
// - otherwise, preserve confidence if meaningful value was given since it may document a failed authority lookup
|
||||
// - otherwise, preserve confidence if meaningful value was given since it may document a failed
|
||||
// authority lookup
|
||||
// - CF_UNSET signifies no authority nor meaningful confidence.
|
||||
// - it's possible to have empty authority & CF_ACCEPTED if e.g. user deletes authority key
|
||||
if (authorityControlled)
|
||||
{
|
||||
if (authorities != null && authorities.get(i) != null && authorities.get(i).length() > 0)
|
||||
{
|
||||
if (authorityControlled) {
|
||||
if (authorities != null && authorities.get(i) != null && authorities.get(i).length() > 0) {
|
||||
metadataValue.setAuthority(authorities.get(i));
|
||||
metadataValue.setConfidence(confidences == null ? Choices.CF_NOVALUE : confidences.get(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
metadataValue.setAuthority(null);
|
||||
metadataValue.setConfidence(confidences == null ? Choices.CF_UNSET : confidences.get(i));
|
||||
}
|
||||
// authority sanity check: if authority is required, was it supplied?
|
||||
// XXX FIXME? can't throw a "real" exception here without changing all the callers to expect it, so use a runtime exception
|
||||
if (authorityRequired && (metadataValue.getAuthority() == null || metadataValue.getAuthority().length() == 0))
|
||||
{
|
||||
throw new IllegalArgumentException("The metadata field \"" + metadataField.toString() + "\" requires an authority key but none was provided. Value=\"" + values.get(i) + "\"");
|
||||
// XXX FIXME? can't throw a "real" exception here without changing all the callers to expect it, so
|
||||
// use a runtime exception
|
||||
if (authorityRequired && (metadataValue.getAuthority() == null || metadataValue.getAuthority()
|
||||
.length() == 0)) {
|
||||
throw new IllegalArgumentException("The metadata field \"" + metadataField
|
||||
.toString() + "\" requires an authority key but none was provided. Value=\"" + values
|
||||
.get(i) + "\"");
|
||||
}
|
||||
}
|
||||
if (values.get(i) != null)
|
||||
{
|
||||
if (values.get(i) != null) {
|
||||
// remove control unicode char
|
||||
String temp = values.get(i).trim();
|
||||
char[] dcvalue = temp.toCharArray();
|
||||
for (int charPos = 0; charPos < dcvalue.length; charPos++)
|
||||
{
|
||||
for (int charPos = 0; charPos < dcvalue.length; charPos++) {
|
||||
if (Character.isISOControl(dcvalue[charPos]) &&
|
||||
!String.valueOf(dcvalue[charPos]).equals("\u0009") &&
|
||||
!String.valueOf(dcvalue[charPos]).equals("\n") &&
|
||||
!String.valueOf(dcvalue[charPos]).equals("\r"))
|
||||
{
|
||||
!String.valueOf(dcvalue[charPos]).equals("\u0009") &&
|
||||
!String.valueOf(dcvalue[charPos]).equals("\n") &&
|
||||
!String.valueOf(dcvalue[charPos]).equals("\r")) {
|
||||
dcvalue[charPos] = ' ';
|
||||
}
|
||||
}
|
||||
metadataValue.setValue(String.valueOf(dcvalue));;
|
||||
}
|
||||
else
|
||||
{
|
||||
metadataValue.setValue(String.valueOf(dcvalue));
|
||||
;
|
||||
} else {
|
||||
metadataValue.setValue(null);
|
||||
}
|
||||
//An update here isn't needed, this is persited upon the merge of the owning object
|
||||
@@ -301,30 +291,38 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value, String authority, int confidence) throws SQLException {
|
||||
addMetadata(context, dso, metadataField, language, Arrays.asList(value), Arrays.asList(authority), Arrays.asList(confidence));
|
||||
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value,
|
||||
String authority, int confidence) throws SQLException {
|
||||
addMetadata(context, dso, metadataField, language, Arrays.asList(value), Arrays.asList(authority),
|
||||
Arrays.asList(confidence));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, String value) throws SQLException {
|
||||
public void addMetadata(Context context, T dso, String schema, String element, String qualifier, String lang,
|
||||
String value) throws SQLException {
|
||||
addMetadata(context, dso, schema, element, qualifier, lang, Arrays.asList(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value) throws SQLException {
|
||||
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value)
|
||||
throws SQLException {
|
||||
addMetadata(context, dso, metadataField, language, Arrays.asList(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, List<String> values) throws SQLException {
|
||||
if(metadataField != null) {
|
||||
String fieldKey = metadataAuthorityService.makeFieldKey(metadataField.getMetadataSchema().getName(), metadataField.getElement(), metadataField.getQualifier());
|
||||
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, List<String> values)
|
||||
throws SQLException {
|
||||
if (metadataField != null) {
|
||||
String fieldKey = metadataAuthorityService
|
||||
.makeFieldKey(metadataField.getMetadataSchema().getName(), metadataField.getElement(),
|
||||
metadataField.getQualifier());
|
||||
if (metadataAuthorityService.isAuthorityControlled(fieldKey)) {
|
||||
List<String> authorities = new ArrayList<String>();
|
||||
List<Integer> confidences = new ArrayList<Integer>();
|
||||
for (int i = 0; i < values.size(); ++i) {
|
||||
if (dso instanceof Item) {
|
||||
getAuthoritiesAndConfidences(fieldKey, ((Item) dso).getOwningCollection(), values, authorities, confidences, i);
|
||||
getAuthoritiesAndConfidences(fieldKey, ((Item) dso).getOwningCollection(), values, authorities,
|
||||
confidences, i);
|
||||
} else {
|
||||
getAuthoritiesAndConfidences(fieldKey, null, values, authorities, confidences, i);
|
||||
}
|
||||
@@ -337,19 +335,20 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, String value, String authority, int confidence) throws SQLException {
|
||||
addMetadata(context, dso, schema, element, qualifier, lang, Arrays.asList(value), Arrays.asList(authority), Arrays.asList(confidence));
|
||||
public void addMetadata(Context context, T dso, String schema, String element, String qualifier, String lang,
|
||||
String value, String authority, int confidence) throws SQLException {
|
||||
addMetadata(context, dso, schema, element, qualifier, lang, Arrays.asList(value), Arrays.asList(authority),
|
||||
Arrays.asList(confidence));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMetadata(Context context, T dso, String schema, String element, String qualifier, String lang) throws SQLException {
|
||||
public void clearMetadata(Context context, T dso, String schema, String element, String qualifier, String lang)
|
||||
throws SQLException {
|
||||
Iterator<MetadataValue> metadata = dso.getMetadata().iterator();
|
||||
while (metadata.hasNext())
|
||||
{
|
||||
while (metadata.hasNext()) {
|
||||
MetadataValue metadataValue = metadata.next();
|
||||
// If this value matches, delete it
|
||||
if (match(schema, element, qualifier, lang, metadataValue))
|
||||
{
|
||||
if (match(schema, element, qualifier, lang, metadataValue)) {
|
||||
metadata.remove();
|
||||
metadataValueService.delete(context, metadataValue);
|
||||
}
|
||||
@@ -362,8 +361,7 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
Iterator<MetadataValue> metadata = dso.getMetadata().iterator();
|
||||
while (metadata.hasNext()) {
|
||||
MetadataValue metadataValue = metadata.next();
|
||||
if(values.contains(metadataValue))
|
||||
{
|
||||
if (values.contains(metadataValue)) {
|
||||
metadata.remove();
|
||||
metadataValueService.delete(context, metadataValue);
|
||||
}
|
||||
@@ -373,23 +371,19 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
|
||||
/**
|
||||
* Retrieve first metadata field value
|
||||
* @param dso
|
||||
* The DSpaceObject which we ask for metadata.
|
||||
* @param schema
|
||||
* the schema for the metadata field. <em>Must</em> match
|
||||
* the <code>name</code> of an existing metadata schema.
|
||||
* @param element
|
||||
* the element to match, or <code>Item.ANY</code>
|
||||
* @param qualifier
|
||||
* the qualifier to match, or <code>Item.ANY</code>
|
||||
* @param language
|
||||
* the language to match, or <code>Item.ANY</code>
|
||||
*
|
||||
* @param dso The DSpaceObject which we ask for metadata.
|
||||
* @param schema the schema for the metadata field. <em>Must</em> match
|
||||
* the <code>name</code> of an existing metadata schema.
|
||||
* @param element the element to match, or <code>Item.ANY</code>
|
||||
* @param qualifier the qualifier to match, or <code>Item.ANY</code>
|
||||
* @param language the language to match, or <code>Item.ANY</code>
|
||||
* @return the first metadata field value
|
||||
*/
|
||||
@Override
|
||||
public String getMetadataFirstValue(T dso, String schema, String element, String qualifier, String language){
|
||||
public String getMetadataFirstValue(T dso, String schema, String element, String qualifier, String language) {
|
||||
List<MetadataValue> metadataValues = getMetadata(dso, schema, element, qualifier, language);
|
||||
if(CollectionUtils.isNotEmpty(metadataValues)){
|
||||
if (CollectionUtils.isNotEmpty(metadataValues)) {
|
||||
return metadataValues.iterator().next().getValue();
|
||||
}
|
||||
return null;
|
||||
@@ -397,12 +391,13 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
|
||||
/**
|
||||
* Set first metadata field value
|
||||
*
|
||||
* @throws SQLException if database error
|
||||
*/
|
||||
@Override
|
||||
public void setMetadataSingleValue(Context context, T dso, String schema, String element, String qualifier, String language, String value) throws SQLException {
|
||||
if(value != null)
|
||||
{
|
||||
public void setMetadataSingleValue(Context context, T dso, String schema, String element, String qualifier,
|
||||
String language, String value) throws SQLException {
|
||||
if (value != null) {
|
||||
clearMetadata(context, dso, schema, element, qualifier, language);
|
||||
addMetadata(context, dso, schema, element, qualifier, language, value);
|
||||
dso.setMetadataModified();
|
||||
@@ -417,72 +412,53 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
* in. Any or all of the element, qualifier and language passed
|
||||
* in can be the <code>Item.ANY</code> wildcard.
|
||||
*
|
||||
* @param schema
|
||||
* the schema for the metadata field. <em>Must</em> match
|
||||
* the <code>name</code> of an existing metadata schema.
|
||||
* @param element
|
||||
* the element to match, or <code>Item.ANY</code>
|
||||
* @param qualifier
|
||||
* the qualifier to match, or <code>Item.ANY</code>
|
||||
* @param language
|
||||
* the language to match, or <code>Item.ANY</code>
|
||||
* @param metadataValue
|
||||
* the Dublin Core value
|
||||
* @param schema the schema for the metadata field. <em>Must</em> match
|
||||
* the <code>name</code> of an existing metadata schema.
|
||||
* @param element the element to match, or <code>Item.ANY</code>
|
||||
* @param qualifier the qualifier to match, or <code>Item.ANY</code>
|
||||
* @param language the language to match, or <code>Item.ANY</code>
|
||||
* @param metadataValue the Dublin Core value
|
||||
* @return <code>true</code> if there is a match
|
||||
*/
|
||||
protected boolean match(String schema, String element, String qualifier,
|
||||
String language, MetadataValue metadataValue)
|
||||
{
|
||||
String language, MetadataValue metadataValue) {
|
||||
|
||||
MetadataField metadataField = metadataValue.getMetadataField();
|
||||
MetadataSchema metadataSchema = metadataField.getMetadataSchema();
|
||||
// We will attempt to disprove a match - if we can't we have a match
|
||||
if (!element.equals(Item.ANY) && !element.equals(metadataField.getElement()))
|
||||
{
|
||||
if (!element.equals(Item.ANY) && !element.equals(metadataField.getElement())) {
|
||||
// Elements do not match, no wildcard
|
||||
return false;
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(qualifier))
|
||||
{
|
||||
if (StringUtils.isBlank(qualifier)) {
|
||||
// Value must be unqualified
|
||||
if (metadataField.getQualifier() != null)
|
||||
{
|
||||
if (metadataField.getQualifier() != null) {
|
||||
// Value is qualified, so no match
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!qualifier.equals(Item.ANY))
|
||||
{
|
||||
} else if (!qualifier.equals(Item.ANY)) {
|
||||
// Not a wildcard, so qualifier must match exactly
|
||||
if (!qualifier.equals(metadataField.getQualifier()))
|
||||
{
|
||||
if (!qualifier.equals(metadataField.getQualifier())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (language == null)
|
||||
{
|
||||
if (language == null) {
|
||||
// Value must be null language to match
|
||||
if (metadataValue.getLanguage() != null)
|
||||
{
|
||||
if (metadataValue.getLanguage() != null) {
|
||||
// Value is qualified, so no match
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!language.equals(Item.ANY))
|
||||
{
|
||||
} else if (!language.equals(Item.ANY)) {
|
||||
// Not a wildcard, so language must match exactly
|
||||
if (!language.equals(metadataValue.getLanguage()))
|
||||
{
|
||||
if (!language.equals(metadataValue.getLanguage())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!schema.equals(Item.ANY))
|
||||
{
|
||||
if (metadataSchema != null && !metadataSchema.getName().equals(schema))
|
||||
{
|
||||
if (!schema.equals(Item.ANY)) {
|
||||
if (metadataSchema != null && !metadataSchema.getName().equals(schema)) {
|
||||
// The namespace doesn't match
|
||||
return false;
|
||||
}
|
||||
@@ -492,7 +468,8 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void getAuthoritiesAndConfidences(String fieldKey, Collection collection, List<String> values, List<String> authorities, List<Integer> confidences, int i) {
|
||||
protected void getAuthoritiesAndConfidences(String fieldKey, Collection collection, List<String> values,
|
||||
List<String> authorities, List<Integer> confidences, int i) {
|
||||
Choices c = choiceAuthorityService.getBestMatch(fieldKey, values.get(i), collection, null);
|
||||
authorities.add(c.values.length > 0 ? c.values[0].authority : null);
|
||||
confidences.add(c.confidence);
|
||||
@@ -505,6 +482,7 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
* The returned array will always have length greater than or equal to 4
|
||||
* <p>
|
||||
* Values in the returned array can be empty or null.
|
||||
*
|
||||
* @param fieldName field name
|
||||
* @return array
|
||||
*/
|
||||
@@ -525,6 +503,7 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
* The returned array will always have length greater than or equal to 4
|
||||
* <p>
|
||||
* When @param fill is true, elements that would be empty or null are replaced by Item.ANY
|
||||
*
|
||||
* @param fieldName field name
|
||||
* @return array
|
||||
*/
|
||||
@@ -538,185 +517,188 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
|
||||
return elements;
|
||||
}
|
||||
|
||||
protected String[] getMDValueByField(String field){
|
||||
protected String[] getMDValueByField(String field) {
|
||||
StringTokenizer dcf = new StringTokenizer(field, ".");
|
||||
|
||||
String[] tokens = { "", "", "" };
|
||||
String[] tokens = {"", "", ""};
|
||||
int i = 0;
|
||||
while(dcf.hasMoreTokens()){
|
||||
while (dcf.hasMoreTokens()) {
|
||||
tokens[i] = dcf.nextToken().trim();
|
||||
i++;
|
||||
}
|
||||
|
||||
if(i!=0){
|
||||
if (i != 0) {
|
||||
return tokens;
|
||||
}else{
|
||||
} else {
|
||||
return getMDValueByLegacyField(field);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Context context, T dso) throws SQLException, AuthorizeException
|
||||
{
|
||||
if(dso.isMetadataModified())
|
||||
{
|
||||
public void update(Context context, T dso) throws SQLException, AuthorizeException {
|
||||
if (dso.isMetadataModified()) {
|
||||
/*
|
||||
Update the order of the metadata values
|
||||
*/
|
||||
// A map created to store the latest place for each metadata field
|
||||
Map<MetadataField, Integer> fieldToLastPlace = new HashMap<>();
|
||||
List<MetadataValue> metadataValues = dso.getMetadata();
|
||||
for (MetadataValue metadataValue : metadataValues)
|
||||
{
|
||||
//Retrieve & store the place for each metadata value
|
||||
int mvPlace = getMetadataValuePlace(fieldToLastPlace, metadataValue);
|
||||
metadataValue.setPlace(mvPlace);
|
||||
}
|
||||
// A map created to store the latest place for each metadata field
|
||||
Map<MetadataField, Integer> fieldToLastPlace = new HashMap<>();
|
||||
List<MetadataValue> metadataValues = dso.getMetadata();
|
||||
for (MetadataValue metadataValue : metadataValues) {
|
||||
//Retrieve & store the place for each metadata value
|
||||
int mvPlace = getMetadataValuePlace(fieldToLastPlace, metadataValue);
|
||||
metadataValue.setPlace(mvPlace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the place of the metadata value
|
||||
*
|
||||
* @param fieldToLastPlace the map containing the latest place of each metadata field
|
||||
* @param metadataValue the metadata value that needs to get a place
|
||||
* @param metadataValue the metadata value that needs to get a place
|
||||
* @return The new place for the metadata valu
|
||||
*/
|
||||
protected int getMetadataValuePlace(Map<MetadataField, Integer> fieldToLastPlace, MetadataValue metadataValue) {
|
||||
MetadataField metadataField = metadataValue.getMetadataField();
|
||||
if(fieldToLastPlace.containsKey(metadataField))
|
||||
{
|
||||
if (fieldToLastPlace.containsKey(metadataField)) {
|
||||
fieldToLastPlace.put(metadataField, fieldToLastPlace.get(metadataField) + 1);
|
||||
}else{
|
||||
} else {
|
||||
// The metadata value place starts at 0
|
||||
fieldToLastPlace.put(metadataField, 0);
|
||||
}
|
||||
return fieldToLastPlace.get(metadataField);
|
||||
}
|
||||
|
||||
protected String[] getMDValueByLegacyField(String field){
|
||||
protected String[] getMDValueByLegacyField(String field) {
|
||||
switch (field) {
|
||||
case "introductory_text":
|
||||
return new String[]{MetadataSchema.DC_SCHEMA, "description", null};
|
||||
return new String[] {MetadataSchema.DC_SCHEMA, "description", null};
|
||||
case "short_description":
|
||||
return new String[]{MetadataSchema.DC_SCHEMA, "description", "abstract"};
|
||||
return new String[] {MetadataSchema.DC_SCHEMA, "description", "abstract"};
|
||||
case "side_bar_text":
|
||||
return new String[]{MetadataSchema.DC_SCHEMA, "description", "tableofcontents"};
|
||||
return new String[] {MetadataSchema.DC_SCHEMA, "description", "tableofcontents"};
|
||||
case "copyright_text":
|
||||
return new String[]{MetadataSchema.DC_SCHEMA, "rights", null};
|
||||
return new String[] {MetadataSchema.DC_SCHEMA, "rights", null};
|
||||
case "name":
|
||||
return new String[]{MetadataSchema.DC_SCHEMA, "title", null};
|
||||
return new String[] {MetadataSchema.DC_SCHEMA, "title", null};
|
||||
case "provenance_description":
|
||||
return new String[]{MetadataSchema.DC_SCHEMA,"provenance", null};
|
||||
return new String[] {MetadataSchema.DC_SCHEMA, "provenance", null};
|
||||
case "license":
|
||||
return new String[]{MetadataSchema.DC_SCHEMA, "rights", "license"};
|
||||
return new String[] {MetadataSchema.DC_SCHEMA, "rights", "license"};
|
||||
case "user_format_description":
|
||||
return new String[]{MetadataSchema.DC_SCHEMA,"format",null};
|
||||
return new String[] {MetadataSchema.DC_SCHEMA, "format", null};
|
||||
case "source":
|
||||
return new String[]{MetadataSchema.DC_SCHEMA,"source",null};
|
||||
return new String[] {MetadataSchema.DC_SCHEMA, "source", null};
|
||||
case "firstname":
|
||||
return new String[]{"eperson","firstname",null};
|
||||
return new String[] {"eperson", "firstname", null};
|
||||
case "lastname":
|
||||
return new String[]{"eperson","lastname",null};
|
||||
return new String[] {"eperson", "lastname", null};
|
||||
case "phone":
|
||||
return new String[]{"eperson","phone",null};
|
||||
return new String[] {"eperson", "phone", null};
|
||||
case "language":
|
||||
return new String[]{"eperson","language",null};
|
||||
return new String[] {"eperson", "language", null};
|
||||
default:
|
||||
return new String[]{null, null, null};
|
||||
return new String[] {null, null, null};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addAndShiftRightMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, String value, String authority, int confidence, int index) throws SQLException {
|
||||
public void addAndShiftRightMetadata(Context context, T dso, String schema, String element, String qualifier,
|
||||
String lang, String value, String authority, int confidence, int index)
|
||||
throws SQLException {
|
||||
|
||||
List<MetadataValue> list = getMetadata(dso, schema, element, qualifier);
|
||||
|
||||
clearMetadata(context, dso, schema, element, qualifier, Item.ANY);
|
||||
List<MetadataValue> list = getMetadata(dso, schema, element, qualifier);
|
||||
|
||||
int idx = 0;
|
||||
boolean last = true;
|
||||
for(MetadataValue rr : list) {
|
||||
if(idx==index) {
|
||||
addMetadata(context, dso, schema, element, qualifier,
|
||||
lang, value, authority, confidence);
|
||||
last = false;
|
||||
}
|
||||
addMetadata(context, dso, schema, element, qualifier,
|
||||
rr.getLanguage(), rr.getValue(), rr.getAuthority(), rr.getConfidence());
|
||||
idx++;
|
||||
}
|
||||
if(last) {
|
||||
addMetadata(context, dso, schema, element, qualifier,
|
||||
lang, value, authority, confidence);
|
||||
}
|
||||
clearMetadata(context, dso, schema, element, qualifier, Item.ANY);
|
||||
|
||||
int idx = 0;
|
||||
boolean last = true;
|
||||
for (MetadataValue rr : list) {
|
||||
if (idx == index) {
|
||||
addMetadata(context, dso, schema, element, qualifier,
|
||||
lang, value, authority, confidence);
|
||||
last = false;
|
||||
}
|
||||
addMetadata(context, dso, schema, element, qualifier,
|
||||
rr.getLanguage(), rr.getValue(), rr.getAuthority(), rr.getConfidence());
|
||||
idx++;
|
||||
}
|
||||
if (last) {
|
||||
addMetadata(context, dso, schema, element, qualifier,
|
||||
lang, value, authority, confidence);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveMetadata(Context context, T dso, String schema, String element, String qualifier, int from, int to)
|
||||
throws SQLException, IllegalArgumentException {
|
||||
|
||||
if(from==to) {
|
||||
throw new IllegalArgumentException("The \"from\" location MUST be different from \"to\" location");
|
||||
}
|
||||
|
||||
List<MetadataValue> list = getMetadata(dso, schema, element, qualifier);
|
||||
|
||||
if(from>=list.size()) {
|
||||
throw new IllegalArgumentException("The \"from\" location MUST exist for the operation to be successful. Idx:" + from);
|
||||
}
|
||||
|
||||
clearMetadata(context, dso, schema, element, qualifier, Item.ANY);
|
||||
|
||||
int idx = 0;
|
||||
MetadataValue moved = null;
|
||||
for (MetadataValue md : list) {
|
||||
if (idx == from) {
|
||||
moved = md;
|
||||
break;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
||||
idx = 0;
|
||||
boolean last = true;
|
||||
for (MetadataValue rr : list) {
|
||||
if (idx == to && to<from) {
|
||||
addMetadata(context, dso, schema, element, qualifier, moved.getLanguage(), moved.getValue(), moved.getAuthority(), moved.getConfidence());
|
||||
last = false;
|
||||
}
|
||||
if (idx != from) {
|
||||
addMetadata(context, dso, schema, element, qualifier, rr.getLanguage(), rr.getValue(),
|
||||
rr.getAuthority(), rr.getConfidence());
|
||||
}
|
||||
if (idx == to && to>from) {
|
||||
addMetadata(context, dso, schema, element, qualifier, moved.getLanguage(), moved.getValue(), moved.getAuthority(), moved.getConfidence());
|
||||
last = false;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
if (last) {
|
||||
addMetadata(context, dso, schema, element, qualifier, moved.getLanguage(), moved.getValue(), moved.getAuthority(), moved.getConfidence());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceMetadata(Context context, T dso, String schema, String element, String qualifier, String lang, String value, String authority, int confidence, int index) throws SQLException {
|
||||
public void moveMetadata(Context context, T dso, String schema, String element, String qualifier, int from, int to)
|
||||
throws SQLException, IllegalArgumentException {
|
||||
|
||||
List<MetadataValue> list = getMetadata(dso, schema, element, qualifier);
|
||||
|
||||
clearMetadata(context, dso, schema, element, qualifier, Item.ANY);
|
||||
if (from == to) {
|
||||
throw new IllegalArgumentException("The \"from\" location MUST be different from \"to\" location");
|
||||
}
|
||||
|
||||
int idx = 0;
|
||||
for(MetadataValue rr : list) {
|
||||
if(idx==index) {
|
||||
addMetadata(context, dso, schema, element, qualifier,
|
||||
lang, value, authority, confidence);
|
||||
}
|
||||
else {
|
||||
addMetadata(context, dso, schema, element, qualifier,
|
||||
rr.getLanguage(), rr.getValue(), rr.getAuthority(), rr.getConfidence());
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
List<MetadataValue> list = getMetadata(dso, schema, element, qualifier);
|
||||
|
||||
if (from >= list.size()) {
|
||||
throw new IllegalArgumentException(
|
||||
"The \"from\" location MUST exist for the operation to be successful. Idx:" + from);
|
||||
}
|
||||
|
||||
clearMetadata(context, dso, schema, element, qualifier, Item.ANY);
|
||||
|
||||
int idx = 0;
|
||||
MetadataValue moved = null;
|
||||
for (MetadataValue md : list) {
|
||||
if (idx == from) {
|
||||
moved = md;
|
||||
break;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
||||
idx = 0;
|
||||
boolean last = true;
|
||||
for (MetadataValue rr : list) {
|
||||
if (idx == to && to < from) {
|
||||
addMetadata(context, dso, schema, element, qualifier, moved.getLanguage(), moved.getValue(),
|
||||
moved.getAuthority(), moved.getConfidence());
|
||||
last = false;
|
||||
}
|
||||
if (idx != from) {
|
||||
addMetadata(context, dso, schema, element, qualifier, rr.getLanguage(), rr.getValue(),
|
||||
rr.getAuthority(), rr.getConfidence());
|
||||
}
|
||||
if (idx == to && to > from) {
|
||||
addMetadata(context, dso, schema, element, qualifier, moved.getLanguage(), moved.getValue(),
|
||||
moved.getAuthority(), moved.getConfidence());
|
||||
last = false;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
if (last) {
|
||||
addMetadata(context, dso, schema, element, qualifier, moved.getLanguage(), moved.getValue(),
|
||||
moved.getAuthority(), moved.getConfidence());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceMetadata(Context context, T dso, String schema, String element, String qualifier, String lang,
|
||||
String value, String authority, int confidence, int index) throws SQLException {
|
||||
|
||||
List<MetadataValue> list = getMetadata(dso, schema, element, qualifier);
|
||||
|
||||
clearMetadata(context, dso, schema, element, qualifier, Item.ANY);
|
||||
|
||||
int idx = 0;
|
||||
for (MetadataValue rr : list) {
|
||||
if (idx == index) {
|
||||
addMetadata(context, dso, schema, element, qualifier,
|
||||
lang, value, authority, confidence);
|
||||
} else {
|
||||
addMetadata(context, dso, schema, element, qualifier,
|
||||
rr.getLanguage(), rr.getValue(), rr.getAuthority(), rr.getConfidence());
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user