Skip to content

Commit

Permalink
feat: Add Pwa Notifications - Meeds-io/MIPs#134
Browse files Browse the repository at this point in the history
  • Loading branch information
rdenarie committed Aug 23, 2024
1 parent 9223715 commit 6227d3b
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 3 deletions.
20 changes: 19 additions & 1 deletion crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@
# Files configuration
#
files: [
{
"source": "/processes-webapp/src/main/resources/locale/commons/Commons_en.properties",

"translation": "%original_path%/%file_name%!_%locale_with_underscore%.%file_extension%",
"translation_replace": {
"_en!": "","ar_SA": "ar","ar_OM": "aro","az_AZ": "az","ca_ES": "ca","ceb_PH": "ceb",
"co_FR": "co","cs_CZ": "cs","de_DE": "de","el_GR": "el","en_US": "en","es_ES": "es_ES","eu_ES": "eu","fa_IR": "fa",
"fi_FI": "fi","fil_PH": "fil","fr_FR": "fr","hi_IN": "hi","hu_HU": "hu","id_ID": "id","it_IT": "it","ja_JP": "ja",
"kab_KAB": "kab","ko_KR": "ko","lt_LT": "lt","ms_MY": "ms","nl_NL": "nl","no_NO": "no","pcm_NG": "pcm","pl_PL": "pl",
"pt_BR": "pt_BR","pt_PT": "pt_PT","ro_RO": "ro","ru_RU": "ru","sk_SK": "sk","sl_SI": "sl","sq_AL": "sq",
"sv_SE": "sv_SE","th_TH": "th","tl_PH": "tl","tr_TR": "tr","uk_UA": "uk","ur_IN": "ur_IN","vi_VN": "vi",
"zh_CN": "zh_CN","zh_TW": "zh_TW",
},
"dest": "add__ons/processes/Commons.properties",
"update_option": "update_as_unapproved",
"escape_special_characters": 0,
"escape_quotes": 0,
},
{
"source" : "/processes-webapp/src/main/resources/locale/portlet/Processes_en.properties",

Expand Down Expand Up @@ -105,4 +123,4 @@ files: [
"escape_special_characters": 0,
"escape_quotes" : 0,
},
]
]
5 changes: 5 additions & 0 deletions processes-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.meeds.pwa</groupId>
<artifactId>pwa-service</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>processes-services</finalName>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2024 eXo Platform SAS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.exoplatform.processes.notification.pwa;

import io.meeds.pwa.model.PwaNotificationMessage;
import io.meeds.pwa.plugin.PwaNotificationPlugin;
import org.exoplatform.commons.api.notification.model.NotificationInfo;
import org.exoplatform.commons.utils.CommonsUtils;
import org.exoplatform.processes.notification.utils.NotificationArguments;
import org.exoplatform.services.resources.LocaleConfig;
import org.exoplatform.services.resources.ResourceBundleService;
import org.exoplatform.social.core.identity.model.Identity;
import org.exoplatform.social.core.manager.IdentityManager;

