From 6328d357972bb2b59e2ba008918b39c93fec480c Mon Sep 17 00:00:00 2001 From: geethkokila Date: Sat, 28 May 2016 00:19:04 +0530 Subject: [PATCH] Changing the device info object by adding the application list --- .../common/device/details/DeviceWrapper.java | 13 +++++++++ .../core/search/mgt/impl/ProcessorImpl.java | 27 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceWrapper.java index 5efdea1b511..47831da5a3b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceWrapper.java @@ -23,6 +23,9 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; + +import java.util.List; @ApiModel(value = "DeviceWrapper", description = "This contains device details including, " + "location and device meta information.") @@ -38,6 +41,8 @@ public class DeviceWrapper { @ApiModelProperty(name = "deviceLocation", value = "Device's current location", required = true) private DeviceLocation deviceLocation; + private List applications; + public Device getDevice() { return device; } @@ -69,5 +74,13 @@ public class DeviceWrapper { public void setDeviceLocation(DeviceLocation deviceLocation) { this.deviceLocation = deviceLocation; } + + public List getApplications() { + return applications; + } + + public void setApplications(List applications) { + this.applications = applications; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java index 55b377d4f57..275eff3d3aa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java @@ -19,8 +19,13 @@ package org.wso2.carbon.device.mgt.core.search.mgt.impl; +import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.search.SearchContext; +import org.wso2.carbon.device.mgt.core.dao.ApplicationDAO; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.search.mgt.*; import org.wso2.carbon.device.mgt.core.search.mgt.dao.SearchDAO; @@ -35,9 +40,11 @@ import java.util.Map; public class ProcessorImpl implements Processor { private SearchDAO searchDAO; + private ApplicationDAO applicationDAO; public ProcessorImpl() { searchDAO = DeviceManagementDAOFactory.getSearchDAO(); + applicationDAO = DeviceManagementDAOFactory.getApplicationDAO(); } @Override @@ -91,7 +98,9 @@ public class ProcessorImpl implements Processor { deviceWrappers.put(Constants.PROP_OR, this.processORSearch(allORDevices)); deviceWrappers.put(Constants.LOCATION, locationDevices); - return aggregator.aggregate(deviceWrappers); + List finalDeviceWrappers = aggregator.aggregate(deviceWrappers); + this.setApplicationListOfDevices(finalDeviceWrappers); + return finalDeviceWrappers; } @Override @@ -186,5 +195,21 @@ public class ProcessorImpl implements Processor { return maps; } + + private void setApplicationListOfDevices(List deviceWrappers) throws SearchMgtException { + try { + DeviceManagementDAOFactory.openConnection(); + for (DeviceWrapper wrapper : deviceWrappers) { + wrapper.setApplications(applicationDAO.getInstalledApplications(wrapper.getDevice().getId())); + } + } catch (DeviceManagementDAOException e) { + throw new SearchMgtException("Error occurred while fetching the Application List of devices ", e); + } catch (SQLException e) { + throw new SearchMgtException("Error occurred while opening a connection to the data source", e); + } finally { + DeviceManagementDAOFactory.closeConnection(); + } + } + }