|
|
@ -84,6 +84,7 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
|
|
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
|
|
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
|
|
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
import javax.validation.Valid;
|
|
|
@ -918,48 +919,66 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Path("/status/count/{type}/{status}")
|
|
|
|
@Path("/status/count/{tenantDomain}/{type}/{status}")
|
|
|
|
public Response getDeviceCountByStatus(@PathParam("type") String type, @PathParam("status") String status) {
|
|
|
|
public Response getDeviceCountByStatus(@PathParam("tenantDomain") String tenantDomain, @PathParam("type") String type, @PathParam("status") String status) {
|
|
|
|
int deviceCount;
|
|
|
|
int deviceCount;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
deviceCount = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCountOfTypeByStatus(type, status);
|
|
|
|
int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain);
|
|
|
|
|
|
|
|
deviceCount = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCountOfTypeByStatus(tenantId, type, status);
|
|
|
|
return Response.status(Response.Status.OK).entity(deviceCount).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(deviceCount).build();
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
String errorMessage = "Error while retrieving device count.";
|
|
|
|
String errorMessage = "Error while retrieving device count.";
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
|
|
|
String errorMessage = "Error resolving tenant Domain";
|
|
|
|
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Path("/status/ids/{type}/{status}")
|
|
|
|
@Path("/status/ids/{tenantDomain}/{type}/{status}")
|
|
|
|
public Response getDeviceIdentifiersByStatus(@PathParam("type") String type, @PathParam("status") String status) {
|
|
|
|
public Response getDeviceIdentifiersByStatus(@PathParam("tenantDomain") String tenantDomain, @PathParam("type") String type, @PathParam("status") String status) {
|
|
|
|
List<String> deviceIds;
|
|
|
|
List<String> deviceIds;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
deviceIds = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceIdentifiersByStatus(type, status);
|
|
|
|
int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain);
|
|
|
|
|
|
|
|
deviceIds = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceIdentifiersByStatus(tenantId, type, status);
|
|
|
|
return Response.status(Response.Status.OK).entity(deviceIds.toArray(new String[0])).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(deviceIds.toArray(new String[0])).build();
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
String errorMessage = "Error while obtaining list of devices";
|
|
|
|
String errorMessage = "Error while obtaining list of devices";
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
|
|
|
String errorMessage = "Error resolving tenant Domain";
|
|
|
|
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
@PUT
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Path("/status/update/{type}/{status}")
|
|
|
|
@Path("/status/update/{tenantDomain}/{type}/{status}")
|
|
|
|
public Response bulkUpdateDeviceStatus(@PathParam("type") String type, @PathParam("status") String status,
|
|
|
|
public Response bulkUpdateDeviceStatus(@PathParam("tenantDomain") String tenantDomain, @PathParam("type") String type,
|
|
|
|
@Valid List<String> deviceList) {
|
|
|
|
@PathParam("status") String status, @Valid List<String> deviceList) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceMgtAPIUtils.getDeviceManagementService().bulkUpdateDeviceStatus(type, deviceList, status);
|
|
|
|
int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain);
|
|
|
|
|
|
|
|
DeviceMgtAPIUtils.getDeviceManagementService().bulkUpdateDeviceStatus(tenantId, type, deviceList, status);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
String errorMessage = "Error while updating device status in bulk.";
|
|
|
|
String errorMessage = "Error while updating device status in bulk.";
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
|
|
|
String errorMessage = "Error resolving tenant Domain";
|
|
|
|
|
|
|
|
log.error(errorMessage, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(errorMessage).build()).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|