From 1736d5db3e9260dfc84ed21ca78b5f7c0db36733 Mon Sep 17 00:00:00 2001 From: harshanL Date: Thu, 12 Feb 2015 18:32:06 +0530 Subject: [PATCH 1/6] CDMF-8 fixes --- .../carbon/device/mgt/core/DeviceManager.java | 24 +- .../device/mgt/core/DeviceManagerImpl.java | 310 ++++++++++-------- .../config/DeviceConfigurationManager.java | 61 ++-- .../config/DeviceManagementRepository.java | 2 +- .../config/LicenseConfigurationManager.java | 60 ++-- .../config/datasource/DataSourceConfig.java | 3 +- .../datasource/JNDILookupDefinition.java | 2 +- .../carbon/device/mgt/core/dao/DeviceDAO.java | 5 +- .../dao/DeviceManagementDAOException.java | 2 +- .../core/dao/DeviceManagementDAOFactory.java | 101 +++--- .../device/mgt/core/dao/DeviceTypeDAO.java | 15 +- .../mgt/core/dao/impl/DeviceDAOImpl.java | 39 ++- .../dao/util/DeviceManagementDAOUtil.java | 223 ++++++------- .../DeviceManagementServiceComponent.java | 215 ++++++------ .../core/service/DeviceManagementService.java | 125 +++---- .../service/LicenseManagementService.java | 10 +- .../DeviceManagementSchemaInitializer.java | 31 +- .../mgt/core/util/DeviceManagerUtil.java | 20 +- 18 files changed, 658 insertions(+), 590 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java index ad95758d32..1f2c4df376 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java @@ -31,26 +31,28 @@ import java.util.List; */ public interface DeviceManager { - public boolean enrollDevice(Device device) throws DeviceManagementException; + public boolean enrollDevice(Device device) throws DeviceManagementException; - public boolean modifyEnrollment(Device device) throws DeviceManagementException; + public boolean modifyEnrollment(Device device) throws DeviceManagementException; - public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException; + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException; - public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException; + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException; - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException; + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException; - public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException; + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException; - public List getAllDevices(String type) throws DeviceManagementException; + public List getAllDevices(String type) throws DeviceManagementException; - public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException; + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException; - public boolean updateDeviceInfo(Device device) throws DeviceManagementException; + public boolean updateDeviceInfo(Device device) throws DeviceManagementException; - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException; - public OperationManager getOperationManager(String type) throws DeviceManagementException; + public OperationManager getOperationManager(String type) throws DeviceManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java index 99a56fb8fb..64ebbf0e46 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java @@ -38,149 +38,169 @@ import java.util.List; public class DeviceManagerImpl implements DeviceManager { - private static Log log = LogFactory.getLog(DeviceManagerImpl.class); - private DeviceDAO deviceDAO; - private DeviceTypeDAO deviceTypeDAO; - private DeviceManagementConfig config; - private DeviceManagementRepository pluginRepository; - - public DeviceManagerImpl(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) { - this.config = config; - this.pluginRepository = pluginRepository; - this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); - this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); - } - - @Override - public boolean enrollDevice(Device device) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); - boolean status = dms.enrollDevice(device); - try { - org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device); - Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType()); - deviceDto.setStatus(Status.ACTIVE); - deviceDto.setDeviceTypeId(deviceTypeId); - this.getDeviceDAO().addDevice(deviceDto); - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'", - e); - } - return status; - } - - @Override - public boolean modifyEnrollment(Device device) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); - boolean status = dms.modifyEnrollment(device); - try { - this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device)); - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while modifying the device '" + device.getId() + "'", - e); - } - return status; - } - - @Override - public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.disenrollDevice(deviceId); - } - - @Override - public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.isEnrolled(deviceId); - } - - @Override - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.isActive(deviceId); - } - - @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.setActive(deviceId, status); - } - - @Override - public List getAllDevices(String type) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); - List devicesList = new ArrayList(); - try { - Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type); - List devices = this.getDeviceDAO().getDevices(deviceTypeId); - - for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) { - DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId()); - Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType); - DeviceIdentifier deviceIdentifier = DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType); - Device dmsDevice = dms.getDevice(deviceIdentifier); - if (dmsDevice != null) { - convertedDevice.setProperties(dmsDevice.getProperties()); - convertedDevice.setFeatures(dmsDevice.getFeatures()); - } - devicesList.add(convertedDevice); - } - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + "'", e); - } - return devicesList; - } - - @Override - public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - Device convertedDevice = null; - try { - Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType()); - org.wso2.carbon.device.mgt.core.dto.Device device = - this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId()); - if (device != null) { - convertedDevice = DeviceManagementDAOUtil - .convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId)); - Device dmsDevice = dms.getDevice(deviceId); - if (dmsDevice != null) { - convertedDevice.setProperties(dmsDevice.getProperties()); - convertedDevice.setFeatures(dmsDevice.getFeatures()); - } - } - } catch (DeviceManagementDAOException e) { - throw new DeviceManagementException( - "Error occurred while obtaining the device for id '" + deviceId.getId() + "'", e); - } - return convertedDevice; - } - - @Override - public boolean updateDeviceInfo(Device device) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); - return dms.updateDeviceInfo(device); - } - - @Override - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) - throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.setOwnership(deviceId, ownershipType); - } - - public OperationManager getOperationManager(String type) throws DeviceManagementException { - DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); - return dms.getOperationManager(); - } - - public DeviceDAO getDeviceDAO() { - return deviceDAO; - } - - public DeviceTypeDAO getDeviceTypeDAO() { - return deviceTypeDAO; - } - - public DeviceManagementRepository getPluginRepository() { - return pluginRepository; - } + private static Log log = LogFactory.getLog(DeviceManagerImpl.class); + private DeviceDAO deviceDAO; + private DeviceTypeDAO deviceTypeDAO; + private DeviceManagementConfig config; + private DeviceManagementRepository pluginRepository; + + public DeviceManagerImpl(DeviceManagementConfig config, + DeviceManagementRepository pluginRepository) { + this.config = config; + this.pluginRepository = pluginRepository; + this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); + this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); + } + + @Override + public boolean enrollDevice(Device device) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(device.getType()); + boolean status = dms.enrollDevice(device); + try { + org.wso2.carbon.device.mgt.core.dto.Device deviceDto = + DeviceManagementDAOUtil.convertDevice(device); + Integer deviceTypeId = + this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType()); + deviceDto.setStatus(Status.ACTIVE); + deviceDto.setDeviceTypeId(deviceTypeId); + this.getDeviceDAO().addDevice(deviceDto); + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException( + "Error occurred while enrolling the device '" + device.getId() + "'", + e); + } + return status; + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(device.getType()); + boolean status = dms.modifyEnrollment(device); + try { + this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device)); + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException( + "Error occurred while modifying the device '" + device.getId() + "'", + e); + } + return status; + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.disenrollDevice(deviceId); + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.isEnrolled(deviceId); + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.isActive(deviceId); + } + + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.setActive(deviceId, status); + } + + @Override + public List getAllDevices(String type) throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); + List devicesList = new ArrayList(); + try { + Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type); + List devices = + this.getDeviceDAO().getDevices(deviceTypeId); + + for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) { + DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId()); + Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType); + DeviceIdentifier deviceIdentifier = + DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType); + Device dmsDevice = dms.getDevice(deviceIdentifier); + if (dmsDevice != null) { + convertedDevice.setProperties(dmsDevice.getProperties()); + convertedDevice.setFeatures(dmsDevice.getFeatures()); + } + devicesList.add(convertedDevice); + } + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException( + "Error occurred while obtaining the device for type '" + type + "'", e); + } + return devicesList; + } + + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + Device convertedDevice = null; + try { + Integer deviceTypeId = + this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType()); + org.wso2.carbon.device.mgt.core.dto.Device device = + this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId()); + if (device != null) { + convertedDevice = DeviceManagementDAOUtil + .convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId)); + Device dmsDevice = dms.getDevice(deviceId); + if (dmsDevice != null) { + convertedDevice.setProperties(dmsDevice.getProperties()); + convertedDevice.setFeatures(dmsDevice.getFeatures()); + } + } + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException( + "Error occurred while obtaining the device for id '" + deviceId.getId() + "'", + e); + } + return convertedDevice; + } + + @Override + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(device.getType()); + return dms.updateDeviceInfo(device); + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.setOwnership(deviceId, ownershipType); + } + + public OperationManager getOperationManager(String type) throws DeviceManagementException { + DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); + return dms.getOperationManager(); + } + + public DeviceDAO getDeviceDAO() { + return deviceDAO; + } + + public DeviceTypeDAO getDeviceTypeDAO() { + return deviceTypeDAO; + } + + public DeviceManagementRepository getPluginRepository() { + return pluginRepository; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java index f9f99ffba9..3f26d2ae6e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceConfigurationManager.java @@ -30,45 +30,46 @@ import javax.xml.bind.Unmarshaller; import java.io.File; /** - * Class responsible for the cdm manager configuration initialization + * Class responsible for the cdm manager configuration initialization. */ public class DeviceConfigurationManager { - private DeviceManagementConfig currentDeviceConfig; - private static DeviceConfigurationManager deviceConfigManager; + private DeviceManagementConfig currentDeviceConfig; + 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; - 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); - } - } + 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; - } + public DeviceManagementConfig getDeviceManagementConfig() { + return currentDeviceConfig; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementRepository.java index 134eec6969..3547c4f333 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementRepository.java @@ -22,7 +22,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** - * Class for holding management repository data + * Class for holding management repository data. */ @XmlRootElement(name = "ManagementRepository") public class DeviceManagementRepository { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/LicenseConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/LicenseConfigurationManager.java index 2995c6b14f..798f6870a6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/LicenseConfigurationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/LicenseConfigurationManager.java @@ -32,42 +32,42 @@ import java.io.File; public class LicenseConfigurationManager { - private LicenseManagementConfig licenseMgtConfig; - private static LicenseConfigurationManager licenseConfigManager; + private LicenseManagementConfig licenseMgtConfig; + private static LicenseConfigurationManager licenseConfigManager; - private static final String licenseMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + - DeviceManagementConstants.Common.DEFAULT_LICENSE_CONFIG_XML_NAME; + private static final String licenseMgtConfigXMLPath = + CarbonUtils.getCarbonConfigDirPath() + File.separator + + DeviceManagementConstants.Common.DEFAULT_LICENSE_CONFIG_XML_NAME; - public static LicenseConfigurationManager getInstance() { - if (licenseConfigManager == null) { - synchronized (LicenseConfigurationManager.class) { - if (licenseConfigManager == null) { - licenseConfigManager = new LicenseConfigurationManager(); - } - } - } - return licenseConfigManager; - } + public static LicenseConfigurationManager getInstance() { + if (licenseConfigManager == null) { + synchronized (LicenseConfigurationManager.class) { + if (licenseConfigManager == null) { + licenseConfigManager = new LicenseConfigurationManager(); + } + } + } + return licenseConfigManager; + } - public synchronized void initConfig() throws LicenseManagementException { + public synchronized void initConfig() throws LicenseManagementException { - //catch generic exception.if any exception occurs wrap and throw LicenseManagementException - try { - File licenseMgtConfig = new File(licenseMgtConfigXMLPath); - Document doc = DeviceManagerUtil.convertToDocument(licenseMgtConfig); + //catch generic exception.if any exception occurs wrap and throw LicenseManagementException + try { + File licenseMgtConfig = new File(licenseMgtConfigXMLPath); + Document doc = DeviceManagerUtil.convertToDocument(licenseMgtConfig); /* Un-marshaling License Management configuration */ - JAXBContext cdmContext = JAXBContext.newInstance(LicenseManagementConfig.class); - Unmarshaller unmarshaller = cdmContext.createUnmarshaller(); - this.licenseMgtConfig = (LicenseManagementConfig) unmarshaller.unmarshal(doc); - } catch (Exception e) { - throw new LicenseManagementException("Error occurred while initializing RSS config", e); - } - } - - public LicenseManagementConfig getLicenseMgtConfig() { - return licenseMgtConfig; - } + JAXBContext cdmContext = JAXBContext.newInstance(LicenseManagementConfig.class); + Unmarshaller unmarshaller = cdmContext.createUnmarshaller(); + this.licenseMgtConfig = (LicenseManagementConfig) unmarshaller.unmarshal(doc); + } catch (Exception e) { + throw new LicenseManagementException("Error occurred while initializing RSS config", e); + } + } + public LicenseManagementConfig getLicenseMgtConfig() { + return licenseMgtConfig; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/datasource/DataSourceConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/datasource/DataSourceConfig.java index bb1c06ab1a..c7dfd4fa20 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/datasource/DataSourceConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/datasource/DataSourceConfig.java @@ -21,7 +21,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** - * Class for holding data source configuration in malformed-cdm-config-no-mgt-repo.xml at parsing with JAXB + * Class for holding data source configuration in malformed-cdm-config-no-mgt-repo.xml at parsing + * with JAXB. */ @XmlRootElement(name = "DataSourceConfiguration") public class DataSourceConfig { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/datasource/JNDILookupDefinition.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/datasource/JNDILookupDefinition.java index 1946ae90cb..cb57709222 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/datasource/JNDILookupDefinition.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/datasource/JNDILookupDefinition.java @@ -22,7 +22,7 @@ import javax.xml.bind.annotation.*; import java.util.List; /** - * Class for hold JndiLookupDefinition of rss-manager.xml at parsing with JAXB + * Class for hold JndiLookupDefinition of rss-manager.xml at parsing with JAXB. */ @XmlRootElement(name = "JndiLookupDefinition") public class JNDILookupDefinition { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index 12d0e757e1..4e3a7f86ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -24,7 +24,7 @@ import org.wso2.carbon.device.mgt.core.dto.Status; import java.util.List; /** - * This class represents the key operations associated with persisting device related information + * This class represents the key operations associated with persisting device related information. */ public interface DeviceDAO { @@ -44,7 +44,8 @@ public interface DeviceDAO { * @return the Device object which matches given data * @throws DeviceManagementDAOException */ - Device getDeviceByDeviceIdentifier(Integer type, String identifier) throws DeviceManagementDAOException; + Device getDeviceByDeviceIdentifier(Integer type, String identifier) + throws DeviceManagementDAOException; List getDevices() throws DeviceManagementDAOException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOException.java index cb48c3320c..6558acc6e6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOException.java @@ -19,7 +19,7 @@ package org.wso2.carbon.device.mgt.core.dao; /** - * Custom exception class for data access related exceptions + * Custom exception class for data access related exceptions. */ public class DeviceManagementDAOException extends Exception { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java index 53b9fd119e..df6ee073a7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java @@ -25,64 +25,69 @@ import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.dao.impl.DeviceDAOImpl; import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; + import javax.sql.DataSource; import java.util.Hashtable; import java.util.List; public class DeviceManagementDAOFactory { - private static DataSource dataSource; - private static final Log log = LogFactory.getLog(DeviceManagementDAOFactory.class); + private static DataSource dataSource; + private static final Log log = LogFactory.getLog(DeviceManagementDAOFactory.class); - public static DeviceDAO getDeviceDAO() { - return new DeviceDAOImpl(dataSource); - } + public static DeviceDAO getDeviceDAO() { + return new DeviceDAOImpl(dataSource); + } - public static DeviceTypeDAO getDeviceTypeDAO() { - return new DeviceTypeDAOImpl(dataSource); - } + public static DeviceTypeDAO getDeviceTypeDAO() { + return new DeviceTypeDAOImpl(dataSource); + } - public static void init(DataSourceConfig config) { - dataSource = resolveDataSource(config); - } + public static void init(DataSourceConfig config) { + dataSource = resolveDataSource(config); + } - public static void init(DataSource dtSource) { - dataSource = dtSource; - } + public static void init(DataSource dtSource) { + dataSource = dtSource; + } - /** - * Resolve data source from the data source definition - * - * @param config data source configuration - * @return data source resolved from the data source definition - */ - private static DataSource resolveDataSource(DataSourceConfig config) { - DataSource dataSource = null; - if (config == null) { - throw new RuntimeException("Device Management Repository data source configuration " + "is null and " + - "thus, is not initialized"); - } - JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); - if (jndiConfig != null) { - if (log.isDebugEnabled()) { - log.debug("Initializing Device Management Repository data source using the JNDI " + - "Lookup Definition"); - } - List jndiPropertyList = jndiConfig.getJndiProperties(); - if (jndiPropertyList != null) { - Hashtable jndiProperties = new Hashtable(); - for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { - jndiProperties.put(prop.getName(), prop.getValue()); - } - dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); - } else { - dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); - } - } - return dataSource; - } + /** + * Resolve data source from the data source definition + * + * @param config data source configuration + * @return data source resolved from the data source definition + */ + private static DataSource resolveDataSource(DataSourceConfig config) { + DataSource dataSource = null; + if (config == null) { + throw new RuntimeException( + "Device Management Repository data source configuration " + "is null and " + + "thus, is not initialized"); + } + JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); + if (jndiConfig != null) { + if (log.isDebugEnabled()) { + log.debug("Initializing Device Management Repository data source using the JNDI " + + "Lookup Definition"); + } + List jndiPropertyList = + jndiConfig.getJndiProperties(); + if (jndiPropertyList != null) { + Hashtable jndiProperties = new Hashtable(); + for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { + jndiProperties.put(prop.getName(), prop.getValue()); + } + dataSource = DeviceManagementDAOUtil + .lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + } else { + dataSource = + DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); + } + } + return dataSource; + } - public static DataSource getDataSource() { - return dataSource; - } + public static DataSource getDataSource() { + return dataSource; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java index f2666bab9d..bed0d07ddd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java @@ -22,20 +22,21 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType; import java.util.List; /** - * This class represents the key operations associated with persisting device type related information + * This class represents the key operations associated with persisting device type related + * information. */ public interface DeviceTypeDAO { - void addDeviceType(DeviceType deviceType) throws DeviceManagementDAOException; + void addDeviceType(DeviceType deviceType) throws DeviceManagementDAOException; - void updateDeviceType(DeviceType deviceType) throws DeviceManagementDAOException; + void updateDeviceType(DeviceType deviceType) throws DeviceManagementDAOException; - List getDeviceTypes() throws DeviceManagementDAOException; + List getDeviceTypes() throws DeviceManagementDAOException; - DeviceType getDeviceType(Integer id) throws DeviceManagementDAOException; + DeviceType getDeviceType(Integer id) throws DeviceManagementDAOException; - Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException; + Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException; - void removeDeviceType(DeviceType deviceType) throws DeviceManagementDAOException; + void removeDeviceType(DeviceType deviceType) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index e47fbcc17e..54010a8554 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -44,15 +44,16 @@ public class DeviceDAOImpl implements DeviceDAO { this.dataSource = dataSource; } - @Override public void addDevice(Device device) throws DeviceManagementDAOException { + @Override + public void addDevice(Device device) throws DeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; try { conn = this.getConnection(); String createDBQuery = - "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DATE_OF_ENROLLMENT, DATE_OF_LAST_UPDATE, OWNERSHIP," + - "STATUS, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, OWNER, TENANT_ID) VALUES " + - "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DATE_OF_ENROLLMENT, DATE_OF_LAST_UPDATE, " + + "OWNERSHIP, STATUS, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, OWNER, TENANT_ID) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(createDBQuery); stmt.setString(1, device.getDescription()); @@ -75,23 +76,29 @@ public class DeviceDAOImpl implements DeviceDAO { } } - @Override public void updateDevice(Device device) throws DeviceManagementDAOException { + @Override + public void updateDevice(Device device) throws DeviceManagementDAOException { } - @Override public void updateDeviceStatus(Long deviceId, Status status) throws DeviceManagementDAOException { + @Override + public void updateDeviceStatus(Long deviceId, Status status) + throws DeviceManagementDAOException { } - @Override public void deleteDevice(Long deviceId) throws DeviceManagementDAOException { + @Override + public void deleteDevice(Long deviceId) throws DeviceManagementDAOException { } - @Override public Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException { + @Override + public Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException { return null; } - @Override public Device getDeviceByDeviceIdentifier(Integer type, String identifier) + @Override + public Device getDeviceByDeviceIdentifier(Integer type, String identifier) throws DeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; @@ -102,7 +109,8 @@ public class DeviceDAOImpl implements DeviceDAO { String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " + "DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " + "DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " + - "WHERE DM_DEVICE.DEVICE_TYPE_ID=? AND DM_DEVICE.DEVICE_IDENTIFICATION=?"; + "WHERE DM_DEVICE.DEVICE_TYPE_ID=? AND " + + "DM_DEVICE.DEVICE_IDENTIFICATION=?"; stmt = conn.prepareStatement(selectDBQueryForType); stmt.setInt(1, type); stmt.setString(2, identifier); @@ -132,11 +140,13 @@ public class DeviceDAOImpl implements DeviceDAO { return device; } - @Override public List getDevices() throws DeviceManagementDAOException { + @Override + public List getDevices() throws DeviceManagementDAOException { return null; } - @Override public List getDevices(Integer type) throws DeviceManagementDAOException { + @Override + public List getDevices(Integer type) throws DeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; ResultSet resultSet = null; @@ -181,8 +191,9 @@ public class DeviceDAOImpl implements DeviceDAO { try { return dataSource.getConnection(); } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while obtaining a connection from the device " + - "management metadata repository datasource", e); + throw new DeviceManagementDAOException( + "Error occurred while obtaining a connection from the device " + + "management metadata repository datasource", e); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java index 7c684993c9..03b1be93e5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java @@ -40,121 +40,124 @@ import java.util.Hashtable; public final class DeviceManagementDAOUtil { - private static final Log log = LogFactory.getLog(DeviceManagementDAOUtil.class); + private static final Log log = LogFactory.getLog(DeviceManagementDAOUtil.class); - public static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) { - if (rs != null) { - try { - rs.close(); - } catch (SQLException e) { - log.warn("Error occurred while closing result set", e); - } - } - if (stmt != null) { - try { - stmt.close(); - } catch (SQLException e) { - log.warn("Error occurred while closing prepared statement", e); - } - } - if (conn != null) { - try { - conn.close(); - } catch (SQLException e) { - log.warn("Error occurred while closing database connection", e); - } - } - } + public static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing result set", e); + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing prepared statement", e); + } + } + if (conn != null) { + try { + conn.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing database connection", e); + } + } + } - /** - * Get id of the current tenant. - * - * @return tenant id - * @throws DeviceManagementDAOException if an error is observed when getting tenant id - */ - public static int getTenantId() throws DeviceManagementDAOException { - CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); - int tenantId = context.getTenantId(); - if (tenantId != MultitenantConstants.INVALID_TENANT_ID) { - return tenantId; - } - String tenantDomain = context.getTenantDomain(); - if (tenantDomain == null) { - String msg = "Tenant domain is not properly set and thus, is null"; - throw new DeviceManagementDAOException(msg); - } - TenantManager tenantManager = DeviceManagementDataHolder.getInstance().getTenantManager(); - try { - tenantId = tenantManager.getTenantId(tenantDomain); - } catch (UserStoreException e) { - String msg = "Error occurred while retrieving id from the domain of tenant " + tenantDomain; - throw new DeviceManagementDAOException(msg); - } - return tenantId; - } + /** + * Get id of the current tenant. + * + * @return tenant id + * @throws DeviceManagementDAOException if an error is observed when getting tenant id + */ + public static int getTenantId() throws DeviceManagementDAOException { + CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); + int tenantId = context.getTenantId(); + if (tenantId != MultitenantConstants.INVALID_TENANT_ID) { + return tenantId; + } + String tenantDomain = context.getTenantDomain(); + if (tenantDomain == null) { + String msg = "Tenant domain is not properly set and thus, is null"; + throw new DeviceManagementDAOException(msg); + } + TenantManager tenantManager = DeviceManagementDataHolder.getInstance().getTenantManager(); + try { + tenantId = tenantManager.getTenantId(tenantDomain); + } catch (UserStoreException e) { + String msg = + "Error occurred while retrieving id from the domain of tenant " + tenantDomain; + throw new DeviceManagementDAOException(msg); + } + return tenantId; + } - public static DataSource lookupDataSource(String dataSourceName, final Hashtable jndiProperties) { - try { - if (jndiProperties == null || jndiProperties.isEmpty()) { - return (DataSource) InitialContext.doLookup(dataSourceName); - } - final InitialContext context = new InitialContext(jndiProperties); - return (DataSource) context.lookup(dataSourceName); - } catch (Exception e) { - throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e); - } - } + public static DataSource lookupDataSource(String dataSourceName, + final Hashtable jndiProperties) { + try { + if (jndiProperties == null || jndiProperties.isEmpty()) { + return (DataSource) InitialContext.doLookup(dataSourceName); + } + final InitialContext context = new InitialContext(jndiProperties); + return (DataSource) context.lookup(dataSourceName); + } catch (Exception e) { + throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e); + } + } - /** - * @param device - The DTO device object. - * @param deviceType - The DeviceType object associated with the device - * @return A Business Object. - */ - public static org.wso2.carbon.device.mgt.common.Device convertDevice(Device device, DeviceType deviceType){ - org.wso2.carbon.device.mgt.common.Device deviceBO = - new org.wso2.carbon.device.mgt.common.Device(); - deviceBO.setDateOfEnrolment(device.getDateOfEnrollment()); - deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate()); - deviceBO.setDescription(device.getDescription()); - deviceBO.setDeviceIdentifier(device.getDeviceIdentificationId()); - deviceBO.setDeviceTypeId(device.getDeviceTypeId()); - deviceBO.setType(deviceType.getName()); - deviceBO.setName(device.getName()); - deviceBO.setId(device.getId()); - deviceBO.setOwner(device.getOwnerId()); - deviceBO.setOwnership(device.getOwnerShip()); - if (device.getStatus() == Status.ACTIVE) { - deviceBO.setStatus(true); - } else if (device.getStatus() == Status.INACTIVE) { - deviceBO.setStatus(false); - } - return deviceBO; - } + /** + * @param device - The DTO device object. + * @param deviceType - The DeviceType object associated with the device + * @return A Business Object. + */ + public static org.wso2.carbon.device.mgt.common.Device convertDevice(Device device, + DeviceType deviceType) { + org.wso2.carbon.device.mgt.common.Device deviceBO = + new org.wso2.carbon.device.mgt.common.Device(); + deviceBO.setDateOfEnrolment(device.getDateOfEnrollment()); + deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate()); + deviceBO.setDescription(device.getDescription()); + deviceBO.setDeviceIdentifier(device.getDeviceIdentificationId()); + deviceBO.setDeviceTypeId(device.getDeviceTypeId()); + deviceBO.setType(deviceType.getName()); + deviceBO.setName(device.getName()); + deviceBO.setId(device.getId()); + deviceBO.setOwner(device.getOwnerId()); + deviceBO.setOwnership(device.getOwnerShip()); + if (device.getStatus() == Status.ACTIVE) { + deviceBO.setStatus(true); + } else if (device.getStatus() == Status.INACTIVE) { + deviceBO.setStatus(false); + } + return deviceBO; + } - public static Device convertDevice(org.wso2.carbon.device.mgt.common.Device - device) throws DeviceManagementDAOException { - Device deviceBO = new Device(); - deviceBO.setDescription(device.getDescription()); - deviceBO.setName(device.getName()); - deviceBO.setDateOfEnrollment(device.getDateOfEnrolment()); - deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate()); + public static Device convertDevice(org.wso2.carbon.device.mgt.common.Device + device) throws DeviceManagementDAOException { + Device deviceBO = new Device(); + deviceBO.setDescription(device.getDescription()); + deviceBO.setName(device.getName()); + deviceBO.setDateOfEnrollment(device.getDateOfEnrolment()); + deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate()); - if (!device.isStatus()){ - deviceBO.setStatus(Status.INACTIVE); - }else{ - deviceBO.setStatus(Status.ACTIVE); - } - deviceBO.setOwnerId(device.getOwner()); - deviceBO.setOwnerShip(device.getOwnership()); - deviceBO.setTenantId(DeviceManagementDAOUtil.getTenantId()); - deviceBO.setDeviceIdentificationId(device.getDeviceIdentifier()); - return deviceBO; - } + if (!device.isStatus()) { + deviceBO.setStatus(Status.INACTIVE); + } else { + deviceBO.setStatus(Status.ACTIVE); + } + deviceBO.setOwnerId(device.getOwner()); + deviceBO.setOwnerShip(device.getOwnership()); + deviceBO.setTenantId(DeviceManagementDAOUtil.getTenantId()); + deviceBO.setDeviceIdentificationId(device.getDeviceIdentifier()); + return deviceBO; + } - public static DeviceIdentifier createDeviceIdentifier(Device device, DeviceType deviceType) { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); - deviceIdentifier.setType(deviceType.getName()); - deviceIdentifier.setId(device.getDeviceIdentificationId()); - return deviceIdentifier; - } + public static DeviceIdentifier createDeviceIdentifier(Device device, DeviceType deviceType) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setType(deviceType.getName()); + deviceIdentifier.setId(device.getDeviceIdentificationId()); + return deviceIdentifier; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 96a591ef75..f97d232226 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -52,112 +52,123 @@ import org.wso2.carbon.user.core.service.RealmService; */ public class DeviceManagementServiceComponent { - private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); - private DeviceManagementRepository pluginRepository = new DeviceManagementRepository(); + private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); + private DeviceManagementRepository pluginRepository = new DeviceManagementRepository(); - protected void activate(ComponentContext componentContext) { - try { - if (log.isDebugEnabled()) { - log.debug("Initializing device management core bundle"); - } - /* Initializing Device Management Configuration */ - DeviceConfigurationManager.getInstance().initConfig(); - DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); + protected void activate(ComponentContext componentContext) { + try { + if (log.isDebugEnabled()) { + log.debug("Initializing device management core bundle"); + } + /* Initializing Device Management Configuration */ + DeviceConfigurationManager.getInstance().initConfig(); + DeviceManagementConfig config = + DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); - DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig(); - DeviceManagementDAOFactory.init(dsConfig); + DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig(); + DeviceManagementDAOFactory.init(dsConfig); - DeviceManager deviceManager = new DeviceManagerImpl(config, this.getPluginRepository()); - DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager); + DeviceManager deviceManager = new DeviceManagerImpl(config, this.getPluginRepository()); + DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager); /* If -Dsetup option enabled then create device management database schema */ - String setupOption = System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP); - if (setupOption != null) { - if (log.isDebugEnabled()) { - log.debug("-Dsetup is enabled. Device management repository schema initialization is about " + - "to begin"); - } - this.setupDeviceManagementSchema(dsConfig); - } - - if (log.isDebugEnabled()) { - log.debug("Registering OSGi service DeviceManagementService"); - } - BundleContext bundleContext = componentContext.getBundleContext(); - bundleContext.registerService(DeviceManagementService.class.getName(), - new DeviceManagementService(), null); - if (log.isDebugEnabled()) { - log.debug("Device management core bundle has been successfully initialized"); - } - } catch (Throwable e) { - String msg = "Error occurred while initializing device management core bundle"; - log.error(msg, e); - } - } - - private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException { - DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config); - log.info("Initializing device management repository database schema"); - - try { - initializer.createRegistryDatabase(); - } catch (Exception e) { - throw new DeviceManagementException("Error occurred while initializing Device Management " + - "database schema", e); - } - if (log.isDebugEnabled()) { - log.debug("Device management metadata repository schema has been successfully initialized"); - } - } - - /** - * Sets Device Manager service. - * @param deviceManagerService An instance of DeviceManagerService - */ - protected void setDeviceManagerService(DeviceManagerService deviceManagerService) { - if (log.isDebugEnabled()) { - log.debug("Setting Device Management Service Provider : '" + - deviceManagerService.getProviderType() + "'"); - } - this.getPluginRepository().addDeviceManagementProvider(deviceManagerService); - } - - /** - * Unsets Device Management service. - * @param deviceManagerService An Instance of DeviceManagerService - */ - protected void unsetDeviceManagerService(DeviceManagerService deviceManagerService) { - if (log.isDebugEnabled()) { - log.debug("Unsetting Device Management Service Provider : '" + - deviceManagerService.getProviderType() + "'"); - } - this.getPluginRepository().removeDeviceManagementProvider(deviceManagerService); - } - - /** - * Sets Realm Service. - * @param realmService An instance of RealmService - */ - protected void setRealmService(RealmService realmService) { - if (log.isDebugEnabled()) { - log.debug("Setting Realm Service"); - } - DeviceManagementDataHolder.getInstance().setRealmService(realmService); - } - - /** - * Unsets Realm Service. - * @param realmService An instance of RealmService - */ - protected void unsetRealmService(RealmService realmService) { - if (log.isDebugEnabled()) { - log.debug("Unsetting Realm Service"); - } - DeviceManagementDataHolder.getInstance().setRealmService(null); - } - - private DeviceManagementRepository getPluginRepository() { - return pluginRepository; - } + String setupOption = + System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP); + if (setupOption != null) { + if (log.isDebugEnabled()) { + log.debug( + "-Dsetup is enabled. Device management repository schema initialization " + + "is about to begin"); + } + this.setupDeviceManagementSchema(dsConfig); + } + + if (log.isDebugEnabled()) { + log.debug("Registering OSGi service DeviceManagementService"); + } + BundleContext bundleContext = componentContext.getBundleContext(); + bundleContext.registerService(DeviceManagementService.class.getName(), + new DeviceManagementService(), null); + if (log.isDebugEnabled()) { + log.debug("Device management core bundle has been successfully initialized"); + } + } catch (Throwable e) { + String msg = "Error occurred while initializing device management core bundle"; + log.error(msg, e); + } + } + + private void setupDeviceManagementSchema(DataSourceConfig config) + throws DeviceManagementException { + DeviceManagementSchemaInitializer initializer = + new DeviceManagementSchemaInitializer(config); + log.info("Initializing device management repository database schema"); + + try { + initializer.createRegistryDatabase(); + } catch (Exception e) { + throw new DeviceManagementException( + "Error occurred while initializing Device Management " + + "database schema", e); + } + if (log.isDebugEnabled()) { + log.debug( + "Device management metadata repository schema has been successfully initialized"); + } + } + + /** + * Sets Device Manager service. + * + * @param deviceManagerService An instance of DeviceManagerService + */ + protected void setDeviceManagerService(DeviceManagerService deviceManagerService) { + if (log.isDebugEnabled()) { + log.debug("Setting Device Management Service Provider : '" + + deviceManagerService.getProviderType() + "'"); + } + this.getPluginRepository().addDeviceManagementProvider(deviceManagerService); + } + + /** + * Unsets Device Management service. + * + * @param deviceManagerService An Instance of DeviceManagerService + */ + protected void unsetDeviceManagerService(DeviceManagerService deviceManagerService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting Device Management Service Provider : '" + + deviceManagerService.getProviderType() + "'"); + } + this.getPluginRepository().removeDeviceManagementProvider(deviceManagerService); + } + + /** + * Sets Realm Service. + * + * @param realmService An instance of RealmService + */ + protected void setRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Setting Realm Service"); + } + DeviceManagementDataHolder.getInstance().setRealmService(realmService); + } + + /** + * Unsets Realm Service. + * + * @param realmService An instance of RealmService + */ + protected void unsetRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting Realm Service"); + } + DeviceManagementDataHolder.getInstance().setRealmService(null); + } + + private DeviceManagementRepository getPluginRepository() { + return pluginRepository; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index 9deed355f1..cb908edd7e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -28,66 +28,69 @@ import java.util.List; public class DeviceManagementService implements DeviceManager { - @Override - public boolean enrollDevice(Device device) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().enrollDevice(device); - } - - @Override - public boolean modifyEnrollment(Device device) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().modifyEnrollment(device); - } - - @Override - public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager() - .disenrollDevice(deviceId); - } - - @Override - public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().isEnrolled(deviceId); - } - - @Override - public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().isActive(deviceId); - } - - @Override - public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().setActive(deviceId, status); - } - - @Override - public List getAllDevices(String type) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().getAllDevices(type); - } - - @Override - public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId) - throws DeviceManagementException { - - Device device = DeviceManagementDataHolder.getInstance().getDeviceManager().getDevice(deviceId); - return device; - } - - @Override - public boolean updateDeviceInfo(Device device) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().updateDeviceInfo(device); - } - - @Override - public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) - throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager() - .setOwnership(deviceId, ownershipType); - } - - @Override - public OperationManager getOperationManager(String type) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager(). - getOperationManager(type); - } + @Override + public boolean enrollDevice(Device device) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().enrollDevice(device); + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().modifyEnrollment(device); + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager() + .disenrollDevice(deviceId); + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().isEnrolled(deviceId); + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().isActive(deviceId); + } + + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager() + .setActive(deviceId, status); + } + + @Override + public List getAllDevices(String type) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().getAllDevices(type); + } + + @Override + public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId) + throws DeviceManagementException { + + Device device = + DeviceManagementDataHolder.getInstance().getDeviceManager().getDevice(deviceId); + return device; + } + + @Override + public boolean updateDeviceInfo(Device device) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().updateDeviceInfo(device); + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager() + .setOwnership(deviceId, ownershipType); + } + + @Override + public OperationManager getOperationManager(String type) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager(). + getOperationManager(type); + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java index bccbcea3c7..7358c52596 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/LicenseManagementService.java @@ -27,8 +27,10 @@ import org.wso2.carbon.device.mgt.core.internal.LicenseManagementDataHolder; public class LicenseManagementService implements LicenseManager { - @Override - public License getLicense(String deviceType, String languageCode) throws LicenseManagementException { - return LicenseManagementDataHolder.getInstance().getLicenseManager().getLicense(deviceType, languageCode); - } + @Override + public License getLicense(String deviceType, String languageCode) + throws LicenseManagementException { + return LicenseManagementDataHolder.getInstance().getLicenseManager() + .getLicense(deviceType, languageCode); + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagementSchemaInitializer.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagementSchemaInitializer.java index b7d6a7b2a7..57880cbd03 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagementSchemaInitializer.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagementSchemaInitializer.java @@ -29,20 +29,21 @@ import java.io.File; public final class DeviceManagementSchemaInitializer extends DatabaseCreator { - private static final Log log = LogFactory.getLog(DeviceManagementSchemaInitializer.class); - private static final String setupSQLScriptBaseLocation = - CarbonUtils.getCarbonHome() + File.separator + "dbscripts" + File.separator + "cdm" + File.separator; - - public DeviceManagementSchemaInitializer(DataSourceConfig config) { - super(DeviceManagerUtil.resolveDataSource(config)); - } - - protected String getDbScriptLocation(String databaseType) { - String scriptName = databaseType + ".sql"; - if (log.isDebugEnabled()) { - log.debug("Loading database script from :" + scriptName); - } - return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName; - } + private static final Log log = LogFactory.getLog(DeviceManagementSchemaInitializer.class); + private static final String setupSQLScriptBaseLocation = + CarbonUtils.getCarbonHome() + File.separator + "dbscripts" + File.separator + "cdm" + + File.separator; + + public DeviceManagementSchemaInitializer(DataSourceConfig config) { + super(DeviceManagerUtil.resolveDataSource(config)); + } + + protected String getDbScriptLocation(String databaseType) { + String scriptName = databaseType + ".sql"; + if (log.isDebugEnabled()) { + log.debug("Loading database script from :" + scriptName); + } + return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index cfeb39c153..fd4a442164 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -50,8 +50,9 @@ public final class DeviceManagerUtil { DocumentBuilder docBuilder = factory.newDocumentBuilder(); return docBuilder.parse(file); } catch (Exception e) { - throw new DeviceManagementException("Error occurred while parsing file, while converting " + - "to a org.w3c.dom.Document : " + e.getMessage(), e); + throw new DeviceManagementException( + "Error occurred while parsing file, while converting " + + "to a org.w3c.dom.Document : " + e.getMessage(), e); } } @@ -65,23 +66,28 @@ public final class DeviceManagerUtil { DataSource dataSource = null; if (config == null) { throw new RuntimeException( - "Device Management Repository data source configuration " + "is null and thus, is not initialized"); + "Device Management Repository data source configuration " + + "is null and thus, is not initialized"); } JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); if (jndiConfig != null) { if (log.isDebugEnabled()) { log.debug( - "Initializing Device Management Repository data source using the JNDI " + "Lookup Definition"); + "Initializing Device Management Repository data source using the JNDI " + + "Lookup Definition"); } - List jndiPropertyList = jndiConfig.getJndiProperties(); + List jndiPropertyList = + jndiConfig.getJndiProperties(); if (jndiPropertyList != null) { Hashtable jndiProperties = new Hashtable(); for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { jndiProperties.put(prop.getName(), prop.getValue()); } - dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + dataSource = DeviceManagementDAOUtil + .lookupDataSource(jndiConfig.getJndiName(), jndiProperties); } else { - dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); + dataSource = + DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); } } return dataSource; From 3032b1c55f0afc36c5fd3d34180838a120f4044f Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Thu, 12 Feb 2015 20:04:48 +0530 Subject: [PATCH 2/6] Adding policy components, renamed the evaluator as the complex policy decision point, added the PIP component and simple policy decision point, Add the interfaces related to policies --- .../pom.xml | 8 +- .../policy/evaluator/FeatureFilter.java | 0 .../policy/evaluator/FeatureFilterImpl.java | 0 .../carbon/policy/evaluator/FeatureRules.java | 0 .../carbon/policy/evaluator/PDPException.java | 0 .../policy/evaluator/PDPServiceImpl.java | 0 .../carbon/policy/evaluator/PolicyFilter.java | 0 .../policy/evaluator/PolicyFilterImpl.java | 0 .../policy/evaluator/spi/PDPService.java | 0 .../policy/evaluator/utils/Constants.java | 0 .../pom.xml | 67 ++++++++ .../point/PolicyInformationServiceImpl.java | 43 ++++++ .../java/org/wso2/carbon/policy/AppTest.java | 38 +++++ .../policy/mgt/common/PIPDeviceData.java | 39 +++++ .../wso2/carbon/policy/mgt/common/Policy.java | 146 +++++++++++++++--- ...e.java => PolicyAdministratorService.java} | 23 ++- .../mgt/common/PolicyEvaluationService.java | 44 ++++++ .../mgt/common/PolicyInformationService.java | 50 ++++++ .../mgt/common/impl/PolicyManagement.java | 4 +- .../pom.xml | 64 ++++++++ .../point/PolicyEvaluationServiceImpl.java | 38 +++++ .../java/org/wso2/carbon/policy/AppTest.java | 38 +++++ components/policy-mgt/pom.xml | 4 +- 23 files changed, 574 insertions(+), 32 deletions(-) rename components/policy-mgt/{org.wso2.carbon.policy.evalutor => org.wso2.carbon.complex.policy.decision.point}/pom.xml (89%) rename components/policy-mgt/{org.wso2.carbon.policy.evalutor => org.wso2.carbon.complex.policy.decision.point}/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilter.java (100%) rename components/policy-mgt/{org.wso2.carbon.policy.evalutor => org.wso2.carbon.complex.policy.decision.point}/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java (100%) rename components/policy-mgt/{org.wso2.carbon.policy.evalutor => org.wso2.carbon.complex.policy.decision.point}/src/main/java/org/wso2/carbon/policy/evaluator/FeatureRules.java (100%) rename components/policy-mgt/{org.wso2.carbon.policy.evalutor => org.wso2.carbon.complex.policy.decision.point}/src/main/java/org/wso2/carbon/policy/evaluator/PDPException.java (100%) rename components/policy-mgt/{org.wso2.carbon.policy.evalutor => org.wso2.carbon.complex.policy.decision.point}/src/main/java/org/wso2/carbon/policy/evaluator/PDPServiceImpl.java (100%) rename components/policy-mgt/{org.wso2.carbon.policy.evalutor => org.wso2.carbon.complex.policy.decision.point}/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilter.java (100%) rename components/policy-mgt/{org.wso2.carbon.policy.evalutor => org.wso2.carbon.complex.policy.decision.point}/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java (100%) rename components/policy-mgt/{org.wso2.carbon.policy.evalutor => org.wso2.carbon.complex.policy.decision.point}/src/main/java/org/wso2/carbon/policy/evaluator/spi/PDPService.java (100%) rename components/policy-mgt/{org.wso2.carbon.policy.evalutor => org.wso2.carbon.complex.policy.decision.point}/src/main/java/org/wso2/carbon/policy/evaluator/utils/Constants.java (100%) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml create mode 100644 components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.information.point/src/test/java/org/wso2/carbon/policy/AppTest.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java rename components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/{PolicyManagerService.java => PolicyAdministratorService.java} (84%) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationService.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationService.java create mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml create mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java create mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/test/java/org/wso2/carbon/policy/AppTest.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.evalutor/pom.xml b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml similarity index 89% rename from components/policy-mgt/org.wso2.carbon.policy.evalutor/pom.xml rename to components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml index f0e929c46f..6777e348ba 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.evalutor/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/pom.xml @@ -28,7 +28,7 @@ 4.0.0 org.wso2.carbon.devicemgt - org.wso2.carbon.policy.evaluator + org.wso2.carbon.complex.policy.decision.point 0.9.1-SNAPSHOT bundle WSO2 Carbon - Policy Decision Point @@ -51,10 +51,10 @@ ${project.artifactId} ${project.artifactId} ${carbon.device.mgt.version} - Policy Management Common Bundle - org.wso2.carbon.policy.evaluator + Complex Policy Decision Point Bundle + org.wso2.carbon.complex.policy.decision.point.internal - org.wso2.carbon.policy.evaluator.* + org.wso2.carbon.complex.policy.decision.point.* diff --git a/components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilter.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilter.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilter.java rename to components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilter.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java rename to components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureFilterImpl.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/FeatureRules.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureRules.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/FeatureRules.java rename to components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/FeatureRules.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/PDPException.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PDPException.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/PDPException.java rename to components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PDPException.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/PDPServiceImpl.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PDPServiceImpl.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/PDPServiceImpl.java rename to components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PDPServiceImpl.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilter.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilter.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilter.java rename to components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilter.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java rename to components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/PolicyFilterImpl.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/spi/PDPService.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/spi/PDPService.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/spi/PDPService.java rename to components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/spi/PDPService.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/utils/Constants.java b/components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/utils/Constants.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.evalutor/src/main/java/org/wso2/carbon/policy/evaluator/utils/Constants.java rename to components/policy-mgt/org.wso2.carbon.complex.policy.decision.point/src/main/java/org/wso2/carbon/policy/evaluator/utils/Constants.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml new file mode 100644 index 0000000000..79cb29e195 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml @@ -0,0 +1,67 @@ + + + + org.wso2.carbon.devicemgt + policy-mgt + 0.9.1-SNAPSHOT + ../pom.xml + + + + 4.0.0 + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.information.point + 0.9.1-SNAPSHOT + bundle + WSO2 Carbon - Policy Information Point + WSO2 Carbon - Policy Information Point + http://wso2.org + + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Policy Information Point Bundle + org.wso2.carbon.policy.information.point.internal + + org.wso2.carbon.policy.information.point.* + + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.equinox + org.eclipse.equinox.common + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.mgt.common + + + + diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java new file mode 100644 index 0000000000..5ce43efddf --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/PolicyInformationServiceImpl.java @@ -0,0 +1,43 @@ +/* +* 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.policy.information.point; + +import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.policy.mgt.common.PIPDeviceData; +import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.PolicyInformationService; + +import java.util.List; + +public class PolicyInformationServiceImpl implements PolicyInformationService{ + @Override + public void getDeviceData(PIPDeviceData pipDeviceData) { + + } + + @Override + public List getRelatedPolicies(PIPDeviceData pipDeviceData) { + return null; + } + + @Override + public List getRelatedFeatures(String deviceType) { + return null; + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/test/java/org/wso2/carbon/policy/AppTest.java b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/test/java/org/wso2/carbon/policy/AppTest.java new file mode 100644 index 0000000000..64bc008ddd --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/test/java/org/wso2/carbon/policy/AppTest.java @@ -0,0 +1,38 @@ +package org.wso2.carbon.policy; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java new file mode 100644 index 0000000000..caf5c81e2c --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDeviceData.java @@ -0,0 +1,39 @@ +/* +* 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.policy.mgt.common; + +import java.sql.Timestamp; +import java.util.List; +import java.util.Map; + +public class PIPDeviceData { + + String deviceId; + String deviceType; + String ownershipType; + List userIds; + List roles; + String altitude; + String longitude; + Timestamp timestamp; + + /*This will be used to record attributes to which would come from other PDPs*/ + Map attributes; + +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java index 0a253421ba..f0f930f57f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java @@ -18,16 +18,82 @@ package org.wso2.carbon.policy.mgt.common; +import java.sql.Date; import java.util.List; +import java.util.Map; +/** + * This class will be the used to create policy object with relevant information for evaluating. + */ public class Policy { - private int id; - private String policyName; - private List featuresList; - private boolean generic; - private List roleList; - private List DeviceList; - private String deviceType; + private int id; // Identifier of the policy. + private int priorityId; // Priority of the policies. This will be used only for simple evaluation. + private String policyName; // Name of the policy. + private List featuresList; // Features included in the policies. + private boolean generic; // If true, this should be applied to all related device. + private List roleList; // Roles which this policy should be applied. + private String ownershipType; // Ownership type (COPE, BYOD, CPE) + private List DeviceList; // Individual devices this policy should be applied + private String deviceType; // Device type to apply the policy. + + /*Dynamic policy attributes*/ + + /*These are related to time based policies*/ + + private int startTime; // Start time to apply the policy. + private int endTime; // After this time policy will not be applied + private Date startDate; // Start date to apply the policy + private Date endDate; // After this date policy will not be applied. + + + /*These are related to location based policies*/ + + private String altitude; // Altitude + private String longitude; // Longitude + + /*This will be used to record attributes which will be used by customer extended PDPs and PIPs*/ + + private Map attributes; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getPriorityId() { + return priorityId; + } + + public void setPriorityId(int priorityId) { + this.priorityId = priorityId; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public List getFeaturesList() { + return featuresList; + } + + public void setFeaturesList(List featuresList) { + this.featuresList = featuresList; + } + + public boolean isGeneric() { + return generic; + } + + public void setGeneric(boolean generic) { + this.generic = generic; + } public List getRoleList() { return roleList; @@ -37,6 +103,14 @@ public class Policy { this.roleList = roleList; } + public String getOwnershipType() { + return ownershipType; + } + + public void setOwnershipType(String ownershipType) { + this.ownershipType = ownershipType; + } + public List getDeviceList() { return DeviceList; } @@ -53,35 +127,59 @@ public class Policy { this.deviceType = deviceType; } - public boolean isGeneric() { - return generic; + public int getStartTime() { + return startTime; } - public void setGeneric(boolean generic) { - this.generic = generic; + public void setStartTime(int startTime) { + this.startTime = startTime; } - public int getId() { - return id; + public int getEndTime() { + return endTime; } - public void setId(int id) { - this.id = id; + public void setEndTime(int endTime) { + this.endTime = endTime; } - public String getPolicyName() { - return policyName; + public Date getStartDate() { + return startDate; } - public void setPolicyName(String policyName) { - this.policyName = policyName; + public void setStartDate(Date startDate) { + this.startDate = startDate; } - public List getFeaturesList() { - return featuresList; + public Date getEndDate() { + return endDate; } - public void setFeaturesList(List featuresList) { - this.featuresList = featuresList; + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + + public String getAltitude() { + return altitude; + } + + public void setAltitude(String altitude) { + this.altitude = altitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; } -} +} \ No newline at end of file diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorService.java similarity index 84% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyManagerService.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorService.java index 1fff4e79fb..4534254ad9 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyManagerService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyAdministratorService.java @@ -22,7 +22,7 @@ package org.wso2.carbon.policy.mgt.common; * This interface defines the policy management which should be implemented by the plugins */ -public interface PolicyManagerService { +public interface PolicyAdministratorService { /** * This method adds a policy to the platform @@ -100,11 +100,32 @@ public interface PolicyManagerService { Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException; + /** + * This method checks weather a policy is available for a device. + * @param deviceId + * @param deviceType + * @return + * @throws PolicyManagementException + */ boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException; + /** + * This method checks weather a policy is used by a particular device. + * @param deviceId + * @param deviceType + * @return + * @throws PolicyManagementException + */ boolean isPolicyUsed(String deviceId, String deviceType) throws PolicyManagementException; + /** + * + * @param deviceId + * @param deviceType + * @param policy + * @throws PolicyManagementException + */ void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationService.java new file mode 100644 index 0000000000..b5082c578d --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationService.java @@ -0,0 +1,44 @@ +/* +* 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.policy.mgt.common; + +import java.util.List; + +/** + * This is the interface which will be used to create plug-able policy decision points. + */ +public interface PolicyEvaluationService { + + + /** + * This method returns the effective policy from the list. + * @param pipDeviceData device information. + * @return returns the effective policy. + */ + Policy getEffectivePolicy(PIPDeviceData pipDeviceData); + + + /** + * This class will return the effective feature set from the list. + * @param pipDeviceData device information. + * @return returns the effective feature set. + */ + List getEffectiveFeatures(PIPDeviceData pipDeviceData); +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationService.java new file mode 100644 index 0000000000..ea9509506a --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyInformationService.java @@ -0,0 +1,50 @@ +/* +* 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.policy.mgt.common; + +import java.util.List; + +/** + * This will be used retrieve data database. This interface has to be implemented by PIP. PIP will be plug-able. + */ +public interface PolicyInformationService { + + /** + * This method will return the data related Device, Some of the device data will provided in the initial pipDeviceData object such as + * device id, device time and location, Other data such as roles, owned users and ownership type will be filled by this method. + * @param pipDeviceData device data. + */ + void getDeviceData(PIPDeviceData pipDeviceData); + + /** + * This method will retrieve the policies related given device Data. + * @param pipDeviceData + * @return + */ + List getRelatedPolicies(PIPDeviceData pipDeviceData); + + /** + * This is will retrieve the features related to device type. This feature list will be used for dynamically + * merging the policies. + * @param deviceType + * @return + */ + List getRelatedFeatures(String deviceType); +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java index de830e596b..3ec34a90f2 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/impl/PolicyManagement.java @@ -20,10 +20,10 @@ package org.wso2.carbon.policy.mgt.common.impl; import org.wso2.carbon.policy.mgt.common.FeatureManagementException; import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.PolicyAdministratorService; import org.wso2.carbon.policy.mgt.common.PolicyManagementException; -import org.wso2.carbon.policy.mgt.common.PolicyManagerService; -public class PolicyManagement implements PolicyManagerService { +public class PolicyManagement implements PolicyAdministratorService { @Override public int addPolicy(Policy policy) { return 0; diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml new file mode 100644 index 0000000000..8363e939da --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml @@ -0,0 +1,64 @@ + + + + org.wso2.carbon.devicemgt + policy-mgt + 0.9.1-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.devicemgt + org.wso2.carbon.simple.policy.decision.point + 0.9.1-SNAPSHOT + bundle + WSO2 Carbon - Simple Policy Decision Point + WSO2 Carbon - Simple Policy Decision Point + http://wso2.org + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Simple Policy Decision Point Bundle + org.wso2.carbon.simple.policy.decision.point.internal + + org.wso2.carbon.simple.policy.decision.point.* + + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.equinox + org.eclipse.equinox.common + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.mgt.common + + + diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java new file mode 100644 index 0000000000..fbeb04c7a4 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java @@ -0,0 +1,38 @@ +/* +* 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.simple.policy.decision.point; + +import org.wso2.carbon.policy.mgt.common.Feature; +import org.wso2.carbon.policy.mgt.common.PIPDeviceData; +import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationService; + +import java.util.List; + +public class PolicyEvaluationServiceImpl implements PolicyEvaluationService { + @Override + public Policy getEffectivePolicy(PIPDeviceData pipDeviceData) { + return null; + } + + @Override + public List getEffectiveFeatures(PIPDeviceData pipDeviceData) { + return null; + } +} diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/test/java/org/wso2/carbon/policy/AppTest.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/test/java/org/wso2/carbon/policy/AppTest.java new file mode 100644 index 0000000000..64bc008ddd --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/test/java/org/wso2/carbon/policy/AppTest.java @@ -0,0 +1,38 @@ +package org.wso2.carbon.policy; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/components/policy-mgt/pom.xml b/components/policy-mgt/pom.xml index fb3a917c2f..8dc5b9f79b 100644 --- a/components/policy-mgt/pom.xml +++ b/components/policy-mgt/pom.xml @@ -38,7 +38,9 @@ org.wso2.carbon.policy.mgt.core org.wso2.carbon.policy.mgt.common - org.wso2.carbon.policy.evalutor + org.wso2.carbon.policy.information.point + org.wso2.carbon.simple.policy.decision.point + org.wso2.carbon.complex.policy.decision.point From db5b8b1e1e8997d1867540fd5bb458062f5c9072 Mon Sep 17 00:00:00 2001 From: harshanL Date: Fri, 13 Feb 2015 10:19:02 +0530 Subject: [PATCH 3/6] Fixed build issue --- .../java/org/wso2/carbon/policy/AppTest.java | 38 ------------------- .../java/org/wso2/carbon/policy/AppTest.java | 38 ------------------- 2 files changed, 76 deletions(-) delete mode 100644 components/policy-mgt/org.wso2.carbon.policy.information.point/src/test/java/org/wso2/carbon/policy/AppTest.java delete mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/test/java/org/wso2/carbon/policy/AppTest.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/test/java/org/wso2/carbon/policy/AppTest.java b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/test/java/org/wso2/carbon/policy/AppTest.java deleted file mode 100644 index 64bc008ddd..0000000000 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/test/java/org/wso2/carbon/policy/AppTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.wso2.carbon.policy; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } -} diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/test/java/org/wso2/carbon/policy/AppTest.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/test/java/org/wso2/carbon/policy/AppTest.java deleted file mode 100644 index 64bc008ddd..0000000000 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/test/java/org/wso2/carbon/policy/AppTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.wso2.carbon.policy; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } -} From 4d87e3f605fc91c80d45aed97ad20e2369edf18d Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 13 Feb 2015 15:01:42 +0530 Subject: [PATCH 4/6] remove xml data adaptor --- .../mgt/core/config/license/License.java | 40 +++++++++---------- .../LicenseManagementServiceComponent.java | 4 +- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/License.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/License.java index 1ad70a3952..e9d5188559 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/License.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/License.java @@ -20,12 +20,8 @@ package org.wso2.carbon.device.mgt.core.config.license; -import org.wso2.carbon.device.mgt.core.util.DateAdapter; - import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; -import java.util.Date; @XmlRootElement(name = "License") public class License { @@ -34,8 +30,9 @@ public class License { private String name; private String version; private String language; - private Date validFrom; - private Date validTo; + + private String validFrom; + private String validTo; private String license; @XmlElement(name = "provider") @@ -74,31 +71,30 @@ public class License { this.language = language; } - @XmlJavaTypeAdapter(DateAdapter.class) - public Date getValidFrom() { + @XmlElement(name = "license") + public String getLicense() { + return license; + } + + public void setLicense(String license) { + this.license = license; + } + + @XmlElement(name = "validFrom") + public String getValidFrom() { return validFrom; } - public void setValidFrom(Date validFrom) { + public void setValidFrom(String validFrom) { this.validFrom = validFrom; } - @XmlJavaTypeAdapter(DateAdapter.class) - public Date getValidTo() { + @XmlElement(name = "validTo") + public String getValidTo() { return validTo; } - public void setValidTo(Date validTo) { + public void setValidTo(String validTo) { this.validTo = validTo; } - - @XmlElement(name = "license") - public String getLicense() { - return license; - } - - public void setLicense(String license) { - this.license = license; - } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java index 67d2b6a835..abf3f218c0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/LicenseManagementServiceComponent.java @@ -124,9 +124,9 @@ public class LicenseManagementServiceComponent { artifact.setAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_PROVIDER, license.getProvider()); artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO, - license.getValidTo().toString()); + license.getValidTo()); artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM, - license.getValidFrom().toString()); + license.getValidFrom()); artifact.setAttribute(DeviceManagementConstants.LicenseProperties.LICENSE,license.getLicense()); artifactManager.addGenericArtifact(artifact); } From cd3913d43de1c30adf34581731f042595521ab6c Mon Sep 17 00:00:00 2001 From: manoj Date: Fri, 13 Feb 2015 19:43:47 +0530 Subject: [PATCH 5/6] Remove Date Adaptor class --- .../device/mgt/core/util/DateAdapter.java | 40 ------------------- 1 file changed, 40 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DateAdapter.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DateAdapter.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DateAdapter.java deleted file mode 100644 index 246852c80d..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DateAdapter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * 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.util; - -import javax.xml.bind.annotation.adapters.XmlAdapter; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -public class DateAdapter extends XmlAdapter { - - private SimpleDateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy"); - - @Override - public Date unmarshal(String strDate) throws ParseException { - return dateFormat.parse(strDate); - } - @Override - public String marshal(Date date) throws ParseException { - return dateFormat.format(date); - } -} From 60e98f12b2009502f4c678c17a86a186c1db6d39 Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Fri, 13 Feb 2015 19:46:08 +0530 Subject: [PATCH 6/6] Adding the bundle activator for PIP --- .../pom.xml | 1 + ...PolicyInformationPointBundleActivator.java | 66 +++++++++++++++++++ .../PolicyManagementServiceComponent.java | 22 ++++++- .../pom.xml | 21 ++++-- pom.xml | 7 +- 5 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/internal/PolicyInformationPointBundleActivator.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml index 79cb29e195..a0c41a2e6f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml @@ -37,6 +37,7 @@ ${carbon.device.mgt.version} Policy Information Point Bundle org.wso2.carbon.policy.information.point.internal + org.wso2.carbon.policy.information.point.internal.PolicyInformationPointBundleActivator org.wso2.carbon.policy.information.point.* diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/internal/PolicyInformationPointBundleActivator.java b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/internal/PolicyInformationPointBundleActivator.java new file mode 100644 index 0000000000..c25b2855db --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/src/main/java/org/wso2/carbon/policy/information/point/internal/PolicyInformationPointBundleActivator.java @@ -0,0 +1,66 @@ +/* +* 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.policy.information.point.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.wso2.carbon.policy.information.point.PolicyInformationServiceImpl; +import org.wso2.carbon.policy.mgt.common.PolicyInformationService; + +public class PolicyInformationPointBundleActivator implements BundleActivator { + + private ServiceRegistration pipServiceRegRef; + private static final Log log = LogFactory.getLog(PolicyInformationPointBundleActivator.class); + + @Override + public void start(BundleContext bundleContext) throws Exception { + try { + if (log.isDebugEnabled()) { + log.debug("Activating Policy information Point bundle."); + } + + pipServiceRegRef = bundleContext.registerService(PolicyInformationService.class.getName(), + new PolicyInformationServiceImpl(), null); + + if (log.isDebugEnabled()) { + log.debug("Policy information Point bundle is activated."); + } + + } catch (Exception ex) { + log.error("Error occurred while activating the Policy Information Point bundle.", ex); + } + + } + + @Override + public void stop(BundleContext bundleContext) throws Exception { + try { + if (log.isDebugEnabled()) { + log.debug("Policy information Point bundle is deactivated."); + } + pipServiceRegRef.unregister(); + } catch (Exception ex) { + log.error("Error occurred while de-activating the Policy Information Point bundle.", ex); + } + + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java index 573cdc4797..16255d95dc 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java @@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.core.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.policy.mgt.common.PolicyInformationService; import org.wso2.carbon.policy.mgt.core.config.PolicyConfigurationManager; import org.wso2.carbon.policy.mgt.core.config.PolicyManagementConfig; import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig; @@ -28,13 +29,19 @@ import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; import org.wso2.carbon.user.core.service.RealmService; /** - * @scr.component name="org.wso2.carbon.policy.manager" immediate="true" + * @scr.component name="org.wso2.carbon.devicemgt.policy.manager" immediate="true" * @scr.reference name="user.realmservice.default" * interface="org.wso2.carbon.user.core.service.RealmService" * cardinality="1..1" * policy="dynamic" * bind="setRealmService" * unbind="unsetRealmService" + * @scr.reference name="org.wso2.carbon.devicemgt.policy.information.point.default" + * interface="org.wso2.carbon.policy.mgt.common.PolicyInformationService" + * cardinality="1..1" + * policy="dynamic" + * bind="setPIPService" + * unbind="unsetPIPService" */ public class PolicyManagementServiceComponent { @@ -81,4 +88,17 @@ public class PolicyManagementServiceComponent { PolicyManagementDataHolder.getInstance().setRealmService(null); } + + protected void setPIPService(PolicyInformationService policyInformationService) { + if (log.isDebugEnabled()) { + log.debug("Setting Policy Information Service"); + } + } + + protected void unsetPIPService(PolicyInformationService policyInformationService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting Policy Information Service"); + } + } + } diff --git a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml index a13e7f0ccd..903a0a5630 100644 --- a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml +++ b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml @@ -18,7 +18,8 @@ ~ under the License. --> - + org.wso2.carbon.devicemgt @@ -47,7 +48,11 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.policy.evaluator + org.wso2.carbon.complex.policy.decision.point + + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.information.point @@ -99,11 +104,17 @@ - org.wso2.carbon.devicemgt:org.wso2.carbon.policy.mgt.core:${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt:org.wso2.carbon.policy.mgt.core:${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt:org.wso2.carbon.policy.mgt.common:${carbon.device.mgt.version} - org.wso2.carbon.devicemgt:org.wso2.carbon.policy.mgt.common:${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt:org.wso2.carbon.complex.policy.decision.point:${carbon.device.mgt.version} - org.wso2.carbon.devicemgt:org.wso2.carbon.policy.evaluator:${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt:org.wso2.carbon.policy.information.point:${carbon.device.mgt.version} diff --git a/pom.xml b/pom.xml index 8ae2f0e636..ee307fb047 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,12 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.policy.evaluator + org.wso2.carbon.complex.policy.decision.point + ${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.information.point ${carbon.device.mgt.version}