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; }
FormatSupport format = importExportService.getWritableFormatById(formatId) .orElseGet(() -> { LOG.info( byte[] resource; try { exportedAnnoFile = importExportService.exportAnnotationDocument(doc, aAnnotatorId, format, doc.getName(), Mode.ANNOTATION); resource = FileUtils.readFileToByteArray(exportedAnnoFile);
private FileResourceStream export() { File downloadFile = null; String username = state.getObject().getMode() .equals(Mode.AUTOMATION) && preferences.getObject().documentType .equals(SELECTEXPORT.AUTOMATED.toString()) ? "CORRECTION_USER" : SecurityContextHolder.getContext().getAuthentication() .getName(); try { downloadFile = importExportService.exportAnnotationDocument( state.getObject().getDocument(), username, importExportService.getFormatByName(preferences.getObject().format) .get(), state.getObject().getDocument().getName(), state.getObject().getMode()); } catch (Exception e) { LOG.error("Export failed", e); error("Export failed:" + ExceptionUtils.getRootCauseMessage(e)); // This will cause the open dialog to pop up again, but at least // the error feedback message will be visible. With the // RestartResponseException the feedback message only flashes. throw new NonResettingRestartException(getPage().getPageClass()); } return new FileResourceStream(downloadFile); }
importExportService.getWritableFormatById(aFormat.get()) .orElseThrow(() -> new UnsupportedFormatException( "Format [%s] cannot be exported. Exportable formats are %s.", aFormat.get(), importExportService.getWritableFormats().stream() .map(FormatSupport::getId) .sorted()
FormatSupport format = importExportService.getWritableFormatById(formatId) .orElseThrow(() -> new UnsupportedFormatException( "Format [%s] cannot be exported. Exportable formats are %s.", aFormat, importExportService.getWritableFormats().stream() .map(FormatSupport::getId) .sorted() try { exportedFile = importExportService.exportCasToFile(jcas.getCas(), doc, doc.getName(), format, true); byte[] resource = FileUtils.readFileToByteArray(exportedFile);
if (!importExportService.getReadableFormatById(format).isPresent()) { throw new UnsupportedFormatException( "Format [%s] not supported. Acceptable formats are %s.", format, importExportService.getReadableFormats().stream() .map(FormatSupport::getId).sorted().collect(Collectors.toList())); tmpFile = File.createTempFile("upload", ".bin"); aFile.transferTo(tmpFile); annotationCas = importExportService.importCasFromFile(tmpFile, project, format);
private List<String> listReadableFormats() { return importExportService.getReadableFormats().stream().map(FormatSupport::getName) .sorted().collect(Collectors.toList()); }
document.setName(fileName); document.setProject(project); document.setFormat(importExportService.getFormatByName(format.getObject()) .get().getId());
if (!importExportService.getReadableFormatById(aFormat).isPresent()) { throw new UnsupportedFormatException( "Format [%s] not supported. Acceptable formats are %s.", aFormat, importExportService.getReadableFormats().stream() .map(FormatSupport::getId).sorted().collect(Collectors.toList()));
state = aModel; List<String> writeableFormats = importExportService.getWritableFormats().stream() .map(FormatSupport::getName).sorted().collect(Collectors.toList());
if (!importExportService.getReadableFormatById(format).isPresent()) { throw new UnsupportedFormatException( "Format [%s] not supported. Acceptable formats are %s.", format, importExportService.getReadableFormats().stream() .map(FormatSupport::getId).sorted().collect(Collectors.toList())); tmpFile = File.createTempFile("upload", ".bin"); aFile.transferTo(tmpFile); annotationCas = importExportService.importCasFromFile(tmpFile, project, format);
FormatSupport format = importExportService.getWritableFormatById(formatId) .orElseThrow(() -> new UnsupportedFormatException( "Format [%s] cannot be exported. Exportable formats are %s.", aFormat, importExportService.getWritableFormats().stream() .map(FormatSupport::getId) .sorted() try { exportedFile = importExportService.exportCasToFile(jcas.getCas(), doc, doc.getName(), format, true); byte[] resource = FileUtils.readFileToByteArray(exportedFile);
importExportService.getWritableFormatById(aFormat.get()) .orElseThrow(() -> new UnsupportedFormatException( "Format [%s] cannot be exported. Exportable formats are %s.", aFormat.get(), importExportService.getWritableFormats().stream() .map(FormatSupport::getId) .sorted()
private List<String> listReadableFormats() { return importExportService.getReadableFormats().stream().map(FormatSupport::getName) .sorted().collect(Collectors.toList()); }
document.setName(fileName); document.setProject(project); document.setFormat(importExportService.getFormatByName(format.getObject()) .get().getId());
if (!importExportService.getReadableFormatById(aFormat).isPresent()) { throw new UnsupportedFormatException( "Format [%s] not supported. Acceptable formats are %s.", aFormat, importExportService.getReadableFormats().stream() .map(FormatSupport::getId).sorted().collect(Collectors.toList()));
List<String> formats = importExportService.getWritableFormats().stream() .map(FormatSupport::getId) .sorted()
FormatSupport format = importExportService.getWritableFormatById(formatId) .orElseGet(() -> { LOG.info( File downloadableFile = importExportService.exportAnnotationDocument(srcDoc, annotatorName, format, annDoc.getName(), Mode.ANNOTATION);
@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(); }
readableFormats = importExportService.getReadableFormats().stream() .map(FormatSupport::getName).sorted().collect(Collectors.toList()); selectedFormat = readableFormats.get(0);