use of de.catma.tag.TagsetDefinition 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\"}";
}
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class TeiTagLibraryDeserializer method deserialize.
private void deserialize() throws ParseException {
Nodes tagsetDefinitionElements = teiDocument.getTagsetDefinitionElements();
for (int i = 0; i < tagsetDefinitionElements.size(); i++) {
TeiElement tagsetDefinitionElement = (TeiElement) tagsetDefinitionElements.get(i);
String nValue = tagsetDefinitionElement.getAttributeValue(Attribute.n);
int dividerPos = nValue.lastIndexOf(' ');
String tagsetName = nValue.substring(0, dividerPos);
// version gets ignored, versioning is done via git or not at all!
// String versionString = nValue.substring(dividerPos+1);
TagsetDefinition tagsetDefinition = new TagsetDefinition(tagsetDefinitionElement.getID(), tagsetName, new Version());
tagManager.addTagsetDefinition(tagsetDefinition);
addTagDefinitions(tagsetDefinition, tagsetDefinitionElement.getChildElements(TeiElementName.fsDecl));
}
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class XmlMarkupCollectionSerializationHandler method scanElements.
private void scanElements(StringBuilder contentBuilder, Element element, Stack<String> elementStack, TagManager tagManager, TagLibrary tagLibrary, Map<String, String> namespacePrefixToTagsetIdMap, AnnotationCollection userMarkupCollection, String docId, int docLength) throws Exception {
int start = contentBuilder.length();
StringBuilder pathBuilder = new StringBuilder();
for (int j = 0; j < elementStack.size(); j++) {
pathBuilder.append("/" + elementStack.get(j));
}
String parentPath = pathBuilder.toString();
elementStack.push(element.getLocalName());
String path = parentPath + "/" + elementStack.peek();
String tagName = element.getLocalName();
String prefix = element.getNamespacePrefix();
String tagsetId = namespacePrefixToTagsetIdMap.get(prefix);
if (tagsetId == null) {
tagsetId = KnownTagsetDefinitionName.DEFAULT_INTRINSIC_XML.asTagsetId();
}
TagsetDefinition tagset = tagLibrary.getTagsetDefinition(tagsetId);
String tagId = idGenerator.generate();
TagDefinition tagDefinition = tagset.getTagDefinitionsByName(tagName).findFirst().orElse(null);
String pathPropertyDefId = null;
if (tagDefinition == null) {
tagDefinition = new TagDefinition(tagId, elementStack.peek(), // no parent, hierarchy is collected in annotation property
null, tagsetId);
tagDefinition.addSystemPropertyDefinition(new PropertyDefinition(idGenerator.generate(PropertyDefinition.SystemPropertyName.catma_displaycolor.name()), PropertyDefinition.SystemPropertyName.catma_displaycolor.name(), Collections.singletonList(ColorConverter.toRGBIntAsString(ColorConverter.randomHex()))));
tagDefinition.addSystemPropertyDefinition(new PropertyDefinition(idGenerator.generate(PropertyDefinition.SystemPropertyName.catma_markupauthor.name()), PropertyDefinition.SystemPropertyName.catma_markupauthor.name(), Collections.singletonList(author)));
pathPropertyDefId = idGenerator.generate();
PropertyDefinition pathDef = new PropertyDefinition(pathPropertyDefId, "path", Collections.emptyList());
tagDefinition.addUserDefinedPropertyDefinition(pathDef);
tagManager.addTagDefinition(tagset, tagDefinition);
} else {
pathPropertyDefId = tagDefinition.getPropertyDefinition("path").getUuid();
}
for (int idx = 0; idx < element.getChildCount(); idx++) {
Node curChild = element.getChild(idx);
if (curChild instanceof Text) {
xmlContentHandler.addTextContent(contentBuilder, element, curChild.getValue());
} else if (curChild instanceof Element) {
// descent
scanElements(contentBuilder, (Element) curChild, elementStack, tagManager, tagLibrary, namespacePrefixToTagsetIdMap, userMarkupCollection, docId, docLength);
}
}
if (element.getChildCount() != 0) {
xmlContentHandler.addBreak(contentBuilder, element);
}
int end = contentBuilder.length();
Range range = new Range(start, end);
if (range.isSinglePoint()) {
int newStart = range.getStartPoint();
if (newStart > 0) {
newStart = newStart - 1;
}
int newEnd = range.getEndPoint();
if (newEnd < docLength - 1) {
newEnd = newEnd + 1;
}
range = new Range(newStart, newEnd);
}
TagInstance tagInstance = new TagInstance(idGenerator.generate(), tagDefinition.getUuid(), author, ZonedDateTime.now().format(DateTimeFormatter.ofPattern(Version.DATETIMEPATTERN)), tagDefinition.getUserDefinedPropertyDefinitions(), tagDefinition.getTagsetDefinitionUuid());
for (int i = 0; i < element.getAttributeCount(); i++) {
PropertyDefinition propertyDefinition = tagDefinition.getPropertyDefinition(element.getAttribute(i).getQualifiedName());
if (propertyDefinition == null) {
propertyDefinition = new PropertyDefinition(idGenerator.generate(), element.getAttribute(i).getQualifiedName(), Collections.singleton(element.getAttribute(i).getValue()));
tagManager.addUserDefinedPropertyDefinition(tagDefinition, propertyDefinition);
} else if (!propertyDefinition.getPossibleValueList().contains(element.getAttribute(i).getValue())) {
List<String> newValueList = new ArrayList<>();
newValueList.addAll(propertyDefinition.getPossibleValueList());
newValueList.add(element.getAttribute(i).getValue());
propertyDefinition.setPossibleValueList(newValueList);
}
Property property = new Property(propertyDefinition.getUuid(), Collections.singleton(element.getAttribute(i).getValue()));
tagInstance.addUserDefinedProperty(property);
}
Property pathProperty = new Property(pathPropertyDefId, Collections.singletonList(path));
tagInstance.addUserDefinedProperty(pathProperty);
TagReference tagReference = new TagReference(tagInstance, docId, range, userMarkupCollection.getId());
userMarkupCollection.addTagReference(tagReference);
elementStack.pop();
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class ProjectView method initActions.
private void initActions() {
documentGridComponent.setSearchFilterProvider(searchInput -> createSearchFilter(searchInput));
documentGrid.addItemClickListener(itemClickEvent -> handleResourceItemClick(itemClickEvent));
ContextMenu addContextMenu = documentGridComponent.getActionGridBar().getBtnAddContextMenu();
MenuItem addDocumentBtn = addContextMenu.addItem("Add Document", clickEvent -> handleAddDocumentRequest());
addDocumentBtn.setEnabled(false);
rbacEnforcer.register(RBACConstraint.ifAuthorized(role -> (project.hasPermission(role, RBACPermission.DOCUMENT_CREATE_OR_UPLOAD)), () -> addDocumentBtn.setEnabled(true)));
MenuItem addCollectionBtn = addContextMenu.addItem("Add Annotation Collection", e -> handleAddCollectionRequest());
addCollectionBtn.setEnabled(false);
rbacEnforcer.register(RBACConstraint.ifAuthorized(role -> (project.hasPermission(role, RBACPermission.COLLECTION_CREATE)), () -> addCollectionBtn.setEnabled(true)));
ContextMenu documentsGridMoreOptionsContextMenu = documentGridComponent.getActionGridBar().getBtnMoreOptionsContextMenu();
MenuItem editDocBtn = documentsGridMoreOptionsContextMenu.addItem("Edit Documents / Collections", (menuItem) -> handleEditResources());
editDocBtn.setEnabled(false);
rbacEnforcer.register(RBACConstraint.ifAuthorized(role -> (project.hasPermission(role, RBACPermission.COLLECTION_DELETE_OR_EDIT) || project.hasPermission(role, RBACPermission.DOCUMENT_DELETE_OR_EDIT)), () -> editDocBtn.setEnabled(true)));
MenuItem deleteDocsBtn = documentsGridMoreOptionsContextMenu.addItem("Delete Documents / Collections", (menuItem) -> handleDeleteResources(menuItem, documentGrid));
deleteDocsBtn.setEnabled(false);
rbacEnforcer.register(RBACConstraint.ifAuthorized(role -> (project.hasPermission(role, RBACPermission.COLLECTION_DELETE_OR_EDIT) || project.hasPermission(role, RBACPermission.DOCUMENT_DELETE_OR_EDIT)), () -> deleteDocsBtn.setEnabled(true)));
documentsGridMoreOptionsContextMenu.addItem("Analyze Documents / Collections", (menuItem) -> handleAnalyzeResources(menuItem, documentGrid));
documentsGridMoreOptionsContextMenu.addItem("Import a Collection", mi -> handleImportCollectionRequest());
MenuItem miExportCollections = documentsGridMoreOptionsContextMenu.addItem("Export Documents & Collections");
StreamResource collectionXmlExportResource = new StreamResource(new CollectionXMLExportStreamSource(() -> getSelectedDocuments(), () -> documentGrid.getSelectedItems().stream().filter(resource -> resource.isCollection()).map(resource -> ((CollectionResource) resource).getCollectionReference()).collect(Collectors.toList()), () -> project), "CATMA-Corpus_Export-" + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) + ".tar.gz");
collectionXmlExportResource.setCacheTime(0);
collectionXmlExportResource.setMIMEType("application/gzip");
FileDownloader collectionXmlExportFileDownloader = new FileDownloader(collectionXmlExportResource);
collectionXmlExportFileDownloader.extend(miExportCollections);
documentsGridMoreOptionsContextMenu.addItem("Select filtered entries", mi -> handleSelectFilteredDocuments());
tagsetGridComponent.getActionGridBar().addBtnAddClickListener(click -> handleAddTagsetRequest());
tagsetGridComponent.getActionGridBar().setAddBtnEnabled(false);
rbacEnforcer.register(RBACConstraint.ifAuthorized(role -> project.hasPermission(role, RBACPermission.TAGSET_CREATE_OR_UPLOAD), () -> tagsetGridComponent.getActionGridBar().setAddBtnEnabled(true)));
ContextMenu moreOptionsMenu = tagsetGridComponent.getActionGridBar().getBtnMoreOptionsContextMenu();
MenuItem editTagset = moreOptionsMenu.addItem("Edit Tagset", mi -> handleEditTagsetRequest());
editTagset.setEnabled(false);
rbacEnforcer.register(RBACConstraint.ifAuthorized(role -> (project.hasPermission(role, RBACPermission.TAGSET_DELETE_OR_EDIT)), () -> editTagset.setEnabled(true)));
MenuItem deleteTagSetBtn = moreOptionsMenu.addItem("Delete Tagset", mi -> handleDeleteTagsetRequest());
deleteTagSetBtn.setEnabled(false);
rbacEnforcer.register(RBACConstraint.ifAuthorized(role -> (project.hasPermission(role, RBACPermission.TAGSET_DELETE_OR_EDIT)), () -> deleteTagSetBtn.setEnabled(true)));
MenuItem importTagSetBtn = moreOptionsMenu.addItem("Import Tagsets", mi -> handleImportTagsetsRequest());
importTagSetBtn.setEnabled(false);
rbacEnforcer.register(RBACConstraint.ifAuthorized(role -> (project.hasPermission(role, RBACPermission.TAGSET_CREATE_OR_UPLOAD)), () -> importTagSetBtn.setEnabled(true)));
MenuItem miExportTagsets = moreOptionsMenu.addItem("Export Tagsets");
MenuItem miExportTagsetsAsXML = miExportTagsets.addItem("as XML");
StreamResource tagsetXmlExportResource = new StreamResource(new TagsetXMLExportStreamSource(() -> tagsetGrid.getSelectedItems(), () -> project), "CATMA-Tag-Library_Export-" + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) + ".xml");
tagsetXmlExportResource.setCacheTime(0);
tagsetXmlExportResource.setMIMEType("text/xml");
FileDownloader tagsetXmlExportFileDownloader = new FileDownloader(tagsetXmlExportResource);
tagsetXmlExportFileDownloader.extend(miExportTagsetsAsXML);
MenuItem miExportTagsetsAsCSV = miExportTagsets.addItem("as CSV");
StreamResource tagsetCsvExportResource = new StreamResource(new TagsetCSVExportStreamSource(() -> tagsetGrid.getSelectedItems(), () -> project), "CATMA-Tag-Library_Export-" + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) + ".csv");
tagsetCsvExportResource.setCacheTime(0);
tagsetCsvExportResource.setMIMEType("text/comma-separated-values");
FileDownloader tagsetCsvExportFileDownloader = new FileDownloader(tagsetCsvExportResource);
tagsetCsvExportFileDownloader.extend(miExportTagsetsAsCSV);
moreOptionsMenu.addItem("Fork Tagsets into another Project", miForkTagset -> handleForkTagsetRequest());
ContextMenu hugeCardMoreOptions = getMoreOptionsContextMenu();
hugeCardMoreOptions.addItem("Commit all changes", mi -> handleCommitRequest());
hugeCardMoreOptions.addItem("Synchronize with the team", mi -> handleSynchronizeRequest());
hugeCardMoreOptions.addSeparator();
hugeCardMoreOptions.addItem("Share project resources (experimental API)", mi -> handleShareProjectResources());
MenuItem miImportCorpus = hugeCardMoreOptions.addItem("Import CATMA 5 Corpus", mi -> handleCorpusImport());
miImportCorpus.setVisible(CATMAPropertyKey.EXPERT.getValue(false) || Boolean.valueOf(((CatmaApplication) UI.getCurrent()).getParameter(Parameter.EXPERT, Boolean.FALSE.toString())));
btSynchBell.addClickListener(event -> handleBtSynchBellClick(event));
// TODO:
// hugeCardMoreOptions.addItem("Print status", e -> project.printStatus());
tagsetGridComponent.setSearchFilterProvider(new SearchFilterProvider<TagsetDefinition>() {
@Override
public SerializablePredicate<TagsetDefinition> createSearchFilter(final String searchInput) {
return new SerializablePredicate<TagsetDefinition>() {
@Override
public boolean test(TagsetDefinition t) {
if (t != null) {
String name = t.getName();
if (name != null) {
return name.toLowerCase().contains(searchInput.toLowerCase());
}
}
return false;
}
};
}
});
tagsetGrid.addItemClickListener(clickEvent -> handleTagsetClick(clickEvent));
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class ProjectView method handleEditTagsetRequest.
private void handleEditTagsetRequest() {
final Set<TagsetDefinition> tagsets = tagsetGrid.getSelectedItems();
if (!tagsets.isEmpty()) {
final TagsetDefinition tagset = tagsets.iterator().next();
SingleTextInputDialog tagsetNameDlg = new SingleTextInputDialog("Edit Tagset", "Please enter the new Tagset name:", tagset.getName(), new SaveCancelListener<String>() {
@Override
public void savePressed(String result) {
project.getTagManager().setTagsetDefinitionName(tagset, result);
}
});
tagsetNameDlg.show();
} else {
Notification.show("Info", "Please select a Tagset first!", Type.HUMANIZED_MESSAGE);
}
}
Aggregations