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

View File

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

View File

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

View File

@ -104,7 +104,8 @@ public class TestAclResource extends BaseJerseyTest {
json = target().path("/document/" + document1Id).request() json = target().path("/document/" + document1Id).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl2Token) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, acl2Token)
.post(Entity.form(new Form() .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")); Assert.assertEquals(document1Id, json.getString("id"));
// Get the document as acl2 // 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("source", "My new source for document 1")
.param("type", "Image") .param("type", "Image")
.param("coverage", "France") .param("coverage", "France")
.param("language", "eng")
.param("rights", "All Rights Reserved") .param("rights", "All Rights Reserved")
.param("tags", tag2Id)), JsonObject.class); .param("tags", tag2Id)), JsonObject.class);
Assert.assertEquals(document1Id, json.getString("id")); Assert.assertEquals(document1Id, json.getString("id"));
@ -289,7 +290,7 @@ public class TestDocumentResource extends BaseJerseyTest {
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
.post(Entity.form(new Form() .post(Entity.form(new Form()
.param("title", "My super title document 2") .param("title", "My super title document 2")
.param("lang", "eng")), JsonObject.class); .param("language", "eng")), JsonObject.class);
Assert.assertEquals(document2Id, json.getString("id")); Assert.assertEquals(document2Id, json.getString("id"));
// Search documents by query // Search documents by query

View File

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