-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate To Spring Services - Meeds-io/MIPs#132 (#500)
This proceed to migrate all Kudos API to use Spring DI instead of Kernel.
- Loading branch information
Showing
72 changed files
with
2,858 additions
and
3,258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 | ||
|
@@ -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); | ||
} | ||
} | ||
|
||
|
@@ -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; | ||
} | ||
|
||
} |
100 changes: 100 additions & 0 deletions
100
kudos-services/src/main/java/io/meeds/kudos/activity/processor/ActivityKudosProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
96
kudos-services/src/main/java/io/meeds/kudos/dao/KudosDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
Oops, something went wrong.