Search in sources :

Example 1 with TagLibrary

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

the class ImportIntrinsicMarkupStep method enter.

@Override
public void enter(boolean back) {
    if (back) {
        return;
    }
    contentPanel.setEnabled(false);
    progressBar.setVisible(true);
    progressBar.setIndeterminate(true);
    @SuppressWarnings("unchecked") final ArrayList<UploadFile> files = new ArrayList<UploadFile>(((Collection<UploadFile>) wizardContext.get(DocumentWizard.WizardContextKey.UPLOAD_FILE_LIST)).stream().filter(uploadFile -> uploadFile.getMimetype().equals(FileType.XML2.getMimeType())).collect(Collectors.toList()));
    final TagManager tagmanager = new TagManager(new TagLibrary());
    BackgroundServiceProvider backgroundServiceProvider = (BackgroundServiceProvider) UI.getCurrent();
    backgroundServiceProvider.submit("inspecting-intrinsic-markup", new DefaultProgressCallable<List<UploadFile>>() {

        @Override
        public List<UploadFile> call() throws Exception {
            IDGenerator idGenerator = new IDGenerator();
            for (UploadFile uploadFile : files) {
                XML2ContentHandler contentHandler = new XML2ContentHandler();
                SourceDocument doc = new SourceDocument(uploadFile.getUuid(), contentHandler);
                SourceDocumentInfo documentInfo = new SourceDocumentInfo();
                TechInfoSet techInfoSet = new TechInfoSet();
                techInfoSet.setURI(uploadFile.getTempFilename());
                documentInfo.setTechInfoSet(techInfoSet);
                contentHandler.setSourceDocumentInfo(documentInfo);
                XmlMarkupCollectionSerializationHandler handler = new XmlMarkupCollectionSerializationHandler(tagmanager, contentHandler, project.getUser().getIdentifier());
                try (FileInputStream fis = new FileInputStream(new File(uploadFile.getTempFilename()))) {
                    AnnotationCollection collection = handler.deserialize(doc, idGenerator.generateCollectionId(), fis);
                    uploadFile.setIntrinsicMarkupCollection(collection);
                }
            }
            return files;
        }
    }, new ExecutionListener<List<UploadFile>>() {

        @Override
        public void done(List<UploadFile> result) {
            contentPanel.setEnabled(true);
            progressBar.setVisible(false);
            progressBar.setIndeterminate(false);
            fileList.clear();
            fileList.addAll(result);
            fileDataProvider.refreshAll();
            tagsetImportList.clear();
            String defaultIntrinsicXMLElmentsName = "Default Intrinsic XML Elements";
            for (TagsetDefinition tagset : tagmanager.getTagLibrary()) {
                if (!tagset.isEmpty()) {
                    TagsetDefinition targetTagset = project.getTagManager().getTagLibrary().getTagsetDefinition(tagset.getUuid());
                    boolean inProject = false;
                    if (targetTagset == null) {
                        targetTagset = tagset;
                    } else {
                        inProject = true;
                    }
                    String namespace = tagset.getName() == null ? "none" : tagset.getName();
                    if (tagset.getName() == null) {
                        tagset.setName(defaultIntrinsicXMLElmentsName);
                    }
                    TagsetImport tagsetImport = new TagsetImport(namespace, tagset, targetTagset, inProject ? TagsetImportState.WILL_BE_MERGED : TagsetImportState.WILL_BE_CREATED);
                    tagsetImportList.add(tagsetImport);
                }
            }
            tagsetDataProvider.refreshAll();
            wizardContext.put(DocumentWizard.WizardContextKey.TAGSET_IMPORT_LIST, tagsetImportList);
            if (stepChangeListener != null) {
                stepChangeListener.stepChanged(ImportIntrinsicMarkupStep.this);
            }
        }

        @Override
        public void error(Throwable t) {
            Logger.getLogger(ImportIntrinsicMarkupStep.class.getName()).log(Level.SEVERE, "Error inspecting files", t);
            String errorMsg = t.getMessage();
            if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
                errorMsg = "";
            }
            Notification.show("Error", String.format("Error inspecting the contents! " + "\n The underlying error message was:\n%1$s", errorMsg), Type.ERROR_MESSAGE);
        }
    });
}
Also used : SourceDocumentInfo(de.catma.document.source.SourceDocumentInfo) ArrayList(java.util.ArrayList) BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) ArrayList(java.util.ArrayList) List(java.util.List) TechInfoSet(de.catma.document.source.TechInfoSet) TagLibrary(de.catma.tag.TagLibrary) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) SourceDocument(de.catma.document.source.SourceDocument) XML2ContentHandler(de.catma.document.source.contenthandler.XML2ContentHandler) FileInputStream(java.io.FileInputStream) TagsetDefinition(de.catma.tag.TagsetDefinition) TagManager(de.catma.tag.TagManager) XmlMarkupCollectionSerializationHandler(de.catma.serialization.intrinsic.xml.XmlMarkupCollectionSerializationHandler) IDGenerator(de.catma.util.IDGenerator) File(java.io.File)

