From 3f0f4ffeaeee7f1653b09a2ab7cbf76e91c9bf5b Mon Sep 17 00:00:00 2001 From: harshanL Date: Wed, 10 Dec 2014 14:10:04 +0530 Subject: [PATCH 1/3] Fixed issues in pom file & enrollment --- product/modules/agents/android/jax-rs/pom.xml | 129 +++++++++--------- .../main/java/cdm/api/android/Enrollment.java | 16 ++- product/modules/p2-profile-gen/pom.xml | 14 +- 3 files changed, 85 insertions(+), 74 deletions(-) diff --git a/product/modules/agents/android/jax-rs/pom.xml b/product/modules/agents/android/jax-rs/pom.xml index 306d7c24d..190d08ff6 100644 --- a/product/modules/agents/android/jax-rs/pom.xml +++ b/product/modules/agents/android/jax-rs/pom.xml @@ -19,10 +19,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - org.wso2.cdmserver - wso2cdmserver-parent + org.wso2.carbon + wso2cdm-parent 2.0.0-SNAPSHOT - ../../../../pom.xml + ../../../../../pom.xml 4.0.0 @@ -47,7 +47,7 @@ maven-war-plugin 2.2 - WEB-INF/lib/*.jar + ${project.artifactId} @@ -72,7 +72,8 @@ - + @@ -109,62 +110,68 @@ - - - org.apache.cxf - cxf-rt-frontend-jaxws - ${cxf.version} - - - org.apache.cxf - cxf-rt-frontend-jaxrs - ${cxf.version} - - - org.apache.cxf - cxf-rt-transports-http - ${cxf.version} - - - junit - junit - test - ${junit.version} - - - commons-httpclient - commons-httpclient - 3.1 - - - javax.ws.rs - jsr311-api - 1.1.1 - - - com.google.code.gson - gson - 2.2.4 - - - org.wso2.carbon - org.wso2.carbon.utils - - - org.wso2.carbon - org.wso2.carbon.device.mgt.common - 2.0.0-SNAPSHOT - - - org.wso2.carbon - org.wso2.carbon.device.mgt.core - 2.0.0-SNAPSHOT - - - org.wso2.carbon - org.wso2.carbon.logging - - + + + org.apache.cxf + cxf-rt-frontend-jaxws + ${cxf.version} + + + org.apache.cxf + cxf-rt-frontend-jaxrs + ${cxf.version} + + + org.apache.cxf + cxf-rt-transports-http + ${cxf.version} + + + junit + junit + test + ${junit.version} + + + commons-httpclient + commons-httpclient + 3.1 + provided + + + javax.ws.rs + jsr311-api + 1.1.1 + provided + + + com.google.code.gson + gson + 2.2.4 + + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + org.wso2.carbon + org.wso2.carbon.device.mgt.common + 2.0.0-SNAPSHOT + provided + + + org.wso2.carbon + org.wso2.carbon.device.mgt.core + 2.0.0-SNAPSHOT + provided + + + org.wso2.carbon + org.wso2.carbon.logging + provided + + 2.6.1 4.8.2 diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java index 141b76f0e..a78f8051c 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java @@ -72,26 +72,30 @@ public class Enrollment { @Consumes("application/json") @Path("{id}") public Response modifyEnrollment(@PathParam("id") String id) { + boolean status = false; CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null); try { - dmService.isRegistered(null); + status = dmService.isRegistered(null); } catch (DeviceManagementException e) { - e.printStackTrace(); + String msg = "Error occurred while modifying enrollment of the device"; + log.error(msg, e); } - return Response.status(201).entity("Registration Successful").build(); + return Response.status(201).entity(status).build(); } @DELETE @Path("{id}") public Response disenrollDevice(@PathParam("id") String id) { + boolean status = false; CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null); try { - dmService.isRegistered(null); + status = dmService.isRegistered(null); } catch (DeviceManagementException e) { - e.printStackTrace(); + String msg = "Error occurred while disenrolling the device"; + log.error(msg, e); } - return Response.status(201).entity("Registration Successful").build(); + return Response.status(201).entity(status).build(); } } diff --git a/product/modules/p2-profile-gen/pom.xml b/product/modules/p2-profile-gen/pom.xml index 2fece93e2..640e71117 100644 --- a/product/modules/p2-profile-gen/pom.xml +++ b/product/modules/p2-profile-gen/pom.xml @@ -104,9 +104,9 @@ org.wso2.carbon:org.wso2.carbon.ndatasource.feature:${carbon.kernel.version} - - org.wso2.carbon:org.wso2.carbon.device.mgt.server.feature:${project.version} - + + + org.wso2.carbon:org.wso2.carbon.webapp.mgt.feature:${carbon.platform.version} @@ -157,10 +157,10 @@ org.wso2.carbon.ndatasource.ui.feature.group ${carbon.kernel.version} - - org.wso2.carbon.device.mgt.server.feature.group - ${project.version} - + + + + org.wso2.carbon.webapp.mgt.feature.group ${carbon.platform.version} From 7eb5b960a9b6ff370d1f1f9214938e868b6b0562 Mon Sep 17 00:00:00 2001 From: harshanL Date: Wed, 10 Dec 2014 14:11:37 +0530 Subject: [PATCH 2/3] Fixed issues in pom file --- product/modules/p2-profile-gen/pom.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/product/modules/p2-profile-gen/pom.xml b/product/modules/p2-profile-gen/pom.xml index 640e71117..2fece93e2 100644 --- a/product/modules/p2-profile-gen/pom.xml +++ b/product/modules/p2-profile-gen/pom.xml @@ -104,9 +104,9 @@ org.wso2.carbon:org.wso2.carbon.ndatasource.feature:${carbon.kernel.version} - - - + + org.wso2.carbon:org.wso2.carbon.device.mgt.server.feature:${project.version} + org.wso2.carbon:org.wso2.carbon.webapp.mgt.feature:${carbon.platform.version} @@ -157,10 +157,10 @@ org.wso2.carbon.ndatasource.ui.feature.group ${carbon.kernel.version} - - - - + + org.wso2.carbon.device.mgt.server.feature.group + ${project.version} + org.wso2.carbon.webapp.mgt.feature.group ${carbon.platform.version} From 7c7768101f32f90cb095ed25d06aa435c60a5f25 Mon Sep 17 00:00:00 2001 From: harshanL Date: Wed, 10 Dec 2014 14:53:15 +0530 Subject: [PATCH 3/3] Modified Android enrollment APIs and changed isRegistered to isEnrolled --- .../mgt/common/spi/DeviceManagerService.java | 2 +- .../carbon/device/mgt/core/DeviceManager.java | 4 +- .../core/service/DeviceManagementService.java | 4 +- .../android/AndroidDeviceManagerService.java | 2 +- .../impl/ios/IOSDeviceManagerService.java | 2 +- .../windows/WindowsDeviceManagerService.java | 2 +- .../main/java/cdm/api/android/Enrollment.java | 102 ++++++++++++++---- 7 files changed, 88 insertions(+), 30 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java index 93469177a..319acca3c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagerService.java @@ -65,7 +65,7 @@ public interface DeviceManagerService { * @return Status of enrollment * @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device */ - boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException; + boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException; /** * Method to retrieve the status of a particular device. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java index 1d541a7da..a7c6ef815 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java @@ -84,10 +84,10 @@ public class DeviceManager implements DeviceManagerService { } @Override - public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); - return dms.isRegistered(deviceId); + return dms.isEnrolled(deviceId); } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index 5a30f8cd7..d7508fb78 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -46,8 +46,8 @@ public class DeviceManagementService implements DeviceManagerService { } @Override - public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { - return DeviceManagementDataHolder.getInstance().getDeviceManager().isRegistered(deviceId); + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + return DeviceManagementDataHolder.getInstance().getDeviceManager().isEnrolled(deviceId); } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java index 59f44f928..648fd2c92 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java @@ -50,7 +50,7 @@ public class AndroidDeviceManagerService implements DeviceManagerService { } @Override - public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { return true; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java index 4baee059d..a458b5952 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java @@ -50,7 +50,7 @@ public class IOSDeviceManagerService implements DeviceManagerService { } @Override - public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { return true; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java index b144670b5..1cc845faa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java @@ -50,7 +50,7 @@ public class WindowsDeviceManagerService implements DeviceManagerService { } @Override - public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { return true; } diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java index a78f8051c..50c3488fe 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java @@ -36,66 +36,124 @@ import javax.ws.rs.core.Response; public class Enrollment { private static Log log = LogFactory.getLog(Enrollment.class); + @POST public Response enrollDevice() { - JsonObject result = new JsonObject(); - result.addProperty("senderId","jwwfowrjwqporqwrpqworpq"); + boolean result = false; + int status = 0; + String msg = ""; CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); - DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null); - Device device = AndroidAPIUtil.convertToDeviceObject(result); + DeviceManagementService dmService = (DeviceManagementService) context + .getOSGiService(DeviceManagementService.class, null); + Device device = AndroidAPIUtil.convertToDeviceObject(null); try { - dmService.enrollDevice(device); + result = dmService.enrollDevice(device); + status = 1; } catch (DeviceManagementException e) { - String msg = "Error occurred while enrolling the device"; + msg = "Error occurred while enrolling the device"; log.error(msg, e); + status = -1; + } + switch (status) { + case 1: + if (result) { + return Response.status(201).entity("Registration Successful").build(); + } + break; + case -1: + return Response.status(500).entity(msg).build(); } - return Response.status(201).entity("Registration Successful").build(); + return Response.status(400).entity("Registration Failed").build(); } @GET @Path("{id}") public Response isEnrolled(@PathParam("id") String id) { - boolean status = false; + boolean result = false; + int status = 0; + String msg = ""; CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); - DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null); + DeviceManagementService dmService = (DeviceManagementService) context + .getOSGiService(DeviceManagementService.class, null); try { DeviceIdentifier deviceIdentifier = AndroidAPIUtil.convertToDeviceIdentifierObject(id); - status = dmService.isRegistered(deviceIdentifier); + result = dmService.isEnrolled(deviceIdentifier); + status = 1; } catch (DeviceManagementException e) { - String msg = "Error occurred while checking enrollment of the device"; + msg = "Error occurred while checking enrollment of the device"; log.error(msg, e); + status = -1; + } + switch (status) { + case 1: + if (result) { + return Response.status(200).entity(result).build(); + } + break; + case -1: + return Response.status(500).entity(msg).build(); } - return Response.status(200).entity(status).build(); + return Response.status(404).entity(result).build(); } @PUT @Consumes("application/json") @Path("{id}") public Response modifyEnrollment(@PathParam("id") String id) { - boolean status = false; + boolean result = false; + int status = 0; + String msg = ""; CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); - DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null); + DeviceManagementService dmService = (DeviceManagementService) context + .getOSGiService(DeviceManagementService.class, null); + Device device = AndroidAPIUtil.convertToDeviceObject(null); try { - status = dmService.isRegistered(null); + result = dmService.modifyEnrollment(device); + status = 1; } catch (DeviceManagementException e) { - String msg = "Error occurred while modifying enrollment of the device"; + msg = "Error occurred while modifying enrollment of the device"; log.error(msg, e); + status = -1; } - return Response.status(201).entity(status).build(); + switch (status) { + case 1: + if (result) { + return Response.status(200).entity("Device information modified").build(); + } + break; + case -1: + return Response.status(500).entity(msg).build(); + } + return Response.status(400).entity("Update enrollment failed").build(); } @DELETE @Path("{id}") public Response disenrollDevice(@PathParam("id") String id) { - boolean status = false; + boolean result = false; + int status = 0; + String msg = ""; CarbonContext context = CarbonContext.getThreadLocalCarbonContext(); - DeviceManagementService dmService = (DeviceManagementService) context.getOSGiService(DeviceManagementService.class,null); + DeviceManagementService dmService = (DeviceManagementService) context + .getOSGiService(DeviceManagementService.class, null); try { - status = dmService.isRegistered(null); + DeviceIdentifier deviceIdentifier = AndroidAPIUtil.convertToDeviceIdentifierObject(id); + result = dmService.disenrollDevice(deviceIdentifier); + status = 1; } catch (DeviceManagementException e) { - String msg = "Error occurred while disenrolling the device"; + msg = "Error occurred while disenrolling the device"; log.error(msg, e); + status = -1; + } + switch (status) { + case 1: + if (result) { + return Response.status(200).entity(result).build(); + } + break; + case -1: + return Response.status(500).entity(msg).build(); } - return Response.status(201).entity(status).build(); + return Response.status(404).entity("Device not found").build(); } }