Skip to content

Commit ed44b1f

Browse files
author
francesco
committed
Merge branch 'master' of https://github.com/logicaldoc/community
2 parents 090de20 + 4517059 commit ed44b1f

File tree

71 files changed

+919
-412
lines changed

Some content is hidden

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

71 files changed

+919
-412
lines changed

logicaldoc-cmis/src/main/java/com/logicaldoc/cmis/LDRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ public String createDocumentFromSource(CallContext context, String sourceId, Str
487487
transaction.setUser(getSessionUser());
488488
transaction.setComment("");
489489

490-
Document newDoc = documentManager.copyToFolder(doc, target, transaction);
490+
Document newDoc = documentManager.copyToFolder(doc, target, transaction, true, true);
491491
return getId(newDoc);
492492

493493
} catch (Exception t) {

logicaldoc-core/src/main/java/com/logicaldoc/core/automation/DocTool.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,14 @@ public void move(Document doc, String targetPath, String username) {
328328
*
329329
* @param doc the document
330330
* @param targetPath the full path of the target folder
331+
* @param links if the links must be copied too
332+
* @param notes if the notes must be copied too
333+
*
331334
* @param username the user in whose name the method is run
332335
*
333336
* @return the new document created
334337
*/
335-
public Document copy(Document doc, String targetPath, String username) {
338+
public Document copy(Document doc, String targetPath, boolean links, boolean notes, String username) {
336339
User user = new SecurityTool().getUser(username);
337340

338341
DocumentManager manager = (DocumentManager) Context.get().getBean(DocumentManager.class);
@@ -344,13 +347,26 @@ public Document copy(Document doc, String targetPath, String username) {
344347
transaction.setUser(user);
345348

346349
try {
347-
return manager.copyToFolder(doc, folder, transaction);
350+
return manager.copyToFolder(doc, folder, transaction, links, notes);
348351
} catch (PersistenceException | IOException e) {
349352
log.error(e.getMessage(), e);
350353
return null;
351354
}
352355
}
353356

357+
/**
358+
* Copies a document into a target folder
359+
*
360+
* @param doc the document
361+
* @param targetPath the full path of the target folder
362+
* @param username the user in whose name the method is run
363+
*
364+
* @return the new document created
365+
*/
366+
public Document copy(Document doc, String targetPath, String username) {
367+
return copy(doc, targetPath, false, false, username);
368+
}
369+
354370
/**
355371
* Links two documents
356372
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ public Document getDocument2() {
4242
public void setDocument2(Document document2) {
4343
this.document2 = document2;
4444
}
45-
}
45+
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,15 @@ public long index(long docId, String content, DocumentHistory transaction)
257257
* @param doc The document to move
258258
* @param folder The target folder
259259
* @param transaction entry to log the event (set the user)
260+
* @param links if links must be copied too
261+
* @param notes if notes and annotations must be copied too
262+
*
260263
* @return The created document
261264
*
262265
* @throws PersistenceException error at data layer
263266
* @throws IOException I/O error
264267
*/
265-
public Document copyToFolder(Document doc, Folder folder, DocumentHistory transaction)
268+
public Document copyToFolder(Document doc, Folder folder, DocumentHistory transaction, boolean links, boolean notes)
266269
throws PersistenceException, IOException;
267270

268271
/**

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

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.logicaldoc.core.conversion.FormatConverterManager;
3131
import com.logicaldoc.core.document.dao.DocumentDAO;
3232
import com.logicaldoc.core.document.dao.DocumentHistoryDAO;
33+
import com.logicaldoc.core.document.dao.DocumentLinkDAO;
3334
import com.logicaldoc.core.document.dao.DocumentNoteDAO;
3435
import com.logicaldoc.core.document.dao.VersionDAO;
3536
import com.logicaldoc.core.folder.Folder;
@@ -83,6 +84,8 @@ public class DocumentManagerImpl implements DocumentManager {
8384

8485
private DocumentDAO documentDAO;
8586

87+
private DocumentLinkDAO documentLinkDAO;
88+
8689
private DocumentNoteDAO documentNoteDAO;
8790

8891
private FolderDAO folderDAO;
@@ -987,7 +990,7 @@ public int countPages(Document doc) {
987990
}
988991
}
989992

990-
public Document copyToFolder(Document doc, Folder folder, DocumentHistory transaction)
993+
public Document copyToFolder(Document doc, Folder folder, DocumentHistory transaction, boolean links, boolean notes)
991994
throws PersistenceException, IOException {
992995
validateTransaction(transaction);
993996

@@ -999,8 +1002,7 @@ public Document copyToFolder(Document doc, Folder folder, DocumentHistory transa
9991002
}
10001003

10011004
String resource = storer.getResourceName(doc, null, null);
1002-
InputStream is = storer.getStream(doc.getId(), resource);
1003-
try {
1005+
try (InputStream is = storer.getStream(doc.getId(), resource);) {
10041006
Document cloned = new Document(doc);
10051007
cloned.setId(0);
10061008
if (doc.getFolder().getId() != folder.getId())
@@ -1026,11 +1028,51 @@ public Document copyToFolder(Document doc, Folder folder, DocumentHistory transa
10261028
copyEvent.setComment(newPath + "/" + createdDocument.getFileName());
10271029
documentDAO.saveDocumentHistory(doc, copyEvent);
10281030

1031+
if (links)
1032+
copyLinks(doc, createdDocument);
1033+
1034+
if (notes)
1035+
copyNotes(doc, createdDocument);
1036+
10291037
return createdDocument;
1030-
} finally {
1031-
if (is != null)
1032-
is.close();
1033-
is = null;
1038+
}
1039+
}
1040+
1041+
private void copyNotes(Document sourceDocument, Document createdDocument) {
1042+
List<DocumentNote> docNotes = documentNoteDAO.findByDocId(sourceDocument.getId(), sourceDocument.getFileVersion());
1043+
for (DocumentNote docNote : docNotes) {
1044+
DocumentNote newNote = new DocumentNote(docNote);
1045+
newNote.setDocId(createdDocument.getId());
1046+
newNote.setFileVersion(null);
1047+
1048+
try {
1049+
documentNoteDAO.store(newNote);
1050+
} catch (PersistenceException e) {
1051+
log.warn("Error copying note {}", docNote);
1052+
}
1053+
}
1054+
}
1055+
1056+
private void copyLinks(Document sourceDocument, Document createdDocument) {
1057+
List<DocumentLink> docLinks = documentLinkDAO.findByDocId(sourceDocument.getId());
1058+
1059+
for (DocumentLink docLink : docLinks) {
1060+
DocumentLink newLink = new DocumentLink();
1061+
newLink.setTenantId(docLink.getTenantId());
1062+
newLink.setType(docLink.getType());
1063+
if (docLink.getDocument1().getId() == sourceDocument.getId()) {
1064+
newLink.setDocument1(createdDocument);
1065+
newLink.setDocument2(docLink.getDocument2());
1066+
} else {
1067+
newLink.setDocument2(createdDocument);
1068+
newLink.setDocument1(docLink.getDocument1());
1069+
}
1070+
1071+
try {
1072+
documentLinkDAO.store(newLink);
1073+
} catch (PersistenceException e) {
1074+
log.warn("Error copying link {}", docLink);
1075+
}
10341076
}
10351077
}
10361078

@@ -1149,7 +1191,7 @@ public Document replaceAlias(long aliasId, DocumentHistory transaction) throws P
11491191
documentDAO.delete(aliasId, transaction);
11501192

11511193
try {
1152-
return copyToFolder(originalDoc, folder, new DocumentHistory(transaction));
1194+
return copyToFolder(originalDoc, folder, new DocumentHistory(transaction), true, true);
11531195
} catch (IOException e) {
11541196
throw new PersistenceException(e);
11551197
}
@@ -1400,8 +1442,7 @@ public void archiveDocuments(long[] docIds, DocumentHistory transaction) throws
14001442
}
14011443

14021444
@Override
1403-
public Ticket createTicket(
1404-
Ticket ticket, DocumentHistory transaction)
1445+
public Ticket createTicket(Ticket ticket, DocumentHistory transaction)
14051446
throws PersistenceException, PermissionException {
14061447
validateTransaction(transaction);
14071448

@@ -1557,10 +1598,10 @@ public int enforceFilesIntoFolderStorage(long rootFolderId, DocumentHistory tran
15571598
targetStorage);
15581599

15591600
List<Document> documents = documentDAO.findByFolder(folderId, null);
1560-
1601+
15611602
for (Document document : documents) {
15621603
int movedFiles = storer.moveResourcesToStore(document.getId(), targetStorage);
1563-
1604+
15641605
if (movedFiles > 0) {
15651606
totalMovedFiles += movedFiles;
15661607
try {
@@ -1714,4 +1755,8 @@ private File mergePdf(File[] pdfs) throws IOException {
17141755
FileUtil.strongDelete(tempDir);
17151756
}
17161757
}
1758+
1759+
public void setDocumentLinkDAO(DocumentLinkDAO documentLinkDAO) {
1760+
this.documentLinkDAO = documentLinkDAO;
1761+
}
17171762
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.Date;
44

5+
import org.apache.commons.lang.StringUtils;
6+
57
import com.logicaldoc.core.PersistentObject;
68

79
/**
@@ -114,8 +116,7 @@ public DocumentNote(DocumentNote source) {
114116
this.type = source.type;
115117
this.recipient = source.recipient;
116118
this.recipientEmail = source.recipientEmail;
117-
118-
setFileVersion(source.getFileVersion());
119+
this.setTenantId(source.getTenantId());
119120
}
120121

121122
public long getDocId() {
@@ -293,4 +294,9 @@ public double getRotation() {
293294
public void setRotation(double rotation) {
294295
this.rotation = rotation;
295296
}
297+
298+
@Override
299+
public String toString() {
300+
return StringUtils.abbreviate(message, 40) + "(" + getId() + ")";
301+
}
296302
}

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,32 @@ public HibernateDocumentNoteDAO() {
3939
}
4040

4141
@Override
42-
public void store(DocumentNote note, DocumentHistory transaction) throws PersistenceException {
43-
super.store(note);
44-
42+
public void store(DocumentNote note) throws PersistenceException {
4543
DocumentDAO documentDao = (DocumentDAO) Context.get().getBean(DocumentDAO.class);
4644
Document doc = documentDao.findById(note.getDocId());
47-
if (doc != null && doc.getIndexed() == AbstractDocument.INDEX_INDEXED) {
45+
if (doc == null)
46+
throw new PersistenceException("Cannot save note for undexisting document " + note.getDocId());
47+
48+
if (note.getFileVersion() == null)
49+
note.setFileVersion(doc.getFileVersion());
50+
51+
super.store(note);
52+
53+
if (doc.getIndexed() == AbstractDocument.INDEX_INDEXED) {
4854
documentDao.initialize(doc);
4955
doc.setIndexed(AbstractDocument.INDEX_TO_INDEX);
5056
documentDao.store(doc);
5157
}
52-
58+
}
59+
60+
@Override
61+
public void store(DocumentNote note, DocumentHistory transaction) throws PersistenceException {
62+
this.store(note);
63+
5364
try {
5465
if (transaction != null) {
66+
DocumentDAO documentDao = (DocumentDAO) Context.get().getBean(DocumentDAO.class);
67+
Document doc = documentDao.findById(note.getDocId());
5568
transaction.setEvent(DocumentEvent.NEW_NOTE.toString());
5669
documentDao.saveDocumentHistory(doc, transaction);
5770
}

logicaldoc-core/src/main/java/com/logicaldoc/core/metadata/AbstractAttributeSet.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class AbstractAttributeSet extends ExtensibleObject {
1616
public static final int TYPE_DEFAULT = 0;
1717

1818
private String name;
19+
20+
private String label;
1921

2022
private String description;
2123

@@ -54,4 +56,12 @@ public int getType() {
5456
public void setType(int type) {
5557
this.type = type;
5658
}
59+
60+
public String getLabel() {
61+
return label;
62+
}
63+
64+
public void setLabel(String label) {
65+
this.label = label;
66+
}
5767
}

logicaldoc-core/src/main/java/com/logicaldoc/core/security/authentication/DefaultAuthenticator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public User authenticate(String username, String password, String key, Client cl
5353
try {
5454
// Make sure the password in the DB follows the current scheme
5555
if (user.getPassword().equals(testLegacy))
56-
userDAO.jdbcUpdate("update ld_user set ld_password='" + test + "' where ld_id " + user.getId());
56+
userDAO.jdbcUpdate("update ld_user set ld_password='" + test + "' where ld_id = " + user.getId());
5757
} catch (PersistenceException e) {
5858
log.warn(e.getMessage());
5959
}

logicaldoc-core/src/main/java/com/logicaldoc/core/util/IconSelector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,6 @@ private static boolean isVideo(String ext) {
201201
public static boolean isPicture(String ext) {
202202
return (ext.equals("jpg") || ext.equals("jpeg") || ext.equals("gif") || ext.equals("png") || ext.equals("bmp")
203203
|| ext.equals("tif") || ext.equals("tiff") || ext.equals("psd") || ext.equals("svg")
204-
|| ext.equals("jfif") || ext.equals("webp"));
204+
|| ext.equals("jfif") || ext.equals("webp") || ext.equals("heic"));
205205
}
206206
}

logicaldoc-core/src/main/resources/context/context-core.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@
298298
<property name="config" ref="ContextProperties" />
299299
<property name="documentDAO" ref="DocumentDAO" />
300300
<property name="documentNoteDAO" ref="DocumentNoteDAO" />
301+
<property name="documentLinkDAO" ref="DocumentLinkDAO" />
301302
<property name="folderDAO" ref="FolderDAO" />
302303
<property name="versionDAO" ref="VersionDAO" />
303304
<property name="ticketDAO" ref="TicketDAO" />

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<property name="deleted" type="int" column="ld_deleted" not-null="true" />
1717
<property name="name" type="string" column="ld_name" length="255" not-null="true" />
1818
<property name="tenantId" type="long" column="ld_tenantid" not-null="true" />
19+
<property name="label" type="string" column="ld_label" length="255" />
1920
<property name="description" type="string" column="ld_description" length="2000" />
2021
<property name="readonly" type="int" column="ld_readonly" not-null="true" />
2122
<property name="type" type="int" column="ld_type" not-null="true" />

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<property name="deleted" type="int" column="ld_deleted" not-null="true" />
1616
<property name="name" type="string" column="ld_name" length="255" not-null="true" />
1717
<property name="tenantId" type="long" column="ld_tenantid" not-null="true" />
18+
<property name="label" type="string" column="ld_label" length="255" />
1819
<property name="description" type="string" column="ld_description" length="2000" />
1920
<property name="readonly" type="int" column="ld_readonly" not-null="true" />
2021
<property name="type" type="int" column="ld_type" not-null="true" />

logicaldoc-core/src/main/resources/plugin.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090

9191
<plugin id="logicaldoc-core" version="8.9.0" class="com.logicaldoc.core.CorePlugin">
9292
<extension-point id="DbInit">
93-
<parameter-def id="name" />
9493
<parameter-def id="sqlFile" />
9594
<parameter-def id="position" />
9695
</extension-point>
@@ -319,7 +318,11 @@
319318
<extension plugin-id="logicaldoc-core" point-id="ThumbnailBuilder" id="psdThumb">
320319
<parameter id="extension" value="psd" />
321320
<parameter id="class" value="com.logicaldoc.core.document.thumbnail.ImageThumbnailBuilder" />
322-
</extension>
321+
</extension>
322+
<extension plugin-id="logicaldoc-core" point-id="ThumbnailBuilder" id="heicThumb">
323+
<parameter id="extension" value="heic" />
324+
<parameter id="class" value="com.logicaldoc.core.document.thumbnail.ImageThumbnailBuilder" />
325+
</extension>
323326
<extension plugin-id="logicaldoc-core" point-id="ThumbnailBuilder" id="pdfThumb">
324327
<parameter id="extension" value="pdf" />
325328
<parameter id="class" value="com.logicaldoc.core.document.thumbnail.PdfThumbnailBuilder" />
@@ -377,7 +380,6 @@
377380

378381
<extension plugin-id="logicaldoc-core" point-id="DbInit" id="coreDbInit">
379382
<parameter id="position" value="1" />
380-
<parameter id="name" value="logicaldoc-core" />
381383
<parameter id="sqlFile" value="sql/logicaldoc-core.sql" />
382384
</extension>
383385

@@ -449,7 +451,7 @@
449451
</extension>
450452

451453
<extension plugin-id="logicaldoc-core" point-id="FormatConverter" id="imageConv">
452-
<parameter id="in" value="png,gif,jpg,jpeg,jfif,tif,tiff,bmp,psd,webp"/>
454+
<parameter id="in" value="png,gif,jpg,jpeg,jfif,tif,tiff,bmp,psd,webp,heic"/>
453455
<parameter id="out" value="pdf"/>
454456
<parameter id="class" value="com.logicaldoc.core.conversion.ImageConverter"/>
455457
</extension>

logicaldoc-core/src/main/resources/sql/logicaldoc-core.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ create table ld_systemmessage (ld_id bigint not null, ld_lastmodified timestamp
7171
ld_lastnotified timestamp, ld_status int not null, ld_trials int,
7272
ld_type int not null, ld_html int not null, primary key (ld_id));
7373
create table ld_template (ld_id bigint not null, ld_lastmodified timestamp not null, ld_recordversion bigint not null,
74-
ld_deleted int not null, ld_tenantid bigint not null, ld_name varchar(255) not null,
74+
ld_deleted int not null, ld_tenantid bigint not null, ld_name varchar(255) not null, ld_label varchar(255),
7575
ld_description varchar(2000), ld_readonly int not null, ld_type int not null, ld_validation varchar(4000),
7676
primary key (ld_id));
7777
create table ld_template_ext (ld_templateid bigint not null, ld_mandatory int not null, ld_type int not null,
@@ -83,7 +83,7 @@ create table ld_template_ext (ld_templateid bigint not null, ld_mandatory int no
8383
create table ld_templategroup (ld_templateid bigint not null, ld_groupid bigint not null, ld_write int not null,
8484
primary key (ld_templateid, ld_groupid));
8585
create table ld_attributeset (ld_id bigint not null, ld_lastmodified timestamp not null, ld_recordversion bigint not null,
86-
ld_deleted int not null, ld_tenantid bigint not null, ld_name varchar(255) not null,
86+
ld_deleted int not null, ld_tenantid bigint not null, ld_name varchar(255) not null, ld_label varchar(255),
8787
ld_description varchar(2000), ld_readonly int not null, ld_type int not null,
8888
primary key (ld_id));
8989
create table ld_attributeset_ext (ld_attsetid bigint not null, ld_mandatory int not null, ld_type int not null,

0 commit comments

Comments
 (0)