#65: Add subject and identifier metadata

This commit is contained in:
jendib 2016-02-13 18:47:13 +01:00
parent 509ab82745
commit 34d1422868
14 changed files with 126 additions and 156 deletions

View File

@ -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());

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
/**
* Getter of createDate.
*
* @return the createDate
*/
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 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;
}

View File

@ -1 +1 @@
db.version=5
db.version=6

View File

@ -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';

View File

@ -1,3 +1,3 @@
api.current_version=${project.version}
api.min_version=1.0
db.version=5
db.version=6

View File

@ -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<String> 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<String> 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);
}

View File

@ -18,6 +18,20 @@
name="description" ng-model="document.description" ng-disabled="fileIsUploading"></textarea>
</div>
</div>
<div class="form-group" ng-class="{ 'has-error': !documentForm.subject.$valid }">
<label class="col-sm-2 control-label" for="inputSubject">Subject</label>
<div class="col-sm-10">
<input ng-maxlength="500" class="form-control" type="text" id="inputSubject"
placeholder="Subject" name="subject" ng-model="document.subject" ng-disabled="fileIsUploading" />
</div>
</div>
<div class="form-group" ng-class="{ 'has-error': !documentForm.identifier.$valid }">
<label class="col-sm-2 control-label" for="inputIdentifier">Identifier</label>
<div class="col-sm-10">
<input ng-maxlength="500" class="form-control" type="text" id="inputIdentifier"
placeholder="Identifier" name="identifier" ng-model="document.identifier" ng-disabled="fileIsUploading" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="inputCreateDate">Creation date</label>
<div class="col-sm-10">

View File

@ -1,4 +1,10 @@
<p class="well-sm" ng-bind-html="document.description | newline"></p>
<dl class="dl-horizontal">
<dt ng-if="document.subject">Subject</dt>
<dd ng-if="document.subject">{{ document.subject }}</dd>
<dt ng-if="document.identifier">Identifier</dt>
<dd ng-if="document.identifier">{{ document.identifier }}</dd>
</dl>
<div ng-file-drop drag-over-class="bg-success" ng-multiple="true" allow-dir="false" ng-model="dropFiles"
accept="image/*,application/pdf,application/zip" ng-file-change="fileDropped($files, $event, $rejectedFiles)">

View File

@ -34,6 +34,12 @@
</div>
<p ng-bind-html="document.description | newline"></p>
<dl class="dl-horizontal">
<dt ng-if="document.subject">Subject</dt>
<dd ng-if="document.subject">{{ document.subject }}</dd>
<dt ng-if="document.identifier">Identifier</dt>
<dd ng-if="document.identifier">{{ document.identifier }}</dd>
</dl>
<div class="row" ui-sortable="fileSortableOptions" ng-model="files" ng-show="files.length > 0">
<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 text-center" ng-repeat="file in files">

View File

@ -1,3 +1,3 @@
api.current_version=${project.version}
api.min_version=1.0
db.version=5
db.version=6

View File

@ -1,3 +1,3 @@
api.current_version=${project.version}
api.min_version=1.0
db.version=5
db.version=6

View File

@ -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");