mirror of
https://github.com/sismics/docs.git
synced 2025-12-13 01:36:18 +00:00
#254: display documents in grid + concept of main file
This commit is contained in:
@@ -189,20 +189,35 @@ public class DocumentDao {
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a document.
|
||||
* Update a document and log the action.
|
||||
*
|
||||
* @param document Document to update
|
||||
* @param userId User ID
|
||||
* @return Updated document
|
||||
*/
|
||||
public Document update(Document document, String userId) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
Document documentDb = updateSilently(document);
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(documentDb, AuditLogType.UPDATE, userId);
|
||||
|
||||
return documentDb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a document without audit log.
|
||||
*
|
||||
* @param document Document to update
|
||||
* @return Updated document
|
||||
*/
|
||||
public Document updateSilently(Document document) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
|
||||
// Get the document
|
||||
Query q = em.createQuery("select d from Document d where d.id = :id and d.deleteDate is null");
|
||||
q.setParameter("id", document.getId());
|
||||
Document documentDb = (Document) q.getSingleResult();
|
||||
|
||||
|
||||
// Update the document
|
||||
documentDb.setTitle(document.getTitle());
|
||||
documentDb.setDescription(document.getDescription());
|
||||
@@ -216,11 +231,9 @@ public class DocumentDao {
|
||||
documentDb.setRights(document.getRights());
|
||||
documentDb.setCreateDate(document.getCreateDate());
|
||||
documentDb.setLanguage(document.getLanguage());
|
||||
documentDb.setFileId(document.getFileId());
|
||||
documentDb.setUpdateDate(new Date());
|
||||
|
||||
// Create audit log
|
||||
AuditLogUtil.create(documentDb, AuditLogType.UPDATE, userId);
|
||||
|
||||
|
||||
return documentDb;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,12 @@ public class DocumentDto {
|
||||
* Document ID.
|
||||
*/
|
||||
private String id;
|
||||
|
||||
|
||||
/**
|
||||
* Main file ID.
|
||||
*/
|
||||
private String fileId;
|
||||
|
||||
/**
|
||||
* Title.
|
||||
*/
|
||||
@@ -114,6 +119,15 @@ public class DocumentDto {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFileId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
public DocumentDto setFileId(String fileId) {
|
||||
this.fileId = fileId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@ import com.google.common.eventbus.AllowConcurrentEvents;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.sismics.docs.core.dao.ContributorDao;
|
||||
import com.sismics.docs.core.dao.DocumentDao;
|
||||
import com.sismics.docs.core.dao.FileDao;
|
||||
import com.sismics.docs.core.event.DocumentUpdatedAsyncEvent;
|
||||
import com.sismics.docs.core.model.context.AppContext;
|
||||
import com.sismics.docs.core.model.jpa.Contributor;
|
||||
import com.sismics.docs.core.model.jpa.Document;
|
||||
import com.sismics.docs.core.model.jpa.File;
|
||||
import com.sismics.docs.core.util.TransactionUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -38,13 +40,25 @@ public class DocumentUpdatedAsyncListener {
|
||||
}
|
||||
|
||||
TransactionUtil.handle(() -> {
|
||||
// Update index
|
||||
// Get the document
|
||||
DocumentDao documentDao = new DocumentDao();
|
||||
Document document = documentDao.getById(event.getDocumentId());
|
||||
if (document == null) {
|
||||
// Document deleted since event fired
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the main file
|
||||
FileDao fileDao = new FileDao();
|
||||
List<File> fileList = fileDao.getByDocumentId(null, event.getDocumentId());
|
||||
if (fileList.isEmpty()) {
|
||||
document.setFileId(null);
|
||||
} else {
|
||||
document.setFileId(fileList.get(0).getId());
|
||||
}
|
||||
|
||||
// Update database and index
|
||||
documentDao.updateSilently(document);
|
||||
AppContext.getInstance().getIndexingHandler().updateDocument(document);
|
||||
|
||||
// Update contributors list
|
||||
|
||||
@@ -29,6 +29,12 @@ public class Document implements Loggable {
|
||||
@Column(name = "DOC_IDUSER_C", nullable = false, length = 36)
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* Main file ID.
|
||||
*/
|
||||
@Column(name = "DOC_IDFILE_C", length = 36)
|
||||
private String fileId;
|
||||
|
||||
/**
|
||||
* Language (ISO 639-9).
|
||||
*/
|
||||
@@ -137,6 +143,15 @@ public class Document implements Loggable {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getFileId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
public Document setFileId(String fileId) {
|
||||
this.fileId = fileId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ public class LuceneIndexingHandler implements IndexingHandler {
|
||||
List<String> criteriaList = new ArrayList<>();
|
||||
Map<String, String> documentSearchMap = Maps.newHashMap();
|
||||
|
||||
StringBuilder sb = new StringBuilder("select distinct d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3, d.DOC_LANGUAGE_C c4, ");
|
||||
StringBuilder sb = new StringBuilder("select distinct d.DOC_ID_C c0, d.DOC_TITLE_C c1, d.DOC_DESCRIPTION_C c2, d.DOC_CREATEDATE_D c3, d.DOC_LANGUAGE_C c4, d.DOC_IDFILE_C, ");
|
||||
sb.append(" s.count c5, ");
|
||||
sb.append(" f.count c6, ");
|
||||
sb.append(" rs2.RTP_ID_C c7, rs2.RTP_NAME_C, d.DOC_UPDATEDATE_D c8 ");
|
||||
@@ -323,6 +323,7 @@ public class LuceneIndexingHandler implements IndexingHandler {
|
||||
documentDto.setDescription((String) o[i++]);
|
||||
documentDto.setCreateTimestamp(((Timestamp) o[i++]).getTime());
|
||||
documentDto.setLanguage((String) o[i++]);
|
||||
documentDto.setFileId((String) o[i++]);
|
||||
Number shareCount = (Number) o[i++];
|
||||
documentDto.setShared(shareCount != null && shareCount.intValue() > 0);
|
||||
Number fileCount = (Number) o[i++];
|
||||
|
||||
@@ -1 +1 @@
|
||||
db.version=20
|
||||
db.version=21
|
||||
@@ -0,0 +1,4 @@
|
||||
alter table T_DOCUMENT add column DOC_IDFILE_C varchar(36);
|
||||
alter table T_DOCUMENT add constraint FK_DOC_IDFILE_C foreign key (DOC_IDFILE_C) references T_FILE (FIL_ID_C) on delete restrict on update restrict;
|
||||
|
||||
update T_CONFIG set CFG_VALUE_C = '21' where CFG_ID_C = 'DB_VERSION';
|
||||
Reference in New Issue
Block a user