Merge branch 'master' into 'master'

Add API to retrieve device filters

See merge request entgra/carbon-device-mgt!533
4.x.x
Dharmakeerthi Lasantha 5 years ago
commit dc05306aa9

@ -2188,4 +2188,43 @@ public interface DeviceManagementService {
value = "The device identifier")
@PathParam("id") String deviceId,
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.wso2.carbon.context.CarbonContext;
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.EnrolmentInfo;
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();
}
}
@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,57 @@
/*
* Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
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