use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument in project webanno by webanno.
the class AnnotationPage method getDocumentFromParameters.
private SourceDocument getDocumentFromParameters(Project aProject, StringValue documentParam) {
SourceDocument document = null;
if (documentParam != null && !documentParam.isEmpty()) {
long documentId = documentParam.toLong();
document = documentService.getSourceDocument(aProject.getId(), documentId);
}
return document;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument in project webanno by webanno.
the class AnnotationPage method getEditorCas.
@Override
public JCas getEditorCas() throws IOException {
AnnotatorState state = getModelObject();
if (state.getDocument() == null) {
throw new IllegalStateException("Please open a document first!");
}
SourceDocument aDocument = getModelObject().getDocument();
AnnotationDocument annotationDocument = documentService.getAnnotationDocument(aDocument, state.getUser());
// If there is no CAS yet for the annotation document, create one.
return documentService.readAnnotationCas(annotationDocument);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument in project webanno by webanno.
the class WebhookServiceTest method test.
@Test
public void test() {
Webhook hook = new Webhook();
hook.setUrl("http://localhost:" + port + "/test/subscribe");
hook.setTopics(asList(PROJECT_STATE, ANNOTATION_STATE, DOCUMENT_STATE));
hook.setEnabled(true);
webhooksConfiguration.setGlobalHooks(asList(hook));
Project project = new Project();
project.setState(ProjectState.NEW);
project.setId(1l);
SourceDocument doc = new SourceDocument();
doc.setProject(project);
doc.setId(2l);
doc.setState(SourceDocumentState.ANNOTATION_IN_PROGRESS);
AnnotationDocument ann = new AnnotationDocument();
ann.setProject(project);
ann.setId(3l);
ann.setDocument(doc);
ann.setState(AnnotationDocumentState.FINISHED);
applicationEventPublisher.publishEvent(new ProjectStateChangedEvent(this, project, ProjectState.CURATION_FINISHED));
applicationEventPublisher.publishEvent(new DocumentStateChangedEvent(this, doc, SourceDocumentState.NEW));
applicationEventPublisher.publishEvent(new AnnotationStateChangeEvent(this, ann, AnnotationDocumentState.IN_PROGRESS));
assertEquals(1, testService.projectStateChangeMsgs.size());
assertEquals(1, testService.docStateChangeMsgs.size());
assertEquals(1, testService.annStateChangeMsgs.size());
}
use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument in project webanno by webanno.
the class ImportUtil method createCurationDocumentContent.
/**
* Copy curation documents from the exported project
* @param zip the ZIP file.
* @param aProject the project.
* @param aRepository the repository service.
* @throws IOException if an I/O error occurs.
*/
@SuppressWarnings("rawtypes")
public static void createCurationDocumentContent(ZipFile zip, Project aProject, DocumentService aRepository) throws IOException {
for (Enumeration zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) zipEnumerate.nextElement();
// Strip leading "/" that we had in ZIP files prior to 2.0.8 (bug #985)
String entryName = normalizeEntryName(entry);
if (entryName.startsWith(CURATION_AS_SERIALISED_CAS)) {
String fileName = entryName.replace(CURATION_AS_SERIALISED_CAS, "");
// the user annotated the document is file name minus extension
// (anno1.ser)
String username = FilenameUtils.getBaseName(fileName).replace(".ser", "");
// name of the annotation document
fileName = fileName.replace(FilenameUtils.getName(fileName), "").replace("/", "");
if (fileName.trim().isEmpty()) {
continue;
}
de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument sourceDocument = aRepository.getSourceDocument(aProject, fileName);
File annotationFilePath = aRepository.getCasFile(sourceDocument, username);
FileUtils.copyInputStreamToFile(zip.getInputStream(entry), annotationFilePath);
LOG.info("Imported curation document content for user [" + username + "] for source document [" + sourceDocument.getId() + "] in project [" + aProject.getName() + "] with id [" + aProject.getId() + "]");
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument in project webanno by webanno.
the class ImportUtil method createSourceDocumentContent.
/**
* copy source document files from the exported source documents
* @param zip the ZIP file.
* @param aProject the project.
* @param aRepository the repository service.
* @throws IOException if an I/O error occurs.
*/
@SuppressWarnings("rawtypes")
public static void createSourceDocumentContent(ZipFile zip, Project aProject, DocumentService aRepository) throws IOException {
for (Enumeration zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) zipEnumerate.nextElement();
// Strip leading "/" that we had in ZIP files prior to 2.0.8 (bug #985)
String entryName = normalizeEntryName(entry);
if (entryName.startsWith(SOURCE)) {
String fileName = FilenameUtils.getName(entryName);
if (fileName.trim().isEmpty()) {
continue;
}
de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument sourceDocument = aRepository.getSourceDocument(aProject, fileName);
File sourceFilePath = aRepository.getSourceDocumentFile(sourceDocument);
FileUtils.copyInputStreamToFile(zip.getInputStream(entry), sourceFilePath);
LOG.info("Imported content for source document [" + sourceDocument.getId() + "] in project [" + aProject.getName() + "] with id [" + aProject.getId() + "]");
}
}
}
Aggregations