From 34d14228685cf07300a2bb55ae70eddbcd4329dc Mon Sep 17 00:00:00 2001 From: jendib Date: Sat, 13 Feb 2016 18:47:13 +0100 Subject: [PATCH] #65: Add subject and identifier metadata --- .../docs/core/dao/jpa/DocumentDao.java | 6 +- .../docs/core/dao/jpa/dto/DocumentDto.java | 102 +++++------------- .../docs/core/dao/lucene/LuceneDao.java | 12 ++- .../sismics/docs/core/model/jpa/Document.java | 100 +++++------------ .../src/main/resources/config.properties | 2 +- .../resources/db/update/dbupdate-006-0.sql | 3 + docs-web/src/dev/resources/config.properties | 2 +- .../docs/rest/resource/DocumentResource.java | 19 +++- .../src/partial/docs/document.edit.html | 14 +++ .../partial/docs/document.view.content.html | 6 ++ .../main/webapp/src/partial/share/share.html | 6 ++ docs-web/src/prod/resources/config.properties | 2 +- .../src/stress/resources/config.properties | 2 +- .../docs/rest/TestDocumentResource.java | 6 ++ 14 files changed, 126 insertions(+), 156 deletions(-) create mode 100644 docs-core/src/main/resources/db/update/dbupdate-006-0.sql diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java index 9be63b68..0d58e3b1 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/DocumentDao.java @@ -89,7 +89,7 @@ public class DocumentDao { */ public DocumentDto getDocument(String id) { EntityManager em = ThreadLocalContext.get().getEntityManager(); - StringBuilder sb = new StringBuilder("select d.DOC_ID_C, d.DOC_TITLE_C, d.DOC_DESCRIPTION_C, d.DOC_CREATEDATE_D, d.DOC_LANGUAGE_C, "); + StringBuilder sb = new StringBuilder("select d.DOC_ID_C, d.DOC_TITLE_C, d.DOC_DESCRIPTION_C, d.DOC_SUBJECT_C, d.DOC_IDENTIFIER_C, d.DOC_CREATEDATE_D, d.DOC_LANGUAGE_C, "); sb.append(" (select count(s.SHA_ID_C) from T_SHARE s, T_ACL ac where ac.ACL_SOURCEID_C = d.DOC_ID_C and ac.ACL_TARGETID_C = s.SHA_ID_C and ac.ACL_DELETEDATE_D is null and s.SHA_DELETEDATE_D is null), "); sb.append(" (select count(f.FIL_ID_C) from T_FILE f where f.FIL_DELETEDATE_D is null and f.FIL_IDDOC_C = d.DOC_ID_C), "); sb.append(" u.USE_USERNAME_C "); @@ -109,6 +109,8 @@ public class DocumentDao { documentDto.setId((String) o[i++]); documentDto.setTitle((String) o[i++]); documentDto.setDescription((String) o[i++]); + documentDto.setSubject((String) o[i++]); + documentDto.setIdentifier((String) o[i++]); documentDto.setCreateTimestamp(((Timestamp) o[i++]).getTime()); documentDto.setLanguage((String) o[i++]); documentDto.setShared(((Number) o[i++]).intValue() > 0); @@ -296,6 +298,8 @@ public class DocumentDao { // Update the document documentFromDb.setTitle(document.getTitle()); documentFromDb.setDescription(document.getDescription()); + documentFromDb.setSubject(document.getSubject()); + documentFromDb.setIdentifier(document.getIdentifier()); documentFromDb.setCreateDate(document.getCreateDate()); documentFromDb.setLanguage(document.getLanguage()); diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/dto/DocumentDto.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/dto/DocumentDto.java index 38414c80..e67a7f7d 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/dto/DocumentDto.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/dto/DocumentDto.java @@ -24,6 +24,16 @@ public class DocumentDto { */ private String description; + /** + * Subject. + */ + private String subject; + + /** + * Identifier. + */ + private String identifier; + /** * Language. */ @@ -49,142 +59,82 @@ public class DocumentDto { */ private String creator; - /** - * Getter de id. - * - * @return the id - */ public String getId() { return id; } - /** - * Setter de id. - * - * @param id id - */ public void setId(String id) { this.id = id; } - /** - * Getter de title. - * - * @return the title - */ public String getTitle() { return title; } - /** - * Setter de title. - * - * @param title title - */ public void setTitle(String title) { this.title = title; } - /** - * Getter de description. - * - * @return the description - */ public String getDescription() { return description; } - /** - * Setter de description. - * - * @param description description - */ public void setDescription(String description) { this.description = description; } - /** - * Getter de createTimestamp. - * - * @return the createTimestamp - */ + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + public Long getCreateTimestamp() { return createTimestamp; } - /** - * Setter of createTimestamp. - * - * @param createTimestamp createTimestamp - */ public void setCreateTimestamp(Long createTimestamp) { this.createTimestamp = createTimestamp; } - /** - * Getter of shared. - * - * @return the shared - */ public Boolean getShared() { return shared; } - /** - * Setter of shared. - * - * @param shared shared - */ public void setShared(Boolean shared) { this.shared = shared; } - /** - * Getter of language. - * - * @return the language - */ public String getLanguage() { return language; } - /** - * Setter of language. - * - * @param language language - */ public void setLanguage(String language) { this.language = language; } - /** - * Getter of fileCount. - * @return fileCount - */ public Integer getFileCount() { return fileCount; } - /** - * Setter of fileCount. - * @param fileCount fileCount - */ public void setFileCount(Integer fileCount) { this.fileCount = fileCount; } - /** - * Getter of creator. - * @return creator - */ public String getCreator() { return creator; } - /** - * Setter of creator. - * @param creator creator - */ public void setCreator(String creator) { this.creator = creator; } diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/lucene/LuceneDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/lucene/LuceneDao.java index c76113c7..cd2d1d0c 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/lucene/LuceneDao.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/lucene/LuceneDao.java @@ -159,6 +159,8 @@ public class LuceneDao { BooleanQuery query = new BooleanQuery(); query.add(qpHelper.parse(searchQuery, "title"), Occur.SHOULD); query.add(qpHelper.parse(searchQuery, "description"), Occur.SHOULD); + query.add(qpHelper.parse(searchQuery, "subject"), Occur.SHOULD); + query.add(qpHelper.parse(searchQuery, "identifier"), Occur.SHOULD); query.add(qpHelper.parse(fullSearchQuery, "content"), Occur.SHOULD); // Search @@ -198,12 +200,16 @@ public class LuceneDao { org.apache.lucene.document.Document luceneDocument = new org.apache.lucene.document.Document(); luceneDocument.add(new StringField("id", document.getId(), Field.Store.YES)); luceneDocument.add(new StringField("type", "document", Field.Store.YES)); - if (document.getTitle() != null) { - luceneDocument.add(new TextField("title", document.getTitle(), Field.Store.NO)); - } + luceneDocument.add(new TextField("title", document.getTitle(), Field.Store.NO)); if (document.getDescription() != null) { luceneDocument.add(new TextField("description", document.getDescription(), Field.Store.NO)); } + if (document.getSubject() != null) { + luceneDocument.add(new TextField("subject", document.getSubject(), Field.Store.NO)); + } + if (document.getIdentifier() != null) { + luceneDocument.add(new TextField("identifier", document.getIdentifier(), Field.Store.NO)); + } return luceneDocument; } diff --git a/docs-core/src/main/java/com/sismics/docs/core/model/jpa/Document.java b/docs-core/src/main/java/com/sismics/docs/core/model/jpa/Document.java index 12cb5a7c..2964a02d 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/model/jpa/Document.java +++ b/docs-core/src/main/java/com/sismics/docs/core/model/jpa/Document.java @@ -39,7 +39,7 @@ public class Document implements Loggable { /** * Title. */ - @Column(name = "DOC_TITLE_C", length = 100) + @Column(name = "DOC_TITLE_C", nullable = false, length = 100) private String title; /** @@ -48,6 +48,18 @@ public class Document implements Loggable { @Column(name = "DOC_DESCRIPTION_C", length = 4000) private String description; + /** + * Subject. + */ + @Column(name = "DOC_SUBJECT_C", length = 500) + private String subject; + + /** + * Identifer. + */ + @Column(name = "DOC_IDENTIFIER_C", length = 500) + private String identifier; + /** * Creation date. */ @@ -60,129 +72,75 @@ public class Document implements Loggable { @Column(name = "DOC_DELETEDATE_D") private Date deleteDate; - /** - * Getter of id. - * - * @return the id - */ public String getId() { return id; } - /** - * Setter of id. - * - * @param id id - */ public void setId(String id) { this.id = id; } - /** - * Getter of language. - * - * @return the language - */ public String getLanguage() { return language; } - /** - * Setter of language. - * - * @param language language - */ public void setLanguage(String language) { this.language = language; } - /** - * Getter of userId. - * - * @return the userId - */ public String getUserId() { return userId; } - /** - * Setter of userId. - * - * @param userId userId - */ public void setUserId(String userId) { this.userId = userId; } - /** - * Getter of title. - * - * @return the title - */ public String getTitle() { return title; } - /** - * Setter of title. - * - * @param title title - */ public void setTitle(String title) { this.title = title; } - /** - * Getter of description. - * - * @return the description - */ public String getDescription() { return description; } - /** - * Setter of description. - * - * @param description description - */ public void setDescription(String description) { this.description = description; } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } - /** - * Getter of createDate. - * - * @return the createDate - */ public Date getCreateDate() { return createDate; } - /** - * Setter of createDate. - * - * @param createDate createDate - */ public void setCreateDate(Date createDate) { this.createDate = createDate; } - /** - * Getter of deleteDate. - * - * @return the deleteDate - */ @Override public Date getDeleteDate() { return deleteDate; } - /** - * Setter of deleteDate. - * - * @param deleteDate deleteDate - */ public void setDeleteDate(Date deleteDate) { this.deleteDate = deleteDate; } diff --git a/docs-core/src/main/resources/config.properties b/docs-core/src/main/resources/config.properties index a8182ebd..cff11a73 100644 --- a/docs-core/src/main/resources/config.properties +++ b/docs-core/src/main/resources/config.properties @@ -1 +1 @@ -db.version=5 \ No newline at end of file +db.version=6 \ No newline at end of file diff --git a/docs-core/src/main/resources/db/update/dbupdate-006-0.sql b/docs-core/src/main/resources/db/update/dbupdate-006-0.sql new file mode 100644 index 00000000..3213010c --- /dev/null +++ b/docs-core/src/main/resources/db/update/dbupdate-006-0.sql @@ -0,0 +1,3 @@ +alter table T_DOCUMENT add column DOC_SUBJECT_C varchar(500); +alter table T_DOCUMENT add column DOC_IDENTIFIER_C varchar(500); +update T_CONFIG set CFG_VALUE_C = '6' where CFG_ID_C = 'DB_VERSION'; diff --git a/docs-web/src/dev/resources/config.properties b/docs-web/src/dev/resources/config.properties index 680c36e5..6c2faf82 100644 --- a/docs-web/src/dev/resources/config.properties +++ b/docs-web/src/dev/resources/config.properties @@ -1,3 +1,3 @@ api.current_version=${project.version} api.min_version=1.0 -db.version=5 \ No newline at end of file +db.version=6 \ No newline at end of file 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 2dda9242..e206b9cd 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 @@ -128,7 +128,8 @@ public class DocumentResource extends BaseResource { } // Below is specific to GET /document/id - + document.add("subject", JsonUtil.nullable(documentDto.getSubject())); + document.add("identifier", JsonUtil.nullable(documentDto.getIdentifier())); document.add("creator", documentDto.getCreator()); // Add ACL @@ -390,6 +391,8 @@ public class DocumentResource extends BaseResource { public Response add( @FormParam("title") String title, @FormParam("description") String description, + @FormParam("subject") String subject, + @FormParam("identifier") String identifier, @FormParam("tags") List tagList, @FormParam("language") String language, @FormParam("create_date") String createDateStr) { @@ -401,6 +404,8 @@ public class DocumentResource extends BaseResource { 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, "description", 0, 500, true); Date createDate = ValidationUtil.validateDate(createDateStr, "create_date", true); if (!Constants.SUPPORTED_LANGUAGES.contains(language)) { throw new ClientException("ValidationError", MessageFormat.format("{0} is not a supported language", language)); @@ -412,6 +417,8 @@ public class DocumentResource extends BaseResource { document.setUserId(principal.getId()); document.setTitle(title); document.setDescription(description); + document.setSubject(subject); + document.setIdentifier(identifier); document.setLanguage(language); if (createDate == null) { document.setCreateDate(new Date()); @@ -461,6 +468,8 @@ public class DocumentResource extends BaseResource { @PathParam("id") String id, @FormParam("title") String title, @FormParam("description") String description, + @FormParam("subject") String subject, + @FormParam("identifier") String identifier, @FormParam("tags") List tagList, @FormParam("language") String language, @FormParam("create_date") String createDateStr) { @@ -472,6 +481,8 @@ public class DocumentResource extends BaseResource { title = ValidationUtil.validateLength(title, "title", 1, 100, true); language = ValidationUtil.validateLength(language, "language", 3, 3, true); description = ValidationUtil.validateLength(description, "description", 0, 4000, true); + subject = ValidationUtil.validateLength(subject, "subject", 0, 500, true); + identifier = ValidationUtil.validateLength(identifier, "identifier", 0, 500, true); Date createDate = ValidationUtil.validateDate(createDateStr, "create_date", true); if (language != null && !Constants.SUPPORTED_LANGUAGES.contains(language)) { throw new ClientException("ValidationError", MessageFormat.format("{0} is not a supported language", language)); @@ -492,6 +503,12 @@ public class DocumentResource extends BaseResource { if (!StringUtils.isEmpty(description)) { document.setDescription(description); } + if (!StringUtils.isEmpty(subject)) { + document.setSubject(subject); + } + if (!StringUtils.isEmpty(identifier)) { + document.setIdentifier(identifier); + } if (createDate != null) { document.setCreateDate(createDate); } 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 736f1136..50738c40 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 @@ -18,6 +18,20 @@ name="description" ng-model="document.description" ng-disabled="fileIsUploading"> +
+ +
+ +
+
+
+ +
+ +
+
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 4d5d7a9d..a2d7b591 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 @@ -1,4 +1,10 @@

