Merge branch 'master' of ssh://repository.entgra.net:222/community/device-mgt-core

# Conflicts:
#	components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml
notification-11094
Charitha Goonetilleke 2 months ago
commit 099d98ebfb

@ -115,7 +115,7 @@ public interface DeviceStatusFilterService {
required = true) @PathParam ("device-type") String deviceType); required = true) @PathParam ("device-type") String deviceType);
@GET @GET
@Path("/is-enabled") @Path("/device-status-check")
@ApiOperation( @ApiOperation(
httpMethod = HTTPConstants.HEADER_GET, httpMethod = HTTPConstants.HEADER_GET,
value = "Get device status filter", value = "Get device status filter",
@ -155,7 +155,7 @@ public interface DeviceStatusFilterService {
Response getDeviceStatusCheck(); Response getDeviceStatusCheck();
@PUT @PUT
@Path("/toggle-device-status") @Path("/device-status-check")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST, httpMethod = HTTPConstants.HEADER_POST,
@ -201,6 +201,7 @@ public interface DeviceStatusFilterService {
@QueryParam("isEnabled") boolean isEnabled); @QueryParam("isEnabled") boolean isEnabled);
@PUT @PUT
@Path("/{deviceType}")
@ApiOperation( @ApiOperation(
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST, httpMethod = HTTPConstants.HEADER_POST,
@ -243,10 +244,51 @@ public interface DeviceStatusFilterService {
name = "deviceType", name = "deviceType",
value = "The device type for which you want to update device status filters.", value = "The device type for which you want to update device status filters.",
required = true) required = true)
@QueryParam("deviceType") String deviceType, @PathParam ("deviceType") String deviceType,
@ApiParam( @ApiParam(
name = "deviceStatus", name = "deviceStatus",
value = "A list of device status values to update for the given device type.", value = "A list of device status values to update for the given device type.",
required = true) required = true)
@QueryParam("deviceStatus") List<String> deviceStatus); @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 { try {
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService(); DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
return Response.status(Response.Status.OK).entity(deviceManagementProviderService return Response.status(Response.Status.OK).entity(deviceManagementProviderService
.getDeviceStatusFilters(deviceType, CarbonContext.getThreadLocalCarbonContext().getTenantId())).build(); .getDeviceStatusFilters(deviceType)).build();
} catch (MetadataKeyNotFoundException e) { } catch (MetadataKeyNotFoundException e) {
String msg = "Couldn't find the device status filter details for device type: " + deviceType; String msg = "Couldn't find the device status filter details for device type: " + deviceType;
log.error(msg, e); log.error(msg, e);
@ -65,7 +65,7 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
} }
@GET @GET
@Path("/is-enabled") @Path("/device-status-check")
@Override @Override
public Response getDeviceStatusCheck() { public Response getDeviceStatusCheck() {
boolean result; boolean result;
@ -83,15 +83,14 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
@Override @Override
@PUT @PUT
@Path("/toggle-device-status") @Path("/device-status-check")
public Response updateDeviceStatusCheck( public Response updateDeviceStatusCheck(
@QueryParam("isEnabled") @QueryParam("isEnabled")
boolean isEnabled) { boolean isEnabled) {
boolean result; boolean result;
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService(); DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
result = deviceManagementProviderService.updateDefaultDeviceStatusCheck(tenantId, isEnabled); result = deviceManagementProviderService.updateDefaultDeviceStatusCheck(isEnabled);
if (result) { if (result) {
return Response.status(Response.Status.OK).entity("Successfully updated device status check.").build(); return Response.status(Response.Status.OK).entity("Successfully updated device status check.").build();
} else { } else {
@ -106,16 +105,14 @@ public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService
@Override @Override
@PUT @PUT
@Path("/{deviceType}")
public Response updateDeviceStatusFilters( public Response updateDeviceStatusFilters(
@QueryParam("deviceType") @PathParam("deviceType") String deviceType,
String deviceType, @QueryParam("deviceStatus") List<String> deviceStatus
@QueryParam("deviceStatus")
List<String> deviceStatus
) { ) {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService(); 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(); return Response.status(Response.Status.OK).entity("Successfully updated device status filters for " + deviceType).build();
} catch (MetadataManagementException e) { } catch (MetadataManagementException e) {
String msg = "Error occurred while updating device status for " + deviceType; 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(); 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; 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 * @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 * This method is useful to update existing allowed device status
* *
* @throws MetadataManagementException if error while updating existing 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; throws MetadataManagementException;
/** /**
@ -53,21 +54,21 @@ public interface DeviceStatusManagementService {
* *
* @throws MetadataManagementException if error while updating existing device status * @throws MetadataManagementException if error while updating existing device status
*/ */
boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked) boolean updateDefaultDeviceStatusCheck(boolean isChecked)
throws MetadataManagementException; throws MetadataManagementException;
/** /**
* This method is useful to get existing device status filters * This method is useful to get existing device status filters
* *
* @throws MetadataManagementException if error while getting existing device status * @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 * 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 * @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 * This method is useful to get existing device status filters

@ -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 io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.util.MetadataConstants;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.sql.SQLException; import java.sql.SQLException;
@ -80,7 +81,8 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
} }
@Override @Override
public void resetToDefaultDeviceStatusFilter(int tenantId) throws MetadataManagementException { public void resetToDefaultDeviceStatusFilter() throws MetadataManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
MetadataManagementDAOFactory.beginTransaction(); MetadataManagementDAOFactory.beginTransaction();
Metadata defaultDeviceStatusMetadata = constructDeviceStatusMetadata(getDefaultDeviceStatus()); Metadata defaultDeviceStatusMetadata = constructDeviceStatusMetadata(getDefaultDeviceStatus());
@ -104,7 +106,8 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
} }
@Override @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 { try {
MetadataManagementDAOFactory.beginTransaction(); MetadataManagementDAOFactory.beginTransaction();
// Retrieve the current device status metadata // Retrieve the current device status metadata
@ -141,7 +144,8 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
} }
@Override @Override
public boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked) throws MetadataManagementException { public boolean updateDefaultDeviceStatusCheck(boolean isChecked) throws MetadataManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
MetadataManagementDAOFactory.beginTransaction(); MetadataManagementDAOFactory.beginTransaction();
if (metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) { if (metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
@ -166,7 +170,8 @@ public class DeviceStatusManagementServiceImpl implements DeviceStatusManagement
} }
@Override @Override
public List<AllowedDeviceStatus> getDeviceStatusFilters(int tenantId) throws MetadataManagementException { public List<AllowedDeviceStatus> getDeviceStatusFilters() throws MetadataManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
MetadataManagementDAOFactory.openConnection(); MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY); 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 { try {
MetadataManagementDAOFactory.openConnection(); MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY); Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);

Loading…
Cancel
Save