|
|
@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
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.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.*;
|
|
|
@ -47,9 +48,8 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Path("/{id}")
|
|
|
|
@Path("/{id}")
|
|
|
|
public Response getActivity(
|
|
|
|
public Response getActivity(@PathParam("id") String id,
|
|
|
|
@PathParam("id") String id,
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
|
|
|
|
Activity activity;
|
|
|
|
Activity activity;
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -58,30 +58,28 @@ 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(
|
|
|
|
throw new NotFoundException(new ErrorResponse.ErrorResponseBuilder().setCode(404l)
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No activity can be " +
|
|
|
|
.setMessage("No activity can be " +
|
|
|
|
"found upon the provided activity id '" + id + "'").build());
|
|
|
|
"found upon the provided activity id '" + id + "'").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(
|
|
|
|
throw new UnexpectedServerErrorException(new ErrorResponse.ErrorResponseBuilder().setCode(500l)
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
.setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(activity).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(activity).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response getActivities(
|
|
|
|
public Response getActivities(@QueryParam("since") String since, @QueryParam("offset") int offset,
|
|
|
|
@QueryParam("since") String since,
|
|
|
|
@QueryParam("limit") int limit,
|
|
|
|
@QueryParam("offset") int offset,
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
@QueryParam("limit") int limit,
|
|
|
|
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long ifModifiedSinceTimestamp = 0;
|
|
|
|
long ifModifiedSinceTimestamp = 0;
|
|
|
|
long sinceTimestamp =0;
|
|
|
|
long sinceTimestamp = 0;
|
|
|
|
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()) {
|
|
|
@ -95,42 +93,44 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ifModifiedSinceTimestamp = ifSinceDate.getTime();
|
|
|
|
ifModifiedSinceTimestamp = ifSinceDate.getTime();
|
|
|
|
isIfModifiedSinceSet = true;
|
|
|
|
isIfModifiedSinceSet = true;
|
|
|
|
timestamp = ifModifiedSinceTimestamp/1000;
|
|
|
|
timestamp = ifModifiedSinceTimestamp / 1000;
|
|
|
|
} else if (since != null && !since.isEmpty()){
|
|
|
|
} else if (since != null && !since.isEmpty()) {
|
|
|
|
Date sinceDate;
|
|
|
|
Date sinceDate;
|
|
|
|
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 {
|
|
|
|
sinceDate = format.parse(since);
|
|
|
|
sinceDate = format.parse(since);
|
|
|
|
}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 'since' filter").build());
|
|
|
|
.setMessage("Invalid date string is provided in 'since' filter").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();
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
activities = dmService.getActivitiesUpdatedAfter(timestamp);
|
|
|
|
activities = dmService.getActivitiesUpdatedAfter(timestamp);
|
|
|
|
if (activities == null || activities.size() == 0) {
|
|
|
|
if (activities == null || activities.size() == 0) {
|
|
|
|
if (isIfModifiedSinceSet) {
|
|
|
|
if (isIfModifiedSinceSet) {
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity("No activities " +
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity(
|
|
|
|
"after the time provided in 'If-Modified-Since' header").build();
|
|
|
|
"No activities " + "after the time provided in 'If-Modified-Since' header")
|
|
|
|
} else if(isSinceSet){
|
|
|
|
.build();
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity("No activities " +
|
|
|
|
} else if (isSinceSet) {
|
|
|
|
"after the time provided in 'since' filter").build();
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity(
|
|
|
|
|
|
|
|
"No activities " + "after the time provided in 'since' filter").build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new NotFoundException(
|
|
|
|
throw new NotFoundException(new ErrorResponse.ErrorResponseBuilder().setCode(404l)
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No activities " +
|
|
|
|
.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);
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
throw new UnexpectedServerErrorException(new ErrorResponse.ErrorResponseBuilder().setCode(500l)
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
.setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(activities).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(activities).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|