Search in sources :

Example 6 with IDGenerator

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

the class GitlabManagerRestricted method getCommentReplies.

@Override
public List<Reply> getCommentReplies(String projectId, Comment comment) throws IOException {
    String resourceId = comment.getDocumentId();
    String projectPath = projectId + "/" + resourceId;
    NotesApi notesApi = restrictedGitLabApi.getNotesApi();
    List<Reply> result = new ArrayList<Reply>();
    try {
        List<Note> notes = notesApi.getIssueNotes(projectPath, comment.getIid());
        for (Note note : notes.stream().filter(n -> !n.getSystem()).collect(Collectors.toList())) {
            // filter system notes
            String noteBody = note.getBody();
            Reply reply = null;
            try {
                reply = new SerializationHelper<Reply>().deserialize(noteBody, Reply.class);
                reply.setCommentUuid(comment.getUuid());
                reply.setId(note.getId());
                reply.setUserId(note.getAuthor().getId());
                reply.setUsername(note.getAuthor().getName());
            } catch (Exception e) {
                logger.log(Level.SEVERE, String.format("Error deserializing Reply #%1$d %2$s", note.getId(), noteBody), e);
                IDGenerator idGenerator = new IDGenerator();
                reply = new Reply(idGenerator.generate(), noteBody, note.getAuthor().getUsername(), note.getAuthor().getId(), comment.getUuid(), note.getId());
            }
            result.add(reply);
        }
        comment.setReplies(result);
        return result;
    } catch (GitLabApiException e) {
        throw new IOException(String.format("Failed to retrieve Replies for Comment %1$s %2$d for resource %3$s in group %4$s!", comment.getUuid(), comment.getIid(), resourceId, projectId), e);
    }
}
Also used : NotesApi(org.gitlab4j.api.NotesApi) JsonObject(com.google.gson.JsonObject) Reply(de.catma.document.comment.Reply) AccessLevel(org.gitlab4j.api.models.AccessLevel) ProjectFilter(org.gitlab4j.api.models.ProjectFilter) StringUtils(org.apache.commons.lang3.StringUtils) Author(org.gitlab4j.api.models.Author) IssuesApi(org.gitlab4j.api.IssuesApi) ChangeUserAttributeEvent(de.catma.ui.events.ChangeUserAttributeEvent) Map(java.util.Map) Group(org.gitlab4j.api.models.Group) IssueState(org.gitlab4j.api.Constants.IssueState) GroupApi(org.gitlab4j.api.GroupApi) Visibility(org.gitlab4j.api.models.Visibility) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) IGitUserInformation(de.catma.repository.git.interfaces.IGitUserInformation) GitMember(de.catma.repository.git.GitMember) Pager(org.gitlab4j.api.Pager) GitlabUtils(de.catma.repository.git.GitlabUtils) Set(java.util.Set) Logger(java.util.logging.Logger) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) Collectors(java.util.stream.Collectors) ProjectReference(de.catma.project.ProjectReference) Objects(java.util.Objects) List(java.util.List) ProjectApi(org.gitlab4j.api.ProjectApi) Optional(java.util.Optional) GitLabApiException(org.gitlab4j.api.GitLabApiException) Status(org.gitlab4j.api.models.ImportStatus.Status) CacheBuilder(com.google.common.cache.CacheBuilder) GitLabApi(org.gitlab4j.api.GitLabApi) RBACPermission(de.catma.rbac.RBACPermission) Permissions(org.gitlab4j.api.models.Permissions) GroupFilter(org.gitlab4j.api.models.GroupFilter) Namespace(org.gitlab4j.api.models.Namespace) HashMap(java.util.HashMap) RBACRole(de.catma.rbac.RBACRole) JsonParser(com.google.gson.JsonParser) User(de.catma.user.User) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) EventBus(com.google.common.eventbus.EventBus) IRemoteGitManagerRestricted(de.catma.repository.git.interfaces.IRemoteGitManagerRestricted) Comment(de.catma.document.comment.Comment) ForkStatus(de.catma.project.ForkStatus) GitProjectManager(de.catma.repository.git.GitProjectManager) Note(org.gitlab4j.api.models.Note) IDGenerator(de.catma.util.IDGenerator) Subscribe(com.google.common.eventbus.Subscribe) CreateRepositoryResponse(de.catma.repository.git.CreateRepositoryResponse) Issue(org.gitlab4j.api.models.Issue) IOException(java.io.IOException) Project(org.gitlab4j.api.models.Project) Maps(com.google.common.collect.Maps) IssueFilter(org.gitlab4j.api.models.IssueFilter) TimeUnit(java.util.concurrent.TimeUnit) Member(org.gitlab4j.api.models.Member) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) BackgroundService(de.catma.backgroundservice.BackgroundService) GitUser(de.catma.repository.git.GitUser) ArrayList(java.util.ArrayList) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) Note(org.gitlab4j.api.models.Note) Reply(de.catma.document.comment.Reply) IDGenerator(de.catma.util.IDGenerator) NotesApi(org.gitlab4j.api.NotesApi)

