|
|
|
@ -29,6 +29,7 @@ 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.RequestValidationUtil;
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
|
|
|
|
|
|
import javax.validation.constraints.Size;
|
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
@ -54,6 +55,8 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
|
Activity activity;
|
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
|
Response response = validateAdminUser();
|
|
|
|
|
if (response == null) {
|
|
|
|
|
try {
|
|
|
|
|
RequestValidationUtil.validateActivityId(id);
|
|
|
|
|
|
|
|
|
@ -71,6 +74,9 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -120,7 +126,6 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
|
long sinceTimestamp;
|
|
|
|
|
long timestamp = 0;
|
|
|
|
|
boolean isIfModifiedSinceSet = false;
|
|
|
|
|
boolean isSinceSet = false;
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("getActivities since: " + since + " , offset: " + offset + " ,limit: " + limit + " ," +
|
|
|
|
|
"ifModifiedSince: " + ifModifiedSince);
|
|
|
|
@ -150,7 +155,6 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
|
"Invalid date string is provided in 'since' filter").build()).build();
|
|
|
|
|
}
|
|
|
|
|
sinceTimestamp = sinceDate.getTime();
|
|
|
|
|
isSinceSet = true;
|
|
|
|
|
timestamp = sinceTimestamp / 1000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -162,7 +166,8 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("getActivities final timestamp " + timestamp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Response response = validateAdminUser();
|
|
|
|
|
if (response == null) {
|
|
|
|
|
List<Activity> activities;
|
|
|
|
|
ActivityList activityList = new ActivityList();
|
|
|
|
|
DeviceManagementProviderService dmService;
|
|
|
|
@ -194,6 +199,24 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response validateAdminUser(){
|
|
|
|
|
try {
|
|
|
|
|
if (!DeviceMgtAPIUtils.isAdmin()) {
|
|
|
|
|
return Response.status(Response.Status.UNAUTHORIZED).entity("Unauthorized operation! Only admin role can perform " +
|
|
|
|
|
"this operation.").build();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
String msg
|
|
|
|
|
= "Error occurred while validating the user have admin role!";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|