Search in sources :

Example 1 with TagDefinition

use of de.catma.tag.TagDefinition 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\"}";
    }
}
Also used : RequestHandler(com.vaadin.server.RequestHandler) ExportDocument(de.catma.api.pre.serialization.models.ExportDocument) VaadinRequest(com.vaadin.server.VaadinRequest) PreApiAnnotation(de.catma.api.pre.serialization.model_wrappers.PreApiAnnotation) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Export(de.catma.api.pre.serialization.models.Export) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) TagsetDefinition(de.catma.tag.TagsetDefinition) IDGenerator(de.catma.util.IDGenerator) NoSuchElementException(java.util.NoSuchElementException) OutputStream(java.io.OutputStream) PreApiSourceDocument(de.catma.api.pre.serialization.model_wrappers.PreApiSourceDocument) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) VaadinResponse(com.vaadin.server.VaadinResponse) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) IOException(java.io.IOException) SourceDocument(de.catma.document.source.SourceDocument) PreApiTagDefinition(de.catma.api.pre.serialization.model_wrappers.PreApiTagDefinition) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) TagReference(de.catma.document.annotation.TagReference) VaadinSession(com.vaadin.server.VaadinSession) TagDefinition(de.catma.tag.TagDefinition) PreApiTagDefinition(de.catma.api.pre.serialization.model_wrappers.PreApiTagDefinition) TagDefinition(de.catma.tag.TagDefinition) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) PreApiSourceDocument(de.catma.api.pre.serialization.model_wrappers.PreApiSourceDocument) PreApiSourceDocument(de.catma.api.pre.serialization.model_wrappers.PreApiSourceDocument) SourceDocument(de.catma.document.source.SourceDocument) ArrayList(java.util.ArrayList) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) IOException(java.io.IOException) ExportDocument(de.catma.api.pre.serialization.models.ExportDocument) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) PreApiTagDefinition(de.catma.api.pre.serialization.model_wrappers.PreApiTagDefinition) TagsetDefinition(de.catma.tag.TagsetDefinition) PreApiAnnotation(de.catma.api.pre.serialization.model_wrappers.PreApiAnnotation) Export(de.catma.api.pre.serialization.models.Export) TagReference(de.catma.document.annotation.TagReference)

Example 2 with TagDefinition

use of de.catma.tag.TagDefinition in project catma by forTEXT.

the class TeiUserMarkupCollectionDeserializer method createTagInstance.

private TagInstance createTagInstance(String tagInstanceID) {
    TeiElement tagInstanceElement = teiDocument.getElementByID(tagInstanceID);
    TagDefinition tagDefinition = tagLibrary.getTagDefinition(tagInstanceElement.getAttributeValue(Attribute.type));
    if (!old2newTagInstanceIDs.containsKey(tagInstanceElement.getID())) {
        old2newTagInstanceIDs.put(tagInstanceElement.getID(), new IDGenerator().generate());
    }
    final TagInstance tagInstance = new TagInstance(old2newTagInstanceIDs.get(tagInstanceElement.getID()), tagDefinition.getUuid(), tagDefinition.getAuthor(), ZonedDateTime.now().format(DateTimeFormatter.ofPattern(Version.DATETIMEPATTERN)), tagDefinition.getUserDefinedPropertyDefinitions(), tagDefinition.getTagsetDefinitionUuid());
    Nodes systemPropertyElements = tagInstanceElement.getChildNodes(TeiElementName.f, AttributeValue.f_name_catma_system_property.getStartsWithFilter());
    addProperties(tagDefinition, new AddPropertyHandler() {

        public void addProperty(Property property) {
            tagInstance.addSystemProperty(property);
        }
    }, systemPropertyElements);
    Nodes userDefinedPropertyElements = tagInstanceElement.getChildNodes(TeiElementName.f, AttributeValue.f_name_catma_system_property.getNotStartsWithFilter());
    addProperties(tagDefinition, new AddPropertyHandler() {

        public void addProperty(Property property) {
            tagInstance.addUserDefinedProperty(property);
        }
    }, userDefinedPropertyElements);
    return tagInstance;
}
Also used : TagDefinition(de.catma.tag.TagDefinition) TagInstance(de.catma.tag.TagInstance) IDGenerator(de.catma.util.IDGenerator) Property(de.catma.tag.Property) Nodes(nu.xom.Nodes)

