Skip to content

Commit

Permalink
Merged in DSC-1393 (pull request DSpace#1338)
Browse files Browse the repository at this point in the history
DSC-1393

Approved-by: Giuseppe Digilio
  • Loading branch information
vins01-4science authored and atarix83 committed Nov 24, 2023
2 parents 9dc73b9 + 5d599bd commit 177fdf0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
public class LicenseValidator implements SubmissionStepValidator {

private static final String ERROR_VALIDATION_LICENSEREQUIRED = "error.validation.license.notgranted";
public static final String ERROR_VALIDATION_LICENSEREQUIRED = "error.validation.license.required";

private String name;

Expand Down
10 changes: 6 additions & 4 deletions dspace-api/src/test/java/org/dspace/harvest/OAIHarvesterIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.util.UUIDUtils;
import org.dspace.validation.LicenseValidator;
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
import org.dspace.xmlworkflow.storedcomponents.PoolTask;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
Expand Down Expand Up @@ -1302,7 +1303,8 @@ public void testRunHarvestWithEmailSentIfItemValidationFails() throws Exception
assertThat(errorDetails.getMessages(), hasSize(2));
assertThat(errorDetails.getMessages(), hasItem("error.validation.filerequired - [/sections/upload]"));
assertThat(errorDetails.getMessages(),
hasItem("error.validation.license.notgranted - [/sections/license]"));
hasItem(LicenseValidator.ERROR_VALIDATION_LICENSEREQUIRED + " - [/sections/license]")
);

verifyNoMoreInteractions(mockClient, mockEmailSender);

Expand Down Expand Up @@ -1425,15 +1427,15 @@ public void testRunHarvestWithEmailSentIfItemAndRecordValidationFails() throws E
List<String> messages = errorDetails.getMessages();
assertThat(messages, hasSize(3));
assertThat(messages, hasItem("error.validation.filerequired - [/sections/upload]"));
assertThat(messages, hasItem("error.validation.license.notgranted - [/sections/license]"));
assertThat(messages, hasItem(LicenseValidator.ERROR_VALIDATION_LICENSEREQUIRED + " - [/sections/license]"));
assertThat(messages, hasItem("error.validation.required - [/sections/publication/dc.date.issued]"));

errorDetails = errors.get("oai:test-harvest:Publications/123456789/1002");
assertThat(errorDetails.getAction(), is("created"));
messages = errorDetails.getMessages();
assertThat(messages, hasSize(3));
assertThat(messages, hasItem("error.validation.filerequired - [/sections/upload]"));
assertThat(messages, hasItem("error.validation.license.notgranted - [/sections/license]"));
assertThat(messages, hasItem(LicenseValidator.ERROR_VALIDATION_LICENSEREQUIRED + " - [/sections/license]"));
assertThat(errorDetails.getMessages(), hasItem(containsString("Element 'oai_cerif:Publishers' "
+ "cannot have character [children]")));

Expand All @@ -1442,7 +1444,7 @@ public void testRunHarvestWithEmailSentIfItemAndRecordValidationFails() throws E
messages = errorDetails.getMessages();
assertThat(messages, hasSize(2));
assertThat(messages, hasItem("error.validation.filerequired - [/sections/upload]"));
assertThat(messages, hasItem("error.validation.license.notgranted - [/sections/license]"));
assertThat(messages, hasItem(LicenseValidator.ERROR_VALIDATION_LICENSEREQUIRED + " - [/sections/license]"));

verifyNoMoreInteractions(mockClient, mockEmailSender);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.supervision.SupervisionOrder;
import org.dspace.util.UUIDUtils;
import org.dspace.validation.LicenseValidator;
import org.dspace.versioning.ItemCorrectionProvider;
import org.hamcrest.Matchers;
import org.junit.Before;
Expand All @@ -130,6 +131,8 @@
*/
public class WorkspaceItemRestRepositoryIT extends AbstractControllerIntegrationTest {

public static final String LICENSE_ERROR_MESSAGE_PATH =
"$.errors[?(@.message=='" + LicenseValidator.ERROR_VALIDATION_LICENSEREQUIRED + "')]";
@Autowired
private CollectionService cs;
@Autowired
Expand Down Expand Up @@ -4597,8 +4600,18 @@ public void patchRejectLicenseTest() throws Exception {
.content(patchBody)
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.license.notgranted')]",
contains( hasJsonPath("$.paths", contains(hasJsonPath("$", is("/sections/license")))))))
.andExpect(
jsonPath(

LICENSE_ERROR_MESSAGE_PATH,
contains(
hasJsonPath(
"$.paths",
contains(hasJsonPath("$", is("/sections/license")))
)
)
)
)
.andExpect(jsonPath("$.sections.license.granted",
is(false)))
.andExpect(jsonPath("$.sections.license.acceptanceDate").isEmpty())
Expand All @@ -4608,8 +4621,8 @@ public void patchRejectLicenseTest() throws Exception {
// verify that the patch changes have been persisted
getClient(authToken).perform(get("/api/submission/workspaceitems/" + witem.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.license.notgranted')]",
contains( hasJsonPath("$.paths", contains(hasJsonPath("$", is("/sections/license")))))))
.andExpect(jsonPath(LICENSE_ERROR_MESSAGE_PATH,
contains( hasJsonPath("$.paths", contains(hasJsonPath("$", is("/sections/license")))))))
.andExpect(jsonPath("$.sections.license.granted",
is(false)))
.andExpect(jsonPath("$.sections.license.acceptanceDate").isEmpty())
Expand All @@ -4625,8 +4638,12 @@ public void patchRejectLicenseTest() throws Exception {
.content(patchBody)
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.license.notgranted')]",
contains( hasJsonPath("$.paths", contains(hasJsonPath("$", is("/sections/license")))))))
.andExpect(jsonPath(LICENSE_ERROR_MESSAGE_PATH,
contains(
hasJsonPath("$.paths",
contains(hasJsonPath("$", is("/sections/license"))))
)
))
.andExpect(jsonPath("$.sections.license.granted",
is(false)))
.andExpect(jsonPath("$.sections.license.acceptanceDate").isEmpty())
Expand All @@ -4636,8 +4653,8 @@ public void patchRejectLicenseTest() throws Exception {
// verify that the patch changes have been persisted
getClient(authToken).perform(get("/api/submission/workspaceitems/" + witem2.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.license.notgranted')]",
contains( hasJsonPath("$.paths", contains(hasJsonPath("$", is("/sections/license")))))))
.andExpect(jsonPath(LICENSE_ERROR_MESSAGE_PATH,
contains( hasJsonPath("$.paths", contains(hasJsonPath("$", is("/sections/license")))))))
.andExpect(jsonPath("$.sections.license.granted",
is(false)))
.andExpect(jsonPath("$.sections.license.acceptanceDate").isEmpty())
Expand All @@ -4653,8 +4670,13 @@ public void patchRejectLicenseTest() throws Exception {
.content(patchBody)
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.license.notgranted')]",
contains( hasJsonPath("$.paths", contains(hasJsonPath("$", is("/sections/license")))))))
.andExpect(jsonPath(LICENSE_ERROR_MESSAGE_PATH,
contains(
hasJsonPath("$.paths",
contains(hasJsonPath("$", is("/sections/license")))
)
)
))
.andExpect(jsonPath("$.sections.license.granted",
is(false)))
.andExpect(jsonPath("$.sections.license.acceptanceDate").isEmpty())
Expand All @@ -4664,8 +4686,13 @@ public void patchRejectLicenseTest() throws Exception {
// verify that the patch changes have been persisted
getClient(authToken).perform(get("/api/submission/workspaceitems/" + witem3.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.license.notgranted')]",
contains( hasJsonPath("$.paths", contains(hasJsonPath("$", is("/sections/license")))))))
.andExpect(jsonPath(LICENSE_ERROR_MESSAGE_PATH,
contains(
hasJsonPath("$.paths",
contains(hasJsonPath("$", is("/sections/license")))
)
)
))
.andExpect(jsonPath("$.sections.license.granted",
is(false)))
.andExpect(jsonPath("$.sections.license.acceptanceDate").isEmpty())
Expand All @@ -4681,8 +4708,14 @@ public void patchRejectLicenseTest() throws Exception {
.content(patchBody)
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.license.notgranted')]",
contains( hasJsonPath("$.paths", contains(hasJsonPath("$", is("/sections/license")))))))
.andExpect(jsonPath(LICENSE_ERROR_MESSAGE_PATH,
contains(
hasJsonPath(
"$.paths",
contains(hasJsonPath("$", is("/sections/license")))
)
)
))
.andExpect(jsonPath("$.sections.license.granted",
is(false)))
.andExpect(jsonPath("$.sections.license.acceptanceDate").isEmpty())
Expand All @@ -4692,8 +4725,8 @@ public void patchRejectLicenseTest() throws Exception {
// verify that the patch changes have been persisted
getClient(authToken).perform(get("/api/submission/workspaceitems/" + witem4.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.license.notgranted')]",
contains( hasJsonPath("$.paths", contains(hasJsonPath("$", is("/sections/license")))))))
.andExpect(jsonPath(LICENSE_ERROR_MESSAGE_PATH,
contains( hasJsonPath("$.paths", contains(hasJsonPath("$", is("/sections/license")))))))
.andExpect(jsonPath("$.sections.license.granted",
is(false)))
.andExpect(jsonPath("$.sections.license.acceptanceDate").isEmpty())
Expand Down

0 comments on commit 177fdf0

Please sign in to comment.