From 0fab8ff935907cb131b11b6d73bf23df5dfa9185 Mon Sep 17 00:00:00 2001 From: jendib Date: Tue, 15 Mar 2016 00:58:55 +0100 Subject: [PATCH] Nullable document metadata can be emptied --- .../docs/rest/resource/DocumentResource.java | 53 ++++++------------- .../src/partial/docs/document.edit.html | 3 ++ .../partial/docs/document.view.content.html | 4 +- .../sismics/docs/rest/TestAclResource.java | 3 +- .../docs/rest/TestDocumentResource.java | 3 +- .../sismics/docs/rest/TestTagResource.java | 4 ++ 6 files changed, 29 insertions(+), 41 deletions(-) diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java index 558be97b..9e2cd043 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/DocumentResource.java @@ -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,42 +576,22 @@ 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.setTitle(title); + document.setDescription(description); + document.setSubject(subject); + document.setIdentifier(identifier); + document.setPublisher(publisher); + document.setFormat(format); + document.setSource(source); + document.setType(type); + document.setCoverage(coverage); + document.setRights(rights); + document.setLanguage(language); + if (createDate == null) { + document.setCreateDate(new Date()); + } else { document.setCreateDate(createDate); } - if (language != null) { - document.setLanguage(language); - } document = documentDao.update(document, principal.getId()); diff --git a/docs-web/src/main/webapp/src/partial/docs/document.edit.html b/docs-web/src/main/webapp/src/partial/docs/document.edit.html index f057e0eb..e03bc32c 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.edit.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.edit.html @@ -98,6 +98,7 @@
@@ -106,6 +107,7 @@
@@ -114,6 +116,7 @@
diff --git a/docs-web/src/main/webapp/src/partial/docs/document.view.content.html b/docs-web/src/main/webapp/src/partial/docs/document.view.content.html index 699ccd49..15127f09 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.view.content.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.view.content.html @@ -26,8 +26,8 @@ -
Relations
-
+
Relations
+
diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestAclResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestAclResource.java index cd423707..aa8bc5cc 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestAclResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestAclResource.java @@ -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 diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestDocumentResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestDocumentResource.java index 5451a3ed..b48dd754 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestDocumentResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestDocumentResource.java @@ -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 diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java index af9c8eb3..49f68a9d 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestTagResource.java @@ -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()));