use of de.catma.project.Project 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.project.Project 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.project.Project in project catma by forTEXT.
the class ProjectView method reloadProject.
/**
* @param projectReference
*/
public void reloadProject(ProjectReference projectReference) {
if (this.project == null) {
setProjectReference(projectReference);
} else {
setEnabled(false);
setProgressBarVisible(true);
final UI ui = UI.getCurrent();
this.project.open(new OpenProjectListener() {
@Override
public void progress(String msg, Object... params) {
ui.access(() -> {
if (params != null) {
progressBar.setCaption(String.format(msg, params));
} else {
progressBar.setCaption(msg);
}
ui.push();
});
}
@Override
public void ready(Project project) {
setProgressBarVisible(false);
ProjectView.this.project = project;
ProjectView.this.project.addPropertyChangeListener(RepositoryChangeEvent.exceptionOccurred, projectExceptionListener);
ProjectView.this.project.getTagManager().addPropertyChangeListener(TagManagerEvent.tagsetDefinitionChanged, tagsetChangeListener);
ProjectView.this.project.addPropertyChangeListener(RepositoryChangeEvent.tagReferencesChanged, tagReferencesChangedListener);
setEnabled(true);
reloadAll();
checkForUnsynchronizedCommits();
}
@Override
public void conflictResolutionNeeded(ConflictedProject conflictedProject) {
setProgressBarVisible(false);
setEnabled(true);
eventBus.post(new RouteToConflictedProjectEvent(conflictedProject));
}
@Override
public void failure(Throwable t) {
setProgressBarVisible(false);
setEnabled(true);
errorHandler.showAndLogError("error opening project", t);
}
});
}
}
use of de.catma.project.Project in project catma by forTEXT.
the class ProjectView method buildResourceDataProvider.
private TreeDataProvider<Resource> buildResourceDataProvider() throws Exception {
if (project != null) {
TreeData<Resource> treeData = new TreeData<>();
Collection<SourceDocument> srcDocs = project.getSourceDocuments();
Locale locale = Locale.getDefault();
for (SourceDocument srcDoc : srcDocs) {
locale = srcDoc.getSourceContentHandler().getSourceDocumentInfo().getIndexInfoSet().getLocale();
DocumentResource docResource = new DocumentResource(srcDoc, project.getProjectId(), project.hasPermission(project.getRoleForDocument(srcDoc.getUuid()), RBACPermission.DOCUMENT_WRITE));
if (project.hasPermission(project.getRoleForDocument(srcDoc.getUuid()), RBACPermission.DOCUMENT_READ)) {
treeData.addItem(null, docResource);
List<AnnotationCollectionReference> collections = srcDoc.getUserMarkupCollectionRefs();
List<Resource> readableCollectionResources = collections.stream().filter(collectionRef -> project.hasPermission(project.getRoleForCollection(collectionRef.getId()), RBACPermission.COLLECTION_READ)).map(collectionRef -> new CollectionResource(collectionRef, project.getProjectId(), project.hasPermission(project.getRoleForCollection(collectionRef.getId()), RBACPermission.COLLECTION_WRITE))).collect(Collectors.toList());
if (!collections.isEmpty()) {
treeData.addItems(docResource, readableCollectionResources);
}
}
}
Collator collator = Collator.getInstance(locale);
collator.setStrength(Collator.PRIMARY);
documentGrid.getColumn(DocumentGridColumn.NAME.name()).setComparator((r1, r2) -> collator.compare(r1.getName(), r2.getName()));
tagsetGrid.getColumn(TagsetGridColumn.NAME.name()).setComparator((t1, t2) -> collator.compare(t1.getName(), t2.getName()));
return new TreeDataProvider<>(treeData);
}
return new TreeDataProvider<>(new TreeData<>());
}
use of de.catma.project.Project in project catma by forTEXT.
the class ProjectView method synchronizeProject.
private void synchronizeProject() throws Exception {
setProgressBarVisible(true);
final UI ui = UI.getCurrent();
project.synchronizeWithRemote(new OpenProjectListener() {
@Override
public void progress(String msg, Object... params) {
ui.access(() -> {
if (params != null) {
progressBar.setCaption(String.format(msg, params));
} else {
progressBar.setCaption(msg);
}
ui.push();
});
}
@Override
public void ready(Project project) {
setProgressBarVisible(false);
reloadAll();
setEnabled(true);
Notification.show("Info", "Your Project has been synchronized!", Type.HUMANIZED_MESSAGE);
checkForUnsynchronizedCommits();
}
@Override
public void conflictResolutionNeeded(ConflictedProject conflictedProject) {
setProgressBarVisible(false);
setEnabled(true);
eventBus.post(new RouteToConflictedProjectEvent(conflictedProject));
}
@Override
public void failure(Throwable t) {
setProgressBarVisible(false);
setEnabled(true);
errorHandler.showAndLogError("error opening project", t);
}
});
}
Aggregations