Removing DeviceWrapper and all its associated usage, as it appeared to be a redundant element in the precense of 'Device'

revert-70aa11f8
prabathabey 9 years ago
parent 3813856be8
commit 9a7286a84b

@ -24,7 +24,6 @@ import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
@ -298,8 +297,7 @@ public interface DeviceManagementService {
code = 200,
message = "OK. \n Device list searched for has successfully been retrieved. Location header " +
"contains URL of newly enrolled device",
response = DeviceWrapper.class,
responseContainer = "List",
response = DeviceList.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",

@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
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.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.search.SearchContext;
@ -77,6 +76,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
PaginationRequest request = new PaginationRequest(offset, limit);
PaginationResult result;
DeviceList devices = new DeviceList();
if (type != null) {
request.setDeviceType(type);
@ -129,13 +129,10 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
result = dms.getAllDevices(request);
int resultCount = result.getRecordsTotal();
if (resultCount == 0) {
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No device is currently" +
" enrolled with the server").build());
Response.status(Response.Status.OK).entity(devices).build();
}
}
DeviceList devices = new DeviceList();
devices.setList((List<Device>) result.getData());
devices.setCount(result.getRecordsTotal());
return Response.status(Response.Status.OK).entity(devices).build();
@ -210,7 +207,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
public Response searchDevices(@QueryParam("offset") int offset,
@QueryParam("limit") int limit, SearchContext searchContext) {
SearchManagerService searchManagerService;
List<DeviceWrapper> devices;
List<Device> devices;
DeviceList deviceList = new DeviceList();
try {
searchManagerService = DeviceMgtAPIUtils.getSearchManagerService();
devices = searchManagerService.search(searchContext);
@ -221,11 +219,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
}
if (devices == null || devices.size() == 0) {
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("It is likely that no device is found upon " +
"the provided search filters").build());
Response.status(Response.Status.OK).entity(deviceList);
}
return Response.status(Response.Status.OK).entity(devices).build();
deviceList.setList(devices);
return Response.status(Response.Status.OK).entity(deviceList).build();
}
@GET

@ -19,15 +19,15 @@
package org.wso2.carbon.device.mgt.core.search.mgt;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.search.Condition;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.search.SearchContext;
import java.util.List;
public interface Processor {
List<DeviceWrapper> execute(SearchContext searchContext) throws SearchMgtException;
List<Device> execute(SearchContext searchContext) throws SearchMgtException;
List<Device> getUpdatedDevices(long epochTime) throws SearchMgtException;
List<DeviceWrapper> getUpdatedDevices(long epochTime) throws SearchMgtException;
}

@ -19,13 +19,13 @@
package org.wso2.carbon.device.mgt.core.search.mgt;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.Device;
import java.util.List;
import java.util.Map;
public interface ResultSetAggregator {
List<DeviceWrapper> aggregate(Map<String, List<DeviceWrapper>> deviceWrappers);
List<Device> aggregate(Map<String, List<Device>> devices);
}

@ -19,15 +19,15 @@
package org.wso2.carbon.device.mgt.core.search.mgt;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.search.SearchContext;
import java.util.List;
public interface SearchManagerService {
List<DeviceWrapper> search(SearchContext searchContext) throws SearchMgtException;
List<Device> search(SearchContext searchContext) throws SearchMgtException;
List<DeviceWrapper> getUpdated(long epochTime) throws SearchMgtException;
List<Device> getUpdated(long epochTime) throws SearchMgtException;
}

@ -19,13 +19,14 @@
package org.wso2.carbon.device.mgt.core.search.mgt.dao;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.Device;
import java.util.List;
public interface SearchDAO {
List<DeviceWrapper> searchDeviceDetailsTable(String query) throws SearchDAOException;
List<Device> searchDeviceDetailsTable(String query) throws SearchDAOException;
List<Device> searchDevicePropertyTable(String query) throws SearchDAOException;
List<DeviceWrapper> searchDevicePropertyTable(String query) throws SearchDAOException;
}

