diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/DeviceStatusFilterService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/DeviceStatusFilterService.java index 7c0d84de1d..dc7c5a70fd 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/DeviceStatusFilterService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/DeviceStatusFilterService.java @@ -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 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(); } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceStatusFilterServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceStatusFilterServiceImpl.java index cc2a2c90e9..680a4e5516 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceStatusFilterServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceStatusFilterServiceImpl.java @@ -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 deviceStatus + @PathParam("deviceType") String deviceType, + @QueryParam("deviceStatus") List 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(); + } + } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/metadata/mgt/DeviceStatusManagementService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/metadata/mgt/DeviceStatusManagementService.java index 5abb9c7e88..163ac9bbc4 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/metadata/mgt/DeviceStatusManagementService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/metadata/mgt/DeviceStatusManagementService.java @@ -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 deviceStatus) + void updateDefaultDeviceStatusFilters(String deviceType, List 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 getDeviceStatusFilters(int tenantId) throws MetadataManagementException; + List 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 getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException; + List getDeviceStatusFilters(String deviceType) throws MetadataManagementException; /** * This method is useful to get existing device status filters diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml index 43f48d94ed..361c06b77d 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml @@ -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, diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceStatusManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceStatusManagementServiceImpl.java index 42c0966da5..351ba5a63f 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceStatusManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceStatusManagementServiceImpl.java @@ -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 deviceStatus) throws MetadataManagementException { + public void updateDefaultDeviceStatusFilters(String deviceType, List 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 getDeviceStatusFilters(int tenantId) throws MetadataManagementException { + public List 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 getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException { + public List getDeviceStatusFilters(String deviceType) throws MetadataManagementException { + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); try { MetadataManagementDAOFactory.openConnection(); Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);