Skip to content

Commit 9c0720a

Browse files
committed
Enbumeraion convesion for status and indexed fields
1 parent 26efcb3 commit 9c0720a

File tree

40 files changed

+373
-404
lines changed

40 files changed

+373
-404
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
import com.logicaldoc.core.document.DocumentHistory;
125125
import com.logicaldoc.core.document.DocumentHistoryDAO;
126126
import com.logicaldoc.core.document.DocumentManager;
127+
import com.logicaldoc.core.document.DocumentStatus;
127128
import com.logicaldoc.core.document.Version;
128129
import com.logicaldoc.core.document.VersionDAO;
129130
import com.logicaldoc.core.folder.Folder;
@@ -807,7 +808,7 @@ public void deleteObjectOrCancelCheckOut(CallContext context, String objectId) {
807808
PersistentObject object = getObject(objectId);
808809

809810
if (object instanceof Document document) {
810-
if (document.getStatus() != AbstractDocument.DOC_UNLOCKED)
811+
if (document.getStatus() != DocumentStatus.UNLOCKED)
811812
cancelCheckOut(objectId);
812813
else
813814
deleteObject(context, objectId);
@@ -978,7 +979,7 @@ public void cancelCheckOut(String objectId) {
978979

979980
Document doc = (Document) object;
980981

981-
if (doc.getStatus() == AbstractDocument.DOC_CHECKED_OUT
982+
if (doc.getStatus() == DocumentStatus.CHECKEDOUT
982983
&& ((getSessionUser().getId() != doc.getLockUserId())
983984
&& (!getSessionUser().isMemberOf(Group.GROUP_ADMIN))))
984985
throw new CmisPermissionDeniedException("You can't change the checkout status on this object!");
@@ -991,7 +992,7 @@ public void cancelCheckOut(String objectId) {
991992
transaction.setUser(getSessionUser());
992993

993994
documentDao.initialize(doc);
994-
doc.setStatus(AbstractDocument.DOC_UNLOCKED);
995+
doc.setStatus(DocumentStatus.UNLOCKED);
995996
documentDao.store(doc, transaction);
996997
} catch (Exception t) {
997998
catchError(t);
@@ -1011,7 +1012,7 @@ public void checkIn(Holder<String> objectId, Boolean major, ContentStream conten
10111012

10121013
Document doc = (Document) object;
10131014

1014-
if (doc.getStatus() == AbstractDocument.DOC_CHECKED_OUT
1015+
if (doc.getStatus() == DocumentStatus.CHECKEDOUT
10151016
&& ((getSessionUser().getId() != doc.getLockUserId())
10161017
&& (!getSessionUser().isMemberOf(Group.GROUP_ADMIN)))) {
10171018
throw new CmisPermissionDeniedException(
@@ -1885,7 +1886,7 @@ private void compileDocumentOrVersionProperties(AbstractDocument doc, ObjectInfo
18851886
}
18861887
addPropertyString(result, typeId, filter, PropertyIds.VERSION_LABEL, doc.getVersion());
18871888
addPropertyId(result, typeId, filter, PropertyIds.VERSION_SERIES_ID, getId(doc));
1888-
if (doc.getStatus() != AbstractDocument.DOC_CHECKED_OUT) {
1889+
if (doc.getStatus() != DocumentStatus.CHECKEDOUT) {
18891890
addPropertyBoolean(result, typeId, filter, PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, false);
18901891
addPropertyString(result, typeId, filter, PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, null);
18911892
addPropertyString(result, typeId, filter, PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, null);
@@ -2585,11 +2586,11 @@ private AllowableActions compileAllowableActions(PersistentObject object) {
25852586
addAction(aas, Action.CAN_GET_CONTENT_STREAM, true);
25862587
addAction(aas, Action.CAN_GET_ALL_VERSIONS, true);
25872588
addAction(aas, Action.CAN_SET_CONTENT_STREAM, write);
2588-
addAction(aas, Action.CAN_CHECK_OUT, document.getStatus() == AbstractDocument.DOC_UNLOCKED && write);
2589-
addAction(aas, Action.CAN_CHECK_IN, document.getStatus() == AbstractDocument.DOC_CHECKED_OUT
2589+
addAction(aas, Action.CAN_CHECK_OUT, document.getStatus() == DocumentStatus.UNLOCKED && write);
2590+
addAction(aas, Action.CAN_CHECK_IN, document.getStatus() == DocumentStatus.CHECKEDOUT
25902591
&& document.getLockUserId().longValue() == getSessionUser().getId() && write);
25912592
addAction(aas, Action.CAN_CANCEL_CHECK_OUT,
2592-
document.getStatus() != AbstractDocument.DOC_UNLOCKED
2593+
document.getStatus() != DocumentStatus.UNLOCKED
25932594
&& (document.getLockUserId().longValue() == getSessionUser().getId()
25942595
|| getSessionUser().isMemberOf(Group.GROUP_ADMIN)));
25952596
} else {

logicaldoc-cmis/src/test/java/com/logicaldoc/cmis/LDRepositoryTest.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.logicaldoc.core.document.DocumentEvent;
5252
import com.logicaldoc.core.document.DocumentHistory;
5353
import com.logicaldoc.core.document.DocumentHistoryDAO;
54+
import com.logicaldoc.core.document.DocumentStatus;
5455
import com.logicaldoc.core.document.Version;
5556
import com.logicaldoc.core.document.VersionDAO;
5657
import com.logicaldoc.core.folder.Folder;
@@ -71,7 +72,7 @@
7172
public class LDRepositoryTest extends AbstractCmisTestCase {
7273

7374
private static final Logger log = LoggerFactory.getLogger(LDRepositoryTest.class);
74-
75+
7576
private FolderDAO fdao;
7677

7778
private DocumentDAO ddao;
@@ -92,7 +93,7 @@ public void setUp() throws IOException, SQLException, PluginException {
9293
fdao = (FolderDAO) context.getBean("FolderDAO");
9394

9495
ddao = (DocumentDAO) context.getBean("DocumentDAO");
95-
96+
9697
try {
9798
addHits();
9899
} catch (Exception e) {
@@ -363,13 +364,13 @@ public void testCancelCheckOut() throws PersistenceException {
363364
Document document = new Document();
364365
document.setFileName("newDocument");
365366
document.setFolder(folder);
366-
document.setStatus(2);
367+
document.setStatus(DocumentStatus.LOCKED);
367368
ddao.store(document);
368369

369370
testSubject.cancelCheckOut("doc." + document.getId());
370371

371372
document = ddao.findById(document.getId());
372-
assertEquals(0, document.getStatus());
373+
assertEquals(DocumentStatus.UNLOCKED, document.getStatus());
373374
}
374375

375376
@Test
@@ -564,28 +565,28 @@ public void testGetObject() {
564565

565566
@Test
566567
public void testCheckOut() throws PersistenceException {
567-
int status = ddao.findById(1L).getStatus();
568-
assertEquals(0, status);
568+
DocumentStatus status = ddao.findById(1L).getStatus();
569+
assertEquals(DocumentStatus.UNLOCKED, status);
569570

570571
Holder<String> stringHolder = new Holder<String>("doc.1");
571572
Holder<Boolean> booleanHolder = new Holder<Boolean>(true);
572573
testSubject.checkOut(stringHolder, booleanHolder);
573574

574575
status = ddao.findById(1L).getStatus();
575-
assertEquals(1, status);
576+
assertEquals(DocumentStatus.CHECKEDOUT, status);
576577
}
577578

578579
@Test
579580
public void testCheckIn() throws PersistenceException, UnsupportedEncodingException {
580-
int status = ddao.findById(6L).getStatus();
581-
assertEquals(0, status);
581+
DocumentStatus status = ddao.findById(6L).getStatus();
582+
assertEquals(DocumentStatus.UNLOCKED, status);
582583

583584
Holder<String> stringHolder = new Holder<String>("doc.6");
584585
Holder<Boolean> booleanHolder = new Holder<Boolean>(true);
585586
testSubject.checkOut(stringHolder, booleanHolder);
586587

587588
status = ddao.findById(6L).getStatus();
588-
assertEquals(1, status);
589+
assertEquals(DocumentStatus.CHECKEDOUT, status);
589590

590591
ObjectInfoImpl cmisObject = (ObjectInfoImpl) testSubject.getObjectInfo("doc.6", null);
591592
assertNotNull(cmisObject);
@@ -626,7 +627,7 @@ public void testCheckIn() throws PersistenceException, UnsupportedEncodingExcept
626627
testSubject.checkIn(stringHolder, true, contentStream, props, content);
627628

628629
status = ddao.findById(6L).getStatus();
629-
assertEquals(0, status);
630+
assertEquals(DocumentStatus.UNLOCKED, status);
630631
}
631632

632633
@Test
@@ -741,21 +742,21 @@ public void testDeleteObject() throws PersistenceException {
741742

742743
@Test
743744
public void testDeleteObjectOrCancelCheckOut() throws PersistenceException {
744-
int status = ddao.findById(1L).getStatus();
745-
assertEquals(0, status);
745+
DocumentStatus status = ddao.findById(1L).getStatus();
746+
assertEquals(DocumentStatus.UNLOCKED, status);
746747

747748
Holder<String> stringHolder = new Holder<String>("doc.1");
748749
Holder<Boolean> booleanHolder = new Holder<Boolean>(true);
749750
testSubject.checkOut(stringHolder, booleanHolder);
750751

751752
status = ddao.findById(1L).getStatus();
752-
assertEquals(1, status);
753+
assertEquals(DocumentStatus.CHECKEDOUT, status);
753754

754755
ddao.findById(1L);
755756
testSubject.deleteObjectOrCancelCheckOut(null, "doc.1");
756757

757758
status = ddao.findById(1L).getStatus();
758-
assertEquals(0, status);
759+
assertEquals(DocumentStatus.UNLOCKED, status);
759760

760761
Document doc = ddao.findById(1L);
761762
assertEquals(0, doc.getDeleted());

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414

1515
import com.logicaldoc.core.PersistenceException;
1616
import com.logicaldoc.core.conversion.FormatConverterManager;
17-
import com.logicaldoc.core.document.AbstractDocument;
1817
import com.logicaldoc.core.document.Document;
1918
import com.logicaldoc.core.document.DocumentDAO;
2019
import com.logicaldoc.core.document.DocumentHistory;
2120
import com.logicaldoc.core.document.DocumentHistoryDAO;
21+
import com.logicaldoc.core.document.DocumentIndexed;
2222
import com.logicaldoc.core.document.DocumentLink;
2323
import com.logicaldoc.core.document.DocumentLinkDAO;
2424
import com.logicaldoc.core.document.DocumentManager;
2525
import com.logicaldoc.core.document.DocumentNote;
2626
import com.logicaldoc.core.document.DocumentNoteDAO;
27+
import com.logicaldoc.core.document.DocumentStatus;
2728
import com.logicaldoc.core.document.Version;
2829
import com.logicaldoc.core.folder.Folder;
2930
import com.logicaldoc.core.folder.FolderDAO;
@@ -499,7 +500,7 @@ public void lock(long docId, String username) {
499500
transaction.setUser(user);
500501

501502
try {
502-
manager.lock(docId, AbstractDocument.DOC_LOCKED, transaction);
503+
manager.lock(docId, DocumentStatus.LOCKED, transaction);
503504
} catch (PersistenceException e) {
504505
log.error(e.getMessage(), e);
505506
}
@@ -1001,7 +1002,7 @@ public String parse(Document document, String fileVersion) {
10011002
public String getText(Document document) {
10021003
String text = null;
10031004

1004-
if (document.getIndexed() == AbstractDocument.INDEX_INDEXED) {
1005+
if (document.getIndexed() == DocumentIndexed.INDEXED) {
10051006
SearchEngine indexer = Context.get(SearchEngine.class);
10061007
Hit hit = indexer.getHit(document.getId());
10071008
if (hit != null)

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

Lines changed: 33 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.util.stream.Collectors;
1010

1111
import javax.persistence.Column;
12+
import javax.persistence.EnumType;
13+
import javax.persistence.Enumerated;
1214
import javax.persistence.MappedSuperclass;
1315
import javax.persistence.Transient;
1416

@@ -60,26 +62,6 @@ public abstract class AbstractDocument extends ExtensibleObject implements Trans
6062

6163
private static final long serialVersionUID = 1L;
6264

63-
/**
64-
* Document's status unlocked: 0
65-
*/
66-
public static final int DOC_UNLOCKED = 0;
67-
68-
/**
69-
* Document's status checked out: 1
70-
*/
71-
public static final int DOC_CHECKED_OUT = 1;
72-
73-
/**
74-
* Document's status locked: 2
75-
*/
76-
public static final int DOC_LOCKED = 2;
77-
78-
/**
79-
* Document's status archived: 3
80-
*/
81-
public static final int DOC_ARCHIVED = 3;
82-
8365
/**
8466
* Document's export status unlocked: 0
8567
*/
@@ -90,26 +72,6 @@ public abstract class AbstractDocument extends ExtensibleObject implements Trans
9072
*/
9173
public static final int EXPORT_LOCKED = 1;
9274

93-
/**
94-
* Document's indexed status to index: 0
95-
*/
96-
public static final int INDEX_TO_INDEX = 0;
97-
98-
/**
99-
* Document's indexed status indexed: 1
100-
*/
101-
public static final int INDEX_INDEXED = 1;
102-
103-
/**
104-
* Document's indexed status skip: 2
105-
*/
106-
public static final int INDEX_SKIP = 2;
107-
108-
/**
109-
* Document's indexed status index just metadata: 3
110-
*/
111-
public static final int INDEX_TO_INDEX_METADATA = 3;
112-
11375
/**
11476
* Document's nature regular document: 0
11577
*/
@@ -151,15 +113,13 @@ public abstract class AbstractDocument extends ExtensibleObject implements Trans
151113
@Column(name = "ld_creatorid", nullable = false)
152114
private long creatorId;
153115

154-
/**
155-
* Whether document is checked out,locked or unlocked
156-
*
157-
* @see Document#DOC_UNLOCKED
158-
* @see Document#DOC_CHECKED_OUT
159-
* @see Document#DOC_LOCKED
160-
*/
161116
@Column(name = "ld_status")
162-
private int status = DOC_UNLOCKED;
117+
@Enumerated(EnumType.ORDINAL)
118+
private DocumentStatus status = DocumentStatus.UNLOCKED;
119+
120+
@Column(name = "ld_indexed", nullable = false)
121+
@Enumerated(EnumType.ORDINAL)
122+
private DocumentIndexed indexed = DocumentIndexed.TO_INDEX;
163123

164124
@Column(name = "ld_type", length = 255)
165125
private String type;
@@ -179,14 +139,6 @@ public abstract class AbstractDocument extends ExtensibleObject implements Trans
179139
@Column(name = "ld_filesize")
180140
private long fileSize = 0;
181141

182-
/**
183-
* The indexing status of the document, one of {@link #INDEX_TO_INDEX},
184-
* {@link #INDEX_TO_INDEX_METADATA}, {@link #INDEX_INDEXED} or
185-
* {@link #INDEX_SKIP}
186-
*/
187-
@Column(name = "ld_indexed", nullable = false)
188-
private int indexed = INDEX_TO_INDEX;
189-
190142
/**
191143
* Identifier of the barcode template to use to process this document
192144
*/
@@ -309,23 +261,6 @@ protected AbstractDocument() {
309261

310262
public abstract long getFolderId();
311263

312-
/**
313-
* The document status
314-
*
315-
* @see Document#DOC_UNLOCKED
316-
* @see Document#DOC_CHECKED_OUT
317-
* @see Document#DOC_LOCKED
318-
*
319-
* @return the document's status
320-
*/
321-
public int getStatus() {
322-
return status;
323-
}
324-
325-
public void setStatus(int status) {
326-
this.status = status;
327-
}
328-
329264
/**
330265
* The working version (the most recent version)
331266
*
@@ -343,6 +278,30 @@ public String getVersion() {
343278
public void setVersion(String version) {
344279
this.version = version;
345280
}
281+
282+
public DocumentStatus getStatus() {
283+
return status;
284+
}
285+
286+
public void setStatus(DocumentStatus status) {
287+
this.status = status;
288+
}
289+
290+
public void setStatus(int status) {
291+
this.status = DocumentStatus.values()[status];
292+
}
293+
294+
public DocumentIndexed getIndexed() {
295+
return indexed;
296+
}
297+
298+
public void setIndexed(DocumentIndexed indexed) {
299+
this.indexed = indexed;
300+
}
301+
302+
public void setIndexed(int indexed) {
303+
this.indexed = DocumentIndexed.values()[indexed];
304+
}
346305

347306
/**
348307
* The document's last publication date. This date is altered by checkin
@@ -445,14 +404,6 @@ public void setLanguage(String language) {
445404
this.language = language;
446405
}
447406

448-
public int getIndexed() {
449-
return indexed;
450-
}
451-
452-
public void setIndexed(int indexed) {
453-
this.indexed = indexed;
454-
}
455-
456407
/**
457408
* Computes the title that is the file name without the extension
458409
*
@@ -663,7 +614,7 @@ public void setExportId(Long exportId) {
663614
}
664615

665616
public boolean isToIndex() {
666-
return indexed == INDEX_TO_INDEX;
617+
return indexed == DocumentIndexed.TO_INDEX;
667618
}
668619

669620
public int getBarcoded() {

0 commit comments

Comments
 (0)