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