User registration email configurations

revert-70aa11f8
manoj 10 years ago
parent 932cb003da
commit 20463cca57

@ -29,6 +29,17 @@ public class EmailMessageProperties {
private String firstName; private String firstName;
private String enrolmentUrl; private String enrolmentUrl;
private String title; private String title;
private String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
private String userName;
public String getMessageBody() { public String getMessageBody() {
return messageBody; return messageBody;
@ -94,6 +105,14 @@ public class EmailMessageProperties {
this.title = title; this.title = title;
} }
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override @Override
public String toString() { public String toString() {
return "EmailMessageProperties{" + return "EmailMessageProperties{" +

@ -39,4 +39,12 @@ public final class DeviceManagementConstants {
public final static String OAUTH_ADMIN_SERVICE = "/services/OAuthAdminService"; public final static String OAUTH_ADMIN_SERVICE = "/services/OAuthAdminService";
} }
public static final class EmailNotifications {
private EmailNotifications() {
throw new AssertionError();
}
public static final String ENROL_NOTIFICATION_TYPE = "enrol";
public static final String USER_REGISTRATION_NOTIFICATION_TYPE = "userRegistration";
}
} }

@ -28,7 +28,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager; import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.email.EnrolmentNotifications; import org.wso2.carbon.device.mgt.core.config.email.NotificationMessages;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
@ -233,12 +233,81 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
@Override @Override
public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException { public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
EnrolmentNotifications enrolmentNotifications = DeviceConfigurationManager.getInstance() List<NotificationMessages> notificationMessages = DeviceConfigurationManager.getInstance()
.getNotificationMessagesConfig().getEnrolmentNotifications(); .getNotificationMessagesConfig().getNotificationMessagesList();
String messageHeader = enrolmentNotifications.getHeader(); String messageHeader = "";
String messageBody = enrolmentNotifications.getBody(); String messageBody = "";
String messageFooter = enrolmentNotifications.getFooter(); String messageFooter = "";
String url = "";
String subject = "";
for(NotificationMessages notificationMessage : notificationMessages){
if (notificationMessage.getType().equals(DeviceManagementConstants.EmailNotifications
.ENROL_NOTIFICATION_TYPE)){
messageHeader = notificationMessage.getHeader();
messageBody = notificationMessage.getBody();
messageFooter = notificationMessage.getFooter();
url = notificationMessage.getUrl();
subject = notificationMessage.getSubject();
break;
}
}
StringBuilder messageBuilder = new StringBuilder();
try {
String title = "";
if (emailMessageProperties.getTitle() != null){
title = emailMessageProperties.getTitle();
}
messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.TITLE + "\\}",
URLEncoder.encode(title, EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.FIRST_NAME + "\\}",
URLEncoder.encode(emailMessageProperties.getFirstName(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageBody = messageBody + System.getProperty("line.separator") + url.replaceAll("\\{"
+ EmailConstants.EnrolmentEmailConstants.DOwN_LOAD_URL + "\\}",
URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageBuilder.append(messageHeader).append(System.getProperty("line.separator")).append(
System.getProperty("line.separator"));
messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(
System.getProperty("line.separator")).append(messageFooter);
} catch (IOException e) {
log.error("IO error in processing enrol email message "+emailMessageProperties);
throw new DeviceManagementException("Error replacing tags in email template '" +
emailMessageProperties.getSubject() + "'", e);
}
emailMessageProperties.setMessageBody(messageBuilder.toString());
emailMessageProperties.setSubject(subject);
EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties);
}
@Override
public void sendRegistrationEmail(EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
List<NotificationMessages> notificationMessages = DeviceConfigurationManager.getInstance()
.getNotificationMessagesConfig().getNotificationMessagesList();
String messageHeader = "";
String messageBody = "";
String messageFooter = "";
String url = "";
String subject = "";
for(NotificationMessages notificationMessage : notificationMessages){
if (notificationMessage.getType().equals(DeviceManagementConstants.EmailNotifications
.USER_REGISTRATION_NOTIFICATION_TYPE)){
messageHeader = notificationMessage.getHeader();
messageBody = notificationMessage.getBody();
messageFooter = notificationMessage.getFooter();
url = notificationMessage.getUrl();
subject = notificationMessage.getSubject();
break;
}
}
StringBuilder messageBuilder = new StringBuilder(); StringBuilder messageBuilder = new StringBuilder();
@ -249,11 +318,20 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
} }
messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.TITLE + "\\}", messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.TITLE + "\\}",
URLEncoder.encode(title, EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); URLEncoder.encode(title, EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.USERNAME + "\\}", messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.FIRST_NAME + "\\}",
URLEncoder.encode(emailMessageProperties.getFirstName(), URLEncoder.encode(emailMessageProperties.getFirstName(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageBody = messageBody + System.getProperty("line.separator") + enrolmentNotifications.getUrl()
.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.DOwN_LOAD_URL + "\\}", messageBody = messageBody.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.USERNAME + "\\}",
URLEncoder.encode(emailMessageProperties.getUserName(), EmailConstants.EnrolmentEmailConstants
.ENCODED_SCHEME));
messageBody = messageBody.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.PASSWORD + "\\}",
URLEncoder.encode(emailMessageProperties.getUserName(), EmailConstants.EnrolmentEmailConstants
.ENCODED_SCHEME));
messageBody = messageBody + System.getProperty("line.separator") + url.replaceAll("\\{"
+ EmailConstants.EnrolmentEmailConstants.DOwN_LOAD_URL + "\\}",
URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(), URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageBuilder.append(messageHeader).append(System.getProperty("line.separator")).append( messageBuilder.append(messageHeader).append(System.getProperty("line.separator")).append(
@ -268,7 +346,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
emailMessageProperties.getSubject() + "'", e); emailMessageProperties.getSubject() + "'", e);
} }
emailMessageProperties.setMessageBody(messageBuilder.toString()); emailMessageProperties.setMessageBody(messageBuilder.toString());
emailMessageProperties.setSubject(enrolmentNotifications.getSubject()); emailMessageProperties.setSubject(subject);
EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties); EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties);
} }

