Implement multi value (status) filtering for getting activity details

Co-authored-by: Gimhan Wijayawardana <gimhan@entgra.io>
Co-committed-by: Gimhan Wijayawardana <gimhan@entgra.io>
appm_improvement
Gimhan Wijayawardana 8 months ago committed by Lasantha Dharmakeerthi
parent ff92eae958
commit 64189a400d

@ -491,7 +491,7 @@ public interface ActivityInfoProviderService {
name = "status", name = "status",
value = "Operation response status to filter" value = "Operation response status to filter"
) )
@QueryParam("status") String status, @QueryParam("status") List<String> statuses,
@ApiParam( @ApiParam(
name = "If-Modified-Since", name = "If-Modified-Since",
value = "Checks if the requested variant was modified, since the specified date-time\n." + value = "Checks if the requested variant was modified, since the specified date-time\n." +
@ -615,7 +615,7 @@ public interface ActivityInfoProviderService {
name = "status", name = "status",
value = "Operation response status to filter" value = "Operation response status to filter"
) )
@QueryParam("status") String status, @QueryParam("status") List<String> statuses,
@ApiParam( @ApiParam(
name = "If-Modified-Since", name = "If-Modified-Since",
value = "Checks if the requested variant was modified, since the specified date-time\n." + value = "Checks if the requested variant was modified, since the specified date-time\n." +

@ -50,6 +50,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -259,7 +260,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
@QueryParam("deviceType") String deviceType, @QueryParam("deviceType") String deviceType,
@QueryParam("deviceId") List<String> deviceIds, @QueryParam("deviceId") List<String> deviceIds,
@QueryParam("type") String type, @QueryParam("type") String type,
@QueryParam("status") String status, @QueryParam("status") List<String> statuses,
@HeaderParam("If-Modified-Since") String ifModifiedSince, @HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("startTimestamp") long startTimestamp, @QueryParam("startTimestamp") long startTimestamp,
@QueryParam("endTimestamp") long endTimestamp) { @QueryParam("endTimestamp") long endTimestamp) {
@ -336,8 +337,12 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
if (type != null && !type.isEmpty()) { if (type != null && !type.isEmpty()) {
activityPaginationRequest.setType(Operation.Type.valueOf(type.toUpperCase())); activityPaginationRequest.setType(Operation.Type.valueOf(type.toUpperCase()));
} }
if (status != null && !status.isEmpty()) { if (statuses != null && !statuses.isEmpty()) {
activityPaginationRequest.setStatus(Operation.Status.valueOf(status.toUpperCase())); List<Operation.Status> statusEnums = new ArrayList<>();
for (String status : statuses) {
statusEnums.add(Operation.Status.valueOf(status.toUpperCase()));
}
activityPaginationRequest.setStatuses(statusEnums);
} }
if (timestamp > 0) { if (timestamp > 0) {
activityPaginationRequest.setSince(timestamp); activityPaginationRequest.setSince(timestamp);
@ -382,7 +387,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
@QueryParam("deviceType") String deviceType, @QueryParam("deviceType") String deviceType,
@QueryParam("deviceId") List<String> deviceIds, @QueryParam("deviceId") List<String> deviceIds,
@QueryParam("type") String type, @QueryParam("type") String type,
@QueryParam("status") String status, @QueryParam("status") List<String> statuses,
@HeaderParam("If-Modified-Since") String ifModifiedSince, @HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("startTimestamp") long startTimestamp, @QueryParam("startTimestamp") long startTimestamp,
@QueryParam("endTimestamp") long endTimestamp) { @QueryParam("endTimestamp") long endTimestamp) {
@ -457,8 +462,12 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
if (type != null && !type.isEmpty()) { if (type != null && !type.isEmpty()) {
activityPaginationRequest.setType(Operation.Type.valueOf(type.toUpperCase())); activityPaginationRequest.setType(Operation.Type.valueOf(type.toUpperCase()));
} }
if (status != null && !status.isEmpty()) { if (statuses != null && !statuses.isEmpty()) {
activityPaginationRequest.setStatus(Operation.Status.valueOf(status.toUpperCase())); List<Operation.Status> statusEnums = new ArrayList<>();
for (String status : statuses) {
statusEnums.add(Operation.Status.valueOf(status.toUpperCase()));
}
activityPaginationRequest.setStatuses(statusEnums);
} }
if (timestamp > 0) { if (timestamp > 0) {
activityPaginationRequest.setSince(timestamp); activityPaginationRequest.setSince(timestamp);

@ -132,7 +132,7 @@ public class ActivityProviderServiceImplTest {
activityPaginationRequest.setDeviceType(DEVICE_TYPE_2); activityPaginationRequest.setDeviceType(DEVICE_TYPE_2);
activityPaginationRequest.setOperationId(OPERATION_ID); activityPaginationRequest.setOperationId(OPERATION_ID);
activityPaginationRequest.setInitiatedBy(INITIATED_BY); activityPaginationRequest.setInitiatedBy(INITIATED_BY);
activityPaginationRequest.setStatus(STATUS); activityPaginationRequest.setStatuses(Collections.singletonList(STATUS));
activityPaginationRequest.setType(TYPE); activityPaginationRequest.setType(TYPE);
activityPaginationRequest.setStartTimestamp(0); activityPaginationRequest.setStartTimestamp(0);
activityPaginationRequest.setEndTimestamp(0); activityPaginationRequest.setEndTimestamp(0);
@ -226,7 +226,7 @@ public class ActivityProviderServiceImplTest {
Mockito.when(this.deviceManagementProviderService.getActivities(Mockito.any())).thenReturn(activities); Mockito.when(this.deviceManagementProviderService.getActivities(Mockito.any())).thenReturn(activities);
Response response = this.activityInfoProviderService.getActivities( Response response = this.activityInfoProviderService.getActivities(
OFFSET, LIMIT, SINCE, INITIATED_BY, OPERATION_CODE, OPERATION_ID, 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.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertNotNull(response); Assert.assertNotNull(response);
@ -258,7 +258,7 @@ public class ActivityProviderServiceImplTest {
Mockito.when(this.deviceManagementProviderService.getDeviceActivities(Mockito.any())).thenReturn(deviceActivities); Mockito.when(this.deviceManagementProviderService.getDeviceActivities(Mockito.any())).thenReturn(deviceActivities);
Response response = this.activityInfoProviderService.getDeviceActivities( Response response = this.activityInfoProviderService.getDeviceActivities(
OFFSET, LIMIT, SINCE, INITIATED_BY, OPERATION_CODE, OPERATION_ID, 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.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertNotNull(response); Assert.assertNotNull(response);

@ -36,7 +36,7 @@ public class ActivityPaginationRequest {
private String initiatedBy; private String initiatedBy;
private long since; private long since;
private Operation.Type type; private Operation.Type type;
private Operation.Status status; private List<Operation.Status> statuses;
private long startTimestamp; private long startTimestamp;
private long endTimestamp; private long endTimestamp;
@ -110,12 +110,12 @@ public class ActivityPaginationRequest {
this.type = type; this.type = type;
} }
public Operation.Status getStatus() { public List<Operation.Status> getStatuses() {
return status; return statuses;
} }
public void setStatus(Operation.Status status) { public void setStatuses(List<Operation.Status> statuses) {
this.status = status; this.statuses = statuses;
} }
public long getStartTimestamp() { public long getStartTimestamp() {

@ -2272,7 +2272,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getDeviceType() != null || if (activityPaginationRequest.getDeviceType() != null ||
(activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) || (activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) ||
activityPaginationRequest.getSince() != 0 || activityPaginationRequest.getSince() != 0 ||
activityPaginationRequest.getStatus() != null) { activityPaginationRequest.getStatuses() != null) {
sql.append("(SELECT DISTINCT OPERATION_ID FROM DM_ENROLMENT_OP_MAPPING eom WHERE TENANT_ID = ? "); 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) { if (activityPaginationRequest.getType() != null) {
sql.append("AND TYPE = ? "); sql.append("AND TYPE = ? ");
} }
if (activityPaginationRequest.getStatus() != null) { if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
sql.append("AND STATUS = ? "); 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 " + sql.append("ORDER BY OPERATION_ID ASC limit ? , ? ) eom_ordered " +
@ -2360,8 +2364,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
sql.append("AND eom.TYPE = ? "); sql.append("AND eom.TYPE = ? ");
} }
if (activityPaginationRequest.getStatus() != null) { if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
sql.append("AND eom.STATUS = ? "); 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"); sql.append("ORDER BY eom.OPERATION_ID, eom.UPDATED_TIMESTAMP");
@ -2372,7 +2380,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getDeviceType() != null || if (activityPaginationRequest.getDeviceType() != null ||
(activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) || (activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) ||
activityPaginationRequest.getSince() != 0 || activityPaginationRequest.getSince() != 0 ||
activityPaginationRequest.getStatus() != null) { activityPaginationRequest.getStatuses() != null) {
if (activityPaginationRequest.getDeviceType() != null) { if (activityPaginationRequest.getDeviceType() != null) {
stmt.setString(index++, activityPaginationRequest.getDeviceType()); stmt.setString(index++, activityPaginationRequest.getDeviceType());
@ -2401,8 +2409,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
stmt.setString(index++, activityPaginationRequest.getType().name()); stmt.setString(index++, activityPaginationRequest.getType().name());
} }
if (activityPaginationRequest.getStatus() != null) { if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
stmt.setString(index++, activityPaginationRequest.getStatus().name()); 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()); stmt.setInt(index++, activityPaginationRequest.getOffset());
@ -2463,8 +2473,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
stmt.setString(index++, activityPaginationRequest.getType().name()); stmt.setString(index++, activityPaginationRequest.getType().name());
} }
if (activityPaginationRequest.getStatus() != null) { if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
stmt.setString(index, activityPaginationRequest.getStatus().name()); 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()) { try (ResultSet rs = stmt.executeQuery()) {
@ -2496,7 +2508,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getDeviceType() != null || if (activityPaginationRequest.getDeviceType() != null ||
(activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) || (activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) ||
activityPaginationRequest.getSince() != 0 || activityPaginationRequest.getSince() != 0 ||
activityPaginationRequest.getStatus() != null) { activityPaginationRequest.getStatuses() != null) {
sql.append("SELECT count(DISTINCT OPERATION_ID) AS ACTIVITY_COUNT " + sql.append("SELECT count(DISTINCT OPERATION_ID) AS ACTIVITY_COUNT " +
"FROM DM_ENROLMENT_OP_MAPPING WHERE TENANT_ID = ? "); "FROM DM_ENROLMENT_OP_MAPPING WHERE TENANT_ID = ? ");
@ -2526,8 +2538,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
sql.append("AND TYPE = ? "); sql.append("AND TYPE = ? ");
} }
if (activityPaginationRequest.getStatus() != null) { if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
sql.append("AND STATUS = ? "); sql.append("AND STATUS IN (");
for (int i = 0; i < activityPaginationRequest.getStatuses().size() - 1; i++) {
sql.append("?, ");
}
sql.append("?) ");
} }
} else { } else {
@ -2555,7 +2571,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getDeviceType() != null || if (activityPaginationRequest.getDeviceType() != null ||
(activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) || (activityPaginationRequest.getDeviceIds() != null && !activityPaginationRequest.getDeviceIds().isEmpty()) ||
activityPaginationRequest.getSince() != 0 || activityPaginationRequest.getSince() != 0 ||
activityPaginationRequest.getStatus() != null) { activityPaginationRequest.getStatuses() != null) {
if (activityPaginationRequest.getDeviceType() != null) { if (activityPaginationRequest.getDeviceType() != null) {
stmt.setString(index++, activityPaginationRequest.getDeviceType()); stmt.setString(index++, activityPaginationRequest.getDeviceType());
} }
@ -2579,8 +2595,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
stmt.setString(index++, activityPaginationRequest.getType().name()); stmt.setString(index++, activityPaginationRequest.getType().name());
} }
if (activityPaginationRequest.getStatus() != null) { if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
stmt.setString(index++, activityPaginationRequest.getStatus().name()); for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) {
stmt.setString(index++, status.name());
}
} }
} else { } else {
if (activityPaginationRequest.getOperationCode() != null) { if (activityPaginationRequest.getOperationCode() != null) {
@ -2662,8 +2680,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
sql.append("AND TYPE = ? "); sql.append("AND TYPE = ? ");
} }
if (activityPaginationRequest.getStatus() != null) { if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
sql.append("AND STATUS = ? "); 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 " + sql.append("ORDER BY ID ASC limit ? , ? ) eom " +
@ -2700,8 +2722,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
stmt.setString(index++, activityPaginationRequest.getType().name()); stmt.setString(index++, activityPaginationRequest.getType().name());
} }
if (activityPaginationRequest.getStatus() != null) { if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
stmt.setString(index++, activityPaginationRequest.getStatus().name()); 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()); stmt.setInt(index++, activityPaginationRequest.getOffset());
@ -2744,7 +2768,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.append("SELECT count(DISTINCT ID) AS ACTIVITY_COUNT " + sql.append("SELECT count(DISTINCT ID) AS ACTIVITY_COUNT " +
"FROM DM_ENROLMENT_OP_MAPPING WHERE TENANT_ID = ? "); "FROM DM_ENROLMENT_OP_MAPPING WHERE TENANT_ID = ? ");
@ -2773,8 +2796,12 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
sql.append("AND TYPE = ? "); sql.append("AND TYPE = ? ");
} }
if (activityPaginationRequest.getStatus() != null) { if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
sql.append("AND STATUS = ? "); 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) { if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) {
@ -2808,8 +2835,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
stmt.setString(index++, activityPaginationRequest.getType().name()); stmt.setString(index++, activityPaginationRequest.getType().name());
} }
if (activityPaginationRequest.getStatus() != null) { if (activityPaginationRequest.getStatuses() != null && !activityPaginationRequest.getStatuses().isEmpty()) {
stmt.setString(index++, activityPaginationRequest.getStatus().name()); for (io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation.Status status : activityPaginationRequest.getStatuses()) {
stmt.setString(index++, status.name());
}
} }
if (isTimeDurationFilteringProvided) { if (isTimeDurationFilteringProvided) {

Loading…
Cancel
Save