Skip to content

Commit

Permalink
#4347 - CAS doctor fails to generate a proper report on projects not …
Browse files Browse the repository at this point in the history
…containing INITIAL_CASes

- Disable implicit CAS doctor check when creating the INITIAL_CAS since either CAS Doctor on the panel is run immediately after or the usual option CAS Doctor check is run on document open
  • Loading branch information
reckart committed Dec 5, 2023
1 parent 7e899cc commit 200bca4
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ public CAS createOrReadInitialCas(SourceDocument aDocument, CasUpgradeMode aUpgr
// adding this feature, the existing projects do not yet have initial CASes, so
// we create them here lazily
try {
return importExportService.importCasFromFile(
return importExportService.importCasFromFileNoChecks(
getSourceDocumentFile(aDocument), aDocument,
aFullProjectTypeSystem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void setup() throws Exception
}).when(sut).getAnnotationDocument(any(), any(String.class));

lenient()
.when(importExportService.importCasFromFile(any(File.class),
.when(importExportService.importCasFromFileNoChecks(any(File.class),
any(SourceDocument.class), any()))
.thenReturn(CasFactory.createText("Test"));
}
Expand All @@ -146,9 +146,9 @@ public void setup() throws Exception
public void thatCreatingOrReadingInitialCasForNewDocumentCreatesNewCas() throws Exception
{
try (CasStorageSession session = CasStorageSession.open()) {
SourceDocument doc = makeSourceDocument(1l, 1l, "test");
var doc = makeSourceDocument(1l, 1l, "test");

JCas cas = sut.createOrReadInitialCas(doc).getJCas();
var cas = sut.createOrReadInitialCas(doc).getJCas();

assertThat(cas).isNotNull();
assertThat(cas.getDocumentText()).isEqualTo("Test");
Expand Down Expand Up @@ -178,8 +178,8 @@ public void testHighConcurrencySingleUser() throws Exception
var typeSystem = mergeTypeSystems(
asList(createTypeSystemDescription(), getInternalTypeSystem()));

when(importExportService.importCasFromFile(any(File.class), any(SourceDocument.class),
any())).then(_invocation -> {
when(importExportService.importCasFromFileNoChecks(any(File.class),
any(SourceDocument.class), any())).then(_invocation -> {
CAS cas = createCas(typeSystem);
cas.setDocumentText(docText);
return cas;
Expand Down Expand Up @@ -246,8 +246,8 @@ public void testHighConcurrencyMultiUser() throws Exception
var typeSystem = mergeTypeSystems(
asList(createTypeSystemDescription(), getInternalTypeSystem()));

when(importExportService.importCasFromFile(any(File.class), any(SourceDocument.class),
any())).then(_invocation -> {
when(importExportService.importCasFromFileNoChecks(any(File.class),
any(SourceDocument.class), any())).then(_invocation -> {
CAS cas = createCas(typeSystem);
cas.setDocumentText(docText);
return cas;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ CAS importCasFromFile(File aFile, SourceDocument aDocument, String aFormat,
TypeSystemDescription aFullProjectTypeSystem)
throws UIMAException, IOException;

CAS importCasFromFileNoChecks(File aFile, SourceDocument aDocument)
throws UIMAException, IOException;

CAS importCasFromFileNoChecks(File aFile, SourceDocument aDocument,
TypeSystemDescription aFullProjectTypeSystem)
throws UIMAException, IOException;

/**
* Exports the given CAS to a file on disk.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,37 @@ public CAS importCasFromFile(File aFile, SourceDocument aDocument,
public CAS importCasFromFile(File aFile, SourceDocument aDocument, String aFormat,
TypeSystemDescription aFullProjectTypeSystem)
throws UIMAException, IOException
{
var cas = importCasFromFileNoChecks(aFile, aDocument, aFormat, aFullProjectTypeSystem);

// Convert the source document to CAS
var format = getReadableFormatById(aFormat).orElseThrow(
() -> new IOException("No reader available for format [" + aFormat + "]"));

runCasDoctorOnImport(aDocument, format, cas);

return cas;
}

@Override
public CAS importCasFromFileNoChecks(File aFile, SourceDocument aDocument)
throws UIMAException, IOException
{
return importCasFromFileNoChecks(aFile, aDocument, aDocument.getFormat(), null);
}

@Override
public CAS importCasFromFileNoChecks(File aFile, SourceDocument aDocument,
TypeSystemDescription aFullProjectTypeSystem)
throws UIMAException, IOException
{
return importCasFromFileNoChecks(aFile, aDocument, aDocument.getFormat(),
aFullProjectTypeSystem);
}

private CAS importCasFromFileNoChecks(File aFile, SourceDocument aDocument, String aFormat,
TypeSystemDescription aFullProjectTypeSystem)
throws UIMAException, IOException
{
TypeSystemDescription tsd = aFullProjectTypeSystem;

Expand All @@ -311,11 +342,11 @@ public CAS importCasFromFile(File aFile, SourceDocument aDocument, String aForma
}

// Convert the source document to CAS
FormatSupport format = getReadableFormatById(aFormat).orElseThrow(
var format = getReadableFormatById(aFormat).orElseThrow(
() -> new IOException("No reader available for format [" + aFormat + "]"));

// Prepare a CAS with the project type system
CAS cas = WebAnnoCasUtil.createCas(tsd);
var cas = WebAnnoCasUtil.createCas(tsd);
format.read(aDocument.getProject(), WebAnnoCasUtil.getRealCas(cas), aFile);

// Create sentence / token annotations if they are missing - sentences first because
Expand All @@ -327,8 +358,6 @@ public CAS importCasFromFile(File aFile, SourceDocument aDocument, String aForma
cas.getAnnotationIndex(getType(cas, Token.class)).size(),
cas.getAnnotationIndex(getType(cas, Sentence.class)).size(), aFile, aFile.length());

runCasDoctorOnImport(aDocument, format, cas);

return cas;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public void setup() throws Exception
@Test
public void testThatAnnotationDocumentsForNonExistingUserAreNotReturned() throws Exception
{
SourceDocument doc = sut.createSourceDocument(new SourceDocument("doc", project, "text"));
var doc = sut.createSourceDocument(new SourceDocument("doc", project, "text"));

AnnotationDocument ann = sut
var ann = sut
.createAnnotationDocument(new AnnotationDocument(annotator1.getUsername(), doc));

assertThat(sut.listAnnotationDocuments(doc))
Expand All @@ -127,9 +127,9 @@ public void testThatAnnotationDocumentsForNonExistingUserAreNotReturned() throws
@Test
public void thatExplicitUserActionsSetAnnotatorState()
{
SourceDocument doc = sut.createSourceDocument(new SourceDocument("doc", project, "text"));
var doc = sut.createSourceDocument(new SourceDocument("doc", project, "text"));

AnnotationDocument ann = sut
var ann = sut
.createAnnotationDocument(new AnnotationDocument(annotator1.getUsername(), doc));

sut.setAnnotationDocumentState(ann, AnnotationDocumentState.IGNORE);
Expand Down Expand Up @@ -191,10 +191,10 @@ public void thatExplicitUserActionsSetAnnotatorState()
@Test
public void thatResettingADocumentSetsAlsoResetsTheStates() throws Exception
{
SourceDocument doc = sut
var doc = sut
.createSourceDocument(new SourceDocument("doc.txt", project, TextFormatSupport.ID));

AnnotationDocument ann = sut
var ann = sut
.createAnnotationDocument(new AnnotationDocument(annotator1.getUsername(), doc));

try (var session = CasStorageSession.open()) {
Expand Down Expand Up @@ -226,7 +226,7 @@ DocumentImportExportService documentImportExportService(
{
var tsd = createTypeSystemDescription();
var importService = mock(DocumentImportExportService.class);
when(importService.importCasFromFile(any(), any(), any()))
when(importService.importCasFromFileNoChecks(any(), any(), any()))
.thenReturn(CasCreationUtils.createCas(tsd, null, null, null));
return importService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm)

try {
casStorageService.forceActionOnCas(sd, INITIAL_CAS_PSEUDO_USER,
(doc, user) -> createOrReadInitialCasWithoutSaving(doc, messageSet),
(doc, user) -> createOrReadInitialCasWithoutSavingOrChecks(doc, messageSet),
(cas) -> casDoctor.repair(project, cas, messageSet.messages), //
true);
}
Expand Down Expand Up @@ -257,7 +257,7 @@ private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm)
try {
objectCount++;
casStorageService.forceActionOnCas(sd, INITIAL_CAS_PSEUDO_USER,
(doc, user) -> createOrReadInitialCasWithoutSaving(doc, messageSet),
(doc, user) -> createOrReadInitialCasWithoutSavingOrChecks(doc, messageSet),
(cas) -> casDoctor.analyze(project, cas, messageSet.messages), //
false);
}
Expand Down Expand Up @@ -341,7 +341,7 @@ private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm)
aTarget.add(this);
}

private CAS createOrReadInitialCasWithoutSaving(SourceDocument aDocument,
private CAS createOrReadInitialCasWithoutSavingOrChecks(SourceDocument aDocument,
LogMessageSet aMessageSet)
throws IOException, UIMAException
{
Expand All @@ -350,8 +350,8 @@ private CAS createOrReadInitialCasWithoutSaving(SourceDocument aDocument,
UNMANAGED_NON_INITIALIZING_ACCESS);
}

CAS cas = importExportService
.importCasFromFile(documentService.getSourceDocumentFile(aDocument), aDocument);
var cas = importExportService.importCasFromFileNoChecks(
documentService.getSourceDocumentFile(aDocument), aDocument);
aMessageSet.messages.add(
LogMessage.info(getClass(), "Created initial CAS for [%s]", aDocument.getName()));
return cas;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ DocumentImportExportService documentImportExportService(
{
var tsd = createTypeSystemDescription();
var importService = mock(DocumentImportExportService.class);
when(importService.importCasFromFile(any(), any(), any()))
when(importService.importCasFromFileNoChecks(any(), any(), any()))
.thenReturn(CasCreationUtils.createCas(tsd, null, null, null));
return importService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ DocumentImportExportService documentImportExportService(
{
var tsd = createTypeSystemDescription();
var importService = mock(DocumentImportExportService.class);
when(importService.importCasFromFile(any(), any(), any()))
when(importService.importCasFromFileNoChecks(any(), any(), any()))
.thenReturn(CasCreationUtils.createCas(tsd, null, null, null));
return importService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ DocumentImportExportService documentImportExportService(
{
var tsd = createTypeSystemDescription();
var importService = mock(DocumentImportExportService.class);
when(importService.importCasFromFile(any(), any(), any()))
when(importService.importCasFromFileNoChecks(any(), any(), any()))
.thenReturn(CasCreationUtils.createCas(tsd, null, null, null));
return importService;
}
Expand Down

0 comments on commit 200bca4

Please sign in to comment.