@ -0,0 +1,89 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.core.config.email;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "Notifications")
public class NotificationMessages {
private String header;
private String body;
private String footer;
private String subject;
private String url;
@XmlAttribute(name = "type")
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
private String type;
@XmlElement(name = "Header", required = true)
public String getHeader() {
return header;
}
public void setHeader(String header) {
this.header = header;
}
@XmlElement(name = "Body", required = true)
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
@XmlElement(name = "Footer", required = true)
public String getFooter() {
return footer;
}
public void setFooter(String footer) {
this.footer = footer;
}
@XmlElement(name = "Subject", required = true)
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
@XmlElement(name = "Url", required = true)
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}

@ -20,19 +20,19 @@ package org.wso2.carbon.device.mgt.core.config.email;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement(name = "Notifications") @XmlRootElement(name = "Notifications")
public class NotificationMessagesConfig { public class NotificationMessagesConfig {
private EnrolmentNotifications enrolmentNotifications; private List<NotificationMessages> notificationMessagesList;
@XmlElement(name = "EnrolmentNotifications", required = true) public List<NotificationMessages> getNotificationMessagesList() {
public EnrolmentNotifications getEnrolmentNotifications() { return notificationMessagesList;
return enrolmentNotifications;
} }
public void setEnrolmentNotifications(EnrolmentNotifications enrolmentNotifications) { public void setNotificationMessagesList(List<NotificationMessages> notificationMessagesList) {
this.enrolmentNotifications = enrolmentNotifications; this.notificationMessagesList = notificationMessagesList;
} }
} }

@ -24,6 +24,8 @@ public final class EmailConstants {
public static final String USERNAME = "user-name"; public static final String USERNAME = "user-name";
public static final String DOwN_LOAD_URL = "downloadUrl"; public static final String DOwN_LOAD_URL = "downloadUrl";
public static final String ENCODED_SCHEME = "UTF-8"; public static final String ENCODED_SCHEME = "UTF-8";
public static final String PASSWORD = "password";
public static final String FIRST_NAME = "first-name";
} }
} }

@ -40,6 +40,8 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
void sendEnrolmentInvitation(EmailMessageProperties config) throws DeviceManagementException; void sendEnrolmentInvitation(EmailMessageProperties config) throws DeviceManagementException;
void sendRegistrationEmail(EmailMessageProperties config) throws DeviceManagementException;
FeatureManager getFeatureManager(String type) throws DeviceManagementException; FeatureManager getFeatureManager(String type) throws DeviceManagementException;
} }

@ -173,10 +173,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
} }
@Override @Override
public void sendEnrolmentInvitation( public void sendEnrolmentInvitation(EmailMessageProperties emailMessageProperties)
EmailMessageProperties emailMessageProperties) throws DeviceManagementException { throws DeviceManagementException {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.sendEnrolmentInvitation(emailMessageProperties); .sendEnrolmentInvitation(emailMessageProperties);
} }
@Override
public void sendRegistrationEmail(EmailMessageProperties emailMessageProperties) throws DeviceManagementException {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.sendRegistrationEmail(emailMessageProperties);
}
} }

@ -23,4 +23,5 @@ import org.wso2.carbon.device.mgt.common.EmailMessageProperties;
public interface EmailService { public interface EmailService {
public void sendEmail(EmailMessageProperties emailMessageProperties) throws DeviceManagementException; public void sendEmail(EmailMessageProperties emailMessageProperties) throws DeviceManagementException;
} }

@ -18,15 +18,30 @@
--> -->
<Notifications> <Notifications>
<EnrolmentNotifications> <Notifications type="enrol">
<Header>Dear {title} {user-name},</Header> <Header>Dear {title} {first-name},</Header>
<Body>You have been registered to the WSO2 MDM. Below is the link to enroll.</Body> <Body>You have been registered to the WSO2 MDM. Below is the link to enroll.</Body>
<Url>{downloadUrl}</Url> <Url>{downloadUrl}</Url>
<Footer> <Footer>
Best Regards, Best Regards,
WSO2 Carbon Team WSO2 MDM Team
http://www.wso2.com http://www.wso2.com
</Footer> </Footer>
<Subject>Enrol your device with WSO2 MDM</Subject> <Subject>Enrol your device with WSO2 MDM</Subject>
</EnrolmentNotifications> </Notifications>
<Notifications type="userRegistration">
<Header>Dear {title} {first-name},</Header>
<Body>You have been registered to WSO2 MDM with following credentials.
Username: {user-name}
Password: {password}
Below is the link to enroll.
</Body>
<Url>{downloadUrl}</Url>
<Footer>
Best Regards,
WSO2 MDM Team
http://www.wso2.com
</Footer>
<Subject>Enrol your device with WSO2 MDM</Subject>
</Notifications>
</Notifications> </Notifications>
Loading…
Cancel
Save