diff --git a/spec/openapi.yaml b/spec/openapi.yaml index f50b6dab3f497b58c53decc0d7578d93efc6743f..0e9ec595d9717e8628b47b9674dcb8716080dc65 100644 --- a/spec/openapi.yaml +++ b/spec/openapi.yaml @@ -292,39 +292,6 @@ paths: description: Error while retrieving data. deprecated: false - /account/profile/{name}/gerrit: - get: - tags: - - User Metadata - summary: Retrieve user gerrit merge count via username - description: Retrieve gerrit merge count data about a specified user. - operationId: RetrieveGerrit - parameters: - - name: name - in: path - description: An ef username. - required: true - style: simple - explode: false - schema: - type: string - responses: - "200": - description: Success - content: - application/json: - schema: - $ref: "#/components/schemas/GerritResponse" - "404": - description: User not found - content: - application/json: - schema: - $ref: "#/components/schemas/Error" - "500": - description: Error while retrieving data. - deprecated: false - /account/profile/{name}/user_delete_request: post: tags: @@ -632,7 +599,7 @@ components: - oniro eca_url: https://api.eclipse.org/account/profile/zacharysabourin/eca projects_url: https://api.eclipse.org/account/profile/zacharysabourin/projects - gerrit_url: https://api.eclipse.org/account/profile/zacharysabourin/gerrit + gerrit_url: "" mailinglist_url: https://api.eclipse.org/account/profile/zacharysabourin/mailing-list mpc_favorites_url: https://marketplace.eclipse.org/user/zacharysabourin/favorites @@ -754,7 +721,8 @@ components: oneOf: - type: string - type: "null" - description: "The user's Gerrit URL." + description: "The user's Gerrit URL, deprecated and always empty" + deprecated: true projects_url: oneOf: - type: string @@ -808,7 +776,7 @@ components: - oniro eca_url: https://api.eclipse.org/account/profile/zacharysabourin/eca projects_url: https://api.eclipse.org/account/profile/zacharysabourin/projects - gerrit_url: https://api.eclipse.org/account/profile/zacharysabourin/gerrit + gerrit_url: "" mailinglist_url: https://api.eclipse.org/account/profile/zacharysabourin/mailing-list mpc_favorites_url: https://marketplace.eclipse.org/user/zacharysabourin/favorites @@ -1063,33 +1031,6 @@ components: Type: PR Description: Person - Project - GerritResponse: - type: object - additionalProperties: false - required: - - merged_changes_count - - gerrit_owner_url - - gerrit_reviewer_url - - account_url - properties: - merged_changes_count: - type: string - description: Count of all merged changes. - gerrit_owner_url: - type: string - description: The owner url for the user. - gerrit_reviewer_url: - type: string - description: The reviewer url for the user. - account_url: - type: string - description: The ef profile url. - example: - merged_changes_count: "99" - gerrit_owner_url: https://git.eclipse.org/r/changes/?q=owner:zachary.sabourin@eclipse-foundation.org - gerrit_reviewer_url: https://git.eclipse.org/r/changes/?q=owner:zachary.sabourin@eclipse-foundation.org - account_url: https://api.eclipse.org/account/profile/zacharysabourin - PaginatedUserDeleteRequests: type: object additionalProperties: false diff --git a/src/main/java/org/eclipsefoundation/profile/api/GerritAPI.java b/src/main/java/org/eclipsefoundation/profile/api/GerritAPI.java deleted file mode 100644 index 32c08bf6017dc5487f54de723314801f4512ab64..0000000000000000000000000000000000000000 --- a/src/main/java/org/eclipsefoundation/profile/api/GerritAPI.java +++ /dev/null @@ -1,41 +0,0 @@ -/********************************************************************* -* Copyright (c) 2023 Eclipse Foundation. -* -* This program and the accompanying materials are made -* available under the terms of the Eclipse Public License 2.0 -* which is available at https://www.eclipse.org/legal/epl-2.0/ -* -* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org> -* -* SPDX-License-Identifier: EPL-2.0 -**********************************************************************/ -package org.eclipsefoundation.profile.api; - -import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; - -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.QueryParam; -import jakarta.ws.rs.core.MediaType; - -/** - * Gerrit API binding. - */ -@Produces(MediaType.APPLICATION_JSON) -@ApplicationScoped -@RegisterRestClient(configKey = "gerrit-api") -public interface GerritAPI { - - /** - * Gets all changes after a specific start point given the query. - * - * @param query The given query. ex: '?q=reviewer:test@email.com status:merged' - * @param start The starting cursor position for results - * @return A JSON string containing all change information. - */ - @GET - @Path("/r/changes/") - String getGerritChanges(@QueryParam("q") String query, @QueryParam("start") int start); -} diff --git a/src/main/java/org/eclipsefoundation/profile/api/models/GerritChangeData.java b/src/main/java/org/eclipsefoundation/profile/api/models/GerritChangeData.java deleted file mode 100644 index d07a4a4add7493e9432c91033397eab553cd6c22..0000000000000000000000000000000000000000 --- a/src/main/java/org/eclipsefoundation/profile/api/models/GerritChangeData.java +++ /dev/null @@ -1,62 +0,0 @@ -/********************************************************************* -* Copyright (c) 2023 Eclipse Foundation. -* -* This program and the accompanying materials are made -* available under the terms of the Eclipse Public License 2.0 -* which is available at https://www.eclipse.org/legal/epl-2.0/ -* -* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org> -* -* SPDX-License-Identifier: EPL-2.0 -**********************************************************************/ -package org.eclipsefoundation.profile.api.models; - -import jakarta.annotation.Nullable; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; -import com.google.auto.value.AutoValue; - -/** - * The data retrieved from the Gerrit API. Contains only fields relevant to this - * application. - */ -@AutoValue -@JsonDeserialize(builder = AutoValue_GerritChangeData.Builder.class) -public abstract class GerritChangeData { - - public abstract String getId(); - - public abstract String getProject(); - - public abstract String getChangeId(); - - public abstract String getStatus(); - - @JsonProperty("_more_changes") - @Nullable - public abstract Boolean getMoreChanges(); - - public static Builder builder() { - return new AutoValue_GerritChangeData.Builder(); - } - - @AutoValue.Builder - @JsonPOJOBuilder(withPrefix = "set") - public abstract static class Builder { - - public abstract Builder setId(String id); - - public abstract Builder setProject(String project); - - public abstract Builder setChangeId(String id); - - public abstract Builder setStatus(String status); - - @JsonProperty("_more_changes") - public abstract Builder setMoreChanges(@Nullable Boolean status); - - public abstract GerritChangeData build(); - } -} diff --git a/src/main/java/org/eclipsefoundation/profile/config/UserMetadataConfig.java b/src/main/java/org/eclipsefoundation/profile/config/UserMetadataConfig.java index e396be4566f5dfa573b558bb935c89c0273e63bd..de115cff9c06ef9c04a48e0f536ea62c75cc1b42 100644 --- a/src/main/java/org/eclipsefoundation/profile/config/UserMetadataConfig.java +++ b/src/main/java/org/eclipsefoundation/profile/config/UserMetadataConfig.java @@ -30,8 +30,7 @@ public interface UserMetadataConfig { PublisherAgreementValidationDefinition publisherAgreementValidation(); /** - * ConfigMapper used to capture all profile metadata URLs. Contains the application base, MPC favorites, gerrit owner, and gerrit - * reviewer URLs. + * ConfigMapper used to capture all profile metadata URLs. Contains the application base and MPC favorites */ interface MetadataURLDefinition { @WithDefault("https://api.eclipse.org/account/profile/") @@ -39,12 +38,6 @@ public interface UserMetadataConfig { @WithDefault("https://api.eclipse.org/marketplace/favorites?name=") String marketplaceFavoritesUrl(); - - @WithDefault("https://git.eclipse.org/r/changes?owner:") - String gerritOwnerUrl(); - - @WithDefault("https://git.eclipse.org/r/changes?reviewer:") - String gerritReviewerUrl(); } /** diff --git a/src/main/java/org/eclipsefoundation/profile/dtos/eclipseapi/GerritCount.java b/src/main/java/org/eclipsefoundation/profile/dtos/eclipseapi/GerritCount.java deleted file mode 100644 index 1594c18f0f406c2ed1328dc47fe13e2a8148ba17..0000000000000000000000000000000000000000 --- a/src/main/java/org/eclipsefoundation/profile/dtos/eclipseapi/GerritCount.java +++ /dev/null @@ -1,149 +0,0 @@ -/********************************************************************* -* Copyright (c) 2023 Eclipse Foundation. -* -* This program and the accompanying materials are made -* available under the terms of the Eclipse Public License 2.0 -* which is available at https://www.eclipse.org/legal/epl-2.0/ -* -* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org> -* -* SPDX-License-Identifier: EPL-2.0 -**********************************************************************/ -package org.eclipsefoundation.profile.dtos.eclipseapi; - -import java.util.Objects; - -import jakarta.inject.Inject; -import jakarta.inject.Singleton; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import jakarta.ws.rs.core.MultivaluedMap; - -import org.eclipsefoundation.persistence.dto.BareNode; -import org.eclipsefoundation.persistence.dto.filter.DtoFilter; -import org.eclipsefoundation.persistence.model.DtoTable; -import org.eclipsefoundation.persistence.model.ParameterizedSQLStatement; -import org.eclipsefoundation.persistence.model.ParameterizedSQLStatementBuilder; -import org.eclipsefoundation.profile.namespace.ProfileAPIParameterNames; - -import com.fasterxml.jackson.annotation.JsonIgnore; - -/** - * DTO for the gerrit_review_count table. - */ -@Entity -@Table(name = "gerrit_review_count") -public class GerritCount extends BareNode { - public static final DtoTable TABLE = new DtoTable(GerritCount.class, "grt"); - - @Id - private int uid; - private int reviewCount; - private int reportDate; - - @JsonIgnore - @Override - public Object getId() { - return getUid(); - } - - public int getUid() { - return this.uid; - } - - public void setUid(int uid) { - this.uid = uid; - } - - public int getReviewCount() { - return this.reviewCount; - } - - public void setReviewCount(int reviewCount) { - this.reviewCount = reviewCount; - } - - public int getReportDate() { - return this.reportDate; - } - - public void setReportDate(int reportDate) { - this.reportDate = reportDate; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + Objects.hash(uid, reviewCount, reportDate); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (!super.equals(obj)) - return false; - if (getClass() != obj.getClass()) - return false; - GerritCount other = (GerritCount) obj; - return Objects.equals(uid, other.uid) && Objects.equals(reviewCount, other.reviewCount) - && Objects.equals(reportDate, other.reportDate); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("GerritCount [uid="); - builder.append(uid); - builder.append(", review_count="); - builder.append(reviewCount); - builder.append(", report_date="); - builder.append(reportDate); - builder.append("]"); - return builder.toString(); - } - - @Singleton - public static class GerritCountFilter implements DtoFilter<GerritCount> { - @Inject - ParameterizedSQLStatementBuilder builder; - - @Override - public ParameterizedSQLStatement getFilters(MultivaluedMap<String, String> params, boolean isRoot) { - ParameterizedSQLStatement statement = builder.build(TABLE); - - if (isRoot) { - String uid = params.getFirst(ProfileAPIParameterNames.UID.getName()); - if (uid != null) { - statement.addClause( - new ParameterizedSQLStatement.Clause(TABLE.getAlias() + ".uid = ?", - new Object[] { Integer.valueOf(uid) })); - } - - String reviewCount = params.getFirst(ProfileAPIParameterNames.REVIEW_COUNT.getName()); - if (reviewCount != null) { - statement.addClause( - new ParameterizedSQLStatement.Clause(TABLE.getAlias() + ".reviewCount = ?", - new Object[] { Integer.valueOf(reviewCount) })); - } - - String reportDate = params.getFirst(ProfileAPIParameterNames.REPORT_DATE.getName()); - if (reportDate != null) { - statement.addClause( - new ParameterizedSQLStatement.Clause(TABLE.getAlias() + ".reportDate = ?", - new Object[] { Integer.valueOf(reportDate) })); - } - } - - return statement; - } - - @Override - public Class<GerritCount> getType() { - return GerritCount.class; - } - } -} diff --git a/src/main/java/org/eclipsefoundation/profile/helpers/ProfileHelper.java b/src/main/java/org/eclipsefoundation/profile/helpers/ProfileHelper.java index c41559bae7181083b0b2761adb2ac7377f44c399..37c8e82b85320e6b675c84bef5641a8caf15c65d 100644 --- a/src/main/java/org/eclipsefoundation/profile/helpers/ProfileHelper.java +++ b/src/main/java/org/eclipsefoundation/profile/helpers/ProfileHelper.java @@ -38,11 +38,9 @@ import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocu import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleEmailsData; import org.eclipsefoundation.http.exception.ApplicationException; import org.eclipsefoundation.profile.api.DrupalAccountsAPI; -import org.eclipsefoundation.profile.api.GerritAPI; import org.eclipsefoundation.profile.api.OrganizationAPI; import org.eclipsefoundation.profile.api.PeopleAPI; import org.eclipsefoundation.profile.api.models.AccountsProfileData; -import org.eclipsefoundation.profile.api.models.GerritChangeData; import org.eclipsefoundation.utils.helper.TransformationHelper; import org.jboss.resteasy.reactive.common.jaxrs.ResponseImpl; import org.slf4j.Logger; @@ -63,7 +61,6 @@ public class ProfileHelper { private static final Logger LOGGER = LoggerFactory.getLogger(ProfileHelper.class); private static final Pattern ALTERNATE_EMAIL_PATTERN = Pattern.compile("alt-email\\s*:\\s*([\\w\\-\\.]+@[\\w\\-]+(\\.[\\w\\-]{2,4})+)"); - private static final int GERRIT_RESPONSE_START_INDEX = 4; private static final String ERROR_MSG = "Issue connecting to Accounts"; public static final String USER_NOT_FOUND_MESSAGE = "User not found."; @@ -72,9 +69,6 @@ public class ProfileHelper { PeopleAPI peopleAPI; @RestClient OrganizationAPI orgAPI; - - @RestClient - GerritAPI gerritAPI; @RestClient DrupalAccountsAPI accountsAPI; @@ -368,82 +362,6 @@ public class ProfileHelper { } } - /** - * Queries the Gerrit API for any changes made by a given user ignoring the first 'x' changes, where x is the current number of tracked - * changes. - * - * @param email The given user's email - * @param start The starting cursor position - * @return A List of GerritChangeData or empty - */ - public List<GerritChangeData> getGerritChanges(String username, int start) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Fetching gerrit changes for user: {}", username); - } - - try { - return getAllGerritChanges(username, start); - } catch (WebApplicationException e) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("GERRIT-API - No results for user: {}", TransformationHelper.formatLog(username), e); - } else { - LOGGER - .warn("GERRIT-API - No results for user: {}, code {}. Enable DEBUG logging for more detailed information", - TransformationHelper.formatLog(username), e.getResponse().getStatus()); - } - return Collections.emptyList(); - } - } - - /** - * Fetches all Gerrit changes starting at previous count. Checks for the '_more_changes' field in the last record. If this field is set, - * it will fetch the following page of results. It will fetch until there are no new changes. - * - * @param query The search query - * @param start The starting cursor position for fetching results. - * @return A list of all the newest changes since the last query. - */ - private List<GerritChangeData> getAllGerritChanges(String username, int start) { - - String query = "reviewer:" + username + " status:merged"; - - List<GerritChangeData> out = new ArrayList<>(); - - // Loop through all results until we hit the end flag - while (true) { - List<GerritChangeData> results = convertGerritJson(gerritAPI.getGerritChanges(query, start)); - out.addAll(results); - - // If '_more_changes' field exists in last record and is true, there is more - if (results.isEmpty() || results.get(results.size() - 1).getMoreChanges() == null - || Boolean.FALSE.equals(results.get(results.size() - 1).getMoreChanges())) { - break; - } - - // increase the start point before getting next set - start += results.size(); - } - - return out; - } - - /** - * Gerrit adds a special set of characters at the start of their response body. To be able to process the json properly, it must first - * be removed. ex: )]}' [ ... valid JSON ... ] - * - * @param body The Gerrit json body - * @return A converted list of GerritchangeData entities if they exist - */ - private List<GerritChangeData> convertGerritJson(String body) { - try { - // Parse the json body after the first 4 characters - return objectMapper.readerForListOf(GerritChangeData.class).readValue(body.substring(GERRIT_RESPONSE_START_INDEX)); - } catch (Exception e) { - LOGGER.error("Error parsing json Gerrit data", e); - return Collections.emptyList(); - } - } - /** * When service is down and endpoint isn't found, a 404 is returned. This 404 will have different contents than if the user is simply * missing, so we can check for expected outputs. Will check if the status is 404, and if the body matches the expected output for when diff --git a/src/main/java/org/eclipsefoundation/profile/helpers/UserMetadataHelper.java b/src/main/java/org/eclipsefoundation/profile/helpers/UserMetadataHelper.java index 57f88eef67a9adeb0f0594f73311494cda11d496..c8d70ea8b66665e50652912a5c1d70cdab5ee839 100644 --- a/src/main/java/org/eclipsefoundation/profile/helpers/UserMetadataHelper.java +++ b/src/main/java/org/eclipsefoundation/profile/helpers/UserMetadataHelper.java @@ -26,8 +26,6 @@ import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocu import org.eclipsefoundation.foundationdb.client.runtime.model.project.ProjectData; import org.eclipsefoundation.foundationdb.client.runtime.model.system.SysRelationData; import org.eclipsefoundation.profile.config.UserMetadataConfig; -import org.eclipsefoundation.profile.dtos.eclipseapi.GerritCount; -import org.eclipsefoundation.profile.models.GerritResponse; import org.eclipsefoundation.profile.models.PeopleProject; import org.eclipsefoundation.profile.models.PeopleProject.Relation; import org.eclipsefoundation.profile.models.PeopleProject.RelationTypeData; @@ -47,21 +45,6 @@ public final class UserMetadataHelper { this.metadataConfig = config; } - /** - * Builds a GerritCount DTO using the user uid and current change count. - * - * @param uid The user's uid - * @param count The current change count - * @return A GerritCount DTO - */ - public GerritCount buildGerritCountDto(String uid, int count) { - GerritCount out = new GerritCount(); - out.setUid(Integer.valueOf(uid)); - out.setReviewCount(count); - out.setReportDate((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())); - return out; - } - /** * Builds the return object for /projects from the full PeopleProjectData returned from fdndb-api. * @@ -122,23 +105,6 @@ public final class UserMetadataHelper { : Collections.emptyMap(); } - /** - * Builds a GerritResponse object given the desired count, and username. Constructs owner, reviewer, and account URLs. - * - * @param count The user review count. - * @param username The username. - * @return A fully populated GerritResponse with all related URLs. - */ - public GerritResponse buildGerritResponse(int count, String username) { - return GerritResponse - .builder() - .setMergedChangesCount(Integer.toString(count)) - .setGerritOwnerUrl(metadataConfig.url().gerritOwnerUrl() + username) - .setGerritReviewerUrl(metadataConfig.url().gerritReviewerUrl() + username) - .setAccountUrl(metadataConfig.url().applicationBaseUrl() + "account/profile/" + username) - .build(); - } - /** * Builds a relation URL for a given user. ex: api.eclipse.org/account/profile/{username}/{resource} * diff --git a/src/main/java/org/eclipsefoundation/profile/models/GerritResponse.java b/src/main/java/org/eclipsefoundation/profile/models/GerritResponse.java deleted file mode 100644 index 7d0c5d8387415893fbb29a7e3ae166bda19b5c2e..0000000000000000000000000000000000000000 --- a/src/main/java/org/eclipsefoundation/profile/models/GerritResponse.java +++ /dev/null @@ -1,51 +0,0 @@ -/********************************************************************* -* Copyright (c) 2023 Eclipse Foundation. -* -* This program and the accompanying materials are made -* available under the terms of the Eclipse Public License 2.0 -* which is available at https://www.eclipse.org/legal/epl-2.0/ -* -* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org> -* -* SPDX-License-Identifier: EPL-2.0 -**********************************************************************/ -package org.eclipsefoundation.profile.models; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; -import com.google.auto.value.AutoValue; - -/** - * The object returned from the Gerrit relationship endpoint. - */ -@AutoValue -@JsonDeserialize(builder = AutoValue_GerritResponse.Builder.class) -public abstract class GerritResponse { - - public abstract String getMergedChangesCount(); - - public abstract String getGerritOwnerUrl(); - - public abstract String getGerritReviewerUrl(); - - public abstract String getAccountUrl(); - - public static Builder builder() { - return new AutoValue_GerritResponse.Builder(); - } - - @AutoValue.Builder - @JsonPOJOBuilder(withPrefix = "set") - public abstract static class Builder { - - public abstract Builder setMergedChangesCount(String count); - - public abstract Builder setGerritOwnerUrl(String url); - - public abstract Builder setGerritReviewerUrl(String url); - - public abstract Builder setAccountUrl(String url); - - public abstract GerritResponse build(); - } -} diff --git a/src/main/java/org/eclipsefoundation/profile/resources/AccountResource.java b/src/main/java/org/eclipsefoundation/profile/resources/AccountResource.java index be76bd6a8711057445394600ac59bfc98014c9a0..2d66879fcaadb46692648ea95cb5afb8a4ab6c11 100644 --- a/src/main/java/org/eclipsefoundation/profile/resources/AccountResource.java +++ b/src/main/java/org/eclipsefoundation/profile/resources/AccountResource.java @@ -26,7 +26,6 @@ import org.eclipsefoundation.efservices.models.AuthenticatedRequestWrapper; import org.eclipsefoundation.http.annotations.AuthenticatedAlternate; import org.eclipsefoundation.http.exception.ApplicationException; import org.eclipsefoundation.profile.models.DeleteRequestData; -import org.eclipsefoundation.profile.models.GerritResponse; import org.eclipsefoundation.profile.models.LdapResult; import org.eclipsefoundation.profile.models.PeopleProject; import org.eclipsefoundation.profile.models.ProfileAPISearchParams; @@ -171,34 +170,6 @@ public class AccountResource { return Response.ok(profileService.getEcaStatus(username, false, Collections.emptyList(), Collections.emptyList())).build(); } - /** - * Returns a 200 OK Response containing the desired user's Gerrit review count. Returns a 404 Not Found Response if the user cannot be - * found. Returns a 500 if there was en error fetching from the Accounts-API - * - * @param username The given username. - * @return A 200 OK Response containing the desired user's Gerrit review count. A 404 Not Found Response if the user cannot be found. - */ - @GET - @Path("account/profile/{username}/gerrit") - public Response getUserGerrit(@PathParam("username") String username) { - CacheWrapper<GerritResponse> cacheResult = cache - .get(username, new MultivaluedHashMap<>(), GerritResponse.class, () -> profileService.getUserGerritCount(username)); - - // ApplicationException is thrown when Account-API fails. Clear cache and return 500 - Optional<Class<?>> errorType = cacheResult.errorType(); - if (errorType.isPresent() && errorType.get().equals(ApplicationException.class)) { - cache.remove(ParameterizedCacheKeyBuilder.builder().clazz(GerritResponse.class).id(username).build()); - throw new ApplicationException(SERVER_ERROR_MSG); - } - - Optional<GerritResponse> gerritData = cacheResult.data(); - if (gerritData.isEmpty()) { - throw new NotFoundException(USER_NOT_FOUND_MSG); - } - - return Response.ok(gerritData.get()).build(); - } - /** * Returns a 200 OK Response containing the desired user's mailing-list subscriptions. Returns a 404 the user does not exist. Returns an * empty list if the user has no mailing-list subscriptions. @@ -316,9 +287,6 @@ public class AccountResource { // anonymize friends table record for user deleteService.anonymizeFriendsTableForUser(user.name()); - // Delete mpc favourite and gerrit data for user - deleteService.performDBCleanupForUser(user.uid()); - // Return all created requests return Response.status(Status.CREATED).header("status", "201 Created").entity(created).build(); } diff --git a/src/main/java/org/eclipsefoundation/profile/services/ProfileService.java b/src/main/java/org/eclipsefoundation/profile/services/ProfileService.java index 0bdfcaffbf82ce37a4cd66fb2a6c9e9a34d82f33..acef0bb14c8aaccef50f6096d54003876f8d6917 100644 --- a/src/main/java/org/eclipsefoundation/profile/services/ProfileService.java +++ b/src/main/java/org/eclipsefoundation/profile/services/ProfileService.java @@ -17,7 +17,6 @@ import org.eclipsefoundation.efservices.api.models.EfUser; import org.eclipsefoundation.efservices.api.models.EfUser.Eca; import org.eclipsefoundation.foundationdb.client.runtime.model.full.FullOrganizationContactData; import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocumentData; -import org.eclipsefoundation.profile.models.GerritResponse; import org.eclipsefoundation.profile.models.PeopleProject; import org.eclipsefoundation.profile.models.ProfileAPISearchParams; import org.eclipsefoundation.profile.models.Subscriptions; @@ -105,12 +104,4 @@ public interface ProfileService { * @return list of previous employment records if available, otherwise an empty list */ List<UserEmploymentHistory> getPersonEmploymentHistory(String username); - - /** - * Returns a GerritResponse object with the user's review count and additional account URLs. - * - * @param username The desired user's username. - * @return An Optional containing the user gerrit count if they exist - */ - GerritResponse getUserGerritCount(String username); } diff --git a/src/main/java/org/eclipsefoundation/profile/services/UserDeleteService.java b/src/main/java/org/eclipsefoundation/profile/services/UserDeleteService.java index 903e192970ea634d119425f9923fd56786a2b3df..150fd6a28fd8d87be17befee43918c697366ae1f 100644 --- a/src/main/java/org/eclipsefoundation/profile/services/UserDeleteService.java +++ b/src/main/java/org/eclipsefoundation/profile/services/UserDeleteService.java @@ -87,11 +87,4 @@ public interface UserDeleteService { * @param username The desired user */ void anonymizeFriendsTableForUser(String username); - - /** - * Deletes records for a user from the following tables: gerrit_review_count, mpc_favorites, and mpc_favorites_list_name - * - * @param uid The given user uid. - */ - void performDBCleanupForUser(String uid); } diff --git a/src/main/java/org/eclipsefoundation/profile/services/impl/DefaultProfileService.java b/src/main/java/org/eclipsefoundation/profile/services/impl/DefaultProfileService.java index 744374f027057aed05d7eb1610b888434d91769b..19be366e9d1d9d9b02b7a6e1dfc50013e5b0371e 100644 --- a/src/main/java/org/eclipsefoundation/profile/services/impl/DefaultProfileService.java +++ b/src/main/java/org/eclipsefoundation/profile/services/impl/DefaultProfileService.java @@ -11,12 +11,10 @@ **********************************************************************/ package org.eclipsefoundation.profile.services.impl; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.SplittableRandom; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -41,22 +39,18 @@ import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocu import org.eclipsefoundation.http.exception.ApplicationException; 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.eclipsefoundation.profile.api.MailingListAPI; import org.eclipsefoundation.profile.api.OrganizationAPI; import org.eclipsefoundation.profile.api.models.AccountsProfileData; import org.eclipsefoundation.profile.config.UserMetadataConfig; -import org.eclipsefoundation.profile.dtos.eclipseapi.GerritCount; import org.eclipsefoundation.profile.helpers.ProfileHelper; import org.eclipsefoundation.profile.helpers.UserMetadataHelper; -import org.eclipsefoundation.profile.models.GerritResponse; import org.eclipsefoundation.profile.models.LdapResult; import org.eclipsefoundation.profile.models.PeopleProject; import org.eclipsefoundation.profile.models.ProfileAPISearchParams; import org.eclipsefoundation.profile.models.Subscriptions; import org.eclipsefoundation.profile.models.UserEmploymentHistory; -import org.eclipsefoundation.profile.namespace.ProfileAPIParameterNames; import org.eclipsefoundation.profile.services.LDAPService; import org.eclipsefoundation.profile.services.ProfileService; import org.eclipsefoundation.utils.helper.TransformationHelper; @@ -81,9 +75,6 @@ import jakarta.ws.rs.core.Response; public class DefaultProfileService implements ProfileService { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultProfileService.class); - private static final SplittableRandom rand = new SplittableRandom(); - private static final int RANDOM_BOUND = 100; - private static final int RANDOM_PROBABILITY = 1; private static final long FUTURE_TIMEOUT = 5; @Inject @@ -276,47 +267,6 @@ public class DefaultProfileService implements ProfileService { } } - @Override - public GerritResponse getUserGerritCount(String username) { - Optional<AccountsProfileData> user = profileHelper.getAccountsProfileByUsername(username); - // A missing UID means Accounts is having issues. We cannot continue with the DB query without it - if (user.isEmpty() || !StringUtils.isNumeric(user.get().getUid())) { - return null; - } - - MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); - params.add(ProfileAPIParameterNames.UID.getName(), user.get().getUid()); - - int count = 0; - List<GerritCount> results = defaultDao.get(new RDBMSQuery<>(wrap, filters.get(GerritCount.class), params)); - if (results != null && !results.isEmpty()) { - - // If initial record exists, set the starting count - count = results.get(0).getReviewCount(); - - // Return current results if not older than 24hrs - if (!metadataHelper.isExpiredReport(results.get(0).getReportDate())) { - metadataHelper.buildGerritResponse(results.get(0).getReviewCount(), username); - } - } - - // 1% chance to fully recount - if (rand.split().nextInt(RANDOM_BOUND) == RANDOM_PROBABILITY) { - count = 0; - } - - // Get all gerrit changes and add the count - count += profileHelper.getGerritChanges(username, count).size(); - - // Add updated/new record to DB - defaultDao - .add(new RDBMSQuery<>(wrap, filters.get(GerritCount.class)), - Arrays.asList(metadataHelper.buildGerritCountDto(user.get().getUid(), count))); - - final int finalCount = count; - return metadataHelper.buildGerritResponse(finalCount, username); - } - @Override public List<UserEmploymentHistory> getPersonEmploymentHistory(String username) { // we only want to process if user exists, so do a simple check to validate they exist first @@ -541,7 +491,7 @@ public class DefaultProfileService implements ProfileService { profile .ecaUrl(metadataHelper.buildRelationshipUrl(username, "eca")) .projectsUrl(metadataHelper.buildRelationshipUrl(username, "projects")) - .gerritUrl(metadataHelper.buildRelationshipUrl(username, "gerrit")) + .gerritUrl("") .mailinglistUrl(metadataHelper.buildRelationshipUrl(username, "mailing-list")) .mpcFavoritesUrl(metadataConfig.url().marketplaceFavoritesUrl() + username + "/favorites"); } diff --git a/src/main/java/org/eclipsefoundation/profile/services/impl/DefaultUserDeleteService.java b/src/main/java/org/eclipsefoundation/profile/services/impl/DefaultUserDeleteService.java index 80944263fd1ff0bd117da0788838b2efe92dd917..bd26ba5900efc77532d82abf973392d2fc083e6c 100644 --- a/src/main/java/org/eclipsefoundation/profile/services/impl/DefaultUserDeleteService.java +++ b/src/main/java/org/eclipsefoundation/profile/services/impl/DefaultUserDeleteService.java @@ -31,7 +31,6 @@ import org.eclipsefoundation.profile.daos.EclipsePersistenceDao; import org.eclipsefoundation.profile.dtos.eclipse.AccountRequests; import org.eclipsefoundation.profile.dtos.eclipse.Friends; import org.eclipsefoundation.profile.dtos.eclipseapi.FinalStageUserDeleteRequest; -import org.eclipsefoundation.profile.dtos.eclipseapi.GerritCount; import org.eclipsefoundation.profile.dtos.eclipseapi.UserDeleteRequest; import org.eclipsefoundation.profile.helpers.UserDeleteHelper; import org.eclipsefoundation.profile.models.DeleteRequestData; @@ -181,13 +180,6 @@ public class DefaultUserDeleteService implements UserDeleteService { } } - @Override - public void performDBCleanupForUser(String uid) { - MultivaluedMap<String, String> params = new MultivaluedHashMap<>(); - params.add(ProfileAPIParameterNames.UID.getName(), uid); - defaultDao.delete(new RDBMSQuery<>(wrap, filters.get(GerritCount.class), params)); - } - @Override public List<DeleteRequestData> fetchFinalStageRequests() { LOGGER.debug("Fetching all final-stage UserDeleteRequests"); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 5cd4dd69a6286654132b673bbfe38872ee102dd1..5d3f4c416f5078bec14638da31d90df5eedef267 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -30,7 +30,6 @@ quarkus.rest-client.accounts-profile-api.url=https://accounts.eclipse.org/accoun #%dev.accounts-api.url=https://accounts-staging.eclipse.org quarkus.rest-client.eclipse-api.url=https://api.eclipse.org quarkus.rest-client.projects-api.url=https://projects.eclipse.org -quarkus.rest-client.gerrit-api.url=https://git.eclipse.org ## Eclipse cache settings eclipse.cache.ttl-max-seconds=300 @@ -53,8 +52,6 @@ eclipse.security.oauth2.filter.enabled=true eclipse.profile.metadata.url.application-base-url=https://api.eclipse.org/ %dev.eclipse.profile.metadata.url.application-base-url=http://localhost:8090/ eclipse.profile.metadata.url.marketplace-favorites-url=https://marketplace.eclipse.org/user/ -eclipse.profile.metadata.url.gerrit-owner-url=https://git.eclipse.org/r/changes/?q=owner: -eclipse.profile.metadata.url.gerrit-reviewer-url=https://git.eclipse.org/r/changes/?q=reviewer: ## User delete hostnames ## Updates to add/remove entries will require an update to the CompletedUserDeleteRequest to equal count - 1 (accounts is final and we action it) diff --git a/src/test/java/org/eclipsefoundation/profile/resources/AccountResourceTest.java b/src/test/java/org/eclipsefoundation/profile/resources/AccountResourceTest.java index 56c73951fcb3cacd95950189373578f21e68556e..82d3c3b9d0db5cdbc36dd30f9362e60648821e29 100644 --- a/src/test/java/org/eclipsefoundation/profile/resources/AccountResourceTest.java +++ b/src/test/java/org/eclipsefoundation/profile/resources/AccountResourceTest.java @@ -26,7 +26,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.eclipsefoundation.profile.dtos.eclipseapi.GerritCount; import org.eclipsefoundation.profile.dtos.eclipseapi.UserDeleteRequest; import org.eclipsefoundation.profile.namespace.ProfileAPIParameterNames; import org.eclipsefoundation.profile.test.api.MockAccountsAPI; @@ -61,7 +60,6 @@ class AccountResourceTest { public static final String MAILING_LIST_URL = PROFILE_BY_USER_URL + "/mailing-list"; public static final String PROJECTS_URL = PROFILE_BY_USER_URL + "/projects"; public static final String FORUM_URL = PROFILE_BY_USER_URL + "/forum"; - public static final String GERRIT_URL = PROFILE_BY_USER_URL + "/gerrit"; public static final String USER_DELETE_URL = "account/profile/{username}/user_delete_request"; /* @@ -265,16 +263,6 @@ class AccountResourceTest { .buildNotFoundCase(PROJECTS_URL, new String[] { TestNamespaceHelper.INVALID_USERNAME }, SchemaNamespaceHelper.ERROR_SCHEMA_PATH); - /* - * GERRIT - */ - public static final EndpointTestCase GET_GERRIT_SUCCESS = TestCaseHelper - .buildSuccessCase(GERRIT_URL, new String[] { TestNamespaceHelper.VALID_USERNAME }, - SchemaNamespaceHelper.GERRIT_RESPONSE_SCHEMA_PATH); - - public static final EndpointTestCase GET_GERRIT_NOT_FOUND = TestCaseHelper - .buildNotFoundCase(GERRIT_URL, new String[] { TestNamespaceHelper.INVALID_USERNAME }, SchemaNamespaceHelper.ERROR_SCHEMA_PATH); - /* * USER DELETE REQUEST */ @@ -843,34 +831,6 @@ class AccountResourceTest { EndpointTestBuilder.from(GET_PROJECTS_NOT_FOUND).andCheckSchema().run(); } - /* - * GET /account/profile/:username/gerrit - */ - @Test - void testGetGerrit_success() { - EndpointTestBuilder.from(GET_GERRIT_SUCCESS).run(); - } - - @Test - void testGetGerrit_success_validateResponseFormat() { - EndpointTestBuilder.from(GET_GERRIT_SUCCESS).andCheckFormat().run(); - } - - @Test - void testGetGerrit_success_validateSchema() { - EndpointTestBuilder.from(GET_GERRIT_SUCCESS).andCheckSchema().run(); - } - - @Test - void testGetGerrit_failure_notfound() { - EndpointTestBuilder.from(GET_GERRIT_NOT_FOUND).run(); - } - - @Test - void testGetGerrit_failure_notfound_validateSchema() { - EndpointTestBuilder.from(GET_GERRIT_NOT_FOUND).andCheckSchema().run(); - } - /* * GET /account/profile/:username/user_delete_request */ @@ -882,19 +842,12 @@ class AccountResourceTest { params.add(ProfileAPIParameterNames.UID.getName(), "42"); RequestWrapper wrap = new FlatRequestWrapper(URI.create("api.eclipse.org")); - List<GerritCount> gerritResults = defaultDao.get(new RDBMSQuery<>(wrap, filters.get(GerritCount.class), params)); - Assertions.assertFalse(gerritResults.isEmpty()); - // assert that the user had 0 entries before List<UserDeleteRequest> deletionResults = defaultDao.get(new RDBMSQuery<>(wrap, filters.get(UserDeleteRequest.class), params)); Assertions.assertTrue(deletionResults.isEmpty()); EndpointTestBuilder.from(buildDeleteTestCaseForUser("firstlast")).doPost(null).run(); - // Ensure record cleaned up - gerritResults = defaultDao.get(new RDBMSQuery<>(wrap, filters.get(GerritCount.class), params)); - Assertions.assertTrue(gerritResults.isEmpty()); - // assert that the proper number of results was created deletionResults = defaultDao.get(new RDBMSQuery<>(wrap, filters.get(UserDeleteRequest.class), params)); Assertions.assertEquals(hosts.size(), deletionResults.size()); diff --git a/src/test/java/org/eclipsefoundation/profile/test/api/MockGerritAPI.java b/src/test/java/org/eclipsefoundation/profile/test/api/MockGerritAPI.java deleted file mode 100644 index 2e4547a21e31e6bd6e265be3119772943da975d6..0000000000000000000000000000000000000000 --- a/src/test/java/org/eclipsefoundation/profile/test/api/MockGerritAPI.java +++ /dev/null @@ -1,85 +0,0 @@ -/********************************************************************* -* Copyright (c) 2023 Eclipse Foundation. -* -* This program and the accompanying materials are made -* available under the terms of the Eclipse Public License 2.0 -* which is available at https://www.eclipse.org/legal/epl-2.0/ -* -* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org> -* -* SPDX-License-Identifier: EPL-2.0 -**********************************************************************/ -package org.eclipsefoundation.profile.test.api; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.microprofile.rest.client.inject.RestClient; -import org.eclipsefoundation.profile.api.GerritAPI; -import org.eclipsefoundation.profile.api.models.GerritChangeData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.ObjectMapper; - -import io.quarkus.test.Mock; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; -import jakarta.ws.rs.core.MultivaluedHashMap; -import jakarta.ws.rs.core.MultivaluedMap; - -@Mock -@RestClient -@ApplicationScoped -public class MockGerritAPI implements GerritAPI { - private static final Logger LOGGER = LoggerFactory.getLogger(MockGerritAPI.class); - - private static final String SPECIAL_CHARS = ")]}'"; - - private MultivaluedMap<String, GerritChangeData> changes; - - @Inject - ObjectMapper objectMapper; - - public MockGerritAPI() { - this.changes = new MultivaluedHashMap<>(); - this.changes - .put("firstlast", - Arrays - .asList(buildGerritChange("1"), buildGerritChange("2"), buildGerritChange("3"), buildGerritChange("4"), - buildGerritChange("5"))); - - this.changes - .put("username", - Arrays - .asList(buildGerritChange("1"), buildGerritChange("2"), buildGerritChange("3"), buildGerritChange("4"), - buildGerritChange("5"))); - } - - @Override - public String getGerritChanges(String query, int start) { - try { - String username = query.substring(query.indexOf(":") + 1, query.indexOf(" ")); - - List<GerritChangeData> results = changes.get(username); - - String json = objectMapper.writeValueAsString(results); - - return SPECIAL_CHARS + json; - - } catch (Exception e) { - LOGGER.error("Error serializing gerrit changes", e); - return SPECIAL_CHARS + "[]"; - } - } - - private GerritChangeData buildGerritChange(String changeId) { - return GerritChangeData - .builder() - .setId("www.eclipse.org?change_id=" + changeId) - .setChangeId(changeId) - .setProject("www.eclipse.org/org") - .setStatus("MERGED") - .build(); - } -} diff --git a/src/test/java/org/eclipsefoundation/profile/test/api/MockProjectAPI.java b/src/test/java/org/eclipsefoundation/profile/test/api/MockProjectAPI.java index f3e110ad97755ea8e31e6534fa86fb51665e29ea..f5fe8131eda0ae198bad2ee7d0cf67ea2d71cee5 100644 --- a/src/test/java/org/eclipsefoundation/profile/test/api/MockProjectAPI.java +++ b/src/test/java/org/eclipsefoundation/profile/test/api/MockProjectAPI.java @@ -50,7 +50,6 @@ public class MockProjectAPI implements ProjectsAPI { Repo r1 = ProjectRepoBuilder.builder().url("http://www.github.com/eclipsefdn/sample").build(); Repo r2 = ProjectRepoBuilder.builder().url("http://www.github.com/eclipsefdn/test").build(); Repo r3 = ProjectRepoBuilder.builder().url("http://www.github.com/eclipsefdn/tck-proto").build(); - Repo r4 = ProjectRepoBuilder.builder().url("/gitroot/sample/gerrit.project.git").build(); // sample users ProjectParticipant u1 = ProjectProjectParticipantBuilder.builder().url("").username("da_wizz").fullName("da_wizz").build(); @@ -70,7 +69,7 @@ public class MockProjectAPI implements ProjectsAPI { .tags(Collections.emptyList()) .githubRepos(Arrays.asList(r1, r2)) .gitlabRepos(Collections.emptyList()) - .gerritRepos(Arrays.asList(r4)) + .gerritRepos(Collections.emptyList()) .committers(Arrays.asList(u1, u2)) .projectLeads(Collections.emptyList()) .gitlab(GitlabProjectBuilder.builder().ignoredSubGroups(Collections.emptyList()).projectGroup("").build()) diff --git a/src/test/java/org/eclipsefoundation/profile/test/helpers/SchemaNamespaceHelper.java b/src/test/java/org/eclipsefoundation/profile/test/helpers/SchemaNamespaceHelper.java index 48dd23b8d1154fa03594acf3107db441e6e670b4..a4984d5c4038a017639cbe1a3df140299eedb680 100644 --- a/src/test/java/org/eclipsefoundation/profile/test/helpers/SchemaNamespaceHelper.java +++ b/src/test/java/org/eclipsefoundation/profile/test/helpers/SchemaNamespaceHelper.java @@ -23,7 +23,6 @@ public class SchemaNamespaceHelper { public static final String EMPLOYMENT_HISTORIES_PATH = BASE_SCHEMA_PATH + "employment-histories" + BASE_SCHEMA_PATH_SUFFIX; public static final String PEOPLE_PROJECT_MAP_PATH = BASE_SCHEMA_PATH + "people-project-map" + BASE_SCHEMA_PATH_SUFFIX; public static final String SUBSCRIPTIONS_SCHEMA_PATH = BASE_SCHEMA_PATH + "subscriptions" + BASE_SCHEMA_PATH_SUFFIX; - public static final String GERRIT_RESPONSE_SCHEMA_PATH = BASE_SCHEMA_PATH + "gerrit-response" + BASE_SCHEMA_PATH_SUFFIX; public static final String PAGINATED_USER_DELETE_REQUESTS_SCHEMA_PATH = BASE_SCHEMA_PATH + "paginated-user-delete-requests" + BASE_SCHEMA_PATH_SUFFIX;