diff --git a/gamification-github-services/pom.xml b/gamification-github-services/pom.xml
index 1388ddf0e..db6abfbb8 100644
--- a/gamification-github-services/pom.xml
+++ b/gamification-github-services/pom.xml
@@ -32,13 +32,17 @@
jar
Gamification - Github Connector - Services
- 0.24
+ 0.30
+
+ io.meeds.social
+ social-component-core
+ provided
+
io.meeds.social
social-component-oauth-auth
- provided
io.meeds.gamification
diff --git a/gamification-github-services/src/main/java/io/meeds/gamification/github/dao/WebHookDAO.java b/gamification-github-services/src/main/java/io/meeds/gamification/github/dao/WebHookDAO.java
deleted file mode 100644
index 406b2fb87..000000000
--- a/gamification-github-services/src/main/java/io/meeds/gamification/github/dao/WebHookDAO.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * This file is part of the Meeds project (https://meeds.io/).
- *
- * Copyright (C) 2020 - 2023 Meeds Lab contact@meedslab.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package io.meeds.gamification.github.dao;
-
-import org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl;
-import io.meeds.gamification.github.entity.WebhookEntity;
-
-import jakarta.persistence.NoResultException;
-import jakarta.persistence.TypedQuery;
-import java.util.List;
-
-public class WebHookDAO extends GenericDAOJPAImpl {
-
- public static final String ORGANIZATION_ID = "organizationId";
-
- public WebhookEntity getWebhookByOrganizationId(long organizationId) {
- TypedQuery query = getEntityManager().createNamedQuery("GitHubWebhooks.getWebhookByOrganizationId",
- WebhookEntity.class);
- query.setParameter(ORGANIZATION_ID, organizationId);
- try {
- return query.getSingleResult();
- } catch (NoResultException e) {
- return null;
- }
- }
-
- public List getWebhookIds(int offset, int limit) {
- TypedQuery query = getEntityManager().createNamedQuery("GitHubWebhooks.getWebhookIds", Long.class);
- if (offset > 0) {
- query.setFirstResult(offset);
- }
- if (limit > 0) {
- query.setMaxResults(limit);
- }
- return query.getResultList();
- }
-}
diff --git a/gamification-github-services/src/main/java/io/meeds/gamification/github/plugin/IssueTriggerPlugin.java b/gamification-github-services/src/main/java/io/meeds/gamification/github/plugin/IssueTriggerPlugin.java
deleted file mode 100644
index e081a6a07..000000000
--- a/gamification-github-services/src/main/java/io/meeds/gamification/github/plugin/IssueTriggerPlugin.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * This file is part of the Meeds project (https://meeds.io/).
- *
- * Copyright (C) 2020 - 2023 Meeds Lab contact@meedslab.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package io.meeds.gamification.github.plugin;
-
-import io.meeds.gamification.github.model.Event;
-import static io.meeds.gamification.github.utils.Utils.*;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-public class IssueTriggerPlugin extends GithubTriggerPlugin {
-
- @Override
- public List getEvents(Map payload) {
- String issueState = extractSubItem(payload, ACTION);
- String objectId = extractSubItem(payload, ISSUE, HTML_URL);
- String userId = extractSubItem(payload, SENDER, LOGIN);
- if (Objects.equals(issueState, OPENED)) {
- return Collections.singletonList(new Event(CREATE_ISSUE_EVENT_NAME,
- userId,
- userId,
- objectId,
- ISSUE_TYPE,
- extractSubItem(payload, "organization", "id"),
- extractSubItem(payload, "repository", "id")));
- } else if (Objects.equals(issueState, CLOSED)) {
- if (Objects.equals(extractSubItem(payload, ISSUE, STATE_REASON), NOT_PLANNED)) {
- return Collections.singletonList(new Event(CLOSE_ISSUE_EVENT_NAME,
- userId,
- userId,
- objectId,
- ISSUE_TYPE,
- extractSubItem(payload, "organization", "id"),
- extractSubItem(payload, "repository", "id")));
- }
- return Collections.emptyList();
- } else if (Objects.equals(issueState, LABELED)) {
- objectId = objectId + "?label=" + extractSubItem(payload, LABEL, NAME);
- return Collections.singletonList(new Event(ADD_ISSUE_LABEL_EVENT_NAME,
- userId,
- userId,
- objectId,
- ISSUE_TYPE,
- extractSubItem(payload, ORGANIZATION, ID),
- extractSubItem(payload, REPOSITORY, ID)));
- } else if (Objects.equals(issueState, UNLABELED)) {
- objectId = objectId + "?label=" + extractSubItem(payload, LABEL, NAME);
- return Collections.singletonList(new Event(DELETE_ISSUE_LABEL_EVENT_NAME,
- userId,
- userId,
- objectId,
- ISSUE_TYPE,
- extractSubItem(payload, ORGANIZATION, ID),
- extractSubItem(payload, REPOSITORY, ID)));
- }
- return Collections.emptyList();
- }
-}
diff --git a/gamification-github-services/src/main/java/io/meeds/gamification/github/plugin/PullRequestReviewTriggerPlugin.java b/gamification-github-services/src/main/java/io/meeds/gamification/github/plugin/PullRequestReviewTriggerPlugin.java
deleted file mode 100644
index b2b471127..000000000
--- a/gamification-github-services/src/main/java/io/meeds/gamification/github/plugin/PullRequestReviewTriggerPlugin.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * This file is part of the Meeds project (https://meeds.io/).
- *
- * Copyright (C) 2020 - 2023 Meeds Lab contact@meedslab.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package io.meeds.gamification.github.plugin;
-
-import io.meeds.gamification.github.model.Event;
-import static io.meeds.gamification.github.utils.Utils.*;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-public class PullRequestReviewTriggerPlugin extends GithubTriggerPlugin {
-
- @Override
- public List getEvents(Map payload) {
- String pullState = extractSubItem(payload, PULL_REQUEST_REVIEW, STATE);
- if (pullState != null && pullState.equals(PULL_REQUEST_COMMENTED)) {
- return Collections.singletonList(new Event(REVIEW_PULL_REQUEST_EVENT_NAME,
- extractSubItem(payload, PULL_REQUEST_REVIEW, USER, LOGIN),
- extractSubItem(payload, PULL_REQUEST_REVIEW, USER, LOGIN),
- extractSubItem(payload, PULL_REQUEST_REVIEW, HTML_URL),
- PR_TYPE,
- extractSubItem(payload, ORGANIZATION, ID),
- extractSubItem(payload, REPOSITORY, ID)));
- } else if (pullState != null && pullState.equals(PULL_REQUEST_VALIDATED)) {
- return Arrays.asList(new Event(PULL_REQUEST_VALIDATED_EVENT_NAME,
- extractSubItem(payload, PULL_REQUEST, USER, LOGIN),
- extractSubItem(payload, PULL_REQUEST, USER, LOGIN),
- extractSubItem(payload, PULL_REQUEST_REVIEW, HTML_URL),
- PR_TYPE,
- extractSubItem(payload, ORGANIZATION, ID),
- extractSubItem(payload, REPOSITORY, ID)),
- new Event(VALIDATE_PULL_REQUEST_EVENT_NAME,
- extractSubItem(payload, PULL_REQUEST_REVIEW, USER, LOGIN),
- extractSubItem(payload, PULL_REQUEST_REVIEW, USER, LOGIN),
- extractSubItem(payload, PULL_REQUEST_REVIEW, HTML_URL),
- PR_TYPE,
- extractSubItem(payload, ORGANIZATION, ID),
- extractSubItem(payload, REPOSITORY, ID)));
- }
- return Collections.emptyList();
- }
-}
diff --git a/gamification-github-services/src/main/java/io/meeds/gamification/github/rest/HooksManagementRest.java b/gamification-github-services/src/main/java/io/meeds/gamification/github/rest/HooksManagementRest.java
deleted file mode 100644
index 1fbf91efc..000000000
--- a/gamification-github-services/src/main/java/io/meeds/gamification/github/rest/HooksManagementRest.java
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * This file is part of the Meeds project (https://meeds.io/).
- *
- * Copyright (C) 2020 - 2022 Meeds Lab contact@meedslab.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package io.meeds.gamification.github.rest;
-
-import javax.annotation.security.RolesAllowed;
-import javax.ws.rs.*;
-import javax.ws.rs.core.*;
-
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-import org.apache.commons.lang3.StringUtils;
-
-import org.exoplatform.commons.ObjectAlreadyExistsException;
-import org.exoplatform.commons.exception.ObjectNotFoundException;
-import io.meeds.gamification.github.model.RemoteRepository;
-import io.meeds.gamification.github.model.WebHook;
-import io.meeds.gamification.github.rest.builder.WebHookBuilder;
-import io.meeds.gamification.github.rest.model.RepositoryList;
-import io.meeds.gamification.github.rest.model.WebHookList;
-import io.meeds.gamification.github.rest.model.WebHookRestEntity;
-import io.meeds.gamification.github.services.GithubConsumerService;
-import io.meeds.gamification.github.services.WebhookService;
-import org.exoplatform.services.rest.http.PATCH;
-import org.exoplatform.services.rest.resource.ResourceContainer;
-import org.exoplatform.services.security.ConversationState;
-
-import java.util.Collection;
-import java.util.List;
-
-import static io.meeds.gamification.utils.Utils.getCurrentUser;
-
-@Path("/gamification/connectors/github/hooks")
-public class HooksManagementRest implements ResourceContainer {
-
- public static final String GITHUB_HOOK_NOT_FOUND = "The GitHub hook doesn't exit";
-
- private final WebhookService webhookService;
-
- private final GithubConsumerService githubConsumerService;
-
- public HooksManagementRest(WebhookService webhookService, GithubConsumerService githubConsumerService) {
- this.webhookService = webhookService;
- this.githubConsumerService = githubConsumerService;
- }
-
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- @RolesAllowed("users")
- @Operation(summary = "Retrieves the list GitHub webHooks", method = "GET")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Request fulfilled"),
- @ApiResponse(responseCode = "401", description = "Unauthorized operation"), })
- public Response getWebHooks(@QueryParam("offset") int offset,
- @Parameter(description = "Query results limit", required = true) @QueryParam("limit") int limit,
- @Parameter(description = "WebHook total size") @Schema(defaultValue = "false") @QueryParam("returnSize") boolean returnSize) {
-
- String currentUser = getCurrentUser();
- List webHookRestEntities;
- try {
- WebHookList webHookList = new WebHookList();
- webHookRestEntities = getWebHookRestEntities(currentUser);
- if (returnSize) {
- int webHookSize = webhookService.countWebhooks(currentUser, false);
- webHookList.setSize(webHookSize);
- }
- webHookList.setWebhooks(webHookRestEntities);
- webHookList.setOffset(offset);
- webHookList.setLimit(limit);
- return Response.ok(webHookList).build();
- } catch (IllegalAccessException e) {
- return Response.status(Response.Status.UNAUTHORIZED).build();
- }
- }
-
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- @Path("{webHookId}")
- @RolesAllowed("users")
- @Operation(summary = "Retrieves a webHook by its technical identifier", method = "GET")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Request fulfilled"),
- @ApiResponse(responseCode = "401", description = "Unauthorized operation"),
- @ApiResponse(responseCode = "400", description = "Invalid query input"),
- @ApiResponse(responseCode = "404", description = "Not found"),
- @ApiResponse(responseCode = "500", description = "Internal server error"), })
- public Response getWebHookById(@Parameter(description = "WebHook technical identifier", required = true) @PathParam("webHookId") long webHookId) {
- if (webHookId == 0) {
- return Response.status(Response.Status.BAD_REQUEST).entity("WebHook Id must be not null").build();
- }
- String currentUser = getCurrentUser();
- try {
- WebHook webHook = webhookService.getWebhookId(webHookId, currentUser);
- return Response.ok(WebHookBuilder.toRestEntity(webhookService, githubConsumerService, webHook)).build();
- } catch (IllegalArgumentException e) {
- return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
- } catch (IllegalAccessException e) {
- return Response.status(Response.Status.UNAUTHORIZED).entity(e.getMessage()).build();
- } catch (ObjectNotFoundException e) {
- return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
- }
- }
-
- @POST
- @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @RolesAllowed("users")
- @Operation(summary = "Create a organization webhook for Remote GitHub connector.", description = "Create a organization webhook for Remote GitHub connector.", method = "POST")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Request fulfilled"),
- @ApiResponse(responseCode = "400", description = "Invalid query input"),
- @ApiResponse(responseCode = "401", description = "Unauthorized operation"),
- @ApiResponse(responseCode = "500", description = "Internal server error") })
- public Response createWebhookHook(@Parameter(description = "GitHub organization name", required = true) @FormParam("organizationName") String organizationName,
- @Parameter(description = "GitHub personal access token", required = true) @FormParam("accessToken") String accessToken) {
-
- if (StringUtils.isBlank(organizationName)) {
- return Response.status(Response.Status.BAD_REQUEST).entity("'organizationName' parameter is mandatory").build();
- }
- if (StringUtils.isBlank(accessToken)) {
- return Response.status(Response.Status.BAD_REQUEST).entity("'accessToken' parameter is mandatory").build();
- }
- String currentUser = ConversationState.getCurrent().getIdentity().getUserId();
- try {
- webhookService.createWebhook(organizationName, accessToken, currentUser);
- return Response.status(Response.Status.CREATED).build();
- } catch (IllegalAccessException e) {
- return Response.status(Response.Status.UNAUTHORIZED).entity(e.getMessage()).build();
- } catch (ObjectAlreadyExistsException e) {
- return Response.status(Response.Status.CONFLICT).entity(e.getMessage()).build();
- } catch (ObjectNotFoundException e) {
- return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
- }
- }
-
- @PATCH
- @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @RolesAllowed("users")
- @Operation(summary = "Update a organization webhook personal access token.", description = "Update a organization webhook personal access token.", method = "PATCH")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Request fulfilled"),
- @ApiResponse(responseCode = "400", description = "Invalid query input"),
- @ApiResponse(responseCode = "401", description = "Unauthorized operation"),
- @ApiResponse(responseCode = "500", description = "Internal server error") })
- public Response updateWebHookAccessToken(@Parameter(description = "webHook id", required = true) @FormParam("webHookId") long webHookId,
- @Parameter(description = "GitHub personal access token", required = true) @FormParam("accessToken") String accessToken) {
-
- if (webHookId <= 0) {
- return Response.status(Response.Status.BAD_REQUEST).entity("'webHookId' must be positive").build();
- }
- if (StringUtils.isBlank(accessToken)) {
- return Response.status(Response.Status.BAD_REQUEST).entity("'accessToken' parameter is mandatory").build();
- }
- String currentUser = ConversationState.getCurrent().getIdentity().getUserId();
- try {
- webhookService.updateWebHookAccessToken(webHookId, accessToken, currentUser);
- return Response.status(Response.Status.CREATED).build();
- } catch (IllegalAccessException e) {
- return Response.status(Response.Status.UNAUTHORIZED).entity(e.getMessage()).build();
- } catch (ObjectNotFoundException e) {
- return Response.status(Response.Status.NOT_FOUND).entity(GITHUB_HOOK_NOT_FOUND).build();
- }
- }
-
- @DELETE
- @Path("{organizationId}")
- @RolesAllowed("users")
- @Operation(summary = "Deletes gitHub organization webhook", description = "Deletes gitHub organization webhook", method = "DELETE")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "204", description = "Request fulfilled"),
- @ApiResponse(responseCode = "400", description = "Bad request"),
- @ApiResponse(responseCode = "401", description = "Unauthorized operation"),
- @ApiResponse(responseCode = "500", description = "Internal server error"), })
- public Response deleteWebhookHook(@Parameter(description = "GitHub organization id", required = true) @PathParam("organizationId") long organizationId) {
- if (organizationId <= 0) {
- return Response.status(Response.Status.BAD_REQUEST).entity("'hookName' parameter is mandatory").build();
- }
- String currentUser = ConversationState.getCurrent().getIdentity().getUserId();
- try {
- webhookService.deleteWebhook(organizationId, currentUser);
- return Response.noContent().build();
- } catch (IllegalAccessException e) {
- return Response.status(Response.Status.UNAUTHORIZED).entity(e.getMessage()).type(MediaType.TEXT_PLAIN).build();
- } catch (ObjectNotFoundException e) {
- return Response.status(Response.Status.NOT_FOUND).entity(GITHUB_HOOK_NOT_FOUND).build();
- }
- }
-
- @GET
- @Path("{organizationId}/repos")
- @Produces(MediaType.APPLICATION_JSON)
- @RolesAllowed("users")
- @Operation(summary = "Retrieves the list GitHub organization repositories", method = "GET")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Request fulfilled"),
- @ApiResponse(responseCode = "401", description = "Unauthorized operation"), })
- public Response getWebHookRepos(@Parameter(description = "GitHub organization id", required = true) @PathParam("organizationId") long organizationId,
- @Parameter(description = "Query page number", required = true) @QueryParam("page") int page,
- @Parameter(description = "Query item per page", required = true) @QueryParam("perPage") int perPage,
- @Parameter(description = "Keyword to search in repositories title", required = true) @QueryParam("keyword") String keyword) {
-
- String currentUser = getCurrentUser();
- List remoteRepositories;
- try {
- RepositoryList repositoryList = new RepositoryList();
- remoteRepositories = webhookService.retrieveOrganizationRepos(organizationId, currentUser, page, perPage, keyword);
- repositoryList.setRemoteRepositories(remoteRepositories);
- repositoryList.setPage(page);
- repositoryList.setPerPage(perPage);
- return Response.ok(repositoryList).build();
- } catch (IllegalAccessException e) {
- return Response.status(Response.Status.UNAUTHORIZED).build();
- } catch (ObjectNotFoundException e) {
- return Response.status(Response.Status.NOT_FOUND).entity(GITHUB_HOOK_NOT_FOUND).build();
- }
- }
-
- @Path("repo/status")
- @POST
- @RolesAllowed("users")
- @Operation(summary = "enables/disables webhook repository.", description = "enables/disables webhook repository", method = "POST")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "204", description = "Request fulfilled"),
- @ApiResponse(responseCode = "400", description = "Bad request"),
- @ApiResponse(responseCode = "401", description = "Unauthorized operation"),
- @ApiResponse(responseCode = "500", description = "Internal server error"), })
- public Response updateWebHookRepoStatus(@Parameter(description = "GitHub organization remote Id", required = true) @FormParam("organizationId") long organizationId,
- @Parameter(description = "Organization repository remote Id", required = true) @FormParam("repositoryId") long repositoryId,
- @Parameter(description = "Organization repository status enabled/disabled. possible values: true for enabled, else false", required = true) @FormParam("enabled") boolean enabled) {
-
- String currentUser = getCurrentUser();
- try {
- webhookService.setWebHookRepositoryEnabled(organizationId, repositoryId, enabled, currentUser);
- return Response.noContent().build();
- } catch (IllegalAccessException e) {
- return Response.status(Response.Status.UNAUTHORIZED).entity(e.getMessage()).type(MediaType.TEXT_PLAIN).build();
- }
- }
-
- @Path("watchScope/status")
- @POST
- @RolesAllowed("users")
- @Operation(summary = "Limit webhook watch scope or not", description = "Limit webhook watch scope or not", method = "POST")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "204", description = "Request fulfilled"),
- @ApiResponse(responseCode = "400", description = "Bad request"),
- @ApiResponse(responseCode = "401", description = "Unauthorized operation"),
- @ApiResponse(responseCode = "500", description = "Internal server error"), })
- public Response updateWebHookWatchScope(@Parameter(description = "GitHub organization remote Id", required = true) @FormParam("organizationId") long organizationId,
- @Parameter(description = "webhook watch scope limited status enabled/disabled. possible values: true for enabled, else false", required = true) @FormParam("enabled") boolean enabled) {
-
- String currentUser = getCurrentUser();
- try {
- webhookService.setWebHookWatchLimitEnabled(organizationId, enabled, currentUser);
- return Response.noContent().build();
- } catch (IllegalAccessException e) {
- return Response.status(Response.Status.UNAUTHORIZED).entity(e.getMessage()).type(MediaType.TEXT_PLAIN).build();
- }
- }
-
- @Path("forceUpdate")
- @PATCH
- @RolesAllowed("users")
- @Operation(summary = "Force Update a github stored webhooks", description = "Force Update a github stored webhooks", method = "PATCH")
- @ApiResponses(value = { @ApiResponse(responseCode = "500", description = "Internal server error") })
- public Response forceUpdateWebhooks() {
- try {
- webhookService.forceUpdateWebhooks();
- return Response.noContent().build();
- } catch (Exception e) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
- }
- }
-
- private List getWebHookRestEntities(String username) throws IllegalAccessException {
- Collection webHooks = webhookService.getWebhooks(username, 0, 20, false);
- return WebHookBuilder.toRestEntities(webhookService, githubConsumerService, webHooks);
- }
-}
diff --git a/gamification-github-services/src/main/java/io/meeds/gamification/github/storage/cached/GithubConsumerCachedStorage.java b/gamification-github-services/src/main/java/io/meeds/gamification/github/storage/cached/GithubConsumerCachedStorage.java
deleted file mode 100644
index e67d93a26..000000000
--- a/gamification-github-services/src/main/java/io/meeds/gamification/github/storage/cached/GithubConsumerCachedStorage.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * This file is part of the Meeds project (https://meeds.io/).
- *
- * Copyright (C) 2020 - 2023 Meeds Lab contact@meedslab.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package io.meeds.gamification.github.storage.cached;
-
-import io.meeds.gamification.github.model.RemoteOrganization;
-import io.meeds.gamification.github.model.WebHook;
-import io.meeds.gamification.github.storage.cached.model.CacheKey;
-import org.exoplatform.commons.cache.future.FutureExoCache;
-import io.meeds.gamification.github.model.RemoteRepository;
-import io.meeds.gamification.github.model.TokenStatus;
-import io.meeds.gamification.github.storage.GithubConsumerStorage;
-import org.exoplatform.services.cache.CacheService;
-import org.exoplatform.services.cache.ExoCache;
-
-import java.io.Serializable;
-import java.util.*;
-
-public class GithubConsumerCachedStorage extends GithubConsumerStorage {
-
- public static final String GITHUB_CACHE_NAME = "github.connector";
-
- private static final int ORG_REPOS_CONTEXT = 0;
-
- private static final int ORG_BY_ID_CONTEXT = 1;
-
- private static final int TOKEN_STATUS_CONTEXT = 2;
-
- private final FutureExoCache githubFutureCache;
-
- public GithubConsumerCachedStorage(CacheService cacheService) {
- ExoCache cacheInstance = cacheService.getCacheInstance(GITHUB_CACHE_NAME);
- this.githubFutureCache = new FutureExoCache<>((context, key) -> {
- if (ORG_REPOS_CONTEXT == context.getContext()) {
- return GithubConsumerCachedStorage.super.retrieveOrganizationRepos(context.getOrganizationName(),
- context.getAccessToken(),
- context.getPage(),
- context.getPerPage(),
- context.getKeyword());
- } else if (ORG_BY_ID_CONTEXT == context.getContext()) {
- return GithubConsumerCachedStorage.super.retrieveRemoteOrganization(context.getOrganizationId(),
- context.getAccessToken());
- } else if (TOKEN_STATUS_CONTEXT == context.getContext()) {
- return GithubConsumerCachedStorage.super.checkGitHubTokenStatus(context.getAccessToken());
- } else {
- throw new UnsupportedOperationException();
- }
- }, cacheInstance);
- }
-
- @Override
- public String deleteWebhookHook(WebHook webHook) {
- try {
- return super.deleteWebhookHook(webHook);
- } finally {
- clearCache(webHook);
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public List retrieveOrganizationRepos(String organizationName,
- String accessToken,
- int page,
- int perPage,
- String keyword) {
- CacheKey cacheKey = new CacheKey(ORG_REPOS_CONTEXT, organizationName, accessToken, page, perPage, keyword);
- List remoteRepositories =
- (List) this.githubFutureCache.get(cacheKey, cacheKey.hashCode());
- return remoteRepositories == null ? Collections.emptyList() : remoteRepositories;
- }
-
- @Override
- public RemoteOrganization retrieveRemoteOrganization(long organizationId, String accessToken) {
- CacheKey cacheKey = new CacheKey(ORG_BY_ID_CONTEXT, organizationId, accessToken);
- return (RemoteOrganization) this.githubFutureCache.get(cacheKey, cacheKey.hashCode());
- }
-
- @Override
- public TokenStatus checkGitHubTokenStatus(String token) {
- CacheKey cacheKey = new CacheKey(TOKEN_STATUS_CONTEXT, token);
- return (TokenStatus) this.githubFutureCache.get(cacheKey, cacheKey.hashCode());
- }
-
- @Override
- public void clearCache() {
- this.githubFutureCache.clear();
- }
-
- @Override
- public void clearCache(WebHook webHook) {
- this.githubFutureCache.remove(new CacheKey(ORG_BY_ID_CONTEXT, webHook.getOrganizationId(), webHook.getToken()).hashCode());
- this.githubFutureCache.remove(new CacheKey(TOKEN_STATUS_CONTEXT, webHook.getToken()).hashCode());
- }
-}
diff --git a/gamification-github-services/src/main/java/io/meeds/gamification/github/storage/cached/model/CacheKey.java b/gamification-github-services/src/main/java/io/meeds/gamification/github/storage/cached/model/CacheKey.java
deleted file mode 100644
index 7a0186e47..000000000
--- a/gamification-github-services/src/main/java/io/meeds/gamification/github/storage/cached/model/CacheKey.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * This file is part of the Meeds project (https://meeds.io/).
- *
- * Copyright (C) 2022 Meeds Lab contact@meedslab.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package io.meeds.gamification.github.storage.cached.model;
-
-import java.io.Serializable;
-
-import io.meeds.gamification.model.filter.ProgramFilter;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@AllArgsConstructor
-@NoArgsConstructor
-@Data
-public class CacheKey implements Serializable {
-
- private static final long serialVersionUID = -8995567724453740730L;
-
- private ProgramFilter programFilter;
-
- private int page;
-
- private int perPage;
-
- private long organizationId;
-
- private String organizationName;
-
- private String accessToken;
-
- private String keyword;
-
- private Integer context;
-
- public CacheKey(Integer context, String organizationName, String accessToken, int page, int perPage, String keyword) {
- this.organizationName = organizationName;
- this.accessToken = accessToken;
- this.page = page;
- this.perPage = perPage;
- this.keyword = keyword;
- this.context = context;
- }
-
- public CacheKey(Integer context, long organizationId, String accessToken) {
- this.organizationId = organizationId;
- this.accessToken = accessToken;
- this.context = context;
- }
-
- public CacheKey(Integer context, String accessToken) {
- this.accessToken = accessToken;
- this.context = context;
- }
-
-}
diff --git a/gamification-github-services/src/main/java/io/meeds/github/gamification/dao/WebHookDAO.java b/gamification-github-services/src/main/java/io/meeds/github/gamification/dao/WebHookDAO.java
new file mode 100644
index 000000000..7ed22a753
--- /dev/null
+++ b/gamification-github-services/src/main/java/io/meeds/github/gamification/dao/WebHookDAO.java
@@ -0,0 +1,27 @@
+/*
+ * This file is part of the Meeds project (https://meeds.io/).
+ *
+ * Copyright (C) 2020 - 2023 Meeds Lab contact@meedslab.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package io.meeds.github.gamification.dao;
+
+import io.meeds.github.gamification.entity.WebhookEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface WebHookDAO extends JpaRepository {
+
+ WebhookEntity findWebhookEntityByOrganizationId(long organizationId);
+}
diff --git a/gamification-github-services/src/main/java/io/meeds/gamification/github/entity/WebhookEntity.java b/gamification-github-services/src/main/java/io/meeds/github/gamification/entity/WebhookEntity.java
similarity index 83%
rename from gamification-github-services/src/main/java/io/meeds/gamification/github/entity/WebhookEntity.java
rename to gamification-github-services/src/main/java/io/meeds/github/gamification/entity/WebhookEntity.java
index 75c8ca471..0e8ce2cc3 100644
--- a/gamification-github-services/src/main/java/io/meeds/gamification/github/entity/WebhookEntity.java
+++ b/gamification-github-services/src/main/java/io/meeds/github/gamification/entity/WebhookEntity.java
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package io.meeds.gamification.github.entity;
+package io.meeds.github.gamification.entity;
import java.io.Serializable;
import java.util.Date;
@@ -29,12 +29,6 @@
@Entity(name = "GitHubWebhooks")
@Table(name = "GITHUB_WEBHOOKS")
-@NamedQuery(name = "GitHubWebhooks.getWebhookByOrganizationId",
- query = "SELECT gitHubWebhook FROM GitHubWebhooks gitHubWebhook"
- + " WHERE gitHubWebhook.organizationId = :organizationId")
-@NamedQuery(name = "GitHubWebhooks.getWebhookIds",
- query = "SELECT gitHubWebhook.id FROM GitHubWebhooks gitHubWebhook"
- + " ORDER BY gitHubWebhook.id ASC")
@Data
public class WebhookEntity implements Serializable {
@@ -53,7 +47,7 @@ public class WebhookEntity implements Serializable {
private Long organizationId;
@Column(name = "ORGANIZATION_NAME", nullable = false)
- private String organizationName;
+ private String organizationName;
@Convert(converter = StringListConverter.class)
@Column(name = "TRIGGERS", nullable = false)
diff --git a/gamification-github-services/src/main/java/io/meeds/gamification/github/exception/GithubConnectionException.java b/gamification-github-services/src/main/java/io/meeds/github/gamification/exception/GithubConnectionException.java
similarity index 96%
rename from gamification-github-services/src/main/java/io/meeds/gamification/github/exception/GithubConnectionException.java
rename to gamification-github-services/src/main/java/io/meeds/github/gamification/exception/GithubConnectionException.java
index f7a0f774b..06080daa6 100644
--- a/gamification-github-services/src/main/java/io/meeds/gamification/github/exception/GithubConnectionException.java
+++ b/gamification-github-services/src/main/java/io/meeds/github/gamification/exception/GithubConnectionException.java
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package io.meeds.gamification.github.exception;
+package io.meeds.github.gamification.exception;
public class GithubConnectionException extends Exception {
diff --git a/gamification-github-services/src/main/java/io/meeds/gamification/github/listener/GithubEventsListener.java b/gamification-github-services/src/main/java/io/meeds/github/gamification/listener/GithubEventsListener.java
similarity index 77%
rename from gamification-github-services/src/main/java/io/meeds/gamification/github/listener/GithubEventsListener.java
rename to gamification-github-services/src/main/java/io/meeds/github/gamification/listener/GithubEventsListener.java
index bbd177c1a..a85a648ee 100644
--- a/gamification-github-services/src/main/java/io/meeds/gamification/github/listener/GithubEventsListener.java
+++ b/gamification-github-services/src/main/java/io/meeds/github/gamification/listener/GithubEventsListener.java
@@ -16,32 +16,42 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package io.meeds.gamification.github.listener;
+package io.meeds.github.gamification.listener;
import java.util.HashMap;
import java.util.Map;
+import jakarta.annotation.PostConstruct;
import org.exoplatform.services.listener.Event;
import org.exoplatform.services.listener.Listener;
import org.exoplatform.services.listener.ListenerService;
+import org.springframework.stereotype.Component;
+import org.springframework.beans.factory.annotation.Autowired;
-import static io.meeds.gamification.github.utils.Utils.GITHUB_ACTION_EVENT;
-import static io.meeds.gamification.github.utils.Utils.GITHUB_CANCEL_ACTION_EVENT;
+import static io.meeds.github.gamification.utils.Utils.GITHUB_ACTION_EVENT;
+import static io.meeds.github.gamification.utils.Utils.GITHUB_CANCEL_ACTION_EVENT;
+@Component
public class GithubEventsListener extends Listener