|
|
|
@ -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.OperationManagementException;
|
|
|
|
|
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.service.api.ActivityInfoProviderService;
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.*;
|
|
|
|
@ -47,8 +48,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
|
@GET
|
|
|
|
|
@Override
|
|
|
|
|
@Path("/{id}")
|
|
|
|
|
public Response getActivity(
|
|
|
|
|
@PathParam("id") String id,
|
|
|
|
|
public Response getActivity(@PathParam("id") String id,
|
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
|
Activity activity;
|
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
@ -58,24 +58,22 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
|
activity = dmService.getOperationByActivityId(id);
|
|
|
|
|
if (activity == null) {
|
|
|
|
|
throw new NotFoundException(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No activity can be " +
|
|
|
|
|
throw new NotFoundException(new ErrorResponse.ErrorResponseBuilder().setCode(404l)
|
|
|
|
|
.setMessage("No activity can be " +
|
|
|
|
|
"found upon the provided activity id '" + id + "'").build());
|
|
|
|
|
}
|
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
|
String msg = "ErrorResponse occurred while fetching the activity for the supplied id.";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
|
throw new UnexpectedServerErrorException(new ErrorResponse.ErrorResponseBuilder().setCode(500l)
|
|
|
|
|
.setMessage(msg).build());
|
|
|
|
|
}
|
|
|
|
|
return Response.status(Response.Status.OK).entity(activity).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Override
|
|
|
|
|
public Response getActivities(
|
|
|
|
|
@QueryParam("since") String since,
|
|
|
|
|
@QueryParam("offset") int offset,
|
|
|
|
|
public Response getActivities(@QueryParam("since") String since, @QueryParam("offset") int offset,
|
|
|
|
|
@QueryParam("limit") int limit,
|
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
|
|
|
|
|
@ -110,27 +108,29 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
|
timestamp = sinceTimestamp / 1000;
|
|
|
|
|
}
|
|
|
|
|
List<Activity> activities;
|
|
|
|
|
ActivityList activityList = new ActivityList();
|
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
|
try {
|
|
|
|
|
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
|
|
|
|
|
activities = dmService.getActivitiesUpdatedAfter(timestamp);
|
|
|
|
|
if (activities == null || activities.size() == 0) {
|
|
|
|
|
if (isIfModifiedSinceSet) {
|
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity("No activities " +
|
|
|
|
|
"after the time provided in 'If-Modified-Since' header").build();
|
|
|
|
|
return Response.status(Response.Status.NOT_MODIFIED).entity(
|
|
|
|
|
"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();
|
|
|
|
|
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());
|
|
|
|
|
throw new NotFoundException(new ErrorResponse.ErrorResponseBuilder().setCode(404l)
|
|
|
|
|
.setMessage("No activities " + "found.").build());
|
|
|
|
|
}
|
|
|
|
|
} 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);
|
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
|
throw new UnexpectedServerErrorException(new ErrorResponse.ErrorResponseBuilder().setCode(500l)
|
|
|
|
|
.setMessage(msg).build());
|
|
|
|
|
}
|
|
|
|
|
return Response.status(Response.Status.OK).entity(activities).build();
|
|
|
|
|
}
|
|
|
|
|