Skip to content

Commit

Permalink
feat: Migrate To Spring Services - Meeds-io/MIPs#132 (#500)
Browse files Browse the repository at this point in the history
This proceed to migrate all Kudos API to use Spring DI instead of
Kernel.
  • Loading branch information
boubaker authored and exo-swf committed Jun 18, 2024
1 parent 3cb0de4 commit 414edbd
Show file tree
Hide file tree
Showing 72 changed files with 2,858 additions and 3,258 deletions.
60 changes: 11 additions & 49 deletions kudos-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,57 +41,19 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<finalName>kudos-services</finalName>
<plugins>
<plugin>
<groupId>io.openapitools.swagger</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<configuration>
<useResourcePackagesChildren>true</useResourcePackagesChildren>
<resourcePackages>
<locations>org.exoplatform.kudos.rest</locations>
</resourcePackages>
<swaggerConfig>
<info>
<title>${rest.api.doc.title}</title>
<version>${rest.api.doc.version}</version>
<description>${rest.api.doc.description}</description>
<license>
<url>https://www.gnu.org/licenses/lgpl-3.0.en.html</url>
<name>LGPL</name>
</license>
</info>
</swaggerConfig>
</configuration>
</plugin>
<plugin>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<exo.properties.url>classpath:/conf/configuration.properties</exo.properties.url>
<exo.profiles>hsqldb</exo.profiles>
<org.apache.commons.logging.Log>org.apache.commons.logging.impl.SimpleLog</org.apache.commons.logging.Log>
<org.apache.commons.logging.simplelog.defaultlog>info</org.apache.commons.logging.simplelog.defaultlog>
<org.apache.commons.logging.simplelog.log.org.exoplatform>debug</org.apache.commons.logging.simplelog.log.org.exoplatform>
<org.apache.commons.logging.simplelog.log.net.hibernate>warn</org.apache.commons.logging.simplelog.log.net.hibernate>
<java.naming.factory.initial>org.exoplatform.services.naming.SimpleContextFactory</java.naming.factory.initial>
<java.util.logging.config.class>org.exoplatform.services.log.impl.SimpleExoLogConfigurator</java.util.logging.config.class>
<exo.profiles>hsqldb</exo.profiles>
<com.arjuna.ats.arjuna.objectstore.objectStoreDir>${project.build.directory}</com.arjuna.ats.arjuna.objectstore.objectStoreDir>
<ObjectStoreEnvironmentBean.objectStoreDir>${project.build.directory}</ObjectStoreEnvironmentBean.objectStoreDir>
<gatein.test.tmp.dir>${project.build.directory}</gatein.test.tmp.dir>
<gatein.test.output.path>${project.build.directory}</gatein.test.output.path>
<exo.files.storage.dir>target/files</exo.files.storage.dir>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
/*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2023 Meeds Association [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 @@ -11,29 +11,46 @@
* 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.kudos.activity;
package io.meeds.kudos.activity;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import org.exoplatform.container.xml.InitParams;
import org.exoplatform.kudos.model.Kudos;
import org.exoplatform.kudos.service.KudosService;
import org.exoplatform.container.xml.ValueParam;
import org.exoplatform.social.core.ActivityTypePlugin;
import org.exoplatform.social.core.activity.model.ExoSocialActivity;
import org.exoplatform.social.core.manager.ActivityManager;
import org.exoplatform.social.core.utils.MentionUtils;

import io.meeds.kudos.model.Kudos;
import io.meeds.kudos.service.KudosService;
import io.meeds.kudos.service.utils.Utils;

import jakarta.annotation.PostConstruct;

@Component
public class KudosActivityTypePlugin extends ActivityTypePlugin {

private KudosService kudosService;
@Autowired
private ActivityManager activityManager;

public KudosActivityTypePlugin(KudosService kudosService,
InitParams params) {
super(params);
this.kudosService = kudosService;
@Autowired
private KudosService kudosService;

public KudosActivityTypePlugin() {
super(initParams());
}

@PostConstruct
public void init() {
activityManager.addActivityTypePlugin(this);
}

@Override
Expand All @@ -43,8 +60,8 @@ public boolean isEnableNotification(ExoSocialActivity activity, String username)
} else {
Kudos kudos = this.kudosService.getKudosByActivityId(Long.parseLong(activity.getId().replace("comment", "")));
return kudos != null
&& !StringUtils.equals(kudos.getReceiverId(), username)
&& !StringUtils.equals(kudos.getSenderId(), username);
&& !StringUtils.equals(kudos.getReceiverId(), username)
&& !StringUtils.equals(kudos.getSenderId(), username);
}
}

Expand All @@ -54,4 +71,17 @@ public String getActivityTitle(ExoSocialActivity activity) {
return kudos == null ? activity.getTitle() : MentionUtils.substituteUsernames(kudos.getMessage());
}

private static InitParams initParams() {
InitParams initParams = new InitParams();
ValueParam param = new ValueParam();
param.setName("type");
param.setValue(Utils.KUDOS_ACTIVITY_COMMENT_TYPE);
initParams.addParameter(param);
param = new ValueParam();
param.setName("enableNotification");
param.setValue("true");
initParams.addParameter(param);
return initParams;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.kudos.activity.processor;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.ValueParam;
import org.exoplatform.portal.config.UserPortalConfigService;
import org.exoplatform.social.core.BaseActivityProcessorPlugin;
import org.exoplatform.social.core.activity.model.ExoSocialActivity;
import org.exoplatform.social.core.manager.ActivityManager;
import org.exoplatform.social.core.utils.MentionUtils;

import io.meeds.kudos.model.Kudos;
import io.meeds.kudos.service.KudosService;

import jakarta.annotation.PostConstruct;

@Component
public class ActivityKudosProcessor extends BaseActivityProcessorPlugin {

@Autowired
private ActivityManager activityManager;

@Autowired
private UserPortalConfigService userPortalConfigService;

@Autowired
private KudosService kudosService;

private String defaultPortal;

public ActivityKudosProcessor() {
super(initParams());
}

@Override
public String getName() {
return "ActivityKudosProcessor";
}

@PostConstruct
public void init() {
defaultPortal = userPortalConfigService.getMetaPortal();
activityManager.addProcessor(this);
}

@Override
public void processActivity(ExoSocialActivity activity) {
if (activity.isComment()) {
return;
}
if (activity.getLinkedProcessedEntities() == null) {
activity.setLinkedProcessedEntities(new HashMap<>());
}
@SuppressWarnings("unchecked")
List<Kudos> linkedKudosList = (List<Kudos>) activity.getLinkedProcessedEntities().get("kudosList");
if (linkedKudosList == null) {
linkedKudosList = kudosService.getKudosListOfActivity(activity.getId());
activity.getLinkedProcessedEntities().put("kudosList", linkedKudosList);
}

if (linkedKudosList != null) {
for (Kudos kudos : linkedKudosList) {
kudos.setMessage(MentionUtils.substituteUsernames(defaultPortal, kudos.getMessage()));
}
}
}

private static InitParams initParams() {
InitParams initParams = new InitParams();
ValueParam param = new ValueParam();
param.setName("priority");
param.setValue("20");
initParams.addParameter(param);
return initParams;
}

}
96 changes: 96 additions & 0 deletions kudos-services/src/main/java/io/meeds/kudos/dao/KudosDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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.kudos.dao;

import java.util.List;

import org.springframework.data.domain.Limit;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import io.meeds.kudos.entity.KudosEntity;
import io.meeds.kudos.entity.KudosReceiverResult;

public interface KudosDAO extends JpaRepository<KudosEntity, Long> {

List<KudosEntity> findByCreatedDateBetweenOrderByCreatedDateDesc(long startDateInSeconds,
long endDateInSeconds,
Limit limit);

List<KudosEntity> findByCreatedDateBetweenAndEntityTypeOrderByCreatedDateDesc(long startDateInSeconds,
long endDateInSeconds,
int entityType,
Limit limit);

List<KudosEntity> findByEntityTypeAndEntityIdOrderByCreatedDateDesc(int entityType, long entityId, Limit limit);

List<KudosEntity> findByCreatedDateBetweenAndReceiverIdAndIsReceiverUserOrderByCreatedDateDesc(long startDateInSeconds,
long endDateInSeconds,
long receiverId,
boolean isReceiverUser,
Limit limit);

List<KudosEntity> findByCreatedDateBetweenAndSenderIdOrderByCreatedDateDesc(long startDateInSeconds,
long endDateInSeconds,
long senderId,
Limit limit);

KudosEntity findByActivityId(Long activityId);

@Query("""
SELECT k FROM Kudos k
WHERE
k.activityId = ?1
OR
(k.entityType in (?2) AND (k.parentEntityId = ?1 OR k.entityId in ?1))
""")
List<KudosEntity> findKudosListOfActivity(Long activityId, List<Integer> entityTypes);

long countByEntityTypeAndEntityId(int entityType, long entityId);

long countByEntityTypeAndEntityIdAndSenderId(int entityType, long entityId, long senderId);

long countByCreatedDateBetweenAndReceiverIdAndIsReceiverUser(long startDateInSeconds,
long endDateInSeconds,
long receiverId,
boolean isReceiverUser);

@Query("""
SELECT COUNT(k.id) FROM Kudos k
WHERE
k.activityId = ?1
OR
(k.entityType in (?2) AND (k.parentEntityId = ?1 OR k.entityId in ?1))
""")
long countKudosListOfActivity(Long activityId, List<Integer> entityTypes);

long countByCreatedDateBetweenAndSenderId(long startDateInSeconds, long endDateInSeconds, long senderId);

@Query("""
SELECT new io.meeds.kudos.entity.KudosReceiverResult(k.receiverId, COUNT(k)) from Kudos k
WHERE k.createdDate >= ?1
AND k.createdDate < ?2
AND k.receiverId IN ?3
GROUP BY k.receiverId
""")
List<KudosReceiverResult> countByCreatedDateBetweenAndReceiverIdIn(long startDateInSeconds,
long endDateInSeconds,
List<Long> receiversId);

}
Loading

0 comments on commit 414edbd

Please sign in to comment.