use of de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExporter in project webanno by webanno.
the class ProjectExportServiceImpl method init.
/* package private */
void init() {
List<ProjectExporter> exps = new ArrayList<>();
if (exportersProxy != null) {
exps.addAll(exportersProxy);
AnnotationAwareOrderComparator.sort(exps);
Set<Class<? extends ProjectExporter>> exporterClasses = new HashSet<>();
for (ProjectExporter init : exps) {
if (exporterClasses.add(init.getClass())) {
log.info("Found project exporter: {}", ClassUtils.getAbbreviatedName(init.getClass(), 20));
} else {
throw new IllegalStateException("There cannot be more than once instance " + "of each project exporter class! Duplicate instance of class: " + init.getClass());
}
}
}
exporters = Collections.unmodifiableList(exps);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExporter in project webanno by webanno.
the class ProjectExportServiceImpl method exportProject.
private ExportedProject exportProject(ProjectExportRequest aRequest, ProjectExportTaskMonitor aMonitor, File aStage) throws ProjectExportException, IOException {
Deque<ProjectExporter> deque = new LinkedList<>(exporters);
Set<Class<? extends ProjectExporter>> initsSeen = new HashSet<>();
Set<ProjectExporter> initsDeferred = SetUtils.newIdentityHashSet();
ExportedProject exProject = new ExportedProject();
exProject.setName(aRequest.getProject().getName());
try {
while (!deque.isEmpty()) {
ProjectExporter initializer = deque.pop();
if (initsDeferred.contains(initializer)) {
throw new IllegalStateException("Circular initializer dependencies in " + initsDeferred + " via " + initializer);
}
if (initsSeen.containsAll(initializer.getExportDependencies())) {
log.debug("Applying project exporter: {}", initializer);
initializer.exportData(aRequest, aMonitor, exProject, aStage);
initsSeen.add(initializer.getClass());
initsDeferred.clear();
} else {
log.debug("Deferring project exporter as dependencies are not yet fulfilled: [{}]", initializer);
deque.add(initializer);
initsDeferred.add(initializer);
}
}
} catch (IOException e) {
// as-is. This allows us to handle export cancellation in the project export UI panel
throw e;
} catch (Exception e) {
throw new ProjectExportException("Project export failed", e);
}
return exProject;
}
use of de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExporter in project webanno by webanno.
the class ProjectExportServiceImpl method importProject.
@Override
@Transactional
public Project importProject(ProjectImportRequest aRequest, ZipFile aZip) throws ProjectExportException {
long start = currentTimeMillis();
Deque<ProjectExporter> deque = new LinkedList<>(exporters);
Set<Class<? extends ProjectExporter>> initsSeen = new HashSet<>();
Set<ProjectExporter> initsDeferred = SetUtils.newIdentityHashSet();
Project project = new Project();
try {
ExportedProject exProject = loadExportedProject(aZip);
// If the name of the project is already taken, generate a new name
String projectName = exProject.getName();
if (projectService.existsProject(projectName)) {
projectName = copyProjectName(projectName);
}
project.setName(projectName);
// We need to set the mode here already because the mode is a non-null column.
// In older versions of WebAnno, the mode was an enum which was serialized as upper-case
// during export but as lower-case in the database. This is compensating for this case.
project.setMode(StringUtils.lowerCase(exProject.getMode(), Locale.US));
// Initial saving of the project
projectService.createProject(project);
// Apply the importers
while (!deque.isEmpty()) {
ProjectExporter importer = deque.pop();
if (initsDeferred.contains(importer)) {
throw new IllegalStateException("Circular initializer dependencies in " + initsDeferred + " via " + importer);
}
if (initsSeen.containsAll(importer.getImportDependencies())) {
log.debug("Applying project importer: {}", importer);
importer.importData(aRequest, project, exProject, aZip);
initsSeen.add(importer.getClass());
initsDeferred.clear();
} else {
log.debug("Deferring project exporter as dependencies are not yet fulfilled: [{}]", importer);
deque.add(importer);
initsDeferred.add(importer);
}
}
} catch (Exception e) {
throw new ProjectExportException("Project import failed", e);
}
log.info("Imported project [{}]({}) ({})", project.getName(), project.getId(), formatDurationWords(currentTimeMillis() - start, true, true));
return project;
}
Aggregations