Example 3 with TagDefinition

use of de.catma.tag.TagDefinition in project catma by forTEXT.

the class TeiTagLibraryDeserializer method addTagDefinitions.

private void addTagDefinitions(TagsetDefinition tagsetDefinition, Elements tagDefinitionElements) throws ParseException {
    for (int i = 0; i < tagDefinitionElements.size(); i++) {
        TeiElement tagDefinitionElement = (TeiElement) tagDefinitionElements.get(i);
        TeiElement descriptionElement = tagDefinitionElement.getFirstTeiChildElement(TeiElementName.fsDescr);
        String description = "";
        if ((descriptionElement != null) && (descriptionElement.getValue() != null)) {
            description = descriptionElement.getValue();
        }
        TagDefinition tagDef = new TagDefinition(tagDefinitionElement.getID(), description, tagDefinitionElement.getAttributeValue(Attribute.fsDecl_baseTypes), tagsetDefinition.getUuid());
        tagManager.addTagDefinition(tagsetDefinition, tagDef);
        addProperties(tagDef, tagDefinitionElement.getChildNodes(TeiElementName.fDecl, AttributeValue.f_Decl_name_catma_system_property.getStartsWithFilter()), tagDefinitionElement.getChildNodes(TeiElementName.fDecl, AttributeValue.f_Decl_name_catma_system_property.getNotStartsWithFilter()));
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition)

Example 4 with TagDefinition

use of de.catma.tag.TagDefinition in project catma by forTEXT.

the class TeiTagLibrarySerializer method write.

private void write(TagsetDefinition tagset, TeiElement encodingDesc) {
    TeiElement fsdDecl = new TeiElement(TeiElementName.fsdDecl);
    fsdDecl.setID(tagset.getUuid());
    fsdDecl.setAttributeValue(Attribute.n, tagset.getName() + " " + tagset.getRevisionHash());
    encodingDesc.appendChild(fsdDecl);
    for (TagDefinition td : tagset) {
        write(td, fsdDecl);
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition)

Example 5 with TagDefinition

use of de.catma.tag.TagDefinition in project catma by forTEXT.

the class GitTagDefinition method getTagDefinition.

public TagDefinition getTagDefinition() {
    TagDefinition tag = new TagDefinition(uuid, name, parentUuid, tagsetDefinitionUuid);
    this.systemPropertyDefinitions.values().forEach(prop -> tag.addSystemPropertyDefinition(prop));
    this.userDefinedPropertyDefinitions.values().forEach(prop -> tag.addUserDefinedPropertyDefinition(prop));
    return tag;
}
Also used : TagDefinition(de.catma.tag.TagDefinition)

Aggregations

TagDefinition (de.catma.tag.TagDefinition)72 ArrayList (java.util.ArrayList)31 PropertyDefinition (de.catma.tag.PropertyDefinition)28 TagsetDefinition (de.catma.tag.TagsetDefinition)28 List (java.util.List)23 IDGenerator (de.catma.util.IDGenerator)22 Pair (de.catma.util.Pair)22 UI (com.vaadin.ui.UI)19 Project (de.catma.project.Project)19 ErrorHandler (de.catma.ui.module.main.ErrorHandler)19 PropertyChangeEvent (java.beans.PropertyChangeEvent)19 PropertyChangeListener (java.beans.PropertyChangeListener)19 IOException (java.io.IOException)19 Collection (java.util.Collection)19 Collectors (java.util.stream.Collectors)19 Notification (com.vaadin.ui.Notification)17 Type (com.vaadin.ui.Notification.Type)17 Set (java.util.Set)17 TagManagerEvent (de.catma.tag.TagManager.TagManagerEvent)16 SaveCancelListener (de.catma.ui.dialog.SaveCancelListener)16