Refactor Agents module

merge-requests/7/head
manoj 10 years ago
parent dd9bfdb6a7
commit 17457bf6d3

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

@ -251,7 +251,7 @@
<files>
<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>
<fileMode>755</fileMode>

@ -115,34 +115,23 @@
<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>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -153,13 +142,11 @@
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -170,11 +157,6 @@
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.0</version>
</dependency>
</dependencies>
<properties>
<cxf.version>2.6.1</cxf.version>
<junit.version>4.8.2</junit.version>
</properties>
</project>

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

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

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

@ -20,7 +20,7 @@
<parent>
<groupId>org.wso2.cdmserver</groupId>
<artifactId>wso2cdmserver-product</artifactId>
<artifactId>wso2cdmserver-product-mobileservices</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
@ -113,23 +113,19 @@
<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>commons-httpclient</groupId>

@ -17,4 +17,46 @@
<module>agents/windows/jax-rs</module>
<module>agents/android/jax-rs</module>
</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>

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

Loading…
Cancel
Save