From 60e539b583d50fb3541ab18aa546ccc45f97499a Mon Sep 17 00:00:00 2001 From: manoj Date: Tue, 27 Jan 2015 20:20:42 +0530 Subject: [PATCH 1/7] set active status for enroll device --- .../device/mgt/core/DeviceManagerImpl.java | 269 +++++++++--------- 1 file changed, 134 insertions(+), 135 deletions(-) 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 c65a5478d5..8038fee69b 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 @@ -39,141 +39,140 @@ 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()); + 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; - } + 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; + } } From 6e262cb60b17e0e61569186fe54b5d7d00d9dca6 Mon Sep 17 00:00:00 2001 From: manoj Date: Tue, 27 Jan 2015 20:22:38 +0530 Subject: [PATCH 2/7] set active status for enroll device --- .../device/mgt/core/DeviceManagerImpl.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) 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 8038fee69b..139679fb3f 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 @@ -51,10 +51,11 @@ public class DeviceManagerImpl implements DeviceManager { this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); } - @Override public boolean enrollDevice(Device device) throws DeviceManagementException { + @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()); @@ -68,7 +69,8 @@ public class DeviceManagerImpl implements DeviceManager { return status; } - @Override public boolean modifyEnrollment(Device device) throws DeviceManagementException { + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType()); boolean status = dms.modifyEnrollment(device); try { @@ -80,27 +82,32 @@ public class DeviceManagerImpl implements DeviceManager { return status; } - @Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + @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 { + @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 { + @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 { + @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 { + @Override + public List getAllDevices(String type) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type); List devicesList = new ArrayList(); try { @@ -124,7 +131,8 @@ public class DeviceManagerImpl implements DeviceManager { return devicesList; } - @Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); Device convertedDevice = null; try { @@ -147,12 +155,14 @@ public class DeviceManagerImpl implements DeviceManager { return convertedDevice; } - @Override public boolean updateDeviceInfo(Device device) throws DeviceManagementException { + @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) + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); return dms.setOwnership(deviceId, ownershipType); From 62f858d6061507d275c5a02e562f5c8a65cb6c1c Mon Sep 17 00:00:00 2001 From: manoj Date: Tue, 27 Jan 2015 21:28:04 +0530 Subject: [PATCH 3/7] License Management Refactor --- .../mgt/common/DeviceManagementConstants.java | 13 ++++ .../device/mgt/core/LicenseManagerImpl.java | 61 ++++++++++--------- .../core/dao/DeviceManagementDAOTests.java | 11 ++-- 3 files changed, 53 insertions(+), 32 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java index 76c541d337..1c0dba69ff 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java @@ -49,4 +49,17 @@ public final class DeviceManagementConstants { public final static String LANGUAGE_CODE_ENGLISH_UK = "en-uk"; } + public static final class DefaultLicences{ + public static final String DEFAULT_LICENSE_CONFIG_XML_NAME = "DefaultLicense.xml"; + } + + public static final class LicenseProperties{ + public static final String OVERVIEW_PROVIDER = "overview_provider"; + public static final String OVERVIEW_NAME = "overview_name"; + public static final String OVERVIEW_LANGUAGE = "overview_language"; + public static final String OVERVIEW_VERSION = "overview_version"; + public static final String VALID_FROM = "overview_validityFrom"; + public static final String VALID_TO = "overview_validityTo"; + public static final String LICENSE = "overview_license"; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java index d00936e3fa..ca1cfa4cf7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/LicenseManagerImpl.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.RegistryType; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.License; import org.wso2.carbon.device.mgt.common.LicenseManagementException; import org.wso2.carbon.governance.api.exception.GovernanceException; @@ -34,32 +35,33 @@ import org.wso2.carbon.governance.api.util.GovernanceUtils; import org.wso2.carbon.registry.core.Registry; import org.wso2.carbon.registry.core.exceptions.RegistryException; import org.wso2.carbon.registry.core.session.UserRegistry; + import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; - public class LicenseManagerImpl implements LicenseManager { private static Log log = LogFactory.getLog(DeviceManagerImpl.class); + private static final DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH); @Override - public License getLicense(final String deviceType, - final String languageCodes) throws LicenseManagementException { + public License getLicense(final String deviceType, final String languageCodes) throws LicenseManagementException { - if (log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("entered get License in license manager impl"); } // TODO: After completes JAX-RX user login, this need to be change to CarbonContext - PrivilegedCarbonContext.getThreadLocalCarbonContext().startTenantFlow(); + PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername("admin"); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - Registry registry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry( - RegistryType.USER_GOVERNANCE); + Registry registry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getRegistry(RegistryType.USER_GOVERNANCE); GenericArtifact[] filteredArtifacts; License license = new License(); @@ -79,41 +81,44 @@ public class LicenseManagerImpl implements LicenseManager { }); String validFrom; String validTo; - DateFormat format; Date fromDate; Date toDate; for (GenericArtifact artifact : filteredArtifacts) { - if (log.isDebugEnabled()){ - log.debug("Overview name:"+artifact.getAttribute("overview_name")); - log.debug("Overview provider:"+artifact.getAttribute("overview_provider")); - log.debug("Overview Language:"+artifact.getAttribute("overview_language")); - log.debug("overview_validityFrom:"+artifact.getAttribute("overview_validityFrom")); - log.debug("overview_validityTo:"+artifact.getAttribute("overview_validityTo")); + if (log.isDebugEnabled()) { + log.debug("Overview name: " + + artifact.getAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_NAME)); + log.debug("Overview provider: " + + artifact.getAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_PROVIDER)); + log.debug("Overview language: " + + artifact.getAttribute(DeviceManagementConstants.LicenseProperties.OVERVIEW_LANGUAGE)); + log.debug("Overview validity from: " + + artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM)); + log.debug("Overview validity to: " + + artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO)); } - validFrom = artifact.getAttribute("overview_validityFrom"); - validTo = artifact.getAttribute("overview_validityTo"); - format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH); + validFrom = artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM); + validTo = artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO); try { fromDate = format.parse(validFrom); toDate = format.parse(validTo); - if (fromDate.getTime()<= new Date().getTime() && new Date().getTime() <= toDate.getTime()){ - license.setLicenseText(artifact.getAttribute("overview_license")); + if (fromDate.getTime() <= new Date().getTime() && new Date().getTime() <= toDate.getTime()) { + license.setLicenseText( + artifact.getAttribute(DeviceManagementConstants.LicenseProperties.LICENSE)); } } catch (ParseException e) { - log.error("validFrom:"+ validFrom); - log.error("validTo:"+validTo); - log.error("Valid date parse error:",e); + log.error("Valid from: " + validFrom); + log.error("Valid to: " + validTo); + log.error("Valid date parse error: ", e); } } } catch (RegistryException regEx) { - log.error("registry exception:",regEx); - throw new LicenseManagementException(); - }finally { + String errorMsg = "Registry error occurred: "; + log.error(errorMsg, regEx); + throw new LicenseManagementException(errorMsg, regEx); + } finally { PrivilegedCarbonContext.endTenantFlow(); } - return license; } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOTests.java index abde92ae30..546ee767c2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOTests.java @@ -156,22 +156,25 @@ public class DeviceManagementDAOTests { Long deviceId = null; Connection conn = null; PreparedStatement stmt = null; - ResultSet rs = null; + ResultSet rs = null ; + String deviceStatus = null; try { conn = DeviceManagementDAOFactory.getDataSource().getConnection(); - stmt = conn.prepareStatement("SELECT ID from DM_DEVICE DEVICE where DEVICE.DEVICE_IDENTIFICATION='111'"); + stmt = conn.prepareStatement("SELECT ID,STATUS from DM_DEVICE DEVICE where DEVICE.DEVICE_IDENTIFICATION='111'"); rs = stmt.executeQuery(); while (rs.next()) { deviceId = rs.getLong(1); + deviceStatus = rs.getString(2); } } catch (SQLException e) { - throw new DeviceManagementDAOException("error in fetch device by device identification id", e); + throw new DeviceManagementDAOException("Error in fetch device by device identification id", e); } finally { TestUtils.cleanupResources(conn, stmt, rs); } - Assert.assertNotNull(deviceId, "Device Id is null"); + Assert.assertNotNull(deviceStatus,"Device status is null"); + Assert.assertEquals(deviceStatus,"ACTIVE","enroll device status should active"); } } From 79261210f2c63b58db17b4524459c03c684e5ff2 Mon Sep 17 00:00:00 2001 From: manoj Date: Tue, 27 Jan 2015 21:35:14 +0530 Subject: [PATCH 4/7] Refactor license constants --- .../mgt/common/DeviceManagementConstants.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java index 1c0dba69ff..7a451ec564 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java @@ -18,42 +18,62 @@ package org.wso2.carbon.device.mgt.common; public final class DeviceManagementConstants { public static final class DataSourceProperties { + private DataSourceProperties() { throw new AssertionError(); } + public static final String DB_CHECK_QUERY = "SELECT * FROM DM_DEVICE"; public static final String SECURE_VAULT_NS = "http://org.wso2.securevault/configuration"; public static final String DEVICE_CONFIG_XML_NAME = "cdm-config.xml"; } public static final class SecureValueProperties { + private SecureValueProperties() { throw new AssertionError(); } + public static final String SECRET_ALIAS_ATTRIBUTE_NAME_WITH_NAMESPACE = "secretAlias"; public static final String SECURE_VAULT_NS = "http://org.wso2.securevault/configuration"; } public static final class MobileDeviceTypes { + private MobileDeviceTypes() { throw new AssertionError(); } + public final static String MOBILE_DEVICE_TYPE_ANDROID = "android"; public final static String MOBILE_DEVICE_TYPE_IOS = "ios"; public final static String MOBILE_DEVICE_TYPE_WINDOWS = "windows"; } - public static final class LanguageCodes{ - private LanguageCodes() { throw new AssertionError();} + public static final class LanguageCodes { + + private LanguageCodes() { + throw new AssertionError(); + } + public final static String LANGUAGE_CODE_ENGLISH_US = "en-us"; public final static String LANGUAGE_CODE_ENGLISH_UK = "en-uk"; } - public static final class DefaultLicences{ + public static final class DefaultLicences { + + private DefaultLicences() { + throw new AssertionError(); + } + public static final String DEFAULT_LICENSE_CONFIG_XML_NAME = "DefaultLicense.xml"; } - public static final class LicenseProperties{ + public static final class LicenseProperties { + + private LicenseProperties() { + throw new AssertionError(); + } + public static final String OVERVIEW_PROVIDER = "overview_provider"; public static final String OVERVIEW_NAME = "overview_name"; public static final String OVERVIEW_LANGUAGE = "overview_language"; From 2eadf11eaf6dbb3cc4a47c1611ee949b4ab65efa Mon Sep 17 00:00:00 2001 From: manoj Date: Tue, 27 Jan 2015 21:37:23 +0530 Subject: [PATCH 5/7] Refactor license constants --- .../carbon/device/mgt/common/DeviceManagementConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java index 7a451ec564..5e63acb960 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java @@ -73,7 +73,7 @@ public final class DeviceManagementConstants { private LicenseProperties() { throw new AssertionError(); } - + public static final String OVERVIEW_PROVIDER = "overview_provider"; public static final String OVERVIEW_NAME = "overview_name"; public static final String OVERVIEW_LANGUAGE = "overview_language"; From f907684a0bb196a1cd56f3d6c6889bcdd53b1663 Mon Sep 17 00:00:00 2001 From: manoj Date: Tue, 27 Jan 2015 21:38:08 +0530 Subject: [PATCH 6/7] license constants Refactor --- .../java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java | 1 - 1 file changed, 1 deletion(-) 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 139679fb3f..10539ae2fb 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 @@ -184,5 +184,4 @@ public class DeviceManagerImpl implements DeviceManager { public DeviceManagementRepository getPluginRepository() { return pluginRepository; } - } From 428554cfe87a9f9d19c40387251148fcaf0f13c0 Mon Sep 17 00:00:00 2001 From: manoj Date: Tue, 27 Jan 2015 21:51:28 +0530 Subject: [PATCH 7/7] Unit test change to prepared statement --- .../core/dao/DeviceManagementDAOTests.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOTests.java index 546ee767c2..6f1b1a5849 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOTests.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOTests.java @@ -51,15 +51,15 @@ public class DeviceManagementDAOTests { TestDBConfiguration dbConfig = getTestDBConfiguration(dbType); switch (dbType) { - case H2: - createH2DB(dbConfig); - BasicDataSource testDataSource = new BasicDataSource(); - testDataSource.setDriverClassName(dbConfig.getDriverClass()); - testDataSource.setUrl(dbConfig.getConnectionUrl()); - testDataSource.setUsername(dbConfig.getUserName()); - testDataSource.setPassword(dbConfig.getPwd()); - DeviceManagementDAOFactory.init(testDataSource); - default: + case H2: + createH2DB(dbConfig); + BasicDataSource testDataSource = new BasicDataSource(); + testDataSource.setDriverClassName(dbConfig.getDriverClass()); + testDataSource.setUrl(dbConfig.getConnectionUrl()); + testDataSource.setUsername(dbConfig.getUserName()); + testDataSource.setPassword(dbConfig.getPwd()); + DeviceManagementDAOFactory.init(testDataSource); + default: } } @@ -133,7 +133,7 @@ public class DeviceManagementDAOTests { } - @Test(dependsOnMethods = {"addDeviceTypeTest"}) + @Test(dependsOnMethods = { "addDeviceTypeTest" }) public void addDeviceTest() throws DeviceManagementDAOException, DeviceManagementException { DeviceDAO deviceMgtDAO = DeviceManagementDAOFactory.getDeviceDAO(); @@ -156,11 +156,13 @@ public class DeviceManagementDAOTests { Long deviceId = null; Connection conn = null; PreparedStatement stmt = null; - ResultSet rs = null ; + ResultSet rs = null; String deviceStatus = null; try { conn = DeviceManagementDAOFactory.getDataSource().getConnection(); - stmt = conn.prepareStatement("SELECT ID,STATUS from DM_DEVICE DEVICE where DEVICE.DEVICE_IDENTIFICATION='111'"); + stmt = conn.prepareStatement( + "SELECT ID,STATUS from DM_DEVICE DEVICE where DEVICE.DEVICE_IDENTIFICATION=?"); + stmt.setString(1,"111"); rs = stmt.executeQuery(); while (rs.next()) { @@ -173,8 +175,8 @@ public class DeviceManagementDAOTests { TestUtils.cleanupResources(conn, stmt, rs); } Assert.assertNotNull(deviceId, "Device Id is null"); - Assert.assertNotNull(deviceStatus,"Device status is null"); - Assert.assertEquals(deviceStatus,"ACTIVE","enroll device status should active"); + Assert.assertNotNull(deviceStatus, "Device status is null"); + Assert.assertEquals(deviceStatus, "ACTIVE", "Enroll device status should active"); } }