Search in sources :

Example 1 with Community

use of org.dspace.content.Community in project DSpace by DSpace.

the class ResourcePolicyRestRepositoryIT method patchAddEndDataTest.

@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))))));
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ReplaceOperation(org.dspace.app.rest.model.patch.ReplaceOperation) RemoveOperation(org.dspace.app.rest.model.patch.RemoveOperation) AddOperation(org.dspace.app.rest.model.patch.AddOperation) Operation(org.dspace.app.rest.model.patch.Operation) AddOperation(org.dspace.app.rest.model.patch.AddOperation) EPerson(org.dspace.eperson.EPerson) Date(java.util.Date) Item(org.dspace.content.Item) Collection(org.dspace.content.Collection) ResourcePolicy(org.dspace.authorize.ResourcePolicy) SimpleDateFormat(java.text.SimpleDateFormat) Community(org.dspace.content.Community) Test(org.junit.Test) AbstractControllerIntegrationTest(org.dspace.app.rest.test.AbstractControllerIntegrationTest)

Example 2 with Community

use of org.dspace.content.Community in project DSpace by DSpace.

the class ResourcePolicyRestRepositoryIT method patchReplaceStartDataForbiddenTest.

@Test
public void patchReplaceStartDataForbiddenTest() 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).build();
    Item item = ItemBuilder.createItem(context, collection).withTitle("Public item").build();
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2019);
    calendar.set(Calendar.MONTH, 9);
    calendar.set(Calendar.DATE, 31);
    Date date = calendar.getTime();
    ResourcePolicy resourcePolicy = ResourcePolicyBuilder.createResourcePolicy(context).withAction(Constants.READ).withDspaceObject(item).withGroup(EPersonServiceFactory.getInstance().getGroupService().findByName(context, Group.ANONYMOUS)).withStartDate(date).withPolicyType(ResourcePolicy.TYPE_CUSTOM).build();
    context.restoreAuthSystemState();
    Calendar calendar2 = Calendar.getInstance();
    SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
    calendar2.set(Calendar.YEAR, 2020);
    calendar2.set(Calendar.MONTH, 0);
    calendar2.set(Calendar.DATE, 1);
    Date newData = calendar2.getTime();
    List<Operation> ops = new ArrayList<Operation>();
    ReplaceOperation replaceOperation = new ReplaceOperation("/startDate", formatDate.format(newData));
    ops.add(replaceOperation);
    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().isForbidden());
    String authToken2 = getAuthToken(admin.getEmail(), password);
    getClient(authToken2).perform(get("/api/authz/resourcepolicies/" + resourcePolicy.getID())).andExpect(status().isOk()).andExpect(jsonPath("$", Matchers.allOf(hasJsonPath("$.action", is(Constants.actionText[resourcePolicy.getAction()])), hasJsonPath("$.startDate", is(formatDate.format(date))), hasJsonPath("$.description", is(resourcePolicy.getRpDescription())))));
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ReplaceOperation(org.dspace.app.rest.model.patch.ReplaceOperation) RemoveOperation(org.dspace.app.rest.model.patch.RemoveOperation) AddOperation(org.dspace.app.rest.model.patch.AddOperation) Operation(org.dspace.app.rest.model.patch.Operation) EPerson(org.dspace.eperson.EPerson) Date(java.util.Date) Item(org.dspace.content.Item) ReplaceOperation(org.dspace.app.rest.model.patch.ReplaceOperation) Collection(org.dspace.content.Collection) ResourcePolicy(org.dspace.authorize.ResourcePolicy) SimpleDateFormat(java.text.SimpleDateFormat) Community(org.dspace.content.Community) Test(org.junit.Test) AbstractControllerIntegrationTest(org.dspace.app.rest.test.AbstractControllerIntegrationTest)

Example 3 with Community

use of org.dspace.content.Community in project DSpace by DSpace.

the class ResourcePolicyRestRepositoryIT method patchAddStartDataTest.

