use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class CurationDocumentServiceImpl method removeCurationDocumentContent.
@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());
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class AutomationServiceEventAdapter method onBeforeProjectRemove.
@EventListener
public void onBeforeProjectRemove(BeforeProjectRemovedEvent aEvent) throws Exception {
Project project = aEvent.getProject();
for (TrainingDocument document : service.listTrainingDocuments(project)) {
service.removeTrainingDocument(document);
}
for (MiraTemplate template : service.listMiraTemplates(project)) {
// remove associated TRAIN and OTHER features from the Mira Template
template.setTrainFeature(null);
template.setOtherFeatures(null);
service.removeMiraTemplate(template);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class ConstraintsServiceEventAdapter method onProjectImport.
@EventListener
public void onProjectImport(ProjectImportEvent aEvent) throws Exception {
Project project = aEvent.getProject();
ZipFile zipFile = aEvent.getZip();
for (Enumeration zipEnumerate = zipFile.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 = ZipUtils.normalizeEntryName(entry);
if (entryName.startsWith(ConstraintsService.CONSTRAINTS + "/")) {
String fileName = FilenameUtils.getName(entry.getName());
if (fileName.trim().isEmpty()) {
continue;
}
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.setProject(project);
constraintSet.setName(fileName);
service.createConstraintSet(constraintSet);
service.writeConstraintSet(constraintSet, zipFile.getInputStream(entry));
log.info("Imported constraint [" + fileName + "] for project [" + project.getName() + "] with id [" + project.getId() + "]");
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class ExportServiceImpl method generateZipFile.
@Override
public File generateZipFile(final ProjectExportRequest aRequest) throws IOException, UIMAException, ClassNotFoundException, ProjectExportException {
// Directory to store source documents and annotation documents
File exportTempDir = File.createTempFile("webanno-project", "export");
exportTempDir.delete();
exportTempDir.mkdirs();
// Target file
File projectZipFile = new File(exportTempDir.getAbsolutePath() + ".zip");
boolean success = false;
try {
// all metadata and project settings data from the database as JSON file
File projectSettings = File.createTempFile(EXPORTED_PROJECT, ".json");
Project project = aRequest.project.getObject();
if (isNull(project.getId())) {
throw new ProjectExportException("Project not yet created. Please save project details first!");
}
de.tudarmstadt.ukp.clarin.webanno.export.model.Project exProjekt = ExportUtil.exportProjectSettings(annotationService, Optional.ofNullable(automationService), documentService, projectService, project, projectSettings, exportTempDir);
JSONUtil.generatePrettyJson(exProjekt, projectSettings);
FileUtils.copyFileToDirectory(projectSettings, exportTempDir);
aRequest.progress = 9;
ExportUtil.exportSourceDocuments(documentService, aRequest, project, exportTempDir);
if (automationService != null) {
ExportUtil.exportTrainingDocuments(automationService, aRequest, project, exportTempDir);
}
ExportUtil.exportAnnotationDocuments(documentService, importExportService, userRepository, aRequest, exportTempDir);
ExportUtil.exportProjectLog(projectService, project, exportTempDir);
ExportUtil.exportGuideLine(projectService, project, exportTempDir);
ExportUtil.exportProjectMetaInf(projectService, project, exportTempDir);
if (constraintsService != null) {
ExportUtil.exportProjectConstraints(constraintsService, project, exportTempDir);
}
aRequest.progress = 90;
ExportUtil.exportCuratedDocuments(documentService, importExportService, aRequest, exportTempDir, true);
try {
ZipUtils.zipFolder(exportTempDir, projectZipFile);
} finally {
FileUtils.forceDelete(projectSettings);
System.gc();
FileUtils.forceDelete(exportTempDir);
}
aRequest.progress = 100;
success = true;
return projectZipFile;
} finally {
if (!success) {
try {
FileUtils.forceDelete(exportTempDir);
} catch (IOException e) {
log.error("Unable to delete temporary export directory [" + exportTempDir + "]");
}
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class ExportUtil method exportAnnotationDocuments.
/**
* Copy annotation document as Serialized CAS from the file system of this project to the
* export folder.
*/
public static void exportAnnotationDocuments(DocumentService documentService, ImportExportService importExportService, UserDao userRepository, ProjectExportRequest aModel, File aCopyDir) throws IOException, UIMAException, ClassNotFoundException {
Project project = aModel.project.getObject();
List<de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument> documents = documentService.listSourceDocuments(project);
int i = 1;
int initProgress = aModel.progress;
for (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument sourceDocument : documents) {
//
// Export initial CASes
//
// The initial CAS must always be exported to ensure that the converted source document
// will *always* have the state it had at the time of the initial import. We we do have
// a reliably initial CAS and instead lazily convert whenever an annotator starts
// annotating, then we could end up with two annotators having two different versions of
// their CAS e.g. if there was a code change in the reader component that affects its
// output.
// If the initial CAS does not exist yet, it must be created before export.
documentService.createOrReadInitialCas(sourceDocument);
File targetDir = new File(aCopyDir.getAbsolutePath() + ANNOTATION_CAS_FOLDER + sourceDocument.getName());
FileUtils.forceMkdir(targetDir);
File initialCasFile = documentService.getCasFile(sourceDocument, INITIAL_CAS_PSEUDO_USER);
FileUtils.copyFileToDirectory(initialCasFile, targetDir);
LOG.info("Exported annotation document content for user [" + INITIAL_CAS_PSEUDO_USER + "] for source document [" + sourceDocument.getId() + "] in project [" + project.getName() + "] with id [" + project.getId() + "]");
//
// Export per-user annotation document
//
// Determine which format to use for export
String formatId;
if (FORMAT_AUTO.equals(aModel.format)) {
formatId = sourceDocument.getFormat();
} else {
formatId = importExportService.getWritableFormatId(aModel.format);
}
Class<?> writer = importExportService.getWritableFormats().get(formatId);
if (writer == null) {
String msg = "[" + sourceDocument.getName() + "] No writer found for format [" + formatId + "] - exporting as WebAnno TSV instead.";
// Avoid repeating the same message over for different users
if (!aModel.messages.contains(msg)) {
aModel.messages.add(msg);
}
writer = WebannoTsv3XWriter.class;
}
// Export annotations from regular users
for (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument annotationDocument : documentService.listAnnotationDocuments(sourceDocument)) {
// annotation document is not NEW/IGNORE
if (userRepository.get(annotationDocument.getUser()) != null && !annotationDocument.getState().equals(AnnotationDocumentState.NEW) && !annotationDocument.getState().equals(AnnotationDocumentState.IGNORE)) {
File annotationDocumentAsSerialisedCasDir = new File(aCopyDir.getAbsolutePath() + ANNOTATION_CAS_FOLDER + sourceDocument.getName());
File annotationDocumentDir = new File(aCopyDir.getAbsolutePath() + ANNOTATION_ORIGINAL_FOLDER + sourceDocument.getName());
FileUtils.forceMkdir(annotationDocumentAsSerialisedCasDir);
FileUtils.forceMkdir(annotationDocumentDir);
File annotationFileAsSerialisedCas = documentService.getCasFile(sourceDocument, annotationDocument.getUser());
File annotationFile = null;
if (annotationFileAsSerialisedCas.exists() && writer != null) {
annotationFile = importExportService.exportAnnotationDocument(sourceDocument, annotationDocument.getUser(), writer, annotationDocument.getUser(), Mode.ANNOTATION, false);
}
if (annotationFileAsSerialisedCas.exists()) {
FileUtils.copyFileToDirectory(annotationFileAsSerialisedCas, annotationDocumentAsSerialisedCasDir);
if (writer != null) {
FileUtils.copyFileToDirectory(annotationFile, annotationDocumentDir);
FileUtils.forceDelete(annotationFile);
}
}
LOG.info("Exported annotation document content for user [" + annotationDocument.getUser() + "] for source document [" + sourceDocument.getId() + "] in project [" + project.getName() + "] with id [" + project.getId() + "]");
}
}
// folder as CURATION_FOLDER
if (WebAnnoConst.PROJECT_TYPE_AUTOMATION.equals(project.getMode()) || WebAnnoConst.PROJECT_TYPE_CORRECTION.equals(project.getMode())) {
File correctionCasFile = documentService.getCasFile(sourceDocument, CORRECTION_USER);
if (correctionCasFile.exists()) {
// Copy CAS - this is used when importing the project again
File curationCasDir = new File(aCopyDir + CURATION_AS_SERIALISED_CAS + sourceDocument.getName());
FileUtils.forceMkdir(curationCasDir);
FileUtils.copyFileToDirectory(correctionCasFile, curationCasDir);
// Copy secondary export format for convenience - not used during import
File curationDir = new File(aCopyDir + CURATION_FOLDER + sourceDocument.getName());
FileUtils.forceMkdir(curationDir);
File correctionFile = importExportService.exportAnnotationDocument(sourceDocument, CORRECTION_USER, writer, CORRECTION_USER, Mode.CORRECTION);
FileUtils.copyFileToDirectory(correctionFile, curationDir);
FileUtils.forceDelete(correctionFile);
}
}
// END FIXME #1224 CURATION_USER and CORRECTION_USER files should be exported in
// annotation_ser
aModel.progress = initProgress + (int) Math.ceil(((double) i) / documents.size() * 80.0);
i++;
}
}
Aggregations