Skip to content

Commit

Permalink
new document history to tack indexation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Jun 8, 2023
1 parent bcabe9f commit 15890b3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum DocumentEvent {
RENAMED("event.renamed"),
DOWNLOADED("event.downloaded"),
INDEXED("event.indexed"),
INDEXED_ERROR("event.indexed.error"),
MOVED("event.moved"),
LOCKED("event.locked"),
UNLOCKED("event.unlocked"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.logicaldoc.core.PersistenceException;
import com.logicaldoc.core.conversion.FormatConverterManager;
import com.logicaldoc.core.document.dao.DocumentDAO;
import com.logicaldoc.core.document.dao.DocumentHistoryDAO;
import com.logicaldoc.core.document.dao.DocumentNoteDAO;
import com.logicaldoc.core.document.dao.VersionDAO;
import com.logicaldoc.core.folder.Folder;
Expand Down Expand Up @@ -486,41 +487,54 @@ public long reindex(long docId, String content, DocumentHistory transaction)

log.debug("Reindexing document {} - {}", docId, doc.getFileName());

String cont = content;
long parsingTime = 0;
if (doc.getDocRef() != null) {
// We are indexing an alias, so index the real document first
Document realDoc = documentDAO.findById(doc.getDocRef());
if (realDoc != null) {
if (realDoc.getIndexed() == AbstractDocument.INDEX_TO_INDEX
|| realDoc.getIndexed() == AbstractDocument.INDEX_TO_INDEX_METADATA)
parsingTime = reindex(realDoc.getId(), content, new DocumentHistory(transaction));

// Take the content from the real document to avoid double
// parsing
if (StringUtils.isEmpty(content))
cont = indexer.getHit(realDoc.getId()).getContent();
} else {
log.debug("Alias {} cannot be indexed because it references an unexisting document {}", doc,
doc.getDocRef());
documentDAO.initialize(doc);
doc.setIndexed(AbstractDocument.INDEX_SKIP);
documentDAO.store(doc);
return 0;
String cont;
long parsingTime;
try {
cont = content;
parsingTime = 0;
if (doc.getDocRef() != null) {
// We are indexing an alias, so index the real document first
Document realDoc = documentDAO.findById(doc.getDocRef());
if (realDoc != null) {
if (realDoc.getIndexed() == AbstractDocument.INDEX_TO_INDEX
|| realDoc.getIndexed() == AbstractDocument.INDEX_TO_INDEX_METADATA)
parsingTime = reindex(realDoc.getId(), content, new DocumentHistory(transaction));

// Take the content from the real document to avoid double
// parsing
if (StringUtils.isEmpty(content))
cont = indexer.getHit(realDoc.getId()).getContent();
} else {
log.debug("Alias {} cannot be indexed because it references an unexisting document {}", doc,
doc.getDocRef());
documentDAO.initialize(doc);
doc.setIndexed(AbstractDocument.INDEX_SKIP);
documentDAO.store(doc);
return 0;
}
}
}

if (StringUtils.isEmpty(cont) && doc.getIndexed() != AbstractDocument.INDEX_TO_INDEX_METADATA) {
// Extracts the content from the file. This may take very long
// time.
Date beforeParsing = new Date();
cont = parseDocument(doc, null);
parsingTime = TimeDiff.getTimeDifference(beforeParsing, new Date(), TimeField.MILLISECOND);
if (StringUtils.isEmpty(cont) && doc.getIndexed() != AbstractDocument.INDEX_TO_INDEX_METADATA) {
// Extracts the content from the file. This may take very long
// time.
Date beforeParsing = new Date();
cont = parseDocument(doc, null);
parsingTime = TimeDiff.getTimeDifference(beforeParsing, new Date(), TimeField.MILLISECOND);
}

// This may take time
addHIt(doc, cont);
} catch (PersistenceException | ParseException e) {
if (transaction != null) {
transaction.setEvent(DocumentEvent.INDEXED_ERROR.toString());
transaction.setComment(e.getMessage());
transaction.setDocument(doc);
DocumentHistoryDAO hDao=(DocumentHistoryDAO)Context.get().getBean(DocumentHistoryDAO.class);
hDao.store(transaction);
}
throw e;
}

// This may take time
addHIt(doc, cont);

// For additional safety update the DB directly
doc.setIndexed(AbstractDocument.INDEX_INDEXED);

Expand Down
2 changes: 2 additions & 0 deletions logicaldoc-i18n/src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ event.stamped = Applied new stamp
event.stamped.short = Applied stamp
event.indexed = Document has been indexed
event.indexed.short = Indexed
event.indexed.error = Error indexing the document
event.indexed.error.short = Indexing error
event.dticket.created = A download ticket has been created
event.dticket.created.short = Created download ticket
event.password.protected = The document has been protected by a password
Expand Down

0 comments on commit 15890b3

Please sign in to comment.