@Test
public void patchAddStartDataTest() 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");
    newCalendar.set(Calendar.YEAR, 2019);
    newCalendar.set(Calendar.MONTH, 9);
    newCalendar.set(Calendar.DATE, 31);
    Date newDate = newCalendar.getTime();
    List<Operation> ops = new ArrayList<Operation>();
    AddOperation addOperation = new AddOperation("/startDate", 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(formatDate.format(newDate))), hasJsonPath("$.endDate", is(resourcePolicy.getEndDate())))));
    getClient(authToken).perform(get("/api/authz/resourcepolicies/" + resourcePolicy.getID())).andExpect(status().isOk()).andExpect(jsonPath("$", Matchers.allOf(hasJsonPath("$.action", is(Constants.actionText[resourcePolicy.getAction()])), hasJsonPath("$.startDate", is(formatDate.format(newDate))))));
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ReplaceOperation(org.dspace.app.rest.model.patch.ReplaceOperation) RemoveOperation(org.dspace.app.rest.model.patch.RemoveOperation) AddOperation(org.dspace.app.rest.model.patch.AddOperation) Operation(org.dspace.app.rest.model.patch.Operation) AddOperation(org.dspace.app.rest.model.patch.AddOperation) EPerson(org.dspace.eperson.EPerson) Date(java.util.Date) Item(org.dspace.content.Item) Collection(org.dspace.content.Collection) ResourcePolicy(org.dspace.authorize.ResourcePolicy) SimpleDateFormat(java.text.SimpleDateFormat) Community(org.dspace.content.Community) Test(org.junit.Test) AbstractControllerIntegrationTest(org.dspace.app.rest.test.AbstractControllerIntegrationTest)

Example 4 with Community

use of org.dspace.content.Community in project DSpace by DSpace.

the class ResourcePolicyRestRepositoryIT method patchReplaceEndDateBeforeStartDataTest.

@Test
public void patchReplaceEndDateBeforeStartDataTest() 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();
    Calendar calendarStartDate = Calendar.getInstance();
    calendarStartDate.set(Calendar.YEAR, 2019);
    calendarStartDate.set(Calendar.MONTH, 10);
    calendarStartDate.set(Calendar.DATE, 21);
    Date startDate = calendarStartDate.getTime();
    Calendar calendarEndDate = Calendar.getInstance();
    calendarEndDate.set(Calendar.YEAR, 2020);
    calendarEndDate.set(Calendar.MONTH, 10);
    calendarEndDate.set(Calendar.DATE, 21);
    Date endDate = calendarEndDate.getTime();
    ResourcePolicy resourcePolicy = ResourcePolicyBuilder.createResourcePolicy(context).withAction(Constants.READ).withDspaceObject(publicItem1).withUser(eperson1).withStartDate(startDate).withEndDate(endDate).withPolicyType(ResourcePolicy.TYPE_CUSTOM).build();
    context.restoreAuthSystemState();
    Calendar newEndDateCalendar = Calendar.getInstance();
    SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
    newEndDateCalendar.set(Calendar.YEAR, 2018);
    newEndDateCalendar.set(Calendar.MONTH, 10);
    newEndDateCalendar.set(Calendar.DATE, 21);
    Date newEndDate = newEndDateCalendar.getTime();
    List<Operation> ops = new ArrayList<Operation>();
    ReplaceOperation replaceOperation = new ReplaceOperation("/endDate", formatDate.format(newEndDate));
    ops.add(replaceOperation);
    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().isBadRequest());
    getClient(authToken).perform(get("/api/authz/resourcepolicies/" + resourcePolicy.getID())).andExpect(status().isOk()).andExpect(jsonPath("$", Matchers.allOf(hasJsonPath("$.action", is(Constants.actionText[resourcePolicy.getAction()])), hasJsonPath("$.startDate", is(formatDate.format(startDate))), hasJsonPath("$.endDate", is(formatDate.format(endDate))))));
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ReplaceOperation(org.dspace.app.rest.model.patch.ReplaceOperation) RemoveOperation(org.dspace.app.rest.model.patch.RemoveOperation) AddOperation(org.dspace.app.rest.model.patch.AddOperation) Operation(org.dspace.app.rest.model.patch.Operation) EPerson(org.dspace.eperson.EPerson) Date(java.util.Date) Item(org.dspace.content.Item) ReplaceOperation(org.dspace.app.rest.model.patch.ReplaceOperation) Collection(org.dspace.content.Collection) ResourcePolicy(org.dspace.authorize.ResourcePolicy) SimpleDateFormat(java.text.SimpleDateFormat) Community(org.dspace.content.Community) Test(org.junit.Test) AbstractControllerIntegrationTest(org.dspace.app.rest.test.AbstractControllerIntegrationTest)

