Search in sources :

Example 11 with Pair

use of de.catma.util.Pair in project catma by forTEXT.

the class ProjectView method importCollection.

private void importCollection() {
    Set<SourceDocument> selectedDocuments = getSelectedDocuments();
    if (selectedDocuments.size() != 1) {
        Notification.show("Info", "Please select the corresponding Document first!", Type.HUMANIZED_MESSAGE);
    } else {
        final SourceDocument document = selectedDocuments.iterator().next();
        GenericUploadDialog uploadDialog = new GenericUploadDialog(String.format("Upload a Collection for %1$s:", document.toString()), new SaveCancelListener<byte[]>() {

            public void savePressed(byte[] result) {
                InputStream is = new ByteArrayInputStream(result);
                try {
                    if (BOMFilterInputStream.hasBOM(result)) {
                        is = new BOMFilterInputStream(is, // $NON-NLS-1$
                        Charset.forName("UTF-8"));
                    }
                    Pair<AnnotationCollection, List<TagsetDefinitionImportStatus>> loadResult = project.loadAnnotationCollection(is, document);
                    List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = loadResult.getSecond();
                    final AnnotationCollection annotationCollection = loadResult.getFirst();
                    CollectionImportDialog tagsetImportDialog = new CollectionImportDialog(tagsetDefinitionImportStatusList, new SaveCancelListener<List<TagsetDefinitionImportStatus>>() {

                        @Override
                        public void savePressed(List<TagsetDefinitionImportStatus> result) {
                            try {
                                project.importCollection(result, annotationCollection);
                            } catch (IOException e) {
                                ((CatmaApplication) UI.getCurrent()).showAndLogError("Error importing Tagsets", e);
                            }
                        }
                    });
                    tagsetImportDialog.show();
                } catch (IOException e) {
                    ((CatmaApplication) UI.getCurrent()).showAndLogError("Error loading external Tagsets", e);
                } finally {
                    CloseSafe.close(is);
                }
            }
        });
        uploadDialog.show();
    }
}
Also used : AnnotationCollection(de.catma.document.annotation.AnnotationCollection) GenericUploadDialog(de.catma.ui.dialog.GenericUploadDialog) ByteArrayInputStream(java.io.ByteArrayInputStream) BOMFilterInputStream(de.catma.document.source.contenthandler.BOMFilterInputStream) InputStream(java.io.InputStream) SourceDocument(de.catma.document.source.SourceDocument) IOException(java.io.IOException) BOMFilterInputStream(de.catma.document.source.contenthandler.BOMFilterInputStream) CatmaApplication(de.catma.ui.CatmaApplication) ByteArrayInputStream(java.io.ByteArrayInputStream) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) ArrayList(java.util.ArrayList) List(java.util.List) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) Pair(de.catma.util.Pair)

Example 12 with Pair

use of de.catma.util.Pair in project catma by forTEXT.

the class TagSelectionPanel method initListeners.

