Skip to content

Commit

Permalink
Merge branch 'main' into feature/4334-New-take-on-TEI-support-based-o…
Browse files Browse the repository at this point in the history
…n-generic-XML-support

* main:
  #4347 - CAS doctor fails to generate a proper report on projects not containing INITIAL_CASes
  #4349 - Project has date in the 70ies if no data is set in JSON
  • Loading branch information
reckart committed Dec 5, 2023
2 parents ec7472c + 72004bf commit daa412d
Show file tree
Hide file tree
Showing 10 changed files with 73 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 @@ -19,6 +19,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.zip.ZipFile;

import de.tudarmstadt.ukp.clarin.webanno.api.export.FullProjectExportRequest;
Expand Down Expand Up @@ -88,6 +89,15 @@ public void importData(ProjectImportRequest aRequest, Project aProject,
aProject.setUpdated(aExProject.getUpdated());
aProject.setAnonymousCuration(aExProject.isAnonymousCuration());

// Set dates to now if no dates are set in the exported project
var now = new Date();
if (aProject.getCreated() == null || aProject.getCreated().getTime() == 0) {
aProject.setCreated(now);
}
if (aProject.getUpdated() == null || aProject.getUpdated().getTime() == 0) {
aProject.setUpdated(now);
}

// Set default to LTR on import from old WebAnno versions
if (aExProject.getScriptDirection() == null) {
aProject.setScriptDirection(ScriptDirection.LTR);
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 daa412d

Please sign in to comment.