@Override public JCas readCorrectionCas(SourceDocument aDocument) throws IOException { return casStorageService.readCas(aDocument, CORRECTION_USER); }
@Override @PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_USER')") public void writeCorrectionCas(JCas aJcas, SourceDocument aDocument) throws IOException { casStorageService.writeCas(aDocument, aJcas, CORRECTION_USER); }
@Override public void deleteCurationCas(SourceDocument aDocument) throws IOException { casStorageService.deleteCas(aDocument, CURATION_USER); }
@Test public void testWriteReadExistsDeleteCas() throws Exception { SourceDocument doc = makeSourceDocument(1l, 1l); JCas cas = JCasFactory.createText("This is a test"); String user = "test"; sut.writeCas(doc, cas, user); assertThat(sut.getCasFile(doc, user)).exists(); assertThat(sut.existsCas(doc, user)).isTrue(); JCas cas2 = sut.readCas(doc, user); assertThat(cas2.getDocumentText()).isEqualTo(cas.getDocumentText()); sut.deleteCas(doc, user); assertThat(sut.getCasFile(doc, user)).doesNotExist(); assertThat(sut.existsCas(doc, user)).isFalse(); }
@Test public void testReadOrCreateCas() throws Exception { SourceDocument doc = makeSourceDocument(2l, 2l); String user = "test"; JCas cas = sut.readOrCreateCas(doc, user, () -> { try { return JCasFactory.createText("This is a test"); } catch (UIMAException e) { throw new IOException(e); } }); assertThat(sut.getCasFile(doc, user)).exists(); assertThat(sut.existsCas(doc, user)).isTrue(); JCas cas2 = sut.readCas(doc, user); assertThat(cas2.getDocumentText()).isEqualTo(cas.getDocumentText()); sut.deleteCas(doc, user); assertThat(sut.getCasFile(doc, user)).doesNotExist(); assertThat(sut.existsCas(doc, user)).isFalse(); }
private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException casStorageService.disableCache(); JCas initialCas = createOrReadInitialCasWithoutSaving(sd, messageSet); casDoctor.repair(project, initialCas.getCas(), messageSet.messages); casStorageService.writeCas(sd, initialCas, INITIAL_CAS_PSEUDO_USER); sd.getName() + " [" + CORRECTION_USER + "]"); try { JCas correctionCas = casStorageService.readCas(sd, CORRECTION_USER, false); casDoctor.repair(project, correctionCas.getCas(), messageSet.messages); CasPersistenceUtils.writeSerializedCas(correctionCas, sd.getName() + " [" + CURATION_USER + "]"); try { JCas curationCas = casStorageService.readCas(sd, CURATION_USER, false); casDoctor.repair(project, curationCas.getCas(), messageSet.messages); CasPersistenceUtils.writeSerializedCas(curationCas, sd.getName() + " [" + ad.getUser() + "]"); try { JCas userCas = casStorageService.readCas(ad.getDocument(), ad.getUser(), false); casDoctor.repair(project, userCas.getCas(), messageSet.messages);
@Test public void testCasMetadataGetsCreated() throws Exception { List<TypeSystemDescription> typeSystems = new ArrayList<>(); typeSystems.add(createTypeSystemDescription()); typeSystems.add(CasMetadataUtils.getInternalTypeSystem()); JCas cas = JCasFactory.createJCas(mergeTypeSystems(typeSystems)); SourceDocument doc = makeSourceDocument(1l, 1l); String user = "test"; sut.writeCas(doc, cas, user); JCas cas2 = sut.readCas(doc, user); List<CASMetadata> cmds = new ArrayList<>(select(cas2, CASMetadata.class)); assertThat(cmds).hasSize(1); assertThat(cmds.get(0).getProjectId()).isEqualTo(doc.getProject().getId()); assertThat(cmds.get(0).getSourceDocumentId()).isEqualTo(doc.getId()); assertThat(cmds.get(0).getLastChangedOnDisk()) .isEqualTo(sut.getCasTimestamp(doc, user).get()); }
casStorageService.performExclusiveBulkOperation(() -> { for (SourceDocument doc : documentService.listSourceDocuments(project)) { for (AnnotationDocument ann : documentService.listAllAnnotationDocuments(doc)) { try { JCas cas = casStorageService.readCas(doc, ann.getUser()); annotationService.upgradeCas(cas.getCas(), doc, ann.getUser()); casStorageService.writeCas(doc, cas, ann.getUser()); JCas cas = casStorageService.readCas(doc, CURATION_USER); annotationService.upgradeCas(cas.getCas(), doc, CURATION_USER); casStorageService.writeCas(doc, cas, CURATION_USER);
private JCas createOrReadInitialCasWithoutSaving(SourceDocument aDocument, LogMessageSet aMessageSet) throws IOException, UIMAException { JCas cas; if (casStorageService.existsCas(aDocument, INITIAL_CAS_PSEUDO_USER)) { cas = casStorageService.readCas(aDocument, INITIAL_CAS_PSEUDO_USER, false); } else { cas = importExportService.importCasFromFile( documentService.getSourceDocumentFile(aDocument), aDocument.getProject(), aDocument.getFormat()); aMessageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "Created initial CAS for [" + aDocument.getName() + "]")); } return cas; }
private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException casStorageService.disableCache(); sd.getName() + " [" + CORRECTION_USER + "]"); try { JCas correctionCas = casStorageService.readCas(sd, CORRECTION_USER, false); casDoctor.analyze(project, correctionCas.getCas(), messageSet.messages); sd.getName() + " [" + CURATION_USER + "]"); try { JCas curationCas = casStorageService.readCas(sd, CURATION_USER, false); casDoctor.analyze(project, curationCas.getCas(), messageSet.messages); sd.getName() + " [" + ad.getUser() + "]"); try { JCas userCas = casStorageService.readCas(ad.getDocument(), ad.getUser(), false); casDoctor.analyze(project, userCas.getCas(), messageSet.messages);
@Override public Optional<Long> getCorrectionCasTimestamp(SourceDocument aDocument) throws IOException { Validate.notNull(aDocument, "Source document must be specified"); return casStorageService.getCasTimestamp(aDocument, CORRECTION_USER); } }
boolean cacheEnabled = false; try { cacheEnabled = casStorageService.isCacheEnabled(); casStorageService.disableCache(); mergeJCas = documentService.readAnnotationCas(randomAnnotationDocument); casStorageService.enableCache();
@Override @Transactional public boolean existsCas(SourceDocument aDocument, String aUser) throws IOException { return casStorageService.existsCas(aDocument, aUser); }
@Override public File getCasFile(SourceDocument aDocument, String aUser) throws IOException { return casStorageService.getCasFile(aDocument, aUser); }
@Override @Transactional public JCas readAnnotationCas(SourceDocument aDocument, String aUserName) throws IOException { // If there is no CAS yet for the source document, create one. JCas jcas = casStorageService.readOrCreateCas(aDocument, aUserName, () -> { // Convert the source file into an annotation CAS return createOrReadInitialCas(aDocument); }); // We intentionally do not upgrade the CAS here because in general the IDs // must remain stable. If an upgrade is required the caller should do it return jcas; }
@Override public void removeCurationDocumentContent(SourceDocument aSourceDocument, String aUsername) throws IOException { if (new File(casStorageService.getAnnotationFolder(aSourceDocument), WebAnnoConst.CURATION_USER + ".ser").exists()) { FileUtils.forceDelete(new File(casStorageService.getAnnotationFolder(aSourceDocument), WebAnnoConst.CURATION_USER + ".ser")); try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aSourceDocument.getProject().getId()))) { Project project = aSourceDocument.getProject(); log.info("Removed curation of source document [{}]({}) from project [{}]({})", aSourceDocument.getName(), aSourceDocument.getId(), project.getName(), project.getId()); } } }
private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException casStorageService.disableCache(); JCas initialCas = createOrReadInitialCasWithoutSaving(sd, messageSet); casDoctor.repair(project, initialCas.getCas(), messageSet.messages); casStorageService.writeCas(sd, initialCas, INITIAL_CAS_PSEUDO_USER); sd.getName() + " [" + CORRECTION_USER + "]"); try { JCas correctionCas = casStorageService.readCas(sd, CORRECTION_USER, false); casDoctor.repair(project, correctionCas.getCas(), messageSet.messages); CasPersistenceUtils.writeSerializedCas(correctionCas, sd.getName() + " [" + CURATION_USER + "]"); try { JCas curationCas = casStorageService.readCas(sd, CURATION_USER, false); casDoctor.repair(project, curationCas.getCas(), messageSet.messages); CasPersistenceUtils.writeSerializedCas(curationCas, sd.getName() + " [" + ad.getUser() + "]"); try { JCas userCas = casStorageService.readCas(ad.getDocument(), ad.getUser(), false); casDoctor.repair(project, userCas.getCas(), messageSet.messages);
casStorageService.performExclusiveBulkOperation(() -> { for (SourceDocument doc : documentService.listSourceDocuments(project)) { for (AnnotationDocument ann : documentService.listAllAnnotationDocuments(doc)) { try { JCas cas = casStorageService.readCas(doc, ann.getUser()); annotationService.upgradeCas(cas.getCas(), doc, ann.getUser()); casStorageService.writeCas(doc, cas, ann.getUser()); JCas cas = casStorageService.readCas(doc, CURATION_USER); annotationService.upgradeCas(cas.getCas(), doc, CURATION_USER); casStorageService.writeCas(doc, cas, CURATION_USER);
private JCas createOrReadInitialCasWithoutSaving(SourceDocument aDocument, LogMessageSet aMessageSet) throws IOException, UIMAException { JCas cas; if (casStorageService.existsCas(aDocument, INITIAL_CAS_PSEUDO_USER)) { cas = casStorageService.readCas(aDocument, INITIAL_CAS_PSEUDO_USER, false); } else { cas = importExportService.importCasFromFile( documentService.getSourceDocumentFile(aDocument), aDocument.getProject(), aDocument.getFormat()); aMessageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "Created initial CAS for [" + aDocument.getName() + "]")); } return cas; }
private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException casStorageService.disableCache(); sd.getName() + " [" + CORRECTION_USER + "]"); try { JCas correctionCas = casStorageService.readCas(sd, CORRECTION_USER, false); casDoctor.analyze(project, correctionCas.getCas(), messageSet.messages); sd.getName() + " [" + CURATION_USER + "]"); try { JCas curationCas = casStorageService.readCas(sd, CURATION_USER, false); casDoctor.analyze(project, curationCas.getCas(), messageSet.messages); sd.getName() + " [" + ad.getUser() + "]"); try { JCas userCas = casStorageService.readCas(ad.getDocument(), ad.getUser(), false); casDoctor.analyze(project, userCas.getCas(), messageSet.messages);