private void initListeners() {
    tagChangedListener = new PropertyChangeListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Object newValue = evt.getNewValue();
            Object oldValue = evt.getOldValue();
            if (oldValue == null) {
                // created
                Pair<TagsetDefinition, TagDefinition> value = (Pair<TagsetDefinition, TagDefinition>) newValue;
                TagsetDefinition tagset = value.getFirst();
                TagDefinition tag = value.getSecond();
                if (tag.getParentUuid().isEmpty()) {
                    TagsetTreeItem tagsetItem = new TagsetDataItem(tagset);
                    tagsetData.addItem(tagsetItem, new TagDataItem(tag));
                    tagsetGrid.expand(tagsetItem);
                } else {
                    TagDefinition parentTag = project.getTagManager().getTagLibrary().getTagDefinition(tag.getParentUuid());
                    TagsetTreeItem parentTagItem = new TagDataItem(parentTag);
                    tagsetData.addItem(parentTagItem, new TagDataItem(tag));
                    tagsetGrid.expand(parentTagItem);
                }
                tagsetDataProvider.refreshAll();
            } else if (newValue == null) {
                // removed
                Pair<TagsetDefinition, TagDefinition> deleted = (Pair<TagsetDefinition, TagDefinition>) oldValue;
                TagDefinition deletedTag = deleted.getSecond();
                tagsetData.removeItem(new TagDataItem(deletedTag));
                tagsetDataProvider.refreshAll();
            } else {
                // update
                TagDefinition tag = (TagDefinition) newValue;
                TagsetDefinition tagset = (TagsetDefinition) oldValue;
                TagsetTreeItem tagsetItem = new TagsetDataItem(tagset);
                tagsetData.removeItem(new TagDataItem(tag));
                TagDataItem tagDataItem = new TagDataItem(tag);
                tagDataItem.setPropertiesExpanded(true);
                tagsetData.addItem(tagsetItem, tagDataItem);
                // TODO: sort
                tagsetDataProvider.refreshAll();
            }
        }
    };
    project.getTagManager().addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagChangedListener);
    this.tagsetChangeListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            handleTagsetChange(evt);
        }
    };
    project.getTagManager().addPropertyChangeListener(TagManagerEvent.tagsetDefinitionChanged, tagsetChangeListener);
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition) TagDefinition(de.catma.tag.TagDefinition) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) Pair(de.catma.util.Pair)

Example 13 with Pair

use of de.catma.util.Pair in project catma by forTEXT.

the class CorpusImportDialog method handleOkPressed.

@Override
protected void handleOkPressed() {
    if (corporaGrid.getSelectedItems().isEmpty()) {
        Notification.show("Info", "Please select a Corpus from the list first!", Type.HUMANIZED_MESSAGE);
    } else {
        final CorpusImportMetadata corpusMetadata = corporaGrid.getSelectedItems().iterator().next();
        BackgroundServiceProvider backgroundServiceProvider = (BackgroundServiceProvider) UI.getCurrent();
        progressBar.setVisible(true);
        progressBar.setIndeterminate(true);
        progressBar.setCaption("Loading Corpus " + corpusMetadata);
        backgroundServiceProvider.submit("load-corpus", new DefaultProgressCallable<Pair<File, List<CorpusImportDocumentMetadata>>>() {

            @Override
            public Pair<File, List<CorpusImportDocumentMetadata>> call() throws Exception {
                File corpusFile = getCorpusFile(corpusMetadata);
                return new Pair<>(corpusFile, null);
            }
        }, new ExecutionListener<Pair<File, List<CorpusImportDocumentMetadata>>>() {

            @Override
            public void done(Pair<File, List<CorpusImportDocumentMetadata>> result) {
                try {
                    List<CorpusImportDocumentMetadata> documentMetadataList = getDocumentMetadata(corpusMetadata);
                    result.setSecond(documentMetadataList);
                    progressBar.setVisible(false);
                    CorpusImportDialog.this.result = result;
                    CorpusImportDialog.super.handleOkPressed();
                } catch (Exception e) {
                    progressBar.setVisible(false);
                    Notification.show("Error", String.format("Error retrieving Document metadata! " + "\n The underlying error message was:\n%2$s", e.getMessage()), Type.ERROR_MESSAGE);
                    handleCancelPressed();
                }
            }

            @Override
            public void error(Throwable t) {
                Logger.getLogger(ProjectView.class.getName()).log(Level.SEVERE, String.format("Error loading CATMA 5 Corpus %1$s!", corpusMetadata.toString()), t);
                String errorMsg = t.getMessage();
                if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
                    errorMsg = "";
                }
                progressBar.setVisible(false);
                Notification.show("Error", String.format("Error listing CATMA 5 Corpus %1$s! " + "\n The underlying error message was:\n%2$s", corpusMetadata.toString(), errorMsg), Type.ERROR_MESSAGE);
                handleCancelPressed();
            }
        });
    }
}
Also used : BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) IOException(java.io.IOException) ArrayList(java.util.ArrayList) List(java.util.List) ProjectView(de.catma.ui.module.project.ProjectView) File(java.io.File) Pair(de.catma.util.Pair)

Example 14 with Pair

