Skip to content

Commit

Permalink
update [email protected] and use Long for Gitlab entities' IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi committed Apr 19, 2022
1 parent 7303e03 commit a44bf9f
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public final class GitLabProjectId
private static final char DELIMITER = '-';

private final String prefix;
private final int gitLabId;
private final long gitLabId;

private GitLabProjectId(String prefix, int gitLabId)
private GitLabProjectId(String prefix, long gitLabId)
{
this.prefix = prefix;
this.gitLabId = gitLabId;
}

public int getGitLabId()
public long getGitLabId()
{
return this.gitLabId;
}
Expand All @@ -54,7 +54,7 @@ public boolean equals(Object other)
@Override
public int hashCode()
{
return Objects.hashCode(this.prefix) ^ this.gitLabId;
return Objects.hashCode(this.prefix) ^ Objects.hashCode(this.gitLabId);
}

@Override
Expand All @@ -63,7 +63,7 @@ public String toString()
return getProjectIdString(this.prefix, this.gitLabId);
}

public static GitLabProjectId newProjectId(String prefix, int gitLabId)
public static GitLabProjectId newProjectId(String prefix, long gitLabId)
{
return new GitLabProjectId(prefix, gitLabId);
}
Expand All @@ -84,19 +84,19 @@ public static GitLabProjectId parseProjectId(String projectId)
return newProjectId(separatorIndex == -1 ? null : projectId.substring(0, separatorIndex), parseGitLabId(projectId, separatorIndex));
}

private static int parseGitLabId(String projectId, int separatorIndex)
private static long parseGitLabId(String projectId, int separatorIndex)
{
try
{
return Integer.parseInt(projectId.substring(separatorIndex + 1));
return Long.parseLong(projectId.substring(separatorIndex + 1));
}
catch (NumberFormatException e)
{
throw new IllegalArgumentException("Invalid project id: " + projectId);
}
}

private static String getProjectIdString(String prefix, int gitLabId)
private static String getProjectIdString(String prefix, long gitLabId)
{
return (prefix != null ? (prefix + DELIMITER) : "") + gitLabId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,26 +498,26 @@ protected static Date toDateIfNotNull(Instant instant)
return (instant == null) ? null : Date.from(instant);
}

protected static Integer parseIntegerIdIfNotNull(String id)
protected static Long parseNumericIdIfNotNull(String id)
{
return parseIntegerIdIfNotNull(id, null);
return parseNumericIdIfNotNull(id, null);
}

protected static Integer parseIntegerIdIfNotNull(String id, Status errorStatus)
protected static Long parseNumericIdIfNotNull(String id, Status errorStatus)
{
return (id == null) ? null : parseIntegerId(id, errorStatus);
return (id == null) ? null : parseNumericId(id, errorStatus);
}

protected static int parseIntegerId(String id)
protected static long parseNumericId(String id)
{
return parseIntegerId(id, null);
return parseNumericId(id, null);
}

