JAX-RS Refractor

revert-70aa11f8
manoj 10 years ago
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,31 +18,27 @@ 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(); result.addProperty("senderId", "jwwfowrjwqporqwrpqworpq");
result.addProperty("senderId", "jwwfowrjwqporqwrpqworpq"); return result.toString();
return result.toString(); }
}
@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"); return result.toString();
return result.toString(); }
}
} }

@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
@ -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,130 +30,118 @@ 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 {
dmService = AndroidAPIUtils.getDeviceManagementService(); try {
} finally { dmService = AndroidAPIUtils.getDeviceManagementService();
PrivilegedCarbonContext.endTenantFlow(); } finally {
} PrivilegedCarbonContext.endTenantFlow();
try { }
if (dmService != null) { try {
result = dmService.getAllDevices( if (dmService != null) {
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); devices = dmService.getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
status = 1; Response.status(HttpStatus.SC_OK);
} else { } else {
status = -1; Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; }
} } catch (DeviceManagementException e) {
msg = "Error occurred while fetching the device list";
} catch (DeviceManagementException e) { log.error(msg, e);
msg = "Error occurred while fetching the device list"; Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
log.error(msg, e); }
status = -1; return devices;
} }
switch (status) {
case 1: @GET
if(result!=null){ @Path("{id}")
String response = new Gson().toJson(result); public org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id) {
return Response.status(HttpStatus.SC_OK).entity(response).build();
} String msg = "";
case -1: DeviceManagementService dmService;
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build(); org.wso2.carbon.device.mgt.common.Device device = new org.wso2.carbon.device.mgt.common.Device();
}
return Response.status(HttpStatus.SC_NOT_FOUND).entity("Unable to fetch device list").build(); try {
} dmService = AndroidAPIUtils.getDeviceManagementService();
} finally {
@GET PrivilegedCarbonContext.endTenantFlow();
@Path("{id}") }
public Response getDevice(@PathParam("id") String id) { DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
int status = 0; try {
String msg = ""; if (dmService != null) {
DeviceManagementService dmService; device = dmService.getDevice(deviceIdentifier);
org.wso2.carbon.device.mgt.common.Device device = if (device == null) {
new org.wso2.carbon.device.mgt.common.Device(); Response.status(HttpStatus.SC_NOT_FOUND);
try { }
dmService = AndroidAPIUtils.getDeviceManagementService();
} finally { } else {
PrivilegedCarbonContext.endTenantFlow(); Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
} }
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
try { } catch (DeviceManagementException e) {
if (dmService != null) { msg = "Error occurred while fetching the device information";
device = dmService.getDevice(deviceIdentifier); log.error(msg, e);
status = 1; Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
} else { }
status = -1; return device;
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; }
}
@PUT
} catch (DeviceManagementException e) { @Path("{id}")
msg = "Error occurred while fetching the device information"; public Message updateDevice(@PathParam("id") String id, String jsonPayload) {
log.error(msg, e);
status = -1; boolean result = false;
} String msg = "";
switch (status) { DeviceManagementService dmService;
case 1: Message responseMessage = new Message();
if(device!=null) {
String response = new Gson().toJson(device); try {
return Response.status(HttpStatus.SC_OK).entity(response).build(); dmService = AndroidAPIUtils.getDeviceManagementService();
} } finally {
break; PrivilegedCarbonContext.endTenantFlow();
case -1: }
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build(); org.wso2.carbon.device.mgt.common.Device device =
} AndroidAPIUtils.convertToDeviceObject(jsonPayload);
return Response.status(HttpStatus.SC_NOT_FOUND).entity("Unable to fetch device information").build(); try {
} if (dmService != null) {
result = dmService.updateDeviceInfo(device);
@PUT if (result) {
@Path("{id}") Response.status(HttpStatus.SC_OK);
public Response updateDevice(@PathParam("id") String id, String jsonPayload) { responseMessage.setResponseMessage("Device has modified");
boolean result = false; } else {
int status = 0; Response.status(HttpStatus.SC_NOT_MODIFIED);
String msg = ""; responseMessage.setResponseMessage("Update device has failed");
DeviceManagementService dmService; }
try { } else {
dmService = AndroidAPIUtils.getDeviceManagementService(); Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
} finally { msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
PrivilegedCarbonContext.endTenantFlow(); responseMessage.setResponseMessage(msg);
} }
org.wso2.carbon.device.mgt.common.Device device =
AndroidAPIUtils.convertToDeviceObject(jsonPayload); } catch (DeviceManagementException e) {
try { msg = "Error occurred while modifying the device information";
if (dmService != null) { log.error(msg, e);
result = dmService.updateDeviceInfo(device); Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
status = 1; responseMessage.setResponseMessage(msg);
} else {
status = -1; }
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
} return responseMessage;
} catch (DeviceManagementException e) { }
msg = "Error occurred while modifying the device information";
log.error(msg, e);
status = -1;
}
switch (status) {
case 1:
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,158 +34,170 @@ 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;
int status = 0; boolean result = false;
String msg = ""; int status = 0;
DeviceManagementService dmService; String msg = "";
try { DeviceManagementService dmService;
dmService = AndroidAPIUtils.getDeviceManagementService(); Message responseMsg = new Message();
} finally {
PrivilegedCarbonContext.endTenantFlow(); try {
} dmService = AndroidAPIUtils.getDeviceManagementService();
Device device = AndroidAPIUtils.convertToDeviceObject(jsonPayload); } finally {
try { PrivilegedCarbonContext.endTenantFlow();
if (dmService != null) { }
result = dmService.enrollDevice(device); Device device = AndroidAPIUtils.convertToDeviceObject(jsonPayload);
status = 1; try {
} else { if (dmService != null) {
status = -1; result = dmService.enrollDevice(device);
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; Response.status(HttpStatus.SC_CREATED);
} responseMsg.setResponseMessage("Device enrollment has succeeded");
} catch (DeviceManagementException e) { return responseMsg;
msg = "Error occurred while enrolling the device";
log.error(msg, e); } else {
status = -1; responseMsg.setResponseMessage(AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
} Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
switch (status) { return responseMsg;
case 1: }
if (result) { } catch (DeviceManagementException e) {
return Response.status(HttpStatus.SC_CREATED).entity("Device enrollment has succeeded").build(); log.error(msg, e);
} responseMsg.setResponseMessage("Error occurred while enrolling the device");
break; Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
case -1: return responseMsg;
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 Message isEnrolled(@PathParam("id") String id) {
public Response 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 {
dmService = AndroidAPIUtils.getDeviceManagementService(); try {
} finally { dmService = AndroidAPIUtils.getDeviceManagementService();
PrivilegedCarbonContext.endTenantFlow(); } finally {
} PrivilegedCarbonContext.endTenantFlow();
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); }
try { DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
if (dmService != null) { try {
result = dmService.isEnrolled(deviceIdentifier); if (dmService != null) {
status = 1; result = dmService.isEnrolled(deviceIdentifier);
} else { if (result) {
status = -1; Response.status(HttpStatus.SC_OK);
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; responseMsg.setResponseMessage("Device already enroll");
} } else {
} catch (DeviceManagementException e) {
msg = "Error occurred while checking enrollment of the device"; Response.status(HttpStatus.SC_NOT_FOUND);
log.error(msg, e); responseMsg.setResponseMessage("Device not enroll");
status = -1; }
} return responseMsg;
switch (status) { } else {
case 1: Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
if (result) { responseMsg.setResponseMessage(AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
return Response.status(HttpStatus.SC_OK).entity(result).build(); return responseMsg;
} }
break; } catch (DeviceManagementException e) {
case -1: msg = "Error occurred while checking enrollment of the device";
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build(); log.error(msg, e);
} responseMsg.setResponseMessage(msg);
return Response.status(HttpStatus.SC_NOT_FOUND).entity(result).build(); Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
} return responseMsg;
}
@PUT
@Path("{id}") }
public Response modifyEnrollment(@PathParam("id") String id, String jsonPayload) {
boolean result = false; @PUT
int status = 0; @Path("{id}")
String msg = ""; public Message modifyEnrollment(@PathParam("id") String id, String jsonPayload) {
DeviceManagementService dmService; boolean result = false;
try { String msg = "";
dmService = AndroidAPIUtils.getDeviceManagementService(); DeviceManagementService dmService;
} finally { Message responseMsg = new Message();
PrivilegedCarbonContext.endTenantFlow();
} try {
Device device = AndroidAPIUtils.convertToDeviceObject(jsonPayload); dmService = AndroidAPIUtils.getDeviceManagementService();
try { } finally {
if (dmService != null) { PrivilegedCarbonContext.endTenantFlow();
result = dmService.modifyEnrollment(device); }
status = 1; Device device = AndroidAPIUtils.convertToDeviceObject(jsonPayload);
} else { try {
status = -1; if (dmService != null) {
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; result = dmService.modifyEnrollment(device);
}
} catch (DeviceManagementException e) { if (result) {
msg = "Error occurred while modifying enrollment of the device"; responseMsg.setResponseMessage("update device");
log.error(msg, e); Response.status(HttpStatus.SC_OK);
status = -1; }else{
} responseMsg.setResponseMessage("Update enrollment has failed");
switch (status) { Response.status(HttpStatus.SC_NOT_MODIFIED);
case 1: }
if (result) { } else {
return Response.status(HttpStatus.SC_OK).entity("Enrollment information has modified").build(); msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
} responseMsg.setResponseMessage(msg);
break; Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
case -1: }
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build(); return responseMsg;
} } catch (DeviceManagementException e) {
return Response.status(HttpStatus.SC_NOT_MODIFIED).entity("Update enrollment has failed").build(); msg = "Error occurred while modifying enrollment of the device";
} log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
@DELETE responseMsg.setResponseMessage(msg);
@Path("{id}") return responseMsg;
public Response disenrollDevice(@PathParam("id") String id) { }
boolean result = false;
int status = 0; }
String msg = "";
DeviceManagementService dmService; @DELETE
try { @Path("{id}")
dmService = AndroidAPIUtils.getDeviceManagementService(); public Message disenrollDevice(@PathParam("id") String id) {
} finally {
PrivilegedCarbonContext.endTenantFlow(); boolean result = false;
} String msg = "";
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); DeviceManagementService dmService;
try { Message responseMsg = new Message();
if (dmService != null) {
result = dmService.disenrollDevice(deviceIdentifier);
status = 1; try {
} else { dmService = AndroidAPIUtils.getDeviceManagementService();
status = -1; } finally {
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE; PrivilegedCarbonContext.endTenantFlow();
} }
} catch (DeviceManagementException e) { DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
msg = "Error occurred while disenrolling the device"; try {
log.error(msg, e); if (dmService != null) {
status = -1; result = dmService.disenrollDevice(deviceIdentifier);
} if (result) {
switch (status) { responseMsg.setResponseMessage("Dis enrolled device");
case 1: Response.status(HttpStatus.SC_OK);
if (result) { }else{
return Response.status(HttpStatus.SC_OK).entity(result).build(); responseMsg.setResponseMessage("Device not found");
} Response.status(HttpStatus.SC_NOT_FOUND);
break; }
case -1: } else {
return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(msg).build(); Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
} msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
return Response.status(HttpStatus.SC_NOT_FOUND).entity("Device not found").build(); responseMsg.setResponseMessage(msg);
} }
return responseMsg;
} catch (DeviceManagementException e) {
msg = "Error occurred while disenrolling the device";
log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
responseMsg.setResponseMessage(msg);
return responseMsg;
}
}
} }

@ -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…
Cancel
Save