|
|
@ -26,8 +26,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ActivityList;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ActivityList;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.ActivityInfoProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.ActivityInfoProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.*;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.NotFoundException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
import javax.ws.rs.*;
|
|
|
@ -58,17 +57,17 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
activity = dmService.getOperationByActivityId(id);
|
|
|
|
activity = dmService.getOperationByActivityId(id);
|
|
|
|
if (activity == null) {
|
|
|
|
if (activity == null) {
|
|
|
|
throw new NotFoundException(new ErrorResponse.ErrorResponseBuilder().setCode(404l)
|
|
|
|
return Response.status(404).entity(
|
|
|
|
.setMessage("No activity can be " +
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage("No activity can be " +
|
|
|
|
"found upon the provided activity id '" + id + "'").build());
|
|
|
|
"found upon the provided activity id '" + id + "'").build()).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Response.status(Response.Status.OK).entity(activity).build();
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
String msg = "ErrorResponse occurred while fetching the activity for the supplied id.";
|
|
|
|
String msg = "ErrorResponse occurred while fetching the activity for the supplied id.";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new UnexpectedServerErrorException(new ErrorResponse.ErrorResponseBuilder().setCode(500l)
|
|
|
|
return Response.serverError().entity(
|
|
|
|
.setMessage(msg).build());
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(activity).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
@ -77,19 +76,21 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
@QueryParam("limit") int limit,
|
|
|
|
@QueryParam("limit") int limit,
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
|
|
|
|
|
|
|
|
long ifModifiedSinceTimestamp = 0;
|
|
|
|
long ifModifiedSinceTimestamp;
|
|
|
|
long sinceTimestamp = 0;
|
|
|
|
long sinceTimestamp;
|
|
|
|
long timestamp = 0;
|
|
|
|
long timestamp = 0;
|
|
|
|
boolean isIfModifiedSinceSet = false;
|
|
|
|
boolean isIfModifiedSinceSet = false;
|
|
|
|
boolean isSinceSet = false;
|
|
|
|
boolean isSinceSet = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) {
|
|
|
|
if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) {
|
|
|
|
Date ifSinceDate;
|
|
|
|
Date ifSinceDate;
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ifSinceDate = format.parse(ifModifiedSince);
|
|
|
|
ifSinceDate = format.parse(ifModifiedSince);
|
|
|
|
} catch (ParseException e) {
|
|
|
|
} catch (ParseException e) {
|
|
|
|
throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder().setCode(400l)
|
|
|
|
return Response.status(400).entity(
|
|
|
|
.setMessage("Invalid date string is provided in 'If-Modified-Since' header").build());
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(
|
|
|
|
|
|
|
|
"Invalid date string is provided in 'If-Modified-Since' header").build()).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ifModifiedSinceTimestamp = ifSinceDate.getTime();
|
|
|
|
ifModifiedSinceTimestamp = ifSinceDate.getTime();
|
|
|
|
isIfModifiedSinceSet = true;
|
|
|
|
isIfModifiedSinceSet = true;
|
|
|
@ -100,13 +101,15 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
sinceDate = format.parse(since);
|
|
|
|
sinceDate = format.parse(since);
|
|
|
|
} catch (ParseException e) {
|
|
|
|
} catch (ParseException e) {
|
|
|
|
throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder().setCode(400l)
|
|
|
|
return Response.status(400).entity(
|
|
|
|
.setMessage("Invalid date string is provided in 'since' filter").build());
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(
|
|
|
|
|
|
|
|
"Invalid date string is provided in 'since' filter").build()).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sinceTimestamp = sinceDate.getTime();
|
|
|
|
sinceTimestamp = sinceDate.getTime();
|
|
|
|
isSinceSet = true;
|
|
|
|
isSinceSet = true;
|
|
|
|
timestamp = sinceTimestamp / 1000;
|
|
|
|
timestamp = sinceTimestamp / 1000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<Activity> activities;
|
|
|
|
List<Activity> activities;
|
|
|
|
ActivityList activityList = new ActivityList();
|
|
|
|
ActivityList activityList = new ActivityList();
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
@ -117,24 +120,18 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
int count = dmService.getActivityCountUpdatedAfter(timestamp);
|
|
|
|
int count = dmService.getActivityCountUpdatedAfter(timestamp);
|
|
|
|
activityList.setCount(count);
|
|
|
|
activityList.setCount(count);
|
|
|
|
if (activities == null || activities.size() == 0) {
|
|
|
|
if (activities == null || activities.size() == 0) {
|
|
|
|
if (isIfModifiedSinceSet) {
|
|
|
|
if (isIfModifiedSinceSet || isSinceSet) {
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity(
|
|
|
|
return Response.notModified().build();
|
|
|
|
"No activities " + "after the time provided in 'If-Modified-Since' header")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
} else if (isSinceSet) {
|
|
|
|
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity(
|
|
|
|
|
|
|
|
"No activities " + "after the time provided in 'since' filter").build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new NotFoundException(new ErrorResponse.ErrorResponseBuilder().setCode(404l)
|
|
|
|
|
|
|
|
.setMessage("No activities " + "found.").build());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Response.ok().entity(activityList).build();
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
String msg
|
|
|
|
String msg
|
|
|
|
= "ErrorResponse occurred while fetching the activities updated after given time stamp.";
|
|
|
|
= "ErrorResponse occurred while fetching the activities updated after given time stamp.";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new UnexpectedServerErrorException(new ErrorResponse.ErrorResponseBuilder().setCode(500l)
|
|
|
|
return Response.serverError().entity(
|
|
|
|
.setMessage(msg).build());
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(activityList).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|