Get devices by identifier list API

merge-requests/547/head
Shamalka Navod 5 years ago committed by Dharmakeerthi Lasantha
parent 66a30ef131
commit 03e87c558f

@ -629,6 +629,52 @@ public interface DeviceManagementService {
@QueryParam("requireDeviceInfo")
boolean requireDeviceInfo);
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/type/any/list")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Getting Details of Devices",
notes = "Get the details of devices by specifying the device identifiers.",
tags = "Device Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:details")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully fetched the details of the device.",
response = Device.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while retrieving the device details.",
response = ErrorResponse.class)
})
Response getDeviceByIdList(List<String> deviceIds);
@PUT
@Produces(MediaType.APPLICATION_JSON)

@ -662,6 +662,27 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return Response.status(Response.Status.OK).entity(device).build();
}
@POST
@Path("/type/any/list")
@Override
public Response getDeviceByIdList(List<String> deviceIds) {
DeviceManagementProviderService deviceManagementProviderService =
DeviceMgtAPIUtils.getDeviceManagementService();
if (deviceIds == null || deviceIds.isEmpty()) {
String msg = "Required values of device identifiers are not set..";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).build();
}
try {
List<Device> devices = deviceManagementProviderService.getDeviceByIdList(deviceIds);
return Response.status(Response.Status.OK).entity(devices).build();
} catch (DeviceManagementException e) {
String msg = "Error encountered while retrieving devices";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Path("/{type}/{id}/location")
@Override

@ -916,4 +916,15 @@ public interface DeviceManagementProviderService {
* @throws {@link OperationManagementException}
*/
boolean isOperationExist(DeviceIdentifier deviceId, int operationId) throws OperationManagementException;
/**
* Get device list for a given device identifier list
*
* @param deviceIdentifiers A list of device identifiers
* @return A list of devices
* @throws {@link DeviceManagementException}
* @throws {@link InvalidDeviceException}
*/
List<Device> getDeviceByIdList(List<String> deviceIdentifiers)
throws DeviceManagementException;
}

@ -4177,4 +4177,23 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return pluginRepository.getOperationManager(deviceId.getType(), this.getTenantId())
.isOperationExist(deviceId, operationId);
}
@Override
public List<Device> getDeviceByIdList(List<String> deviceIdentifiers) throws DeviceManagementException {
int tenantId = this.getTenantId();
try {
DeviceManagementDAOFactory.openConnection();
return deviceDAO.getDevicesByIdentifiers(deviceIdentifiers, tenantId);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving device list.";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
}

Loading…
Cancel
Save