use of de.tudarmstadt.ukp.clarin.webanno.api.dao.casstorage.CasStorageSession in project webanno by webanno.
the class CasStorageServiceImplTest method testReadOrCreateCas.
@Test
public void testReadOrCreateCas() throws Exception {
try (CasStorageSession casStorageSession = openNested(true)) {
// Setup fixture
SourceDocument doc = makeSourceDocument(3l, 3l, "test");
String user = "test";
String text = "This is a test";
createCasFile(doc, user, text);
// Actual test
JCas cas = sut.readCas(doc, user).getJCas();
assertThat(cas.getDocumentText()).isEqualTo(text);
sut.deleteCas(doc, user);
assertThat(sut.getCasFile(doc, user)).doesNotExist();
assertThat(sut.existsCas(doc, user)).isFalse();
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.dao.casstorage.CasStorageSession in project webanno by webanno.
the class CasStorageServiceImplTest method testWriteReadExistsDeleteCas.
@Test
public void testWriteReadExistsDeleteCas() throws Exception {
try (CasStorageSession casStorageSession = openNested(true)) {
// Setup fixture
SourceDocument doc = makeSourceDocument(1l, 1l, "test");
JCas templateCas = JCasFactory.createText("This is a test");
casStorageSession.add("cas", EXCLUSIVE_WRITE_ACCESS, templateCas.getCas());
String user = "test";
sut.writeCas(doc, templateCas.getCas(), user);
assertThat(sut.getCasFile(doc, user)).exists();
assertThat(sut.existsCas(doc, user)).isTrue();
// Actual test
CAS cas = sut.readCas(doc, user);
assertThat(cas.getDocumentText()).isEqualTo(templateCas.getDocumentText());
sut.deleteCas(doc, user);
assertThat(sut.getCasFile(doc, user)).doesNotExist();
assertThat(sut.existsCas(doc, user)).isFalse();
assertThat(casStorageSession.contains(cas)).isFalse();
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.dao.casstorage.CasStorageSession in project webanno by webanno.
the class DocumentServiceImplTest method thatReadingNonExistentAnnotationCasCreatesNewCas.
@Test
public void thatReadingNonExistentAnnotationCasCreatesNewCas() throws Exception {
try (CasStorageSession session = CasStorageSession.open()) {
SourceDocument sourceDocument = makeSourceDocument(1l, 1l, "test");
User user = makeUser();
JCas cas = sut.readAnnotationCas(sourceDocument, user.getUsername()).getJCas();
assertThat(cas).isNotNull();
assertThat(cas.getDocumentText()).isEqualTo("Test");
assertThat(storageService.getCasFile(sourceDocument, user.getUsername())).exists();
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.dao.casstorage.CasStorageSession in project webanno by webanno.
the class DocumentServiceImplTest method thatCreatingOrReadingInitialCasForNewDocumentCreatesNewCas.
@Test
public void thatCreatingOrReadingInitialCasForNewDocumentCreatesNewCas() throws Exception {
try (CasStorageSession session = CasStorageSession.open()) {
SourceDocument doc = makeSourceDocument(1l, 1l, "test");
JCas cas = sut.createOrReadInitialCas(doc).getJCas();
assertThat(cas).isNotNull();
assertThat(cas.getDocumentText()).isEqualTo("Test");
assertThat(storageService.getCasFile(doc, INITIAL_CAS_PSEUDO_USER)).exists();
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.dao.casstorage.CasStorageSession in project webanno by webanno.
the class ImportExportServiceImpl method exportAnnotationDocument.
@Override
@Transactional
public File exportAnnotationDocument(SourceDocument aDocument, String aUser, FormatSupport aFormat, String aFileName, Mode aMode, boolean aStripExtension, Map<Pair<Project, String>, Object> aBulkOperationContext) throws UIMAException, IOException, ClassNotFoundException {
Map<Pair<Project, String>, Object> bulkOperationContext = aBulkOperationContext;
if (bulkOperationContext == null) {
bulkOperationContext = new HashMap<>();
}
String username;
// (Annotated) or the automated document
if (aMode.equals(ANNOTATION) || aMode.equals(AUTOMATION) || aMode.equals(CORRECTION)) {
username = aUser;
} else // The merge result will be exported
{
username = CURATION_USER;
}
// Read file
File exportFile;
try (CasStorageSession session = CasStorageSession.openNested()) {
CAS cas = casStorageService.readCas(aDocument, username);
exportFile = exportCasToFile(cas, aDocument, aFileName, aFormat, aStripExtension, aBulkOperationContext);
}
Project project = aDocument.getProject();
try (MDC.MDCCloseable closable = MDC.putCloseable(KEY_PROJECT_ID, String.valueOf(project.getId()))) {
log.info("Exported annotations [{}]({}) for user [{}] from project [{}]({}) " + "using format [{}]", aDocument.getName(), aDocument.getId(), aUser, project.getName(), project.getId(), aFormat.getId());
}
return exportFile;
}
Aggregations