Skip to content

Commit

Permalink
feat: Crowdin connector Improve & clean code - Meeds-io/MIPs#121
Browse files Browse the repository at this point in the history
  • Loading branch information
AzmiTouil committed May 14, 2024
1 parent 7b4b0ff commit ff2d7dd
Show file tree
Hide file tree
Showing 53 changed files with 2,029 additions and 1,842 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2023 Meeds Lab [email protected]
*
* Copyright (C) 2020 - 2024 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
Expand All @@ -9,43 +11,17 @@
* 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.crowdin.dao;

import io.meeds.gamification.crowdin.entity.WebhookEntity;
import jakarta.persistence.NoResultException;
import jakarta.persistence.TypedQuery;
import org.exoplatform.commons.persistence.impl.GenericDAOJPAImpl;
import org.springframework.stereotype.Component;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
@Component
public class WebHookDAO extends GenericDAOJPAImpl<WebhookEntity, Long> {
public interface WebHookDAO extends JpaRepository<WebhookEntity, Long> {

public static final String PROJECT_ID = "projectId";

public WebhookEntity getWebhookByProjectId(long projectId) {
TypedQuery<WebhookEntity> query = getEntityManager().createNamedQuery("CrowdinWebhooks.getWebhookByProjectId",
WebhookEntity.class);
query.setParameter(PROJECT_ID, projectId);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

public List<Long> getWebhookIds(int offset, int limit) {
TypedQuery<Long> query = getEntityManager().createNamedQuery("CrowdinWebhooks.getWebhookIds", Long.class);
if (offset > 0) {
query.setFirstResult(offset);
}
if (limit > 0) {
query.setMaxResults(limit);
}
return query.getResultList();
}
WebhookEntity findWebhookEntityByProjectId(long projectId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2023 Meeds Lab [email protected]
*
* Copyright (C) 2020 - 2024 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
Expand All @@ -9,30 +11,23 @@
* 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.crowdin.entity;

import jakarta.persistence.*;
import lombok.Data;
import org.exoplatform.commons.api.persistence.ExoEntity;
import org.exoplatform.commons.utils.StringListConverter;

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

import jakarta.persistence.*;
import lombok.Data;
import org.exoplatform.commons.utils.StringListConverter;

@Entity(name = "CrowdinWebhooks")
@ExoEntity
@Table(name = "CROWDIN_WEBHOOKS")
@NamedQuery(name = "CrowdinWebhooks.getWebhookByProjectId",
query = "SELECT crowdinWebhook FROM CrowdinWebhooks crowdinWebhook"
+ " WHERE crowdinWebhook.projectId = :projectId")
@NamedQuery(name = "CrowdinWebhooks.getWebhookIds",
query = "SELECT crowdinWebhook.id FROM CrowdinWebhooks crowdinWebhook"
+ " ORDER BY crowdinWebhook.id ASC")
@Data
public class WebhookEntity implements Serializable {

Expand All @@ -51,7 +46,7 @@ public class WebhookEntity implements Serializable {
private Long projectId;

@Column(name = "PROJECT_NAME", nullable = false)
private String projectName;
private String projectName;

@Convert(converter = StringListConverter.class)
@Column(name = "TRIGGERS", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 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 io.meeds.gamification.crowdin.exception;

public class CrowdinConnectionException extends Exception {

private static final long serialVersionUID = -2437500058122638710L;
private static final long serialVersionUID = -2437500058122638710L;

public CrowdinConnectionException(String e) {
super(e);
}

public CrowdinConnectionException(String message, Exception e) {
super(message, e);
}
public CrowdinConnectionException(String e) {
super(e);
}

public CrowdinConnectionException(String message, Exception e) {
super(message, e);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2023 Meeds Lab contact@meedslab.com
* Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -11,6 +11,7 @@
* 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.
Expand All @@ -26,23 +27,23 @@
@AllArgsConstructor
public class Event {

String name;
String name;

String sender;
String sender;

String receiver;
String receiver;

String objectId;
String objectId;

String objectType;
String objectType;

String projectId;
String projectId;

String languageId;
String languageId;

boolean mustBeHuman;

String directoryId;
String directoryId;

boolean isCancelling;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 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 io.meeds.gamification.crowdin.model;

import lombok.AllArgsConstructor;
Expand All @@ -8,7 +26,10 @@
@AllArgsConstructor
@NoArgsConstructor
public class RemoteDirectory {
private long id;
private long projectId;
private String path;

private long id;

private long projectId;

private String path;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 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 io.meeds.gamification.crowdin.model;

import lombok.AllArgsConstructor;
Expand All @@ -8,6 +26,8 @@
@AllArgsConstructor
@NoArgsConstructor
public class RemoteLanguage {
private String id;
private String name;

private String id;

private String name;
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 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 io.meeds.gamification.crowdin.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class RemoteProject implements Cloneable {
private long id;
private String identifier;
private String name;
private String description;
private String avatarUrl;
private List<RemoteLanguage> languages;

@Override
public RemoteProject clone() {
return new RemoteProject(id, identifier, name, description, avatarUrl, languages);
}

private long id;

private String identifier;

private String name;

private String description;

private String avatarUrl;

private List<RemoteLanguage> languages;

@Override
public RemoteProject clone() { // NOSONAR
return new RemoteProject(id, identifier, name, description, avatarUrl, languages);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2023 Meeds Lab
* [email protected]
*
* Copyright (C) 2020 - 2024 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
* 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.
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.meeds.gamification.crowdin.model;

Expand Down
Loading

0 comments on commit ff2d7dd

Please sign in to comment.