mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
D4CRIS-338 add implementation to grant license
This commit is contained in:
@@ -10,6 +10,7 @@ package org.dspace.content;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
@@ -437,4 +438,16 @@ public class Bitstream extends DSpaceObject implements DSpaceObjectLegacySupport
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add date for bitstream granted (used into the use case for license grant the {@link LicenseUtils#grantLicense(Context, Item, String, String)}
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* the dspace context
|
||||||
|
* @param acceptanceDate the granted date
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public void setAcceptanceDate(Context context, DCDate acceptanceDate) throws SQLException {
|
||||||
|
getBitstreamService().setMetadataSingleValue(context, this, MetadataSchema.DC_SCHEMA, "rights", "date", null, acceptanceDate.toString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@ package org.dspace.content;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Formatter;
|
import java.util.Formatter;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -133,12 +134,13 @@ public class LicenseUtils
|
|||||||
* the item object of the license
|
* the item object of the license
|
||||||
* @param licenseText
|
* @param licenseText
|
||||||
* the license the user granted
|
* the license the user granted
|
||||||
|
* @param acceptanceDate TODO
|
||||||
* @throws SQLException if database error
|
* @throws SQLException if database error
|
||||||
* @throws IOException if IO error
|
* @throws IOException if IO error
|
||||||
* @throws AuthorizeException if authorization error
|
* @throws AuthorizeException if authorization error
|
||||||
*/
|
*/
|
||||||
public static void grantLicense(Context context, Item item,
|
public static void grantLicense(Context context, Item item,
|
||||||
String licenseText) throws SQLException, IOException,
|
String licenseText, String acceptanceDate) throws SQLException, IOException,
|
||||||
AuthorizeException
|
AuthorizeException
|
||||||
{
|
{
|
||||||
// Put together text to store
|
// Put together text to store
|
||||||
@@ -154,7 +156,12 @@ public class LicenseUtils
|
|||||||
// Now set the format and name of the bitstream
|
// Now set the format and name of the bitstream
|
||||||
b.setName(context, "license.txt");
|
b.setName(context, "license.txt");
|
||||||
b.setSource(context, "Written by org.dspace.content.LicenseUtils");
|
b.setSource(context, "Written by org.dspace.content.LicenseUtils");
|
||||||
|
|
||||||
|
DCDate acceptanceDCDate = DCDate.getCurrent();
|
||||||
|
if(acceptanceDate!=null) {
|
||||||
|
acceptanceDCDate = new DCDate(acceptanceDate);
|
||||||
|
}
|
||||||
|
b.setAcceptanceDate(context, acceptanceDCDate);
|
||||||
// Find the License format
|
// Find the License format
|
||||||
BitstreamFormat bf = bitstreamFormat.findByShortDescription(context,
|
BitstreamFormat bf = bitstreamFormat.findByShortDescription(context,
|
||||||
"License");
|
"License");
|
||||||
|
@@ -233,7 +233,7 @@ public class LicenseUtilsTest extends AbstractUnitTest
|
|||||||
Item item = installItemService.installItem(context, workspaceItemService.create(context, collection, false));
|
Item item = installItemService.installItem(context, workspaceItemService.create(context, collection, false));
|
||||||
String defaultLicense = licenseService.getDefaultSubmissionLicense();
|
String defaultLicense = licenseService.getDefaultSubmissionLicense();
|
||||||
|
|
||||||
LicenseUtils.grantLicense(context, item, defaultLicense);
|
LicenseUtils.grantLicense(context, item, defaultLicense, null);
|
||||||
|
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
IOUtils.copy(bitstreamService.retrieve(context, itemService.getBundles(item, "LICENSE").get(0).getBitstreams().get(0)), writer);
|
IOUtils.copy(bitstreamService.retrieve(context, itemService.getBundles(item, "LICENSE").get(0).getBitstreams().get(0)), writer);
|
||||||
|
@@ -251,16 +251,16 @@ public class WorkspaceItemRestRepository extends DSpaceRestRepository<WorkspaceI
|
|||||||
if(path.length>4) {
|
if(path.length>4) {
|
||||||
index = path[4];
|
index = path[4];
|
||||||
}
|
}
|
||||||
String operation = op.getOp();
|
String operation = op.getOp();
|
||||||
LateObjectEvaluator value = (LateObjectEvaluator)op.getValue();
|
|
||||||
evaluatePatch(context, request, source, wsi, operation, section, target, index, value);
|
evaluatePatch(context, request, source, wsi, operation, section, target, index, op.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wis.update(context, source);
|
wis.update(context, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void evaluatePatch(Context context, HttpServletRequest request, WorkspaceItem source, WorkspaceItemRest wsi, String operation, String section, String target, String index,
|
private void evaluatePatch(Context context, HttpServletRequest request, WorkspaceItem source, WorkspaceItemRest wsi, String operation, String section, String target, String index,
|
||||||
LateObjectEvaluator value) throws Exception {
|
Object value) throws Exception {
|
||||||
SubmissionConfig submissionConfig = submissionConfigReader.getSubmissionConfigByName(wsi.getSubmissionDefinition().getName());
|
SubmissionConfig submissionConfig = submissionConfigReader.getSubmissionConfigByName(wsi.getSubmissionDefinition().getName());
|
||||||
for(int stepNum = 0; stepNum<submissionConfig.getNumberOfSteps(); stepNum++) {
|
for(int stepNum = 0; stepNum<submissionConfig.getNumberOfSteps(); stepNum++) {
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ public interface AbstractRestProcessingStep {
|
|||||||
public <T extends Serializable> T getData(WorkspaceItem obj, SubmissionStepConfig config) throws Exception;
|
public <T extends Serializable> T getData(WorkspaceItem obj, SubmissionStepConfig config) throws Exception;
|
||||||
|
|
||||||
public void doPatchProcessing(Context context, Request currentRequest, WorkspaceItem source, String operation,
|
public void doPatchProcessing(Context context, Request currentRequest, WorkspaceItem source, String operation,
|
||||||
String target, String index, LateObjectEvaluator value) throws Exception;
|
String target, String index, Object value) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -34,7 +34,7 @@ public class CollectionStep extends org.dspace.submit.step.SelectCollectionStep
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doPatchProcessing(Context context, Request currentRequest, WorkspaceItem source, String operation,
|
public void doPatchProcessing(Context context, Request currentRequest, WorkspaceItem source, String operation,
|
||||||
String target, String index, LateObjectEvaluator value) {
|
String target, String index, Object value) {
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case "move":
|
case "move":
|
||||||
|
|
||||||
|
@@ -79,10 +79,11 @@ public class DescribeStep extends org.dspace.submit.step.DescribeStep implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doPatchProcessing(Context context, Request currentRequest, WorkspaceItem source, String operation,
|
public void doPatchProcessing(Context context, Request currentRequest, WorkspaceItem source, String operation,
|
||||||
String target, String index, LateObjectEvaluator value) throws Exception {
|
String target, String index, Object value) throws Exception {
|
||||||
MetadataValueRest[] list = null;
|
MetadataValueRest[] list = null;
|
||||||
if(value!=null) {
|
if(value!=null) {
|
||||||
list = (MetadataValueRest[])value.evaluate(MetadataValueRest[].class);
|
LateObjectEvaluator object = (LateObjectEvaluator)value;
|
||||||
|
list = (MetadataValueRest[])object.evaluate(MetadataValueRest[].class);
|
||||||
}
|
}
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case "add":
|
case "add":
|
||||||
|
@@ -7,15 +7,23 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.app.rest.submit.step;
|
package org.dspace.app.rest.submit.step;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import org.atteo.evo.inflector.English;
|
import org.atteo.evo.inflector.English;
|
||||||
import org.dspace.app.rest.model.BitstreamRest;
|
import org.dspace.app.rest.model.BitstreamRest;
|
||||||
import org.dspace.app.rest.model.step.DataLicense;
|
import org.dspace.app.rest.model.step.DataLicense;
|
||||||
import org.dspace.app.rest.submit.AbstractRestProcessingStep;
|
import org.dspace.app.rest.submit.AbstractRestProcessingStep;
|
||||||
import org.dspace.app.util.SubmissionStepConfig;
|
import org.dspace.app.util.SubmissionStepConfig;
|
||||||
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.Bitstream;
|
import org.dspace.content.Bitstream;
|
||||||
|
import org.dspace.content.Item;
|
||||||
|
import org.dspace.content.LicenseUtils;
|
||||||
import org.dspace.content.WorkspaceItem;
|
import org.dspace.content.WorkspaceItem;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.services.model.Request;
|
import org.dspace.services.model.Request;
|
||||||
import org.springframework.data.rest.webmvc.json.patch.LateObjectEvaluator;
|
import org.springframework.data.rest.webmvc.json.patch.LateObjectEvaluator;
|
||||||
|
|
||||||
@@ -43,16 +51,29 @@ public class LicenseStep extends org.dspace.submit.step.LicenseStep implements A
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doPatchProcessing(Context context, Request currentRequest, WorkspaceItem source, String operation,
|
public void doPatchProcessing(Context context, Request currentRequest, WorkspaceItem source, String operation,
|
||||||
String target, String index, LateObjectEvaluator value) {
|
String target, String index, Object value) throws Exception {
|
||||||
switch (operation) {
|
|
||||||
case "replace":
|
if("acceptanceDate".equals(target)) {
|
||||||
|
Item item = source.getItem();
|
||||||
break;
|
EPerson submitter = context.getCurrentUser();
|
||||||
case "remove":
|
|
||||||
|
switch (operation) {
|
||||||
break;
|
case "replace":
|
||||||
default:
|
// remove any existing DSpace license (just in case the user
|
||||||
throw new RuntimeException("Operation "+operation+" not yet implemented!");
|
// accepted it previously)
|
||||||
|
itemService.removeDSpaceLicense(context, item);
|
||||||
|
|
||||||
|
String license = LicenseUtils.getLicenseText(context.getCurrentLocale(), source.getCollection(), item,
|
||||||
|
submitter);
|
||||||
|
|
||||||
|
LicenseUtils.grantLicense(context, item, license, (String)value);
|
||||||
|
break;
|
||||||
|
case "remove":
|
||||||
|
itemService.removeDSpaceLicense(context, item);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Operation " + operation + " not yet implemented!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,7 @@ public class UploadStep extends org.dspace.submit.step.UploadStep implements Abs
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doPatchProcessing(Context context, Request currentRequest, WorkspaceItem source, String operation,
|
public void doPatchProcessing(Context context, Request currentRequest, WorkspaceItem source, String operation,
|
||||||
String target, String index, LateObjectEvaluator value) {
|
String target, String index, Object value) {
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case "add":
|
case "add":
|
||||||
|
|
||||||
|
@@ -590,5 +590,10 @@
|
|||||||
<qualifier>license</qualifier>
|
<qualifier>license</qualifier>
|
||||||
<scope_note></scope_note>
|
<scope_note></scope_note>
|
||||||
</dc-type>
|
</dc-type>
|
||||||
|
<dc-type>
|
||||||
|
<schema>dc</schema>
|
||||||
|
<element>rights</element>
|
||||||
|
<qualifier>date</qualifier>
|
||||||
|
<scope_note></scope_note>
|
||||||
|
</dc-type>
|
||||||
</dspace-dc-types>
|
</dspace-dc-types>
|
||||||
|
Reference in New Issue
Block a user