+
+
Subject
+
{{ document.subject }}
+
Identifier
+
{{ document.identifier }}
+
diff --git a/docs-web/src/main/webapp/src/partial/share/share.html b/docs-web/src/main/webapp/src/partial/share/share.html index 1f1e1d26..1f6a0964 100644 --- a/docs-web/src/main/webapp/src/partial/share/share.html +++ b/docs-web/src/main/webapp/src/partial/share/share.html @@ -34,6 +34,12 @@

+
+
Subject
+
{{ document.subject }}
+
Identifier
+
{{ document.identifier }}
+
diff --git a/docs-web/src/prod/resources/config.properties b/docs-web/src/prod/resources/config.properties index 680c36e5..6c2faf82 100644 --- a/docs-web/src/prod/resources/config.properties +++ b/docs-web/src/prod/resources/config.properties @@ -1,3 +1,3 @@ api.current_version=${project.version} api.min_version=1.0 -db.version=5 \ No newline at end of file +db.version=6 \ No newline at end of file diff --git a/docs-web/src/stress/resources/config.properties b/docs-web/src/stress/resources/config.properties index 680c36e5..6c2faf82 100644 --- a/docs-web/src/stress/resources/config.properties +++ b/docs-web/src/stress/resources/config.properties @@ -1,3 +1,3 @@ api.current_version=${project.version} api.min_version=1.0 -db.version=5 \ No newline at end of file +db.version=6 \ No newline at end of file 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 e48ada16..2bb7072c 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 @@ -62,6 +62,8 @@ public class TestDocumentResource extends BaseJerseyTest { .put(Entity.form(new Form() .param("title", "My super title document 1") .param("description", "My super description for document 1") + .param("subject", "Subject document 1") + .param("identifier", "Identifier document 1") .param("tags", tag1Id) .param("language", "eng") .param("create_date", Long.toString(create1Date))), JsonObject.class); @@ -160,6 +162,8 @@ public class TestDocumentResource extends BaseJerseyTest { Assert.assertEquals(1, searchDocuments("full:title", document1Token)); Assert.assertEquals(1, searchDocuments("title", document1Token)); Assert.assertEquals(1, searchDocuments("super description", document1Token)); + Assert.assertEquals(1, searchDocuments("subject", document1Token)); + Assert.assertEquals(1, searchDocuments("identifier", document1Token)); Assert.assertEquals(1, searchDocuments("at:" + DateTimeFormat.forPattern("yyyy").print(new Date().getTime()), document1Token)); Assert.assertEquals(1, searchDocuments("at:" + DateTimeFormat.forPattern("yyyy-MM").print(new Date().getTime()), document1Token)); Assert.assertEquals(1, searchDocuments("at:" + DateTimeFormat.forPattern("yyyy-MM-dd").print(new Date().getTime()), document1Token)); @@ -190,6 +194,8 @@ public class TestDocumentResource extends BaseJerseyTest { Assert.assertEquals(true, json.getBoolean("shared")); Assert.assertEquals("My super title document 1", json.getString("title")); Assert.assertEquals("My super description for document 1", json.getString("description")); + Assert.assertEquals("Subject document 1", json.getString("subject")); + Assert.assertEquals("Identifier document 1", json.getString("identifier")); Assert.assertEquals("eng", json.getString("language")); Assert.assertEquals(create1Date, json.getJsonNumber("create_date").longValue()); tags = json.getJsonArray("tags");