use of de.catma.api.pre.serialization.model_wrappers.PreApiAnnotation in project catma by forTEXT.
the class ProjectResourceExportApiRequestHandler method serializeProjectResources.
private String serializeProjectResources() {
try {
Export export = new Export();
for (SourceDocument sourceDocument : project.getSourceDocuments()) {
ArrayList<AnnotationCollection> annotationCollections = new ArrayList<>();
for (AnnotationCollectionReference annotationCollectionReference : sourceDocument.getUserMarkupCollectionRefs()) {
annotationCollections.add(project.getUserMarkupCollection(annotationCollectionReference));
}
ArrayList<TagDefinition> tagDefinitions = new ArrayList<>();
ArrayList<TagReference> tagReferences = new ArrayList<>();
for (AnnotationCollection annotationCollection : annotationCollections) {
for (TagsetDefinition tagsetDefinition : annotationCollection.getTagLibrary().getTagsetDefinitions()) {
tagDefinitions.addAll(tagsetDefinition.stream().collect(Collectors.toList()));
}
tagReferences.addAll(annotationCollection.getTagReferences());
}
ExportDocument exportDocument = new ExportDocument(new PreApiSourceDocument(sourceDocument, String.format("%s%s/doc/%s", BASE_URL, handlerPath.substring(1), sourceDocument.getUuid().toLowerCase())), tagDefinitions.stream().map(PreApiTagDefinition::new).collect(Collectors.toList()), tagReferences.stream().map((TagReference tagReference) -> {
try {
return new PreApiAnnotation(tagReference, tagDefinitions.stream().filter(td -> td.getUuid().equals(tagReference.getTagDefinitionId())).findFirst().get(), sourceDocument);
} catch (IOException e) {
logger.log(Level.WARNING, String.format("Error serializing TagReference: %s", tagReference), e);
return null;
}
}).collect(Collectors.toList()));
export.addExportDocument(exportDocument);
}
return new SerializationHelper<Export>().serialize(export);
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to serialize project resources", e);
return "{\"error\": \"Failed to serialize project resources, please contact CATMA support\"}";
}
}
Aggregations