use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class AnnotateResourcePanel method handleCollectionChanged.
@Subscribe
public void handleCollectionChanged(CollectionChangeEvent collectionChangeEvent) {
if (collectionChangeEvent.getChangeType().equals(ChangeType.CREATED)) {
SourceDocument document = collectionChangeEvent.getDocument();
AnnotationCollectionReference collectionReference = collectionChangeEvent.getCollectionReference();
CollectionDataItem collectionDataItem = new CollectionDataItem(collectionReference, project.hasPermission(project.getRoleForCollection(collectionReference.getId()), RBACPermission.COLLECTION_WRITE));
documentData.getRootItems().stream().filter(item -> ((DocumentDataItem) item).getDocument().equals(document)).findAny().ifPresent(documentDataItem -> {
documentData.addItem(documentDataItem, collectionDataItem);
documentTree.getDataProvider().refreshAll();
});
if (isAttached()) {
Notification.show("Info", String.format("Collection %1$s has been created!", collectionReference.toString()), Type.TRAY_NOTIFICATION);
}
if (getSelectedDocument() != null && getSelectedDocument().equals(document)) {
collectionDataItem.fireSelectedEvent(this.resourceSelectionListener);
}
} else if (collectionChangeEvent.getChangeType().equals(ChangeType.DELETED)) {
Optional<DocumentTreeItem> optionalDocResource = documentData.getRootItems().stream().filter(item -> ((DocumentDataItem) item).getDocument().equals(collectionChangeEvent.getDocument())).findAny();
if (optionalDocResource.isPresent()) {
documentData.getChildren(optionalDocResource.get()).stream().filter(item -> ((CollectionDataItem) item).getCollectionRef().equals(collectionChangeEvent.getCollectionReference())).findAny().ifPresent(item -> documentData.removeItem(item));
}
} else {
documentTree.getDataProvider().refreshAll();
}
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class CollectionXMLExportStreamSource method getStream.
@Override
public InputStream getStream() {
final UI ui = UI.getCurrent();
final Project project = projectSupplier.get();
final Corpus corpus = new Corpus();
final Collection<SourceDocument> documents = documentSupplier.get();
final Collection<AnnotationCollectionReference> collectionReferences = collectionReferenceSupplier.get();
try {
Set<String> documentIds = documents.stream().map(doc -> doc.getUuid()).collect(Collectors.toSet());
collectionReferences.stream().forEach(ref -> documentIds.add(ref.getSourceDocumentId()));
for (String documentId : documentIds) {
corpus.addSourceDocument(project.getSourceDocument(documentId));
}
if (corpus.getSourceDocuments().size() == 0) {
return null;
}
collectionReferences.forEach(ref -> corpus.addUserMarkupCollectionReference(ref));
File tempFile = File.createTempFile(new IDGenerator().generate() + "_AnnotationCollection_Export", "tgz");
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
new CorpusExporter(project, true).export(project.getName(), corpus, fos);
}
return new FileInputStream(tempFile);
} catch (Exception e) {
((ErrorHandler) ui).showAndLogError("Error exporting Documents and Collections!", e);
}
return null;
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class GitMarkupCollectionHandler method getCollectionReference.
public AnnotationCollectionReference getCollectionReference(String projectId, String markupCollectionId) throws Exception {
try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
localGitRepoManager.open(projectId, projectRootRepositoryName);
String markupCollectionSubmoduleRelDir = String.format("%s/%s", GitProjectHandler.ANNOTATION_COLLECTION_SUBMODULES_DIRECTORY_NAME, markupCollectionId);
File markupCollectionSubmoduleAbsPath = new File(localGitRepoManager.getRepositoryWorkTree().toString(), markupCollectionSubmoduleRelDir);
String markupCollectionRevisionHash = localGitRepoManager.getSubmoduleHeadRevisionHash(markupCollectionSubmoduleRelDir);
// can't call open on an attached instance
localGitRepoManager.detach();
File markupCollectionHeaderFile = new File(markupCollectionSubmoduleAbsPath, HEADER_FILE_NAME);
String serializedMarkupCollectionHeaderFile = FileUtils.readFileToString(markupCollectionHeaderFile, StandardCharsets.UTF_8);
GitMarkupCollectionHeader markupCollectionHeader = new SerializationHelper<GitMarkupCollectionHeader>().deserialize(serializedMarkupCollectionHeaderFile, GitMarkupCollectionHeader.class);
ContentInfoSet contentInfoSet = new ContentInfoSet(markupCollectionHeader.getAuthor(), markupCollectionHeader.getDescription(), markupCollectionHeader.getPublisher(), markupCollectionHeader.getName());
return new AnnotationCollectionReference(markupCollectionId, markupCollectionRevisionHash, contentInfoSet, markupCollectionHeader.getSourceDocumentId(), markupCollectionHeader.getSourceDocumentVersion());
}
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class GitProjectHandler method ensureDevBranches.
public void ensureDevBranches() throws Exception {
logger.info(String.format("Ensuring dev branches for project %1$s", projectId));
try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
// tagsets
GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(localGitRepoManager, this.remoteGitServerManager, this.credentialsProvider);
for (TagsetDefinition tagset : getTagsets()) {
logger.info(String.format("Checking out dev branch for tagset \"%1$s\" with ID %2$s", tagset.getName(), tagset.getUuid()));
gitTagsetHandler.checkout(projectId, tagset.getUuid(), ILocalGitRepositoryManager.DEFAULT_LOCAL_DEV_BRANCH, true);
}
// collections
GitMarkupCollectionHandler collectionHandler = new GitMarkupCollectionHandler(localGitRepoManager, this.remoteGitServerManager, this.credentialsProvider);
for (AnnotationCollectionReference collectionReference : getCollectionReferences()) {
logger.info(String.format("Checking out dev branch for collection \"%1$s\" with ID %2$s", collectionReference.getName(), collectionReference.getId()));
collectionHandler.checkout(projectId, collectionReference.getId(), ILocalGitRepositoryManager.DEFAULT_LOCAL_DEV_BRANCH, true);
}
// documents
GitSourceDocumentHandler gitSourceDocumentHandler = new GitSourceDocumentHandler(localGitRepoManager, remoteGitServerManager, credentialsProvider);
for (SourceDocument sourceDocument : getDocuments()) {
logger.info(String.format("Checking out dev branch for document \"%s\" with ID %s", sourceDocument.getSourceContentHandler().getSourceDocumentInfo().getContentInfoSet().getTitle(), sourceDocument.getUuid()));
gitSourceDocumentHandler.checkout(projectId, sourceDocument.getUuid(), ILocalGitRepositoryManager.DEFAULT_LOCAL_DEV_BRANCH, true);
}
}
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class GitProjectHandler method verifyCollections.
public void verifyCollections() throws Exception {
List<AnnotationCollectionReference> collectionRefs = getCollectionReferences();
Set<String> documentIds = getDocuments().stream().map(SourceDocument::getUuid).collect(Collectors.toSet());
Set<AnnotationCollectionReference> staleCollectionCandidates = new HashSet<>();
for (AnnotationCollectionReference collectionRef : collectionRefs) {
String documentId = collectionRef.getSourceDocumentId();
if (!documentIds.contains(documentId)) {
staleCollectionCandidates.add(collectionRef);
}
}
if (!staleCollectionCandidates.isEmpty()) {
try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
localGitRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
Set<String> verifiedDeleted = localGitRepoManager.verifyDeletedResources(staleCollectionCandidates.stream().map(AnnotationCollectionReference::getSourceDocumentId).collect(Collectors.toSet()));
localGitRepoManager.detach();
// TODO: unnecessary to loop over all collections when only the stale candidates can end up in verifiedDeleted
for (AnnotationCollectionReference collectionRef : collectionRefs) {
String collectionId = collectionRef.getId();
RBACRole collectionRole = rolesPerResource.get(collectionId);
if (collectionRole != null && hasPermission(collectionRole, RBACPermission.COLLECTION_DELETE_OR_EDIT)) {
if (verifiedDeleted.contains(collectionRef.getSourceDocumentId())) {
logger.info(String.format("Removing stale Collection %1$s with ID %2$s due to removal of corresp. Document with ID %3$s", collectionRef.getName(), collectionRef.getId(), collectionRef.getSourceDocumentId()));
removeCollection(collectionRef);
}
}
}
}
}
}
Aggregations