Refactor Agents module

revert-70aa11f8
manoj 10 years ago
parent dd9bfdb6a7
commit 17457bf6d3

@ -133,15 +133,7 @@
<artifactId>org.eclipse.equinox.common</artifactId> <artifactId>org.eclipse.equinox.common</artifactId>
<version>${eclipse.equinox.common.version}</version> <version>${eclipse.equinox.common.version}</version>
</dependency> </dependency>
<!--Test dependencies-->
<!--
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12-beta-3</version>
<scope>test</scope>
</dependency>
-->
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>org.testng</groupId>
<artifactId>testng</artifactId> <artifactId>testng</artifactId>

@ -251,7 +251,7 @@
<files> <files>
<file> <file>
<source>../agents/android/jax-rs/target/cdm-android-api.war</source> <source>../mobileservices/agents/android/jax-rs/target/cdm-android-api.war</source>
<outputDirectory>wso2cdm-${pom.version}/repository/deployment/server/webapps <outputDirectory>wso2cdm-${pom.version}/repository/deployment/server/webapps
</outputDirectory> </outputDirectory>
<fileMode>755</fileMode> <fileMode>755</fileMode>

@ -115,34 +115,23 @@
<dependency> <dependency>
<groupId>org.apache.cxf</groupId> <groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId> <artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.cxf</groupId> <groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId> <artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.cxf</groupId> <groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId> <artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.ws.rs</groupId> <groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId> <artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -153,13 +142,11 @@
<dependency> <dependency>
<groupId>org.wso2.carbon</groupId> <groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId> <artifactId>org.wso2.carbon.device.mgt.common</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.wso2.carbon</groupId> <groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId> <artifactId>org.wso2.carbon.device.mgt.core</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -170,11 +157,6 @@
<dependency> <dependency>
<groupId>org.codehaus.jackson</groupId> <groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId> <artifactId>jackson-jaxrs</artifactId>
<version>1.9.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
<properties>
<cxf.version>2.6.1</cxf.version>
<junit.version>4.8.2</junit.version>
</properties>
</project> </project>

