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 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; }
@Test public void thatCreatingOrReadingInitialCasForNewDocumentCreatesNewCas() throws Exception { when(importExportService.importCasFromFile(any(File.class), any(Project.class), any())).thenReturn(JCasFactory.createText("Test")); SourceDocument doc = makeSourceDocument(1l, 1l, "test"); JCas cas = sut.createOrReadInitialCas(doc); assertThat(cas).isNotNull(); assertThat(cas.getDocumentText()).isEqualTo("Test"); assertThat(storageService.getCasFile(doc, WebAnnoConst.INITIAL_CAS_PSEUDO_USER)).exists(); }
tmpFile = File.createTempFile("upload", ".bin"); aFile.transferTo(tmpFile); annotationCas = importExportService.importCasFromFile(tmpFile, project, format);
tmpFile = File.createTempFile("upload", ".bin"); aFile.transferTo(tmpFile); annotationCas = importExportService.importCasFromFile(tmpFile, project, format);
@Test public void thatReadingNonExistentAnnotationCasCreatesNewCas() throws Exception { SourceDocument sourceDocument = makeSourceDocument(1l, 1l, "test"); User user = makeUser(); when(userRepository.get(user.getUsername())).thenReturn(user); when(entityManager.createQuery(anyString(), any())).thenThrow(NoResultException.class); when(importExportService.importCasFromFile(any(File.class), any(Project.class), any())).thenReturn(JCasFactory.createText("Test")); JCas cas = sut.readAnnotationCas(sourceDocument, user.getUsername()); assertThat(cas).isNotNull(); assertThat(cas.getDocumentText()).isEqualTo("Test"); assertThat(storageService.getCasFile(sourceDocument, user.getUsername())).exists(); }
@Override public JCas createOrReadInitialCas(SourceDocument aDocument) throws IOException { Validate.notNull(aDocument, "Source document must be specified"); log.info("Loading initial CAS for source document " + "[{}]({}) in project [{}]({})", aDocument.getName(), aDocument.getId(), aDocument.getProject().getName(), aDocument.getProject().getId()); return casStorageService.readOrCreateCas(aDocument, INITIAL_CAS_PSEUDO_USER, () -> { // Normally, the initial CAS should be created on document import, but after // adding this feature, the existing projects do not yet have initial CASes, so // we create them here lazily try { return importExportService.importCasFromFile( getSourceDocumentFile(aDocument), aDocument.getProject(), aDocument.getFormat()); } catch (UIMAException e) { throw new IOException("Unable to create CAS: " + e.getMessage(), e); } }); }
@Override public JCas createOrReadInitialCas(SourceDocument aDocument) throws IOException { Validate.notNull(aDocument, "Source document must be specified"); log.info("Loading initial CAS for source document " + "[{}]({}) in project [{}]({})", aDocument.getName(), aDocument.getId(), aDocument.getProject().getName(), aDocument.getProject().getId()); return casStorageService.readOrCreateCas(aDocument, INITIAL_CAS_PSEUDO_USER, () -> { // Normally, the initial CAS should be created on document import, but after // adding this feature, the existing projects do not yet have initial CASes, so // we create them here lazily try { return importExportService.importCasFromFile( getSourceDocumentFile(aDocument), aDocument.getProject(), aDocument.getFormat()); } catch (UIMAException e) { throw new IOException("Unable to create CAS: " + e.getMessage(), e); } }); }
cas = importExportService.importCasFromFile(aFile, aDocument.getProject(), aDocument.getFormat()); automationCasStorageService.analyzeAndRepair(aDocument, cas.getCas());
@Override public JCas createInitialCas(TrainingDocument aDocument) throws UIMAException, IOException, ClassNotFoundException { JCas jcas = importExportService.importCasFromFile(getTrainingDocumentFile(aDocument), aDocument.getProject(), aDocument.getFormat()); automationCasStorageService.analyzeAndRepair(aDocument, jcas.getCas()); CasPersistenceUtils.writeSerializedCas(jcas, getCasFile(aDocument)); return jcas; }