mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Merge pull request #8180 from atmire/w2p-87624_Issue-rp_patches
Fix for resource policy end date add patch not working
This commit is contained in:
@@ -43,7 +43,6 @@ public class ResourcePolicyEndDateAddOperation<R> extends PatchOperation<R> {
|
||||
checkOperationValue(operation.getValue());
|
||||
if (this.supports(resource, operation)) {
|
||||
ResourcePolicy resourcePolicy = (ResourcePolicy) resource;
|
||||
resourcePolicyUtils.checkResourcePolicyForExistingEndDateValue(resourcePolicy, operation);
|
||||
resourcePolicyUtils.checkResourcePolicyForConsistentEndDateValue(resourcePolicy, operation);
|
||||
this.add(resourcePolicy, operation);
|
||||
return resource;
|
||||
|
@@ -1353,6 +1353,65 @@ public class ResourcePolicyRestRepositoryIT extends AbstractControllerIntegratio
|
||||
hasJsonPath("$.startDate", is(formatDate.format(newDate))))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patchAddEndDataTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
EPerson eperson1 = EPersonBuilder.createEPerson(context)
|
||||
.withEmail("eperson1@mail.com")
|
||||
.withPassword("qwerty01")
|
||||
.build();
|
||||
|
||||
Community community = CommunityBuilder.createCommunity(context).build();
|
||||
|
||||
Collection collection = CollectionBuilder.createCollection(context, community)
|
||||
.withAdminGroup(eperson1)
|
||||
.build();
|
||||
|
||||
Item publicItem1 = ItemBuilder.createItem(context, collection)
|
||||
.withTitle("Public item")
|
||||
.build();
|
||||
|
||||
ResourcePolicy resourcePolicy = ResourcePolicyBuilder.createResourcePolicy(context)
|
||||
.withAction(Constants.READ)
|
||||
.withDspaceObject(publicItem1)
|
||||
.withGroup(
|
||||
EPersonServiceFactory.getInstance().getGroupService()
|
||||
.findByName(context,
|
||||
Group.ANONYMOUS))
|
||||
.withPolicyType(ResourcePolicy.TYPE_CUSTOM)
|
||||
.build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
Calendar newCalendar = Calendar.getInstance();
|
||||
SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date newDate = new Date();
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
AddOperation addOperation = new AddOperation("/endDate", formatDate.format(newDate));
|
||||
ops.add(addOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
String authToken = getAuthToken(eperson1.getEmail(), "qwerty01");
|
||||
getClient(authToken).perform(patch("/api/authz/resourcepolicies/" + resourcePolicy.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$", Matchers.allOf(
|
||||
hasJsonPath("$.name", is(resourcePolicy.getRpName())),
|
||||
hasJsonPath("$.description", is(resourcePolicy.getRpDescription())),
|
||||
hasJsonPath("$.action", is(Constants.actionText[resourcePolicy.getAction()])),
|
||||
hasJsonPath("$.startDate", is(resourcePolicy.getStartDate())),
|
||||
hasJsonPath("$.endDate", is(formatDate.format(newDate))))));
|
||||
|
||||
getClient(authToken).perform(get("/api/authz/resourcepolicies/" + resourcePolicy.getID()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$", Matchers.allOf(
|
||||
hasJsonPath("$.action", is(Constants.actionText[resourcePolicy.getAction()])),
|
||||
hasJsonPath("$.endDate", is(formatDate.format(newDate))))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patchRemoveStartDataTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
Reference in New Issue
Block a user