Nullable document metadata can be emptied

This commit is contained in:
jendib 2016-03-15 00:58:55 +01:00
parent 00ee2d3bf6
commit 0fab8ff935
6 changed files with 29 additions and 41 deletions

View File

@ -27,7 +27,6 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.StreamingOutput;
import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
@ -547,8 +546,8 @@ public class DocumentResource extends BaseResource {
}
// Validate input data
title = ValidationUtil.validateLength(title, "title", 1, 100, true);
language = ValidationUtil.validateLength(language, "language", 3, 3, true);
title = ValidationUtil.validateLength(title, "title", 1, 100, false);
language = ValidationUtil.validateLength(language, "language", 3, 3, false);
description = ValidationUtil.validateLength(description, "description", 0, 4000, true);
subject = ValidationUtil.validateLength(subject, "subject", 0, 500, true);
identifier = ValidationUtil.validateLength(identifier, "identifier", 0, 500, true);
@ -577,41 +576,21 @@ public class DocumentResource extends BaseResource {
}
// Update the document
if (!StringUtils.isEmpty(title)) {
document.setTitle(title);
}
if (!StringUtils.isEmpty(description)) {
document.setDescription(description);
}
if (!StringUtils.isEmpty(subject)) {
document.setSubject(subject);
}
if (!StringUtils.isEmpty(identifier)) {
document.setIdentifier(identifier);
}
if (!StringUtils.isEmpty(publisher)) {
document.setPublisher(publisher);
}
if (!StringUtils.isEmpty(format)) {
document.setFormat(format);
}
if (!StringUtils.isEmpty(source)) {
document.setSource(source);
}
if (!StringUtils.isEmpty(type)) {
document.setType(type);
}
if (!StringUtils.isEmpty(coverage)) {
document.setCoverage(coverage);
}
if (!StringUtils.isEmpty(rights)) {
document.setRights(rights);
}
if (createDate != null) {
document.setCreateDate(createDate);
}
if (language != null) {
document.setLanguage(language);
if (createDate == null) {
document.setCreateDate(new Date());
} else {
document.setCreateDate(createDate);
}
document = documentDao.update(document, principal.getId());

View File

@ -98,6 +98,7 @@
<label class="col-sm-2 control-label" for="inputType">Type</label>
<div class="col-sm-10">
<select class="form-control" id="inputType" name="type" ng-model="document.type" ng-disabled="fileIsUploading">
<option value=""></option>
<option ng-repeat="vocabulary in vocabularies['type']">{{ vocabulary.value }}</option>
</select>
</div>
@ -106,6 +107,7 @@
<label class="col-sm-2 control-label" for="inputCoverage">Coverage</label>
<div class="col-sm-10">
<select class="form-control" id="inputCoverage" name="coverage" ng-model="document.coverage" ng-disabled="fileIsUploading">
<option value=""></option>
<option ng-repeat="vocabulary in vocabularies['coverage']">{{ vocabulary.value }}</option>
</select>
</div>
@ -114,6 +116,7 @@
<label class="col-sm-2 control-label" for="inputRights">Rights</label>
<div class="col-sm-10">
<select class="form-control" id="inputRights" name="rights" ng-model="document.rights" ng-disabled="fileIsUploading">
<option value=""></option>
<option ng-repeat="vocabulary in vocabularies['rights']">{{ vocabulary.value }}</option>
</select>
</div>

View File

@ -26,8 +26,8 @@
</span>
</span>
</dd>
<dt>Relations</dt>
<dd>
<dt ng-if="document.relations.length > 0">Relations</dt>
<dd ng-if="document.relations.length > 0">
<span ng-repeat="relation in document.relations">
<span class="btn btn-link btn-xs">
<a href="#/document/view/{{ relation.id }}">

View File

@ -104,7 +104,8 @@ public class TestAclResource extends BaseJerseyTest {
json = target().path("/document/" + document1Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl2Token)
.post(Entity.form(new Form()
.param("title", "My new super document 1")), JsonObject.class);
.param("title", "My new super document 1")
.param("language", "eng")), JsonObject.class);
Assert.assertEquals(document1Id, json.getString("id"));
// Get the document as acl2

View File

@ -280,6 +280,7 @@ public class TestDocumentResource extends BaseJerseyTest {
.param("source", "My new source for document 1")
.param("type", "Image")
.param("coverage", "France")
.param("language", "eng")
.param("rights", "All Rights Reserved")
.param("tags", tag2Id)), JsonObject.class);
Assert.assertEquals(document1Id, json.getString("id"));
@ -289,7 +290,7 @@ public class TestDocumentResource extends BaseJerseyTest {
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
.post(Entity.form(new Form()
.param("title", "My super title document 2")
.param("lang", "eng")), JsonObject.class);
.param("language", "eng")), JsonObject.class);
Assert.assertEquals(document2Id, json.getString("id"));
// Search documents by query

View File

@ -85,6 +85,8 @@ public class TestTagResource extends BaseJerseyTest {
response = target().path("/document/" + document2Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token)
.post(Entity.form(new Form()
.param("title", "My super document 2")
.param("language", "eng")
.param("tags", tag3Id)
.param("tags", tag4Id)));
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
@ -102,6 +104,8 @@ public class TestTagResource extends BaseJerseyTest {
response = target().path("/document/" + document2Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, tag1Token)
.post(Entity.form(new Form()
.param("title", "My super document 2")
.param("language", "eng")
.param("tags", tag4Id)));
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));