Search in sources :

Example 6 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class ProjectView method handleAddCollectionRequest.

private void handleAddCollectionRequest() {
    Set<SourceDocument> selectedDocuments = getSelectedDocuments();
    if (!selectedDocuments.isEmpty()) {
        SingleTextInputDialog collectionNameDlg = new SingleTextInputDialog("Add Annotation Collection(s)", "Please enter the Collection name:", new SaveCancelListener<String>() {

            @Override
            public void savePressed(String result) {
                for (SourceDocument document : selectedDocuments) {
                    project.createUserMarkupCollection(result, document);
                }
            }
        });
        collectionNameDlg.show();
    } else {
        Notification.show("Info", "Please select one or more Documents first!", Type.HUMANIZED_MESSAGE);
    }
}
Also used : SourceDocument(de.catma.document.source.SourceDocument) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog)

Example 7 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class ProjectView method addUploadFile.

private void addUploadFile(UploadFile uploadFile, boolean useApostropheAsSeparator, String collectionNamePattern) {
    SourceDocumentInfo sourceDocumentInfo = new SourceDocumentInfo(uploadFile.getIndexInfoSet(useApostropheAsSeparator), uploadFile.getContentInfoSet(), uploadFile.getTechInfoSet());
    SourceContentHandler contentHandler = sourceDocumentInfo.getTechInfoSet().getMimeType().equals(FileType.XML2.getMimeType()) ? new XML2ContentHandler() : new TikaContentHandler();
    contentHandler.setSourceDocumentInfo(sourceDocumentInfo);
    SourceDocument document = new SourceDocument(uploadFile.getUuid(), contentHandler);
    try {
        String content = document.getContent();
        FileOSType fileOSType = FileOSType.getFileOSType(content);
        sourceDocumentInfo.getTechInfoSet().setFileOSType(fileOSType);
        CRC32 checksum = new CRC32();
        checksum.update(content.getBytes());
        sourceDocumentInfo.getTechInfoSet().setChecksum(checksum.getValue());
        project.insert(document);
        AnnotationCollection intrinsicMarkupCollection = uploadFile.getIntrinsicMarkupCollection();
        if (intrinsicMarkupCollection != null) {
            project.importCollection(Collections.emptyList(), intrinsicMarkupCollection);
        }
        if (collectionNamePattern != null && !collectionNamePattern.isEmpty()) {
            String collectionName = collectionNamePattern.replace("{{Title}}", uploadFile.getTitle());
            project.createUserMarkupCollection(collectionName, document);
        }
    } catch (IOException e) {
        Logger.getLogger(ProjectView.class.getName()).log(Level.SEVERE, String.format("Error loading content of %1$s", uploadFile.getTempFilename().toString()), e);
        String errorMsg = e.getMessage();
        if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
            errorMsg = "";
        }
        Notification.show("Error", String.format("Error loading content of %1$s! " + "This document will be skipped!\n The underlying error message was:\n%2$s", uploadFile.getTitle(), errorMsg), Type.ERROR_MESSAGE);
    }
}
Also used : AnnotationCollection(de.catma.document.annotation.AnnotationCollection) SourceDocumentInfo(de.catma.document.source.SourceDocumentInfo) CRC32(java.util.zip.CRC32) TikaContentHandler(de.catma.document.source.contenthandler.TikaContentHandler) SourceDocument(de.catma.document.source.SourceDocument) XML2ContentHandler(de.catma.document.source.contenthandler.XML2ContentHandler) FileOSType(de.catma.document.source.FileOSType) IOException(java.io.IOException) SourceContentHandler(de.catma.document.source.contenthandler.SourceContentHandler)

Example 8 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class ProjectView method handleEditResources.

