From a3dc5d07e555a117c3c35afda952770bd7eb4824 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Thu, 22 Jan 2015 21:14:35 +0530 Subject: [PATCH] * Commented cdm app copying * Implemented the getDevice() * Added documentation * Added a method to deviceDAO to get the device by a DeviceIdentifier --- .../device/mgt/core/DeviceManagerImpl.java | 21 ++++++++- .../carbon/device/mgt/core/dao/DeviceDAO.java | 8 ++++ .../mgt/core/dao/impl/DeviceDAOImpl.java | 44 ++++++++++++++++++- .../modules/distribution/src/assembly/bin.xml | 16 ++++--- 4 files changed, 80 insertions(+), 9 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 1af868981a..0f5c75cb25 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 @@ -135,7 +135,26 @@ public class DeviceManagerImpl implements DeviceManager { @Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.getDevice(deviceId); + 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()); + } + }else{ + throw new DeviceManagementException("No device found for the id '" + deviceId.getId() + "'"); + } + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while obtaining the device for id '" + deviceId.getId() + "'", + e); + } + return convertedDevice; } @Override 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 d99db291a2..faced8c295 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 @@ -38,6 +38,14 @@ public interface DeviceDAO { Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException; + /** + * @param type - Device type. + * @param identifier - Device identifier. + * @return + * @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/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 97fa8e25b3..8ac8e74e6a 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 @@ -21,8 +21,8 @@ package org.wso2.carbon.device.mgt.core.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; -import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.Device; import org.wso2.carbon.device.mgt.core.dto.Status; @@ -98,6 +98,48 @@ public class DeviceDAOImpl implements DeviceDAO { return null; } + @Override public Device getDeviceByDeviceIdentifier(Integer type, String identifier) + throws DeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + Device device = null; + try { + conn = this.getConnection(); + 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=?"; + stmt = conn.prepareStatement(selectDBQueryForType); + stmt.setInt(1, type); + stmt.setString(2, identifier); + resultSet = stmt.executeQuery(); + while (resultSet.next()) { + device = new Device(); + device.setId(resultSet.getInt(1)); + device.setDescription(resultSet.getString(2)); + device.setName(resultSet.getString(3)); + device.setDateOfEnrollment(resultSet.getLong(4)); + device.setDateOfLastUpdate(resultSet.getLong(5)); + //TODO:- Ownership is not a enum in DeviceDAO + device.setOwnerShip(resultSet.getString(6)); + device.setStatus(Status.valueOf(resultSet.getString(7))); + device.setDeviceTypeId(resultSet.getInt(8)); + device.setDeviceIdentificationId(resultSet.getString(9)); + device.setOwnerId(resultSet.getString(10)); + device.setTenantId(resultSet.getInt(11)); + } + } catch (SQLException e) { + String msg = "Error occurred while listing devices for type '" + type + "'"; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } finally { + DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet); + } + return device; + } + + @Override public List getDevices() throws DeviceManagementDAOException { return null; diff --git a/product/modules/distribution/src/assembly/bin.xml b/product/modules/distribution/src/assembly/bin.xml index 8c186c073d..7a79eb6b89 100644 --- a/product/modules/distribution/src/assembly/bin.xml +++ b/product/modules/distribution/src/assembly/bin.xml @@ -223,13 +223,15 @@ ${project.artifactId}-${project.version}/repository/resources - - - src/repository/jaggeryapps - wso2cdm-${project.version}/repository/deployment/server/jaggeryapps - - 755 - + + + + + + +