Merge pull request #10748 from DSpace/backport-10745-to-dspace-7_x

[Port dspace-7_x] Improve DSpaceObjectService string comparison tests
This commit is contained in:
Tim Donohue
2025-05-14 15:53:11 -05:00
committed by GitHub
2 changed files with 11 additions and 11 deletions

View File

@@ -187,11 +187,11 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
String authority) {
List<MetadataValue> metadata = getMetadata(dso, schema, element, qualifier, lang);
List<MetadataValue> result = new ArrayList<>(metadata);
if (!authority.equals(Item.ANY)) {
if (!Item.ANY.equals(authority)) {
Iterator<MetadataValue> iterator = result.iterator();
while (iterator.hasNext()) {
MetadataValue metadataValue = iterator.next();
if (!authority.equals(metadataValue.getAuthority())) {
if (!StringUtils.equals(authority, metadataValue.getAuthority())) {
iterator.remove();
}
}
@@ -509,7 +509,7 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
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 (!Item.ANY.equals(element) && !StringUtils.equals(element, metadataField.getElement())) {
// Elements do not match, no wildcard
return false;
}
@@ -520,9 +520,9 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
// Value is qualified, so no match
return false;
}
} else if (!qualifier.equals(Item.ANY)) {
} else if (!Item.ANY.equals(qualifier)) {
// Not a wildcard, so qualifier must match exactly
if (!qualifier.equals(metadataField.getQualifier())) {
if (!StringUtils.equals(qualifier, metadataField.getQualifier())) {
return false;
}
}
@@ -533,15 +533,15 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
// Value is qualified, so no match
return false;
}
} else if (!language.equals(Item.ANY)) {
} else if (!Item.ANY.equals(language)) {
// Not a wildcard, so language must match exactly
if (!language.equals(metadataValue.getLanguage())) {
if (!StringUtils.equals(language, metadataValue.getLanguage())) {
return false;
}
}
if (!schema.equals(Item.ANY)) {
if (metadataSchema != null && !metadataSchema.getName().equals(schema)) {
if (!Item.ANY.equals(schema)) {
if (!StringUtils.equals(schema, metadataSchema.getName())) {
// The namespace doesn't match
return false;
}

View File

@@ -202,7 +202,7 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
* Get the value(s) of a metadata field.
* @param dSpaceObject the object whose metadata are sought.
* @param mdString the name of the field: {@code schema.element.qualifier}.
* @param authority name of the authority which controls these values, or null.
* @param authority name of the authority which controls these values, or Item.ANY, or null.
* @return all matching metadata values, or null if none.
*/
public List<MetadataValue> getMetadata(T dSpaceObject, String mdString, String authority);
@@ -216,7 +216,7 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
* @param lang the language of the requested field value(s),
* null if explicitly no language,
* or {@link org.dspace.content.Item.ANY} to match all languages.
* @param authority name of the authority which controls these values, or null.
* @param authority name of the authority which controls these values, or Item.ANY, or null.
* @return value(s) of the indicated field for the given DSO, or null.
*/
public List<MetadataValue> getMetadata(T dSpaceObject, String schema,