mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Add device status filters updating logic (#519)
Co-authored-by: tcdlpds <tcdlpds@gmail.com> Reviewed-on: https://repository.entgra.net/community/device-mgt-core/pulls/519 Co-authored-by: Lasantha Dharmakeerthi <lasantha@entgra.io> Co-committed-by: Lasantha Dharmakeerthi <lasantha@entgra.io>
This commit is contained in:
parent
3eced40f98
commit
c78d272bb8
@ -115,7 +115,7 @@ public interface DeviceStatusFilterService {
|
||||
required = true) @PathParam ("device-type") String deviceType);
|
||||
|
||||
@GET
|
||||
@Path("/is-enabled")
|
||||
@Path("/device-status-check")
|
||||
@ApiOperation(
|
||||
httpMethod = HTTPConstants.HEADER_GET,
|
||||
value = "Get device status filter",
|
||||
@ -155,7 +155,7 @@ public interface DeviceStatusFilterService {
|
||||
Response getDeviceStatusCheck();
|
||||
|
||||
@PUT
|
||||
@Path("/toggle-device-status")
|
||||
@Path("/device-status-check")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_POST,
|
||||
@ -201,6 +201,7 @@ public interface DeviceStatusFilterService {
|
||||
@QueryParam("isEnabled") boolean isEnabled);
|
||||
|
||||
@PUT
|
||||
@Path("/{deviceType}")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_POST,
|
||||
@ -243,10 +244,51 @@ public interface DeviceStatusFilterService {
|
||||
name = "deviceType",
|
||||
value = "The device type for which you want to update device status filters.",
|
||||
required = true)
|
||||
@QueryParam("deviceType") String deviceType,
|
||||
@PathParam ("deviceType") String deviceType,
|
||||
@ApiParam(
|
||||
name = "deviceStatus",
|
||||
value = "A list of device status values to update for the given device type.",
|
||||
required = true)
|
||||
@QueryParam("deviceStatus") List<String> deviceStatus);
|
||||
|
||||
@POST
|
||||
@Path("/default")
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = HTTPConstants.HEADER_POST,
|
||||
value = "Add Default Device status filters",
|
||||
notes = "Add Default Device status filters",
|
||||
tags = "Tenant Metadata Management",
|
||||
extensions = {
|
||||
@Extension(properties = {
|
||||
@ExtensionProperty(name = Constants.SCOPE, value = "dm:devicestatusfilter:update")
|
||||
})
|
||||
}
|
||||
)
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
code = 200,
|
||||
message = "OK. \n Successfully add default device status filters.",
|
||||
response = Response.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 = 500,
|
||||
message = "Internal Server Error. " +
|
||||
"\n Server error occurred while adding default device status filters.",
|
||||
response = ErrorResponse.class)
|
||||
})
|
||||
Response setDefaultStatusFilterData();
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
|
||||
try {
|
||||
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
|
||||
return Response.status(Response.Status.OK).entity(deviceManagementProviderService
|
||||
.getDeviceStatusFilters(deviceType, CarbonContext.getThreadLocalCarbonContext().getTenantId())).build();
|
||||
.getDeviceStatusFilters(deviceType)).build();
|
||||
} catch (MetadataKeyNotFoundException e) {
|
||||
String msg = "Couldn't find the device status filter details for device type: " + deviceType;
|
||||
log.error(msg, e);
|
||||
@ -65,7 +65,7 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/is-enabled")
|
||||
@Path("/device-status-check")
|
||||
@Override
|
||||
public Response getDeviceStatusCheck() {
|
||||
boolean result;
|
||||
@ -83,15 +83,14 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
|
||||
|
||||
@Override
|
||||
@PUT
|
||||
@Path("/toggle-device-status")
|
||||
@Path("/device-status-check")
|
||||
public Response updateDeviceStatusCheck(
|
||||
@QueryParam("isEnabled")
|
||||
boolean isEnabled) {
|
||||
boolean result;
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
|
||||
result = deviceManagementProviderService.updateDefaultDeviceStatusCheck(tenantId, isEnabled);
|
||||
result = deviceManagementProviderService.updateDefaultDeviceStatusCheck(isEnabled);
|
||||
if (result) {
|
||||
return Response.status(Response.Status.OK).entity("Successfully updated device status check.").build();
|
||||
} else {
|
||||
@ -106,16 +105,14 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
|
||||
|
||||
@Override
|
||||
@PUT
|
||||
@Path("/{deviceType}")
|
||||
public Response updateDeviceStatusFilters(
|
||||
@QueryParam("deviceType")
|
||||
String deviceType,
|
||||
@QueryParam("deviceStatus")
|
||||
List<String> deviceStatus
|
||||
@PathParam("deviceType") String deviceType,
|
||||
@QueryParam("deviceStatus") List<String> deviceStatus
|
||||
) {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
|
||||
deviceManagementProviderService.updateDefaultDeviceStatusFilters(tenantId, deviceType, deviceStatus);
|
||||
deviceManagementProviderService.updateDefaultDeviceStatusFilters(deviceType, deviceStatus);
|
||||
return Response.status(Response.Status.OK).entity("Successfully updated device status filters for " + deviceType).build();
|
||||
} catch (MetadataManagementException e) {
|
||||
String msg = "Error occurred while updating device status for " + deviceType;
|
||||
@ -123,4 +120,18 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response setDefaultStatusFilterData() {
|
||||
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
|
||||
try {
|
||||
deviceManagementProviderService.resetToDefaultDeviceStatusFilter();
|
||||
return Response.status(Response.Status.OK).entity("Successfully updated device status filters to " +
|
||||
"default values that is configured in the product").build();
|
||||
} catch (MetadataManagementException e) {
|
||||
String msg = "Error occurred while updating device status for default values that is configured in the product";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,18 +34,19 @@ public interface DeviceStatusManagementService {
|
||||
void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException;
|
||||
|
||||
/**
|
||||
* This method is useful to reset existing device status to default values in xml
|
||||
* This method is useful to reset existing device status to default values and device status check value to
|
||||
* default value that is defined in the ui-config
|
||||
*
|
||||
* @throws MetadataManagementException if error while resetting default device status
|
||||
*/
|
||||
void resetToDefaultDeviceStatusFilter(int tenantId) throws MetadataManagementException;
|
||||
void resetToDefaultDeviceStatusFilter() throws MetadataManagementException;
|
||||
|
||||
/**
|
||||
* This method is useful to update existing allowed device status
|
||||
*
|
||||
* @throws MetadataManagementException if error while updating existing device status
|
||||
*/
|
||||
void updateDefaultDeviceStatusFilters(int tenantId, String deviceType, List<String> deviceStatus)
|
||||
void updateDefaultDeviceStatusFilters(String deviceType, List<String> deviceStatus)
|
||||
throws MetadataManagementException;
|
||||
|
||||
/**
|
||||
@ -53,21 +54,21 @@ public interface DeviceStatusManagementService {
|
||||
*
|
||||
* @throws MetadataManagementException if error while updating existing device status
|
||||
*/
|
||||
boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked)
|
||||
boolean updateDefaultDeviceStatusCheck(boolean isChecked)
|
||||
throws MetadataManagementException;
|
||||
/**
|
||||
* This method is useful to get existing device status filters
|
||||
*
|
||||
* @throws MetadataManagementException if error while getting existing device status
|
||||
*/
|
||||
List<AllowedDeviceStatus> getDeviceStatusFilters(int tenantId) throws MetadataManagementException;
|
||||
List<AllowedDeviceStatus> getDeviceStatusFilters() throws MetadataManagementException;
|
||||
|
||||
/**
|
||||
* This method is useful to get existing device status filters by device type and tenant id
|
||||
*
|
||||
* @throws MetadataManagementException if error while getting existing device status
|
||||
*/
|
||||
List<String> getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException;
|
||||
List<String> getDeviceStatusFilters(String deviceType) throws MetadataManagementException;
|
||||
|
||||
/**
|
||||
* This method is useful to get existing device status filters
|
||||
|
||||
@ -143,7 +143,6 @@
|
||||
io.entgra.device.mgt.core.device.mgt.core.config.keymanager,
|
||||
io.entgra.device.mgt.core.device.mgt.core.config.license,
|
||||
io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt,
|
||||
io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.documentation,
|
||||
io.entgra.device.mgt.core.device.mgt.core.config.metadata.mgt.whitelabel,
|
||||
io.entgra.device.mgt.core.device.mgt.core.config.operation.timeout,
|
||||
io.entgra.device.mgt.core.device.mgt.core.config.pagination,
|
||||
|
||||
@ -36,6 +36,7 @@ import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataManage
|
||||
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.util.MetadataConstants;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.sql.SQLException;
|
||||
@ -80,7 +81,8 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetToDefaultDeviceStatusFilter(int tenantId) throws MetadataManagementException {
|
||||
public void resetToDefaultDeviceStatusFilter() throws MetadataManagementException {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
MetadataManagementDAOFactory.beginTransaction();
|
||||
Metadata defaultDeviceStatusMetadata = constructDeviceStatusMetadata(getDefaultDeviceStatus());
|
||||
@ -104,7 +106,8 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDefaultDeviceStatusFilters(int tenantId, String deviceType, List<String> deviceStatus) throws MetadataManagementException {
|
||||
public void updateDefaultDeviceStatusFilters(String deviceType, List<String> deviceStatus) throws MetadataManagementException {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
MetadataManagementDAOFactory.beginTransaction();
|
||||
// Retrieve the current device status metadata
|
||||
@ -141,7 +144,8 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked) throws MetadataManagementException {
|
||||
public boolean updateDefaultDeviceStatusCheck(boolean isChecked) throws MetadataManagementException {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
MetadataManagementDAOFactory.beginTransaction();
|
||||
if (metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
|
||||
@ -166,7 +170,8 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AllowedDeviceStatus> getDeviceStatusFilters(int tenantId) throws MetadataManagementException {
|
||||
public List<AllowedDeviceStatus> getDeviceStatusFilters() throws MetadataManagementException {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
MetadataManagementDAOFactory.openConnection();
|
||||
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
||||
@ -193,7 +198,8 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
|
||||
|
||||
}
|
||||
|
||||
public List<String> getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException {
|
||||
public List<String> getDeviceStatusFilters(String deviceType) throws MetadataManagementException {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
MetadataManagementDAOFactory.openConnection();
|
||||
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user