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/ActivityInfoProviderService.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/ActivityInfoProviderService.java index 7cc2aaf0bf..27d855b3b1 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/ActivityInfoProviderService.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/ActivityInfoProviderService.java @@ -491,7 +491,7 @@ public interface ActivityInfoProviderService { name = "status", value = "Operation response status to filter" ) - @QueryParam("status") String status, + @QueryParam("status") List statuses, @ApiParam( name = "If-Modified-Since", value = "Checks if the requested variant was modified, since the specified date-time\n." + @@ -615,7 +615,7 @@ public interface ActivityInfoProviderService { name = "status", value = "Operation response status to filter" ) - @QueryParam("status") String status, + @QueryParam("status") List statuses, @ApiParam( name = "If-Modified-Since", value = "Checks if the requested variant was modified, since the specified date-time\n." + 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/ActivityProviderServiceImpl.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/ActivityProviderServiceImpl.java index 2fca4e46f3..a4148f07a8 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/ActivityProviderServiceImpl.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/ActivityProviderServiceImpl.java @@ -50,6 +50,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -259,7 +260,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService @QueryParam("deviceType") String deviceType, @QueryParam("deviceId") List deviceIds, @QueryParam("type") String type, - @QueryParam("status") String status, + @QueryParam("status") List statuses, @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("startTimestamp") long startTimestamp, @QueryParam("endTimestamp") long endTimestamp) { @@ -336,8 +337,12 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService if (type != null && !type.isEmpty()) { activityPaginationRequest.setType(Operation.Type.valueOf(type.toUpperCase())); } - if (status != null && !status.isEmpty()) { - activityPaginationRequest.setStatus(Operation.Status.valueOf(status.toUpperCase())); + if (statuses != null && !statuses.isEmpty()) { + List statusEnums = new ArrayList<>(); + for (String status : statuses) { + statusEnums.add(Operation.Status.valueOf(status.toUpperCase())); + } + activityPaginationRequest.setStatuses(statusEnums); } if (timestamp > 0) { activityPaginationRequest.setSince(timestamp); @@ -382,7 +387,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService @QueryParam("deviceType") String deviceType, @QueryParam("deviceId") List deviceIds, @QueryParam("type") String type, - @QueryParam("status") String status, + @QueryParam("status") List statuses, @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("startTimestamp") long startTimestamp, @QueryParam("endTimestamp") long endTimestamp) { @@ -457,8 +462,12 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService if (type != null && !type.isEmpty()) { activityPaginationRequest.setType(Operation.Type.valueOf(type.toUpperCase())); } - if (status != null && !status.isEmpty()) { - activityPaginationRequest.setStatus(Operation.Status.valueOf(status.toUpperCase())); + if (statuses != null && !statuses.isEmpty()) { + List statusEnums = new ArrayList<>(); + for (String status : statuses) { + statusEnums.add(Operation.Status.valueOf(status.toUpperCase())); + } + activityPaginationRequest.setStatuses(statusEnums); } if (timestamp > 0) { activityPaginationRequest.setSince(timestamp); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/ActivityProviderServiceImplTest.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/ActivityProviderServiceImplTest.java index 5a6d9d0983..59baa18242 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/ActivityProviderServiceImplTest.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/ActivityProviderServiceImplTest.java @@ -132,7 +132,7 @@ public class ActivityProviderServiceImplTest { activityPaginationRequest.setDeviceType(DEVICE_TYPE_2); activityPaginationRequest.setOperationId(OPERATION_ID); activityPaginationRequest.setInitiatedBy(INITIATED_BY); - activityPaginationRequest.setStatus(STATUS); + activityPaginationRequest.setStatuses(Collections.singletonList(STATUS)); activityPaginationRequest.setType(TYPE); activityPaginationRequest.setStartTimestamp(0); activityPaginationRequest.setEndTimestamp(0); @@ -226,7 +226,7 @@ public class ActivityProviderServiceImplTest { Mockito.when(this.deviceManagementProviderService.getActivities(Mockito.any())).thenReturn(activities); Response response = this.activityInfoProviderService.getActivities( OFFSET, LIMIT, SINCE, INITIATED_BY, OPERATION_CODE, OPERATION_ID, - DEVICE_TYPE_2, Collections.singletonList(DEVICE_ID), TYPE.toString(), STATUS.toString(), null, 0, 0); + DEVICE_TYPE_2, Collections.singletonList(DEVICE_ID), TYPE.toString(), Collections.singletonList(STATUS.toString()), null, 0, 0); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); Assert.assertNotNull(response); @@ -258,7 +258,7 @@ public class ActivityProviderServiceImplTest { Mockito.when(this.deviceManagementProviderService.getDeviceActivities(Mockito.any())).thenReturn(deviceActivities); Response response = this.activityInfoProviderService.getDeviceActivities( OFFSET, LIMIT, SINCE, INITIATED_BY, OPERATION_CODE, OPERATION_ID, - DEVICE_TYPE_2, Collections.singletonList(DEVICE_ID), TYPE.toString(), STATUS.toString(), null, 0, 0); + DEVICE_TYPE_2, Collections.singletonList(DEVICE_ID), TYPE.toString(), Collections.singletonList(STATUS.toString()), null, 0, 0); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); Assert.assertNotNull(response); 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/ActivityPaginationRequest.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/ActivityPaginationRequest.java index 058b82dd2f..77161d7036 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/ActivityPaginationRequest.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/ActivityPaginationRequest.java @@ -36,7 +36,7 @@ public class ActivityPaginationRequest { private String initiatedBy; private long since; private Operation.Type type; - private Operation.Status status; + private List statuses; private long startTimestamp; private long endTimestamp; @@ -110,12 +110,12 @@ public class ActivityPaginationRequest { this.type = type; } - public Operation.Status getStatus() { - return status; + public List getStatuses() { + return statuses; } - public void setStatus(Operation.Status status) { - this.status = status; + public void setStatuses(List statuses) { + this.statuses = statuses; } public long getStartTimestamp() { 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/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index 319e2d09f8..4a96d6606a 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -2272,7 +2272,7 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getDeviceType() != null || (activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) || activityPaginationRequest.getSince() != 0 || - activityPaginationRequest.getStatus() != null) { + activityPaginationRequest.getStatuses() != null) { sql.append("(SELECT DISTINCT OPERATION_ID FROM DM_ENROLMENT_OP_MAPPING eom WHERE TENANT_ID = ? "); @@ -2305,8 +2305,12 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getType() != null) { sql.append("AND TYPE = ? "); } - if (activityPaginationRequest.getStatus() != null) { - sql.append("AND STATUS = ? "); + if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) { + sql.append("AND STATUS IN ("); + for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) { + sql.append("?, "); + } + sql.append("?) "); } sql.append("ORDER BY OPERATION_ID ASC limit ? , ? ) eom_ordered " + @@ -2360,8 +2364,12 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getType() != null) { sql.append("AND eom.TYPE = ? "); } - if (activityPaginationRequest.getStatus() != null) { - sql.append("AND eom.STATUS = ? "); + if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) { + sql.append("AND eom.STATUS IN ("); + for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) { + sql.append("?, "); + } + sql.append("?) "); } sql.append("ORDER BY eom.OPERATION_ID, eom.UPDATED_TIMESTAMP"); @@ -2372,7 +2380,7 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getDeviceType() != null || (activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) || activityPaginationRequest.getSince() != 0 || - activityPaginationRequest.getStatus() != null) { + activityPaginationRequest.getStatuses() != null) { if (activityPaginationRequest.getDeviceType() != null) { stmt.setString(index++, activityPaginationRequest.getDeviceType()); @@ -2401,8 +2409,10 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getType() != null) { stmt.setString(index++, activityPaginationRequest.getType().name()); } - if (activityPaginationRequest.getStatus() != null) { - stmt.setString(index++, activityPaginationRequest.getStatus().name()); + if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) { + for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) { + stmt.setString(index++, status.name()); + } } stmt.setInt(index++, activityPaginationRequest.getOffset()); @@ -2463,8 +2473,10 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getType() != null) { stmt.setString(index++, activityPaginationRequest.getType().name()); } - if (activityPaginationRequest.getStatus() != null) { - stmt.setString(index, activityPaginationRequest.getStatus().name()); + if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) { + for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) { + stmt.setString(index++, status.name()); + } } try (ResultSet rs = stmt.executeQuery()) { @@ -2496,7 +2508,7 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getDeviceType() != null || (activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) || activityPaginationRequest.getSince() != 0 || - activityPaginationRequest.getStatus() != null) { + activityPaginationRequest.getStatuses() != null) { sql.append("SELECT count(DISTINCT OPERATION_ID) AS ACTIVITY_COUNT " + "FROM DM_ENROLMENT_OP_MAPPING WHERE TENANT_ID = ? "); @@ -2526,8 +2538,12 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getType() != null) { sql.append("AND TYPE = ? "); } - if (activityPaginationRequest.getStatus() != null) { - sql.append("AND STATUS = ? "); + if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) { + sql.append("AND STATUS IN ("); + for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) { + sql.append("?, "); + } + sql.append("?) "); } } else { @@ -2555,7 +2571,7 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getDeviceType() != null || (activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) || activityPaginationRequest.getSince() != 0 || - activityPaginationRequest.getStatus() != null) { + activityPaginationRequest.getStatuses() != null) { if (activityPaginationRequest.getDeviceType() != null) { stmt.setString(index++, activityPaginationRequest.getDeviceType()); } @@ -2579,8 +2595,10 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getType() != null) { stmt.setString(index++, activityPaginationRequest.getType().name()); } - if (activityPaginationRequest.getStatus() != null) { - stmt.setString(index++, activityPaginationRequest.getStatus().name()); + if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) { + for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) { + stmt.setString(index++, status.name()); + } } } else { if (activityPaginationRequest.getOperationCode() != null) { @@ -2662,8 +2680,12 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getType() != null) { sql.append("AND TYPE = ? "); } - if (activityPaginationRequest.getStatus() != null) { - sql.append("AND STATUS = ? "); + if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) { + sql.append("AND STATUS IN ("); + for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) { + sql.append("?, "); + } + sql.append("?) "); } sql.append("ORDER BY ID ASC limit ? , ? ) eom " + @@ -2700,8 +2722,10 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getType() != null) { stmt.setString(index++, activityPaginationRequest.getType().name()); } - if (activityPaginationRequest.getStatus() != null) { - stmt.setString(index++, activityPaginationRequest.getStatus().name()); + if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) { + for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) { + stmt.setString(index++, status.name()); + } } stmt.setInt(index++, activityPaginationRequest.getOffset()); @@ -2744,7 +2768,6 @@ public class GenericOperationDAOImpl implements OperationDAO { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); StringBuilder sql = new StringBuilder(); - sql.append("SELECT count(DISTINCT ID) AS ACTIVITY_COUNT " + "FROM DM_ENROLMENT_OP_MAPPING WHERE TENANT_ID = ? "); @@ -2773,8 +2796,12 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getType() != null) { sql.append("AND TYPE = ? "); } - if (activityPaginationRequest.getStatus() != null) { - sql.append("AND STATUS = ? "); + if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) { + sql.append("AND STATUS IN ("); + for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) { + sql.append("?, "); + } + sql.append("?) "); } if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) { @@ -2808,8 +2835,10 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getType() != null) { stmt.setString(index++, activityPaginationRequest.getType().name()); } - if (activityPaginationRequest.getStatus() != null) { - stmt.setString(index++, activityPaginationRequest.getStatus().name()); + if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) { + for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) { + stmt.setString(index++, status.name()); + } } if (isTimeDurationFilteringProvided) {