mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
implemented remove patch operation for workspaceitem-data-access endpoint
This commit is contained in:
@@ -8,12 +8,14 @@
|
||||
package org.dspace.authorize.dao.impl;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.Order;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
@@ -60,6 +62,9 @@ public class ResourcePolicyDAOImpl extends AbstractHibernateDAO<ResourcePolicy>
|
||||
criteriaBuilder.equal(resourcePolicyRoot.get(ResourcePolicy_.rptype), type)
|
||||
)
|
||||
);
|
||||
List<Order> orderList = new LinkedList<>();
|
||||
orderList.add(criteriaBuilder.asc(resourcePolicyRoot.get(ResourcePolicy_.id)));
|
||||
criteriaQuery.orderBy(orderList);
|
||||
return list(context, criteriaQuery, false, ResourcePolicy.class, -1, -1);
|
||||
}
|
||||
|
||||
|
@@ -7,14 +7,18 @@
|
||||
*/
|
||||
package org.dspace.submit.model;
|
||||
|
||||
import static org.dspace.authorize.ResourcePolicy.TYPE_CUSTOM;
|
||||
import static org.dspace.core.Constants.READ;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.Group;
|
||||
@@ -134,9 +138,9 @@ public class AccessConditionOption {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new resource policy for a bitstream
|
||||
* Create a new resource policy for a DSpaceObject
|
||||
* @param context DSpace context
|
||||
* @param b bitstream for which resource policy is created
|
||||
* @param obj DSpaceObject for which resource policy is created
|
||||
* @param name name of the resource policy
|
||||
* @param description description of the resource policy
|
||||
* @param startDate start date of the resource policy. If {@link #getHasStartDate()} returns false,
|
||||
@@ -144,7 +148,7 @@ public class AccessConditionOption {
|
||||
* @param endDate end date of the resource policy. If {@link #getHasEndDate()} returns false,
|
||||
* endDate should be null. Otherwise endDate may not be null.
|
||||
*/
|
||||
public void createResourcePolicy(Context context, Bitstream b, String name, String description,
|
||||
public void createResourcePolicy(Context context, DSpaceObject obj, String name, String description,
|
||||
Date startDate, Date endDate)
|
||||
throws SQLException, AuthorizeException, ParseException {
|
||||
if (getHasStartDate() && startDate == null) {
|
||||
@@ -187,8 +191,58 @@ public class AccessConditionOption {
|
||||
}
|
||||
|
||||
Group group = groupService.findByName(context, getGroupName());
|
||||
authorizeService.createResourcePolicy(context, b, group, null, Constants.READ,
|
||||
authorizeService.createResourcePolicy(context, obj, group, null, Constants.READ,
|
||||
ResourcePolicy.TYPE_CUSTOM, name, description, startDate,
|
||||
endDate);
|
||||
}
|
||||
|
||||
public boolean canCreateResourcePolicy(Context context, String name, Date startDate, Date endDate)
|
||||
throws SQLException, AuthorizeException, ParseException {
|
||||
if (getHasStartDate() && Objects.isNull(startDate)) {
|
||||
throw new IllegalStateException("The access condition " + getName() + " requires a start date.");
|
||||
}
|
||||
if (getHasEndDate() && Objects.isNull(endDate)) {
|
||||
throw new IllegalStateException("The access condition " + getName() + " requires an end date.");
|
||||
}
|
||||
if (!getHasStartDate() && Objects.nonNull(startDate)) {
|
||||
throw new IllegalStateException("The access condition " + getName() + " cannot contain a start date.");
|
||||
}
|
||||
if (!getHasEndDate() && Objects.nonNull(endDate)) {
|
||||
throw new IllegalStateException("The access condition " + getName() + " cannot contain an end date.");
|
||||
}
|
||||
|
||||
Date latestStartDate = null;
|
||||
if (Objects.nonNull(getStartDateLimit())) {
|
||||
latestStartDate = dateMathParser.parseMath(getStartDateLimit());
|
||||
}
|
||||
|
||||
Date latestEndDate = null;
|
||||
if (Objects.nonNull(getEndDateLimit())) {
|
||||
latestEndDate = dateMathParser.parseMath(getEndDateLimit());
|
||||
}
|
||||
|
||||
// throw if startDate after latestStartDate
|
||||
if (Objects.nonNull(startDate) && Objects.nonNull(latestStartDate) && startDate.after(latestStartDate)) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"The start date of access condition %s should be earlier than %s from now.",
|
||||
getName(), getStartDateLimit()
|
||||
));
|
||||
}
|
||||
|
||||
// throw if endDate after latestEndDate
|
||||
if (Objects.nonNull(endDate) && Objects.nonNull(latestEndDate) && endDate.after(latestEndDate)) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"The end date of access condition %s should be earlier than %s from now.",
|
||||
getName(), getEndDateLimit()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ResourcePolicy createPolicy(Context context, DSpaceObject obj, String name, String description,
|
||||
Date startDate, Date endDate) throws SQLException, AuthorizeException {
|
||||
Group group = groupService.findByName(context, getGroupName());
|
||||
return authorizeService.createResourcePolicy(context, obj, group, null, READ, TYPE_CUSTOM,
|
||||
name, description, startDate, endDate);
|
||||
}
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ import org.dspace.app.rest.model.step.UploadBitstreamRest;
|
||||
*
|
||||
* @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.it)
|
||||
*/
|
||||
public class UploadBitstreamAccessConditionDTO {
|
||||
public class AccessConditionDTO {
|
||||
|
||||
private Integer id;
|
||||
|
||||
|
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 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.model.step;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.dspace.app.rest.model.AccessConditionDTO;
|
||||
|
||||
/**
|
||||
* Java Bean to expose the access conditions during in progress submission.
|
||||
*
|
||||
* @author Mykhaylo Boychuk (mykhaylo.boychuk@4science.com)
|
||||
*/
|
||||
public class DataAccessCondition implements SectionData {
|
||||
|
||||
private static final long serialVersionUID = -502652293641527738L;
|
||||
|
||||
/**
|
||||
* If discoverable = 'false' indicates whether the current item hidden
|
||||
* from all search/browse/OAI results, and is therefore only
|
||||
* accessible via direct link (or bookmark).
|
||||
*/
|
||||
private Boolean discoverable;
|
||||
|
||||
/**
|
||||
* An array of all the policies that has been applied by the user to the item.
|
||||
*/
|
||||
private List<AccessConditionDTO> accessConditions;
|
||||
|
||||
public List<AccessConditionDTO> getAccessConditions() {
|
||||
if (Objects.isNull(accessConditions)) {
|
||||
accessConditions = new ArrayList<>();
|
||||
}
|
||||
return accessConditions;
|
||||
}
|
||||
|
||||
public void setAccessConditions(List<AccessConditionDTO> accessConditions) {
|
||||
this.accessConditions = accessConditions;
|
||||
}
|
||||
|
||||
public Boolean getDiscoverable() {
|
||||
return discoverable;
|
||||
}
|
||||
|
||||
public void setDiscoverable(Boolean discoverable) {
|
||||
this.discoverable = discoverable;
|
||||
}
|
||||
|
||||
}
|
@@ -6,21 +6,20 @@
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest.model.step;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.app.rest.model.AccessConditionDTO;
|
||||
import org.dspace.app.rest.model.BitstreamFormatRest;
|
||||
import org.dspace.app.rest.model.CheckSumRest;
|
||||
import org.dspace.app.rest.model.MetadataValueRest;
|
||||
import org.dspace.app.rest.model.UploadBitstreamAccessConditionDTO;
|
||||
|
||||
/**
|
||||
* This Java Bean is used to represent a single bitstream with all its metadata
|
||||
* and access conditions ({@link UploadBitstreamAccessConditionDTO}) inside an
|
||||
* and access conditions ({@link AccessConditionDTO}) inside an
|
||||
* upload submission section ({@link DataUpload}
|
||||
*
|
||||
*/
|
||||
@@ -28,7 +27,7 @@ public class UploadBitstreamRest extends UploadStatusResponse {
|
||||
|
||||
private UUID uuid;
|
||||
private Map<String, List<MetadataValueRest>> metadata = new HashMap<>();
|
||||
private List<UploadBitstreamAccessConditionDTO> accessConditions;
|
||||
private List<AccessConditionDTO> accessConditions;
|
||||
private BitstreamFormatRest format;
|
||||
private Long sizeBytes;
|
||||
private CheckSumRest checkSum;
|
||||
@@ -74,14 +73,14 @@ public class UploadBitstreamRest extends UploadStatusResponse {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public List<UploadBitstreamAccessConditionDTO> getAccessConditions() {
|
||||
public List<AccessConditionDTO> getAccessConditions() {
|
||||
if (accessConditions == null) {
|
||||
accessConditions = new ArrayList<>();
|
||||
}
|
||||
return accessConditions;
|
||||
}
|
||||
|
||||
public void setAccessConditions(List<UploadBitstreamAccessConditionDTO> accessConditions) {
|
||||
public void setAccessConditions(List<AccessConditionDTO> accessConditions) {
|
||||
this.accessConditions = accessConditions;
|
||||
}
|
||||
|
||||
|
@@ -36,6 +36,8 @@ public interface DataProcessingStep extends RestProcessingStep {
|
||||
public static final String UPLOAD_STEP_ACCESSCONDITIONS_OPERATION_ENTRY = "accessConditions";
|
||||
public static final String LICENSE_STEP_OPERATION_ENTRY = "granted";
|
||||
public static final String CCLICENSE_STEP_OPERATION_ENTRY = "cclicense/uri";
|
||||
public static final String ACCESS_CONDITION_STEP_OPERATION_ENTRY = "discoverable";
|
||||
public static final String ACCESS_CONDITION_POLICY_STEP_OPERATION_ENTRY = "accessConditions";
|
||||
|
||||
public static final String UPLOAD_STEP_METADATA_PATH = "metadata";
|
||||
|
||||
|
@@ -22,11 +22,11 @@ import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||
import org.dspace.app.rest.exception.RESTAuthorizationException;
|
||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||
import org.dspace.app.rest.model.AInprogressSubmissionRest;
|
||||
import org.dspace.app.rest.model.AccessConditionDTO;
|
||||
import org.dspace.app.rest.model.BitstreamRest;
|
||||
import org.dspace.app.rest.model.CheckSumRest;
|
||||
import org.dspace.app.rest.model.ErrorRest;
|
||||
import org.dspace.app.rest.model.MetadataValueRest;
|
||||
import org.dspace.app.rest.model.UploadBitstreamAccessConditionDTO;
|
||||
import org.dspace.app.rest.model.WorkspaceItemRest;
|
||||
import org.dspace.app.rest.model.patch.Operation;
|
||||
import org.dspace.app.rest.model.step.DataCCLicense;
|
||||
@@ -162,7 +162,7 @@ public class SubmissionService {
|
||||
/**
|
||||
* Build the rest representation of a bitstream as used in the upload section
|
||||
* ({@link DataUpload}. It contains all its metadata and the list of applied
|
||||
* access conditions (@link {@link UploadBitstreamAccessConditionDTO}
|
||||
* access conditions (@link {@link AccessConditionDTO}
|
||||
*
|
||||
* @param configurationService the DSpace ConfigurationService
|
||||
* @param source the bitstream to translate in its rest submission
|
||||
@@ -204,7 +204,7 @@ public class SubmissionService {
|
||||
|
||||
for (ResourcePolicy rp : source.getResourcePolicies()) {
|
||||
if (ResourcePolicy.TYPE_CUSTOM.equals(rp.getRpType())) {
|
||||
UploadBitstreamAccessConditionDTO uploadAccessCondition = createAccessConditionFromResourcePolicy(rp);
|
||||
AccessConditionDTO uploadAccessCondition = createAccessConditionFromResourcePolicy(rp);
|
||||
data.getAccessConditions().add(uploadAccessCondition);
|
||||
}
|
||||
}
|
||||
@@ -271,8 +271,8 @@ public class SubmissionService {
|
||||
return wi;
|
||||
}
|
||||
|
||||
private UploadBitstreamAccessConditionDTO createAccessConditionFromResourcePolicy(ResourcePolicy rp) {
|
||||
UploadBitstreamAccessConditionDTO accessCondition = new UploadBitstreamAccessConditionDTO();
|
||||
private AccessConditionDTO createAccessConditionFromResourcePolicy(ResourcePolicy rp) {
|
||||
AccessConditionDTO accessCondition = new AccessConditionDTO();
|
||||
|
||||
accessCondition.setId(rp.getID());
|
||||
accessCondition.setName(rp.getRpName());
|
||||
|
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* 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 java.util.Objects;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||
import org.dspace.content.InProgressSubmission;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.submit.model.AccessConditionConfiguration;
|
||||
import org.dspace.submit.model.AccessConditionConfigurationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Submission "add" PATCH operation
|
||||
* to change item discoverable true|false.
|
||||
*
|
||||
* @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.com)
|
||||
*/
|
||||
public class AccessConditionDiscoverableReplacePatchOperation extends ReplacePatchOperation<String> {
|
||||
|
||||
@Autowired
|
||||
private AccessConditionConfigurationService accessConditionConfigurationService;
|
||||
|
||||
@Override
|
||||
void replace(Context context, HttpServletRequest currentRequest, InProgressSubmission source, String string,
|
||||
Object value) throws Exception {
|
||||
Boolean discoverable = null;
|
||||
|
||||
String stepId = (String) currentRequest.getAttribute("accessConditionSectionId");
|
||||
AccessConditionConfiguration configuration = accessConditionConfigurationService.getMap().get(stepId);
|
||||
|
||||
if (Objects.isNull(configuration) || !configuration.getDiscoverable().booleanValue()) {
|
||||
throw new UnprocessableEntityException("The current access configurations does not allow" +
|
||||
" the user to specify the visibility of the item");
|
||||
}
|
||||
|
||||
if (value instanceof String) {
|
||||
discoverable = BooleanUtils.toBooleanObject((String) value);
|
||||
} else {
|
||||
discoverable = (Boolean) value;
|
||||
}
|
||||
|
||||
if (Objects.isNull(discoverable)) {
|
||||
throw new UnprocessableEntityException(
|
||||
"Value is not a valid boolean expression permitted value: true|false");
|
||||
}
|
||||
|
||||
Item item = source.getItem();
|
||||
|
||||
if (discoverable == item.isDiscoverable()) {
|
||||
return;
|
||||
} else if (discoverable) {
|
||||
item.setDiscoverable(discoverable);
|
||||
} else {
|
||||
item.setDiscoverable(discoverable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<String[]> getArrayClassForEvaluation() {
|
||||
return String[].class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<String> getClassForEvaluation() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* 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 java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||
import org.dspace.app.rest.model.AccessConditionDTO;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.authorize.service.ResourcePolicyService;
|
||||
import org.dspace.content.InProgressSubmission;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Submission "remove" operation to remove custom resource policies.
|
||||
*
|
||||
* @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.com)
|
||||
*/
|
||||
public class AccessConditionRemovePatchOperation extends RemovePatchOperation<AccessConditionDTO> {
|
||||
|
||||
@Autowired
|
||||
private AuthorizeService authorizeService;
|
||||
@Autowired
|
||||
private ResourcePolicyService resourcePolicyService;
|
||||
|
||||
@Override
|
||||
void remove(Context context, HttpServletRequest currentRequest, InProgressSubmission source, String path,
|
||||
Object value) throws Exception {
|
||||
|
||||
// "path" : "/sections/<:name-of-the-form>/accessConditions/0"
|
||||
// "abspath" : "/accessConditions/0"
|
||||
String[] split = getAbsolutePath(path).split("/");
|
||||
Item item = source.getItem();
|
||||
|
||||
if (split.length == 1) {
|
||||
// reset the access condition to the empty array
|
||||
authorizeService.removePoliciesActionFilter(context, item, Constants.READ);
|
||||
} else if (split.length == 2) {
|
||||
// to remove an access condition
|
||||
// contains "<:access-idx>"
|
||||
Integer idxToDelete = null;
|
||||
try {
|
||||
idxToDelete = Integer.parseInt(split[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new UnprocessableEntityException("The provided index format is not correct! Must be a number!");
|
||||
}
|
||||
|
||||
List<ResourcePolicy> policies = resourcePolicyService.find(context, item, ResourcePolicy.TYPE_CUSTOM);
|
||||
if ((idxToDelete < 0 || idxToDelete >= policies.size()) && policies.isEmpty()) {
|
||||
throw new UnprocessableEntityException("The provided index:" + idxToDelete + " is not supported,"
|
||||
+ " currently the are " + policies.size() + " access conditions");
|
||||
}
|
||||
|
||||
ResourcePolicy resourcePolicyToDelete = policies.get(idxToDelete);
|
||||
item.getResourcePolicies().remove(resourcePolicyToDelete);
|
||||
context.commit();
|
||||
resourcePolicyService.delete(context, resourcePolicyToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<AccessConditionDTO[]> getArrayClassForEvaluation() {
|
||||
return AccessConditionDTO[].class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<AccessConditionDTO> getClassForEvaluation() {
|
||||
return AccessConditionDTO.class;
|
||||
}
|
||||
|
||||
}
|
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.dspace.app.rest.model.UploadBitstreamAccessConditionDTO;
|
||||
import org.dspace.app.rest.model.AccessConditionDTO;
|
||||
import org.dspace.app.rest.model.patch.LateObjectEvaluator;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.Bitstream;
|
||||
@@ -33,7 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
*
|
||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||
*/
|
||||
public class BitstreamResourcePolicyAddPatchOperation extends AddPatchOperation<UploadBitstreamAccessConditionDTO> {
|
||||
public class BitstreamResourcePolicyAddPatchOperation extends AddPatchOperation<AccessConditionDTO> {
|
||||
|
||||
|
||||
@Autowired
|
||||
@@ -61,8 +61,8 @@ public class BitstreamResourcePolicyAddPatchOperation extends AddPatchOperation<
|
||||
for (Bitstream bitstream : bb.getBitstreams()) {
|
||||
if (idx == Integer.parseInt(split[1])) {
|
||||
|
||||
List<UploadBitstreamAccessConditionDTO> newAccessConditions =
|
||||
new ArrayList<UploadBitstreamAccessConditionDTO>();
|
||||
List<AccessConditionDTO> newAccessConditions =
|
||||
new ArrayList<AccessConditionDTO>();
|
||||
if (split.length == 3) {
|
||||
authorizeService.removePoliciesActionFilter(context, bitstream, Constants.READ);
|
||||
newAccessConditions = evaluateArrayObject((LateObjectEvaluator) value);
|
||||
@@ -83,12 +83,12 @@ public class BitstreamResourcePolicyAddPatchOperation extends AddPatchOperation<
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<UploadBitstreamAccessConditionDTO[]> getArrayClassForEvaluation() {
|
||||
return UploadBitstreamAccessConditionDTO[].class;
|
||||
protected Class<AccessConditionDTO[]> getArrayClassForEvaluation() {
|
||||
return AccessConditionDTO[].class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<UploadBitstreamAccessConditionDTO> getClassForEvaluation() {
|
||||
return UploadBitstreamAccessConditionDTO.class;
|
||||
protected Class<AccessConditionDTO> getClassForEvaluation() {
|
||||
return AccessConditionDTO.class;
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ package org.dspace.app.rest.submit.factory.impl;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.dspace.app.rest.model.UploadBitstreamAccessConditionDTO;
|
||||
import org.dspace.app.rest.model.AccessConditionDTO;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.authorize.service.ResourcePolicyService;
|
||||
import org.dspace.content.Bitstream;
|
||||
@@ -29,7 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||
*/
|
||||
public class BitstreamResourcePolicyRemovePatchOperation
|
||||
extends RemovePatchOperation<UploadBitstreamAccessConditionDTO> {
|
||||
extends RemovePatchOperation<AccessConditionDTO> {
|
||||
|
||||
@Autowired
|
||||
ItemService itemService;
|
||||
@@ -84,12 +84,12 @@ public class BitstreamResourcePolicyRemovePatchOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<UploadBitstreamAccessConditionDTO[]> getArrayClassForEvaluation() {
|
||||
return UploadBitstreamAccessConditionDTO[].class;
|
||||
protected Class<AccessConditionDTO[]> getArrayClassForEvaluation() {
|
||||
return AccessConditionDTO[].class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<UploadBitstreamAccessConditionDTO> getClassForEvaluation() {
|
||||
return UploadBitstreamAccessConditionDTO.class;
|
||||
protected Class<AccessConditionDTO> getClassForEvaluation() {
|
||||
return AccessConditionDTO.class;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* 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.step;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||
import org.dspace.app.rest.model.AccessConditionDTO;
|
||||
import org.dspace.app.rest.model.patch.Operation;
|
||||
import org.dspace.app.rest.model.step.DataAccessCondition;
|
||||
import org.dspace.app.rest.submit.AbstractProcessingStep;
|
||||
import org.dspace.app.rest.submit.SubmissionService;
|
||||
import org.dspace.app.rest.submit.factory.PatchOperationFactory;
|
||||
import org.dspace.app.rest.submit.factory.impl.PatchOperation;
|
||||
import org.dspace.app.util.SubmissionStepConfig;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
import org.dspace.content.InProgressSubmission;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
/**
|
||||
* AccessCondition step for DSpace Spring Rest. Expose information about
|
||||
* the resource policies for the in progress submission.
|
||||
*
|
||||
* @author Mykhaylo Boychuk (mykhaylo.boychuk@4science.com)
|
||||
*/
|
||||
public class AccessConditionStep extends AbstractProcessingStep {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public DataAccessCondition getData(SubmissionService submissionService, InProgressSubmission obj,
|
||||
SubmissionStepConfig config) throws Exception {
|
||||
DataAccessCondition accessCondition = new DataAccessCondition();
|
||||
accessCondition.setDiscoverable(obj.getItem().isDiscoverable());
|
||||
accessCondition.setAccessConditions(getAccessConditionList(obj.getItem()));
|
||||
return accessCondition;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void doPatchProcessing(Context context, HttpServletRequest currentRequest, InProgressSubmission source,
|
||||
Operation op, SubmissionStepConfig stepConf) throws Exception {
|
||||
String instance = StringUtils.EMPTY;
|
||||
if (op.getPath().contains(ACCESS_CONDITION_STEP_OPERATION_ENTRY)) {
|
||||
instance = ACCESS_CONDITION_STEP_OPERATION_ENTRY;
|
||||
} else if (op.getPath().contains(ACCESS_CONDITION_POLICY_STEP_OPERATION_ENTRY)) {
|
||||
instance = ACCESS_CONDITION_POLICY_STEP_OPERATION_ENTRY;
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(instance)) {
|
||||
throw new UnprocessableEntityException("The path " + op.getPath() + " is not supported by the operation "
|
||||
+ op.getOp());
|
||||
}
|
||||
|
||||
currentRequest.setAttribute("accessConditionSectionId", stepConf.getId());
|
||||
PatchOperation<String> patchOperation = new PatchOperationFactory().instanceOf(instance, op.getOp());
|
||||
patchOperation.perform(context, currentRequest, source, op);
|
||||
}
|
||||
|
||||
private List<AccessConditionDTO> getAccessConditionList(Item item) {
|
||||
List<AccessConditionDTO> accessConditions = new ArrayList<AccessConditionDTO>();
|
||||
for (ResourcePolicy rp : item.getResourcePolicies()) {
|
||||
if (ResourcePolicy.TYPE_CUSTOM.equals(rp.getRpType())) {
|
||||
AccessConditionDTO accessConditionDTO = createAccessConditionFromResourcePolicy(rp);
|
||||
accessConditions.add(accessConditionDTO);
|
||||
}
|
||||
}
|
||||
return accessConditions;
|
||||
}
|
||||
|
||||
private AccessConditionDTO createAccessConditionFromResourcePolicy(ResourcePolicy rp) {
|
||||
AccessConditionDTO accessCondition = new AccessConditionDTO();
|
||||
|
||||
accessCondition.setId(rp.getID());
|
||||
accessCondition.setName(rp.getRpName());
|
||||
accessCondition.setDescription(rp.getRpDescription());
|
||||
accessCondition.setStartDate(rp.getStartDate());
|
||||
accessCondition.setEndDate(rp.getEndDate());
|
||||
return accessCondition;
|
||||
}
|
||||
|
||||
}
|
@@ -72,7 +72,7 @@ public class UploadStep extends AbstractProcessingStep
|
||||
if (op.getPath().contains(UPLOAD_STEP_METADATA_PATH)) {
|
||||
instance = UPLOAD_STEP_METADATA_OPERATION_ENTRY;
|
||||
} else if (op.getPath().contains(UPLOAD_STEP_ACCESSCONDITIONS_OPERATION_ENTRY)) {
|
||||
instance = UPLOAD_STEP_ACCESSCONDITIONS_OPERATION_ENTRY;
|
||||
instance = stepConf.getType() + "." + UPLOAD_STEP_ACCESSCONDITIONS_OPERATION_ENTRY;
|
||||
} else {
|
||||
instance = UPLOAD_STEP_REMOVE_OPERATION_ENTRY;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class UploadStep extends AbstractProcessingStep
|
||||
}
|
||||
} else {
|
||||
if (op.getPath().contains(UPLOAD_STEP_ACCESSCONDITIONS_OPERATION_ENTRY)) {
|
||||
instance = UPLOAD_STEP_ACCESSCONDITIONS_OPERATION_ENTRY;
|
||||
instance = stepConf.getType() + "." + UPLOAD_STEP_ACCESSCONDITIONS_OPERATION_ENTRY;
|
||||
} else if (op.getPath().contains(UPLOAD_STEP_METADATA_PATH)) {
|
||||
instance = UPLOAD_STEP_METADATA_OPERATION_ENTRY;
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@
|
||||
<bean
|
||||
class="org.dspace.app.rest.submit.factory.impl.LicenseAddPatchOperation"/>
|
||||
</entry>
|
||||
<entry key="accessConditions">
|
||||
<entry key="upload.accessConditions">
|
||||
<bean
|
||||
class="org.dspace.app.rest.submit.factory.impl.BitstreamResourcePolicyAddPatchOperation"/>
|
||||
</entry>
|
||||
@@ -60,6 +60,9 @@
|
||||
<bean
|
||||
class="org.dspace.app.rest.submit.factory.impl.CCLicenseAddPatchOperation"/>
|
||||
</entry>
|
||||
<entry key="accessConditions">
|
||||
<bean class="org.dspace.app.rest.submit.factory.impl.AccessConditionAddPatchOperation"/>
|
||||
</entry>
|
||||
</map>
|
||||
</entry>
|
||||
<entry key="remove">
|
||||
@@ -91,6 +94,9 @@
|
||||
<bean
|
||||
class="org.dspace.app.rest.submit.factory.impl.CCLicenseRemovePatchOperation"/>
|
||||
</entry>
|
||||
<entry key="accessConditions">
|
||||
<bean class="org.dspace.app.rest.submit.factory.impl.AccessConditionRemovePatchOperation"/>
|
||||
</entry>
|
||||
</map>
|
||||
</entry>
|
||||
<entry key="replace">
|
||||
@@ -110,7 +116,7 @@
|
||||
<bean
|
||||
class="org.dspace.app.rest.submit.factory.impl.LicenseReplacePatchOperation"/>
|
||||
</entry>
|
||||
<entry key="accessConditions">
|
||||
<entry key="upload.accessConditions">
|
||||
<bean
|
||||
class="org.dspace.app.rest.submit.factory.impl.BitstreamResourcePolicyReplacePatchOperation"/>
|
||||
</entry>
|
||||
@@ -118,6 +124,12 @@
|
||||
<bean
|
||||
class="org.dspace.app.rest.submit.factory.impl.CollectionReplacePatchOperation"/>
|
||||
</entry>
|
||||
<entry key="discoverable">
|
||||
<bean class="org.dspace.app.rest.submit.factory.impl.AccessConditionDiscoverableReplacePatchOperation"/>
|
||||
</entry>
|
||||
<entry key="accessConditions">
|
||||
<bean class="org.dspace.app.rest.submit.factory.impl.AccessConditionReplacePatchOperation"/>
|
||||
</entry>
|
||||
</map>
|
||||
</entry>
|
||||
</map>
|
||||
|
Reference in New Issue
Block a user