Search in sources :

Example 1 with ProjectApi

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

the class GitlabManagerRestricted method getResourcePermissions.

private Map<String, AccessLevel> getResourcePermissions(Integer groupId) throws GitLabApiException {
    Map<String, AccessLevel> resultMap = Maps.newHashMap();
    ProjectApi projectApi = new ProjectApi(restrictedGitLabApi);
    logger.info("Loading project permissions");
    List<Project> resourceAndContainerProjects = projectApi.getProjects(new ProjectFilter().withMembership(true));
    logger.info(String.format("Filtering %1$d resources on group #%2$d", resourceAndContainerProjects.size(), groupId));
    Set<Project> filteredOnGroupProjects = resourceAndContainerProjects.stream().filter(p -> p.getNamespace().getId().equals(groupId)).collect(Collectors.toSet());
    logger.info(String.format("Updating accesslevel registry for %1$d resources", filteredOnGroupProjects.size()));
    for (Project p : filteredOnGroupProjects) {
        Permissions permission = p.getPermissions();
        if (permission.getGroupAccess() != null) {
            resultMap.put(p.getName(), permission.getGroupAccess().getAccessLevel());
        }
        if (permission.getProjectAccess() != null && (!resultMap.containsKey(p.getName()) || resultMap.get(p.getName()).value.intValue() < permission.getProjectAccess().getAccessLevel().value.intValue())) {
            resultMap.put(p.getName(), permission.getProjectAccess().getAccessLevel());
        }
    }
    return resultMap;
}
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) Project(org.gitlab4j.api.models.Project) ProjectFilter(org.gitlab4j.api.models.ProjectFilter) ProjectApi(org.gitlab4j.api.ProjectApi) Permissions(org.gitlab4j.api.models.Permissions) AccessLevel(org.gitlab4j.api.models.AccessLevel)

Example 2 with ProjectApi

use of org.gitlab4j.api.ProjectApi 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 3 with ProjectApi

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

the class GitLabServerManagerTest method tearDown.

@AfterEach
public void tearDown() throws Exception {
    GitLabApi adminGitLabApi = gitlabManagerPrivileged.getGitLabApi();
    GroupApi groupApi = adminGitLabApi.getGroupApi();
    ProjectApi projectApi = adminGitLabApi.getProjectApi();
    UserApi userApi = adminGitLabApi.getUserApi();
    if (groupsToDeleteOnTearDown.size() > 0) {
        for (String groupPath : groupsToDeleteOnTearDown) {
            gitlabManagerRestricted.deleteGroup(groupPath);
            await().until(() -> groupApi.getGroups().isEmpty());
        }
    }
    if (repositoriesToDeleteOnTearDown.size() > 0) {
        for (Integer repositoryId : repositoriesToDeleteOnTearDown) {
            gitlabManagerRestricted.deleteRepository(repositoryId);
            await().until(() -> projectApi.getProjects().isEmpty());
        }
    }
    if (usersToDeleteOnTearDown.size() > 0) {
        for (Integer userId : usersToDeleteOnTearDown) {
            userApi.deleteUser(userId);
            GitLabServerManagerTest.awaitUserDeleted(userApi, userId);
        }
    }
    // delete the GitLab user that we created in setUp, including associated groups/repos
    // TODO: explicit deletion of associated groups/repos (above) is now superfluous since we are doing a hard delete
    userApi.deleteUser(gitlabManagerRestricted.getUser().getUserId(), true);
// GitLabServerManagerTest.awaitUserDeleted(userApi, gitlabManagerRestricted.getUser().getUserId());
}
Also used : GitLabApi(org.gitlab4j.api.GitLabApi) GroupApi(org.gitlab4j.api.GroupApi) ProjectApi(org.gitlab4j.api.ProjectApi) UserApi(org.gitlab4j.api.UserApi) AfterEach(org.junit.jupiter.api.AfterEach)

Example 4 with ProjectApi

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

the class GitlabManagerRestricted method createRepository.

@Override
public CreateRepositoryResponse createRepository(String name, String path, String groupPath) throws IOException {
    GroupApi groupApi = restrictedGitLabApi.getGroupApi();
    ProjectApi projectApi = restrictedGitLabApi.getProjectApi();
    try {
        Group group = groupApi.getGroup(groupPath);
        Namespace namespace = new Namespace();
        namespace.setId(group.getId());
        Project project = new Project();
        project.setName(name);
        project.setNamespace(namespace);
        if (StringUtils.isNotEmpty(path)) {
            project.setPath(path);
        }
        project = projectApi.createProject(project);
        return new CreateRepositoryResponse(groupPath, project.getId(), GitlabUtils.rewriteGitLabServerUrl(project.getHttpUrlToRepo()));
    } catch (GitLabApiException e) {
        throw new IOException("Failed to create remote Git repository", e);
    }
}
Also used : Group(org.gitlab4j.api.models.Group) Project(org.gitlab4j.api.models.Project) GroupApi(org.gitlab4j.api.GroupApi) ProjectApi(org.gitlab4j.api.ProjectApi) CreateRepositoryResponse(de.catma.repository.git.CreateRepositoryResponse) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) Namespace(org.gitlab4j.api.models.Namespace)

Example 5 with ProjectApi

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

the class GitlabManagerRestricted method getProjectRootRepositoryUrl.

@Override
public String getProjectRootRepositoryUrl(ProjectReference projectReference) throws IOException {
    try {
        ProjectApi projectApi = restrictedGitLabApi.getProjectApi();
        Project rootProject = projectApi.getProject(projectReference.getProjectId(), GitProjectManager.getProjectRootRepositoryName(projectReference.getProjectId()));
        return GitlabUtils.rewriteGitLabServerUrl(rootProject.getHttpUrlToRepo());
    } catch (GitLabApiException e) {
        throw new IOException("Failed to load Project's Root Repository URL: " + GitProjectManager.getProjectRootRepositoryName(projectReference.getProjectId()), e);
    }
}
Also used : Project(org.gitlab4j.api.models.Project) ProjectApi(org.gitlab4j.api.ProjectApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)4 CreateRepositoryResponse (de.catma.repository.git.CreateRepositoryResponse)3 ProjectApi (org.gitlab4j.api.ProjectApi)3 Cache (com.google.common.cache.Cache)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 Maps (com.google.common.collect.Maps)2 EventBus (com.google.common.eventbus.EventBus)2 Subscribe (com.google.common.eventbus.Subscribe)2 JsonObject (com.google.gson.JsonObject)2 JsonParser (com.google.gson.JsonParser)2 BackgroundService (de.catma.backgroundservice.BackgroundService)2 Comment (de.catma.document.comment.Comment)2 Reply (de.catma.document.comment.Reply)2 ForkStatus (de.catma.project.ForkStatus)2 ProjectReference (de.catma.project.ProjectReference)2 CATMAPropertyKey (de.catma.properties.CATMAPropertyKey)2 RBACPermission (de.catma.rbac.RBACPermission)2 RBACRole (de.catma.rbac.RBACRole)2 GitMember (de.catma.repository.git.GitMember)2 GitProjectManager (de.catma.repository.git.GitProjectManager)2