Add API to retrieve device filters

4.x.x
Saad Sahibjan 5 years ago
parent df1cda1e00
commit a356ec797c

@ -2188,4 +2188,43 @@ public interface DeviceManagementService {
value = "The device identifier") value = "The device identifier")
@PathParam("id") String deviceId, @PathParam("id") String deviceId,
OperationStatusBean operationStatusBean); OperationStatusBean operationStatusBean);
@GET
@Path("/filters")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Retrieving filters of device.",
notes = "Provides filters in devices of Entgra IoT Server which can be used in UI for filtering.",
tags = "Device Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully fetched the device filters.",
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 = 500,
message = "Error occurred while getting the version data.",
response = ErrorResponse.class)
})
Response getDeviceFilters();
} }

@ -44,6 +44,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceFilters;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.Feature;
@ -1274,4 +1275,36 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} }
} }
@GET
@Path("/filters")
@Override
public Response getDeviceFilters() {
try {
List<String> deviceTypeNames = new ArrayList<>();
List<String> ownershipNames = new ArrayList<>();
List<String> statusNames = new ArrayList<>();
List<DeviceType> deviceTypes = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceTypes();
for (DeviceType deviceType : deviceTypes) {
deviceTypeNames.add(deviceType.getName());
}
EnrolmentInfo.OwnerShip[] ownerShips = EnrolmentInfo.OwnerShip.values();
for (EnrolmentInfo.OwnerShip ownerShip : ownerShips) {
ownershipNames.add(ownerShip.name());
}
EnrolmentInfo.Status[] statuses = EnrolmentInfo.Status.values();
for (EnrolmentInfo.Status status : statuses) {
statusNames.add(status.name());
}
DeviceFilters deviceFilters = new DeviceFilters();
deviceFilters.setDeviceTypes(deviceTypeNames);
deviceFilters.setOwnerships(ownershipNames);
deviceFilters.setStatuses(statusNames);
return Response.status(Response.Status.OK).entity(deviceFilters).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred white retrieving device types to be used in device filters.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
} }

@ -0,0 +1,40 @@
package org.wso2.carbon.device.mgt.common;
import java.io.Serializable;
import java.util.List;
/**
* This class carries information related to device filtering values which will be used in the UI to filter devices.
*/
public class DeviceFilters implements Serializable {
private static final long serialVersionUID = -5249449134602406387L;
private List<String> deviceTypes;
private List<String> ownerships;
private List<String> statuses;
public List<String> getDeviceTypes() {
return deviceTypes;
}
public void setDeviceTypes(List<String> deviceTypes) {
this.deviceTypes = deviceTypes;
}
public List<String> getOwnerships() {
return ownerships;
}
public void setOwnerships(List<String> ownerships) {
this.ownerships = ownerships;
}
public List<String> getStatuses() {
return statuses;
}
public void setStatuses(List<String> statuses) {
this.statuses = statuses;
}
}
Loading…
Cancel
Save