use of de.catma.util.Pair in project catma by forTEXT.

the class AddParenttagDialog method getResult.

@Override
protected Pair<TagsetDefinition, TagDefinition> getResult() {
    TagDefinition tag = new TagDefinition(idGenerator.generate(), tfName.getValue(), null, cbTagsets.getValue().getUuid());
    tag.addSystemPropertyDefinition(new PropertyDefinition(idGenerator.generate(PropertyDefinition.SystemPropertyName.catma_displaycolor.name()), PropertyDefinition.SystemPropertyName.catma_displaycolor.name(), Collections.singletonList(String.valueOf(colorPicker.getValue().getRGB()))));
    for (PropertyDefinition propertyDefinition : propertyDefDataProvider.getItems()) {
        tag.addUserDefinedPropertyDefinition(propertyDefinition);
    }
    return new Pair<>(cbTagsets.getValue(), tag);
}
Also used : TagDefinition(de.catma.tag.TagDefinition) PropertyDefinition(de.catma.tag.PropertyDefinition) Pair(de.catma.util.Pair)

Example 15 with Pair

use of de.catma.util.Pair in project catma by forTEXT.

the class GitlabManagerPrivileged method acquireImpersonationToken.

@Override
public Pair<GitUser, String> acquireImpersonationToken(String identifier, String provider, String email, String name) throws IOException {
    User user = this.acquireUser(identifier, provider, email, name);
    UserApi customUserApi = this.privilegedGitLabApi.getUserApi();
    try {
        List<PersonalAccessToken> impersonationTokens = customUserApi.getImpersonationTokens(user.getId(), ImpersonationState.ACTIVE);
        // revoke the default token if it exists actively
        for (PersonalAccessToken token : impersonationTokens) {
            if (token.getName().equals(GITLAB_DEFAULT_IMPERSONATION_TOKEN_NAME)) {
                privilegedGitLabApi.getUserApi().revokeImpersonationToken(user.getId(), token.getId());
                break;
            }
        }
    } catch (GitLabApiException e) {
        throw new IOException("Failed to revoke existing impersonation token", e);
    }
    String impersonationToken = this.createImpersonationToken(user.getId(), GITLAB_DEFAULT_IMPERSONATION_TOKEN_NAME);
    if (impersonationToken == null) {
        String errorMessage = String.format("Failed to acquire impersonation token for CATMA with identifier `%s`. " + "The creation of the token the associated GitLab user ID `%s` failed, no " + "active impersonation token called `%s` can be found!", identifier, user.getId(), GITLAB_DEFAULT_IMPERSONATION_TOKEN_NAME);
        throw new IOException(errorMessage);
    }
    Pair<GitUser, String> retVal = new Pair<>(new GitUser(user), impersonationToken);
    return retVal;
}
Also used : User(org.gitlab4j.api.models.User) GitUser(de.catma.repository.git.GitUser) PersonalAccessToken(org.gitlab4j.api.models.PersonalAccessToken) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) UserApi(org.gitlab4j.api.UserApi) GitUser(de.catma.repository.git.GitUser) Pair(de.catma.util.Pair)

Aggregations

Pair (de.catma.util.Pair)20 TagsetDefinition (de.catma.tag.TagsetDefinition)11 TagDefinition (de.catma.tag.TagDefinition)10 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)9 List (java.util.List)8 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)7 PropertyDefinition (de.catma.tag.PropertyDefinition)7 PropertyChangeEvent (java.beans.PropertyChangeEvent)7 PropertyChangeListener (java.beans.PropertyChangeListener)7 SourceDocument (de.catma.document.source.SourceDocument)6 Notification (com.vaadin.ui.Notification)5 Type (com.vaadin.ui.Notification.Type)5 UI (com.vaadin.ui.UI)5 Project (de.catma.project.Project)5 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)4 Multimap (com.google.common.collect.Multimap)4 EventBus (com.google.common.eventbus.EventBus)4 HorizontalLayout (com.vaadin.ui.HorizontalLayout)4 BackgroundServiceProvider (de.catma.backgroundservice.BackgroundServiceProvider)4