@ -15,13 +15,11 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
//org.wso2.carbon....
package org.wso2.cdmserver.mobileservices.android; package org.wso2.cdmserver.mobileservices.android;
import org.wso2.cdmserver.mobileservices.android.common.AndroidAgentException; import org.wso2.cdmserver.mobileservices.android.common.AndroidAgentException;
import org.wso2.cdmserver.mobileservices.android.util.AndroidAPIUtils; import org.wso2.cdmserver.mobileservices.android.util.AndroidAPIUtils;
import org.wso2.cdmserver.mobileservices.android.util.Message; import org.wso2.cdmserver.mobileservices.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.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
@ -53,8 +51,8 @@ public class Device {
List<org.wso2.carbon.device.mgt.common.Device> devices; List<org.wso2.carbon.device.mgt.common.Device> devices;
try { try {
devices = AndroidAPIUtils.getDeviceManagementService().getAllDevices( devices = AndroidAPIUtils.getDeviceManagementService().getAllDevices(DeviceManagementConstants
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); .MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
return devices; return devices;
} catch (DeviceManagementServiceException deviceMgtServiceEx) { } catch (DeviceManagementServiceException deviceMgtServiceEx) {
String errorMsg = "Device management service error"; String errorMsg = "Device management service error";
@ -84,7 +82,7 @@ public class Device {
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier); device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier);
if (device == null) { if (device == null) {
Response.status(HttpStatus.SC_NOT_FOUND); Response.status(Response.Status.NOT_FOUND);
} }
return device; return device;
} catch (DeviceManagementServiceException deviceMgtServiceEx) { } catch (DeviceManagementServiceException deviceMgtServiceEx) {
@ -116,10 +114,10 @@ public class Device {
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
result = AndroidAPIUtils.getDeviceManagementService().updateDeviceInfo(device); result = AndroidAPIUtils.getDeviceManagementService().updateDeviceInfo(device);
if (result) { if (result) {
Response.status(HttpStatus.SC_ACCEPTED); Response.status(Response.Status.ACCEPTED);
responseMessage.setResponseMessage("Device information has modified successfully."); responseMessage.setResponseMessage("Device information has modified successfully.");
} else { } else {
Response.status(HttpStatus.SC_NOT_MODIFIED); Response.status(Response.Status.NOT_MODIFIED);
responseMessage.setResponseMessage("Device not found for the update."); responseMessage.setResponseMessage("Device not found for the update.");
} }
return responseMessage; return responseMessage;

@ -18,17 +18,16 @@
package org.wso2.cdmserver.mobileservices.android; package org.wso2.cdmserver.mobileservices.android;
import org.wso2.cdmserver.mobileservices.android.common.AndroidAgentException;
import org.wso2.cdmserver.mobileservices.android.util.AndroidAPIUtils;
import org.wso2.cdmserver.mobileservices.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.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManagementServiceException; import org.wso2.carbon.device.mgt.common.DeviceManagementServiceException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.cdmserver.mobileservices.android.common.AndroidAgentException;
import org.wso2.cdmserver.mobileservices.android.util.AndroidAPIUtils;
import org.wso2.cdmserver.mobileservices.android.util.Message;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -50,7 +49,7 @@ public class Enrollment {
try { try {
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
AndroidAPIUtils.getDeviceManagementService().enrollDevice(device); AndroidAPIUtils.getDeviceManagementService().enrollDevice(device);
Response.status(HttpStatus.SC_CREATED); Response.status(Response.Status.CREATED);
responseMsg.setResponseMessage("Device enrollment succeeded"); responseMsg.setResponseMessage("Device enrollment succeeded");
return responseMsg; return responseMsg;
} catch (DeviceManagementServiceException deviceServiceMgtEx) { } catch (DeviceManagementServiceException deviceServiceMgtEx) {
@ -71,13 +70,13 @@ public class Enrollment {
boolean result; boolean result;
Message responseMsg = new Message(); Message responseMsg = new Message();
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
try { try {
result = AndroidAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier); result = AndroidAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier);
if (result) { if (result) {
Response.status(HttpStatus.SC_OK);
responseMsg.setResponseMessage("Device has already enrolled"); responseMsg.setResponseMessage("Device has already enrolled");
} else { } else {
Response.status(HttpStatus.SC_NOT_FOUND); Response.status(Response.Status.NOT_FOUND);
responseMsg.setResponseMessage("Device not found"); responseMsg.setResponseMessage("Device not found");
} }
return responseMsg; return responseMsg;
@ -99,16 +98,15 @@ public class Enrollment {
boolean result; boolean result;
Message responseMsg = new Message(); Message responseMsg = new Message();
try { try {
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
result = AndroidAPIUtils.getDeviceManagementService().modifyEnrollment(device); result = AndroidAPIUtils.getDeviceManagementService().modifyEnrollment(device);
if (result) { if (result) {
responseMsg.setResponseMessage("Device enrollment has updated successfully"); responseMsg.setResponseMessage("Device enrollment has updated successfully");
Response.status(HttpStatus.SC_ACCEPTED); Response.status(Response.Status.ACCEPTED);
} else { } else {
responseMsg.setResponseMessage("Device not found for enrollment"); responseMsg.setResponseMessage("Device not found for enrollment");
Response.status(HttpStatus.SC_NOT_MODIFIED); Response.status(Response.Status.NOT_MODIFIED);
} }
return responseMsg; return responseMsg;
} catch (DeviceManagementServiceException deviceServiceMgtEx) { } catch (DeviceManagementServiceException deviceServiceMgtEx) {
@ -120,15 +118,13 @@ public class Enrollment {
log.error(errorMsg, deviceMgtEx); log.error(errorMsg, deviceMgtEx);
throw new AndroidAgentException(errorMsg, deviceMgtEx); throw new AndroidAgentException(errorMsg, deviceMgtEx);
} }
} }
@DELETE @DELETE
@Path("{id}") @Path("{id}")
public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException { public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException {
DeviceManagementService dmService;
Message responseMsg = new Message(); Message responseMsg = new Message();
boolean result; boolean result;
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
@ -136,10 +132,9 @@ public class Enrollment {
result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier);
if (result) { if (result) {
responseMsg.setResponseMessage("Device has removed successfully"); responseMsg.setResponseMessage("Device has removed successfully");
Response.status(HttpStatus.SC_OK);
} else { } else {
responseMsg.setResponseMessage("Device not found"); responseMsg.setResponseMessage("Device not found");
Response.status(HttpStatus.SC_NOT_FOUND); Response.status(Response.Status.NOT_FOUND);
} }
return responseMsg; return responseMsg;
} catch (DeviceManagementServiceException deviceServiceMgtEx) { } catch (DeviceManagementServiceException deviceServiceMgtEx) {

@ -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,
@ -24,7 +24,6 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.cdmserver.mobileservices.android.common.AndroidAgentException; import org.wso2.cdmserver.mobileservices.android.common.AndroidAgentException;
import org.wso2.cdmserver.mobileservices.android.util.AndroidAPIUtils; import org.wso2.cdmserver.mobileservices.android.util.AndroidAPIUtils;
import org.wso2.cdmserver.mobileservices.android.util.Message; import org.wso2.cdmserver.mobileservices.android.util.Message;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
@ -60,17 +59,14 @@ public class Operation {
operations = dmService.getOperationManager( operations = dmService.getOperationManager(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID) DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID)
.getOperations(deviceIdentifier); .getOperations(deviceIdentifier);
Response.status(HttpStatus.SC_OK);
return operations; return operations;
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
msg = "Error occurred while fetching the operation manager for the device type."; msg = "Error occurred while fetching the operation manager for the device type.";
log.error(msg, e); log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
throw new AndroidAgentException(msg, e); throw new AndroidAgentException(msg, e);
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
msg = "Error occurred while fetching the operation list for the device."; msg = "Error occurred while fetching the operation list for the device.";
log.error(msg, e); log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
throw new AndroidAgentException(msg, e); throw new AndroidAgentException(msg, e);
} }
} }
@ -84,7 +80,6 @@ public class Operation {
try { try {
dmService = AndroidAPIUtils.getDeviceManagementService(); dmService = AndroidAPIUtils.getDeviceManagementService();
} catch (DeviceManagementServiceException deviceMgtServiceEx) { } catch (DeviceManagementServiceException deviceMgtServiceEx) {
msg = "Device management service error"; msg = "Device management service error";
log.error(msg, deviceMgtServiceEx); log.error(msg, deviceMgtServiceEx);
@ -94,22 +89,19 @@ public class Operation {
try { try {
boolean result = dmService.getOperationManager("").addOperation(null, null); boolean result = dmService.getOperationManager("").addOperation(null, null);
if (result) { if (result) {
Response.status(HttpStatus.SC_OK);
responseMsg.setResponseMessage("Device has already enrolled"); responseMsg.setResponseMessage("Device has already enrolled");
} else { } else {
Response.status(HttpStatus.SC_NOT_FOUND); Response.status(Response.Status.NOT_FOUND);
responseMsg.setResponseMessage("Operation not found"); responseMsg.setResponseMessage("Operation not found");
} }
return responseMsg; return responseMsg;
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
msg = "Error occurred while fetching the operation manager for the device type."; msg = "Error occurred while fetching the operation manager for the device type.";
log.error(msg, e); log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
throw new AndroidAgentException(msg, e); throw new AndroidAgentException(msg, e);
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
msg = "Error occurred while updating the operation status for the device."; msg = "Error occurred while updating the operation status for the device.";
log.error(msg, e); log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
throw new AndroidAgentException(msg, e); throw new AndroidAgentException(msg, e);
} }
} }

@ -20,7 +20,7 @@
<parent> <parent>
<groupId>org.wso2.cdmserver</groupId> <groupId>org.wso2.cdmserver</groupId>
<artifactId>wso2cdmserver-product</artifactId> <artifactId>wso2cdmserver-product-mobileservices</artifactId>
<version>2.0.0-SNAPSHOT</version> <version>2.0.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath> <relativePath>../../../pom.xml</relativePath>
</parent> </parent>
@ -113,23 +113,19 @@
<dependency> <dependency>
<groupId>org.apache.cxf</groupId> <groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId> <artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.cxf</groupId> <groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId> <artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.cxf</groupId> <groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId> <artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
<version>${junit.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-httpclient</groupId> <groupId>commons-httpclient</groupId>

@ -17,4 +17,46 @@
<module>agents/windows/jax-rs</module> <module>agents/windows/jax-rs</module>
<module>agents/android/jax-rs</module> <module>agents/android/jax-rs</module>
</modules> </modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>${javax.ws.rs.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<cxf.version>2.6.1</cxf.version>
<junit.version>4.8.2</junit.version>
<jackson.version>1.9.0</jackson.version>
<javax.ws.rs.version>1.1.1</javax.ws.rs.version>
</properties>
</project> </project>

@ -35,5 +35,9 @@
<modules> <modules>
<module>modules/mobileservices</module> <module>modules/mobileservices</module>
<module>modules/rest-api</module>
<module>modules/p2-profile-gen</module>
<module>modules/distribution</module>
<module>modules/integration</module>
</modules> </modules>
</project> </project>

Loading…
Cancel
Save