Skip to content

Commit d686233

Browse files
Issue 1295: Allow to submit item with only metadata - with no need to set Clarin License (#1302)
* Issue 1295: Allow to submit item with only metadata - with no need to set the Clarin License * checkstyle * fixed test failures * fixed IT test failures * resolve MR comments
1 parent bf20d76 commit d686233

File tree

10 files changed

+219
-16
lines changed

10 files changed

+219
-16
lines changed

dspace-api/src/test/data/dspaceFolder/config/item-submission.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,16 @@
109109
<!--Step will be to select a Creative Commons License -->
110110
<step-definition id="cclicense"> <heading>submit.progressbar.CClicense</heading>
111111
<processing-class>org.dspace.app.rest.submit.step.CCLicenseStep</processing-class>
112-
<type>cclicense</type>
112+
<type>cclicense</type>
113113
</step-definition>
114114

115-
<step-definition id="extractionstep">
115+
<step-definition id="clarin-license">
116+
<heading>submit.progressbar.clarin-license</heading>
117+
<processing-class>org.dspace.app.rest.submit.step.ClarinLicenseResourceStep</processing-class>
118+
<type>clarin-license</type>
119+
</step-definition>
120+
121+
<step-definition id="extractionstep">
116122
<heading>submit.progressbar.ExtractMetadataStep</heading>
117123
<processing-class>org.dspace.app.rest.submit.step.ExtractMetadataStep</processing-class>
118124
<type>extract</type>
@@ -219,6 +225,8 @@
219225
<!--Step will be to Sign off on the License -->
220226
<step id="license"/>
221227
<step id="cclicense"/>
228+
229+
<step id="clarin-license"/>
222230
</submission-process>
223231

224232
<submission-process name="languagetestprocess">

dspace-api/src/test/data/dspaceFolder/config/local.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,6 @@ webui.supported.locales = cs
331331
##### S3 #####
332332
# S3 direct download is not used in the test environment
333333
s3.download.direct.enabled = false
334+
335+
# Enable user registration for tests
336+
user.registration = true

dspace-api/src/test/java/org/dspace/builder/WorkspaceItemBuilder.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ protected WorkspaceItemBuilder(Context context) {
4141
}
4242

4343
public static WorkspaceItemBuilder createWorkspaceItem(final Context context, final Collection col) {
44-
WorkspaceItemBuilder builder = new WorkspaceItemBuilder(context);
45-
return builder.create(context, col, null);
44+
return createWorkspaceItem(context, col, null);
4645
}
4746

4847
public static WorkspaceItemBuilder createWorkspaceItem(final Context context, final Collection col, UUID uuid) {
4948
WorkspaceItemBuilder builder = new WorkspaceItemBuilder(context);
50-
return builder.create(context, col, uuid);
49+
return builder.create(context, col, uuid).withClarinLicense();
50+
}
51+
52+
public static WorkspaceItemBuilder createWorkspaceItemWithNoClarinLicense(final Context context,
53+
final Collection col) {
54+
WorkspaceItemBuilder builder = new WorkspaceItemBuilder(context);
55+
return builder.create(context, col, null);
5156
}
5257

5358
/**
@@ -226,6 +231,12 @@ public WorkspaceItemBuilder grantLicense() {
226231
return this;
227232
}
228233

234+
public WorkspaceItemBuilder withClarinLicense() {
235+
addMetadataValue(MetadataSchemaEnum.DC.getName(), "rights", null, "GNU General Public Licence, version 3");
236+
addMetadataValue(MetadataSchemaEnum.DC.getName(), "rights", "uri", "http://opensource.org/licenses/GPL-3.0");
237+
return addMetadataValue(MetadataSchemaEnum.DC.getName(), "rights", "label", "PUB");
238+
}
239+
229240
public WorkspaceItemBuilder withFulltext(String name, String source, InputStream is) {
230241
try {
231242
Item item = workspaceItem.getItem();

dspace-server-webapp/src/main/java/org/dspace/app/rest/submit/step/validation/ClarinLicenseResourceValidation.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ public List<? extends ErrorRest> validate(SubmissionService submissionService, I
4545
List<MetadataValue> licenseLabel = itemService.getMetadataByMetadataString(item, "dc.rights.label");
4646

4747
List<ErrorRest> errors = new ArrayList<>();
48-
if (CollectionUtils.isEmpty(licenseDefinition) || CollectionUtils.isEmpty(licenseName) ||
49-
CollectionUtils.isEmpty(licenseLabel)) {
50-
addError(errors, ERROR_VALIDATION_CLARIN_LICENSE_GRANTED,
51-
"/" + WorkspaceItemRestRepository.OPERATION_PATH_SECTIONS + "/"
52-
+ config.getId());
48+
// check that if there are local files, the license fields are filled
49+
if (hasFiles(item)) {
50+
if (CollectionUtils.isEmpty(licenseDefinition) || CollectionUtils.isEmpty(licenseName) ||
51+
CollectionUtils.isEmpty(licenseLabel)) {
52+
addError(errors, ERROR_VALIDATION_CLARIN_LICENSE_GRANTED,
53+
"/" + WorkspaceItemRestRepository.OPERATION_PATH_SECTIONS + "/"
54+
+ config.getId());
55+
}
5356
}
5457

55-
5658
return errors;
5759
}
5860

@@ -63,4 +65,13 @@ public ItemService getItemService() {
6365
public void setItemService(ItemService itemService) {
6466
this.itemService = itemService;
6567
}
68+
69+
private boolean hasFiles(Item item) {
70+
List<MetadataValue> hasFiles = itemService.getMetadataByMetadataString(item, "local.has.files");
71+
if (CollectionUtils.isEmpty(hasFiles)) {
72+
return false;
73+
} else {
74+
return "yes".equalsIgnoreCase(hasFiles.get(0).getValue());
75+
}
76+
}
6677
}

dspace-server-webapp/src/test/java/org/dspace/app/rest/CCLicenseAddPatchOperationIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void patchSubmissionCCLicense() throws Exception {
5353
.withName("Collection")
5454
.build();
5555

56-
WorkspaceItem workspaceItem = WorkspaceItemBuilder.createWorkspaceItem(context, collection)
56+
WorkspaceItem workspaceItem = WorkspaceItemBuilder.createWorkspaceItemWithNoClarinLicense(context, collection)
5757
.withTitle("Workspace Item")
5858
.build();
5959

@@ -93,7 +93,7 @@ public void patchSubmissionCCLicenseInvalid() throws Exception {
9393
.withName("Collection")
9494
.build();
9595

96-
WorkspaceItem workspaceItem = WorkspaceItemBuilder.createWorkspaceItem(context, collection)
96+
WorkspaceItem workspaceItem = WorkspaceItemBuilder.createWorkspaceItemWithNoClarinLicense(context, collection)
9797
.withTitle("Workspace Item")
9898
.build();
9999

dspace-server-webapp/src/test/java/org/dspace/app/rest/CCLicenseRemovePatchOperationIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void patchRemoveSubmissionCCLicense() throws Exception {
5353
.withName("Collection")
5454
.build();
5555

56-
WorkspaceItem workspaceItem = WorkspaceItemBuilder.createWorkspaceItem(context, collection)
56+
WorkspaceItem workspaceItem = WorkspaceItemBuilder.createWorkspaceItemWithNoClarinLicense(context, collection)
5757
.withTitle("Workspace Item")
5858
.build();
5959

@@ -115,7 +115,7 @@ public void patchRemoveSubmissionCCLicenseNonExisting() throws Exception {
115115
.withName("Collection")
116116
.build();
117117

118-
WorkspaceItem workspaceItem = WorkspaceItemBuilder.createWorkspaceItem(context, collection)
118+
WorkspaceItem workspaceItem = WorkspaceItemBuilder.createWorkspaceItemWithNoClarinLicense(context, collection)
119119
.withTitle("Workspace Item")
120120
.build();
121121

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
package org.dspace.app.rest;
9+
10+
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
11+
import static org.hamcrest.Matchers.contains;
12+
import static org.hamcrest.Matchers.hasSize;
13+
import static org.hamcrest.Matchers.is;
14+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
15+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
16+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
17+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
18+
19+
import java.io.InputStream;
20+
21+
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
22+
import org.dspace.builder.CollectionBuilder;
23+
import org.dspace.builder.CommunityBuilder;
24+
import org.dspace.builder.WorkspaceItemBuilder;
25+
import org.dspace.content.Collection;
26+
import org.dspace.content.Community;
27+
import org.dspace.content.WorkspaceItem;
28+
import org.dspace.content.service.CollectionService;
29+
import org.dspace.content.service.ItemService;
30+
import org.dspace.services.ConfigurationService;
31+
import org.junit.Before;
32+
import org.junit.Test;
33+
import org.springframework.beans.factory.annotation.Autowired;
34+
import org.springframework.mock.web.MockMultipartFile;
35+
36+
/**
37+
* Test suite for testing ClarinLicenseResourceValidation.
38+
*
39+
* @author Milan Kuchtiak
40+
*
41+
*/
42+
public class ClarinLicenseResourceValidationIT extends AbstractControllerIntegrationTest {
43+
44+
@Autowired
45+
private CollectionService cs;
46+
@Autowired
47+
private ItemService itemService;
48+
@Autowired
49+
private ConfigurationService configurationService;
50+
51+
@Before
52+
@Override
53+
public void setUp() throws Exception {
54+
super.setUp();
55+
56+
// make file upload mandatory in submissions
57+
configurationService.setProperty("webui.submit.upload.required", true);
58+
}
59+
60+
@Test
61+
public void createWorkspaceWithFiles_TitleAndClarinLicenseMissing() throws Exception {
62+
context.turnOffAuthorisationSystem();
63+
64+
parentCommunity = CommunityBuilder.createCommunity(context)
65+
.withName("Parent Community")
66+
.build();
67+
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
68+
.withName("Sub Community")
69+
.build();
70+
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
71+
72+
String authToken = getAuthToken(eperson.getEmail(), password);
73+
74+
WorkspaceItem wItem = WorkspaceItemBuilder.createWorkspaceItemWithNoClarinLicense(context, col1)
75+
.withIssueDate("2017-10-17")
76+
.grantLicense()
77+
.build();
78+
79+
InputStream pdf = getClass().getResourceAsStream("simple-article.pdf");
80+
final MockMultipartFile pdfFile = new MockMultipartFile("file", "/local/path/simple-article.pdf",
81+
"application/pdf", pdf);
82+
83+
context.restoreAuthSystemState();
84+
// upload the file in our workspaceitem
85+
getClient(authToken).perform(multipart("/api/submission/workspaceitems/" + wItem.getID())
86+
.file(pdfFile))
87+
.andExpect(status().isCreated())
88+
.andExpect(jsonPath("$.sections.upload.files[0].metadata['dc.title'][0].value",
89+
is("simple-article.pdf")))
90+
.andExpect(jsonPath("$.sections.upload.files[0].metadata['dc.source'][0].value",
91+
is("/local/path/simple-article.pdf")));
92+
93+
// Verify errors for missing title and clarin license
94+
getClient(authToken).perform(get("/api/submission/workspaceitems/" + wItem.getID()))
95+
.andExpect(status().isOk())
96+
.andExpect(jsonPath("$.errors", hasSize(2)))
97+
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.required')]",
98+
contains( hasJsonPath("$.paths",
99+
contains(hasJsonPath("$", is("/sections/traditionalpageone/dc.title")))))))
100+
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.clarin-license.notgranted')]",
101+
contains( hasJsonPath("$.paths",
102+
contains(hasJsonPath("$", is("/sections/clarin-license")))))));
103+
}
104+
105+
@Test
106+
public void createWorkspaceWithoutFiles_UploadRequired() throws Exception {
107+
context.turnOffAuthorisationSystem();
108+
109+
parentCommunity = CommunityBuilder.createCommunity(context)
110+
.withName("Parent Community")
111+
.build();
112+
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
113+
.withName("Sub Community")
114+
.build();
115+
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
116+
117+
String authToken = getAuthToken(eperson.getEmail(), password);
118+
119+
WorkspaceItem witem = WorkspaceItemBuilder.createWorkspaceItemWithNoClarinLicense(context, col1)
120+
.withTitle("Test WorkspaceItem")
121+
.withIssueDate("2017-10-17")
122+
.build();
123+
124+
context.restoreAuthSystemState();
125+
// Verify error for missing files (with upload required to be set to true)
126+
// Also check whether there is no error for missing license.
127+
// Since there are no files, the license is not required.
128+
getClient(authToken).perform(get("/api/submission/workspaceitems/" + witem.getID()))
129+
.andExpect(status().isOk())
130+
.andExpect(jsonPath("$.errors", hasSize(1)))
131+
.andExpect(jsonPath("$.errors[?(@.message=='error.validation.filerequired')]",
132+
contains(hasJsonPath("$.paths", contains(hasJsonPath("$", is("/sections/upload")))))));
133+
}
134+
135+
@Test
136+
public void createWorkspaceWithoutFiles_UploadNotRequired() throws Exception {
137+
context.turnOffAuthorisationSystem();
138+
139+
configurationService.setProperty("webui.submit.upload.required", false);
140+
141+
parentCommunity = CommunityBuilder.createCommunity(context)
142+
.withName("Parent Community")
143+
.build();
144+
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
145+
.withName("Sub Community")
146+
.build();
147+
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
148+
149+
String authToken = getAuthToken(eperson.getEmail(), password);
150+
151+
WorkspaceItem witem = WorkspaceItemBuilder.createWorkspaceItemWithNoClarinLicense(context, col1)
152+
.withTitle("Test WorkspaceItem")
153+
.withIssueDate("2017-10-17")
154+
.build();
155+
156+
context.restoreAuthSystemState();
157+
// Verify there are no errors (with upload required to be set to false).
158+
// Since there are no files, the license is not required.
159+
getClient(authToken).perform(get("/api/submission/workspaceitems/" + witem.getID()))
160+
.andExpect(status().isOk())
161+
.andExpect(jsonPath("$.errors").doesNotExist());
162+
}
163+
164+
}

