Skip to content

Commit

Permalink
PR Review
Browse files Browse the repository at this point in the history
  • Loading branch information
AzmiTouil committed Aug 1, 2023
1 parent e394e53 commit fefd7ef
Show file tree
Hide file tree
Showing 33 changed files with 1,710 additions and 791 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2020 - 2022 Meeds Association [email protected]
* 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 org.exoplatform.gamification.github.dao;

import org.apache.commons.collections.CollectionUtils;
import org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl;
import org.exoplatform.gamification.github.entity.WebhookEntity;

import javax.persistence.NoResultException;
import javax.persistence.Tuple;
import javax.persistence.TypedQuery;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

public class WebHookDAO extends GenericDAOJPAImpl<WebhookEntity, Long> {

public static final String ORGANIZATION_ID = "organizationId";

public WebhookEntity getWebhookByOrganizationId(long organizationId) {
TypedQuery<WebhookEntity> query = getEntityManager().createNamedQuery("GitHubWebhooks.getWebhookByOrganizationId",
WebhookEntity.class);
query.setParameter(ORGANIZATION_ID, organizationId);
query.setMaxResults(1);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

public List<Long> getWebhookIds(int offset, int limit) {
TypedQuery<Tuple> query = getEntityManager().createNamedQuery("GitHubWebhooks.getWebhookIds", Tuple.class);
List<Tuple> result = query.getResultList();
if (CollectionUtils.isEmpty(result)) {
return Collections.emptyList();
} else {
Stream<Long> resultStream = result.stream().map(tuple -> tuple.get(0, Long.class));
if (offset > 0) {
resultStream = resultStream.skip(offset);
}
if (limit > 0) {
resultStream = resultStream.limit(limit);
}
return resultStream.toList();
}
}

public String getWebHookHookSecret(long organizationId) {
TypedQuery<String> query = getEntityManager().createNamedQuery("GitHubWebhooks.getWebHookHookSecret", String.class);
query.setParameter(ORGANIZATION_ID, organizationId);
query.setMaxResults(1);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

public String getWebHookAccessToken(long organizationId) {
TypedQuery<String> query = getEntityManager().createNamedQuery("GitHubWebhooks.getWebHookAccessToken", String.class);
query.setParameter(ORGANIZATION_ID, organizationId);
query.setMaxResults(1);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2020 - 2023 Meeds Association [email protected]
* 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 org.exoplatform.gamification.github.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.*;

import org.exoplatform.commons.api.persistence.ExoEntity;

import lombok.Data;

@Entity(name = "GitHubWebhooks")
@ExoEntity
@Table(name = "GITHUB_WEBHOOKS")
@NamedQuery(
name = "GitHubWebhooks.getWebhookByOrganizationId",
query = "SELECT gitHubWebhook FROM GitHubWebhooks gitHubWebhook"
+ " WHERE gitHubWebhook.organizationId = :organizationId")
@NamedQuery(
name = "GitHubWebhooks.getWebHookHookSecret",
query = "SELECT gitHubWebhook.secret FROM GitHubWebhooks gitHubWebhook"
+ " WHERE gitHubWebhook.organizationId = :organizationId")
@NamedQuery(
name = "GitHubWebhooks.getWebHookAccessToken",
query = "SELECT gitHubWebhook.token FROM GitHubWebhooks gitHubWebhook"
+ " WHERE gitHubWebhook.organizationId = :organizationId")
@NamedQuery(
name = "GitHubWebhooks.getWebhookIds",
query = "SELECT gitHubWebhook.id FROM GitHubWebhooks gitHubWebhook")
@Data
public class WebhookEntity implements Serializable {

private static final long serialVersionUID = 2607146513663056421L;

@Id
@SequenceGenerator(name = "SEQ_GITHUB_WEBHOOKS_ID", sequenceName = "SEQ_GITHUB_WEBHOOKS_ID", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_GITHUB_WEBHOOKS_ID")
@Column(name = "ID")
protected Long id;

@Column(name = "WEBHOOK_ID")
protected Long webhookId;

@Column(name = "ORGANIZATION_ID", nullable = false)
protected Long organizationId;

@Column(name = "ENABLED", nullable = false)
protected Boolean enabled;

@Column(name = "WATCHED_DATE", nullable = false)
protected Date watchedDate;

@Column(name = "WATCHED_BY", nullable = false)
protected Long watchedBy;

@Column(name = "UPDATED_DATE", nullable = false)
protected Date updatedDate;

@Column(name = "SECRET", nullable = false)
private String secret;

@Column(name = "TOKEN", nullable = false)
private String token;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@

import java.util.Map;

import org.exoplatform.gamification.github.services.GithubHooksManagement;
import org.exoplatform.gamification.github.services.impl.WebhookServiceImpl;
import org.exoplatform.services.listener.Event;
import org.exoplatform.services.listener.Listener;

public class GithubEventsListener extends Listener<Map<String, String>, String> {

private GithubHooksManagement githubHooksManagement;
private final WebhookServiceImpl webhookService;

public GithubEventsListener(GithubHooksManagement githubHooksManagement) {
this.githubHooksManagement = githubHooksManagement;
public GithubEventsListener(WebhookServiceImpl webhookService) {
this.webhookService = webhookService;
}

@Override
public void onEvent(Event<Map<String, String>, String> event) throws Exception {
public void onEvent(Event<Map<String, String>, String> event) {
String ruleTitle = event.getSource().get("ruleTitle");
String senderId = event.getSource().get("senderId");
String receiverId = event.getSource().get("receiverId");
String object = event.getSource().get("object");
githubHooksManagement.createGamificationHistory(ruleTitle, senderId, receiverId, object);
webhookService.createGamificationHistory(ruleTitle, senderId, receiverId, object);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2020 - 2023 Meeds Association
* [email protected]
* 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 org.exoplatform.gamification.github.model;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class RemoteOrganization {

long id;

String name;

String title;

String description;

String avatarUrl;
}
Loading

0 comments on commit fefd7ef

Please sign in to comment.