Example 7 with IDGenerator

use of de.catma.util.IDGenerator 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;
}
Also used : CorpusExporter(de.catma.document.corpus.CorpusExporter) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) Collection(java.util.Collection) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) FileInputStream(java.io.FileInputStream) SourceDocument(de.catma.document.source.SourceDocument) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) File(java.io.File) Corpus(de.catma.document.corpus.Corpus) ErrorHandler(de.catma.ui.module.main.ErrorHandler) IDGenerator(de.catma.util.IDGenerator) InputStream(java.io.InputStream) StreamSource(com.vaadin.server.StreamResource.StreamSource) SourceDocument(de.catma.document.source.SourceDocument) CorpusExporter(de.catma.document.corpus.CorpusExporter) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Corpus(de.catma.document.corpus.Corpus) FileInputStream(java.io.FileInputStream) Project(de.catma.project.Project) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) File(java.io.File) IDGenerator(de.catma.util.IDGenerator)

Example 8 with IDGenerator

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

the class TagInstance method addSystemProperty.

public void addSystemProperty(Property property) {
    String propertyDefinitionId = property.getPropertyDefinitionId();
    IDGenerator idGenerator = new IDGenerator();
    String authorId = idGenerator.generate(SystemPropertyName.catma_markupauthor.name());
    String timestampId = idGenerator.generate(SystemPropertyName.catma_markuptimestamp.name());
    if (authorId.equals(propertyDefinitionId)) {
        this.author = property.getFirstValue();
    } else if (timestampId.equals(propertyDefinitionId)) {
        this.timestamp = property.getFirstValue();
    }
}
Also used : IDGenerator(de.catma.util.IDGenerator)

Example 9 with IDGenerator

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

the class TaggerView method addComment.

@Override
public void addComment(List<Range> absoluteRanges, int x, int y) {
    User user = project.getUser();
    IDGenerator idGenerator = new IDGenerator();
    CommentDialog commentDialog = new CommentDialog(commentBody -> {
        try {
            project.addComment(new Comment(idGenerator.generate(), user.getName(), user.getUserId(), commentBody, absoluteRanges, this.sourceDocument.getUuid()));
        } catch (IOException e) {
            errorHandler.showAndLogError("Error adding Comment!", e);
        }
    });
    commentDialog.show(x, y);
}
Also used : ClientComment(de.catma.ui.client.ui.tagger.shared.ClientComment) Comment(de.catma.document.comment.Comment) User(de.catma.user.User) IOException(java.io.IOException) IDGenerator(de.catma.util.IDGenerator)

Example 10 with IDGenerator

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

the class TagInstance method getSystemProperties.

/**
 * @return non modifiable collection of system properties
 * @see PropertyDefinition.SystemPropertyName
 */
public Collection<Property> getSystemProperties() {
    Collection<Property> systemProperties = new HashSet<>();
    IDGenerator idGenerator = new IDGenerator();
    String authorId = idGenerator.generate(SystemPropertyName.catma_markupauthor.name());
    systemProperties.add(new Property(authorId, Collections.singleton(author)));
    String timestampId = idGenerator.generate(SystemPropertyName.catma_markuptimestamp.name());
    systemProperties.add(new Property(timestampId, Collections.singleton(timestamp)));
    return Collections.unmodifiableCollection(systemProperties);
}
Also used : IDGenerator(de.catma.util.IDGenerator) HashSet(java.util.HashSet)

Aggregations

IDGenerator (de.catma.util.IDGenerator)25 File (java.io.File)12 TagsetDefinition (de.catma.tag.TagsetDefinition)11 FileInputStream (java.io.FileInputStream)10 Version (de.catma.tag.Version)8 ContentInfoSet (de.catma.document.source.ContentInfoSet)6 SourceDocumentInfo (de.catma.document.source.SourceDocumentInfo)6 SingleTextInputDialog (de.catma.ui.dialog.SingleTextInputDialog)6 ArrayList (java.util.ArrayList)6 EventBus (com.google.common.eventbus.EventBus)5 UI (com.vaadin.ui.UI)5 BackgroundService (de.catma.backgroundservice.BackgroundService)5 IndexInfoSet (de.catma.document.source.IndexInfoSet)5 SourceDocument (de.catma.document.source.SourceDocument)5 TechInfoSet (de.catma.document.source.TechInfoSet)5 Project (de.catma.project.Project)5 TagDefinition (de.catma.tag.TagDefinition)5 JGitRepoManager (de.catma.repository.git.managers.JGitRepoManager)4 TagLibrary (de.catma.tag.TagLibrary)4 TagManager (de.catma.tag.TagManager)4