Search in sources :

Example 26 with GitLabApiException

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

the class GitlabManagerRestricted method updateGroup.

@Override
public void updateGroup(String name, String path, String description) throws IOException {
    try {
        GroupApi groupApi = restrictedGitLabApi.getGroupApi();
        groupApi.updateGroup(path, name, path, description, null, null, null, null);
    } catch (GitLabApiException e) {
        throw new IOException("Failed to update name/description for group", e);
    }
}
Also used : GroupApi(org.gitlab4j.api.GroupApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Example 27 with GitLabApiException

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

the class GitlabManagerRestricted method getComments.

@Override
public List<Comment> getComments(String projectId) throws IOException {
    try {
        List<Comment> result = new ArrayList<Comment>();
        IssuesApi issuesApi = new IssuesApi(restrictedGitLabApi);
        String projectPath = projectId;
        List<Issue> issues = issuesApi.getGroupIssues(projectPath, new IssueFilter().withLabels(Collections.singletonList(CATMA_COMMENT_LABEL)).withState(IssueState.OPENED));
        for (Issue issue : issues) {
            String description = issue.getDescription();
            int noteCount = issue.getUserNotesCount();
            try {
                Author author = issue.getAuthor();
                Comment comment = new SerializationHelper<Comment>().deserialize(description, Comment.class);
                comment.setId(issue.getId());
                comment.setIid(issue.getIid());
                comment.setUserId(author.getId());
                comment.setUsername(author.getName());
                comment.setReplyCount(noteCount);
                result.add(comment);
            } catch (Exception e) {
                logger.log(Level.SEVERE, String.format("Error deserializing Comment #%1$d %2$s", issue.getId(), description), e);
            }
        }
        return result;
    } catch (GitLabApiException e) {
        throw new IOException(String.format("Failed to retrieve Comments in group %1$s!", projectId), e);
    }
}
Also used : Comment(de.catma.document.comment.Comment) IssuesApi(org.gitlab4j.api.IssuesApi) Issue(org.gitlab4j.api.models.Issue) ArrayList(java.util.ArrayList) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) IssueFilter(org.gitlab4j.api.models.IssueFilter) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) Author(org.gitlab4j.api.models.Author)

Example 28 with GitLabApiException

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

the class GitlabManagerRestricted method removeComment.

@Override
public void removeComment(String projectId, Comment comment) throws IOException {
    String resourceId = comment.getDocumentId();
    try {
        String projectPath = projectId + "/" + resourceId;
        IssuesApi issuesApi = restrictedGitLabApi.getIssuesApi();
        issuesApi.closeIssue(projectPath, comment.getIid());
    } catch (GitLabApiException e) {
        throw new IOException(String.format("Failed to remove Comment %1$s %2$d for resource %3$s in group %4$s!", comment.getUuid(), comment.getIid(), resourceId, projectId), e);
    }
}
Also used : IssuesApi(org.gitlab4j.api.IssuesApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Example 29 with GitLabApiException

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

the class GitlabManagerRestricted method getResourceMembers.

@Override
public Set<de.catma.user.Member> getResourceMembers(String projectId, String resourceId) throws IOException {
    try {
        Project project = restrictedGitLabApi.getProjectApi().getProject(projectId, resourceId);
        if (project != null) {
            List<GitMember> allMembers = new ProjectApi(restrictedGitLabApi).getAllMembers(project.getId()).stream().map(member -> new GitMember(member)).collect(Collectors.toList());
            Map<Integer, de.catma.user.Member> mergedList = new HashMap<>();
            for (de.catma.user.Member m : allMembers) {
                if (!mergedList.containsKey(m.getUserId()) || mergedList.get(m.getUserId()).getRole().getAccessLevel() < m.getRole().getAccessLevel()) {
                    mergedList.put(m.getUserId(), m);
                }
            }
            return mergedList.values().stream().collect(Collectors.toSet());
        } else {
            throw new IOException("resource unknown");
        }
    } catch (GitLabApiException e) {
        throw new IOException("resource unknown");
    }
}
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) HashMap(java.util.HashMap) ProjectApi(org.gitlab4j.api.ProjectApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) Project(org.gitlab4j.api.models.Project) GitMember(de.catma.repository.git.GitMember) GitMember(de.catma.repository.git.GitMember) Member(org.gitlab4j.api.models.Member)

Example 30 with GitLabApiException

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

the class GitlabManagerCommon method assignDefaultAccessToRootProject.

private RBACSubject assignDefaultAccessToRootProject(RBACSubject subject, Integer groupId) throws IOException {
    try {
        Group group = getGitLabApi().getGroupApi().getGroup(groupId);
        Project rootProject = getGitLabApi().getProjectApi().getProject(group.getName(), GitProjectManager.getProjectRootRepositoryName(group.getName()));
        try {
            Member member = getGitLabApi().getProjectApi().getMember(rootProject.getId(), subject.getUserId());
            if (member.getAccessLevel().value < RBACRole.ASSISTANT.getAccessLevel()) {
                return new GitMember(getGitLabApi().getProjectApi().updateMember(rootProject.getId(), subject.getUserId(), AccessLevel.forValue(RBACRole.ASSISTANT.getAccessLevel())));
            } else {
                // In both cases we refuse to update the role, and simply do nothing.
                return subject;
            }
        } catch (GitLabApiException e) {
            return new GitMember(getGitLabApi().getProjectApi().addMember(rootProject.getId(), subject.getUserId(), AccessLevel.forValue(RBACRole.ASSISTANT.getAccessLevel())));
        }
    } catch (GitLabApiException e) {
        throw new IOException("error assigning default access to root project in group #" + groupId, e);
    }
}
Also used : Group(org.gitlab4j.api.models.Group) Project(org.gitlab4j.api.models.Project) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) GitMember(de.catma.repository.git.GitMember) GitMember(de.catma.repository.git.GitMember) Member(org.gitlab4j.api.models.Member)

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