Adding new apis for getting the device location when list of device identifiers are supplied

revert-70aa11f8
geethkokila 9 years ago
parent f4f47cbfdd
commit 0221782533

@ -105,4 +105,24 @@ public interface DeviceInformation {
@ApiParam(name = "id", value = "Provide the device identifier", @ApiParam(name = "id", value = "Provide the device identifier",
required = true) @PathParam("id") String id); required = true) @PathParam("id") String id);
@GET
@Path("location/list")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Get the locations of devices",
notes = "This will return the locations of devices including latitude and longitude as well the "
+ "physical address for the supplied device identifiers",
response = DeviceLocation.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = ""),
@ApiResponse(code = 400, message = ""),
@ApiResponse(code = 400, message = ""),
@ApiResponse(code = 500, message = "Internal Server Error")
})
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDeviceLocations(@ApiParam(name = "deviceIdentifiers", value = "List of device identifiers",
required = true) List<DeviceIdentifier> deviceIdentifiers);
} }

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.jaxrs.api.impl; package org.wso2.carbon.device.mgt.jaxrs.api.impl;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
@ -96,5 +97,21 @@ public class DeviceInformationImpl implements DeviceInformation {
} }
return Response.status(Response.Status.OK).entity(deviceLocation).build(); return Response.status(Response.Status.OK).entity(deviceLocation).build();
} }
@Override
public Response getDeviceLocations(@ApiParam(name = "deviceIdentifiers", value = "List of device identifiers",
required = true) List<DeviceIdentifier> deviceIdentifiers) {
DeviceInformationManager informationManager;
List<DeviceLocation> deviceLocations;
try {
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceLocations = informationManager.getDeviceLocations(deviceIdentifiers);
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device location.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(deviceLocations).build();
}
} }

@ -72,6 +72,14 @@ public interface DeviceInformationManager {
*/ */
DeviceLocation getDeviceLocation(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException; DeviceLocation getDeviceLocation(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException;
/**
* This method will return the device location with latitude, longitude, address etc.. of supplied devices.
* @param deviceIdentifiers - List of Device identifier and device type.
* @return Device Location list.
* @throws DeviceDetailsMgtException
*/
List<DeviceLocation> getDeviceLocations(List<DeviceIdentifier> deviceIdentifiers) throws DeviceDetailsMgtException;
// /** // /**
// * This method will manage the storing of device application list. // * This method will manage the storing of device application list.
// * @param deviceApplication - Device application list. // * @param deviceApplication - Device application list.

@ -121,7 +121,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
} }
} }
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
for(Integer id : deviceIds) { for (Integer id : deviceIds) {
DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(id); DeviceInfo deviceInfo = deviceDetailsDAO.getDeviceInformation(id);
deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(id)); deviceInfo.setDeviceDetailsMap(deviceDetailsDAO.getDeviceProperties(id));
deviceInfos.add(deviceInfo); deviceInfos.add(deviceInfo);
@ -183,5 +183,26 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
} }
} }
@Override
public List<DeviceLocation> getDeviceLocations(List<DeviceIdentifier> deviceIdentifiers) throws DeviceDetailsMgtException {
try {
List<Device> devices = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getAllDevices(deviceIdentifiers.get(0).getType());
List<DeviceLocation> deviceLocations = new ArrayList<>();
DeviceManagementDAOFactory.openConnection();
for (Device device : devices) {
deviceLocations.add(deviceDetailsDAO.getDeviceLocation(device.getId()));
}
return deviceLocations;
} catch (DeviceManagementException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving the devices.", e);
} catch (SQLException e) {
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e);
} catch (DeviceDetailsMgtDAOException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving device locations.", e);
}
}
} }

Loading…
Cancel
Save