Search in sources :

Example 21 with GitLabApiException

use of org.gitlab4j.api.GitLabApiException 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 22 with GitLabApiException

use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.

the class GitlabManagerRestricted method deleteGroup.

@Override
public void deleteGroup(String path) throws IOException {
    GroupApi groupApi = restrictedGitLabApi.getGroupApi();
    try {
        // TODO: remove, deleteGroup can work with the path
        Group group = groupApi.getGroup(path);
        groupApi.deleteGroup(group);
    } catch (GitLabApiException e) {
        throw new IOException("Failed to delete remote group", e);
    }
}
Also used : Group(org.gitlab4j.api.models.Group) GroupApi(org.gitlab4j.api.GroupApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Example 23 with GitLabApiException

use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.

the class GitlabManagerRestricted method addComment.

@Override
public void addComment(String projectId, Comment comment) throws IOException {
    String resourceId = comment.getDocumentId();
    try {
        String projectPath = projectId + "/" + resourceId;
        IssuesApi issuesApi = restrictedGitLabApi.getIssuesApi();
        String title = comment.getBody().substring(0, Math.min(100, comment.getBody().length()));
        if (title.length() < comment.getBody().length()) {
            title += "...";
        }
        String description = new SerializationHelper<Comment>().serialize(comment);
        Issue issue = issuesApi.createIssue(projectPath, title, description, null, null, null, CATMA_COMMENT_LABEL, null, null, null, null);
        comment.setId(issue.getId());
        comment.setIid(issue.getIid());
    } catch (GitLabApiException e) {
        throw new IOException(String.format("Failed to add a new Comment for resource %1$s in group %2$s!", resourceId, projectId), e);
    }
}
Also used : Comment(de.catma.document.comment.Comment) IssuesApi(org.gitlab4j.api.IssuesApi) Issue(org.gitlab4j.api.models.Issue) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Example 24 with GitLabApiException

use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.

the class GitlabManagerRestricted method leaveGroup.

@Override
public void leaveGroup(String path) throws IOException {
    GroupApi groupApi = restrictedGitLabApi.getGroupApi();
    try {
        Group group = groupApi.getGroup(path);
        Member member = groupApi.getMember(group.getId(), user.getUserId());
        if (member != null && member.getAccessLevel().value >= AccessLevel.GUEST.value && member.getAccessLevel().value < AccessLevel.OWNER.value) {
            groupApi.removeMember(group.getId(), user.getUserId());
        }
    } catch (GitLabApiException ge) {
        throw new IOException("Couldn't leave group", ge);
    }
}
Also used : Group(org.gitlab4j.api.models.Group) GroupApi(org.gitlab4j.api.GroupApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) GitMember(de.catma.repository.git.GitMember) Member(org.gitlab4j.api.models.Member)

Example 25 with GitLabApiException

use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.

the class GitlabManagerRestricted method getRolesPerResource.

public Map<String, RBACRole> getRolesPerResource(String projectId) throws IOException {
    try {
        Group group = restrictedGitLabApi.getGroupApi().getGroup(projectId);
        Map<String, AccessLevel> permMap = getResourcePermissions(group.getId());
        return permMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> RBACRole.forValue(e.getValue().value)));
    } catch (GitLabApiException e) {
        throw new IOException("Permission retrieval failed!", 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) Group(org.gitlab4j.api.models.Group) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) AccessLevel(org.gitlab4j.api.models.AccessLevel)

Aggregations

GitLabApiException (org.gitlab4j.api.GitLabApiException)77 IOException (java.io.IOException)35 GitLabApi (org.gitlab4j.api.GitLabApi)18 Project (org.gitlab4j.api.models.Project)18 Group (org.gitlab4j.api.models.Group)14 List (java.util.List)12 GitLabProjectId (org.finos.legend.sdlc.server.gitlab.GitLabProjectId)9 MergeRequest (org.gitlab4j.api.models.MergeRequest)9 GitMember (de.catma.repository.git.GitMember)8 ArrayList (java.util.ArrayList)8 LegendSDLCServerException (org.finos.legend.sdlc.server.error.LegendSDLCServerException)8 MergeRequestApi (org.gitlab4j.api.MergeRequestApi)8 UserApi (org.gitlab4j.api.UserApi)8 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)7 Workflow (com.tremolosecurity.provisioning.core.Workflow)7 GroupApi (org.gitlab4j.api.GroupApi)7 IssuesApi (org.gitlab4j.api.IssuesApi)7 AccessLevel (org.gitlab4j.api.models.AccessLevel)7 Issue (org.gitlab4j.api.models.Issue)7 Comment (de.catma.document.comment.Comment)6