mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
D4CRIS-416 first implementation to respect rest contract
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest.submit.factory.impl;
|
||||
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.LicenseUtils;
|
||||
import org.dspace.content.WorkspaceItem;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.services.model.Request;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Submission "add" PATCH operation
|
||||
*
|
||||
* To accept a license the timestamp of the acceptance the client must send a
|
||||
* JSON Patch ADD operation as follow.
|
||||
*
|
||||
* Example: <code>
|
||||
* curl -X PATCH http://${dspace.url}/api/submission/workspaceitems/<:id-workspaceitem> -H "
|
||||
* Content-Type: application/json" -d '[{ "op": "add", "path": "
|
||||
* /sections/license/acceptanceDate", "value": "2017-11-20T10:32:42Z"}]'
|
||||
* </code>
|
||||
*
|
||||
* Please note that according to the JSON Patch specification RFC6902 a
|
||||
* subsequent add operation on the acceptanceDate will have the effect to
|
||||
* replace the previous granted license with a new one.
|
||||
*
|
||||
*
|
||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||
*
|
||||
*/
|
||||
public class LicenseAddPatchOperation extends AddPatchOperation<String> {
|
||||
|
||||
@Autowired
|
||||
ItemService itemService;
|
||||
|
||||
@Override
|
||||
protected Class<String[]> getArrayClassForEvaluation() {
|
||||
return String[].class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<String> getClassForEvaluation() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
void add(Context context, Request currentRequest, WorkspaceItem source, String string, Object value)
|
||||
throws Exception {
|
||||
Item item = source.getItem();
|
||||
EPerson submitter = context.getCurrentUser();
|
||||
|
||||
// remove any existing DSpace license (just in case the user
|
||||
// accepted it previously)
|
||||
itemService.removeDSpaceLicense(context, item);
|
||||
|
||||
String license = LicenseUtils.getLicenseText(context.getCurrentLocale(), source.getCollection(), item,
|
||||
submitter);
|
||||
|
||||
LicenseUtils.grantLicense(context, item, license, (String) value);
|
||||
}
|
||||
|
||||
}
|
@@ -15,7 +15,15 @@ import org.dspace.services.model.Request;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Submission License "remove" patch operation
|
||||
* Submission License "remove" patch operation.
|
||||
*
|
||||
* To remove a previous granted license:
|
||||
*
|
||||
* Example: <code>
|
||||
* curl -X PATCH http://${dspace.url}/api/submission/workspaceitems/<:id-workspaceitem> -H "
|
||||
* Content-Type: application/json" -d '[{ "op": "remove", "path": "
|
||||
* /sections/license/acceptanceDate"}]'
|
||||
* </code>
|
||||
*
|
||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||
*
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.app.rest.submit.factory.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.content.Bundle;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.LicenseUtils;
|
||||
import org.dspace.content.WorkspaceItem;
|
||||
@@ -15,10 +18,15 @@ import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.services.model.Request;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Submission "replace" patch operation
|
||||
*
|
||||
* The replace operation allows to replace existent information with new one.
|
||||
* Attempt to use the replace operation without a previous accepted license must
|
||||
* return an error.
|
||||
*
|
||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||
*
|
||||
*/
|
||||
@@ -26,10 +34,14 @@ public class LicenseReplacePatchOperation extends ReplacePatchOperation<String>
|
||||
|
||||
@Autowired
|
||||
ItemService itemService;
|
||||
|
||||
|
||||
@Override
|
||||
void replace(Context context, Request currentRequest, WorkspaceItem source, String string, Object value) throws Exception {
|
||||
void replace(Context context, Request currentRequest, WorkspaceItem source, String string, Object value)
|
||||
throws Exception {
|
||||
Item item = source.getItem();
|
||||
List<Bundle> bunds = itemService.getBundles(item, "LICENSE");
|
||||
Assert.notEmpty(bunds);
|
||||
|
||||
EPerson submitter = context.getCurrentUser();
|
||||
|
||||
// remove any existing DSpace license (just in case the user
|
||||
@@ -38,10 +50,9 @@ public class LicenseReplacePatchOperation extends ReplacePatchOperation<String>
|
||||
|
||||
String license = LicenseUtils.getLicenseText(context.getCurrentLocale(), source.getCollection(), item,
|
||||
submitter);
|
||||
|
||||
LicenseUtils.grantLicense(context, item, license, (String)value);
|
||||
}
|
||||
|
||||
LicenseUtils.grantLicense(context, item, license, (String) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<String[]> getArrayClassForEvaluation() {
|
||||
@@ -53,5 +64,4 @@ public class LicenseReplacePatchOperation extends ReplacePatchOperation<String>
|
||||
return String.class;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user