Example 2 with TagLibrary

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

the class TagsetXMLExportStreamSource method getStream.

@Override
public InputStream getStream() {
    final UI ui = UI.getCurrent();
    Set<TagsetDefinition> tagsets = tagsetsSupplier.get();
    Project project = projectSupplier.get();
    if (tagsets != null && !tagsets.isEmpty()) {
        TeiDocumentFactory teiDocumentFactory = new TeiDocumentFactory();
        try {
            final TeiDocument teiDocument = teiDocumentFactory.createEmptyDocument(null);
            final TeiTagLibrarySerializer teiTagSerializer = new TeiTagLibrarySerializer(teiDocument);
            final TagManager tagManager = new TagManager(new TagLibrary());
            tagsets.forEach(tagset -> tagManager.addTagsetDefinition(tagset));
            final ContentInfoSet contentInfoSet = new ContentInfoSet(project.getUser().toString(), project.getDescription(), project.getUser().toString(), project.getName());
            teiDocument.getTeiHeader().setValues(contentInfoSet);
            teiTagSerializer.serialize(tagManager.getTagLibrary());
            File tempFile = File.createTempFile(new IDGenerator().generate() + "_TagLibrary_Export", "xml");
            try (FileOutputStream fos = new FileOutputStream(tempFile)) {
                teiDocument.printXmlDocument(fos);
            }
            return new FileInputStream(tempFile);
        } catch (Exception e) {
            ((ErrorHandler) ui).showAndLogError("Error exporting Tagsets to XML!", e);
        }
    }
    return null;
}
Also used : TagLibrary(de.catma.tag.TagLibrary) TeiDocumentFactory(de.catma.serialization.tei.TeiDocumentFactory) TeiTagLibrarySerializer(de.catma.serialization.tei.TeiTagLibrarySerializer) FileInputStream(java.io.FileInputStream) TagsetDefinition(de.catma.tag.TagsetDefinition) Project(de.catma.project.Project) TagManager(de.catma.tag.TagManager) ContentInfoSet(de.catma.document.source.ContentInfoSet) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) File(java.io.File) IDGenerator(de.catma.util.IDGenerator) TeiDocument(de.catma.serialization.tei.TeiDocument)

Example 3 with TagLibrary

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

the class GraphWorktreeProject method loadTagLibrary.

@Override
public List<TagsetDefinitionImportStatus> loadTagLibrary(InputStream inputStream) throws IOException {
    TeiSerializationHandlerFactory factory = new TeiSerializationHandlerFactory();
    factory.setTagManager(new TagManager(new TagLibrary()));
    TagLibrarySerializationHandler tagLibrarySerializationHandler = factory.getTagLibrarySerializationHandler();
    TagLibrary importedLibrary = tagLibrarySerializationHandler.deserialize(null, inputStream);
    List<String> resourceIds = gitProjectHandler.getResourceIds();
    List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = new ArrayList<>();
    for (TagsetDefinition tagset : importedLibrary) {
        boolean inProjectHistory = resourceIds.contains(tagset.getUuid());
        boolean current = inProjectHistory && (getTagManager().getTagLibrary().getTagsetDefinition(tagset.getUuid()) != null);
        tagsetDefinitionImportStatusList.add(new TagsetDefinitionImportStatus(tagset, inProjectHistory, current));
    }
    return tagsetDefinitionImportStatusList;
}
Also used : TagLibrary(de.catma.tag.TagLibrary) TagsetDefinition(de.catma.tag.TagsetDefinition) TagManager(de.catma.tag.TagManager) TeiSerializationHandlerFactory(de.catma.serialization.tei.TeiSerializationHandlerFactory) TeiTagLibrarySerializationHandler(de.catma.serialization.tei.TeiTagLibrarySerializationHandler) TagLibrarySerializationHandler(de.catma.serialization.TagLibrarySerializationHandler) ArrayList(java.util.ArrayList) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus)

Example 4 with TagLibrary

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

the class GraphWorktreeProject method loadAnnotationCollection.