public class CancelRequestPwaPlugin implements PwaNotificationPlugin {

public final static String ID = "CancelRequestPlugin";
private static final String TITLE_LABEL_KEY = "pwa.notification.CancelRequestPwaPlugin.title";

private ResourceBundleService resourceBundleService;

private IdentityManager identityManager;

public CancelRequestPwaPlugin(ResourceBundleService resourceBundleService, IdentityManager identityManager) {
this.resourceBundleService = resourceBundleService;
this.identityManager = identityManager;
}

@Override
public IdentityManager getIdentityManager() {
return this.identityManager;
}

@Override
public String getId() {
return ID;
}

@Override
public PwaNotificationMessage process(NotificationInfo notification, LocaleConfig localeConfig) {
PwaNotificationMessage notificationMessage = new PwaNotificationMessage();

String userFullName = getFullName(notification.getValueOwnerParameter(NotificationArguments.REQUEST_CREATOR.getKey()));

String title = resourceBundleService.getSharedString(TITLE_LABEL_KEY, localeConfig.getLocale())
.replace("{0}",userFullName)
.replace("{1}",notification.getValueOwnerParameter(NotificationArguments.REQUEST_PROCESS.getKey()));
notificationMessage.setTitle(title);
String url = notification.getValueOwnerParameter(NotificationArguments.PROCESS_URL.getKey());
url = url.replace(CommonsUtils.getCurrentDomain(), "");
notificationMessage.setUrl(url);
return notificationMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2024 eXo Platform SAS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.exoplatform.processes.notification.pwa;

import io.meeds.pwa.model.PwaNotificationMessage;
import io.meeds.pwa.plugin.PwaNotificationPlugin;
import org.exoplatform.commons.api.notification.model.NotificationInfo;
import org.exoplatform.commons.utils.CommonsUtils;
import org.exoplatform.processes.notification.utils.NotificationArguments;
import org.exoplatform.services.resources.LocaleConfig;
import org.exoplatform.services.resources.ResourceBundleService;
import org.exoplatform.social.core.manager.IdentityManager;

public class CreateRequestPwaPlugin implements PwaNotificationPlugin {

public final static String ID = "CreateRequestPlugin";
private static final String TITLE_LABEL_KEY = "pwa.notification.CreateRequestPwaPlugin.title";


private ResourceBundleService resourceBundleService;
private IdentityManager identityManager;

public CreateRequestPwaPlugin(ResourceBundleService resourceBundleService, IdentityManager identityManager) {
this.resourceBundleService = resourceBundleService;
this.identityManager = identityManager;


}

@Override
public IdentityManager getIdentityManager() {
return this.identityManager;
}
@Override
public String getId() {
return ID;
}

@Override
public PwaNotificationMessage process(NotificationInfo notification, LocaleConfig localeConfig) {
PwaNotificationMessage notificationMessage = new PwaNotificationMessage();

String userFullName = getFullName(notification.getValueOwnerParameter(NotificationArguments.REQUEST_CREATOR.getKey()));

String title = resourceBundleService.getSharedString(TITLE_LABEL_KEY, localeConfig.getLocale())
.replace("{0}",userFullName)
.replace("{1}",notification.getValueOwnerParameter(NotificationArguments.REQUEST_PROCESS.getKey()));
notificationMessage.setTitle(title);
String url = notification.getValueOwnerParameter(NotificationArguments.REQUEST_URL.getKey());
url = url.replace(CommonsUtils.getCurrentDomain(), "");
notificationMessage.setUrl(url);
return notificationMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2024 eXo Platform SAS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.exoplatform.processes.notification.pwa;

import io.meeds.pwa.model.PwaNotificationMessage;
import io.meeds.pwa.plugin.PwaNotificationPlugin;
import org.exoplatform.commons.api.notification.model.NotificationInfo;
import org.exoplatform.commons.utils.CommonsUtils;
import org.exoplatform.processes.notification.utils.NotificationArguments;
import org.exoplatform.services.resources.LocaleConfig;
import org.exoplatform.services.resources.ResourceBundleService;
import org.exoplatform.social.core.manager.IdentityManager;

public class RequestCommentPwaPlugin implements PwaNotificationPlugin {

public static final String ID = "RequestCommentPlugin";
private static final String TITLE_LABEL_KEY = "pwa.notification.RequestCommentPwaPlugin.title";

private ResourceBundleService resourceBundleService;
private IdentityManager identityManager;


public RequestCommentPwaPlugin(ResourceBundleService resourceBundleService, IdentityManager identityManager) {
this.resourceBundleService = resourceBundleService;
this.identityManager = identityManager;

}
@Override
public IdentityManager getIdentityManager() {
return this.identityManager;
}

@Override
public String getId() {
return ID;
}

@Override
public PwaNotificationMessage process(NotificationInfo notification, LocaleConfig localeConfig) {
PwaNotificationMessage notificationMessage = new PwaNotificationMessage();

String userFullName = getFullName(notification.getValueOwnerParameter(NotificationArguments.REQUEST_COMMENT_AUTHOR.getKey()));

String title = resourceBundleService.getSharedString(TITLE_LABEL_KEY, localeConfig.getLocale())
.replace("{0}",userFullName)
.replace("{1}",notification.getValueOwnerParameter(NotificationArguments.REQUEST_TITLE.getKey()))
.replace("{2}",notification.getValueOwnerParameter(NotificationArguments.REQUEST_PROCESS.getKey()));
notificationMessage.setTitle(title);
String url = notification.getValueOwnerParameter(NotificationArguments.REQUEST_COMMENT_URL.getKey());
url = url.replace(CommonsUtils.getCurrentDomain(), "");
notificationMessage.setUrl(url);
return notificationMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@
<type>org.exoplatform.processes.rest.ProcessesRest</type>
</component>

<component>
<type>org.exoplatform.processes.notification.pwa.CancelRequestPwaPlugin</type>
</component>
<component>
<type>org.exoplatform.processes.notification.pwa.CreateRequestPwaPlugin</type>
</component>
<component>
<type>org.exoplatform.processes.notification.pwa.RequestCommentPwaPlugin</type>
</component>
<external-component-plugins>
<target-component>org.exoplatform.commons.file.services.NameSpaceService</target-component>
<component-plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pwa.notification.CreateRequestPwaPlugin.title={0} has created a new request on the {1} process
pwa.notification.CancelRequestPwaPlugin.title={0} has cancelled the request
pwa.notification.RequestCommentPwaPlugin.title={0} has commented on your request {1} in {2} process
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pwa.notification.CreateRequestPwaPlugin.title={0} a cr\u00e9\u00e9 une nouvelle demande sur le process {1}
pwa.notification.CancelRequestPwaPlugin.title={0} a annul\u00e9 sa demande
pwa.notification.RequestCommentPwaPlugin.title={0} a comment\u00e9 votre demande {1} dans le processus {2}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ export default {
message() {
return this.$t('Notification.process.request.commented', {
0: `<a class="user-name font-weight-bold">${this.profileFullName}</a>`,
1: `<a class="user-name font-weight-bold">${this.processTitle}</a>`});
1: `<a class="user-name font-weight-bold">${this.requestTitle}</a>`,
2: `<a class="user-name font-weight-bold">${this.processTitle}</a>`});
}
}
};
</script>
</script>

0 comments on commit 6227d3b

Please sign in to comment.