dspace-server-webapp/src/test/java/org/dspace/app/rest/SubmissionDefinitionsControllerIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public void findSections() throws Exception {
205205
// We expect the content type to be "application/hal+json;charset=UTF-8"
206206
.andExpect(content().contentType(contentType))
207207
// Match only that a section exists with a submission configuration behind
208-
.andExpect(jsonPath("$._embedded.submissionsections", hasSize(9)))
208+
.andExpect(jsonPath("$._embedded.submissionsections", hasSize(10)))
209209
.andExpect(jsonPath("$._embedded.submissionsections",
210210
Matchers.hasItem(
211211
allOf(

dspace-server-webapp/src/test/java/org/dspace/app/rest/WorkspaceItemRestRepositoryIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ public void setUp() throws Exception {
150150
adminGroup = EPersonServiceFactory.getInstance().getGroupService().findByName(context, Group.ADMIN);
151151

152152
context.restoreAuthSystemState();
153+
154+
// make file upload mandatory in submissions
155+
configurationService.setProperty("webui.submit.upload.required", true);
153156
}
154157

155158
@Test

dspace/config/clarin-dspace.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,6 @@ plugin.sequence.org.dspace.authenticate.AuthenticationMethod = org.dspace.authen
341341
# self-registration(new registration), for the name/password authentication, is disabled
342342
# but existing users can still use the name/password authentication
343343
user.registration = false
344+
345+
# This option allows submitter to skip file upload step in the submission process
346+
webui.submit.upload.required = false

0 commit comments

Comments
 (0)