private void handleEditResources() {
    final Set<Resource> selectedResources = documentGrid.getSelectedItems();
    if (selectedResources.isEmpty()) {
        Notification.show("Info", "Please select a resource first!", Type.HUMANIZED_MESSAGE);
    } else {
        final Resource resource = selectedResources.iterator().next();
        if (selectedResources.size() > 1) {
            documentGridComponent.setSelectionMode(SelectionMode.SINGLE);
        }
        if (resource.isCollection()) {
            final AnnotationCollectionReference collectionRef = ((CollectionResource) selectedResources.iterator().next()).getCollectionReference();
            SingleTextInputDialog collectionNameDlg = new SingleTextInputDialog("Edit Collection", "Please enter the new collection name:", new SaveCancelListener<String>() {

                @Override
                public void savePressed(String result) {
                    collectionRef.getContentInfoSet().setTitle(result);
                    try {
                        project.update(collectionRef, collectionRef.getContentInfoSet());
                        documentGrid.getDataProvider().refreshItem(resource);
                    } catch (Exception e) {
                        errorHandler.showAndLogError("Error updating collection", e);
                    }
                }
            });
            collectionNameDlg.show();
        } else {
            final SourceDocument document = ((DocumentResource) selectedResources.iterator().next()).getDocument();
            SingleTextInputDialog collectionNameDlg = new SingleTextInputDialog("Edit Document", "Please enter the new document name:", new SaveCancelListener<String>() {

                @Override
                public void savePressed(String result) {
                    document.getSourceContentHandler().getSourceDocumentInfo().getContentInfoSet().setTitle(result);
                    try {
                        project.update(document, document.getSourceContentHandler().getSourceDocumentInfo().getContentInfoSet());
                    } catch (Exception e) {
                        errorHandler.showAndLogError("Error updating document", e);
                    }
                }
            });
            collectionNameDlg.show();
        }
    }
}
Also used : SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException)

Example 9 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class ProjectView method handleCollectionChanged.

@Subscribe
public void handleCollectionChanged(CollectionChangeEvent collectionChangeEvent) {
    if (collectionChangeEvent.getChangeType().equals(ChangeType.CREATED)) {
        SourceDocument document = collectionChangeEvent.getDocument();
        AnnotationCollectionReference collectionReference = collectionChangeEvent.getCollectionReference();
        @SuppressWarnings("unchecked") TreeDataProvider<Resource> resourceDataProvider = (TreeDataProvider<Resource>) documentGrid.getDataProvider();
        CollectionResource collectionResource = new CollectionResource(collectionReference, project.getProjectId(), project.hasPermission(project.getRoleForCollection(collectionReference.getId()), RBACPermission.COLLECTION_WRITE));
        DocumentResource documentResource = new DocumentResource(document, project.getProjectId(), project.hasPermission(project.getRoleForDocument(document.getUuid()), RBACPermission.DOCUMENT_WRITE));
        resourceDataProvider.getTreeData().addItem(documentResource, collectionResource);
        resourceDataProvider.refreshAll();
        if (isAttached()) {
            documentGrid.expand(documentResource);
            Notification.show("Info", String.format("Collection %1$s has been created!", collectionReference.toString()), Type.TRAY_NOTIFICATION);
        }
    } else {
        initData();
    }
    btSynchBell.setVisible(true);
}
Also used : TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Subscribe(com.google.common.eventbus.Subscribe)

Example 10 with SourceDocument

use of de.catma.document.source.SourceDocument 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)

Aggregations

SourceDocument (de.catma.document.source.SourceDocument)48 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)23 Project (de.catma.project.Project)17 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)15 List (java.util.List)15 TagsetDefinition (de.catma.tag.TagsetDefinition)13 IOException (java.io.IOException)13 Collectors (java.util.stream.Collectors)13 UI (com.vaadin.ui.UI)12 IDGenerator (de.catma.util.IDGenerator)12 HashSet (java.util.HashSet)12 ErrorHandler (de.catma.ui.module.main.ErrorHandler)11 EventBus (com.google.common.eventbus.EventBus)10 Subscribe (com.google.common.eventbus.Subscribe)10 CollectionChangeEvent (de.catma.project.event.CollectionChangeEvent)10 TreeDataProvider (com.vaadin.data.provider.TreeDataProvider)9 ChangeType (de.catma.project.event.ChangeType)9 RBACPermission (de.catma.rbac.RBACPermission)9 Pair (de.catma.util.Pair)9 Indexer (de.catma.indexer.Indexer)8