mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
JAX-RS Refractor
This commit is contained in:
parent
69c730d147
commit
37a47ec347
@ -15,8 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.common;
|
package org.wso2.carbon.device.mgt.common;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@XmlRootElement
|
||||||
public class Device {
|
public class Device {
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
@ -45,6 +47,7 @@ public class Device {
|
|||||||
|
|
||||||
private List<Property> properties;
|
private List<Property> properties;
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -52,7 +55,7 @@ public class Device {
|
|||||||
public void setId(int id) {
|
public void setId(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
@XmlElement
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
@ -60,7 +63,7 @@ public class Device {
|
|||||||
public void setDescription(String description) {
|
public void setDescription(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
@XmlElement
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -68,7 +71,7 @@ public class Device {
|
|||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
@XmlElement
|
||||||
public Long getDateOfEnrolment() {
|
public Long getDateOfEnrolment() {
|
||||||
return dateOfEnrolment;
|
return dateOfEnrolment;
|
||||||
}
|
}
|
||||||
@ -76,7 +79,7 @@ public class Device {
|
|||||||
public void setDateOfEnrolment(Long dateOfEnrolment) {
|
public void setDateOfEnrolment(Long dateOfEnrolment) {
|
||||||
this.dateOfEnrolment = dateOfEnrolment;
|
this.dateOfEnrolment = dateOfEnrolment;
|
||||||
}
|
}
|
||||||
|
@XmlElement
|
||||||
public Long getDateOfLastUpdate() {
|
public Long getDateOfLastUpdate() {
|
||||||
return dateOfLastUpdate;
|
return dateOfLastUpdate;
|
||||||
}
|
}
|
||||||
@ -84,7 +87,7 @@ public class Device {
|
|||||||
public void setDateOfLastUpdate(Long dateOfLastUpdate) {
|
public void setDateOfLastUpdate(Long dateOfLastUpdate) {
|
||||||
this.dateOfLastUpdate = dateOfLastUpdate;
|
this.dateOfLastUpdate = dateOfLastUpdate;
|
||||||
}
|
}
|
||||||
|
@XmlElement
|
||||||
public String getOwnership() {
|
public String getOwnership() {
|
||||||
return ownership;
|
return ownership;
|
||||||
}
|
}
|
||||||
@ -92,7 +95,7 @@ public class Device {
|
|||||||
public void setOwnership(String ownership) {
|
public void setOwnership(String ownership) {
|
||||||
this.ownership = ownership;
|
this.ownership = ownership;
|
||||||
}
|
}
|
||||||
|
@XmlElement
|
||||||
public boolean isStatus() {
|
public boolean isStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -100,7 +103,7 @@ public class Device {
|
|||||||
public void setStatus(boolean status) {
|
public void setStatus(boolean status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
@XmlElement
|
||||||
public int getDeviceTypeId() {
|
public int getDeviceTypeId() {
|
||||||
return deviceTypeId;
|
return deviceTypeId;
|
||||||
}
|
}
|
||||||
@ -108,7 +111,7 @@ public class Device {
|
|||||||
public void setDeviceTypeId(int deviceTypeId) {
|
public void setDeviceTypeId(int deviceTypeId) {
|
||||||
this.deviceTypeId = deviceTypeId;
|
this.deviceTypeId = deviceTypeId;
|
||||||
}
|
}
|
||||||
|
@XmlElement
|
||||||
public String getDeviceIdentifier() {
|
public String getDeviceIdentifier() {
|
||||||
return deviceIdentifier;
|
return deviceIdentifier;
|
||||||
}
|
}
|
||||||
@ -116,7 +119,7 @@ public class Device {
|
|||||||
public void setDeviceIdentifier(String deviceIdentifier) {
|
public void setDeviceIdentifier(String deviceIdentifier) {
|
||||||
this.deviceIdentifier = deviceIdentifier;
|
this.deviceIdentifier = deviceIdentifier;
|
||||||
}
|
}
|
||||||
|
@XmlElement
|
||||||
public String getOwner() {
|
public String getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
@ -124,7 +127,7 @@ public class Device {
|
|||||||
public void setOwner(String owner) {
|
public void setOwner(String owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
|
@XmlElement
|
||||||
public List<Feature> getFeatures() {
|
public List<Feature> getFeatures() {
|
||||||
return features;
|
return features;
|
||||||
}
|
}
|
||||||
@ -132,7 +135,7 @@ public class Device {
|
|||||||
public void setFeatures(List<Feature> features) {
|
public void setFeatures(List<Feature> features) {
|
||||||
this.features = features;
|
this.features = features;
|
||||||
}
|
}
|
||||||
|
@XmlElement
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@ -140,7 +143,7 @@ public class Device {
|
|||||||
public void setType(String type) {
|
public void setType(String type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
@XmlElement
|
||||||
public List<Property> getProperties() {
|
public List<Property> getProperties() {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,7 +109,12 @@ public final class DeviceManagementDAOUtil {
|
|||||||
deviceBO.setName(device.getName());
|
deviceBO.setName(device.getName());
|
||||||
deviceBO.setDateOfEnrollment(device.getDateOfEnrolment());
|
deviceBO.setDateOfEnrollment(device.getDateOfEnrolment());
|
||||||
deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate());
|
deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate());
|
||||||
deviceBO.setStatus(Status.valueOf(String.valueOf(device.isStatus())));
|
|
||||||
|
if (!device.isStatus()){
|
||||||
|
deviceBO.setStatus(Status.INACTIVE);
|
||||||
|
}else{
|
||||||
|
deviceBO.setStatus(Status.ACTIVE);
|
||||||
|
}
|
||||||
deviceBO.setOwnerId(device.getOwner());
|
deviceBO.setOwnerId(device.getOwner());
|
||||||
deviceBO.setOwnerShip(device.getOwnership());
|
deviceBO.setOwnerShip(device.getOwnership());
|
||||||
deviceBO.setTenantId(DeviceManagementDAOUtil.getTenantId());
|
deviceBO.setTenantId(DeviceManagementDAOUtil.getTenantId());
|
||||||
|
|||||||
@ -41,7 +41,7 @@ import org.wso2.carbon.user.core.service.RealmService;
|
|||||||
* unbind="unsetRealmService"
|
* unbind="unsetRealmService"
|
||||||
* @scr.reference name="device.manager.service"
|
* @scr.reference name="device.manager.service"
|
||||||
* interface="org.wso2.carbon.device.mgt.common.spi.DeviceManagerService"
|
* interface="org.wso2.carbon.device.mgt.common.spi.DeviceManagerService"
|
||||||
* cardinality="1..n"
|
* cardinality="0..n"
|
||||||
* policy="dynamic"
|
* policy="dynamic"
|
||||||
* bind="setDeviceManagerService"
|
* bind="setDeviceManagerService"
|
||||||
* unbind="unsetDeviceManagerService"
|
* unbind="unsetDeviceManagerService"
|
||||||
|
|||||||
@ -144,11 +144,6 @@
|
|||||||
<version>1.1.1</version>
|
<version>1.1.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.code.gson</groupId>
|
|
||||||
<artifactId>gson</artifactId>
|
|
||||||
<version>2.2.4</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon</groupId>
|
<groupId>org.wso2.carbon</groupId>
|
||||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||||
@ -171,6 +166,11 @@
|
|||||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
|
<artifactId>jackson-jaxrs</artifactId>
|
||||||
|
<version>1.1.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<cxf.version>2.6.1</cxf.version>
|
<cxf.version>2.6.1</cxf.version>
|
||||||
|
|||||||
@ -18,18 +18,15 @@ package cdm.api.android;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.FormParam;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
|
|
||||||
|
@Produces({ "application/json", "application/xml" })
|
||||||
|
@Consumes({ "application/json", "application/xml" })
|
||||||
@Path("/authenticate/")
|
@Path("/authenticate/")
|
||||||
public class Authentication {
|
public class Authentication {
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/device/")
|
@Path("/device/")
|
||||||
@Produces("application/json")
|
|
||||||
public String authenticateDevice(@FormParam("username") String username,
|
public String authenticateDevice(@FormParam("username") String username,
|
||||||
@FormParam("password") String password) {
|
@FormParam("password") String password) {
|
||||||
JsonObject result = new JsonObject();
|
JsonObject result = new JsonObject();
|
||||||
@ -39,7 +36,6 @@ public class Authentication {
|
|||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/device/license")
|
@Path("/device/license")
|
||||||
@Produces("application/json")
|
|
||||||
public String getLicense() {
|
public String getLicense() {
|
||||||
JsonObject result = new JsonObject();
|
JsonObject result = new JsonObject();
|
||||||
result.addProperty("licenseText", "License Agreement");
|
result.addProperty("licenseText", "License Agreement");
|
||||||
|
|||||||
@ -18,7 +18,7 @@ package cdm.api.android;
|
|||||||
|
|
||||||
import cdm.api.android.util.AndroidAPIUtils;
|
import cdm.api.android.util.AndroidAPIUtils;
|
||||||
import cdm.api.android.util.AndroidConstants;
|
import cdm.api.android.util.AndroidConstants;
|
||||||
import com.google.gson.Gson;
|
import cdm.api.android.util.Message;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@ -30,21 +30,25 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
|||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Android Device Management REST-API implementation.
|
* Android Device Management REST-API implementation.
|
||||||
*/
|
*/
|
||||||
|
@Produces({ "application/json", "application/xml" })
|
||||||
|
@Consumes({ "application/json", "application/xml" })
|
||||||
public class Device {
|
public class Device {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Device.class);
|
private static Log log = LogFactory.getLog(Device.class);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
public Response getAllDevices() {
|
public List<org.wso2.carbon.device.mgt.common.Device> getAllDevices() {
|
||||||
List<org.wso2.carbon.device.mgt.common.Device> result = null;
|
|
||||||
int status = 0;
|
List<org.wso2.carbon.device.mgt.common.Device> devices = null;
|
||||||
String msg = "";
|
String msg = "";
|
||||||
DeviceManagementService dmService;
|
DeviceManagementService dmService;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
||||||
} finally {
|
} finally {
|
||||||
@ -52,39 +56,27 @@ public class Device {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (dmService != null) {
|
if (dmService != null) {
|
||||||
result = dmService.getAllDevices(
|
devices = dmService.getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
Response.status(HttpStatus.SC_OK);
|
||||||
status = 1;
|
|
||||||
} else {
|
} else {
|
||||||
status = -1;
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
msg = "Error occurred while fetching the device list";
|
msg = "Error occurred while fetching the device list";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
status = -1;
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
switch (status) {
|
return devices;
|
||||||
case 1:
|
|
||||||
if(result!=null){
|
|
||||||
String response = new Gson().toJson(result);
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(response).build();
|
|
||||||
}
|
|
||||||
case -1:
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(HttpStatus.SC_NOT_FOUND).entity("Unable to fetch device list").build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public Response getDevice(@PathParam("id") String id) {
|
public org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id) {
|
||||||
int status = 0;
|
|
||||||
String msg = "";
|
String msg = "";
|
||||||
DeviceManagementService dmService;
|
DeviceManagementService dmService;
|
||||||
org.wso2.carbon.device.mgt.common.Device device =
|
org.wso2.carbon.device.mgt.common.Device device = new org.wso2.carbon.device.mgt.common.Device();
|
||||||
new org.wso2.carbon.device.mgt.common.Device();
|
|
||||||
try {
|
try {
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
||||||
} finally {
|
} finally {
|
||||||
@ -94,37 +86,31 @@ public class Device {
|
|||||||
try {
|
try {
|
||||||
if (dmService != null) {
|
if (dmService != null) {
|
||||||
device = dmService.getDevice(deviceIdentifier);
|
device = dmService.getDevice(deviceIdentifier);
|
||||||
status = 1;
|
if (device == null) {
|
||||||
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
status = -1;
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
msg = "Error occurred while fetching the device information";
|
msg = "Error occurred while fetching the device information";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
status = -1;
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
switch (status) {
|
return device;
|
||||||
case 1:
|
|
||||||
if(device!=null) {
|
|
||||||
String response = new Gson().toJson(device);
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(response).build();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(HttpStatus.SC_NOT_FOUND).entity("Unable to fetch device information").build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public Response updateDevice(@PathParam("id") String id, String jsonPayload) {
|
public Message updateDevice(@PathParam("id") String id, String jsonPayload) {
|
||||||
|
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
int status = 0;
|
|
||||||
String msg = "";
|
String msg = "";
|
||||||
DeviceManagementService dmService;
|
DeviceManagementService dmService;
|
||||||
|
Message responseMessage = new Message();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
||||||
} finally {
|
} finally {
|
||||||
@ -135,25 +121,27 @@ public class Device {
|
|||||||
try {
|
try {
|
||||||
if (dmService != null) {
|
if (dmService != null) {
|
||||||
result = dmService.updateDeviceInfo(device);
|
result = dmService.updateDeviceInfo(device);
|
||||||
status = 1;
|
if (result) {
|
||||||
|
Response.status(HttpStatus.SC_OK);
|
||||||
|
responseMessage.setResponseMessage("Device has modified");
|
||||||
} else {
|
} else {
|
||||||
status = -1;
|
Response.status(HttpStatus.SC_NOT_MODIFIED);
|
||||||
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
responseMessage.setResponseMessage("Update device has failed");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
||||||
|
responseMessage.setResponseMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
msg = "Error occurred while modifying the device information";
|
msg = "Error occurred while modifying the device information";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
status = -1;
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
responseMessage.setResponseMessage(msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
switch (status) {
|
|
||||||
case 1:
|
return responseMessage;
|
||||||
if (result) {
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity("Device has modified").build();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(HttpStatus.SC_NOT_MODIFIED).entity("Update device has failed").build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,9 +18,10 @@ package cdm.api.android;
|
|||||||
|
|
||||||
import cdm.api.android.util.AndroidAPIUtils;
|
import cdm.api.android.util.AndroidAPIUtils;
|
||||||
import cdm.api.android.util.AndroidConstants;
|
import cdm.api.android.util.AndroidConstants;
|
||||||
|
import cdm.api.android.util.Message;
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
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.apache.commons.httpclient.HttpStatus;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
@ -33,16 +34,21 @@ import javax.ws.rs.core.Response;
|
|||||||
/**
|
/**
|
||||||
* Android Device Enrollment REST-API implementation.
|
* Android Device Enrollment REST-API implementation.
|
||||||
*/
|
*/
|
||||||
|
@Produces({ "application/json", "application/xml" })
|
||||||
|
@Consumes({ "application/json", "application/xml" })
|
||||||
public class Enrollment {
|
public class Enrollment {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(Enrollment.class);
|
private static Log log = LogFactory.getLog(Enrollment.class);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
public Response enrollDevice(String jsonPayload) {
|
public Message enrollDevice(String jsonPayload) {
|
||||||
|
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
String msg = "";
|
String msg = "";
|
||||||
DeviceManagementService dmService;
|
DeviceManagementService dmService;
|
||||||
|
Message responseMsg = new Message();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
||||||
} finally {
|
} finally {
|
||||||
@ -52,35 +58,33 @@ public class Enrollment {
|
|||||||
try {
|
try {
|
||||||
if (dmService != null) {
|
if (dmService != null) {
|
||||||
result = dmService.enrollDevice(device);
|
result = dmService.enrollDevice(device);
|
||||||
status = 1;
|
Response.status(HttpStatus.SC_CREATED);
|
||||||
|
responseMsg.setResponseMessage("Device enrollment has succeeded");
|
||||||
|
return responseMsg;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
status = -1;
|
responseMsg.setResponseMessage(AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
|
||||||
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
return responseMsg;
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
msg = "Error occurred while enrolling the device";
|
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
status = -1;
|
responseMsg.setResponseMessage("Error occurred while enrolling the device");
|
||||||
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
return responseMsg;
|
||||||
}
|
}
|
||||||
switch (status) {
|
|
||||||
case 1:
|
|
||||||
if (result) {
|
|
||||||
return Response.status(HttpStatus.SC_CREATED).entity("Device enrollment has succeeded").build();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(HttpStatus.SC_BAD_REQUEST).entity("Device enrollment has Failed").build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public Response isEnrolled(@PathParam("id") String id) {
|
public Message isEnrolled(@PathParam("id") String id) {
|
||||||
|
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
int status = 0;
|
|
||||||
String msg = "";
|
String msg = "";
|
||||||
DeviceManagementService dmService;
|
DeviceManagementService dmService;
|
||||||
|
Message responseMsg = new Message();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
||||||
} finally {
|
} finally {
|
||||||
@ -90,35 +94,38 @@ public class Enrollment {
|
|||||||
try {
|
try {
|
||||||
if (dmService != null) {
|
if (dmService != null) {
|
||||||
result = dmService.isEnrolled(deviceIdentifier);
|
result = dmService.isEnrolled(deviceIdentifier);
|
||||||
status = 1;
|
if (result) {
|
||||||
|
Response.status(HttpStatus.SC_OK);
|
||||||
|
responseMsg.setResponseMessage("Device already enroll");
|
||||||
} else {
|
} else {
|
||||||
status = -1;
|
|
||||||
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
||||||
|
responseMsg.setResponseMessage("Device not enroll");
|
||||||
|
}
|
||||||
|
return responseMsg;
|
||||||
|
} else {
|
||||||
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
responseMsg.setResponseMessage(AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
|
||||||
|
return responseMsg;
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
msg = "Error occurred while checking enrollment of the device";
|
msg = "Error occurred while checking enrollment of the device";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
status = -1;
|
responseMsg.setResponseMessage(msg);
|
||||||
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
return responseMsg;
|
||||||
}
|
}
|
||||||
switch (status) {
|
|
||||||
case 1:
|
|
||||||
if (result) {
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(result).build();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(HttpStatus.SC_NOT_FOUND).entity(result).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public Response modifyEnrollment(@PathParam("id") String id, String jsonPayload) {
|
public Message modifyEnrollment(@PathParam("id") String id, String jsonPayload) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
int status = 0;
|
|
||||||
String msg = "";
|
String msg = "";
|
||||||
DeviceManagementService dmService;
|
DeviceManagementService dmService;
|
||||||
|
Message responseMsg = new Message();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
||||||
} finally {
|
} finally {
|
||||||
@ -128,35 +135,40 @@ public class Enrollment {
|
|||||||
try {
|
try {
|
||||||
if (dmService != null) {
|
if (dmService != null) {
|
||||||
result = dmService.modifyEnrollment(device);
|
result = dmService.modifyEnrollment(device);
|
||||||
status = 1;
|
|
||||||
} else {
|
if (result) {
|
||||||
status = -1;
|
responseMsg.setResponseMessage("update device");
|
||||||
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
Response.status(HttpStatus.SC_OK);
|
||||||
|
}else{
|
||||||
|
responseMsg.setResponseMessage("Update enrollment has failed");
|
||||||
|
Response.status(HttpStatus.SC_NOT_MODIFIED);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
||||||
|
responseMsg.setResponseMessage(msg);
|
||||||
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
return responseMsg;
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
msg = "Error occurred while modifying enrollment of the device";
|
msg = "Error occurred while modifying enrollment of the device";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
status = -1;
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
responseMsg.setResponseMessage(msg);
|
||||||
|
return responseMsg;
|
||||||
}
|
}
|
||||||
switch (status) {
|
|
||||||
case 1:
|
|
||||||
if (result) {
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity("Enrollment information has modified").build();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(HttpStatus.SC_NOT_MODIFIED).entity("Update enrollment has failed").build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public Response disenrollDevice(@PathParam("id") String id) {
|
public Message disenrollDevice(@PathParam("id") String id) {
|
||||||
|
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
int status = 0;
|
|
||||||
String msg = "";
|
String msg = "";
|
||||||
DeviceManagementService dmService;
|
DeviceManagementService dmService;
|
||||||
|
Message responseMsg = new Message();
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dmService = AndroidAPIUtils.getDeviceManagementService();
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
||||||
} finally {
|
} finally {
|
||||||
@ -166,25 +178,26 @@ public class Enrollment {
|
|||||||
try {
|
try {
|
||||||
if (dmService != null) {
|
if (dmService != null) {
|
||||||
result = dmService.disenrollDevice(deviceIdentifier);
|
result = dmService.disenrollDevice(deviceIdentifier);
|
||||||
status = 1;
|
if (result) {
|
||||||
} else {
|
responseMsg.setResponseMessage("Dis enrolled device");
|
||||||
status = -1;
|
Response.status(HttpStatus.SC_OK);
|
||||||
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
}else{
|
||||||
|
responseMsg.setResponseMessage("Device not found");
|
||||||
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
||||||
|
responseMsg.setResponseMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseMsg;
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
msg = "Error occurred while disenrolling the device";
|
msg = "Error occurred while disenrolling the device";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
status = -1;
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
responseMsg.setResponseMessage(msg);
|
||||||
|
return responseMsg;
|
||||||
}
|
}
|
||||||
switch (status) {
|
|
||||||
case 1:
|
|
||||||
if (result) {
|
|
||||||
return Response.status(HttpStatus.SC_OK).entity(result).build();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
||||||
}
|
|
||||||
return Response.status(HttpStatus.SC_NOT_FOUND).entity("Device not found").build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,20 +27,33 @@
|
|||||||
<jaxrs:serviceBeans>
|
<jaxrs:serviceBeans>
|
||||||
<ref bean="serviceBean"/>
|
<ref bean="serviceBean"/>
|
||||||
</jaxrs:serviceBeans>
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
</jaxrs:providers>
|
||||||
</jaxrs:server>
|
</jaxrs:server>
|
||||||
<jaxrs:server id="deviceManagementService" address="/devices">
|
<jaxrs:server id="deviceManagementService" address="/devices">
|
||||||
<jaxrs:serviceBeans>
|
<jaxrs:serviceBeans>
|
||||||
<ref bean="deviceMgtServiceBean"/>
|
<ref bean="deviceMgtServiceBean"/>
|
||||||
</jaxrs:serviceBeans>
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
</jaxrs:providers>
|
||||||
</jaxrs:server>
|
</jaxrs:server>
|
||||||
<jaxrs:server id="enrollmentService" address="/enrollment">
|
<jaxrs:server id="enrollmentService" address="/enrollment">
|
||||||
<jaxrs:serviceBeans>
|
<jaxrs:serviceBeans>
|
||||||
<ref bean="enrollmentServiceBean"/>
|
<ref bean="enrollmentServiceBean"/>
|
||||||
</jaxrs:serviceBeans>
|
</jaxrs:serviceBeans>
|
||||||
|
<jaxrs:providers>
|
||||||
|
<ref bean="jsonProvider"/>
|
||||||
|
</jaxrs:providers>
|
||||||
</jaxrs:server>
|
</jaxrs:server>
|
||||||
|
|
||||||
<bean id="serviceBean" class="cdm.api.android.Authentication"/>
|
<bean id="serviceBean" class="cdm.api.android.Authentication"/>
|
||||||
<bean id="deviceMgtServiceBean" class="cdm.api.android.Device"/>
|
<bean id="deviceMgtServiceBean" class="cdm.api.android.Device"/>
|
||||||
<bean id="enrollmentServiceBean" class="cdm.api.android.Enrollment"/>
|
<bean id="enrollmentServiceBean" class="cdm.api.android.Enrollment"/>
|
||||||
|
<bean id="testServiceBean" class="cdm.api.android.Test"/>
|
||||||
|
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
|
||||||
|
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user