|
|
|
@ -20,12 +20,7 @@ package org.wso2.carbon.device.mgt.iot.api;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.*;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
@ -33,56 +28,20 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord;
|
|
|
|
|
|
|
|
|
|
import javax.jws.WebService;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import javax.ws.rs.Consumes;
|
|
|
|
|
import javax.ws.rs.DELETE;
|
|
|
|
|
import javax.ws.rs.FormParam;
|
|
|
|
|
import javax.ws.rs.GET;
|
|
|
|
|
import javax.ws.rs.HeaderParam;
|
|
|
|
|
import javax.ws.rs.POST;
|
|
|
|
|
import javax.ws.rs.PUT;
|
|
|
|
|
import javax.ws.rs.Path;
|
|
|
|
|
import javax.ws.rs.PathParam;
|
|
|
|
|
import javax.ws.rs.Produces;
|
|
|
|
|
import javax.ws.rs.QueryParam;
|
|
|
|
|
import javax.ws.rs.core.Context;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.util.APIUtil;
|
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@WebService public class DevicesManagerService {
|
|
|
|
|
|
|
|
|
|
private static Log log = LogFactory.getLog(DevicesManagerService.class);
|
|
|
|
|
|
|
|
|
|
@Context //injected response proxy supporting multiple thread
|
|
|
|
|
private HttpServletResponse response;
|
|
|
|
|
|
|
|
|
|
private PrivilegedCarbonContext ctx;
|
|
|
|
|
|
|
|
|
|
private DeviceManagementProviderService getServiceProvider() {
|
|
|
|
|
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
|
ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
|
|
ctx.setTenantDomain(tenantDomain, true);
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Getting thread local carbon context for tenant domain: " + tenantDomain);
|
|
|
|
|
}
|
|
|
|
|
return (DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null);
|
|
|
|
|
}
|
|
|
|
|
public class DevicesManagerService {
|
|
|
|
|
|
|
|
|
|
private void endTenantFlow() {
|
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
|
ctx = null;
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Tenant flow ended");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private static final Log log = LogFactory.getLog(DevicesManagerService.class);
|
|
|
|
|
|
|
|
|
|
private Device[] getActiveDevices(List<Device> devices){
|
|
|
|
|
private Device[] getActiveDevices(List<Device> devices) {
|
|
|
|
|
List<Device> activeDevices = new ArrayList<>();
|
|
|
|
|
if (devices != null) {
|
|
|
|
|
for (Device device : devices) {
|
|
|
|
@ -94,29 +53,27 @@ import java.util.List;
|
|
|
|
|
return activeDevices.toArray(new Device[activeDevices.size()]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/user/{username}/all")
|
|
|
|
|
@Path("/devices/users/{userName}")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public Device[] getDevicesOfUser(@PathParam("username") String username) {
|
|
|
|
|
public Response getDevicesOfUser(@PathParam("userName") String userName) {
|
|
|
|
|
try {
|
|
|
|
|
List<Device> devices = this.getServiceProvider().getDevicesOfUser(username);
|
|
|
|
|
return this.getActiveDevices(devices);
|
|
|
|
|
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
|
|
|
.getDevicesOfUser(userName);
|
|
|
|
|
Device[] devicesArr = this.getActiveDevices(devices);
|
|
|
|
|
return Response.status(Response.Status.OK).entity(devicesArr).build();
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/user/{username}/all/count")
|
|
|
|
|
@Path("/devices/users/{userName}/count")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public int getDeviceCount(@PathParam("username") String username){
|
|
|
|
|
public Response getDeviceCount(@PathParam("userName") String userName) {
|
|
|
|
|
try {
|
|
|
|
|
List<Device> devices = this.getServiceProvider().getDevicesOfUser(username);
|
|
|
|
|
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
|
|
|
.getDevicesOfUser(userName);
|
|
|
|
|
if (devices != null) {
|
|
|
|
|
List<Device> activeDevices = new ArrayList<>();
|
|
|
|
|
for (Device device : devices) {
|
|
|
|
@ -124,191 +81,182 @@ import java.util.List;
|
|
|
|
|
activeDevices.add(device);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return activeDevices.size();
|
|
|
|
|
return Response.status(Response.Status.OK).entity(activeDevices.size()).build();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return 0;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/identifier/{identifier}")
|
|
|
|
|
@Path("/devices/{deviceType}/{identifier}")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public Device getDevice(@PathParam("type") String type, @PathParam("identifier") String identifier){
|
|
|
|
|
public Response getDevice(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@PathParam("identifier") String identifier) {
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
try {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setId(identifier);
|
|
|
|
|
deviceIdentifier.setType(type);
|
|
|
|
|
return this.getServiceProvider().getDevice(deviceIdentifier);
|
|
|
|
|
deviceIdentifier.setType(deviceType);
|
|
|
|
|
Device device = APIUtil.getDeviceManagementService().getDevice(
|
|
|
|
|
deviceIdentifier);
|
|
|
|
|
if (device != null) {
|
|
|
|
|
return Response.status(Response.Status.OK).entity(device).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/all")
|
|
|
|
|
@Path("/devices/types")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public DeviceType[] getDeviceTypes(){
|
|
|
|
|
try{
|
|
|
|
|
List<DeviceType> deviceTypes = this.getServiceProvider().getAvailableDeviceTypes();
|
|
|
|
|
return deviceTypes.toArray(new DeviceType[deviceTypes.size()]);
|
|
|
|
|
public Response getDeviceTypes() {
|
|
|
|
|
try {
|
|
|
|
|
List<DeviceType> deviceTypes = APIUtil.getDeviceManagementService()
|
|
|
|
|
.getAvailableDeviceTypes();
|
|
|
|
|
DeviceType[] deviceTypesArr = deviceTypes.toArray(new DeviceType[deviceTypes.size()]);
|
|
|
|
|
return Response.status(Response.Status.OK).entity(deviceTypesArr).build();
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/all")
|
|
|
|
|
@Path("/devices/{deviceType}")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public Device[] getAllDevices(@PathParam("type") String type){
|
|
|
|
|
try{
|
|
|
|
|
List<Device> devices = this.getServiceProvider().getAllDevices(type);
|
|
|
|
|
return this.getActiveDevices(devices);
|
|
|
|
|
public Response getAllDevices(@PathParam("deviceType") String deviceType) {
|
|
|
|
|
try {
|
|
|
|
|
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
|
|
|
.getAllDevices(deviceType);
|
|
|
|
|
Device[] devicesArr = this.getActiveDevices(devices);
|
|
|
|
|
return Response.status(Response.Status.OK).entity(devicesArr).build();
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/all")
|
|
|
|
|
@Path("/devices")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public Device[] getAllDevices(){
|
|
|
|
|
try{
|
|
|
|
|
List<Device> devices = this.getServiceProvider().getAllDevices();
|
|
|
|
|
return this.getActiveDevices(devices);
|
|
|
|
|
public Response getAllDevices() {
|
|
|
|
|
try {
|
|
|
|
|
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
|
|
|
.getAllDevices();
|
|
|
|
|
return Response.status(Response.Status.OK).entity(this.getActiveDevices(devices)).build();
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/config")
|
|
|
|
|
@Path("/devices/{deviceType}/config")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public TenantConfiguration getConfiguration(@PathParam("type") String type){
|
|
|
|
|
public Response getConfiguration(@PathParam("deviceType") String deviceType) {
|
|
|
|
|
try {
|
|
|
|
|
return this.getServiceProvider().getConfiguration(type);
|
|
|
|
|
TenantConfiguration tenantConfiguration = APIUtil.getDeviceManagementService().getConfiguration(deviceType);
|
|
|
|
|
if (tenantConfiguration != null) {
|
|
|
|
|
return Response.status(Response.Status.OK).entity(tenantConfiguration).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/role/{role}/all")
|
|
|
|
|
@Path("/devices/search/role")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public Device[] getAllDevicesOfRole(@PathParam("role") String roleName){
|
|
|
|
|
try{
|
|
|
|
|
List<Device> devices = this.getServiceProvider().getAllDevicesOfRole(roleName);
|
|
|
|
|
return this.getActiveDevices(devices);
|
|
|
|
|
public Response getAllDevicesOfRole(@QueryParam("roleName") String roleName) {
|
|
|
|
|
try {
|
|
|
|
|
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
|
|
|
.getAllDevicesOfRole(roleName);
|
|
|
|
|
Device[] devicesArr = this.getActiveDevices(devices);
|
|
|
|
|
return Response.status(Response.Status.OK).entity(devicesArr).build();
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/name/{name}/all")
|
|
|
|
|
@Path("/devices/search/name")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public Device[] getDevicesByName(@PathParam("name") String name) {
|
|
|
|
|
try{
|
|
|
|
|
List<Device> devices = this.getServiceProvider().getDevicesByName(name);
|
|
|
|
|
return this.getActiveDevices(devices);
|
|
|
|
|
public Response getDevicesByName(@PathParam("deviceName") String deviceName) {
|
|
|
|
|
try {
|
|
|
|
|
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
|
|
|
.getDevicesByName(deviceName);
|
|
|
|
|
Device[] devicesArr = this.getActiveDevices(devices);
|
|
|
|
|
return Response.status(Response.Status.OK).entity(devicesArr).build();
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/identifier/{identifier}/status")
|
|
|
|
|
@Path("/devices/{deviceType}/{identifier}/status")
|
|
|
|
|
@PUT
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
void updateDeviceEnrolmentInfo(@PathParam("type") String type, @PathParam("identifier") String identifier,
|
|
|
|
|
@FormParam("status") EnrolmentInfo.Status status) {
|
|
|
|
|
DeviceManagementProviderService providerService = this.getServiceProvider();
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setType(type);
|
|
|
|
|
deviceIdentifier.setId(identifier);
|
|
|
|
|
public Response updateDeviceEnrolmentInfo(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@PathParam("identifier") String identifier,
|
|
|
|
|
@FormParam("status") EnrolmentInfo.Status status) {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementProviderService providerService = APIUtil.getDeviceManagementService();
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setType(deviceType);
|
|
|
|
|
deviceIdentifier.setId(identifier);
|
|
|
|
|
Device device = providerService.getDevice(deviceIdentifier);
|
|
|
|
|
providerService.updateDeviceEnrolmentInfo(device, status);
|
|
|
|
|
return Response.status(Response.Status.NO_CONTENT).build();
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/status/{status}/all")
|
|
|
|
|
@Path("/devices/search/status")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public Device[] getDevicesByStatus(@PathParam("status") EnrolmentInfo.Status status) {
|
|
|
|
|
try{
|
|
|
|
|
List<Device> devices = this.getServiceProvider().getDevicesByStatus(status);
|
|
|
|
|
return this.getActiveDevices(devices);
|
|
|
|
|
public Response getDevicesByStatus(@QueryParam("status") EnrolmentInfo.Status status) {
|
|
|
|
|
try {
|
|
|
|
|
List<Device> devices = APIUtil.getDeviceManagementService()
|
|
|
|
|
.getDevicesByStatus(status);
|
|
|
|
|
Device[] devicesArr = this.getActiveDevices(devices);
|
|
|
|
|
return Response.status(Response.Status.OK).entity(devicesArr).build();
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/license")
|
|
|
|
|
@Path("/devices/{deviceType}/license")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public License getLicense(@PathParam("type") String type, @QueryParam("languageCode") String languageCode) {
|
|
|
|
|
try{
|
|
|
|
|
return this.getServiceProvider().getLicense(type, languageCode);
|
|
|
|
|
public Response getLicense(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@QueryParam("languageCode") String languageCode) {
|
|
|
|
|
try {
|
|
|
|
|
License license = APIUtil.getDeviceManagementService().getLicense(
|
|
|
|
|
deviceType, languageCode);
|
|
|
|
|
if (license != null) {
|
|
|
|
|
return Response.status(Response.Status.OK).entity(license).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/license")
|
|
|
|
|
@Path("/devices/{deviceType}/license")
|
|
|
|
|
@POST
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public void addLicense(@PathParam("type") String type, @FormParam("provider") String provider,
|
|
|
|
|
@FormParam("name") String name, @FormParam("version") String version,
|
|
|
|
|
@FormParam("language") String language, @FormParam("validFrom") Date validFrom,
|
|
|
|
|
@FormParam("validTo") Date validTo, @FormParam("text") String text) {
|
|
|
|
|
try{
|
|
|
|
|
public Response addLicense(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@FormParam("provider") String provider, @FormParam("name") String name,
|
|
|
|
|
@FormParam("version") String version, @FormParam("language") String language,
|
|
|
|
|
@FormParam("validFrom") Date validFrom, @FormParam("validTo") Date validTo,
|
|
|
|
|
@FormParam("text") String text) {
|
|
|
|
|
try {
|
|
|
|
|
License license = new License();
|
|
|
|
|
license.setProvider(provider);
|
|
|
|
|
license.setName(name);
|
|
|
|
@ -317,26 +265,27 @@ import java.util.List;
|
|
|
|
|
license.setValidFrom(validFrom);
|
|
|
|
|
license.setValidTo(validTo);
|
|
|
|
|
license.setText(text);
|
|
|
|
|
this.getServiceProvider().addLicense(type, license);
|
|
|
|
|
APIUtil.getDeviceManagementService().addLicense(deviceType, license);
|
|
|
|
|
return Response.status(Response.Status.NO_CONTENT).build();
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/identifier/{identifier}")
|
|
|
|
|
@Path("/devices/{deviceType}/{identifier}/enrollment")
|
|
|
|
|
@PUT
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
boolean modifyEnrollment(@PathParam("type") String type, @PathParam("identifier") String identifier,
|
|
|
|
|
@FormParam("name") String name, @FormParam("description") String description,
|
|
|
|
|
@FormParam("enrollmentId") int enrollmentId,
|
|
|
|
|
@FormParam("dateOfEnrolment") long dateOfEnrolment,
|
|
|
|
|
@FormParam("dateOfLastUpdate") long dateOfLastUpdate,
|
|
|
|
|
@FormParam("ownership") EnrolmentInfo.OwnerShip ownership,
|
|
|
|
|
@FormParam("status") EnrolmentInfo.Status status,
|
|
|
|
|
@FormParam("owner") String owner) {
|
|
|
|
|
public Response modifyEnrollment(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@PathParam("identifier") String identifier,
|
|
|
|
|
@FormParam("name") String name,
|
|
|
|
|
@FormParam("description") String description,
|
|
|
|
|
@FormParam("groupId") int groupId,
|
|
|
|
|
@FormParam("enrollmentId") int enrollmentId,
|
|
|
|
|
@FormParam("dateOfEnrolment") long dateOfEnrolment,
|
|
|
|
|
@FormParam("dateOfLastUpdate") long dateOfLastUpdate,
|
|
|
|
|
@FormParam("ownership") EnrolmentInfo.OwnerShip ownership,
|
|
|
|
|
@FormParam("status") EnrolmentInfo.Status status,
|
|
|
|
|
@FormParam("owner") String owner) {
|
|
|
|
|
|
|
|
|
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
|
|
|
|
enrolmentInfo.setId(enrollmentId);
|
|
|
|
@ -347,33 +296,36 @@ import java.util.List;
|
|
|
|
|
enrolmentInfo.setOwner(owner);
|
|
|
|
|
|
|
|
|
|
Device device = new Device();
|
|
|
|
|
device.setType(type);
|
|
|
|
|
device.setType(deviceType);
|
|
|
|
|
device.setDeviceIdentifier(identifier);
|
|
|
|
|
device.setName(name);
|
|
|
|
|
device.setDescription(description);
|
|
|
|
|
device.setEnrolmentInfo(enrolmentInfo);
|
|
|
|
|
try {
|
|
|
|
|
return this.getServiceProvider().modifyEnrollment(device);
|
|
|
|
|
boolean isModified = APIUtil.getDeviceManagementService()
|
|
|
|
|
.modifyEnrollment(device);
|
|
|
|
|
if (isModified) {
|
|
|
|
|
return Response.status(Response.Status.NO_CONTENT).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return false;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device")
|
|
|
|
|
@Path("/devices/{deviceType}/{identifier}/enrollment")
|
|
|
|
|
@POST
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
boolean enrollDevice(@FormParam("type") String type, @FormParam("identifier") String identifier,
|
|
|
|
|
@FormParam("name") String name, @FormParam("description") String description,
|
|
|
|
|
@FormParam("enrollmentId") int enrollmentId,
|
|
|
|
|
@FormParam("dateOfEnrolment") long dateOfEnrolment,
|
|
|
|
|
@FormParam("dateOfLastUpdate") long dateOfLastUpdate,
|
|
|
|
|
@FormParam("ownership") EnrolmentInfo.OwnerShip ownership,
|
|
|
|
|
@FormParam("status") EnrolmentInfo.Status status,
|
|
|
|
|
@FormParam("owner") String owner) {
|
|
|
|
|
public Response enrollDevice(@PathParam("deviceType") String deviceType, @PathParam("identifier") String identifier,
|
|
|
|
|
@FormParam("name") String name, @FormParam("description") String description,
|
|
|
|
|
@FormParam("groupId") int groupId,
|
|
|
|
|
@FormParam("enrollmentId") int enrollmentId,
|
|
|
|
|
@FormParam("dateOfEnrolment") long dateOfEnrolment,
|
|
|
|
|
@FormParam("dateOfLastUpdate") long dateOfLastUpdate,
|
|
|
|
|
@FormParam("ownership") EnrolmentInfo.OwnerShip ownership,
|
|
|
|
|
@FormParam("status") EnrolmentInfo.Status status,
|
|
|
|
|
@FormParam("owner") String owner) {
|
|
|
|
|
|
|
|
|
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
|
|
|
|
enrolmentInfo.setId(enrollmentId);
|
|
|
|
@ -384,197 +336,232 @@ import java.util.List;
|
|
|
|
|
enrolmentInfo.setOwner(owner);
|
|
|
|
|
|
|
|
|
|
Device device = new Device();
|
|
|
|
|
device.setType(type);
|
|
|
|
|
device.setType(deviceType);
|
|
|
|
|
device.setDeviceIdentifier(identifier);
|
|
|
|
|
device.setName(name);
|
|
|
|
|
device.setDescription(description);
|
|
|
|
|
device.setEnrolmentInfo(enrolmentInfo);
|
|
|
|
|
try {
|
|
|
|
|
return this.getServiceProvider().enrollDevice(device);
|
|
|
|
|
boolean isModified = APIUtil.getDeviceManagementService().enrollDevice(
|
|
|
|
|
device);
|
|
|
|
|
if (isModified) {
|
|
|
|
|
return Response.status(Response.Status.NO_CONTENT).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return false;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/tenantconfiguration")
|
|
|
|
|
@Path("/devices/tenant/configuration")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public TenantConfiguration getConfiguration(){
|
|
|
|
|
public Response getTenantConfiguration() {
|
|
|
|
|
try {
|
|
|
|
|
return this.getServiceProvider().getConfiguration();
|
|
|
|
|
TenantConfiguration tenantConfiguration = APIUtil.getDeviceManagementService().getConfiguration();
|
|
|
|
|
if (tenantConfiguration != null) {
|
|
|
|
|
return Response.status(Response.Status.OK).entity(tenantConfiguration).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/tenantconfiguration")
|
|
|
|
|
@Path("/devices/tenant/configuration")
|
|
|
|
|
@POST
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public boolean saveConfiguration(@FormParam("tenantConfiguration") TenantConfiguration tenantConfiguration){
|
|
|
|
|
public Response saveTenantConfiguration(@FormParam("tenantConfiguration") TenantConfiguration tenantConfiguration) {
|
|
|
|
|
try {
|
|
|
|
|
return this.getServiceProvider().saveConfiguration(tenantConfiguration);
|
|
|
|
|
boolean isSaved = APIUtil.getDeviceManagementService()
|
|
|
|
|
.saveConfiguration(tenantConfiguration);
|
|
|
|
|
if (isSaved) {
|
|
|
|
|
return Response.status(Response.Status.NO_CONTENT).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return false;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/identifier/{identifier}")
|
|
|
|
|
@Path("/devices/{deviceType}/{identifier}")
|
|
|
|
|
@DELETE
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public boolean disenrollDevice(@PathParam("type") String type, @PathParam("identifier") String identifier){
|
|
|
|
|
public Response disenrollDevice(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@PathParam("identifier") String identifier) {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setType(type);
|
|
|
|
|
deviceIdentifier.setType(deviceType);
|
|
|
|
|
deviceIdentifier.setId(identifier);
|
|
|
|
|
try {
|
|
|
|
|
return this.getServiceProvider().disenrollDevice(deviceIdentifier);
|
|
|
|
|
boolean isDisEnrolled = APIUtil.getDeviceManagementService()
|
|
|
|
|
.disenrollDevice(deviceIdentifier);
|
|
|
|
|
if (isDisEnrolled) {
|
|
|
|
|
return Response.status(Response.Status.NO_CONTENT).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return false;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/identifier/{identifier}/enrolled")
|
|
|
|
|
@Path("/devices/{deviceType}/{identifier}/enrollment")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public boolean isEnrolled(@PathParam("type") String type, @PathParam("identifier") String identifier){
|
|
|
|
|
public Response isEnrolled(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@PathParam("identifier") String identifier) {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setType(type);
|
|
|
|
|
deviceIdentifier.setType(deviceType);
|
|
|
|
|
deviceIdentifier.setId(identifier);
|
|
|
|
|
try {
|
|
|
|
|
return this.getServiceProvider().isEnrolled(deviceIdentifier);
|
|
|
|
|
boolean isEnrolled = APIUtil.getDeviceManagementService().isEnrolled(
|
|
|
|
|
deviceIdentifier);
|
|
|
|
|
if (isEnrolled) {
|
|
|
|
|
return Response.status(Response.Status.NO_CONTENT).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return false;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@Path("/device/type/{type}/identifier/{identifier}/active")
|
|
|
|
|
|
|
|
|
|
@Path("/devices/{deviceType}/{identifier}/status")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public boolean isActive(@PathParam("type") String type, @PathParam("identifier") String identifier){
|
|
|
|
|
public Response isActive(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@PathParam("identifier") String identifier) {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setType(type);
|
|
|
|
|
deviceIdentifier.setType(deviceType);
|
|
|
|
|
deviceIdentifier.setId(identifier);
|
|
|
|
|
try {
|
|
|
|
|
return this.getServiceProvider().isActive(deviceIdentifier);
|
|
|
|
|
boolean isActive = APIUtil.getDeviceManagementService().isActive(
|
|
|
|
|
deviceIdentifier);
|
|
|
|
|
if (isActive) {
|
|
|
|
|
return Response.status(Response.Status.NO_CONTENT).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return false;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/identifier/{identifier}/active")
|
|
|
|
|
@Path("/devices/{deviceType}/{identifier}/status")
|
|
|
|
|
@PUT
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public boolean setActive(@PathParam("type") String type, @PathParam("identifier") String identifier,
|
|
|
|
|
@FormParam("status") boolean status){
|
|
|
|
|
public Response changeDeviceStatus(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@PathParam("identifier") String identifier,
|
|
|
|
|
@FormParam("status") boolean status) {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setType(type);
|
|
|
|
|
deviceIdentifier.setType(deviceType);
|
|
|
|
|
deviceIdentifier.setId(identifier);
|
|
|
|
|
try {
|
|
|
|
|
return this.getServiceProvider().setActive(deviceIdentifier, status);
|
|
|
|
|
boolean isActivated = APIUtil.getDeviceManagementService().setActive(
|
|
|
|
|
deviceIdentifier, status);
|
|
|
|
|
if (isActivated) {
|
|
|
|
|
return Response.status(Response.Status.NO_CONTENT).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return false;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/identifier/{identifier}/ownership")
|
|
|
|
|
@Path("/devices/{deviceType}/{identifier}/ownership")
|
|
|
|
|
@PUT
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public boolean setOwnership(@PathParam("type") String type, @PathParam("identifier") String identifier,
|
|
|
|
|
@FormParam("ownership") String ownership){
|
|
|
|
|
public Response setOwnership(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@PathParam("identifier") String identifier,
|
|
|
|
|
@FormParam("ownership") String ownership) {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setType(type);
|
|
|
|
|
deviceIdentifier.setType(deviceType);
|
|
|
|
|
deviceIdentifier.setId(identifier);
|
|
|
|
|
try {
|
|
|
|
|
return this.getServiceProvider().setOwnership(deviceIdentifier, ownership);
|
|
|
|
|
boolean isOwnershipChanged = APIUtil.getDeviceManagementService()
|
|
|
|
|
.setOwnership(deviceIdentifier, ownership);
|
|
|
|
|
if (isOwnershipChanged) {
|
|
|
|
|
return Response.status(Response.Status.NO_CONTENT).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return false;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/identifier/{identifier}/status")
|
|
|
|
|
@Path("/devices/{deviceType}/{identifier}/enrollment/status")
|
|
|
|
|
@PUT
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public boolean setStatus(@PathParam("type") String type, @PathParam("identifier") String identifier,
|
|
|
|
|
@FormParam("owner") String owner, @FormParam("status") EnrolmentInfo.Status status){
|
|
|
|
|
public Response setStatus(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@PathParam("identifier") String identifier, @FormParam("owner") String owner,
|
|
|
|
|
@FormParam("status") EnrolmentInfo.Status status) {
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
deviceIdentifier.setType(type);
|
|
|
|
|
deviceIdentifier.setType(deviceType);
|
|
|
|
|
deviceIdentifier.setId(identifier);
|
|
|
|
|
try {
|
|
|
|
|
return this.getServiceProvider().setStatus(deviceIdentifier, owner, status);
|
|
|
|
|
boolean isStatusChanged = APIUtil.getDeviceManagementService()
|
|
|
|
|
.setStatus(deviceIdentifier, owner, status);
|
|
|
|
|
if (isStatusChanged) {
|
|
|
|
|
return Response.status(Response.Status.NO_CONTENT).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return false;
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/identifier/{identifier}/sensor/{sensorName}")
|
|
|
|
|
@Path("/devices/{deviceType}/{identifier}/sensors/{sensorName}")
|
|
|
|
|
@POST
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public boolean setSensorValue(@PathParam("type") String type, @PathParam("identifier") String deviceId,
|
|
|
|
|
@PathParam("sensorName") String sensorName,
|
|
|
|
|
@HeaderParam("sensorValue") String sensorValue){
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return SensorDataManager.getInstance().setSensorRecord(deviceId, sensorName, sensorValue, Calendar
|
|
|
|
|
.getInstance().getTimeInMillis());
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
public Response setSensorValue(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@PathParam("identifier") String deviceId,
|
|
|
|
|
@PathParam("sensorName") String sensorName,
|
|
|
|
|
@FormParam("sensorValue") String sensorValue) {
|
|
|
|
|
boolean isValueSet = SensorDataManager.getInstance().setSensorRecord(deviceId, sensorName,
|
|
|
|
|
sensorValue, Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
if (isValueSet) {
|
|
|
|
|
return Response.status(Response.Status.NO_CONTENT).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("/device/type/{type}/identifier/{identifier}/sensor/{sensorName}")
|
|
|
|
|
@Path("/devices/{deviceType}/{identifier}/sensors/{sensorName}")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public SensorRecord getSensorValue(@PathParam("type") String type, @PathParam("identifier") String deviceId,
|
|
|
|
|
@PathParam("sensorName") String sensorName, @HeaderParam("defaultValue") String defaultValue){
|
|
|
|
|
public Response getSensorValue(@PathParam("deviceType") String deviceType,
|
|
|
|
|
@PathParam("identifier") String deviceId,
|
|
|
|
|
@PathParam("sensorName") String sensorName,
|
|
|
|
|
@QueryParam("defaultValue") String defaultValue) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return SensorDataManager.getInstance().getSensorRecord(deviceId, sensorName);
|
|
|
|
|
SensorRecord sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, sensorName);
|
|
|
|
|
if (sensorRecord != null) {
|
|
|
|
|
return Response.status(Response.Status.OK).entity(sensorRecord).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceControllerException e) {
|
|
|
|
|
log.error("Error on reading sensor value: " + e.getMessage());
|
|
|
|
|
if(defaultValue != null){
|
|
|
|
|
return new SensorRecord(defaultValue, Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
}else{
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
return null;
|
|
|
|
|
if (defaultValue != null) {
|
|
|
|
|
SensorRecord sensorRecord = new SensorRecord(defaultValue,
|
|
|
|
|
Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
return Response.status(Response.Status.OK).entity(sensorRecord).build();
|
|
|
|
|
} else {
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
this.endTenantFlow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|