DS-4389 improving patch system framework - Minor feedback changes PR 2591

This commit is contained in:
Marie Verdonck
2019-12-10 17:40:15 +01:00
parent b781ae5560
commit ce2662c58d
14 changed files with 32 additions and 38 deletions

View File

@@ -91,7 +91,6 @@ public class MetadataFieldServiceImpl implements MetadataFieldService {
return metadataFieldDAO.findByElement(context, metadataSchema, element, qualifier); return metadataFieldDAO.findByElement(context, metadataSchema, element, qualifier);
} }
@Override @Override
public MetadataField findByElement(Context context, String metadataSchemaName, String element, String qualifier) public MetadataField findByElement(Context context, String metadataSchemaName, String element, String qualifier)
throws SQLException { throws SQLException {
@@ -107,8 +106,7 @@ public class MetadataFieldServiceImpl implements MetadataFieldService {
if (schema == null || element == null) { if (schema == null || element == null) {
return null; return null;
} else { } else {
MetadataSchema metadataSchema = metadataSchemaService.find(context, schema); return this.findByElement(context, schema, element, qualifier);
return this.findByElement(context, metadataSchema, element, qualifier);
} }
} }

View File

@@ -182,7 +182,7 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
/** /**
* Add metadata fields. These are appended to existing values. * Add metadata fields. These are appended to existing values.
* Use <code>clearDC</code> to remove values. The ordering of values * Use <code>clearMetadata</code> to remove values. The ordering of values
* passed in is maintained. * passed in is maintained.
* <p> * <p>
* If metadata authority control is available, try to get authority * If metadata authority control is available, try to get authority
@@ -207,7 +207,7 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
/** /**
* Add metadata fields. These are appended to existing values. * Add metadata fields. These are appended to existing values.
* Use <code>clearDC</code> to remove values. The ordering of values * Use <code>clearMetadata</code> to remove values. The ordering of values
* passed in is maintained. * passed in is maintained.
* *
* @param context DSpace context * @param context DSpace context
@@ -231,7 +231,7 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
/** /**
* Add metadata fields. These are appended to existing values. * Add metadata fields. These are appended to existing values.
* Use <code>clearDC</code> to remove values. The ordering of values * Use <code>clearMetadata</code> to remove values. The ordering of values
* passed in is maintained. * passed in is maintained.
* *
* @param context DSpace context * @param context DSpace context
@@ -272,7 +272,7 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
/** /**
* Add a single metadata field. This is appended to existing * Add a single metadata field. This is appended to existing
* values. Use <code>clearDC</code> to remove values. * values. Use <code>clearMetadata</code> to remove values.
* *
* @param context DSpace context * @param context DSpace context
* @param dso DSpaceObject * @param dso DSpaceObject
@@ -292,7 +292,7 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
/** /**
* Add a single metadata field. This is appended to existing * Add a single metadata field. This is appended to existing
* values. Use <code>clearDC</code> to remove values. * values. Use <code>clearMetadata</code> to remove values.
* *
* @param context DSpace context * @param context DSpace context
* @param dso DSpaceObject * @param dso DSpaceObject
@@ -314,10 +314,10 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
/** /**
* Clear metadata values. As with <code>getDC</code> above, * Clear metadata values. As with <code>getDC</code> above,
* passing in <code>null</code> only matches fields where the qualifier or * passing in <code>null</code> only matches fields where the qualifier orr
* language is actually <code>null</code>.<code>Item.ANY</code> will * language is actually <code>null</code>.<code>Item.ANY</code> will
* match any element, qualifier or language, including <code>null</code>. * match any element, qualifier or language, including <code>null</code>.
* Thus, <code>dspaceobject.clearDC(Item.ANY, Item.ANY, Item.ANY)</code> will * Thus, <code>dspaceobject.clearMetadata(Item.ANY, Item.ANY, Item.ANY)</code> will
* remove all Dublin Core metadata associated with an DSpaceObject. * remove all Dublin Core metadata associated with an DSpaceObject.
* *
* @param context DSpace context * @param context DSpace context
@@ -372,7 +372,7 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
/** /**
* Add a single metadata field. Whether it's appended or prepended depends on index parameter. * Add a single metadata field. Whether it's appended or prepended depends on index parameter.
* Use <code>clearDC</code> to remove values. * Use <code>clearMetadata</code> to remove values.
* *
* @param context DSpace context * @param context DSpace context
* @param dso DSpaceObject * @param dso DSpaceObject

View File

@@ -46,7 +46,7 @@ public class ResourcePatch<M extends DSpaceObject> {
/** /**
* Checks with all possible patch operations whether they support this operation * Checks with all possible patch operations whether they support this operation
* (based on instanceof restModel and operation.path * (based on instanceof dso and operation.path)
* @param context Context of patch operation * @param context Context of patch operation
* @param dso the dso resource to patch * @param dso the dso resource to patch
* @param operation the patch operation * @param operation the patch operation

View File

@@ -36,7 +36,7 @@ public class BundleMoveOperation extends PatchOperation<Bundle> {
BundleService bundleService; BundleService bundleService;
@Autowired @Autowired
DspaceObjectMetadataPatchUtils dspaceObjectMetadataPatchUtils; DSpaceObjectMetadataPatchUtils dspaceObjectMetadataPatchUtils;
private static final String OPERATION_PATH_BUNDLE_MOVE = "/_links/bitstreams/"; private static final String OPERATION_PATH_BUNDLE_MOVE = "/_links/bitstreams/";

View File

@@ -32,10 +32,10 @@ import org.springframework.stereotype.Component;
* @author Maria Verdonck (Atmire) on 18/11/2019 * @author Maria Verdonck (Atmire) on 18/11/2019
*/ */
@Component @Component
public class DspaceObjectMetadataAddOperation<R extends DSpaceObject> extends PatchOperation<R> { public class DSpaceObjectMetadataAddOperation<R extends DSpaceObject> extends PatchOperation<R> {
@Autowired @Autowired
DspaceObjectMetadataPatchUtils metadataPatchUtils; DSpaceObjectMetadataPatchUtils metadataPatchUtils;
@Override @Override
public R perform(Context context, R resource, Operation operation) throws SQLException { public R perform(Context context, R resource, Operation operation) throws SQLException {

View File

@@ -39,10 +39,10 @@ import org.springframework.stereotype.Component;
* @author Maria Verdonck (Atmire) on 18/11/2019 * @author Maria Verdonck (Atmire) on 18/11/2019
*/ */
@Component @Component
public class DspaceObjectMetadataCopyOperation<R extends DSpaceObject> extends PatchOperation<R> { public class DSpaceObjectMetadataCopyOperation<R extends DSpaceObject> extends PatchOperation<R> {
@Autowired @Autowired
DspaceObjectMetadataPatchUtils metadataPatchUtils; DSpaceObjectMetadataPatchUtils metadataPatchUtils;
@Override @Override
public R perform(Context context, R resource, Operation operation) throws SQLException { public R perform(Context context, R resource, Operation operation) throws SQLException {
@@ -85,7 +85,7 @@ public class DspaceObjectMetadataCopyOperation<R extends DSpaceObject> extends P
throw new UnprocessableEntityException("There is no metadata of this type at that index"); throw new UnprocessableEntityException("There is no metadata of this type at that index");
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new IllegalArgumentException("This index (" + indexToCopyFrom + ") is not valid nr", e); throw new IllegalArgumentException("This index (" + indexToCopyFrom + ") is not valid number.", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new DSpaceBadRequestException("SQLException in DspaceObjectMetadataCopyOperation.copy trying to " + throw new DSpaceBadRequestException("SQLException in DspaceObjectMetadataCopyOperation.copy trying to " +
"add metadata to dso.", e); "add metadata to dso.", e);

View File

@@ -35,10 +35,10 @@ import org.springframework.stereotype.Component;
* @author Maria Verdonck (Atmire) on 18/11/2019 * @author Maria Verdonck (Atmire) on 18/11/2019
*/ */
@Component @Component
public class DspaceObjectMetadataMoveOperation<R extends DSpaceObject> extends PatchOperation<R> { public class DSpaceObjectMetadataMoveOperation<R extends DSpaceObject> extends PatchOperation<R> {
@Autowired @Autowired
DspaceObjectMetadataPatchUtils metadataPatchUtils; DSpaceObjectMetadataPatchUtils metadataPatchUtils;
@Override @Override
public R perform(Context context, R resource, Operation operation) throws SQLException { public R perform(Context context, R resource, Operation operation) throws SQLException {

View File

@@ -29,7 +29,7 @@ import org.springframework.stereotype.Component;
* @author Maria Verdonck (Atmire) on 18/11/2019 * @author Maria Verdonck (Atmire) on 18/11/2019
*/ */
@Component @Component
public final class DspaceObjectMetadataPatchUtils { public final class DSpaceObjectMetadataPatchUtils {
private ObjectMapper objectMapper = new ObjectMapper(); private ObjectMapper objectMapper = new ObjectMapper();
@@ -41,7 +41,7 @@ public final class DspaceObjectMetadataPatchUtils {
*/ */
protected static final String METADATA_PATH = "/metadata"; protected static final String METADATA_PATH = "/metadata";
private DspaceObjectMetadataPatchUtils() { private DSpaceObjectMetadataPatchUtils() {
} }
/** /**
@@ -149,8 +149,7 @@ public final class DspaceObjectMetadataPatchUtils {
protected String getIndexFromPath(String path) { protected String getIndexFromPath(String path) {
String[] partsOfPath = path.split("/"); String[] partsOfPath = path.split("/");
// Index of md being patched // Index of md being patched
String indexInPath = (partsOfPath.length > 3) ? partsOfPath[3] : null; return (partsOfPath.length > 3) ? partsOfPath[3] : null;
return indexInPath;
} }
protected void checkMetadataFieldNotNull(MetadataField metadataField) { protected void checkMetadataFieldNotNull(MetadataField metadataField) {

View File

@@ -39,10 +39,10 @@ import org.springframework.stereotype.Component;
* @author Maria Verdonck (Atmire) on 18/11/2019 * @author Maria Verdonck (Atmire) on 18/11/2019
*/ */
@Component @Component
public class DspaceObjectMetadataRemoveOperation<R extends DSpaceObject> extends PatchOperation<R> { public class DSpaceObjectMetadataRemoveOperation<R extends DSpaceObject> extends PatchOperation<R> {
@Autowired @Autowired
DspaceObjectMetadataPatchUtils metadataPatchUtils; DSpaceObjectMetadataPatchUtils metadataPatchUtils;
@Override @Override
public R perform(Context context, R resource, Operation operation) throws SQLException { public R perform(Context context, R resource, Operation operation) throws SQLException {
@@ -88,7 +88,7 @@ public class DspaceObjectMetadataRemoveOperation<R extends DSpaceObject> extends
} }
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new IllegalArgumentException("This index (" + index + ") is not valid nr", e); throw new IllegalArgumentException("This index (" + index + ") is not valid number.", e);
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
throw new UnprocessableEntityException("There is no metadata of this type at that index"); throw new UnprocessableEntityException("There is no metadata of this type at that index");
} catch (SQLException e) { } catch (SQLException e) {

View File

@@ -37,10 +37,10 @@ import org.springframework.stereotype.Component;
* @author Maria Verdonck (Atmire) on 18/11/2019 * @author Maria Verdonck (Atmire) on 18/11/2019
*/ */
@Component @Component
public class DspaceObjectMetadataReplaceOperation<R extends DSpaceObject> extends PatchOperation<R> { public class DSpaceObjectMetadataReplaceOperation<R extends DSpaceObject> extends PatchOperation<R> {
@Autowired @Autowired
DspaceObjectMetadataPatchUtils metadataPatchUtils; DSpaceObjectMetadataPatchUtils metadataPatchUtils;
@Override @Override
public R perform(Context context, R resource, Operation operation) throws SQLException { public R perform(Context context, R resource, Operation operation) throws SQLException {
@@ -166,7 +166,7 @@ public class DspaceObjectMetadataReplaceOperation<R extends DSpaceObject> extend
throw new UnprocessableEntityException("There is no metadata of this type at that index"); throw new UnprocessableEntityException("There is no metadata of this type at that index");
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new IllegalArgumentException("This index (" + index + ") is not valid nr", e); throw new IllegalArgumentException("This index (" + index + ") is not valid number.", e);
} }
} }

View File

@@ -15,7 +15,7 @@ import org.dspace.core.Context;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* This is the implementation for Item resource patches. * This is the implementation for Item 'discoverable' patches.
* *
* Example: <code> * Example: <code>
* curl -X PATCH http://${dspace.url}/api/core/items/<:id-item> -H " * curl -X PATCH http://${dspace.url}/api/core/items/<:id-item> -H "
@@ -37,10 +37,8 @@ public class ItemDiscoverableReplaceOperation<R> extends PatchOperation<R> {
Boolean discoverable = getBooleanOperationValue(operation.getValue()); Boolean discoverable = getBooleanOperationValue(operation.getValue());
if (supports(object, operation)) { if (supports(object, operation)) {
Item item = (Item) object; Item item = (Item) object;
if (discoverable) { if (discoverable && item.getTemplateItemOf() != null) {
if (item.getTemplateItemOf() != null) { throw new UnprocessableEntityException("A template item cannot be discoverable.");
throw new UnprocessableEntityException("A template item cannot be discoverable.");
}
} }
item.setDiscoverable(discoverable); item.setDiscoverable(discoverable);
return object; return object;

View File

@@ -21,7 +21,7 @@ import org.dspace.core.Context;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* This is the implementation for Item resource patches. * This is the implementation for Item 'withdrawn' patches.
* <p> * <p>
* Example: <code> * Example: <code>
* curl -X PATCH http://${dspace.url}/api/core/items/<:id-item> -H " * curl -X PATCH http://${dspace.url}/api/core/items/<:id-item> -H "

View File

@@ -71,7 +71,7 @@ public abstract class PatchOperation<M> {
} }
/** /**
* Determines whether or not this Patch Operation can do this patch (RestModel and path gets checked) * Determines whether or not this Patch Operation can do this patch (Object of operation and path gets checked)
* @param objectToMatch Object whose class must be instance of type object * @param objectToMatch Object whose class must be instance of type object
* for which this PatchOperation was created * for which this PatchOperation was created
* @param operation Operation of the patch, should match this type of Patch Operation * @param operation Operation of the patch, should match this type of Patch Operation

View File

@@ -37,7 +37,6 @@ import org.springframework.stereotype.Component;
public class EPersonRestPermissionEvaluatorPlugin extends RestObjectPermissionEvaluatorPlugin { public class EPersonRestPermissionEvaluatorPlugin extends RestObjectPermissionEvaluatorPlugin {
private static final Logger log = LoggerFactory.getLogger(EPersonRestPermissionEvaluatorPlugin.class); private static final Logger log = LoggerFactory.getLogger(EPersonRestPermissionEvaluatorPlugin.class);
public static final String OPERATION_PASSWORD_CHANGE = "/password";
@Autowired @Autowired
AuthorizeService authorizeService; AuthorizeService authorizeService;