public Pair<AnnotationCollection, List<TagsetDefinitionImportStatus>> loadAnnotationCollection(InputStream inputStream, SourceDocument document) throws IOException {
    TagManager tagManager = new TagManager(new TagLibrary());
    TeiTagLibrarySerializationHandler tagLibrarySerializationHandler = new TeiTagLibrarySerializationHandler(tagManager);
    TagLibrary importedLibrary = tagLibrarySerializationHandler.deserialize(null, inputStream);
    List<String> resourceIds = gitProjectHandler.getResourceIds();
    List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = new ArrayList<>();
    for (TagsetDefinition tagset : importedLibrary) {
        boolean inProjectHistory = resourceIds.contains(tagset.getUuid());
        boolean current = inProjectHistory && (getTagManager().getTagLibrary().getTagsetDefinition(tagset.getUuid()) != null);
        tagsetDefinitionImportStatusList.add(new TagsetDefinitionImportStatus(tagset, inProjectHistory, current));
    }
    String collectionId = idGenerator.generate();
    TeiUserMarkupCollectionDeserializer deserializer = new TeiUserMarkupCollectionDeserializer(tagLibrarySerializationHandler.getTeiDocument(), tagManager.getTagLibrary(), collectionId);
    AnnotationCollection annotationCollection = new AnnotationCollection(collectionId, tagLibrarySerializationHandler.getTeiDocument().getContentInfoSet(), tagManager.getTagLibrary(), deserializer.getTagReferences(), document.getUuid(), document.getRevisionHash());
    return new Pair<>(annotationCollection, tagsetDefinitionImportStatusList);
}
Also used : TagLibrary(de.catma.tag.TagLibrary) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) TeiTagLibrarySerializationHandler(de.catma.serialization.tei.TeiTagLibrarySerializationHandler) ArrayList(java.util.ArrayList) TeiUserMarkupCollectionDeserializer(de.catma.serialization.tei.TeiUserMarkupCollectionDeserializer) TagsetDefinition(de.catma.tag.TagsetDefinition) TagManager(de.catma.tag.TagManager) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) Pair(de.catma.util.Pair)

Example 5 with TagLibrary

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

the class GraphWorktreeProject method synchronizeWithRemote.

