D4CRIS-416 refactoring to accept "from" attribute from operation; introduce constants to discriminate patch operation implementation; finalize move operation for metadata;

This commit is contained in:
Luigi Andrea Pascarelli
2017-12-12 15:19:57 +01:00
parent e8a17a0aac
commit 2e215bfd17
30 changed files with 161 additions and 110 deletions

View File

@@ -645,4 +645,52 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
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, Item.ANY);
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());
}
}
}