Search in sources :

Example 1 with ProjectFilter

use of org.gitlab4j.api.models.ProjectFilter 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 ProjectFilter

use of org.gitlab4j.api.models.ProjectFilter in project octane-gitlab-service by MicroFocus.

the class GitlabServices method getJobList.

CIJobsList getJobList() {
    CIJobsList ciJobsList = dtoFactory.newDTO(CIJobsList.class);
    List<PipelineNode> list = new ArrayList<>();
    String projectNames = "";
    try {
        ProjectFilter filter = new ProjectFilter();
        filter.withMinAccessLevel(AccessLevel.MAINTAINER);
        List<Project> projectsFilters = gitLabApi.getProjectApi().getProjects(filter);
        log.info("There are only " + projectsFilters.size() + " projects with access level => MAINTAINER for the integrated user");
        for (Project project : projectsFilters) {
            try {
                ParsedPath parseProject = new ParsedPath(project, gitLabApi);
                PipelineNode buildConf;
                if (parseProject.isMultiBranch()) {
                    buildConf = dtoFactory.newDTO(PipelineNode.class).setJobCiId(parseProject.getJobCiId(true)).setName(project.getNameWithNamespace()).setMultiBranchType(MultiBranchType.MULTI_BRANCH_PARENT);
                } else {
                    buildConf = dtoFactory.newDTO(PipelineNode.class).setJobCiId(parseProject.getJobCiId(false)).setName(project.getNameWithNamespace());
                }
                projectNames = projectNames + buildConf.getName() + ",";
                list.add(buildConf);
            } catch (Exception e) {
                log.warn("Failed to add some tags to the job list", e);
            }
        }
    } catch (Exception e) {
        log.warn("Failed to add some jobs to the job list", e);
    }
    log.info("getJobList results:" + projectNames);
    ciJobsList.setJobs(list.toArray(new PipelineNode[list.size()]));
    return ciJobsList;
}
Also used : CIJobsList(com.hp.octane.integrations.dto.general.CIJobsList) Project(org.gitlab4j.api.models.Project) ParsedPath(com.microfocus.octane.gitlab.helpers.ParsedPath) ProjectFilter(org.gitlab4j.api.models.ProjectFilter) ArrayList(java.util.ArrayList) PipelineNode(com.hp.octane.integrations.dto.pipelines.PipelineNode) MalformedURLException(java.net.MalformedURLException) GitLabApiException(org.gitlab4j.api.GitLabApiException)

Aggregations

ArrayList (java.util.ArrayList)2 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 Maps (com.google.common.collect.Maps)1 EventBus (com.google.common.eventbus.EventBus)1 Subscribe (com.google.common.eventbus.Subscribe)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 CIJobsList (com.hp.octane.integrations.dto.general.CIJobsList)1 PipelineNode (com.hp.octane.integrations.dto.pipelines.PipelineNode)1 ParsedPath (com.microfocus.octane.gitlab.helpers.ParsedPath)1 BackgroundService (de.catma.backgroundservice.BackgroundService)1 Comment (de.catma.document.comment.Comment)1 Reply (de.catma.document.comment.Reply)1 ForkStatus (de.catma.project.ForkStatus)1 ProjectReference (de.catma.project.ProjectReference)1 CATMAPropertyKey (de.catma.properties.CATMAPropertyKey)1 RBACPermission (de.catma.rbac.RBACPermission)1 RBACRole (de.catma.rbac.RBACRole)1 CreateRepositoryResponse (de.catma.repository.git.CreateRepositoryResponse)1