Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit 4356097

Browse files
author
sachin-maheshwari
authored
Merge pull request #48 from appirio-tech/dev
JIRA-28 shutdown AP-Notifications legacy service
2 parents 188113f + 2a0083f commit 4356097

File tree

6 files changed

+107
-4
lines changed

6 files changed

+107
-4
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ workflows:
146146
context : org-global
147147
filters:
148148
branches:
149-
only: [dev, 'shapeup3']
149+
only: [dev, 'feature/jira-plat-28']
150150
# Production build is executed on "master" branch only.
151151
- "build-prod":
152152
context : org-global

buildtokenproperties.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ AUTH0_NEW_DOMAIN=$(eval "echo \$${ENV}_AUTH0_NEW_DOMAIN")
4444
AUTH0_DOMAIN=$(eval "echo \$${ENV}_AUTH0_DOMAIN")
4545

4646
SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID")
47-
47+
SENDGRID_WELCOME_EMAIL_TEMPLATE_ID=$(eval "echo \$${ENV}_SENDGRID_WELCOME_EMAIL_TEMPLATE_ID")
4848

4949

5050
if [[ -z "$ENV" ]] ; then
@@ -110,3 +110,4 @@ perl -pi -e "s|\{\{M2MAUTHCONFIG_USERPROFILES_DELETE\}\}|$M2MAUTHCONFIG_USERPROF
110110
perl -pi -e "s/\{\{AUTH0_NEW_DOMAIN\}\}/$AUTH0_NEW_DOMAIN/g" $CONFFILENAME
111111
perl -pi -e "s/\{\{AUTH0_DOMAIN\}\}/$AUTH0_DOMAIN/g" $CONFFILENAME
112112
perl -pi -e "s/\{\{SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID\}\}/$SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID/g" $CONFFILENAME
113+
perl -pi -e "s/\{\{SENDGRID_WELCOME_EMAIL_TEMPLATE_ID\}\}/$SENDGRID_WELCOME_EMAIL_TEMPLATE_ID/g" $CONFFILENAME

src/main/java/com/appirio/tech/core/service/identity/IdentityApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public void run(IdentityConfiguration configuration, Environment environment) th
234234
userResource.setAuth0Client(configuration.getAuth0()); // TODO: constructor
235235
userResource.setDomain(configuration.getAuthDomain());
236236
userResource.setSendgridTemplateId(Utils.getString("sendGridTemplateId"));
237+
userResource.setSendgridWelcomeTemplateId(Utils.getString("sendGridWelcomeTemplateId"));
237238
// this secret _used_ to be different from the one used in AuthorizationResource.
238239
// it _was_ the secret x2. (userResource.setSecret(getSecret()+getSecret());)
239240
// we assume this was done to further limit the usability of the oneTimeToken generated in userResource

