Email functionality

4.x.x
manoj 10 years ago
parent 78959f0cfb
commit 7c0ca194a1

@ -71,4 +71,10 @@ public final class DeviceManagementConstants {
public static final String LICENSE_REGISTRY_KEY = "license";
}
public static final class NotificationProperties {
private NotificationProperties() {
throw new AssertionError();
}
public static final String NOTIFICATION_CONFIG_FILE = "notification-messages.xml";
}
}

@ -18,22 +18,24 @@
package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
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.common.operation.mgt.OperationManager;
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.EnrolmentNotifications;
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.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.*;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.dto.Status;
import org.wso2.carbon.device.mgt.core.internal.EmailServiceDataHolder;
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
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.common.operation.mgt.OperationManager;
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;
@ -188,7 +190,8 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
List<Device> devicesOfUser = new ArrayList<Device>();
try {
int tenantId = DeviceManagerUtil.getTenantId();
List<org.wso2.carbon.device.mgt.core.dto.Device> devicesList = this.deviceDAO.getDeviceListOfUser(username, tenantId);
List<org.wso2.carbon.device.mgt.core.dto.Device> devicesList = this.deviceDAO
.getDeviceListOfUser(username, tenantId);
for (int x = 0; x < devicesList.size(); x++) {
org.wso2.carbon.device.mgt.core.dto.Device device = devicesList.get(x);
device.setDeviceType(deviceTypeDAO.getDeviceType(device.getDeviceTypeId()));
@ -207,7 +210,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
}
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining devices for user " +
"'" + username + "'", e);
"'" + username + "'", e);
}
return devicesOfUser;
}
@ -215,8 +218,14 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
@Override
public void sendEnrollInvitation(String emailAddress) throws DeviceManagementException {
EmailMessageProperties emailMessageProperties = new EmailMessageProperties();
emailMessageProperties.setSubject("");
// EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail();
EnrolmentNotifications enrolmentNotifications = DeviceConfigurationManager.getInstance()
.getNotificationMessagesConfig()
.getEnrolmentNotifications();
emailMessageProperties.setMailTo(new String[]{emailAddress});
emailMessageProperties.setSubject(enrolmentNotifications.getSubject());
emailMessageProperties.setMessageBody(enrolmentNotifications.getMessage());
EmailServiceDataHolder.getInstance().getEmailServiceProvider().sendEmail(emailMessageProperties);
}
@Override
@ -288,7 +297,7 @@ public class DeviceManagementServiceProviderImpl implements DeviceManagementServ
@Override
public boolean addOperation(Operation operation,
List<DeviceIdentifier> devices) throws OperationManagementException {
List<DeviceIdentifier> devices) throws OperationManagementException {
return operationManager.addOperation(operation, devices);
}

@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.utils.CarbonUtils;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.File;
@ -33,42 +34,64 @@ import java.io.File;
*/
public class DeviceConfigurationManager {
private DeviceManagementConfig currentDeviceConfig;
private static DeviceConfigurationManager deviceConfigManager;
private DeviceManagementConfig currentDeviceConfig;
private NotificationMessagesConfig notificationMessagesConfig;
private static DeviceConfigurationManager deviceConfigManager;
private static final String deviceMgtConfigXMLPath =
CarbonUtils.getCarbonConfigDirPath() + File.separator +
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
private static final String deviceMgtConfigXMLPath =
CarbonUtils.getCarbonConfigDirPath() + File.separator +
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
private static final String notificationMessagesConfigXMLPath =
CarbonUtils.getCarbonConfigDirPath() + File.separator +
DeviceManagementConstants.NotificationProperties.NOTIFICATION_CONFIG_FILE;
public static DeviceConfigurationManager getInstance() {
if (deviceConfigManager == null) {
synchronized (DeviceConfigurationManager.class) {
if (deviceConfigManager == null) {
deviceConfigManager = new DeviceConfigurationManager();
}
}
}
return deviceConfigManager;
}
public static DeviceConfigurationManager getInstance() {
if (deviceConfigManager == null) {
synchronized (DeviceConfigurationManager.class) {
if (deviceConfigManager == null) {
deviceConfigManager = new DeviceConfigurationManager();
}
}
}
return deviceConfigManager;
}
public synchronized void initConfig() throws DeviceManagementException {
public synchronized void initConfig() throws DeviceManagementException {
//catch generic exception.if any exception occurs wrap and throw DeviceManagementException
try {
File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
//catch generic exception.if any exception occurs wrap and throw DeviceManagementException
try {
File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
/* Un-marshaling Device Management configuration */
JAXBContext cdmContext = JAXBContext.newInstance(DeviceManagementConfig.class);
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
this.currentDeviceConfig = (DeviceManagementConfig) unmarshaller.unmarshal(doc);
} catch (Exception e) {
throw new DeviceManagementException("Error occurred while initializing RSS config", e);
}
}
public DeviceManagementConfig getDeviceManagementConfig() {
return currentDeviceConfig;
}
JAXBContext cdmContext = JAXBContext.newInstance(DeviceManagementConfig.class);
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
this.currentDeviceConfig = (DeviceManagementConfig) unmarshaller.unmarshal(doc);
} catch (JAXBException jaxbEx) {
throw new DeviceManagementException("Error occurred while initializing Data Source config", jaxbEx);
}
try {
File notificationConfig = new File(notificationMessagesConfigXMLPath);
Document doc = DeviceManagerUtil.convertToDocument(notificationConfig);
/* Un-marshaling Notifications Management configuration */
JAXBContext notificationContext = JAXBContext.newInstance(NotificationMessagesConfig.class);
Unmarshaller unmarshaller = notificationContext.createUnmarshaller();
this.notificationMessagesConfig = (NotificationMessagesConfig) unmarshaller.unmarshal(doc);
}catch(JAXBException jaxbEx){
throw new DeviceManagementException("Error occurred while initializing Notification settings config",
jaxbEx);
}
}
public DeviceManagementConfig getDeviceManagementConfig() {
return currentDeviceConfig;
}
public NotificationMessagesConfig getNotificationMessagesConfig() {
return notificationMessagesConfig;
}
}

@ -1,5 +1,6 @@
instructions.configure = \
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/notification-messages.xml,target:${installFolder}/../../conf/notification-messages.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\
Loading…
Cancel
Save