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;
}
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");
}
}
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());
}
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);
}
}
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);
}
}
Aggregations