@ -25,7 +25,6 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.search.mgt.dao.SearchDAO;
@ -38,22 +37,19 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SearchDAOImpl implements SearchDAO {
private static final Log log = LogFactory.getLog(SearchDAOImpl.class);
@Override
public List<DeviceWrapper> searchDeviceDetailsTable(String query) throws SearchDAOException {
public List<Device> searchDeviceDetailsTable(String query) throws SearchDAOException {
if (log.isDebugEnabled()) {
log.debug("Query : " + query);
}
Connection conn;
PreparedStatement stmt = null;
ResultSet rs;
List<DeviceWrapper> devices = new ArrayList<>();
List<Device> devices = new ArrayList<>();
Map<Integer, Integer> devs = new HashMap<>();
try {
conn = this.getConnection();
@ -101,15 +97,11 @@ public class SearchDAOImpl implements SearchDAO {
deviceLocation.setDeviceId(rs.getInt("ID"));
deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP")));
DeviceWrapper wrapper = new DeviceWrapper();
wrapper.setDevice(device);
wrapper.setDeviceInfo(deviceInfo);
wrapper.setDeviceLocation(deviceLocation);
wrapper.setDeviceIdentifier(identifier);
devices.add(wrapper);
deviceInfo.setLocation(deviceLocation);
device.setDeviceInfo(deviceInfo);
devices.add(device);
devs.put(device.getId(), device.getId());
}
}
} catch (SQLException e) {
throw new SearchDAOException("Error occurred while acquiring the device details.", e);
@ -126,8 +118,7 @@ public class SearchDAOImpl implements SearchDAO {
}
@Override
public List<DeviceWrapper> searchDevicePropertyTable(String query) throws SearchDAOException {
public List<Device> searchDevicePropertyTable(String query) throws SearchDAOException {
if (log.isDebugEnabled()) {
log.debug("Query : " + query);
}
@ -135,7 +126,7 @@ public class SearchDAOImpl implements SearchDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs;
List<DeviceWrapper> devices = new ArrayList<>();
List<Device> devices = new ArrayList<>();
Map<Integer, Integer> devs = new HashMap<>();
try {
conn = this.getConnection();
@ -183,13 +174,9 @@ public class SearchDAOImpl implements SearchDAO {
deviceLocation.setDeviceId(rs.getInt("ID"));
deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP")));
DeviceWrapper wrapper = new DeviceWrapper();
wrapper.setDevice(device);
wrapper.setDeviceInfo(deviceInfo);
wrapper.setDeviceLocation(deviceLocation);
wrapper.setDeviceIdentifier(identifier);
devices.add(wrapper);
deviceInfo.setLocation(deviceLocation);
device.setDeviceInfo(deviceInfo);
devices.add(device);
devs.put(device.getId(), device.getId());
}
@ -214,8 +201,7 @@ public class SearchDAOImpl implements SearchDAO {
return DeviceManagementDAOFactory.getConnection();
}
private List<DeviceWrapper> fillPropertiesOfDevices(List<DeviceWrapper> devices) throws SearchDAOException {
private List<Device> fillPropertiesOfDevices(List<Device> devices) throws SearchDAOException {
if (devices.isEmpty()) {
return null;
}
@ -249,14 +235,13 @@ public class SearchDAOImpl implements SearchDAO {
return devices;
}
private DeviceInfo getDeviceInfo(List<DeviceWrapper> devices, int deviceId) {
for (DeviceWrapper dw : devices) {
if (dw.getDevice().getId() == deviceId) {
if (dw.getDeviceInfo() == null) {
dw.setDeviceInfo(new DeviceInfo());
private DeviceInfo getDeviceInfo(List<Device> devices, int deviceId) {
for (Device device : devices) {
if (device.getId() == deviceId) {
if (device.getDeviceInfo() == null) {
device.setDeviceInfo(new DeviceInfo());
}
return dw.getDeviceInfo();
return device.getDeviceInfo();
}
}
return null;

@ -19,10 +19,7 @@
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;
@ -48,13 +45,13 @@ public class ProcessorImpl implements Processor {
}
@Override
public List<DeviceWrapper> execute(SearchContext searchContext) throws SearchMgtException {
public List<Device> execute(SearchContext searchContext) throws SearchMgtException {
QueryBuilder queryBuilder = new QueryBuilderImpl();
List<DeviceWrapper> generalDevices = new ArrayList<>();
List<List<DeviceWrapper>> allANDDevices = new ArrayList<>();
List<List<DeviceWrapper>> allORDevices = new ArrayList<>();
List<DeviceWrapper> locationDevices = new ArrayList<>();
List<Device> generalDevices = new ArrayList<>();
List<List<Device>> allANDDevices = new ArrayList<>();
List<List<Device>> allORDevices = new ArrayList<>();
List<Device> locationDevices = new ArrayList<>();
try {
Map<String, List<String>> queries = queryBuilder.buildQueries(searchContext.getConditions());
DeviceManagementDAOFactory.openConnection();
@ -64,13 +61,13 @@ public class ProcessorImpl implements Processor {
}
if (queries.containsKey(Constants.PROP_AND)) {
for (String query : queries.get(Constants.PROP_AND)) {
List<DeviceWrapper> andDevices = searchDAO.searchDevicePropertyTable(query);
List<Device> andDevices = searchDAO.searchDevicePropertyTable(query);
allANDDevices.add(andDevices);
}
}
if (queries.containsKey(Constants.PROP_OR)) {
for (String query : queries.get(Constants.PROP_OR)) {
List<DeviceWrapper> orDevices = searchDAO.searchDevicePropertyTable(query);
List<Device> orDevices = searchDAO.searchDevicePropertyTable(query);
allORDevices.add(orDevices);
}
}
@ -88,23 +85,22 @@ public class ProcessorImpl implements Processor {
DeviceManagementDAOFactory.closeConnection();
}
ResultSetAggregator aggregator = new ResultSetAggregatorImpl();
Map<String, List<DeviceWrapper>> deviceWrappers = new HashMap<>();
Map<String, List<Device>> devices = new HashMap<>();
deviceWrappers.put(Constants.GENERAL, generalDevices);
deviceWrappers.put(Constants.PROP_AND, this.processANDSearch(allANDDevices));
deviceWrappers.put(Constants.PROP_OR, this.processORSearch(allORDevices));
deviceWrappers.put(Constants.LOCATION, locationDevices);
devices.put(Constants.GENERAL, generalDevices);
devices.put(Constants.PROP_AND, this.processANDSearch(allANDDevices));
devices.put(Constants.PROP_OR, this.processORSearch(allORDevices));
devices.put(Constants.LOCATION, locationDevices);
List<DeviceWrapper> finalDeviceWrappers = aggregator.aggregate(deviceWrappers);
this.setApplicationListOfDevices(finalDeviceWrappers);
return finalDeviceWrappers;
List<Device> finalDevices = aggregator.aggregate(devices);
this.setApplicationListOfDevices(finalDevices);
return finalDevices;
}
@Override
public List<DeviceWrapper> getUpdatedDevices(long epochTime) throws SearchMgtException {
public List<Device> getUpdatedDevices(long epochTime) throws SearchMgtException {
if((1 + (int)Math.floor(Math.log10(epochTime))) <=10 ) {
epochTime = epochTime * 1000;
@ -126,15 +122,14 @@ public class ProcessorImpl implements Processor {
}
private List<DeviceWrapper> processANDSearch(List<List<DeviceWrapper>> deLists) {
List<DeviceWrapper> devices = new ArrayList<>();
List<DeviceWrapper> smallestDeviceList = this.findListWithLowestItems(deLists);
List<Map<Integer, DeviceWrapper>> maps = this.convertDeviceListToMap(deLists);
private List<Device> processANDSearch(List<List<Device>> deLists) {
List<Device> deviceList = new ArrayList<>();
List<Device> smallestDeviceList = this.findListWithLowestItems(deLists);
List<Map<Integer, Device>> maps = this.convertDeviceListToMap(deLists);
boolean valueExist = false;
for (DeviceWrapper dw : smallestDeviceList) {
for (Map<Integer, DeviceWrapper> deviceWrapperMap : maps) {
if (deviceWrapperMap.containsKey(dw.getDevice().getId())) {
for (Device device : smallestDeviceList) {
for (Map<Integer, Device> devices : maps) {
if (devices.containsKey(device.getId())) {
valueExist = true;
} else {
valueExist = false;
@ -142,63 +137,61 @@ public class ProcessorImpl implements Processor {
}
}
if (valueExist) {
devices.add(dw);
deviceList.add(device);
}
}
return devices;
return deviceList;
}
private List<DeviceWrapper> processORSearch(List<List<DeviceWrapper>> deLists) {
List<DeviceWrapper> devices = new ArrayList<>();
Map<Integer, DeviceWrapper> map = new HashMap<>();
private List<Device> processORSearch(List<List<Device>> deLists) {
List<Device> devices = new ArrayList<>();
Map<Integer, Device> map = new HashMap<>();
for (List<DeviceWrapper> list : deLists) {
for (DeviceWrapper dw : list) {
if (!map.containsKey(dw.getDevice().getId())) {
map.put(dw.getDevice().getId(), dw);
devices.add(dw);
for (List<Device> list : deLists) {
for (Device device : list) {
if (!map.containsKey(device.getId())) {
map.put(device.getId(), device);
devices.add(device);
}
}
}
return devices;
}
private List<DeviceWrapper> findListWithLowestItems(List<List<DeviceWrapper>> deLists) {
private List<Device> findListWithLowestItems(List<List<Device>> deLists) {
int size = 0;
List<DeviceWrapper> deviceWrappers = new ArrayList<>();
for (List<DeviceWrapper> list : deLists) {
List<Device> devices = new ArrayList<>();
for (List<Device> list : deLists) {
if (size == 0) {
size = list.size();
deviceWrappers = list;
continue;
devices = list;
} else {
if (list.size() < size) {
deviceWrappers = list;
devices = list;
}
}
}
return deviceWrappers;
return devices;
}
private List<Map<Integer, DeviceWrapper>> convertDeviceListToMap(List<List<DeviceWrapper>> deLists) {
List<Map<Integer, DeviceWrapper>> maps = new ArrayList<>();
for (List<DeviceWrapper> deviceWrapperList : deLists) {
Map<Integer, DeviceWrapper> deviceWrapperMap = new HashMap<>();
private List<Map<Integer, Device>> convertDeviceListToMap(List<List<Device>> deLists) {
List<Map<Integer, Device>> maps = new ArrayList<>();
for (List<Device> devices : deLists) {
Map<Integer, Device> deviceMap = new HashMap<>();
for (DeviceWrapper dw : deviceWrapperList) {
deviceWrapperMap.put(dw.getDevice().getId(), dw);
for (Device device: devices) {
deviceMap.put(device.getId(), device);
}
maps.add(deviceWrapperMap);
maps.add(deviceMap);
}
return maps;
}
private void setApplicationListOfDevices(List<DeviceWrapper> deviceWrappers) throws SearchMgtException {
private void setApplicationListOfDevices(List<Device> devices) throws SearchMgtException {
try {
DeviceManagementDAOFactory.openConnection();
for (DeviceWrapper wrapper : deviceWrappers) {
wrapper.setApplications(applicationDAO.getInstalledApplications(wrapper.getDevice().getId()));
for (Device device : devices) {
device.setApplications(applicationDAO.getInstalledApplications(device.getId()));
}
} catch (DeviceManagementDAOException e) {
throw new SearchMgtException("Error occurred while fetching the Application List of devices ", e);

@ -19,23 +19,26 @@
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;
import org.wso2.carbon.device.mgt.core.search.mgt.Constants;
import org.wso2.carbon.device.mgt.core.search.mgt.ResultSetAggregator;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ResultSetAggregatorImpl implements ResultSetAggregator {
@Override
public List<DeviceWrapper> aggregate(Map<String, List<DeviceWrapper>> deviceWrappers) {
public List<Device> aggregate(Map<String, List<Device>> devices) {
Map<Integer, DeviceWrapper> generalQueryMap = this.convertToMap(deviceWrappers.get(Constants.GENERAL));
Map<Integer, DeviceWrapper> andMap = this.convertToMap(deviceWrappers.get(Constants.PROP_AND));
Map<Integer, DeviceWrapper> orMap = this.convertToMap(deviceWrappers.get(Constants.PROP_OR));
Map<Integer, DeviceWrapper> locationMap = this.convertToMap(deviceWrappers.get(Constants.LOCATION));
Map<Integer, DeviceWrapper> finalMap = new HashMap<>();
List<DeviceWrapper> finalResult = new ArrayList<>();
Map<Integer, Device> generalQueryMap = this.convertToMap(devices.get(Constants.GENERAL));
Map<Integer, Device> andMap = this.convertToMap(devices.get(Constants.PROP_AND));
Map<Integer, Device> orMap = this.convertToMap(devices.get(Constants.PROP_OR));
Map<Integer, Device> locationMap = this.convertToMap(devices.get(Constants.LOCATION));
Map<Integer, Device> finalMap = new HashMap<>();
List<Device> finalResult = new ArrayList<>();
if (andMap.isEmpty()) {
finalMap = generalQueryMap;
@ -70,24 +73,23 @@ public class ResultSetAggregatorImpl implements ResultSetAggregator {
return finalResult;
}
private Map<Integer, DeviceWrapper> convertToMap(List<DeviceWrapper> deviceWrappers) {
if (deviceWrappers == null) {
private Map<Integer, Device> convertToMap(List<Device> devices) {
if (devices == null) {
return null;
}
Map<Integer, DeviceWrapper> deviceWrapperMap = new HashMap<>();
for (DeviceWrapper dw : deviceWrappers) {
deviceWrapperMap.put(dw.getDevice().getId(), dw);
Map<Integer, Device> deviceWrapperMap = new HashMap<>();
for (Device device : devices) {
deviceWrapperMap.put(device.getId(), device);
}
return deviceWrapperMap;
}
private List<DeviceWrapper> convertDeviceMapToList(Map<Integer, DeviceWrapper> map) {
List<DeviceWrapper> list = new ArrayList<>();
private List<Device> convertDeviceMapToList(Map<Integer, Device> map) {
List<Device> list = new ArrayList<>();
for (Integer a : map.keySet()) {
list.add(map.get(a));
}
return list;
}
}

@ -19,7 +19,7 @@
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;
import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.core.search.mgt.Processor;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
@ -29,7 +29,6 @@ import java.util.List;
public class SearchManagerServiceImpl implements SearchManagerService {
private Processor processor;
public SearchManagerServiceImpl() {
@ -37,13 +36,14 @@ public class SearchManagerServiceImpl implements SearchManagerService {
}
@Override
public List<DeviceWrapper> search(SearchContext searchContext) throws SearchMgtException {
public List<Device> search(SearchContext searchContext) throws SearchMgtException {
return processor.execute(searchContext);
}
@Override
public List<DeviceWrapper> getUpdated(long epochTime) throws SearchMgtException {
public List<Device> getUpdated(long epochTime) throws SearchMgtException {
return processor.getUpdatedDevices(epochTime);
}
}

@ -19,7 +19,7 @@
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;
import java.util.ArrayList;
import java.util.HashMap;
@ -65,22 +65,23 @@ public class Utils {
boolean bool = false;
switch (column) {
case "deviceModel":
case "deviceModel":
bool = true;
break;
case "vendor":
case "vendor":
bool = true;
break;
case "osVersion":
case "osVersion":
bool = true;
break;
case "connectionType":
case "connectionType":
bool = true;
break;
case "ssid":
case "ssid":
bool = true;
break;
default: bool =false;
default:
bool = false;
break;
}
@ -89,9 +90,9 @@ public class Utils {
public static String getConvertedValue(String column, String value) {
if(checkColumnType(column)){
return "\'" + value + "\'";
} else return value;
if (checkColumnType(column)) {
return "\'" + value + "\'";
} else return value;
}
@ -130,28 +131,28 @@ public class Utils {
return stList;
}
public static Integer[] getArrayOfDeviceIds(List<DeviceWrapper> deviceWrappers) {
Integer[] arr = new Integer[deviceWrappers.size()];
public static Integer[] getArrayOfDeviceIds(List<Device> devices) {
Integer[] arr = new Integer[devices.size()];
int x = 0;
for (DeviceWrapper dw : deviceWrappers) {
arr[x] = dw.getDevice().getId();
for (Device device : devices) {
arr[x] = device.getId();
x++;
}
return arr;
}
public static String getDeviceIdsAsString(List<DeviceWrapper> deviceWrappers) {
public static String getDeviceIdsAsString(List<Device> devices) {
String str = "";
for (DeviceWrapper dw : deviceWrappers) {
str += dw.getDevice().getId() + ",";
for (Device device : devices) {
str += device.getId() + ",";
}
if (deviceWrappers.isEmpty()) {
if (devices.isEmpty()) {
return null;
}
return str.substring(0, str.length() - 1);
}
}

@ -24,7 +24,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.search.Condition;
import org.wso2.carbon.device.mgt.common.search.SearchContext;
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
@ -79,22 +79,22 @@ public class SearchDevice extends BaseDeviceManagementTest {
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
List<DeviceWrapper> deviceWrappers = service.search(context);
List<Device> devices = service.search(context);
Gson gson = new Gson();
String bbbb = gson.toJson(deviceWrappers);
String bbbb = gson.toJson(devices);
log.info(bbbb);
for (DeviceWrapper dw : deviceWrappers) {
log.debug(dw.getDevice().getDescription());
log.debug(dw.getDevice().getDeviceIdentifier());
for (Device device : devices) {
log.debug(device.getDescription());
log.debug(device.getDeviceIdentifier());
}
}
@Test
public void doValidLocationSearch() throws Exception{
public void doValidLocationSearch() throws Exception {
SearchContext context = new SearchContext();
List<Condition> conditions = new ArrayList<>();
@ -109,21 +109,21 @@ public class SearchDevice extends BaseDeviceManagementTest {
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
List<DeviceWrapper> deviceWrappers = service.search(context);
List<Device> devices = service.search(context);
Gson gson = new Gson();
String bbbb = gson.toJson(deviceWrappers);
String bbbb = gson.toJson(devices);
log.info("Valid Search " + bbbb);
for (DeviceWrapper dw : deviceWrappers) {
log.debug(dw.getDevice().getDescription());
log.debug(dw.getDevice().getDeviceIdentifier());
for (Device device : devices) {
log.debug(device.getDescription());
log.debug(device.getDeviceIdentifier());
}
}
@Test
public void doInvalidLocationSearch() throws Exception{
public void doInvalidLocationSearch() throws Exception {
SearchContext context = new SearchContext();
List<Condition> conditions = new ArrayList<>();
@ -138,21 +138,21 @@ public class SearchDevice extends BaseDeviceManagementTest {
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
List<DeviceWrapper> deviceWrappers = service.search(context);
List<Device> devices = service.search(context);
Gson gson = new Gson();
String bbbb = gson.toJson(deviceWrappers);
String bbbb = gson.toJson(devices);
log.info("Invalid Search " + bbbb);
for (DeviceWrapper dw : deviceWrappers) {
log.debug(dw.getDevice().getDescription());
log.debug(dw.getDevice().getDeviceIdentifier());
for (Device device : devices) {
log.debug(device.getDescription());
log.debug(device.getDeviceIdentifier());
}
}
@Test
public void doStringSearch() throws Exception{
public void doStringSearch() throws Exception {
SearchContext context = new SearchContext();
List<Condition> conditions = new ArrayList<>();
@ -167,16 +167,16 @@ public class SearchDevice extends BaseDeviceManagementTest {
context.setConditions(conditions);
SearchManagerService service = new SearchManagerServiceImpl();
List<DeviceWrapper> deviceWrappers = service.search(context);
List<Device> devices = service.search(context);
Gson gson = new Gson();
String bbbb = gson.toJson(deviceWrappers);
String bbbb = gson.toJson(devices);
log.info("Invalid Search " + bbbb);
for (DeviceWrapper dw : deviceWrappers) {
log.debug(dw.getDevice().getDescription());
log.debug(dw.getDevice().getDeviceIdentifier());
for (Device device : devices) {
log.debug(device.getDescription());
log.debug(device.getDeviceIdentifier());
}
}
}

Loading…
Cancel
Save