-
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.
Browse files
Browse the repository at this point in the history
…Meeds-io/meeds#576 (#317) This change will allow to reuse Activity Notifications for Kudos Activities and comment but not for the receiver who will get one single specific notification.
- Loading branch information
Showing
7 changed files
with
331 additions
and
2 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
kudos-services/src/main/java/org/exoplatform/kudos/activity/KudosActivityTypePlugin.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,56 @@ | ||
/** | ||
* 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.kudos.activity; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import org.exoplatform.container.xml.InitParams; | ||
import org.exoplatform.kudos.model.Kudos; | ||
import org.exoplatform.kudos.service.KudosService; | ||
import org.exoplatform.social.core.ActivityTypePlugin; | ||
import org.exoplatform.social.core.activity.model.ExoSocialActivity; | ||
|
||
public class KudosActivityTypePlugin extends ActivityTypePlugin { | ||
|
||
private KudosService kudosService; | ||
|
||
public KudosActivityTypePlugin(KudosService kudosService, | ||
InitParams params) { | ||
super(params); | ||
this.kudosService = kudosService; | ||
} | ||
|
||
@Override | ||
public boolean isEnableNotification(ExoSocialActivity activity, String username) { | ||
if (StringUtils.isBlank(username)) { | ||
return false; | ||
} 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); | ||
} | ||
} | ||
|
||
@Override | ||
public String getActivityTitle(ExoSocialActivity activity) { | ||
Kudos kudos = this.kudosService.getKudosByActivityId(Long.parseLong(activity.getId().replace("comment", ""))); | ||
return kudos == null ? activity.getTitle() : kudos.getMessage(); | ||
} | ||
|
||
} |
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
68 changes: 68 additions & 0 deletions
68
...ces/src/main/java/org/exoplatform/kudos/notification/plugin/KudosActivityChildPlugin.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,68 @@ | ||
/** | ||
* 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.kudos.notification.plugin; | ||
|
||
import static org.exoplatform.kudos.service.utils.Utils.KUDOS_ACTIVITY_COMMENT_TYPE; | ||
|
||
import org.exoplatform.commons.api.notification.NotificationContext; | ||
import org.exoplatform.commons.api.notification.model.NotificationInfo; | ||
import org.exoplatform.commons.api.notification.plugin.AbstractNotificationChildPlugin; | ||
import org.exoplatform.commons.api.notification.service.template.TemplateContext; | ||
import org.exoplatform.commons.notification.template.TemplateUtils; | ||
import org.exoplatform.container.xml.InitParams; | ||
import org.exoplatform.kudos.model.Kudos; | ||
import org.exoplatform.kudos.service.KudosService; | ||
import org.exoplatform.social.notification.plugin.SocialNotificationUtils; | ||
|
||
public class KudosActivityChildPlugin extends AbstractNotificationChildPlugin { | ||
|
||
private KudosService kudosService; | ||
|
||
public KudosActivityChildPlugin(KudosService kudosService, InitParams initParams) { | ||
super(initParams); | ||
this.kudosService = kudosService; | ||
} | ||
|
||
@Override | ||
public String makeContent(NotificationContext ctx) { | ||
NotificationInfo notification = ctx.getNotificationInfo(); | ||
if (notification == null) { | ||
return ""; | ||
} | ||
|
||
String activityId = notification.getValueOwnerParameter(SocialNotificationUtils.ACTIVITY_ID.getKey()); | ||
Kudos kudos = kudosService.getKudosByActivityId(Long.parseLong(activityId.replace("comment", ""))); | ||
if (kudos == null) { | ||
return ""; | ||
} | ||
TemplateContext templateContext = new TemplateContext(getId(), getLanguage(notification)); | ||
templateContext.put("MESSAGE", kudos.getMessage()); | ||
return TemplateUtils.processGroovy(templateContext); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return KUDOS_ACTIVITY_COMMENT_TYPE; | ||
} | ||
|
||
@Override | ||
public boolean isValid(NotificationContext ctx) { | ||
return false; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
kudos-services/src/main/resources/notification/KudosActivity.gtmpl
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,20 @@ | ||
<% | ||
/** | ||
* This file is part of the Meeds project (https://meeds.io/). | ||
* | ||
* Copyright (C) 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. | ||
*/ | ||
%> | ||
<span class="kudos-message">$MESSAGE</span> |
83 changes: 83 additions & 0 deletions
83
...s-services/src/test/java/org/exoplatform/kudos/activity/KudosActivityChildPluginTest.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,83 @@ | ||
/** | ||
* 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.kudos.activity; | ||
|
||
import static org.exoplatform.kudos.service.utils.Utils.KUDOS_ACTIVITY_COMMENT_TYPE; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import org.exoplatform.commons.api.notification.NotificationContext; | ||
import org.exoplatform.commons.api.notification.model.NotificationInfo; | ||
import org.exoplatform.container.xml.InitParams; | ||
import org.exoplatform.kudos.model.Kudos; | ||
import org.exoplatform.kudos.notification.plugin.KudosActivityChildPlugin; | ||
import org.exoplatform.kudos.service.KudosService; | ||
import org.exoplatform.kudos.test.BaseKudosTest; | ||
import org.exoplatform.social.notification.plugin.SocialNotificationUtils; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class KudosActivityChildPluginTest extends BaseKudosTest { | ||
|
||
private static final long KUDOS_BY_ACTIVITY_ID = 5l; | ||
|
||
private static final String KUDOS_MESSAGE = "KUDOS_MESSAGE"; | ||
|
||
@Mock | ||
private KudosService kudosService; | ||
|
||
@Mock | ||
private InitParams initParams; | ||
|
||
@Mock | ||
private NotificationContext ctx; | ||
|
||
@Mock | ||
private NotificationInfo notification; | ||
|
||
@Mock | ||
private Kudos kudos; | ||
|
||
@Test | ||
public void testGetId() { | ||
KudosActivityChildPlugin kudosActivityChildPlugin = new KudosActivityChildPlugin(kudosService, initParams); | ||
assertEquals(KUDOS_ACTIVITY_COMMENT_TYPE, kudosActivityChildPlugin.getId()); | ||
} | ||
|
||
@Test | ||
public void testIsValid() { | ||
KudosActivityChildPlugin kudosActivityChildPlugin = new KudosActivityChildPlugin(kudosService, initParams); | ||
assertFalse(kudosActivityChildPlugin.isValid(null)); | ||
} | ||
|
||
@Test | ||
public void testMakeContent() { | ||
KudosActivityChildPlugin kudosActivityChildPlugin = new KudosActivityChildPlugin(kudosService, initParams); | ||
when(kudosService.getKudosByActivityId(KUDOS_BY_ACTIVITY_ID)).thenReturn(kudos); | ||
when(kudos.getMessage()).thenReturn(KUDOS_MESSAGE); | ||
when(ctx.getNotificationInfo()).thenReturn(notification); | ||
when(notification.getValueOwnerParameter(SocialNotificationUtils.ACTIVITY_ID.getKey())).thenReturn(String.valueOf(KUDOS_BY_ACTIVITY_ID)); | ||
|
||
assertTrue(StringUtils.contains(kudosActivityChildPlugin.makeContent(ctx), KUDOS_MESSAGE)); | ||
} | ||
|
||
} |
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