use of org.finos.legend.sdlc.domain.model.user.User in project legend-sdlc by finos.
the class GitLabUserApi method getUserById.
@Override
public User getUserById(String userId) {
LegendSDLCServerException.validateNonNull(userId, "userId cannot be null");
Exception exception = null;
for (GitLabMode mode : getValidGitLabModes()) {
User user;
try {
user = fromGitLabAbstractUser(getGitLabApi(mode).getUserApi().getUser(userId));
} catch (Exception e) {
exception = e;
user = null;
}
if (user != null) {
return user;
}
}
if (exception != null) {
throw buildException(exception, () -> "User " + getCurrentUser() + " is not allowed to get user " + userId, () -> "Unknown user: " + userId, () -> "Error getting user " + userId);
}
throw new LegendSDLCServerException("Unknown user: " + userId, Status.NOT_FOUND);
}
use of org.finos.legend.sdlc.domain.model.user.User in project legend-sdlc by finos.
the class GitLabUserApi method getCurrentUserInfo.
@Override
public User getCurrentUserInfo() {
List<Exception> exceptions = Lists.mutable.empty();
for (GitLabMode mode : getValidGitLabModes()) {
try {
User user = fromGitLabAbstractUser(getGitLabApi(mode).getUserApi().getCurrentUser());
if (user != null) {
return user;
}
} catch (Exception e) {
exceptions.add(e);
}
}
if (exceptions.isEmpty()) {
throw new LegendSDLCServerException("Could not get current user information");
}
Exception e = exceptions.get(0);
for (Exception other : exceptions) {
if (other != e) {
e.addSuppressed(other);
}
}
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to get current user information", null, () -> "Error getting current user information");
}
use of org.finos.legend.sdlc.domain.model.user.User in project legend-sdlc by finos.
the class GitLabReviewApi method getReviews.
@Override
public List<Review> getReviews(String projectId, ReviewState state, Iterable<String> revisionIds, Instant since, Instant until, Integer limit) {
LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
Set<String> revisionIdSet;
if (revisionIds == null) {
revisionIdSet = Collections.emptySet();
} else if (revisionIds instanceof Set) {
revisionIdSet = (Set<String>) revisionIds;
} else {
revisionIdSet = Sets.mutable.withAll(revisionIds);
}
Stream<MergeRequest> mergeRequestStream;
try {
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
if (!revisionIdSet.isEmpty()) {
// TODO: we might want to do this differently since the number of revision IDs can be huge
// we can have a threshold for which we change our strategy to to make a single call for
// merge requests by the other criteria and then filter by revisionIds.
MutableIntSet mergeRequestIds = IntSets.mutable.empty();
CommitsApi commitsApi = getGitLabApi(gitLabProjectId.getGitLabMode()).getCommitsApi();
// Combine all MRs associated with each revision
mergeRequestStream = revisionIdSet.stream().flatMap(revisionId -> {
try {
return PagerTools.stream(withRetries(() -> commitsApi.getMergeRequests(gitLabProjectId.getGitLabId(), revisionId, ITEMS_PER_PAGE)));
} catch (Exception e) {
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to get reviews associated with revision " + revisionId + " for project " + projectId, () -> "Unknown revision (" + revisionId + ") or project (" + projectId + ")", () -> "Error getting reviews associated with revision " + revisionId + " for project " + projectId);
}
}).filter(// remove duplicates
mr -> (mr.getIid() != null) && mergeRequestIds.add(mr.getIid()));
MergeRequestState mergeRequestState = getMergeRequestState(state);
if (mergeRequestState != MergeRequestState.ALL) {
String mergeRequestStateString = mergeRequestState.toString();
mergeRequestStream = mergeRequestStream.filter(mr -> mergeRequestStateString.equalsIgnoreCase(mr.getState()));
}
} else {
// if no revision ID is specified we will use the default merge request API from Gitlab to take advantage of the filter
MergeRequestFilter mergeRequestFilter = withMergeRequestFilters(new MergeRequestFilter(), state, since, until).withProjectId(gitLabProjectId.getGitLabId());
mergeRequestStream = PagerTools.stream(withRetries(() -> getGitLabApi(gitLabProjectId.getGitLabMode()).getMergeRequestApi().getMergeRequests(mergeRequestFilter, ITEMS_PER_PAGE)));
}
Stream<Review> stream = mergeRequestStream.filter(BaseGitLabApi::isReviewMergeRequest).map(mr -> fromGitLabMergeRequest(projectId, mr));
return addReviewFilters(stream, state, since, until, limit).collect(Collectors.toList());
} catch (Exception e) {
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to get reviews for project " + projectId + ((state == null) ? "" : (" with state " + state)), () -> "Unknown project (" + projectId + ")", () -> "Error getting reviews for project " + projectId + ((state == null) ? "" : (" with state " + state)));
}
}
Aggregations