Skip to content

Commit b72e247

Browse files
committed
#1298 Display last note in Documents grid
1 parent 8bd7d65 commit b72e247

File tree

130 files changed

+592
-1282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+592
-1282
lines changed

logicaldoc-core/src/main/java/com/logicaldoc/core/dashlet/DashletContent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ private void printExtendedAttributes(DateFormat df, PrintWriter writer, Document
325325
case Integer integer -> writer.print(Integer.toString(integer));
326326
case Long longVal -> writer.print(Long.toString(longVal));
327327
case Double doubleVal -> writer.print(Double.toString(doubleVal));
328+
case String str -> writer.print(str);
328329
default -> throw new IllegalArgumentException("Unexpected value: " + val);
329330
}
330331
writer.print("</ext_" + name + ">");

logicaldoc-core/src/main/java/com/logicaldoc/core/document/AbstractDocument.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ public abstract class AbstractDocument extends SecurableExtensibleObject impleme
112112
public static final int NATURE_DOC = 0;
113113

114114
private String comment;
115+
116+
/**
117+
* The text of the last note put on the document
118+
*/
119+
private String lastNote;
115120

116121
private long fileSize = 0;
117122

@@ -1082,6 +1087,14 @@ public void setDocAttrs(int docAttrs) {
10821087
this.docAttrs = docAttrs;
10831088
}
10841089

