Merge branch 'rest-api-improvements' of https://github.com/wso2/carbon-device-mgt into rest-api-improvements

revert-70aa11f8
prabathabey 9 years ago
commit 95458ce9b0

@ -23,6 +23,9 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 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, " + @ApiModel(value = "DeviceWrapper", description = "This contains device details including, " +
"location and device meta information.") "location and device meta information.")
@ -37,6 +40,8 @@ public class DeviceWrapper {
private DeviceInfo deviceInfo; private DeviceInfo deviceInfo;
@ApiModelProperty(name = "deviceLocation", value = "Device's current location", required = true) @ApiModelProperty(name = "deviceLocation", value = "Device's current location", required = true)
private DeviceLocation deviceLocation; private DeviceLocation deviceLocation;
@ApiModelProperty(name = "applications", value = "Application list of devices", required = true)
private List<Application> applications;
public Device getDevice() { public Device getDevice() {
return device; return device;
@ -69,5 +74,13 @@ public class DeviceWrapper {
public void setDeviceLocation(DeviceLocation deviceLocation) { public void setDeviceLocation(DeviceLocation deviceLocation) {
this.deviceLocation = deviceLocation; this.deviceLocation = deviceLocation;
} }
public List<Application> getApplications() {
return applications;
}
public void setApplications(List<Application> applications) {
this.applications = applications;
}
} }

@ -21,6 +21,8 @@ package org.wso2.carbon.device.mgt.core.search.mgt.impl;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; 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.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.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.search.mgt.*; import org.wso2.carbon.device.mgt.core.search.mgt.*;
import org.wso2.carbon.device.mgt.core.search.mgt.dao.SearchDAO; import org.wso2.carbon.device.mgt.core.search.mgt.dao.SearchDAO;
@ -35,9 +37,11 @@ import java.util.Map;
public class ProcessorImpl implements Processor { public class ProcessorImpl implements Processor {
private SearchDAO searchDAO; private SearchDAO searchDAO;
private ApplicationDAO applicationDAO;
public ProcessorImpl() { public ProcessorImpl() {
searchDAO = DeviceManagementDAOFactory.getSearchDAO(); searchDAO = DeviceManagementDAOFactory.getSearchDAO();
applicationDAO = DeviceManagementDAOFactory.getApplicationDAO();
} }
@Override @Override
@ -91,7 +95,9 @@ public class ProcessorImpl implements Processor {
deviceWrappers.put(Constants.PROP_OR, this.processORSearch(allORDevices)); deviceWrappers.put(Constants.PROP_OR, this.processORSearch(allORDevices));
deviceWrappers.put(Constants.LOCATION, locationDevices); deviceWrappers.put(Constants.LOCATION, locationDevices);
return aggregator.aggregate(deviceWrappers); List<DeviceWrapper> finalDeviceWrappers = aggregator.aggregate(deviceWrappers);
this.setApplicationListOfDevices(finalDeviceWrappers);
return finalDeviceWrappers;
} }
@Override @Override
@ -186,5 +192,20 @@ public class ProcessorImpl implements Processor {
return maps; return maps;
} }
private void setApplicationListOfDevices(List<DeviceWrapper> 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();
}
}
} }

Loading…
Cancel
Save