use of de.tudarmstadt.ukp.clarin.webanno.api.event.ProjectImportEvent in project webanno by webanno.
the class ImportServiceImpl method importProject.
@Override
public Project importProject(File aProjectFile, boolean aGenerateUsers) throws Exception {
Project importedProject = new Project();
ZipFile zip = new ZipFile(aProjectFile);
InputStream projectInputStream = null;
for (Enumeration<? extends ZipEntry> zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) zipEnumerate.nextElement();
if (entry.toString().replace("/", "").startsWith(ImportUtil.EXPORTED_PROJECT) && entry.toString().replace("/", "").endsWith(".json")) {
projectInputStream = zip.getInputStream(entry);
break;
}
}
// Load the project model from the JSON file
String text = IOUtils.toString(projectInputStream, "UTF-8");
de.tudarmstadt.ukp.clarin.webanno.export.model.Project importedProjectSetting = JSONUtil.getJsonConverter().getObjectMapper().readValue(text, de.tudarmstadt.ukp.clarin.webanno.export.model.Project.class);
// Import the project itself
importedProject = ImportUtil.createProject(importedProjectSetting, projectService);
// Import additional project things
projectService.onProjectImport(zip, importedProjectSetting, importedProject);
// Import missing users
if (aGenerateUsers) {
ImportUtil.createMissingUsers(importedProjectSetting, userRepository);
}
applicationEventPublisher.publishEvent(new ProjectImportEvent(this, zip, importedProjectSetting, importedProject));
// Import layers
Map<String, AnnotationFeature> featuresMap = ImportUtil.createLayer(importedProject, importedProjectSetting, userRepository, annotationService);
/*
* for (TagSet tagset : importedProjectSetting.getTagSets()) {
* ImportUtil.createTagset(importedProject, tagset, projectRepository, annotationService); }
*/
// Import source document
ImportUtil.createSourceDocument(importedProjectSetting, importedProject, documentService);
// Import Training document
if (automationService != null) {
ImportUtil.createTrainingDocument(importedProjectSetting, importedProject, automationService, featuresMap);
}
// Import source document content
ImportUtil.createSourceDocumentContent(zip, importedProject, documentService);
// Import training document content
if (automationService != null) {
ImportUtil.createTrainingDocumentContent(zip, importedProject, automationService);
}
// Import automation settings
if (automationService != null) {
ImportUtil.createMiraTemplate(importedProjectSetting, automationService, featuresMap);
}
// Import annotation document content
ImportUtil.createAnnotationDocument(importedProjectSetting, importedProject, documentService);
// Import annotation document content
ImportUtil.createAnnotationDocumentContent(zip, importedProject, documentService);
// Import curation document content
ImportUtil.createCurationDocumentContent(zip, importedProject, documentService);
return importedProject;
}
Aggregations