Example 5 with Community

use of org.dspace.content.Community in project DSpace by DSpace.

the class ResourcePolicyRestRepositoryIT method patchReplaceStartDataTest.

@Test
public void patchReplaceStartDataTest() 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();
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2019);
    calendar.set(Calendar.MONTH, 9);
    calendar.set(Calendar.DATE, 31);
    Date data = calendar.getTime();
    ResourcePolicy resourcePolicy = ResourcePolicyBuilder.createResourcePolicy(context).withAction(Constants.READ).withDspaceObject(publicItem1).withGroup(EPersonServiceFactory.getInstance().getGroupService().findByName(context, Group.ANONYMOUS)).withStartDate(data).withPolicyType(ResourcePolicy.TYPE_CUSTOM).build();
    context.restoreAuthSystemState();
    Calendar newCalendar = Calendar.getInstance();
    SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
    newCalendar.set(Calendar.YEAR, 2020);
    newCalendar.set(Calendar.MONTH, 0);
    newCalendar.set(Calendar.DATE, 1);
    Date newDate = newCalendar.getTime();
    List<Operation> ops = new ArrayList<Operation>();
    ReplaceOperation replaceOperation = new ReplaceOperation("/startDate", formatDate.format(newDate));
    ops.add(replaceOperation);
    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(formatDate.format(newDate))), hasJsonPath("$.endDate", is(resourcePolicy.getEndDate())))));
    getClient(authToken).perform(get("/api/authz/resourcepolicies/" + resourcePolicy.getID())).andExpect(status().isOk()).andExpect(jsonPath("$", Matchers.allOf(hasJsonPath("$.action", is(Constants.actionText[resourcePolicy.getAction()])), hasJsonPath("$.startDate", is(formatDate.format(newDate))))));
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ReplaceOperation(org.dspace.app.rest.model.patch.ReplaceOperation) RemoveOperation(org.dspace.app.rest.model.patch.RemoveOperation) AddOperation(org.dspace.app.rest.model.patch.AddOperation) Operation(org.dspace.app.rest.model.patch.Operation) EPerson(org.dspace.eperson.EPerson) Date(java.util.Date) Item(org.dspace.content.Item) ReplaceOperation(org.dspace.app.rest.model.patch.ReplaceOperation) Collection(org.dspace.content.Collection) ResourcePolicy(org.dspace.authorize.ResourcePolicy) SimpleDateFormat(java.text.SimpleDateFormat) Community(org.dspace.content.Community) Test(org.junit.Test) AbstractControllerIntegrationTest(org.dspace.app.rest.test.AbstractControllerIntegrationTest)

Aggregations

Community (org.dspace.content.Community)776 Test (org.junit.Test)653 Collection (org.dspace.content.Collection)651 AbstractControllerIntegrationTest (org.dspace.app.rest.test.AbstractControllerIntegrationTest)577 Item (org.dspace.content.Item)348 WorkspaceItem (org.dspace.content.WorkspaceItem)228 EPerson (org.dspace.eperson.EPerson)183 ArrayList (java.util.ArrayList)167 XmlWorkflowItem (org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem)131 Operation (org.dspace.app.rest.model.patch.Operation)127 ReplaceOperation (org.dspace.app.rest.model.patch.ReplaceOperation)123 InputStream (java.io.InputStream)115 AddOperation (org.dspace.app.rest.model.patch.AddOperation)114 RemoveOperation (org.dspace.app.rest.model.patch.RemoveOperation)96 ResourcePolicy (org.dspace.authorize.ResourcePolicy)78 Bitstream (org.dspace.content.Bitstream)76 Group (org.dspace.eperson.Group)71 Matchers.emptyOrNullString (org.hamcrest.Matchers.emptyOrNullString)71 HashMap (java.util.HashMap)59 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)53