Email format

4.x.x
manoj 10 years ago
parent 28a00cd21c
commit a458c71789

@ -17,6 +17,8 @@
*/
package org.wso2.carbon.device.mgt.core;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
@ -40,6 +42,8 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
@ -51,6 +55,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
private OperationManager operationManager;
private LicenseManager licenseManager;
private static Log log = LogFactory.getLog(DeviceManagementServiceProviderImpl.class);
public DeviceManagementServiceProviderImpl(DeviceManagementRepository pluginRepository) {
this.pluginRepository = pluginRepository;
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
@ -216,16 +222,45 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
}
@Override
public void sendEnrollInvitation(String emailAddress) throws DeviceManagementException {
public void sendEnrollInvitation(String title, String userName, String emailAddress, String enrolUrl) throws
DeviceManagementException {
EmailMessageProperties emailMessageProperties = new EmailMessageProperties();
EnrolmentNotifications enrolmentNotifications = DeviceConfigurationManager.getInstance()
.getNotificationMessagesConfig()
.getEnrolmentNotifications();
.getNotificationMessagesConfig().getEnrolmentNotifications();
emailMessageProperties.setMailTo(new String[]{emailAddress});
emailMessageProperties.setMailTo(new String[] { emailAddress });
emailMessageProperties.setSubject(enrolmentNotifications.getSubject());
emailMessageProperties.setMessageBody(enrolmentNotifications.getMessage());
String messageHeader = enrolmentNotifications.getHeader();
String messageBody = enrolmentNotifications.getBody();
String messageFooter = enrolmentNotifications.getFooter();
StringBuilder messageBuilder = new StringBuilder();
try {
messageHeader = messageHeader.replaceAll("\\{title\\}",
URLEncoder.encode(title, "UTF-8"));
messageHeader = messageHeader.replaceAll("\\{user-name\\}",
URLEncoder.encode(userName, "UTF-8"));
messageBody = messageBody+ System.getProperty("line.separator") + enrolmentNotifications.getUrl()
.replaceAll("\\{downloadUrl\\}", URLEncoder.encode(enrolUrl, "UTF-8"));
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 ioEx) {
String errorMsg = "Error replacing tags in email template" + title;
log.error(errorMsg, ioEx);
throw new DeviceManagementException(errorMsg, ioEx);
}
emailMessageProperties.setMessageBody(messageBuilder.toString());
EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties);
}
@Override

@ -24,19 +24,39 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "EnrolmentNotifications")
public class EnrolmentNotifications {
private String message;
private String header;
private String body;
private String footer;
private String subject;
private String url;
@XmlElement(name = "message", required = true)
public String getMessage() {
return message;
@XmlElement(name = "Header", required = true)
public String getHeader() {
return header;
}
public void setMessage(String message) {
this.message = message;
public void setHeader(String header) {
this.header = header;
}
@XmlElement(name = "subject", required = true)
@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;
}
@ -44,4 +64,12 @@ public class EnrolmentNotifications {
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;
}
}

@ -38,6 +38,6 @@ public interface DeviceManagementService extends DeviceManager, LicenseManager,
List<Device> getDeviceListOfUser(String username) throws DeviceManagementException;
void sendEnrollInvitation(String emailAddress) throws DeviceManagementException;
void sendEnrollInvitation(String title, String userName, String emailAddress, String enrolUrl) throws DeviceManagementException;
}

@ -26,7 +26,6 @@ import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder;
import java.util.List;
@ -87,8 +86,10 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
}
@Override
public void sendEnrollInvitation(String emailAddress) throws DeviceManagementException {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().sendEnrollInvitation(emailAddress);
public void sendEnrollInvitation(String title, String userName, String emailAddress, String enrolUrl)
throws DeviceManagementException {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.sendEnrollInvitation(title, userName, emailAddress, enrolUrl);
}
@Override

@ -20,7 +20,14 @@
<Notifications>
<EnrolmentNotifications>
<message>Please enroll your device</message>
<subject>Enroll your device</subject>
<Header>Dear {title} {user-name},</Header>
<Body>Please go to the following url and enrol your device</Body>
<Url>{downloadUrl}</Url>
<Footer>
Best Regards,
WSO2 Carbon Team
http://www.wso2.com
</Footer>
<Subject>Enrol your device</Subject>
</EnrolmentNotifications>
</Notifications>
Loading…
Cancel
Save