protected static int parseIntegerId(String id, Status errorStatus)
protected static long parseNumericId(String id, Status errorStatus)
{
try
{
return Integer.parseInt(id);
return Long.parseLong(id);
}
catch (NumberFormatException e)
{
Expand Down Expand Up @@ -770,7 +770,7 @@ protected MergeRequest getReviewMergeRequest(MergeRequestApi mergeRequestApi, Gi

protected MergeRequest getReviewMergeRequest(MergeRequestApi mergeRequestApi, GitLabProjectId projectId, String reviewId, boolean includeRebaseInProgress)
{
int mergeRequestId = parseIntegerId(reviewId);
long mergeRequestId = parseNumericId(reviewId);
MergeRequest mergeRequest;
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private GitLabBuildAccessContext(String projectId)
@Override
public Build getBuild(String buildId)
{
int pipelineId = parseIntegerIdIfNotNull(buildId);
long pipelineId = parseNumericIdIfNotNull(buildId);
Pipeline pipeline;
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Issue getIssue(String projectId, String issueId)
try
{
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
org.gitlab4j.api.models.Issue issue = withRetries(() -> getGitLabApi().getIssuesApi().getIssue(gitLabProjectId.getGitLabId(), parseIntegerIdIfNotNull(issueId)));
org.gitlab4j.api.models.Issue issue = withRetries(() -> getGitLabApi().getIssuesApi().getIssue(gitLabProjectId.getGitLabId(), parseNumericIdIfNotNull(issueId)));
return fromGitLabIssue(issue);
}
catch (Exception e)
Expand All @@ -62,7 +62,7 @@ public List<Issue> getIssues(String projectId)
try
{
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
Pager<org.gitlab4j.api.models.Issue> pager = withRetries(() -> getGitLabApi().getIssuesApi().getIssues((Integer) gitLabProjectId.getGitLabId(), ITEMS_PER_PAGE));
Pager<org.gitlab4j.api.models.Issue> pager = withRetries(() -> getGitLabApi().getIssuesApi().getIssues(gitLabProjectId.getGitLabId(), ITEMS_PER_PAGE));
return PagerTools.stream(pager).map(GitLabIssueApi::fromGitLabIssue).collect(PagerTools.listCollector(pager));
}
catch (Exception e)
Expand Down Expand Up @@ -103,7 +103,7 @@ public void deleteIssue(String projectId, String issueId)
try
{
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
withRetries(() -> getGitLabApi().getIssuesApi().deleteIssue(gitLabProjectId.getGitLabId(), parseIntegerIdIfNotNull(issueId)));
withRetries(() -> getGitLabApi().getIssuesApi().deleteIssue(gitLabProjectId.getGitLabId(), parseNumericIdIfNotNull(issueId)));
}
catch (LegendSDLCServerException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public ImportReport importProject(String id, String groupId, String artifactId)
GitLabProjectId projectId;
if (id.chars().allMatch(Character::isDigit))
{
projectId = GitLabProjectId.newProjectId(this.getGitLabConfiguration().getProjectIdPrefix(), Integer.parseInt(id));
projectId = GitLabProjectId.newProjectId(this.getGitLabConfiguration().getProjectIdPrefix(), Long.parseLong(id));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package org.finos.legend.sdlc.server.gitlab.api;

import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.factory.primitive.IntSets;
import org.eclipse.collections.api.set.primitive.MutableLongSet;
import org.eclipse.collections.impl.factory.primitive.LongSets;
import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType;
import org.finos.legend.sdlc.domain.model.review.Review;
import org.finos.legend.sdlc.domain.model.review.ReviewState;
Expand Down Expand Up @@ -97,7 +97,7 @@ else if (revisionIds instanceof Set)
// 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();
MutableLongSet mergeRequestIds = LongSets.mutable.empty();
CommitsApi commitsApi = getGitLabApi().getCommitsApi();
// Combine all MRs associated with each revision
mergeRequestStream = revisionIdSet.stream().flatMap(revisionId ->
Expand Down Expand Up @@ -863,12 +863,12 @@ private static Review fromGitLabMergeRequest(String projectId, MergeRequest merg
return newReview(mergeRequest.getIid(), projectId, workspaceInfo, mergeRequest.getTitle(), mergeRequest.getDescription(), mergeRequest.getCreatedAt(), mergeRequest.getUpdatedAt(), mergeRequest.getClosedAt(), mergeRequest.getMergedAt(), mergeRequest.getState(), mergeRequest.getAuthor(), mergeRequest.getMergeCommitSha(), mergeRequest.getWebUrl(), mergeRequest.getLabels());
}

private static Review newReview(Integer reviewId, String projectId, WorkspaceInfo workspaceInfo, String title, String description, Date createdAt, Date lastUpdatedAt, Date closedAt, Date committedAt, String reviewState, AbstractUser<?> author, String commitRevisionId, String webURL, List<String> labels)
private static Review newReview(Long reviewId, String projectId, WorkspaceInfo workspaceInfo, String title, String description, Date createdAt, Date lastUpdatedAt, Date closedAt, Date committedAt, String reviewState, AbstractUser<?> author, String commitRevisionId, String webURL, List<String> labels)
{
return newReview(reviewId, projectId, workspaceInfo.getWorkspaceId(), workspaceInfo.getWorkspaceType(), title, description, createdAt, lastUpdatedAt, closedAt, committedAt, reviewState, author, commitRevisionId, webURL, labels);
}

private static Review newReview(Integer reviewId, String projectId, String workspaceId, WorkspaceType workspaceType, String title, String description, Date createdAt, Date lastUpdatedAt, Date closedAt, Date committedAt, String reviewState, AbstractUser<?> author, String commitRevisionId, String webURL, List<String> labels)
private static Review newReview(Long reviewId, String projectId, String workspaceId, WorkspaceType workspaceType, String title, String description, Date createdAt, Date lastUpdatedAt, Date closedAt, Date committedAt, String reviewState, AbstractUser<?> author, String commitRevisionId, String webURL, List<String> labels)
{
return newReview(toStringIfNotNull(reviewId), projectId, workspaceId, workspaceType, title, description, toInstantIfNotNull(createdAt), toInstantIfNotNull(lastUpdatedAt), toInstantIfNotNull(closedAt), toInstantIfNotNull(committedAt), getReviewState(reviewState), fromGitLabAbstractUser(author), commitRevisionId, webURL, labels);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.impl.utility.Iterate;
import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType;
import org.finos.legend.sdlc.domain.model.revision.Revision;
import org.finos.legend.sdlc.domain.model.revision.RevisionAlias;
import org.finos.legend.sdlc.domain.model.version.VersionId;
Expand Down Expand Up @@ -191,7 +190,7 @@ private GitLabWorkflowAccessContext(String projectId)
@Override
public Workflow getWorkflow(String workflowId)
{
int pipelineId = parseIntegerIdIfNotNull(workflowId);
long pipelineId = parseNumericIdIfNotNull(workflowId);
Pipeline pipeline;
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public List<WorkflowJob> getWorkflowJobs(String workflowId, Iterable<WorkflowJob
{
LegendSDLCServerException.validateNonNull(workflowId, "workflowId may not be null");

int pipelineId = parseIntegerIdIfNotNull(workflowId);
long pipelineId = parseNumericIdIfNotNull(workflowId);
GitLabApi gitLabApi = getGitLabApi();
PipelineApi pipelineApi = gitLabApi.getPipelineApi();

Expand Down Expand Up @@ -320,10 +320,10 @@ public WorkflowJob cancelWorkflowJob(String workflowId, String workflowJobId)

protected Job getJob(String workflowId, String workflowJobId)
{
return getJob(parseIntegerId(workflowId), parseIntegerId(workflowJobId));
return getJob(parseNumericId(workflowId), parseNumericId(workflowJobId));
}

protected Job getJob(int pipelineId, int jobId)
protected Job getJob(long pipelineId, long jobId)
{
JobApi jobApi = getGitLabApi().getJobApi();
Job job;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testGetProjectIdString()
String prefix = "SOMEPREFIX";
for (int i = 0; i < 1024; i++)
{
Project project = new Project().withId(i);
Project project = new Project().withId((long) i);
Assert.assertEquals(prefix + "-" + i, GitLabProjectId.getProjectIdString(prefix, project));
Assert.assertEquals("" + i, GitLabProjectId.getProjectIdString(null, project));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTest() throws GitLabApiExcep

GitLabProjectId sdlcGitLabProjectId = GitLabProjectId.parseProjectId(projectId);
MergeRequestApi mergeRequestApi = gitLabMemberUserContext.getGitLabAPI().getMergeRequestApi();
int parsedMergeRequestId = Integer.parseInt(reviewId);
int gitlabProjectId = sdlcGitLabProjectId.getGitLabId();
long parsedMergeRequestId = Long.parseLong(reviewId);
long gitlabProjectId = sdlcGitLabProjectId.getGitLabId();

String requiredStatus = "can_be_merged";
CallUntil<MergeRequest, GitLabApiException> callUntil = CallUntil.callUntil(
Expand Down Expand Up @@ -308,8 +308,8 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTest() throws GitLabApiExce

GitLabProjectId sdlcGitLabProjectId = GitLabProjectId.parseProjectId(projectId);
MergeRequestApi mergeRequestApi = gitLabMemberUserContext.getGitLabAPI().getMergeRequestApi();
int parsedMergeRequestId = Integer.parseInt(reviewId);
int gitlabProjectId = sdlcGitLabProjectId.getGitLabId();
long parsedMergeRequestId = Long.parseLong(reviewId);
long gitlabProjectId = sdlcGitLabProjectId.getGitLabId();

String requiredStatus = "can_be_merged";
CallUntil<MergeRequest, GitLabApiException> callUntil = CallUntil.callUntil(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ public void runUpdateUserWorkspaceWithRebaseNoConflictTest() throws GitLabApiExc

GitLabProjectId sdlcGitLabProjectId = GitLabProjectId.parseProjectId(projectId);
MergeRequestApi mergeRequestApi = gitLabMemberUserContext.getGitLabAPI().getMergeRequestApi();
Integer parsedMergeRequestId = Integer.parseInt(reviewId);
Integer gitlabProjectId = sdlcGitLabProjectId.getGitLabId();
long parsedMergeRequestId = Long.parseLong(reviewId);
long gitlabProjectId = sdlcGitLabProjectId.getGitLabId();

String requiredStatus = "can_be_merged";
CallUntil<MergeRequest, GitLabApiException> callUntil = CallUntil.callUntil(
Expand Down Expand Up @@ -339,8 +339,8 @@ public void runUpdateGroupWorkspaceWithRebaseNoConflictTest() throws GitLabApiEx

GitLabProjectId sdlcGitLabProjectId = GitLabProjectId.parseProjectId(projectId);
MergeRequestApi mergeRequestApi = gitLabMemberUserContext.getGitLabAPI().getMergeRequestApi();
Integer parsedMergeRequestId = Integer.parseInt(reviewId);
Integer gitlabProjectId = sdlcGitLabProjectId.getGitLabId();
long parsedMergeRequestId = Long.parseLong(reviewId);
long gitlabProjectId = sdlcGitLabProjectId.getGitLabId();

String requiredStatus = "can_be_merged";
CallUntil<MergeRequest, GitLabApiException> callUntil = CallUntil.callUntil(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public String getWebUrl()
}

@JsonIgnore
public boolean containsUserWorkspace(String workspaceId)
public boolean containsUrWorkspace(String workspaceId)
{
return this.userWorkspaces.containsKey(workspaceId);
}
Expand Down
24 changes: 17 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<dropwizard-swagger.version>1.3.17-1</dropwizard-swagger.version>
<eclipsecollections.version>10.2.0</eclipsecollections.version>
<findbugs.version>3.0.0</findbugs.version>
<gitlab4j.version>4.16.0</gitlab4j.version>
<gitlab4j.version>5.0.1</gitlab4j.version>
<guava.version>30.0-jre</guava.version>
<guice.version>4.2.1</guice.version>
<h2.version>1.4.200</h2.version>
Expand Down Expand Up @@ -543,6 +543,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.sdlc</groupId>
<artifactId>legend-sdlc-test-utils</artifactId>
<version>${project.version}</version>
</dependency>

<!-- External Legend dependencies -->
<dependency>
Expand All @@ -569,12 +574,12 @@
<groupId>org.finos.legend.pure</groupId>
<artifactId>legend-pure-code-compiled-core</artifactId>
<version>${legend.pure.version}</version>
<exclusions>
<exclusion>
<groupId>org.antlr</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
<exclusions>
<exclusion>
<groupId>org.antlr</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.finos.legend.pure</groupId>
Expand Down Expand Up @@ -844,6 +849,11 @@
<artifactId>jackson-dataformat-yaml</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
Expand Down
Loading

0 comments on commit a44bf9f

Please sign in to comment.