Merge branch 'master' into 'application-mgt-new'

Changing status related APIs to honour tenant ID

See merge request charithag/carbon-device-mgt!1
feature/appm-store/pbac
Charitha Goonetilleke 5 years ago
commit c29dc4dddb

@ -1627,7 +1627,7 @@ public interface DeviceManagementService {
@Valid OperationRequest operationRequest); @Valid OperationRequest operationRequest);
@GET @GET
@Path("/status/count/{type}/{status}") @Path("/status/count/{tenantDomain}/{type}/{status}")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
@ -1678,6 +1678,13 @@ public interface DeviceManagementService {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getDeviceCountByStatus( Response getDeviceCountByStatus(
@ApiParam(
name = "tenantDomain",
value = "The tenant doamin.",
required = true)
@PathParam("tenantDomain")
@Size(max = 45)
String tenantDomain,
@ApiParam( @ApiParam(
name = "type", name = "type",
value = "The device type name, such as ios, android, windows or fire-alarm.", value = "The device type name, such as ios, android, windows or fire-alarm.",
@ -1695,7 +1702,7 @@ public interface DeviceManagementService {
@GET @GET
@Path("/status/ids/{type}/{status}") @Path("/status/ids/{tenantDomain}/{type}/{status}")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "GET", httpMethod = "GET",
@ -1747,6 +1754,13 @@ public interface DeviceManagementService {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getDeviceIdentifiersByStatus( Response getDeviceIdentifiersByStatus(
@ApiParam(
name = "tenantDomain",
value = "The tenant domain.",
required = true)
@PathParam("tenantDomain")
@Size(max = 45)
String tenantDomain,
@ApiParam( @ApiParam(
name = "type", name = "type",
value = "The device type name, such as ios, android, windows or fire-alarm.", value = "The device type name, such as ios, android, windows or fire-alarm.",
@ -1763,7 +1777,7 @@ public interface DeviceManagementService {
String status); String status);
@PUT @PUT
@Path("/status/update/{type}/{status}") @Path("/status/update/{tenantDomain}/{type}/{status}")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
@ -1814,7 +1828,10 @@ public interface DeviceManagementService {
"Server error occurred while retrieving information requested device.", "Server error occurred while retrieving information requested device.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response bulkUpdateDeviceStatus(@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true) Response bulkUpdateDeviceStatus(
@ApiParam(name = "tenantDomain", value = "The tenant domain.", required = true)
@PathParam("tenantDomain") String tenantDomain,
@ApiParam(name = "type", value = "The device type, such as ios, android or windows.", required = true)
@PathParam("type") String type, @PathParam("type") String type,
@ApiParam(name = "status", value = "The device type, such as ios, android or windows.", required = true) @ApiParam(name = "status", value = "The device type, such as ios, android or windows.", required = true)
@PathParam("status") String status, @PathParam("status") String status,

@ -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();
} }

@ -727,11 +727,11 @@ public interface DeviceManagementProviderService {
List<GeoCluster> findGeoClusters(String deviceType, GeoCoordinate southWest, GeoCoordinate northEast, List<GeoCluster> findGeoClusters(String deviceType, GeoCoordinate southWest, GeoCoordinate northEast,
int geohashLength) throws DeviceManagementException; int geohashLength) throws DeviceManagementException;
int getDeviceCountOfTypeByStatus(String deviceType, String deviceStatus) throws DeviceManagementException; int getDeviceCountOfTypeByStatus(int tenantId, String deviceType, String deviceStatus) throws DeviceManagementException;
List<String> getDeviceIdentifiersByStatus(String deviceType, String deviceStatus) throws DeviceManagementException; List<String> getDeviceIdentifiersByStatus(int tenantId, String deviceType, String deviceStatus) throws DeviceManagementException;
boolean bulkUpdateDeviceStatus(String deviceType, List<String> deviceList, String status) throws DeviceManagementException; boolean bulkUpdateDeviceStatus(int tenantId, String deviceType, List<String> deviceList, String status) throws DeviceManagementException;
boolean updateEnrollment(String owner, List<String> deviceIdentifiers) boolean updateEnrollment(String owner, List<String> deviceIdentifiers)
throws DeviceManagementException, UserNotFoundException, InvalidDeviceException; throws DeviceManagementException, UserNotFoundException, InvalidDeviceException;

@ -3038,8 +3038,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public int getDeviceCountOfTypeByStatus(String deviceType, String deviceStatus) throws DeviceManagementException { public int getDeviceCountOfTypeByStatus(int tenantId, String deviceType, String deviceStatus) throws DeviceManagementException {
int tenantId = this.getTenantId();
try { try {
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
return deviceDAO.getDeviceCount(deviceType, deviceStatus, tenantId); return deviceDAO.getDeviceCount(deviceType, deviceStatus, tenantId);
@ -3057,8 +3056,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public List<String> getDeviceIdentifiersByStatus(String deviceType, String deviceStatus) throws DeviceManagementException { public List<String> getDeviceIdentifiersByStatus(int tenantId, String deviceType, String deviceStatus) throws DeviceManagementException {
int tenantId = this.getTenantId();
List<String> deviceIds; List<String> deviceIds;
try { try {
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
@ -3078,8 +3076,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public boolean bulkUpdateDeviceStatus(String deviceType, List<String> deviceList, String status) throws DeviceManagementException { public boolean bulkUpdateDeviceStatus(int tenantId, String deviceType,
int tenantId = this.getTenantId(); List<String> deviceList, String status)
throws DeviceManagementException {
boolean success; boolean success;
try { try {
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();

Loading…
Cancel
Save