src/main/java/com/appirio/tech/core/service/identity/resource/UserResource.java

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public class UserResource implements GetResource<User>, DDLResource<User> {
104104
private String domain;
105105

106106
private String sendgridTemplateId;
107+
108+
private String sendgridWelcomeTemplateId;
107109

108110
protected UserDAO userDao;
109111

@@ -908,12 +910,15 @@ public ApiResponse resendEmail(
908910
data.put("domain", getDomain());
909911
data.put("subDomain", "platform");
910912
data.put("path", "/onboard");
913+
data.put("redirectUrl", "https%3A%2F%2Fplatform."+getDomain()+"%2Fonboard");
911914

912915
if (user.getRegSource() != null && user.getRegSource().matches("tcBusiness")) {
913916
data.put("subDomain", "connect");
914917
data.put("path", "/");
918+
data.put("redirectUrl", "https%3A%2F%2Fconnect."+getDomain()+"%2F");
915919
}
916920

921+
917922
payload.put("data", data);
918923

919924
Map<String,Object> from = new LinkedHashMap<String,Object>();
@@ -1742,10 +1747,19 @@ public String getSendgridTemplateId() {
17421747
return sendgridTemplateId;
17431748
}
17441749

1750+
public void setSendgridWelcomeTemplateId(String sendgridWelcomeTemplateId) {
1751+
this.sendgridWelcomeTemplateId = sendgridWelcomeTemplateId;
1752+
}
1753+
1754+
public String getSendgridWelcomeTemplateId() {
1755+
return sendgridWelcomeTemplateId;
1756+
}
1757+
17451758
public void setSendgridTemplateId(String sendgridTemplateId) {
17461759
this.sendgridTemplateId = sendgridTemplateId;
17471760
}
17481761

1762+
17491763
public String getSecret() {
17501764
return secret;
17511765
}
@@ -1758,13 +1772,99 @@ protected void publishUserEvent(String topic, User user) {
17581772
if(user==null)
17591773
return;
17601774
logger.info(String.format("Publishing a user event to '%s'. userId: %s, handle: %s", topic, user.getId(), user.getHandle()));
1775+
1776+
/**
1777+
* trigger event for new kafka
1778+
*/
17611779
publishEvent(topic, user);
17621780
}
17631781

17641782

17651783
protected void notifyActivation(User user, String redirectUrl) {
17661784
NotificationPayload payload = createActivationNotificationPayload(user, redirectUrl);
17671785
publishNotificationEvent(payload.getMailRepresentation());
1786+
1787+
/**
1788+
* trigger event for new kafka
1789+
*/
1790+
sendActivationEmailEvent(user, redirectUrl);
1791+
}
1792+
1793+
private void sendActivationEmailEvent(User user, String redirectUrl) {
1794+
1795+
EventMessage msg = EventMessage.getDefault();
1796+
msg.setTopic("external.action.email");
1797+
1798+
Map<String,Object> payload = new LinkedHashMap<String,Object>();
1799+
1800+
Map<String,Object> data = new LinkedHashMap<String,Object>();
1801+
data.put("handle", user.getHandle());
1802+
data.put("code", user.getCredential().getActivationCode());
1803+
data.put("domain", getDomain());
1804+
data.put("redirectUrl", redirectUrl);
1805+
1806+
if ((redirectUrl ==null) || (redirectUrl.isEmpty())) {
1807+
data.put("subDomain", "platform");
1808+
data.put("path", "/onboard");
1809+
1810+
if (user.getRegSource() != null && user.getRegSource().matches("tcBusiness")) {
1811+
data.put("subDomain", "connect");
1812+
data.put("path", "/");
1813+
}
1814+
}
1815+
1816+
payload.put("data", data);
1817+
1818+
Map<String,Object> from = new LinkedHashMap<String,Object>();
1819+
from.put("email", String.format("Topcoder <noreply@%s>", getDomain()));
1820+
payload.put("from", from);
1821+
1822+
payload.put("version", "v3");
1823+
payload.put("sendgrid_template_id", this.getSendgridTemplateId());
1824+
1825+
ArrayList<String> recipients = new ArrayList<String>();
1826+
recipients.add(user.getEmail());
1827+
1828+
payload.put("recipients", recipients);
1829+
1830+
msg.setPayload(payload);
1831+
try {
1832+
this.eventBusServiceClient.reFireEvent(msg);
1833+
} catch (Exception e) {
1834+
logger.error("Error occured while publishing the events to new kafka.");
1835+
}
1836+
}
1837+
1838+
private void sendWelcomeEmailEvent(User user) {
1839+
1840+
EventMessage msg = EventMessage.getDefault();
1841+
msg.setTopic("external.action.email");
1842+
1843+
Map<String,Object> payload = new LinkedHashMap<String,Object>();
1844+
1845+
Map<String,Object> data = new LinkedHashMap<String,Object>();
1846+
data.put("handle", user.getHandle());
1847+
1848+
payload.put("data", data);
1849+
1850+
Map<String,Object> from = new LinkedHashMap<String,Object>();
1851+
from.put("email", String.format("Topcoder <noreply@%s>", getDomain()));
1852+
payload.put("from", from);
1853+
1854+
payload.put("version", "v3");
1855+
payload.put("sendgrid_template_id", this.getSendgridWelcomeTemplateId());
1856+
1857+
ArrayList<String> recipients = new ArrayList<String>();
1858+
recipients.add(user.getEmail());
1859+
1860+
payload.put("recipients", recipients);
1861+
1862+
msg.setPayload(payload);
1863+
try {
1864+
this.eventBusServiceClient.reFireEvent(msg);
1865+
} catch (Exception e) {
1866+
logger.error("Error occured while publishing the events to new kafka.");
1867+
}
17681868
}
17691869

17701870
protected NotificationPayload createActivationNotificationPayload(User user, String redirectUrl) {
@@ -1784,6 +1884,7 @@ protected void notifyPasswordReset(User user, String resetToken, String resetPas
17841884
protected void notifyWelcome(User user) {
17851885
publishNotificationEvent(
17861886
new NotificationPayload.WelcomePayload(user).getMailRepresentation());
1887+
sendWelcomeEmailEvent(user);
17871888
}
17881889

17891890
protected void publishNotificationEvent(MailRepresentation mail) {
@@ -1821,8 +1922,6 @@ protected void publishEvent(String topic, Object payload) {
18211922
logger.error(String.format("Failed to convert the payload - %s", payload), e);
18221923
}
18231924

1824-
1825-
18261925
}
18271926

18281927
/**

src/main/resources/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ context:
1212
passwordHashKey: @application.password.key@
1313
ssoTokenSalt: @application.ssotoken.salt@
1414
sendGridTemplateId: @application.sendgrid.template.id@
15+
sendGridWelcomeTemplateId: @application.sendgrid.welcome.template.id@
1516
jwtExpirySeconds: 600
1617
cookieExpirySeconds: 7776000
1718

token.properties.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#sendgrid
1111
@application.sendgrid.template.id@={{SENDGRID_RESEND_ACTIVATION_EMAIL_TEMPLATE_ID}}
12+
@application.sendgrid.welcome.template.id@={{SENDGRID_WELCOME_EMAIL_TEMPLATE_ID}}
1213

1314
@ldap.host@={{LDAP_SERVER}}
1415
@ldap.port@=389

0 commit comments

Comments
 (0)