|
|
@ -74,42 +74,54 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response getActivities(
|
|
|
|
public Response getActivities(
|
|
|
|
@QueryParam("timestamp") long timestamp,
|
|
|
|
@QueryParam("since") String since,
|
|
|
|
@QueryParam("offset") int offset,
|
|
|
|
@QueryParam("offset") int offset,
|
|
|
|
@QueryParam("limit") int limit,
|
|
|
|
@QueryParam("limit") int limit,
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
|
|
|
|
|
|
|
|
long sinceTimestamp = 0;
|
|
|
|
long ifModifiedSinceTimestamp = 0;
|
|
|
|
boolean isSinceModifiedIsSet = false;
|
|
|
|
long sinceTimestamp =0;
|
|
|
|
|
|
|
|
boolean isIfModifiedSinceSet = false;
|
|
|
|
if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) {
|
|
|
|
if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) {
|
|
|
|
|
|
|
|
Date sinceDate;
|
|
|
|
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
|
|
|
|
sinceDate = format.parse(ifModifiedSince);
|
|
|
|
Date sinceDate = format.parse(ifModifiedSince);
|
|
|
|
|
|
|
|
sinceTimestamp = sinceDate.getTime();
|
|
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
} catch (ParseException e) {
|
|
|
|
throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder().setCode(400l)
|
|
|
|
throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder().setCode(400l)
|
|
|
|
.setMessage("Invalid date " + "string is provided in 'If-Modified-Since' header").build());
|
|
|
|
.setMessage("Invalid date string is provided in 'If-Modified-Since' header").build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ifModifiedSinceTimestamp = sinceDate.getTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sinceTimestamp > timestamp) {
|
|
|
|
if (since != null && !since.isEmpty()){
|
|
|
|
timestamp = sinceTimestamp;
|
|
|
|
Date sinceDate;
|
|
|
|
isSinceModifiedIsSet = true;
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
sinceDate = format.parse(since);
|
|
|
|
|
|
|
|
}catch (ParseException e){
|
|
|
|
|
|
|
|
throw new InputValidationException(new ErrorResponse.ErrorResponseBuilder().setCode(400l)
|
|
|
|
|
|
|
|
.setMessage("Invalid date string is provided in 'since' filter").build());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sinceTimestamp = sinceDate.getTime();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ifModifiedSinceTimestamp >= sinceTimestamp) {
|
|
|
|
|
|
|
|
sinceTimestamp = ifModifiedSinceTimestamp;
|
|
|
|
|
|
|
|
isIfModifiedSinceSet = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Activity> activities;
|
|
|
|
List<Activity> activities;
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
activities = dmService.getActivitiesUpdatedAfter(timestamp);
|
|
|
|
activities = dmService.getActivitiesUpdatedAfter(sinceTimestamp);
|
|
|
|
if (activities == null || activities.size() == 0) {
|
|
|
|
if (activities == null || activities.size() == 0) {
|
|
|
|
if (isSinceModifiedIsSet) {
|
|
|
|
if (isIfModifiedSinceSet) {
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity("No activities " +
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity("No activities " +
|
|
|
|
"after the timestamp provided in 'If-Modified-Since' header").build();
|
|
|
|
"after the time provided in 'If-Modified-Since' header").build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new NotFoundException(
|
|
|
|
throw new NotFoundException(
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No activities " +
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No activities " +
|
|
|
|
"found.").build());
|
|
|
|
"found.").build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
String msg = "ErrorResponse occurred while fetching the activities updated after given time stamp.";
|
|
|
|
String msg = "ErrorResponse occurred while fetching the activities updated after given time stamp.";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|