Skip to content

Commit

Permalink
Merge branch 'release/32.x'
Browse files Browse the repository at this point in the history
* release/32.x:
  #4782 - Avoid duplicate key error when importing documents very rapidly
  #4778 - Links and other active elements in PDFs interfere with annotation and should be disabled
  • Loading branch information
reckart committed Apr 30, 2024
2 parents 7003749 + 83c394f commit b9c54b2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void renderHead(IHeaderResponse aResponse)
aResponse.render(JavaScriptHeaderItem.forReference(PdfJsViewerJavaScriptReference.get()));
var script = String.join("\n", //
"window.addEventListener('DOMContentLoaded', function() {", //
" PDFViewerApplicationOptions.set('annotationMode', 0);", //
" PDFViewerApplicationOptions.set('defaultUrl', null);", //
" PDFViewerApplicationOptions.set('disablePreferences', true);", //
" PDFViewerApplicationOptions.set('workerSrc', 'pdf.worker.min.js');", //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private boolean isBeingDeleted(long aProjectId)
private PooledIndex acquireIndex(long aProjectId)
{
synchronized (indexes) {
PooledIndex pooledIndex = indexes.get(aProjectId);
var pooledIndex = indexes.get(aProjectId);

if (pooledIndex != null && pooledIndex.isTombstone()) {
throw new IllegalStateException("Project [" + aProjectId
Expand Down Expand Up @@ -364,7 +364,7 @@ private PooledIndex acquireIndex(long aProjectId)
}

if (pooledIndex == null) {
Index index = loadIndex(aProjectId);
var index = loadIndex(aProjectId);
pooledIndex = new PooledIndex(index);
indexes.put(aProjectId, pooledIndex);
}
Expand Down Expand Up @@ -443,21 +443,22 @@ public void onLayerConfigurationChanged(LayerConfigurationChangedEvent aEvent)
}

@Override
@Transactional
public void indexDocument(SourceDocument aSourceDocument, byte[] aBinaryCas)
{
try (PooledIndex pooledIndex = acquireIndex(aSourceDocument.getProject().getId())) {
try (var pooledIndex = acquireIndex(aSourceDocument.getProject().getId())) {
indexDocument(pooledIndex, aSourceDocument, aBinaryCas);
}
}

private void indexDocument(PooledIndex aPooledIndex, SourceDocument aSourceDocument,
byte[] aBinaryCas)
{
Project project = aSourceDocument.getProject();
var project = aSourceDocument.getProject();

log.debug("Request to index source document {} in project {}", aSourceDocument, project);

Index index = aPooledIndex.get();
var index = aPooledIndex.get();
// Index already initialized? If not, schedule full re-indexing job. This will also
// index the given document, so we can stop here after scheduling the re-indexing.
if (!index.getPhysicalIndex().isCreated()) {
Expand Down Expand Up @@ -736,7 +737,7 @@ public boolean isIndexValid(Project aProject)
return false;
}

return !pooledIndex.get().getInvalid();
return !pooledIndex.get().isInvalid();
}
}

Expand Down Expand Up @@ -803,7 +804,7 @@ private void ensureIndexIsCreatedAndValid(Project aProject, Index aIndex)
}

// Is the index valid?
if (aIndex.getInvalid()) {
if (aIndex.isInvalid()) {
if (getIndexProgress(aProject).isEmpty()) {
// Index is invalid, schedule a new index rebuild
enqueueReindexTask(aProject, "ensureIndexIsCreatedAndValid[invalid]");
Expand All @@ -830,8 +831,11 @@ private void ensureIndexIsCreatedAndValid(Project aProject, Index aIndex)

private void invalidateIndexAndForceIndexRebuild(Project aProject, Index aIndex, String aReason)
{
aIndex.setInvalid(true);
entityManager.merge(aIndex);
if (!aIndex.isInvalid()) {
// Only update flag and DB if necessary
aIndex.setInvalid(true);
entityManager.merge(aIndex);
}

enqueueReindexTask(aProject, "ensureIndexIsCreatedAndValid[doesNotExist]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Index
@JoinColumn(name = "project")
private Project project;

private Boolean invalid;
private boolean invalid;

@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = true)
Expand Down Expand Up @@ -85,14 +85,14 @@ public void setProject(Project project)
this.project = project;
}

public Boolean getInvalid()
public boolean isInvalid()
{
return invalid;
}

public void setInvalid(Boolean state)
public void setInvalid(Boolean aState)
{
this.invalid = state;
invalid = aState;
}

public Date getCreationDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public String getTitle()
@Override
public void execute()
{
try (CasStorageSession session = CasStorageSession.open()) {
try (var session = CasStorageSession.open()) {
var cas = documentService.createOrReadInitialCas(getSourceDocument(), AUTO_CAS_UPGRADE,
SHARED_READ_ONLY_ACCESS);
searchService.indexDocument(getSourceDocument(), WebAnnoCasUtil.casToByteArray(cas));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCauseMessage;
import static org.apache.wicket.event.Broadcast.BUBBLE;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -168,13 +167,13 @@ private void actionImport(AjaxRequestTarget aTarget, Form<Void> aForm)
}

try {
SourceDocument document = new SourceDocument();
var document = new SourceDocument();
document.setName(fileName);
document.setProject(project);
document.setFormat(
importExportService.getFormatByName(format.getObject()).get().getId());

try (InputStream is = documentToUpload.getInputStream()) {
try (var is = documentToUpload.getInputStream()) {
documentService.uploadSourceDocument(is, document, fullProjectTypeSystem);
}

Expand Down

0 comments on commit b9c54b2

Please sign in to comment.