mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
70506: CC license (REST): Patch submission (Remove)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* 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.InProgressSubmission;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.license.service.CreativeCommonsService;
|
||||
import org.dspace.services.model.Request;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
||||
/**
|
||||
* Submission "remove" PATCH operation
|
||||
*
|
||||
* To remove the Creative Commons License of a workspace item.
|
||||
*
|
||||
* Example: <code>
|
||||
* curl -X PATCH http://${dspace.server.url}/api/submission/workspaceitems/31599 -H "Content-Type:
|
||||
* application/json" -d '[{ "op": "remove", "path": "/sections/cclicense/uri"}]'
|
||||
* </code>
|
||||
*/
|
||||
public class CCLicenseRemovePatchOperation extends RemovePatchOperation<String> {
|
||||
|
||||
@Autowired
|
||||
CreativeCommonsService creativeCommonsService;
|
||||
|
||||
@Override
|
||||
protected Class<String[]> getArrayClassForEvaluation() {
|
||||
return String[].class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<String> getClassForEvaluation() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
void remove(Context context, Request currentRequest, InProgressSubmission source, String path, Object value)
|
||||
throws Exception {
|
||||
Item item = source.getItem();
|
||||
creativeCommonsService.removeLicense(context, item);
|
||||
}
|
||||
|
||||
}
|
@@ -81,6 +81,10 @@
|
||||
<bean
|
||||
class="org.dspace.app.rest.submit.factory.impl.BitstreamResourcePolicyRemovePatchOperation"/>
|
||||
</entry>
|
||||
<entry key="cclicense/uri">
|
||||
<bean
|
||||
class="org.dspace.app.rest.submit.factory.impl.CCLicenseRemovePatchOperation"/>
|
||||
</entry>
|
||||
</map>
|
||||
</entry>
|
||||
<entry key="replace">
|
||||
|
@@ -7,7 +7,11 @@
|
||||
*/
|
||||
package org.dspace.app.rest;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -26,7 +30,7 @@ import org.dspace.content.WorkspaceItem;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Class to the methods from the CCLicenseAddPatchOperation
|
||||
* Class to test the methods from the CCLicenseAddPatchOperation
|
||||
* Since the CC Licenses are obtained from the CC License API, a mock service has been implemented
|
||||
* This mock service will return a fixed set of CC Licenses using a similar structure to the ones obtained from the
|
||||
* CC License API.
|
||||
@@ -54,7 +58,8 @@ public class CCLicenseAddPatchOperationIT extends AbstractControllerIntegrationT
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
AddOperation addOperation = new AddOperation("/sections/cclicense/uri", "license-uri");
|
||||
AddOperation addOperation = new AddOperation("/sections/cclicense/uri",
|
||||
"http://creativecommons.org/licenses/by-nc-sa/4.0/");
|
||||
|
||||
ops.add(addOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
@@ -63,7 +68,13 @@ public class CCLicenseAddPatchOperationIT extends AbstractControllerIntegrationT
|
||||
getClient(adminToken).perform(patch("/api/submission/workspaceitems/" + workspaceItem.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isOk());
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.sections.cclicense", allOf(
|
||||
hasJsonPath("$.uri", is("http://creativecommons.org/licenses/by-nc-sa/4.0/")),
|
||||
hasJsonPath("$.rights",
|
||||
is("Attribution-NonCommercial-ShareAlike 4.0 International")),
|
||||
hasJsonPath("$.file.name", is("license_rdf"))
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.dspace.app.rest.builder.CollectionBuilder;
|
||||
import org.dspace.app.rest.builder.CommunityBuilder;
|
||||
import org.dspace.app.rest.builder.WorkspaceItemBuilder;
|
||||
import org.dspace.app.rest.model.patch.AddOperation;
|
||||
import org.dspace.app.rest.model.patch.Operation;
|
||||
import org.dspace.app.rest.model.patch.RemoveOperation;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.WorkspaceItem;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Class to test the methods from the CCLicenseRemovePatchOperation
|
||||
* Since the CC Licenses are obtained from the CC License API, a mock service has been implemented
|
||||
* This mock service will return a fixed set of CC Licenses using a similar structure to the ones obtained from the
|
||||
* CC License API.
|
||||
* Refer to {@link org.dspace.license.MockCCLicenseConnectorServiceImpl} for more information
|
||||
*/
|
||||
public class CCLicenseRemovePatchOperationIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void patchRemoveSubmissionCCLicense() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
Community community = CommunityBuilder.createCommunity(context)
|
||||
.withName("Community")
|
||||
.build();
|
||||
|
||||
Collection collection = CollectionBuilder.createCollection(context, community)
|
||||
.withName("Collection")
|
||||
.build();
|
||||
|
||||
WorkspaceItem workspaceItem = WorkspaceItemBuilder.createWorkspaceItem(context, collection)
|
||||
.withTitle("Workspace Item")
|
||||
.build();
|
||||
|
||||
String adminToken = getAuthToken(admin.getEmail(), password);
|
||||
|
||||
// First add a license and verify it is added
|
||||
List<Operation> ops = new ArrayList<Operation>();
|
||||
AddOperation addOperation = new AddOperation("/sections/cclicense/uri",
|
||||
"http://creativecommons.org/licenses/by-nc-sa/4.0/");
|
||||
|
||||
ops.add(addOperation);
|
||||
String patchBody = getPatchContent(ops);
|
||||
|
||||
|
||||
getClient(adminToken).perform(patch("/api/submission/workspaceitems/" + workspaceItem.getID())
|
||||
.content(patchBody)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.sections.cclicense", allOf(
|
||||
hasJsonPath("$.uri", is("http://creativecommons.org/licenses/by-nc-sa/4.0/")),
|
||||
hasJsonPath("$.rights",
|
||||
is("Attribution-NonCommercial-ShareAlike 4.0 International")),
|
||||
hasJsonPath("$.file.name", is("license_rdf"))
|
||||
)));
|
||||
|
||||
|
||||
|
||||
// Remove the license again and verify it is removed
|
||||
|
||||
List<Operation> removeOps = new ArrayList<Operation>();
|
||||
RemoveOperation removeOperation = new RemoveOperation("/sections/cclicense/uri");
|
||||
|
||||
removeOps.add(removeOperation);
|
||||
String removePatch = getPatchContent(removeOps);
|
||||
|
||||
|
||||
getClient(adminToken).perform(patch("/api/submission/workspaceitems/" + workspaceItem.getID())
|
||||
.content(removePatch)
|
||||
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.sections", not(hasJsonPath("cclicense"))));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user