|
|
@ -29,6 +29,7 @@ import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Operation;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ActivityList;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ActivityList;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceActivityList;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.common.ActivityIdList;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.common.ActivityIdList;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.ActivityInfoProviderService;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.ActivityInfoProviderService;
|
|
|
@ -246,6 +247,130 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
|
|
|
@Path("/devices")
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Response getDeviceActivities(@DefaultValue("0") @QueryParam("offset") int offset,
|
|
|
|
|
|
|
|
@DefaultValue("20") @QueryParam("limit") int limit,
|
|
|
|
|
|
|
|
@QueryParam("since") String since,
|
|
|
|
|
|
|
|
@QueryParam("initiatedBy") String initiatedBy,
|
|
|
|
|
|
|
|
@QueryParam("operationCode") String operationCode,
|
|
|
|
|
|
|
|
@QueryParam("operationId") int operationId,
|
|
|
|
|
|
|
|
@QueryParam("deviceType") String deviceType,
|
|
|
|
|
|
|
|
@QueryParam("deviceId") List<String> deviceIds,
|
|
|
|
|
|
|
|
@QueryParam("type") String type,
|
|
|
|
|
|
|
|
@QueryParam("status") String status,
|
|
|
|
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
|
|
|
|
|
|
|
@QueryParam("startTimestamp") long startTimestamp,
|
|
|
|
|
|
|
|
@QueryParam("endTimestamp") long endTimestamp) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long ifModifiedSinceTimestamp;
|
|
|
|
|
|
|
|
long sinceTimestamp;
|
|
|
|
|
|
|
|
long timestamp = 0;
|
|
|
|
|
|
|
|
boolean isTimeDurationProvided = false;
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("getDeviceActivities since: " + since + " , offset: " + offset + " ,limit: " + limit + " ," +
|
|
|
|
|
|
|
|
"ifModifiedSince: " + ifModifiedSince);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
|
|
|
|
|
|
|
if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) {
|
|
|
|
|
|
|
|
Date ifSinceDate;
|
|
|
|
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ifSinceDate = format.parse(ifModifiedSince);
|
|
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
|
|
return Response.status(400).entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(
|
|
|
|
|
|
|
|
"Invalid date string is provided in 'If-Modified-Since' header").build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ifModifiedSinceTimestamp = ifSinceDate.getTime();
|
|
|
|
|
|
|
|
timestamp = ifModifiedSinceTimestamp / 1000;
|
|
|
|
|
|
|
|
} else if (since != null && !since.isEmpty()) {
|
|
|
|
|
|
|
|
Date sinceDate;
|
|
|
|
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
sinceDate = format.parse(since);
|
|
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
|
|
return Response.status(400).entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(
|
|
|
|
|
|
|
|
"Invalid date string is provided in 'since' filter").build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sinceTimestamp = sinceDate.getTime();
|
|
|
|
|
|
|
|
timestamp = sinceTimestamp / 1000;
|
|
|
|
|
|
|
|
} else if (startTimestamp > 0 && endTimestamp > 0) {
|
|
|
|
|
|
|
|
RequestValidationUtil.validateTimeDuration(startTimestamp, endTimestamp);
|
|
|
|
|
|
|
|
isTimeDurationProvided = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (timestamp == 0 && !isTimeDurationProvided) {
|
|
|
|
|
|
|
|
//If timestamp is not sent by the user, a default value is set, that is equal to current time-12 hours.
|
|
|
|
|
|
|
|
long time = System.currentTimeMillis() / 1000;
|
|
|
|
|
|
|
|
timestamp = time - 42300;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("getDeviceActivities final timestamp " + timestamp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceActivityList deviceActivityList = new DeviceActivityList();
|
|
|
|
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
|
|
|
|
ActivityPaginationRequest activityPaginationRequest = new ActivityPaginationRequest(offset, limit);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Calling database to get device activities.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
|
|
|
|
if (initiatedBy != null && !initiatedBy.isEmpty()) {
|
|
|
|
|
|
|
|
activityPaginationRequest.setInitiatedBy(initiatedBy);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (operationCode != null && !operationCode.isEmpty()) {
|
|
|
|
|
|
|
|
activityPaginationRequest.setOperationCode(operationCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (operationId > 0) {
|
|
|
|
|
|
|
|
activityPaginationRequest.setOperationId(operationId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceType != null && !deviceType.isEmpty()) {
|
|
|
|
|
|
|
|
activityPaginationRequest.setDeviceType(deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceIds != null && !deviceIds.isEmpty()) {
|
|
|
|
|
|
|
|
activityPaginationRequest.setDeviceIds(deviceIds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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 (timestamp > 0) {
|
|
|
|
|
|
|
|
activityPaginationRequest.setSince(timestamp);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
activityPaginationRequest.setStartTimestamp(startTimestamp);
|
|
|
|
|
|
|
|
activityPaginationRequest.setEndTimestamp(endTimestamp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Device Activity request: " + new Gson().toJson(activityPaginationRequest));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = dmService.getDeviceActivitiesCount(activityPaginationRequest);
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Filtered Device Activity count: " + count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
|
|
|
deviceActivityList.setList(dmService.getDeviceActivities(activityPaginationRequest));
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Fetched Device Activity count: " + deviceActivityList.getList().size());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) {
|
|
|
|
|
|
|
|
return Response.notModified().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
deviceActivityList.setCount(count);
|
|
|
|
|
|
|
|
return Response.ok().entity(deviceActivityList).build();
|
|
|
|
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
|
|
|
|
String msg
|
|
|
|
|
|
|
|
= "ErrorResponse occurred while fetching the device activities updated after given time stamp.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response getActivities(@DefaultValue("0") @QueryParam("offset") int offset,
|
|
|
|
public Response getActivities(@DefaultValue("0") @QueryParam("offset") int offset,
|
|
|
@ -306,69 +431,64 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("getActivities final timestamp " + timestamp);
|
|
|
|
log.debug("getActivities final timestamp " + timestamp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Response response = validateAdminPermission();
|
|
|
|
ActivityList activityList = new ActivityList();
|
|
|
|
if (response == null) {
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
ActivityList activityList = new ActivityList();
|
|
|
|
ActivityPaginationRequest activityPaginationRequest = new ActivityPaginationRequest(offset, limit);
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
try {
|
|
|
|
ActivityPaginationRequest activityPaginationRequest = new ActivityPaginationRequest(offset, limit);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
try {
|
|
|
|
log.debug("Calling database to get activities.");
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
}
|
|
|
|
log.debug("Calling database to get activities.");
|
|
|
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
}
|
|
|
|
if (initiatedBy != null && !initiatedBy.isEmpty()) {
|
|
|
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
activityPaginationRequest.setInitiatedBy(initiatedBy);
|
|
|
|
if (initiatedBy != null && !initiatedBy.isEmpty()) {
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setInitiatedBy(initiatedBy);
|
|
|
|
if (operationCode != null && !operationCode.isEmpty()) {
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setOperationCode(operationCode);
|
|
|
|
if (operationCode != null && !operationCode.isEmpty()) {
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setOperationCode(operationCode);
|
|
|
|
if (operationId > 0) {
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setOperationId(operationId);
|
|
|
|
if (operationId > 0) {
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setOperationId(operationId);
|
|
|
|
if (deviceType != null && !deviceType.isEmpty()) {
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setDeviceType(deviceType);
|
|
|
|
if (deviceType != null && !deviceType.isEmpty()) {
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setDeviceType(deviceType);
|
|
|
|
if (deviceIds != null && !deviceIds.isEmpty()) {
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setDeviceIds(deviceIds);
|
|
|
|
if (deviceIds != null && !deviceIds.isEmpty()) {
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setDeviceIds(deviceIds);
|
|
|
|
if (type != null && !type.isEmpty()) {
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setType(Operation.Type.valueOf(type.toUpperCase()));
|
|
|
|
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 (status != null && !status.isEmpty()) {
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setStatus(Operation.Status.valueOf(status.toUpperCase()));
|
|
|
|
if (timestamp > 0) {
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setSince(timestamp);
|
|
|
|
if (timestamp > 0) {
|
|
|
|
} else {
|
|
|
|
activityPaginationRequest.setSince(timestamp);
|
|
|
|
activityPaginationRequest.setStartTimestamp(startTimestamp);
|
|
|
|
} else {
|
|
|
|
activityPaginationRequest.setEndTimestamp(endTimestamp);
|
|
|
|
activityPaginationRequest.setStartTimestamp(startTimestamp);
|
|
|
|
}
|
|
|
|
activityPaginationRequest.setEndTimestamp(endTimestamp);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
}
|
|
|
|
log.debug("Activity request: " + new Gson().toJson(activityPaginationRequest));
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
}
|
|
|
|
log.debug("Activity request: " + new Gson().toJson(activityPaginationRequest));
|
|
|
|
int count = dmService.getActivitiesCount(activityPaginationRequest);
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
int count = dmService.getActivitiesCount(activityPaginationRequest);
|
|
|
|
log.debug("Filtered Activity count: " + count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
|
|
|
activityList.setList(dmService.getActivities(activityPaginationRequest));
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Filtered Activity count: " + count);
|
|
|
|
log.debug("Fetched Activity count: " + activityList.getList().size());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
|
|
|
activityList.setList(dmService.getActivities(activityPaginationRequest));
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Fetched Activity count: " + activityList.getList().size());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) {
|
|
|
|
|
|
|
|
return Response.notModified().build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
activityList.setCount(count);
|
|
|
|
} else if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) {
|
|
|
|
return Response.ok().entity(activityList).build();
|
|
|
|
return Response.notModified().build();
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
|
|
|
|
String msg
|
|
|
|
|
|
|
|
= "ErrorResponse occurred while fetching the activities updated after given time stamp.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
activityList.setCount(count);
|
|
|
|
return response;
|
|
|
|
return Response.ok().entity(activityList).build();
|
|
|
|
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
|
|
|
|
String msg
|
|
|
|
|
|
|
|
= "ErrorResponse occurred while fetching the activities updated after given time stamp.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|