mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-10 11:33:11 +00:00
Merge pull request #9639 from 4Science/task/main/DURACOM-265_CC-licence-step-does-not-work
[ #2161] Provide a way to require Creative Commons license in submission form
This commit is contained in:
@@ -0,0 +1,120 @@
|
|||||||
|
/**
|
||||||
|
* 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.validation;
|
||||||
|
|
||||||
|
import static org.dspace.app.rest.repository.WorkspaceItemRestRepository.OPERATION_PATH_SECTIONS;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.model.ErrorRest;
|
||||||
|
import org.dspace.app.rest.submit.SubmissionService;
|
||||||
|
import org.dspace.app.util.DCInputsReaderException;
|
||||||
|
import org.dspace.app.util.SubmissionStepConfig;
|
||||||
|
import org.dspace.content.InProgressSubmission;
|
||||||
|
import org.dspace.content.Item;
|
||||||
|
import org.dspace.content.service.ItemService;
|
||||||
|
import org.dspace.license.CreativeCommonsServiceImpl;
|
||||||
|
import org.dspace.services.ConfigurationService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class validates that the Creative Commons License has been granted for the
|
||||||
|
* in-progress submission.
|
||||||
|
*
|
||||||
|
* @author Mattia Vianelli (Mattia.Vianelli@4science.com)
|
||||||
|
*/
|
||||||
|
public class CclicenseValidator extends AbstractValidation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a Creative Commons License configuration.
|
||||||
|
* @param configurationService DSpace configuration provided by the DI container.
|
||||||
|
*/
|
||||||
|
@Inject
|
||||||
|
public CclicenseValidator(ConfigurationService configurationService) {
|
||||||
|
this.configurationService = configurationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final ConfigurationService configurationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ItemService itemService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CreativeCommonsServiceImpl creativeCommonsService;
|
||||||
|
|
||||||
|
public static final String ERROR_VALIDATION_CCLICENSEREQUIRED = "error.validation.cclicense.required";
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the license of the item.
|
||||||
|
* @param item The item whose cclicense is to be validated.
|
||||||
|
* @param config The configuration for the submission step for cclicense.
|
||||||
|
* @return A list of validation errors.
|
||||||
|
*/
|
||||||
|
private List<ErrorRest> validateLicense(Item item, SubmissionStepConfig config) {
|
||||||
|
List<ErrorRest> errors = new ArrayList<>(1);
|
||||||
|
|
||||||
|
String licenseURI = creativeCommonsService.getLicenseURI(item);
|
||||||
|
if (licenseURI == null || licenseURI.isBlank()) {
|
||||||
|
addError(errors, ERROR_VALIDATION_CCLICENSEREQUIRED, "/" + OPERATION_PATH_SECTIONS + "/" + config.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemService getItemService() {
|
||||||
|
return itemService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemService(ItemService itemService) {
|
||||||
|
this.itemService = itemService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if at least one Creative Commons License is required when submitting a new Item.
|
||||||
|
* @return true if a Creative Commons License is required setting true for the property cc.license.required.
|
||||||
|
*/
|
||||||
|
public Boolean isRequired() {
|
||||||
|
return configurationService.getBooleanProperty("cc.license.required", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform validation on the item and config(ccLicense).
|
||||||
|
* @param obj The submission to be validated.
|
||||||
|
* @param config The configuration for the submission step for cclicense.
|
||||||
|
* @return A list of validation errors.
|
||||||
|
* @throws SQLException If there is a problem accessing the database.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends ErrorRest> validate(SubmissionService submissionService,
|
||||||
|
InProgressSubmission obj,
|
||||||
|
SubmissionStepConfig config)
|
||||||
|
throws DCInputsReaderException, SQLException {
|
||||||
|
|
||||||
|
if (this.isRequired() && obj != null && obj.getItem() != null) {
|
||||||
|
return validateLicense(obj.getItem(), config);
|
||||||
|
} else {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -27,6 +27,11 @@
|
|||||||
<property name="uploadConfigurationService" ref="uploadConfigurationService"/>
|
<property name="uploadConfigurationService" ref="uploadConfigurationService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean name="cclicenseValidation" class="org.dspace.app.rest.submit.step.validation.CclicenseValidator">
|
||||||
|
<property name="itemService" ref="org.dspace.content.ItemServiceImpl"/>
|
||||||
|
<property name="name" value="cclicense"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
<bean name="licenseValidation" class="org.dspace.app.rest.submit.step.validation.LicenseValidation">
|
<bean name="licenseValidation" class="org.dspace.app.rest.submit.step.validation.LicenseValidation">
|
||||||
<property name="name" value="license"/>
|
<property name="name" value="license"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
@@ -9785,4 +9785,47 @@ ResourcePolicyBuilder.createResourcePolicy(context, null, adminGroup)
|
|||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.sections.upload.primary", is(idFirstPdf.get())));
|
.andExpect(jsonPath("$.sections.upload.primary", is(idFirstPdf.get())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createWorkspaceWithoutCclicense_CclicenseRequired() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
|
//1. A community-collection structure with one parent community with sub-community and one collection.
|
||||||
|
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||||
|
.withName("Parent Community")
|
||||||
|
.build();
|
||||||
|
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
|
||||||
|
.withName("Sub Community")
|
||||||
|
.build();
|
||||||
|
Collection col1 = CollectionBuilder.createCollection(context, child1)
|
||||||
|
.withName("Collection 1")
|
||||||
|
.withSubmitterGroup(eperson)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
String authToken = getAuthToken(eperson.getEmail(), password);
|
||||||
|
|
||||||
|
//disable file upload mandatory
|
||||||
|
configurationService.setProperty("webui.submit.upload.required", false);
|
||||||
|
configurationService.setProperty("cc.license.required", true);
|
||||||
|
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
AtomicReference<Integer> idRef = new AtomicReference<>();
|
||||||
|
try {
|
||||||
|
// create an empty workspaceitem explicitly in the col1, check validation on creation
|
||||||
|
getClient(authToken).perform(post("/api/submission/workspaceitems")
|
||||||
|
.param("owningCollection", col1.getID().toString())
|
||||||
|
.contentType(org.springframework.http.MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().isCreated())
|
||||||
|
// cclicense is required
|
||||||
|
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.cclicense.required')]",
|
||||||
|
contains(
|
||||||
|
hasJsonPath("$.paths", contains(
|
||||||
|
hasJsonPath("$", Matchers.is("/sections/cclicense"))
|
||||||
|
)))))
|
||||||
|
.andDo(result -> idRef.set(read(result.getResponse().getContentAsString(), "$.id")));
|
||||||
|
} finally {
|
||||||
|
WorkspaceItemBuilder.deleteWorkspaceItem(idRef.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -996,6 +996,11 @@ metadata.hide.person.email = true
|
|||||||
# dspace-angular environment configuration property submission.typeBind.field
|
# dspace-angular environment configuration property submission.typeBind.field
|
||||||
#submit.type-bind.field = dc.type
|
#submit.type-bind.field = dc.type
|
||||||
|
|
||||||
|
# Wheter or not we REQUIRE that the cclicense is provided
|
||||||
|
# during the cclicense step in the submission process
|
||||||
|
# Defaults to false; If you set to 'true', submitter needs to provide cclicense
|
||||||
|
#cc.license.required = true
|
||||||
|
|
||||||
#### Creative Commons settings ######
|
#### Creative Commons settings ######
|
||||||
|
|
||||||
# The url to the web service API
|
# The url to the web service API
|
||||||
|
Reference in New Issue
Block a user