diff --git a/pom.xml b/pom.xml index e482291316bd7946154507e07ae94233705b12f2..c8afded4fdb966f323be43e6b137e85814f499a8 100644 --- a/pom.xml +++ b/pom.xml @@ -15,10 +15,10 @@ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id> - <quarkus.platform.version>3.8.3</quarkus.platform.version> + <quarkus.platform.version>3.8.6</quarkus.platform.version> <surefire-plugin.version>3.1.2</surefire-plugin.version> <maven.compiler.parameters>true</maven.compiler.parameters> - <eclipse-api-version>1.0.2</eclipse-api-version> + <eclipse-api-version>1.1.6</eclipse-api-version> <auto-value.version>1.10.4</auto-value.version> <org.mapstruct.version>1.5.5.Final</org.mapstruct.version> <sonar.sources>src/main</sonar.sources> diff --git a/src/main/java/org/eclipsefoundation/git/eca/api/GithubAPI.java b/src/main/java/org/eclipsefoundation/git/eca/api/GithubAPI.java index 644e65e5cf45a09a343d3679b40755c12550eeb4..ec77f9021627078cfe9ba499f54a099afdb66204 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/api/GithubAPI.java +++ b/src/main/java/org/eclipsefoundation/git/eca/api/GithubAPI.java @@ -11,6 +11,17 @@ */ package org.eclipsefoundation.git.eca.api; +import java.util.List; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; +import org.eclipsefoundation.core.service.APIMiddleware.BaseAPIParameters; +import org.eclipsefoundation.git.eca.api.models.GithubAccessToken; +import org.eclipsefoundation.git.eca.api.models.GithubApplicationInstallationData; +import org.eclipsefoundation.git.eca.api.models.GithubCommit; +import org.eclipsefoundation.git.eca.api.models.GithubCommitStatusRequest; +import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.PullRequest; +import org.jboss.resteasy.reactive.RestResponse; + import jakarta.ws.rs.BeanParam; import jakarta.ws.rs.GET; import jakarta.ws.rs.HeaderParam; @@ -18,15 +29,9 @@ import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.HttpHeaders; import jakarta.ws.rs.core.Response; -import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; -import org.eclipsefoundation.core.service.APIMiddleware.BaseAPIParameters; -import org.eclipsefoundation.git.eca.api.models.GithubAccessToken; -import org.eclipsefoundation.git.eca.api.models.GithubCommitStatusRequest; -import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.PullRequest; -import org.jboss.resteasy.util.HttpHeaderNames; - /** * Bindings used by the webhook logic to retrieve data about the PR to be validated. * @@ -48,7 +53,7 @@ public interface GithubAPI { */ @GET @Path("repos/{repoFull}/pulls/{pullNumber}") - public PullRequest getPullRequest(@HeaderParam(HttpHeaderNames.AUTHORIZATION) String bearer, + public PullRequest getPullRequest(@HeaderParam(HttpHeaders.AUTHORIZATION) String bearer, @HeaderParam("X-GitHub-Api-Version") String apiVersion, @PathParam("repoFull") String repoFull, @PathParam("pullNumber") int pullNumber); @@ -63,13 +68,12 @@ public interface GithubAPI { */ @GET @Path("repos/{repoFull}/pulls/{pullNumber}/commits") - public Response getCommits(@HeaderParam(HttpHeaderNames.AUTHORIZATION) String bearer, + public RestResponse<List<GithubCommit>> getCommits(@HeaderParam(HttpHeaders.AUTHORIZATION) String bearer, @HeaderParam("X-GitHub-Api-Version") String apiVersion, @PathParam("repoFull") String repoFull, @PathParam("pullNumber") int pullNumber); /** - * Posts an update to the Github API, using an access token to update a given pull requests commit status, targeted - * using the head sha. + * Posts an update to the Github API, using an access token to update a given pull requests commit status, targeted using the head sha. * * @param bearer authorization header value, access token for application with access to repo * @param apiVersion the version of the GH API to target when making the request @@ -80,13 +84,13 @@ public interface GithubAPI { */ @POST @Path("repos/{repoFull}/statuses/{prHeadSha}") - public Response updateStatus(@HeaderParam(HttpHeaderNames.AUTHORIZATION) String bearer, + public Response updateStatus(@HeaderParam(HttpHeaders.AUTHORIZATION) String bearer, @HeaderParam("X-GitHub-Api-Version") String apiVersion, @PathParam("repoFull") String repoFull, @PathParam("prHeadSha") String prHeadSha, GithubCommitStatusRequest commitStatusUpdate); /** - * Requires a JWT bearer token for the application to retrieve installations for. Returns a list of installations for - * the given application. + * Requires a JWT bearer token for the application to retrieve installations for. Returns a list of installations for the given + * application. * * @param params the general params for requests, including pagination * @param bearer JWT bearer token for the target application @@ -94,7 +98,8 @@ public interface GithubAPI { */ @GET @Path("app/installations") - public Response getInstallations(@BeanParam BaseAPIParameters params, @HeaderParam(HttpHeaderNames.AUTHORIZATION) String bearer); + public RestResponse<List<GithubApplicationInstallationData>> getInstallations(@BeanParam BaseAPIParameters params, + @HeaderParam(HttpHeaders.AUTHORIZATION) String bearer); /** * Retrieves an access token for a specific installation, given the applications JWT bearer and the api version. @@ -106,7 +111,7 @@ public interface GithubAPI { */ @POST @Path("app/installations/{installationId}/access_tokens") - public GithubAccessToken getNewAccessToken(@HeaderParam(HttpHeaderNames.AUTHORIZATION) String bearer, + public GithubAccessToken getNewAccessToken(@HeaderParam(HttpHeaders.AUTHORIZATION) String bearer, @HeaderParam("X-GitHub-Api-Version") String apiVersion, @PathParam("installationId") String installationId); /** @@ -118,7 +123,6 @@ public interface GithubAPI { */ @GET @Path("installation/repositories") - public Response getInstallationRepositories(@BeanParam BaseAPIParameters params, - @HeaderParam(HttpHeaderNames.AUTHORIZATION) String bearer); + public Response getInstallationRepositories(@BeanParam BaseAPIParameters params, @HeaderParam(HttpHeaders.AUTHORIZATION) String bearer); } diff --git a/src/main/java/org/eclipsefoundation/git/eca/api/GitlabAPI.java b/src/main/java/org/eclipsefoundation/git/eca/api/GitlabAPI.java index 60e600d790ae170206b5935f01897ee469964674..db46bb830b3580a8e7fd08463c24fc675cbc968d 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/api/GitlabAPI.java +++ b/src/main/java/org/eclipsefoundation/git/eca/api/GitlabAPI.java @@ -11,6 +11,14 @@ **********************************************************************/ package org.eclipsefoundation.git.eca.api; +import java.util.List; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; +import org.eclipsefoundation.core.service.APIMiddleware.BaseAPIParameters; +import org.eclipsefoundation.git.eca.api.models.GitlabProjectResponse; +import org.eclipsefoundation.git.eca.api.models.GitlabUserResponse; +import org.jboss.resteasy.reactive.RestResponse; + import jakarta.enterprise.context.ApplicationScoped; import jakarta.ws.rs.BeanParam; import jakarta.ws.rs.GET; @@ -18,12 +26,6 @@ import jakarta.ws.rs.HeaderParam; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.QueryParam; -import jakarta.ws.rs.core.Response; - -import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; -import org.eclipsefoundation.core.service.APIMiddleware.BaseAPIParameters; -import org.eclipsefoundation.git.eca.api.models.GitlabProjectResponse; -import org.eclipsefoundation.git.eca.api.models.GitlabUserResponse; /** * Interface for interacting with the GitLab API. Used to fetch project data. @@ -33,40 +35,36 @@ import org.eclipsefoundation.git.eca.api.models.GitlabUserResponse; public interface GitlabAPI { /** - * Fetches data for a project using the projectId. The id and a token of - * adequate permissions is required. + * Fetches data for a project using the projectId. The id and a token of adequate permissions is required. * * @param privateToken the header token - * @param projectId the project id + * @param projectId the project id * @return A GitlabProjectResponse object */ @GET @Path("/projects/{id}") - GitlabProjectResponse getProjectInfo(@HeaderParam("PRIVATE-TOKEN") String privateToken, - @PathParam("id") int projectId); + GitlabProjectResponse getProjectInfo(@HeaderParam("PRIVATE-TOKEN") String privateToken, @PathParam("id") int projectId); /** - * Fetches data for private projects. A token of adequate permissions is - * required. Visibility should be set to "private" and per_page should be set to - * 100 to minimize API calls. + * Fetches data for private projects. A token of adequate permissions is required. Visibility should be set to "private" and per_page + * should be set to 100 to minimize API calls. * * @param privateToken the header token - * @param visibility the project visibility - * @param perPage the number of results per page + * @param visibility the project visibility + * @param perPage the number of results per page * @return A Response containing a private project list */ @GET @Path("/projects") - Response getPrivateProjects(@BeanParam BaseAPIParameters baseParams, + RestResponse<List<GitlabProjectResponse>> getPrivateProjects(@BeanParam BaseAPIParameters baseParams, @HeaderParam("PRIVATE-TOKEN") String privateToken, @QueryParam("visibility") String visibility, @QueryParam("per_page") Integer perPage); /** - * Fetches data for a user using the userId. The id and a token of - * adequate permissions is required. + * Fetches data for a user using the userId. The id and a token of adequate permissions is required. * * @param privateToken the header token - * @param userId the project id + * @param userId the project id * @returnA A GitlabUserResponse object */ @GET diff --git a/src/main/java/org/eclipsefoundation/git/eca/config/ECAParallelProcessingConfig.java b/src/main/java/org/eclipsefoundation/git/eca/config/ECAParallelProcessingConfig.java index 514eca3b4eb18cb3046f6200e112c1bfc1309584..b510a8c2ca0d11971c466f6b80f2669defe26996 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/config/ECAParallelProcessingConfig.java +++ b/src/main/java/org/eclipsefoundation/git/eca/config/ECAParallelProcessingConfig.java @@ -14,8 +14,6 @@ package org.eclipsefoundation.git.eca.config; import io.smallrye.config.ConfigMapping; import io.smallrye.config.WithDefault; -import jakarta.validation.constraints.Max; -import jakarta.validation.constraints.Min; /** * @@ -26,8 +24,6 @@ public interface ECAParallelProcessingConfig { @WithDefault("false") boolean enabled(); - @Min(2) - @Max(10) @WithDefault("3") int threadsPerValidation(); } diff --git a/src/main/java/org/eclipsefoundation/git/eca/helper/CommitHelper.java b/src/main/java/org/eclipsefoundation/git/eca/helper/CommitHelper.java index 1d4693ba098ceda726bfa23ff13f96ea14201836..1a514cc91412fccb73009e47ef59c9fe3d706162 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/helper/CommitHelper.java +++ b/src/main/java/org/eclipsefoundation/git/eca/helper/CommitHelper.java @@ -15,14 +15,14 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.List; +import org.bouncycastle.util.encoders.Hex; import org.eclipsefoundation.efservices.api.models.Project; import org.eclipsefoundation.git.eca.model.Commit; import org.eclipsefoundation.git.eca.model.ValidationRequest; import org.eclipsefoundation.git.eca.namespace.GitEcaParameterNames; import org.eclipsefoundation.http.exception.ApplicationException; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; -import io.undertow.util.HexConverter; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; /** @@ -66,7 +66,7 @@ public class CommitHelper { } public static MultivaluedMap<String, String> getCommitParams(List<String> commitShas, String projectId, String repoUrl) { - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.put(GitEcaParameterNames.SHAS_RAW, commitShas); params.add(GitEcaParameterNames.REPO_URL_RAW, repoUrl); if (projectId != null) { @@ -87,7 +87,7 @@ public class CommitHelper { sb.append(req.getRepoUrl()); req.getCommits().forEach(c -> sb.append(c.getHash())); try { - return HexConverter.convertToHexString(MessageDigest.getInstance("MD5").digest(sb.toString().getBytes())); + return Hex.toHexString(MessageDigest.getInstance("MD5").digest(sb.toString().getBytes())); } catch (NoSuchAlgorithmException e) { throw new ApplicationException("Error while encoding request fingerprint - couldn't find MD5 algorithm.", e); } diff --git a/src/main/java/org/eclipsefoundation/git/eca/helper/GithubValidationHelper.java b/src/main/java/org/eclipsefoundation/git/eca/helper/GithubValidationHelper.java index 3634834f45d054c1c80fdb6d908dd8e0b7ebbe82..5d8992d6311c63ea9eb32b5f8efee4601a14f4b6 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/helper/GithubValidationHelper.java +++ b/src/main/java/org/eclipsefoundation/git/eca/helper/GithubValidationHelper.java @@ -19,7 +19,6 @@ import java.util.Optional; import java.util.function.Supplier; import org.apache.commons.lang3.StringUtils; -import org.apache.http.HttpStatus; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.eclipse.microprofile.rest.client.inject.RestClient; import org.eclipsefoundation.core.service.APIMiddleware; @@ -48,7 +47,6 @@ import org.eclipsefoundation.persistence.model.RDBMSQuery; import org.eclipsefoundation.persistence.service.FilterService; import org.eclipsefoundation.utils.helper.DateTimeHelper; import org.eclipsefoundation.utils.helper.TransformationHelper; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,7 +55,9 @@ import jakarta.inject.Inject; import jakarta.ws.rs.BadRequestException; import jakarta.ws.rs.NotFoundException; import jakarta.ws.rs.ServerErrorException; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; +import jakarta.ws.rs.core.Response; /** * This class is used to adapt Github requests to the standard validation workflow in a way that could be reused by both resource calls and @@ -135,7 +135,7 @@ public class GithubValidationHelper { prResponse.get()); if (updatedTracking == null) { throw new ServerErrorException("Error while attempting to revalidate request, try again later.", - HttpStatus.SC_INTERNAL_SERVER_ERROR); + Response.Status.INTERNAL_SERVER_ERROR); } // get the commit status of commits to use for checking historic validation @@ -173,8 +173,7 @@ public class GithubValidationHelper { // get the commits that will be validated, don't cache as changes can come in too fast for it to be useful List<GithubCommit> commits = middleware .getAll(i -> ghApi - .getCommits(jwtHelper.getGhBearerString(installationId), apiVersion, repositoryFullName, pullRequestNumber), - GithubCommit.class); + .getCommits(jwtHelper.getGhBearerString(installationId), apiVersion, repositoryFullName, pullRequestNumber)); if (LOGGER.isTraceEnabled()) { LOGGER .trace("Retrieved {} commits for PR {} in repo {}", commits.size(), pullRequestNumber, @@ -339,7 +338,7 @@ public class GithubValidationHelper { public Optional<GithubWebhookTracking> getExistingRequestInformation(RequestWrapper wrapper, String installationId, String repositoryFullName, int pullRequestNumber) { checkRequestParameters(installationId, repositoryFullName, pullRequestNumber); - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.INSTALLATION_ID_RAW, installationId); params.add(GitEcaParameterNames.REPOSITORY_FULL_NAME_RAW, repositoryFullName); params.add(GitEcaParameterNames.PULL_REQUEST_NUMBER_RAW, Integer.toString(pullRequestNumber)); diff --git a/src/main/java/org/eclipsefoundation/git/eca/helper/ProjectHelper.java b/src/main/java/org/eclipsefoundation/git/eca/helper/ProjectHelper.java index 263d3d1193bdcc3cbe409ab26754a2aeefa305a5..1c6e0aa22614538a2fe1b584f871961e90039893 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/helper/ProjectHelper.java +++ b/src/main/java/org/eclipsefoundation/git/eca/helper/ProjectHelper.java @@ -26,12 +26,12 @@ import org.eclipsefoundation.efservices.api.models.Project.ProjectParticipant; import org.eclipsefoundation.efservices.services.ProjectService; import org.eclipsefoundation.git.eca.model.ValidationRequest; import org.eclipsefoundation.git.eca.namespace.ProviderType; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +import jakarta.ws.rs.core.MultivaluedHashMap; /** * Helps manage projects by providing filters on top of the generic service as well as operations like adapting interest groups to projects @@ -106,7 +106,7 @@ public final class ProjectHelper { * @return list of available projects or empty list if none found. */ public List<Project> getProjects() { - return cache.get("all-combined", new MultivaluedMapImpl<>(), Project.class, () -> { + return cache.get("all-combined", new MultivaluedHashMap<>(), Project.class, () -> { List<Project> availableProjects = projects.getAllProjects(); availableProjects.addAll(adaptInterestGroups(projects.getAllInterestGroups())); return availableProjects; diff --git a/src/main/java/org/eclipsefoundation/git/eca/resource/GithubWebhooksResource.java b/src/main/java/org/eclipsefoundation/git/eca/resource/GithubWebhooksResource.java index ccfa078e6795cb6e70669b443d586708b168866b..33c519f60ec77010874210d96d25938fa9493eef 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/resource/GithubWebhooksResource.java +++ b/src/main/java/org/eclipsefoundation/git/eca/resource/GithubWebhooksResource.java @@ -15,7 +15,6 @@ import java.net.URI; import java.util.List; import java.util.Optional; -import org.apache.http.HttpStatus; import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest; import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.PullRequest; import org.eclipsefoundation.git.eca.dto.GithubWebhookTracking; @@ -28,7 +27,6 @@ import org.eclipsefoundation.git.eca.namespace.HCaptchaErrorCodes; import org.eclipsefoundation.git.eca.namespace.WebhookHeaders; import org.eclipsefoundation.git.eca.service.GithubApplicationService; import org.eclipsefoundation.utils.helper.TransformationHelper; -import org.jboss.resteasy.annotations.jaxrs.HeaderParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,6 +34,7 @@ import jakarta.inject.Inject; import jakarta.ws.rs.BadRequestException; import jakarta.ws.rs.FormParam; import jakarta.ws.rs.GET; +import jakarta.ws.rs.HeaderParam; import jakarta.ws.rs.NotFoundException; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; @@ -148,7 +147,7 @@ public class GithubWebhooksResource extends CommonResource { if (tracking == null) { throw new ServerErrorException(String .format("Cannot find a tracked pull request with for repo '%s', pull request number '%d'", sanitizedRepoName, prNo), - HttpStatus.SC_INTERNAL_SERVER_ERROR); + Status.INTERNAL_SERVER_ERROR); } else if (!"open".equalsIgnoreCase(tracking.getLastKnownState())) { // we do not want to reprocess non-open pull requests throw new BadRequestException("Cannot revalidate a non-open pull request"); @@ -187,7 +186,7 @@ public class GithubWebhooksResource extends CommonResource { return Response.ok(RevalidationResponse.builder().setLocation(URI.create(sb.toString())).build()).build(); } catch (Exception e) { // rewrap exception, as some of the Github stuff can fail w/o explanation - throw new ServerErrorException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e); + throw new ServerErrorException(Status.INTERNAL_SERVER_ERROR, e); } } diff --git a/src/main/java/org/eclipsefoundation/git/eca/resource/StatusResource.java b/src/main/java/org/eclipsefoundation/git/eca/resource/StatusResource.java index 0a95623ebf8f157bb0afe6b93889d2458cd84c2d..65040e11703e20bf77974172977a6270240f5a26 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/resource/StatusResource.java +++ b/src/main/java/org/eclipsefoundation/git/eca/resource/StatusResource.java @@ -26,7 +26,6 @@ import org.eclipsefoundation.git.eca.namespace.ProviderType; import org.eclipsefoundation.git.eca.service.GithubApplicationService; import org.eclipsefoundation.git.eca.service.ValidationService; import org.eclipsefoundation.git.eca.service.ValidationStatusService; -import org.jboss.resteasy.client.exception.ResteasyWebApplicationException; import io.quarkus.qute.Location; import io.quarkus.qute.Template; @@ -37,6 +36,7 @@ import jakarta.ws.rs.NotFoundException; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.UriInfo; @@ -216,7 +216,7 @@ public class StatusResource extends CommonResource { .data(INCLUDE_INSTALL_LINK_PARAMETER, false) .render()) .build(); - } catch (NotFoundException | ResteasyWebApplicationException e) { + } catch (WebApplicationException e) { return Response .ok() .entity(errorTemplate diff --git a/src/main/java/org/eclipsefoundation/git/eca/resource/ValidationResource.java b/src/main/java/org/eclipsefoundation/git/eca/resource/ValidationResource.java index cc5be71f5ac31e7c95991d05081ee07089885bdf..8695bcf4ac15fa5abf24bc4088b28b67ae5bb857 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/resource/ValidationResource.java +++ b/src/main/java/org/eclipsefoundation/git/eca/resource/ValidationResource.java @@ -27,7 +27,6 @@ import org.eclipsefoundation.git.eca.namespace.APIStatusCode; import org.eclipsefoundation.git.eca.service.ValidationService; import org.eclipsefoundation.utils.exception.FinalForbiddenException; import org.eclipsefoundation.utils.helper.TransformationHelper; -import org.jboss.resteasy.annotations.jaxrs.QueryParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,6 +38,7 @@ import jakarta.ws.rs.NotFoundException; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; diff --git a/src/main/java/org/eclipsefoundation/git/eca/resource/WebhooksResource.java b/src/main/java/org/eclipsefoundation/git/eca/resource/WebhooksResource.java index a53f253fe6d4ea35e8a4b39f22e7fbb95cc403a9..cc214b35c6a7b425756135a4b0629162e4762353 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/resource/WebhooksResource.java +++ b/src/main/java/org/eclipsefoundation/git/eca/resource/WebhooksResource.java @@ -16,7 +16,6 @@ import org.eclipsefoundation.git.eca.namespace.EventType; import org.eclipsefoundation.git.eca.namespace.WebhookHeaders; import org.eclipsefoundation.git.eca.service.SystemHookService; import org.eclipsefoundation.http.model.RequestWrapper; -import org.jboss.resteasy.annotations.jaxrs.HeaderParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,6 +23,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.inject.Inject; +import jakarta.ws.rs.HeaderParam; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.core.Response; diff --git a/src/main/java/org/eclipsefoundation/git/eca/service/impl/CachedUserService.java b/src/main/java/org/eclipsefoundation/git/eca/service/impl/CachedUserService.java index 5fae962459e7fe615b8eb58d2a5e4bece72c4b90..cfb9bfd7b18b3b4e12528a1ef5da77666016eadf 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/service/impl/CachedUserService.java +++ b/src/main/java/org/eclipsefoundation/git/eca/service/impl/CachedUserService.java @@ -29,7 +29,6 @@ import org.eclipsefoundation.efservices.services.ProfileService; import org.eclipsefoundation.git.eca.api.BotsAPI; import org.eclipsefoundation.git.eca.config.MailValidationConfig; import org.eclipsefoundation.git.eca.service.UserService; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,6 +38,7 @@ import jakarta.annotation.PostConstruct; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.ws.rs.WebApplicationException; +import jakarta.ws.rs.core.MultivaluedHashMap; /** * Wrapped cached and authenticated access to user objects. @@ -76,7 +76,7 @@ public class CachedUserService implements UserService { if (StringUtils.isBlank(mail)) { return null; } - CacheWrapper<EfUser> result = cache.get(mail, new MultivaluedMapImpl<>(), EfUser.class, () -> retrieveUser(mail)); + CacheWrapper<EfUser> result = cache.get(mail, new MultivaluedHashMap<>(), EfUser.class, () -> retrieveUser(mail)); Optional<EfUser> user = result.getData(); if (user.isPresent()) { LOGGER.debug("Found user with email {}", mail); @@ -155,7 +155,7 @@ public class CachedUserService implements UserService { // standard user check (returns best match) LOGGER.debug("Checking user with mail {}", mail); try { - Optional<EfUser> user = profile.performUserSearch(UserSearchParams.builder().setMail(mail).build()); + Optional<EfUser> user = profile.performUserSearch(new UserSearchParams(null, null, mail)); if (user.isPresent()) { return user.get(); } @@ -250,7 +250,7 @@ public class CachedUserService implements UserService { private List<JsonNode> getBots() { return cache - .get("allBots", new MultivaluedMapImpl<>(), JsonNode.class, () -> bots.getBots()) + .get("allBots", new MultivaluedHashMap<>(), JsonNode.class, () -> bots.getBots()) .getData() .orElse(Collections.emptyList()); } diff --git a/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultGithubApplicationService.java b/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultGithubApplicationService.java index 82ae77563e6a2113a9e0385d14d5fcb5b74a375d..d0603fc5794f6cb816f9a72026c91aab04130402 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultGithubApplicationService.java +++ b/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultGithubApplicationService.java @@ -37,7 +37,6 @@ import org.eclipsefoundation.http.model.RequestWrapper; import org.eclipsefoundation.persistence.dao.PersistenceDao; import org.eclipsefoundation.persistence.model.RDBMSQuery; import org.eclipsefoundation.persistence.service.FilterService; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,6 +46,7 @@ import com.github.benmanes.caffeine.cache.Caffeine; import jakarta.annotation.PostConstruct; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; /** @@ -118,7 +118,7 @@ public class DefaultGithubApplicationService implements GithubApplicationService @Override public Optional<PullRequest> getPullRequest(String installationId, String repoFullName, Integer pullRequest) { return cache - .get(repoFullName, new MultivaluedMapImpl<>(), PullRequest.class, + .get(repoFullName, new MultivaluedHashMap<>(), PullRequest.class, () -> gh.getPullRequest(jwt.getGhBearerString(installationId), apiVersion, repoFullName, pullRequest)) .getData(); } @@ -148,7 +148,7 @@ public class DefaultGithubApplicationService implements GithubApplicationService RequestWrapper wrap = new FlatRequestWrapper(URI.create("https://api.eclipse.org/git/webhooks/github/installations")); // build query to do fetch of records for currently active application - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.APPLICATION_ID_RAW, Integer.toString(config.github().appId())); // we don't want to use the limit, as we want to pull all of the records we can find diff --git a/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultReportsService.java b/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultReportsService.java index fef0c3c52cc2fa2bbb05d6ef3e7f6ab9aef8dd9f..eb0f5beac5002d4dd0c41e68fd3d603e98c8ccc7 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultReportsService.java +++ b/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultReportsService.java @@ -25,12 +25,12 @@ import org.eclipsefoundation.http.model.RequestWrapper; import org.eclipsefoundation.persistence.dao.PersistenceDao; import org.eclipsefoundation.persistence.model.RDBMSQuery; import org.eclipsefoundation.persistence.service.FilterService; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; @ApplicationScoped @@ -50,7 +50,7 @@ public class DefaultReportsService implements ReportsService { public List<PrivateProjectData> getPrivateProjectEvents(RequestWrapper wrap, String status, LocalDate since, LocalDate until) { - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); if (StringUtils.isNotBlank(status)) { if (status.equalsIgnoreCase(GitEcaParameterNames.STATUS_ACTIVE.getName())) { diff --git a/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultSystemHookService.java b/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultSystemHookService.java index 9dc585a263e79def4f0db3c14069eda30f023656..eb24c5dba511ca143f2bde96fb29fd685030f929 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultSystemHookService.java +++ b/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultSystemHookService.java @@ -34,7 +34,6 @@ import org.eclipsefoundation.http.model.RequestWrapper; import org.eclipsefoundation.persistence.dao.PersistenceDao; import org.eclipsefoundation.persistence.model.RDBMSQuery; import org.eclipsefoundation.persistence.service.FilterService; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,6 +43,7 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.control.ActivateRequestContext; import jakarta.inject.Inject; import jakarta.transaction.Transactional; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; @ApplicationScoped @@ -117,7 +117,7 @@ public class DefaultSystemHookService implements SystemHookService { LOGGER.debug("Tracking creation of project: [id: {}, path: {}]", hook.getProjectId(), hook.getPathWithNamespace()); CacheWrapper<GitlabProjectResponse> response = cache - .get(Integer.toString(hook.getProjectId()), new MultivaluedMapImpl<>(), GitlabProjectResponse.class, + .get(Integer.toString(hook.getProjectId()), new MultivaluedHashMap<>(), GitlabProjectResponse.class, () -> api.getProjectInfo(apiToken, hook.getProjectId())); if (response.getData().isPresent()) { @@ -144,7 +144,7 @@ public class DefaultSystemHookService implements SystemHookService { try { LOGGER.debug("Tracking deletion of project: [id: {}, path: {}]", hook.getProjectId(), hook.getPathWithNamespace()); - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.PROJECT_ID.getName(), Integer.toString(hook.getProjectId())); params.add(GitEcaParameterNames.PROJECT_PATH.getName(), hook.getPathWithNamespace()); @@ -173,7 +173,7 @@ public class DefaultSystemHookService implements SystemHookService { try { LOGGER.debug("Tracking renaming of project: [id: {}, path: {}]", hook.getProjectId(), hook.getOldPathWithNamespace()); - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.PROJECT_ID.getName(), Integer.toString(hook.getProjectId())); params.add(GitEcaParameterNames.PROJECT_PATH.getName(), hook.getOldPathWithNamespace()); @@ -229,7 +229,7 @@ public class DefaultSystemHookService implements SystemHookService { */ private String fetchUserName(Integer userId) { Optional<GitlabUserResponse> response = cache - .get(Integer.toString(userId), new MultivaluedMapImpl<>(), GitlabUserResponse.class, + .get(Integer.toString(userId), new MultivaluedHashMap<>(), GitlabUserResponse.class, () -> api.getUserInfo(apiToken, userId)) .getData(); return response.isPresent() ? response.get().getUsername() : null; diff --git a/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationStatusService.java b/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationStatusService.java index 2329dc2ad715eaeed65c6b5cac94d991e2773957..00d19252fd348e5cd08cd5edccaa38369290b89b 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationStatusService.java +++ b/src/main/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationStatusService.java @@ -38,12 +38,12 @@ import org.eclipsefoundation.persistence.dao.PersistenceDao; import org.eclipsefoundation.persistence.model.RDBMSQuery; import org.eclipsefoundation.persistence.service.FilterService; import org.eclipsefoundation.utils.helper.DateTimeHelper; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; /** @@ -63,7 +63,7 @@ public class DefaultValidationStatusService implements ValidationStatusService { if (StringUtils.isAllBlank(fingerprint)) { return Collections.emptyList(); } - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.FINGERPRINT_RAW, fingerprint); RDBMSQuery<CommitValidationStatus> q = new RDBMSQuery<>(wrapper, filters.get(CommitValidationStatus.class), params); // set use limit to false to collect all data in one request @@ -76,7 +76,7 @@ public class DefaultValidationStatusService implements ValidationStatusService { if (shas == null || shas.isEmpty()) { return Collections.emptyList(); } - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.put(GitEcaParameterNames.SHAS_RAW, shas); RDBMSQuery<CommitValidationStatus> q = new RDBMSQuery<>(wrapper, filters.get(CommitValidationStatus.class), params); // set use limit to false to collect all data in one request @@ -203,7 +203,7 @@ public class DefaultValidationStatusService implements ValidationStatusService { return status.get(); } else { // lookup the existing status to prevent issues with near parallel requests/duplicate commit data - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.SHAS_RAW, c.getHash()); params.add(GitEcaParameterNames.REPO_URL_RAW, req.getRepoUrl().toString()); List<CommitValidationStatus> existingStatus = dao diff --git a/src/main/java/org/eclipsefoundation/git/eca/tasks/GithubInstallationUpdateTask.java b/src/main/java/org/eclipsefoundation/git/eca/tasks/GithubInstallationUpdateTask.java index 0a6cda1462f1b127ddc2fe74d95038d85e345ff3..5b24ae85a00893e52c5458aaddbdd57bab0340b2 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/tasks/GithubInstallationUpdateTask.java +++ b/src/main/java/org/eclipsefoundation/git/eca/tasks/GithubInstallationUpdateTask.java @@ -15,7 +15,7 @@ import java.net.URI; import java.util.Date; import java.util.List; -import org.apache.maven.shared.utils.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.eclipse.microprofile.rest.client.inject.RestClient; import org.eclipsefoundation.core.service.APIMiddleware; @@ -31,7 +31,6 @@ import org.eclipsefoundation.persistence.dao.PersistenceDao; import org.eclipsefoundation.persistence.model.RDBMSQuery; import org.eclipsefoundation.persistence.service.FilterService; import org.eclipsefoundation.utils.helper.DateTimeHelper; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,6 +40,7 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.control.ActivateRequestContext; import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; /** @@ -89,7 +89,7 @@ public class GithubInstallationUpdateTask { // get the installations for the currently configured app List<GithubApplicationInstallationData> installations = middle - .getAll(i -> gh.getInstallations(i, "Bearer " + jwt.generateJwt()), GithubApplicationInstallationData.class); + .getAll(i -> gh.getInstallations(i, "Bearer " + jwt.generateJwt())); // check that there are installations if (installations.isEmpty()) { LOGGER.warn("Did not find any installations for the currently configured Github application"); @@ -116,7 +116,7 @@ public class GithubInstallationUpdateTask { } // build query to do cleanup of stale records - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.APPLICATION_ID_RAW, Integer.toString(config.github().appId())); params.add(GitEcaParameterNames.LAST_UPDATED_BEFORE_RAW, DateTimeHelper.toRFC3339(startingTimestamp)); @@ -134,7 +134,7 @@ public class GithubInstallationUpdateTask { private GithubApplicationInstallation processInstallation(GithubApplicationInstallationData ghInstallation) { RequestWrapper wrap = new FlatRequestWrapper(URI.create("https://api.eclipse.org/git/webhooks/github/installations")); // build the lookup query for the current installation record - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.APPLICATION_ID_RAW, Integer.toString(config.github().appId())); params.add(GitEcaParameterNames.INSTALLATION_ID_RAW, Integer.toString(ghInstallation.getId())); diff --git a/src/main/java/org/eclipsefoundation/git/eca/tasks/GithubRevalidationQueue.java b/src/main/java/org/eclipsefoundation/git/eca/tasks/GithubRevalidationQueue.java index af73d060dc0672f9ade27bb3a3b6771ead5227cf..35bddfdf45b0b842362ad2a0cc9bdd82fdc7b7d8 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/tasks/GithubRevalidationQueue.java +++ b/src/main/java/org/eclipsefoundation/git/eca/tasks/GithubRevalidationQueue.java @@ -27,7 +27,6 @@ import org.eclipsefoundation.persistence.model.RDBMSQuery; import org.eclipsefoundation.persistence.namespace.PersistenceUrlParameterNames; import org.eclipsefoundation.persistence.service.FilterService; import org.eclipsefoundation.utils.helper.DateTimeHelper; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,6 +36,7 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.control.ActivateRequestContext; import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; /** @@ -83,7 +83,7 @@ public class GithubRevalidationQueue { } // set up params for looking up the top of the revalidation queue - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.NEEDS_REVALIDATION_RAW, "true"); params.add(PersistenceUrlParameterNames.SORT.getName(), "lastUpdated"); params.add(DefaultUrlParameterNames.PAGESIZE.getName(), "1"); diff --git a/src/main/java/org/eclipsefoundation/git/eca/tasks/ScheduledPrivateProjectScanTask.java b/src/main/java/org/eclipsefoundation/git/eca/tasks/ScheduledPrivateProjectScanTask.java index f5f1d73b80011dd312c096f0329078efa34607a1..29ce5b87f18a8c13d5c239433bb076bd68f438ba 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/tasks/ScheduledPrivateProjectScanTask.java +++ b/src/main/java/org/eclipsefoundation/git/eca/tasks/ScheduledPrivateProjectScanTask.java @@ -30,7 +30,6 @@ import org.eclipsefoundation.http.model.RequestWrapper; import org.eclipsefoundation.persistence.dao.impl.DefaultHibernateDao; import org.eclipsefoundation.persistence.model.RDBMSQuery; import org.eclipsefoundation.persistence.service.FilterService; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,6 +39,7 @@ import io.quarkus.scheduler.Scheduled; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; @ApplicationScoped @@ -69,10 +69,8 @@ public class ScheduledPrivateProjectScanTask { // Fetch all private projects from GL, while paginating results Optional<List<GitlabProjectResponse>> response = cache - .get("all", new MultivaluedMapImpl<>(), GitlabProjectResponse.class, - () -> middleware - .getAll(p -> api.getPrivateProjects(p, apiToken, "private", PRIVATE_PROJECT_PAGE_SIZE), - GitlabProjectResponse.class)) + .get("all", new MultivaluedHashMap<>(), GitlabProjectResponse.class, + () -> middleware.getAll(p -> api.getPrivateProjects(p, apiToken, "private", PRIVATE_PROJECT_PAGE_SIZE))) .getData(); response.ifPresent(this::processGitlabResponseList); @@ -80,8 +78,7 @@ public class ScheduledPrivateProjectScanTask { } /** - * Processes the list of gitlab project response objects and updates the missed deletion, creation, and rename events in - * the DB + * Processes the list of gitlab project response objects and updates the missed deletion, creation, and rename events in the DB * * @param projectList the list of private projects to process */ @@ -108,7 +105,7 @@ public class ScheduledPrivateProjectScanTask { RequestWrapper wrapper = new FlatRequestWrapper(URI.create("https://api.eclipse.org")); // Ad ids to be reverse searched against - MultivaluedMap<String, String> excludingParams = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> excludingParams = new MultivaluedHashMap<>(); excludingParams .put(GitEcaParameterNames.NOT_IN_PROJECT_IDS.getName(), projectList.stream().map(p -> Integer.toString(p.getId())).toList()); @@ -135,10 +132,9 @@ public class ScheduledPrivateProjectScanTask { FilterService filters) { RequestWrapper wrapper = new FlatRequestWrapper(URI.create("https://api.eclipse.org")); - MultivaluedMap<String, String> includingParams = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> includingParams = new MultivaluedHashMap<>(); includingParams - .put(GitEcaParameterNames.PROJECT_IDS.getName(), - projectList.stream().map(p -> Integer.toString(p.getId())).toList()); + .put(GitEcaParameterNames.PROJECT_IDS.getName(), projectList.stream().map(p -> Integer.toString(p.getId())).toList()); // Get by id since project ids never change List<PrivateProjectEvent> results = dao.get(new RDBMSQuery<>(wrapper, filters.get(PrivateProjectEvent.class), includingParams)); @@ -201,7 +197,7 @@ public class ScheduledPrivateProjectScanTask { */ private String fetchUserName(Integer userId) { Optional<GitlabUserResponse> response = cache - .get(Integer.toString(userId), new MultivaluedMapImpl<>(), GitlabUserResponse.class, + .get(Integer.toString(userId), new MultivaluedHashMap<>(), GitlabUserResponse.class, () -> api.getUserInfo(apiToken, userId)) .getData(); return response.isPresent() ? response.get().getUsername() : null; diff --git a/src/test/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationServiceTest.java b/src/test/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationServiceTest.java index 7be8a66a4ab119b6a0cbf795282290b7c2fb1982..6e43af89f46b85dd51464a9f680ca25cc0015a68 100644 --- a/src/test/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationServiceTest.java +++ b/src/test/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationServiceTest.java @@ -19,12 +19,12 @@ import org.eclipsefoundation.persistence.dao.PersistenceDao; import org.eclipsefoundation.persistence.model.RDBMSQuery; import org.eclipsefoundation.persistence.service.FilterService; import org.eclipsefoundation.utils.helper.DateTimeHelper; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import io.quarkus.test.junit.QuarkusTest; import jakarta.inject.Inject; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; @QuarkusTest @@ -49,7 +49,7 @@ class DefaultValidationServiceTest { String errorCommitHash = "duplicate-message-err-02"; RequestWrapper wrap = new FlatRequestWrapper(URI.create("https://api.eclipse.org/git/eca/test")); - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.SHAS_RAW, errorCommitHash); // check that there are multiple messages on the commit List<CommitValidationStatus> statuses = dao.get(new RDBMSQuery<>(wrap, filters.get(CommitValidationStatus.class), params)); diff --git a/src/test/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationStatusServiceTest.java b/src/test/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationStatusServiceTest.java index 1fa8ad4cda0ffa9c29975c62c4394d046149150a..93a09b85b63282df06528c32879db37e79841be1 100644 --- a/src/test/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationStatusServiceTest.java +++ b/src/test/java/org/eclipsefoundation/git/eca/service/impl/DefaultValidationStatusServiceTest.java @@ -29,12 +29,12 @@ import org.eclipsefoundation.http.model.RequestWrapper; import org.eclipsefoundation.persistence.dao.PersistenceDao; import org.eclipsefoundation.persistence.model.RDBMSQuery; import org.eclipsefoundation.persistence.service.FilterService; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import io.quarkus.test.junit.QuarkusTest; import jakarta.inject.Inject; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; @QuarkusTest @@ -77,7 +77,7 @@ class DefaultValidationStatusServiceTest { // check the raw dao against results String errorCommitHash = "deduplicate-message-test-01"; - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.SHAS_RAW, errorCommitHash); // check that there are multiple messages on the commit List<CommitValidationStatus> statuses = dao.get(new RDBMSQuery<>(wrap, filters.get(CommitValidationStatus.class), params)); @@ -154,7 +154,7 @@ class DefaultValidationStatusServiceTest { // check the raw dao against results String errorCommitHash = "deduplicate-message-test-01"; - MultivaluedMap<String, String> params = new MultivaluedMapImpl<>(); + MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); params.add(GitEcaParameterNames.SHAS_RAW, errorCommitHash); // check that there are multiple messages on the commit List<CommitValidationStatus> statuses = dao.get(new RDBMSQuery<>(wrap, filters.get(CommitValidationStatus.class), params)); diff --git a/src/test/java/org/eclipsefoundation/git/eca/test/api/MockAccountsAPI.java b/src/test/java/org/eclipsefoundation/git/eca/test/api/MockAccountsAPI.java index 7e233c43908ab64794d211fa4d8ace737d1fe994..b0a0ec97005a0edcb1c28ae0162b918fb9cf0ffc 100644 --- a/src/test/java/org/eclipsefoundation/git/eca/test/api/MockAccountsAPI.java +++ b/src/test/java/org/eclipsefoundation/git/eca/test/api/MockAccountsAPI.java @@ -209,9 +209,9 @@ public class MockAccountsAPI implements ProfileAPI { return users .values() .stream() - .filter(usernamePredicate(params.getName())) - .filter(u -> params.getMail() == null || u.getMail().equals(params.getMail())) - .filter(u -> params.getUid() == null || u.getUid().equals(params.getUid())) + .filter(usernamePredicate(params.name)) + .filter(u -> params.mail == null || u.getMail().equals(params.mail)) + .filter(u -> params.uid == null || u.getUid().equals(params.uid)) .toList(); } diff --git a/src/test/java/org/eclipsefoundation/git/eca/test/api/MockGithubAPI.java b/src/test/java/org/eclipsefoundation/git/eca/test/api/MockGithubAPI.java index 5ba3c8a9ba84b1653fd9c0c9d664f3342a9d9ef8..4afea1712c664d6b6bcce0bff426c2cd64b049b1 100644 --- a/src/test/java/org/eclipsefoundation/git/eca/test/api/MockGithubAPI.java +++ b/src/test/java/org/eclipsefoundation/git/eca/test/api/MockGithubAPI.java @@ -25,12 +25,14 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; import org.eclipsefoundation.core.service.APIMiddleware.BaseAPIParameters; import org.eclipsefoundation.git.eca.api.GithubAPI; import org.eclipsefoundation.git.eca.api.models.GithubAccessToken; +import org.eclipsefoundation.git.eca.api.models.GithubApplicationInstallationData; import org.eclipsefoundation.git.eca.api.models.GithubCommit; import org.eclipsefoundation.git.eca.api.models.GithubCommit.CommitData; import org.eclipsefoundation.git.eca.api.models.GithubCommit.GitCommitUser; import org.eclipsefoundation.git.eca.api.models.GithubCommit.GithubCommitUser; import org.eclipsefoundation.git.eca.api.models.GithubCommitStatusRequest; import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.PullRequest; +import org.jboss.resteasy.reactive.RestResponse; import io.quarkus.test.Mock; @@ -45,24 +47,30 @@ public class MockGithubAPI implements GithubAPI { public MockGithubAPI() { this.commitStatuses = new HashMap<>(); this.commits = new HashMap<>(); - this.commits.put("eclipsefdn/sample", - Map.of(42, - Arrays.asList(GithubCommit.builder() - .setSha("sha-1234") - .setAuthor(GithubCommitUser.builder().setLogin("testuser").build()) - .setCommitter(GithubCommitUser.builder().setLogin("testuser").build()) - .setParents(Collections.emptyList()) - .setCommit(CommitData.builder() - .setAuthor( - GitCommitUser.builder().setName("The Wizard") - .setEmail("code.wiz@important.co") + this.commits + .put("eclipsefdn/sample", + Map + .of(42, Arrays + .asList(GithubCommit + .builder() + .setSha("sha-1234") + .setAuthor(GithubCommitUser.builder().setLogin("testuser").build()) + .setCommitter(GithubCommitUser.builder().setLogin("testuser").build()) + .setParents(Collections.emptyList()) + .setCommit(CommitData + .builder() + .setAuthor(GitCommitUser + .builder() + .setName("The Wizard") + .setEmail("code.wiz@important.co") + .build()) + .setCommitter(GitCommitUser + .builder() + .setName("The Wizard") + .setEmail("code.wiz@important.co") + .build()) .build()) - .setCommitter( - GitCommitUser.builder().setName("The Wizard") - .setEmail("code.wiz@important.co") - .build()) - .build()) - .build()))); + .build()))); } @Override @@ -71,32 +79,29 @@ public class MockGithubAPI implements GithubAPI { } @Override - public Response getCommits(String bearer, String apiVersion, String repoFull, int pullNumber) { + public RestResponse<List<GithubCommit>> getCommits(String bearer, String apiVersion, String repoFull, int pullNumber) { List<GithubCommit> results = commits.get(repoFull).get(pullNumber); if (results == null || !results.isEmpty()) { - return Response.status(404).build(); + return RestResponse.status(404); } - return Response.ok(results).build(); + return RestResponse.ok(results); } @Override public Response updateStatus(String bearer, String apiVersion, String repoFull, String prHeadSha, GithubCommitStatusRequest commitStatusUpdate) { - commitStatuses.computeIfAbsent(repoFull, m -> new HashMap<>()).merge(prHeadSha, commitStatusUpdate.getState(), - (k, v) -> v); + commitStatuses.computeIfAbsent(repoFull, m -> new HashMap<>()).merge(prHeadSha, commitStatusUpdate.getState(), (k, v) -> v); return Response.ok().build(); } @Override - public Response getInstallations(BaseAPIParameters params, String bearer) { + public RestResponse<List<GithubApplicationInstallationData>> getInstallations(BaseAPIParameters params, String bearer) { throw new UnsupportedOperationException("Unimplemented method 'getInstallations'"); } @Override public GithubAccessToken getNewAccessToken(String bearer, String apiVersion, String installationId) { - return GithubAccessToken.builder() - .setToken("gh-token-" + installationId) - .setExpiresAt(LocalDateTime.now().plusHours(1L)).build(); + return GithubAccessToken.builder().setToken("gh-token-" + installationId).setExpiresAt(LocalDateTime.now().plusHours(1L)).build(); } @Override diff --git a/src/test/java/org/eclipsefoundation/git/eca/test/api/MockGitlabAPI.java b/src/test/java/org/eclipsefoundation/git/eca/test/api/MockGitlabAPI.java index a19adab07ff9e9d2d523ef8172166ff1624ceaad..178dad4cd25206072fc4c67ee3d30d117b3f2314 100644 --- a/src/test/java/org/eclipsefoundation/git/eca/test/api/MockGitlabAPI.java +++ b/src/test/java/org/eclipsefoundation/git/eca/test/api/MockGitlabAPI.java @@ -16,17 +16,16 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.ws.rs.core.Response; - import org.eclipse.microprofile.rest.client.inject.RestClient; import org.eclipsefoundation.core.service.APIMiddleware.BaseAPIParameters; import org.eclipsefoundation.git.eca.api.GitlabAPI; import org.eclipsefoundation.git.eca.api.models.GitlabProjectResponse; import org.eclipsefoundation.git.eca.api.models.GitlabProjectResponse.ForkedProject; import org.eclipsefoundation.git.eca.api.models.GitlabUserResponse; +import org.jboss.resteasy.reactive.RestResponse; import io.quarkus.test.Mock; +import jakarta.enterprise.context.ApplicationScoped; @Mock @RestClient @@ -82,9 +81,9 @@ public class MockGitlabAPI implements GitlabAPI { } @Override - public Response getPrivateProjects(BaseAPIParameters baseParams, String privateToken, String visibility, + public RestResponse<List<GitlabProjectResponse>> getPrivateProjects(BaseAPIParameters baseParams, String privateToken, String visibility, Integer perPage) { - return Response.ok().build(); + return RestResponse.ok(); } @Override diff --git a/src/test/java/org/eclipsefoundation/git/eca/test/api/MockProjectsAPI.java b/src/test/java/org/eclipsefoundation/git/eca/test/api/MockProjectsAPI.java index d971dd30cac258207827b7f837356bb77b3fc717..c2e73d2dc041b43ffe483173e4aea617a9a551b2 100644 --- a/src/test/java/org/eclipsefoundation/git/eca/test/api/MockProjectsAPI.java +++ b/src/test/java/org/eclipsefoundation/git/eca/test/api/MockProjectsAPI.java @@ -31,10 +31,12 @@ import org.eclipsefoundation.efservices.api.models.Project.GithubProject; import org.eclipsefoundation.efservices.api.models.Project.ProjectParticipant; import org.eclipsefoundation.efservices.api.models.Project.Repo; import org.eclipsefoundation.efservices.api.models.Project.WebsiteRepo; +import org.eclipsefoundation.testing.helpers.MockDataPaginationHandler; +import org.jboss.resteasy.reactive.RestResponse; import io.quarkus.test.Mock; +import io.smallrye.mutiny.Uni; import jakarta.enterprise.context.ApplicationScoped; -import jakarta.ws.rs.core.Response; @Mock @RestClient @@ -44,6 +46,7 @@ public class MockProjectsAPI implements ProjectsAPI { public static final String WEBSITE_REPO_URL = "http://gitlab.eclipse.org/sample/repo/complex-path-123"; private List<Project> projects; + private List<InterestGroup> igs; public MockProjectsAPI() { this.projects = new ArrayList<>(); @@ -149,66 +152,65 @@ public class MockProjectsAPI implements ProjectsAPI { .setReleases(Collections.emptyList()) .setTopLevelProject("eclipse") .build()); + this.igs = Arrays + .asList(InterestGroup + .builder() + .setProjectId("foundation-internal.ig.mittens") + .setId("1") + .setLogo("") + .setState("active") + .setTitle("Magical IG Tributed To Eclipse News Sources") + .setDescription(Descriptor.builder().setFull("Sample").setSummary("Sample").build()) + .setScope(Descriptor.builder().setFull("Sample").setSummary("Sample").build()) + .setGitlab(GitlabProject + .builder() + .setIgnoredSubGroups(Collections.emptyList()) + .setProjectGroup("eclipse-ig/mittens") + .build()) + .setLeads(Arrays + .asList(InterestGroupParticipant + .builder() + .setUrl("https://api.eclipse.org/account/profile/zacharysabourin") + .setUsername("zacharysabourin") + .setFullName("zachary sabourin") + .setOrganization(Organization + .builder() + .setDocuments(Collections.emptyMap()) + .setId("id") + .setName("org") + .build()) + .build())) + .setParticipants(Arrays + .asList(InterestGroupParticipant + .builder() + .setUrl("https://api.eclipse.org/account/profile/skilpatrick") + .setUsername("skilpatrick") + .setFullName("Skil Patrick") + .setOrganization(Organization + .builder() + .setDocuments(Collections.emptyMap()) + .setId("id") + .setName("org") + .build()) + .build())) + .setShortProjectId("mittens") + .setResources(Resource.builder().setMembers("members").setWebsite("google.com").build()) + .setMailingList("mailinglist.com") + .build()); } @Override - public Response getProjects(BaseAPIParameters params, int isSpecProject) { - + public Uni<RestResponse<List<Project>>> getProjects(BaseAPIParameters params, int isSpecProject) { + List<Project> out = projects; if (isSpecProject == 1) { - return Response.ok(projects.stream().filter(p -> p.getSpecWorkingGroup().isPresent()).toList()).build(); + out = out.stream().filter(p -> p.getSpecWorkingGroup().isPresent()).toList(); } - return Response.ok(projects).build(); + return Uni.createFrom().item(MockDataPaginationHandler.paginateData(params, out)); } @Override - public Response getInterestGroups(BaseAPIParameters params) { - return Response - .ok(Arrays - .asList(InterestGroup - .builder() - .setProjectId("foundation-internal.ig.mittens") - .setId("1") - .setLogo("") - .setState("active") - .setTitle("Magical IG Tributed To Eclipse News Sources") - .setDescription(Descriptor.builder().setFull("Sample").setSummary("Sample").build()) - .setScope(Descriptor.builder().setFull("Sample").setSummary("Sample").build()) - .setGitlab(GitlabProject - .builder() - .setIgnoredSubGroups(Collections.emptyList()) - .setProjectGroup("eclipse-ig/mittens") - .build()) - .setLeads(Arrays - .asList(InterestGroupParticipant - .builder() - .setUrl("https://api.eclipse.org/account/profile/zacharysabourin") - .setUsername("zacharysabourin") - .setFullName("zachary sabourin") - .setOrganization(Organization - .builder() - .setDocuments(Collections.emptyMap()) - .setId("id") - .setName("org") - .build()) - .build())) - .setParticipants(Arrays - .asList(InterestGroupParticipant - .builder() - .setUrl("https://api.eclipse.org/account/profile/skilpatrick") - .setUsername("skilpatrick") - .setFullName("Skil Patrick") - .setOrganization(Organization - .builder() - .setDocuments(Collections.emptyMap()) - .setId("id") - .setName("org") - .build()) - .build())) - .setShortProjectId("mittens") - .setResources(Resource.builder().setMembers("members").setWebsite("google.com").build()) - .setMailingList("mailinglist.com") - .build())) - .build(); + public Uni<RestResponse<List<InterestGroup>>> getInterestGroups(BaseAPIParameters params) { + return Uni.createFrom().item(MockDataPaginationHandler.paginateData(params, igs)); } }