Adding activity apis to get the updated once after a given time

revert-70aa11f8
geethkokila 9 years ago
parent 2925f52cd8
commit b7da99a621

@ -93,4 +93,56 @@ public interface ActivityInfoProviderService {
required = false) required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince); @HeaderParam("If-Modified-Since") String ifModifiedSince);
@GET
@Path("/")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
response = Activity.class,
responseContainer = "List",
value = "Retrieve details of a particular activity.",
notes = "This will return information of a particular activities i.e. meta information of operations, " +
"etc; including the responses from the devices which happened after given time.")
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "OK. \n Activity details is successfully fetched",
response = Activity.class,
responseContainer = "List",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching activity data.")
})
@Permission(scope = "activity-view", permissions = {"/permission/admin/device-mgt/admin/activities/view"})
Response getActivities(
@ApiParam(
name = "timestamp",
value = "Validates if the requested variant has not been modified since the time specified, this " +
"should be provided in unix format in seconds.",
required = true)
@QueryParam("timestamp") String timestamp);
} }

@ -129,6 +129,75 @@ public interface DeviceManagementService {
required = false) required = false)
@QueryParam("limit") int limit); @QueryParam("limit") int limit);
@GET
@Path("{type}/{id}/info")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Retrieve devices information from the supplied device identifier.",
notes = "This will return device information such as CPU usage, memory usage etc for supplied device " +
"identifier.",
response = DeviceInfo.class,
tags = "Device Management")
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Information of the submitted list of devices is returned",
response = DeviceInfo.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests.")}),
@ApiResponse(
code = 303,
message = "See Other. \n Source can be retrieved from the URL specified at the Location header.",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "The Source URL of the document.")}),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 406,
message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while retrieving information of the list of the devices submitted.")
})
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDeviceInfo(
@ApiParam(
name = "type",
value = "The device type, such as ios, android or windows.",
required = true)
@PathParam("type") String type,
@ApiParam(
name = "id",
value = "The device identifier of the device.",
required = true)
@PathParam("id") String id,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@POST @POST
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
@ -300,6 +369,49 @@ public interface DeviceManagementService {
required = false) required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince); @HeaderParam("If-Modified-Since") String ifModifiedSince);
@POST
@Path("/locations")
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Get the device location of a given devices and a device type.",
notes = "This will return the device locations including latitude and longitude as well the "
+ "physical address of the given devices.",
response = DeviceLocation.class,
responseContainer = "List",
tags = "Device Management")
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "Successfully fetched the device location.",
response = DeviceLocation.class,
responseContainer = "List"),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 404,
message = "Location details are not available for the given devices."),
@ApiResponse(
code = 500,
message = "Error occurred while getting the device location.")
})
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDeviceLocations(
@ApiParam(
name = "deviceIds",
value = "List of device identifiers",
required = true) List<DeviceIdentifier> deviceIds,
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince);
@GET @GET
@Path("/{type}/{id}/features") @Path("/{type}/{id}/features")
@ApiOperation( @ApiOperation(

@ -29,7 +29,9 @@ import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.ws.rs.HeaderParam; import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List;
public class ActivityProviderServiceImpl implements ActivityInfoProviderService { public class ActivityProviderServiceImpl implements ActivityInfoProviderService {
@ -53,4 +55,20 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
return Response.status(Response.Status.OK).entity(operation).build(); return Response.status(Response.Status.OK).entity(operation).build();
} }
@Override
@Path("/")
public Response getActivities(
@QueryParam("timestamp") String timestamp) {
List<Activity> activities = null;
DeviceManagementProviderService dmService;
try {
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
activities = dmService.getActivitiesUpdatedAfter(Long.parseLong(timestamp));
} catch (OperationManagementException e) {
String msg = "Error occurred while fetching the activities updated after given time stamp.";
log.error(msg, e);
Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(activities).build();
}
} }

@ -82,6 +82,26 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
} }
} }
@GET
@Path("{type}/{id}/info")
public Response getDeviceInfo(@PathParam("type") String type, @PathParam("id") String id,
@HeaderParam("If-Modified-Since") String timestamp) {
DeviceInformationManager informationManager;
DeviceInfo deviceInfo;
try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(id);
deviceIdentifier.setType(type);
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceInfo = informationManager.getDeviceInfo(deviceIdentifier);
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device information.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(deviceInfo).build();
}
@POST @POST
@Override @Override
public Response getDevicesInfo( public Response getDevicesInfo(
@ -152,6 +172,23 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
return Response.status(Response.Status.OK).entity(deviceLocation).build(); return Response.status(Response.Status.OK).entity(deviceLocation).build();
} }
@POST
@Path("/locations")
public Response getDeviceLocations(List<DeviceIdentifier> deviceIdentifiers,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
DeviceInformationManager informationManager;
List<DeviceLocation> deviceLocations;
try {
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceLocations = informationManager.getDeviceLocations(deviceIdentifiers);
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device location.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(deviceLocations).build();
}
@GET @GET
@Path("/{type}/{id}/features") @Path("/{type}/{id}/features")
@Override @Override
@ -180,7 +217,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService{
@POST @POST
@Path("/search-devices") @Path("/search-devices")
@Override @Override
public Response searchDevices(@QueryParam("offset") int offset, int limit, SearchContext searchContext) { public Response searchDevices(@QueryParam("offset") int offset, @QueryParam("limit") int limit, SearchContext searchContext) {
SearchManagerService searchManagerService; SearchManagerService searchManagerService;
List<DeviceWrapper> devices; List<DeviceWrapper> devices;
try { try {

@ -72,6 +72,14 @@ public interface DeviceInformationManager {
*/ */
DeviceLocation getDeviceLocation(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException; DeviceLocation getDeviceLocation(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException;
/**
* This method will return the device location with latitude, longitude, address etc.. of supplied devices.
* @param deviceIdentifiers - List of Device identifier and device type.
* @return Device Location list.
* @throws DeviceDetailsMgtException
*/
List<DeviceLocation> getDeviceLocations(List<DeviceIdentifier> deviceIdentifiers) throws DeviceDetailsMgtException;
// /** // /**
// * This method will manage the storing of device application list. // * This method will manage the storing of device application list.
// * @param deviceApplication - Device application list. // * @param deviceApplication - Device application list.

@ -183,5 +183,26 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
} }
} }
@Override
public List<DeviceLocation> getDeviceLocations(List<DeviceIdentifier> deviceIdentifiers) throws DeviceDetailsMgtException {
try {
List<Device> devices = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getAllDevices(deviceIdentifiers.get(0).getType());
List<DeviceLocation> deviceLocations = new ArrayList<>();
DeviceManagementDAOFactory.openConnection();
for (Device device : devices) {
deviceLocations.add(deviceDetailsDAO.getDeviceLocation(device.getId()));
}
return deviceLocations;
} catch (DeviceManagementException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving the devices.", e);
} catch (SQLException e) {
throw new DeviceDetailsMgtException("SQL error occurred while retrieving device from database.", e);
} catch (DeviceDetailsMgtDAOException e) {
throw new DeviceDetailsMgtException("Exception occurred while retrieving device locations.", e);
}
}
} }

Loading…
Cancel
Save