1090+
public String getLastNote() {
1091+
return lastNote;
1092+
}
1093+
1094+
public void setLastNote(String lastNote) {
1095+
this.lastNote = lastNote;
1096+
}
1097+
10851098
@Override
10861099
public int hashCode() {
10871100
final int prime = 31;

logicaldoc-core/src/main/java/com/logicaldoc/core/document/DocumentManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ public Document copyToFolder(Document doc, Folder folder, DocumentHistory transa
10591059
private void copyNotes(Document sourceDocument, Document createdDocument) throws PersistenceException {
10601060
List<DocumentNote> docNotes = documentNoteDAO.findByDocId(sourceDocument.getId(),
10611061
sourceDocument.getFileVersion());
1062+
docNotes.sort((o1, o2) -> o1.getDate().compareTo(o2.getDate()));
10621063
for (DocumentNote docNote : docNotes) {
10631064
DocumentNote newNote = new DocumentNote(docNote);
10641065
newNote.setDocId(createdDocument.getId());

logicaldoc-core/src/main/java/com/logicaldoc/core/document/HibernateDocumentNoteDAO.java

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
import com.logicaldoc.core.PersistenceException;
1414
import com.logicaldoc.core.security.Session;
1515
import com.logicaldoc.core.security.SessionManager;
16+
import com.logicaldoc.core.threading.ThreadPools;
1617
import com.logicaldoc.util.Context;
18+
import com.logicaldoc.util.html.HTMLSanitizer;
1719

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

4547
super.store(note);
4648

47-
if (doc.getIndexed() == AbstractDocument.INDEX_INDEXED) {
48-
documentDao.initialize(doc);
49-
doc.setIndexed(AbstractDocument.INDEX_TO_INDEX);
50-
documentDao.store(doc);
51-
}
49+
updateLastNote(doc, note);
50+
}
51+
52+
private void updateLastNote(Document doccument, DocumentNote note) {
53+
// In case of note on the whole document, update the document's lastNote field
54+
if (note.getPage() == 0)
55+
ThreadPools.get().execute(() -> {
56+
try {
57+
DocumentDAO dao = Context.get(DocumentDAO.class);
58+
Document document = dao.findById(note.getDocId());
59+
dao.initialize(document);
60+
61+
String lastNoteMessage = dao.queryForList(
62+
"select ld_message from ld_note where ld_page=0 and ld_id=:id order by ld_date desc",
63+
Map.of("id", note.getDocId()), String.class, null).stream().findFirst()
64+
.orElse(note.getMessage());
65+
66+
document.setLastNote(HTMLSanitizer.sanitizeSimpleText(lastNoteMessage));
67+
if (doccument.getIndexed() == AbstractDocument.INDEX_INDEXED)
68+
doccument.setIndexed(AbstractDocument.INDEX_TO_INDEX);
69+
dao.store(document);
70+
} catch (PersistenceException e) {
71+
log.error(e.getMessage(), e);
72+
}
73+
}, "Note");
5274
}
5375

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

79101
@Override
80-
public List<DocumentNote> findByDocIdAndType(long docId, String fileVersion, String type) throws PersistenceException {
102+
public List<DocumentNote> findByDocIdAndType(long docId, String fileVersion, String type)
103+
throws PersistenceException {
81104
return findByDocIdAndTypes(docId, fileVersion, StringUtils.isEmpty(type) ? null : Arrays.asList(type));
82105
}
83106

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

117-
private void markToIndex(long docId) throws PersistenceException {
118-
DocumentDAO documentDao = Context.get(DocumentDAO.class);
119-
Document doc = documentDao.findById(docId);
120-
if (doc != null && doc.getIndexed() == AbstractDocument.INDEX_INDEXED) {
121-
documentDao.initialize(doc);
122-
doc.setIndexed(AbstractDocument.INDEX_TO_INDEX);
123-
documentDao.store(doc);
124-
}
125-
}
126140

127141
@Override
128142
public void delete(long id, int code) throws PersistenceException {
129143
DocumentNote note = findById(id);
130-
if (note != null)
131-
markToIndex(note.getDocId());
132-
super.delete(id, code);
144+
if (note != null) {
145+
super.delete(id, code);
146+
DocumentDAO documentDao = Context.get(DocumentDAO.class);
147+
Document document = documentDao.findById(note.getDocId());
148+
if (document != null && document.getIndexed() == AbstractDocument.INDEX_INDEXED) {
149+
// Mark to index
150+
documentDao.initialize(document);
151+
document.setIndexed(AbstractDocument.INDEX_TO_INDEX);
152+
documentDao.store(document);
153+
updateLastNote(document, note);
154+
}
155+
}
133156
}
134157

135158
@Override

logicaldoc-core/src/main/java/com/logicaldoc/core/document/Version.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ public static Version create(Document document, User user, String comment, Strin
225225
version.setWorkflowStatus(document.getWorkflowStatus());
226226
version.setWorkflowStatusDisplay(document.getWorkflowStatusDisplay());
227227
version.setColor(document.getColor());
228+
version.setLastNote(document.getLastNote());
228229

229230
if (document.getTemplate() != null) {
230231
version.setTemplateId(document.getTemplate().getId());

logicaldoc-core/src/main/java/com/logicaldoc/core/folder/HibernateFolderDAO.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,15 +1438,9 @@ public Folder createPath(Folder parent, String path, boolean inheritSecurity, Fo
14381438

14391439
while (st.hasMoreTokens()) {
14401440
String name = st.nextToken();
1441-
1442-
Map<String, Object> params = new HashMap<>();
1443-
params.put("folderId", folder.getId());
1444-
params.put("name", name);
1445-
params.put("tenantId", folder.getTenantId());
1446-
1447-
long child = findIdsByWhere(
1448-
"_entity.parentId = :folderId and _entity.name = :name and _entity.tenantId = :tenantId", params,
1449-
null, null).stream().findFirst().orElse(0L);
1441+
long child = queryForLong(
1442+
"select ld_id from ld_folder where ld_deleted=0 and ld_parentid = :folderId and ld_name = :name and ld_tenantid = :tenantId",
1443+
Map.of("folderId", folder.getId(), "name", name, "tenantId", folder.getTenantId()));
14501444

14511445
if (child == 0L) {
14521446
Folder folderVO = new Folder();

logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/FulltextSearch.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public Hit mapRow(ResultSet rs, int rowNum) throws SQLException {
110110
hit.setLanguage(rs.getString(36));
111111
hit.setPages(rs.getInt(37));
112112
hit.setColor(rs.getString(38));
113+
hit.setLastNote(rs.getString(39));
113114

114115
return hit;
115116
}
@@ -197,7 +198,7 @@ public void internalSearch() throws SearchException {
197198
richQuery.append(
198199
" FOLD.ld_name, A.ld_folderid, A.ld_tgs tags, A.ld_templateid, C.ld_name, A.ld_tenantid, A.ld_docreftype, ");
199200
richQuery.append(
200-
" A.ld_stamped, A.ld_password, A.ld_workflowstatusdisp, A.ld_language, A.ld_pages, A.ld_color ");
201+
" A.ld_stamped, A.ld_password, A.ld_workflowstatusdisp, A.ld_language, A.ld_pages, A.ld_color, A.ld_lastnote ");
201202
richQuery.append(" from ld_document A ");
202203
richQuery.append(" join ld_folder FOLD on A.ld_folderid=FOLD.ld_id ");
203204
richQuery.append(" left outer join ld_template C on A.ld_templateid=C.ld_id ");
@@ -227,7 +228,7 @@ public void internalSearch() throws SearchException {
227228
richQuery.append(
228229
" FOLD.ld_name, A.ld_folderid, A.ld_tgs tags, REF.ld_templateid, C.ld_name, A.ld_tenantid, A.ld_docreftype, ");
229230
richQuery.append(
230-
" REF.ld_stamped, REF.ld_password, REF.ld_workflowstatusdisp, REF.ld_language, REF.ld_pages, A.ld_color ");
231+
" REF.ld_stamped, REF.ld_password, REF.ld_workflowstatusdisp, REF.ld_language, REF.ld_pages, A.ld_color, A.ld_lastnote ");
231232
richQuery.append(" from ld_document A ");
232233
richQuery.append(" join ld_folder FOLD on A.ld_folderid=FOLD.ld_id ");
233234
richQuery.append(" join ld_document REF on A.ld_docref=REF.ld_id ");

logicaldoc-core/src/main/java/com/logicaldoc/core/searchengine/TagSearch.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private String prepareQuery() throws PersistenceException {
5959
query.append(" A.ld_rating, A.ld_fileversion, A.ld_comment, A.ld_workflowstatus, A.ld_startpublishing, ");
6060
query.append(" A.ld_stoppublishing, A.ld_published, ");
6161
query.append(" B.ld_name, A.ld_folderid, A.ld_templateid, C.ld_name, A.ld_tenantid, A.ld_docreftype, ");
62-
query.append(" A.ld_stamped, A.ld_password, A.ld_workflowstatusdisp, A.ld_language, A.ld_pages, A.ld_color ");
62+
query.append(" A.ld_stamped, A.ld_password, A.ld_workflowstatusdisp, A.ld_language, A.ld_pages, A.ld_color, A.ld_lastnote ");
6363
query.append(" from ld_document A ");
6464
query.append(" join ld_folder B on A.ld_folderid=B.ld_id ");
6565
query.append(" left outer join ld_template C on A.ld_templateid=C.ld_id ");
@@ -77,7 +77,7 @@ private String prepareQuery() throws PersistenceException {
7777
query.append(" A.ld_stoppublishing, A.ld_published, ");
7878
query.append(" B.ld_name, A.ld_folderid, REF.ld_templateid, C.ld_name, A.ld_tenantid, A.ld_docreftype, ");
7979
query.append(
80-
" REF.ld_stamped, REF.ld_password, REF.ld_workflowstatusdisp, REF.ld_language, REF.ld_pages, A.ld_color ");
80+
" REF.ld_stamped, REF.ld_password, REF.ld_workflowstatusdisp, REF.ld_language, REF.ld_pages, A.ld_color, A.ld_lastnote ");
8181
query.append(" from ld_document A ");
8282
query.append(" join ld_folder B on A.ld_folderid=B.ld_id ");
8383
query.append(" join ld_document REF on A.ld_docref=REF.ld_id ");
@@ -207,6 +207,7 @@ public Hit mapRow(ResultSet rs, int rowNum) throws SQLException {
207207
hit.setLanguage(rs.getString(35));
208208
hit.setPages(rs.getInt(36));
209209
hit.setColor(rs.getString(37));
210+
hit.setLastNote(rs.getString(38));
210211

211212
return hit;
212213
}

logicaldoc-core/src/main/java/com/logicaldoc/core/task/Task.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public void notifyReport() {
409409
* @return the report's body
410410
*/
411411
protected String prepareReport(Locale locale) {
412-
return null;
412+
return "";
413413
}
414414

415415
/**

logicaldoc-core/src/main/resources/mappings/Document.hbm.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
<property name="deleted" type="int" column="ld_deleted" not-null="true" />
1717
<property name="tenantId" type="long" column="ld_tenantid" not-null="true" />
1818
<property name="immutable" type="int" column="ld_immutable" not-null="true" />
19-
<property name="customId" type="string" column="ld_customid" length="700" />
20-
<property name="comment" type="string" column="ld_comment" length="1000" />
19+
<property name="customId" type="string" column="ld_customid" />
20+
<property name="comment" type="string" column="ld_comment" />
21+
<property name="lastNote" type="string" column="ld_lastnote" />
2122
<property name="version" type="string" column="ld_version" length="10" />
2223
<property name="fileVersion" type="string" column="ld_fileversion" length="10" />
2324
<property name="date" type="timestamp" column="ld_date" />

0 commit comments

Comments
 (0)