@Override
public void synchronizeWithRemote(OpenProjectListener openProjectListener) throws Exception {
    if (hasUncommittedChanges()) {
        throw new IllegalStateException("There are uncommitted changes that need to be committed first!");
    }
    for (TagsetDefinition tagset : getTagsets()) {
        gitProjectHandler.synchronizeTagsetWithRemote(tagset.getUuid());
    }
    for (SourceDocument document : getSourceDocuments()) {
        gitProjectHandler.synchronizeSourceDocumentWithRemote(document.getUuid());
        for (AnnotationCollectionReference collectionReference : document.getUserMarkupCollectionRefs()) {
            gitProjectHandler.synchronizeCollectionWithRemote(collectionReference.getId());
        }
    }
    gitProjectHandler.synchronizeWithRemote();
    if (gitProjectHandler.hasConflicts()) {
        gitProjectHandler.initAndUpdateSubmodules();
        openProjectListener.conflictResolutionNeeded(new GitConflictedProject(projectReference, gitProjectHandler, documentId -> getSourceDocumentURI(documentId)));
    } else {
        boolean forceGraphReload = gitProjectHandler.loadRolesPerResource();
        gitProjectHandler.initAndUpdateSubmodules();
        gitProjectHandler.removeStaleSubmoduleDirectories();
        gitProjectHandler.ensureDevBranches();
        rootRevisionHash = gitProjectHandler.getRootRevisionHash();
        ProgressListener progressListener = new ProgressListener() {

            @Override
            public void setProgress(String value, Object... args) {
                openProjectListener.progress(value, args);
            }
        };
        graphProjectHandler.ensureProjectRevisionIsLoaded(new ExecutionListener<TagManager>() {

            @Override
            public void error(Throwable t) {
                openProjectListener.failure(t);
            }

            @Override
            public void done(TagManager result) {
                tagManager.load(result.getTagLibrary());
                openProjectListener.ready(GraphWorktreeProject.this);
            }
        }, progressListener, rootRevisionHash, tagManager, () -> gitProjectHandler.getTagsets(), () -> gitProjectHandler.getDocuments(), (tagLibrary) -> gitProjectHandler.getCollections(tagLibrary, progressListener), forceGraphReload, backgroundService);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Reply(de.catma.document.comment.Reply) LoadingCache(com.google.common.cache.LoadingCache) Status(org.eclipse.jgit.api.Status) UI(com.vaadin.ui.UI) IndexedProject(de.catma.indexer.IndexedProject) TermExtractor(de.catma.indexer.TermExtractor) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInfoProvider(de.catma.repository.git.graph.FileInfoProvider) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Locale(java.util.Locale) Map(java.util.Map) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) URI(java.net.URI) Path(java.nio.file.Path) CommitInfo(de.catma.project.CommitInfo) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) ExecutionListener(de.catma.backgroundservice.ExecutionListener) Collection(java.util.Collection) Set(java.util.Set) TagInstance(de.catma.tag.TagInstance) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) ProjectReference(de.catma.project.ProjectReference) TagReference(de.catma.document.annotation.TagReference) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) TPGraphProjectHandler(de.catma.repository.git.graph.tp.TPGraphProjectHandler) TagDefinition(de.catma.tag.TagDefinition) CacheBuilder(com.google.common.cache.CacheBuilder) ContentInfoSet(de.catma.document.source.ContentInfoSet) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) RBACPermission(de.catma.rbac.RBACPermission) StatusPrinter(de.catma.repository.git.managers.StatusPrinter) PropertyDefinition(de.catma.tag.PropertyDefinition) TagManager(de.catma.tag.TagManager) CommentProvider(de.catma.repository.git.graph.CommentProvider) RBACRole(de.catma.rbac.RBACRole) MediaType(org.apache.tika.mime.MediaType) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) User(de.catma.user.User) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) CommentChangeEvent(de.catma.project.event.CommentChangeEvent) Comment(de.catma.document.comment.Comment) Charset(java.nio.charset.Charset) TeiTagLibrarySerializationHandler(de.catma.serialization.tei.TeiTagLibrarySerializationHandler) Member(de.catma.user.Member) StandardContentHandler(de.catma.document.source.contenthandler.StandardContentHandler) TagsetDefinition(de.catma.tag.TagsetDefinition) Pair(de.catma.util.Pair) IDGenerator(de.catma.util.IDGenerator) RBACSubject(de.catma.rbac.RBACSubject) TagLibrary(de.catma.tag.TagLibrary) PropertyChangeEvent(java.beans.PropertyChangeEvent) OpenProjectListener(de.catma.project.OpenProjectListener) TeiSerializationHandlerFactory(de.catma.serialization.tei.TeiSerializationHandlerFactory) RemovalNotification(com.google.common.cache.RemovalNotification) ProgressListener(de.catma.backgroundservice.ProgressListener) Property(de.catma.tag.Property) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TermInfo(de.catma.indexer.TermInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) File(java.io.File) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) TagLibrarySerializationHandler(de.catma.serialization.TagLibrarySerializationHandler) Indexer(de.catma.indexer.Indexer) ChangeType(de.catma.project.event.ChangeType) GraphProjectHandler(de.catma.repository.git.graph.GraphProjectHandler) ReplyChangeEvent(de.catma.project.event.ReplyChangeEvent) Paths(java.nio.file.Paths) PropertyChangeSupport(java.beans.PropertyChangeSupport) RemovalListener(com.google.common.cache.RemovalListener) BackgroundService(de.catma.backgroundservice.BackgroundService) InputStream(java.io.InputStream) TeiUserMarkupCollectionDeserializer(de.catma.serialization.tei.TeiUserMarkupCollectionDeserializer) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TagsetDefinition(de.catma.tag.TagsetDefinition) TagManager(de.catma.tag.TagManager) ProgressListener(de.catma.backgroundservice.ProgressListener)

Aggregations

TagLibrary (de.catma.tag.TagLibrary)10 TagManager (de.catma.tag.TagManager)8 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)7 TagsetDefinition (de.catma.tag.TagsetDefinition)7 ArrayList (java.util.ArrayList)7 TagsetDefinitionImportStatus (de.catma.serialization.TagsetDefinitionImportStatus)5 IDGenerator (de.catma.util.IDGenerator)5 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5 List (java.util.List)5 UI (com.vaadin.ui.UI)4 TagReference (de.catma.document.annotation.TagReference)4 ContentInfoSet (de.catma.document.source.ContentInfoSet)4 SourceDocument (de.catma.document.source.SourceDocument)4 Property (de.catma.tag.Property)4 TagDefinition (de.catma.tag.TagDefinition)4 TagInstance (de.catma.tag.TagInstance)4 Pair (de.catma.util.Pair)4 IOException (java.io.IOException)4 Collection (java.util.Collection)4