Skip to content

Commit

Permalink
#1298 Display last note in Documents grid
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Jan 6, 2025
1 parent 8bd7d65 commit b72e247
Show file tree
Hide file tree
Showing 130 changed files with 592 additions and 1,282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ private void printExtendedAttributes(DateFormat df, PrintWriter writer, Document
case Integer integer -> writer.print(Integer.toString(integer));
case Long longVal -> writer.print(Long.toString(longVal));
case Double doubleVal -> writer.print(Double.toString(doubleVal));
case String str -> writer.print(str);
default -> throw new IllegalArgumentException("Unexpected value: " + val);
}
writer.print("</ext_" + name + ">");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public abstract class AbstractDocument extends SecurableExtensibleObject impleme
public static final int NATURE_DOC = 0;

private String comment;

/**
* The text of the last note put on the document
*/
private String lastNote;

private long fileSize = 0;

Expand Down Expand Up @@ -1082,6 +1087,14 @@ public void setDocAttrs(int docAttrs) {
this.docAttrs = docAttrs;
}

public String getLastNote() {
return lastNote;
}

public void setLastNote(String lastNote) {
this.lastNote = lastNote;
}

@Override
public int hashCode() {
final int prime = 31;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ public Document copyToFolder(Document doc, Folder folder, DocumentHistory transa
private void copyNotes(Document sourceDocument, Document createdDocument) throws PersistenceException {
List<DocumentNote> docNotes = documentNoteDAO.findByDocId(sourceDocument.getId(),
sourceDocument.getFileVersion());
docNotes.sort((o1, o2) -> o1.getDate().compareTo(o2.getDate()));
for (DocumentNote docNote : docNotes) {
DocumentNote newNote = new DocumentNote(docNote);
newNote.setDocId(createdDocument.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import com.logicaldoc.core.PersistenceException;
import com.logicaldoc.core.security.Session;
import com.logicaldoc.core.security.SessionManager;
import com.logicaldoc.core.threading.ThreadPools;
import com.logicaldoc.util.Context;
import com.logicaldoc.util.html.HTMLSanitizer;

/**
* Hibernate implementation of <code>DocumentNoteDAO</code>
Expand Down Expand Up @@ -44,11 +46,31 @@ public void store(DocumentNote note) throws PersistenceException {

super.store(note);

if (doc.getIndexed() == AbstractDocument.INDEX_INDEXED) {
documentDao.initialize(doc);
doc.setIndexed(AbstractDocument.INDEX_TO_INDEX);
documentDao.store(doc);
}
updateLastNote(doc, note);
}

private void updateLastNote(Document doccument, DocumentNote note) {
// In case of note on the whole document, update the document's lastNote field
if (note.getPage() == 0)
ThreadPools.get().execute(() -> {
try {
DocumentDAO dao = Context.get(DocumentDAO.class);
Document document = dao.findById(note.getDocId());
dao.initialize(document);

String lastNoteMessage = dao.queryForList(
"select ld_message from ld_note where ld_page=0 and ld_id=:id order by ld_date desc",
Map.of("id", note.getDocId()), String.class, null).stream().findFirst()
.orElse(note.getMessage());

document.setLastNote(HTMLSanitizer.sanitizeSimpleText(lastNoteMessage));
if (doccument.getIndexed() == AbstractDocument.INDEX_INDEXED)
doccument.setIndexed(AbstractDocument.INDEX_TO_INDEX);
dao.store(document);
} catch (PersistenceException e) {
log.error(e.getMessage(), e);
}
}, "Note");
}

@Override
Expand Down Expand Up @@ -77,7 +99,8 @@ public List<DocumentNote> findByDocId(long docId, String fileVersion) throws Per
}

@Override
public List<DocumentNote> findByDocIdAndType(long docId, String fileVersion, String type) throws PersistenceException {
public List<DocumentNote> findByDocIdAndType(long docId, String fileVersion, String type)
throws PersistenceException {
return findByDocIdAndTypes(docId, fileVersion, StringUtils.isEmpty(type) ? null : Arrays.asList(type));
}

Expand Down Expand Up @@ -114,22 +137,22 @@ public List<DocumentNote> findByUserId(long userId) throws PersistenceException
return findByWhere(ENTITY + ".userId =" + userId, "order by " + ENTITY + ".date desc", null);
}

private void markToIndex(long docId) throws PersistenceException {
DocumentDAO documentDao = Context.get(DocumentDAO.class);
Document doc = documentDao.findById(docId);
if (doc != null && doc.getIndexed() == AbstractDocument.INDEX_INDEXED) {
documentDao.initialize(doc);
doc.setIndexed(AbstractDocument.INDEX_TO_INDEX);
documentDao.store(doc);
}
}

@Override
public void delete(long id, int code) throws PersistenceException {
DocumentNote note = findById(id);
if (note != null)
markToIndex(note.getDocId());
super.delete(id, code);
if (note != null) {
super.delete(id, code);
DocumentDAO documentDao = Context.get(DocumentDAO.class);
Document document = documentDao.findById(note.getDocId());
if (document != null && document.getIndexed() == AbstractDocument.INDEX_INDEXED) {
// Mark to index
documentDao.initialize(document);
document.setIndexed(AbstractDocument.INDEX_TO_INDEX);
documentDao.store(document);
updateLastNote(document, note);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public static Version create(Document document, User user, String comment, Strin
version.setWorkflowStatus(document.getWorkflowStatus());
version.setWorkflowStatusDisplay(document.getWorkflowStatusDisplay());
version.setColor(document.getColor());
version.setLastNote(document.getLastNote());

if (document.getTemplate() != null) {
version.setTemplateId(document.getTemplate().getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1438,15 +1438,9 @@ public Folder createPath(Folder parent, String path, boolean inheritSecurity, Fo

while (st.hasMoreTokens()) {
String name = st.nextToken();

Map<String, Object> params = new HashMap<>();
params.put("folderId", folder.getId());
params.put("name", name);
params.put("tenantId", folder.getTenantId());

long child = findIdsByWhere(
"_entity.parentId = :folderId and _entity.name = :name and _entity.tenantId = :tenantId", params,
null, null).stream().findFirst().orElse(0L);
long child = queryForLong(
"select ld_id from ld_folder where ld_deleted=0 and ld_parentid = :folderId and ld_name = :name and ld_tenantid = :tenantId",
Map.of("folderId", folder.getId(), "name", name, "tenantId", folder.getTenantId()));

if (child == 0L) {
Folder folderVO = new Folder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public Hit mapRow(ResultSet rs, int rowNum) throws SQLException {
hit.setLanguage(rs.getString(36));
hit.setPages(rs.getInt(37));
hit.setColor(rs.getString(38));
hit.setLastNote(rs.getString(39));

return hit;
}
Expand Down Expand Up @@ -197,7 +198,7 @@ public void internalSearch() throws SearchException {
richQuery.append(
" FOLD.ld_name, A.ld_folderid, A.ld_tgs tags, A.ld_templateid, C.ld_name, A.ld_tenantid, A.ld_docreftype, ");
richQuery.append(
" A.ld_stamped, A.ld_password, A.ld_workflowstatusdisp, A.ld_language, A.ld_pages, A.ld_color ");
" A.ld_stamped, A.ld_password, A.ld_workflowstatusdisp, A.ld_language, A.ld_pages, A.ld_color, A.ld_lastnote ");
richQuery.append(" from ld_document A ");
richQuery.append(" join ld_folder FOLD on A.ld_folderid=FOLD.ld_id ");
richQuery.append(" left outer join ld_template C on A.ld_templateid=C.ld_id ");
Expand Down Expand Up @@ -227,7 +228,7 @@ public void internalSearch() throws SearchException {
richQuery.append(
" FOLD.ld_name, A.ld_folderid, A.ld_tgs tags, REF.ld_templateid, C.ld_name, A.ld_tenantid, A.ld_docreftype, ");
richQuery.append(
" REF.ld_stamped, REF.ld_password, REF.ld_workflowstatusdisp, REF.ld_language, REF.ld_pages, A.ld_color ");
" REF.ld_stamped, REF.ld_password, REF.ld_workflowstatusdisp, REF.ld_language, REF.ld_pages, A.ld_color, A.ld_lastnote ");
richQuery.append(" from ld_document A ");
richQuery.append(" join ld_folder FOLD on A.ld_folderid=FOLD.ld_id ");
richQuery.append(" join ld_document REF on A.ld_docref=REF.ld_id ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private String prepareQuery() throws PersistenceException {
query.append(" A.ld_rating, A.ld_fileversion, A.ld_comment, A.ld_workflowstatus, A.ld_startpublishing, ");
query.append(" A.ld_stoppublishing, A.ld_published, ");
query.append(" B.ld_name, A.ld_folderid, A.ld_templateid, C.ld_name, A.ld_tenantid, A.ld_docreftype, ");
query.append(" A.ld_stamped, A.ld_password, A.ld_workflowstatusdisp, A.ld_language, A.ld_pages, A.ld_color ");
query.append(" A.ld_stamped, A.ld_password, A.ld_workflowstatusdisp, A.ld_language, A.ld_pages, A.ld_color, A.ld_lastnote ");
query.append(" from ld_document A ");
query.append(" join ld_folder B on A.ld_folderid=B.ld_id ");
query.append(" left outer join ld_template C on A.ld_templateid=C.ld_id ");
Expand All @@ -77,7 +77,7 @@ private String prepareQuery() throws PersistenceException {
query.append(" A.ld_stoppublishing, A.ld_published, ");
query.append(" B.ld_name, A.ld_folderid, REF.ld_templateid, C.ld_name, A.ld_tenantid, A.ld_docreftype, ");
query.append(
" REF.ld_stamped, REF.ld_password, REF.ld_workflowstatusdisp, REF.ld_language, REF.ld_pages, A.ld_color ");
" REF.ld_stamped, REF.ld_password, REF.ld_workflowstatusdisp, REF.ld_language, REF.ld_pages, A.ld_color, A.ld_lastnote ");
query.append(" from ld_document A ");
query.append(" join ld_folder B on A.ld_folderid=B.ld_id ");
query.append(" join ld_document REF on A.ld_docref=REF.ld_id ");
Expand Down Expand Up @@ -207,6 +207,7 @@ public Hit mapRow(ResultSet rs, int rowNum) throws SQLException {
hit.setLanguage(rs.getString(35));
hit.setPages(rs.getInt(36));
hit.setColor(rs.getString(37));
hit.setLastNote(rs.getString(38));

return hit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public void notifyReport() {
* @return the report's body
*/
protected String prepareReport(Locale locale) {
return null;
return "";
}

/**
Expand Down
5 changes: 3 additions & 2 deletions logicaldoc-core/src/main/resources/mappings/Document.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
<property name="deleted" type="int" column="ld_deleted" not-null="true" />
<property name="tenantId" type="long" column="ld_tenantid" not-null="true" />
<property name="immutable" type="int" column="ld_immutable" not-null="true" />
<property name="customId" type="string" column="ld_customid" length="700" />
<property name="comment" type="string" column="ld_comment" length="1000" />
<property name="customId" type="string" column="ld_customid" />
<property name="comment" type="string" column="ld_comment" />
<property name="lastNote" type="string" column="ld_lastnote" />
<property name="version" type="string" column="ld_version" length="10" />
<property name="fileVersion" type="string" column="ld_fileversion" length="10" />
<property name="date" type="timestamp" column="ld_date" />
Expand Down
5 changes: 3 additions & 2 deletions logicaldoc-core/src/main/resources/mappings/Version.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<property name="tenantId" type="long" column="ld_tenantid" not-null="true" />
<property name="docId" type="long" column="ld_documentid" not-null="true" />
<property name="immutable" type="int" column="ld_immutable" not-null="true" />
<property name="customId" type="string" column="ld_customid" length="700" />
<property name="customId" type="string" column="ld_customid" />
<property name="lastNote" type="string" column="ld_lastnote" />
<property name="version" type="string" column="ld_version" length="10" />
<property name="fileVersion" type="string" column="ld_fileversion" length="10" />
<property name="date" type="timestamp" column="ld_date" />
Expand Down Expand Up @@ -48,7 +49,7 @@
<property name="username" type="string" column="ld_username" length="255" />
<property name="userId" type="long" column="ld_userid" />
<property name="versionDate" type="timestamp" column="ld_versiondate" />
<property name="comment" type="string" column="ld_comment" length="1000" />
<property name="comment" type="string" column="ld_comment" />
<property name="event" type="string" column="ld_event" length="255" />
<property name="exportStatus" type="int" column="ld_exportstatus" not-null="true" />
<property name="exportId" type="long" column="ld_exportid" />
Expand Down
4 changes: 2 additions & 2 deletions logicaldoc-core/src/main/resources/sql/logicaldoc-core.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ create table ld_document (ld_id bigint not null, ld_lastmodified timestamp not n
ld_filesize bigint, ld_indexed int not null, ld_barcoded int not null, ld_signed int not null, ld_stamped int not null,
ld_digest varchar(255), ld_folderid bigint, ld_templateid bigint, ld_exportstatus int not null,
ld_exportid bigint, ld_exportname varchar(255), ld_exportversion varchar(10), ld_docref bigint, ld_docreftype varchar(255),
ld_deleteuserid bigint, ld_deleteuser varchar(255), ld_rating int, ld_comment varchar(1000),
ld_deleteuserid bigint, ld_deleteuser varchar(255), ld_rating int, ld_comment varchar(1000), ld_lastnote varchar(4000),
ld_workflowstatus varchar(1000), ld_workflowstatusdisp varchar(1000),
ld_published int not null, ld_startpublishing timestamp, ld_stoppublishing timestamp null, ld_transactionid varchar(255),
ld_extresid varchar(255), ld_tgs varchar(1000), ld_pages int not null, ld_previewpages int not null, ld_nature int not null,
Expand Down Expand Up @@ -134,7 +134,7 @@ create table ld_version (ld_id bigint not null, ld_lastmodified timestamp not nu
ld_deleted int not null, ld_tenantid bigint not null, ld_immutable int not null, ld_customid varchar(200),
ld_version varchar(255), ld_fileversion varchar(10), ld_date timestamp, ld_creation timestamp, ld_publisher varchar(255),
ld_publisherid bigint not null, ld_creator varchar(255), ld_creatorid bigint not null, ld_status int, ld_type varchar(255),
ld_lockuserid bigint, ld_lockuser varchar(255),
ld_lockuserid bigint, ld_lockuser varchar(255), ld_lastnote varchar(4000),
ld_language varchar(10), ld_filename varchar(255), ld_password varchar(255),
ld_filesize bigint, ld_indexed int not null, ld_barcoded int not null, ld_signed int not null, ld_stamped int not null,
ld_digest varchar(255), ld_folderid bigint, ld_foldername varchar(1000), ld_templateid bigint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ create table ld_document (ld_id bigint not null, ld_lastmodified datetime not nu
ld_filesize bigint, ld_indexed int not null, ld_barcoded int not null, ld_signed int not null, ld_stamped int not null,
ld_digest varchar(255), ld_folderid bigint, ld_templateid bigint, ld_exportstatus int not null,
ld_exportid bigint, ld_exportname varchar(255), ld_exportversion varchar(10), ld_docref bigint, ld_docreftype varchar(255),
ld_deleteuserid bigint, ld_deleteuser varchar(255), ld_rating int, ld_comment varchar(1000),
ld_deleteuserid bigint, ld_deleteuser varchar(255), ld_rating int, ld_comment varchar(1000), ld_lastnote varchar(4000),
ld_workflowstatus varchar(1000), ld_workflowstatusdisp varchar(1000),
ld_published int not null, ld_startpublishing datetime, ld_stoppublishing datetime null, ld_transactionid varchar(255),
ld_extresid varchar(255), ld_tgs varchar(1000), ld_pages int not null, ld_previewpages int not null, ld_nature int not null,
Expand Down Expand Up @@ -133,7 +133,7 @@ create table ld_version (ld_id bigint not null, ld_lastmodified datetime not nul
ld_version varchar(255), ld_fileversion varchar(10), ld_date datetime, ld_creation datetime, ld_publisher varchar(255),
ld_publisherid bigint not null, ld_creator varchar(255), ld_creatorid bigint not null, ld_status int, ld_type varchar(255),
ld_lockuserid bigint, ld_lockuser varchar(255),
ld_language varchar(10), ld_filename varchar(255), ld_password varchar(255),
ld_language varchar(10), ld_filename varchar(255), ld_password varchar(255), ld_lastnote varchar(4000),
ld_filesize bigint, ld_indexed int not null, ld_barcoded int not null, ld_signed int not null, ld_stamped int not null,
ld_digest varchar(255), ld_folderid bigint, ld_foldername varchar(1000), ld_templateid bigint,
ld_templatename varchar(1000), ld_tgs varchar(1000), ld_username varchar(255), ld_userid bigint, ld_versiondate datetime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ create table ld_document (ld_id bigint not null, ld_lastmodified datetime not nu
ld_filesize bigint, ld_indexed int not null, ld_barcoded int not null, ld_signed int not null, ld_stamped int not null,
ld_digest nvarchar(255), ld_folderid bigint, ld_templateid bigint, ld_exportstatus int not null,
ld_exportid bigint, ld_exportname nvarchar(255), ld_exportversion nvarchar(10), ld_docref bigint, ld_docreftype nvarchar(255),
ld_deleteuserid bigint, ld_deleteuser nvarchar(255), ld_rating int, ld_comment nvarchar(1000),
ld_deleteuserid bigint, ld_deleteuser nvarchar(255), ld_rating int, ld_comment nvarchar(1000), ld_lastnote nvarchar(4000),
ld_workflowstatus nvarchar(1000), ld_workflowstatusdisp nvarchar(1000),
ld_published int not null, ld_startpublishing datetime, ld_stoppublishing datetime null, ld_transactionid nvarchar(255),
ld_extresid nvarchar(255), ld_tgs nvarchar(1000), ld_pages int not null, ld_previewpages int not null, ld_nature int not null,
Expand Down Expand Up @@ -137,7 +137,7 @@ create table ld_version (ld_id bigint not null, ld_lastmodified datetime not nul
ld_version nvarchar(255), ld_fileversion nvarchar(10), ld_date datetime, ld_creation datetime, ld_publisher nvarchar(255),
ld_publisherid bigint not null, ld_creator nvarchar(255), ld_creatorid bigint not null, ld_status int, ld_type nvarchar(255),
ld_lockuserid bigint, ld_lockuser nvarchar(255),
ld_language nvarchar(10), ld_filename nvarchar(255), ld_password nvarchar(255),
ld_language nvarchar(10), ld_filename nvarchar(255), ld_password nvarchar(255), ld_lastnote nvarchar(4000),
ld_filesize bigint, ld_indexed int not null, ld_barcoded int not null, ld_signed int not null, ld_stamped int not null,
ld_digest nvarchar(255), ld_folderid bigint, ld_foldername nvarchar(1000), ld_templateid bigint,
ld_templatename nvarchar(1000), ld_tgs nvarchar(1000), ld_username nvarchar(255), ld_userid bigint, ld_versiondate datetime,
Expand Down
Loading

0 comments on commit b72e247

Please sign in to comment.