From 92503ac0fe93605eadb8c83c6ad130af4888e975 Mon Sep 17 00:00:00 2001 From: harshanL Date: Fri, 16 Jan 2015 17:52:31 +0530 Subject: [PATCH] Added CDM-REST APIs --- .../device/mgt/common/DefaultOperation.java | 30 ---- .../carbon/device/mgt/common/Operation.java | 73 +++++--- .../device/mgt/common/OperationData.java | 75 -------- .../device/mgt/common/OperationFactory.java | 24 --- .../device/mgt/common/OperationManager.java | 29 +++- .../mgt/core/DeviceManagementRepository.java | 3 +- .../DeviceManagementServiceComponent.java | 3 +- .../AbstractMobileOperationManager.java | 17 +- .../dao/MobileDeviceManagementDAOFactory.java | 22 ++- .../dao/impl/DeviceOperationDAOImpl.java | 26 +-- .../mobile/dao/impl/MobileDeviceDAOImpl.java | 14 +- .../device/mgt/mobile/dto/MobileDevice.java | 18 ++ .../AndroidMobileOperationManager.java | 22 ++- .../util/MobileDeviceManagementUtil.java | 6 + .../main/java/cdm/api/android/Operation.java | 116 +++++++++++++ .../src/main/java/cdm/api/android/Test.java | 3 +- .../cdm/api/android/util/AndroidAPIUtils.java | 5 +- .../jax-rs/src/main/webapp/WEB-INF/web.xml | 4 - .../modules/distribution/src/assembly/bin.xml | 16 +- .../src/repository/dbscripts/cdm/h2.sql | 4 +- .../repository/dbscripts/cdm/plugins/h2.sql | 2 + product/modules/rest-api/pom.xml | 161 ++++++++++++++++++ .../org/wso2/carbon/cdm/api/Operation.java | 111 ++++++++++++ .../cdm/api/common/CDMAPIException.java | 57 +++++++ .../carbon/cdm/api/common/ErrorHandler.java | 30 ++++ .../carbon/cdm/api/common/ErrorMessage.java | 39 +++++ .../api/context/DeviceOperationContext.java | 52 ++++++ .../carbon/cdm/api/util/CDMAPIConstants.java | 23 +++ .../wso2/carbon/cdm/api/util/CDMAPIUtils.java | 51 ++++++ .../org/wso2/carbon/cdm/api/util/Message.java | 46 +++++ .../webapp/META-INF/webapp-classloading.xml | 33 ++++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 40 +++++ .../rest-api/src/main/webapp/WEB-INF/web.xml | 37 ++++ product/pom.xml | 2 +- 34 files changed, 1002 insertions(+), 192 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DefaultOperation.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationData.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationFactory.java create mode 100644 product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Operation.java create mode 100644 product/modules/rest-api/pom.xml create mode 100644 product/modules/rest-api/src/main/java/org/wso2/carbon/cdm/api/Operation.java create mode 100644 product/modules/rest-api/src/main/java/org/wso2/carbon/cdm/api/common/CDMAPIException.java create mode 100644 product/modules/rest-api/src/main/java/org/wso2/carbon/cdm/api/common/ErrorHandler.java create mode 100644 product/modules/rest-api/src/main/java/org/wso2/carbon/cdm/api/common/ErrorMessage.java create mode 100644 product/modules/rest-api/src/main/java/org/wso2/carbon/cdm/api/context/DeviceOperationContext.java create mode 100644 product/modules/rest-api/src/main/java/org/wso2/carbon/cdm/api/util/CDMAPIConstants.java create mode 100644 product/modules/rest-api/src/main/java/org/wso2/carbon/cdm/api/util/CDMAPIUtils.java create mode 100644 product/modules/rest-api/src/main/java/org/wso2/carbon/cdm/api/util/Message.java create mode 100644 product/modules/rest-api/src/main/webapp/META-INF/webapp-classloading.xml create mode 100644 product/modules/rest-api/src/main/webapp/WEB-INF/cxf-servlet.xml create mode 100644 product/modules/rest-api/src/main/webapp/WEB-INF/web.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DefaultOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DefaultOperation.java deleted file mode 100644 index f947e7f45f..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DefaultOperation.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * 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 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wso2.carbon.device.mgt.common; - -public class DefaultOperation implements Operation { - - @Override - public void init() { - - } - - @Override - public void execute() { - - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java index 8424142f7d..755be0b5cc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Operation.java @@ -1,33 +1,60 @@ -/** - * Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + package org.wso2.carbon.device.mgt.common; -/** - * This class needs to be implemented by all - */ -public interface Operation { +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Properties; + +@XmlRootElement +public class Operation { + + public enum Type { + CONFIG, MESSAGE, INFO + } + + private String code; + private Properties properties; + private Type type; + + @XmlElement + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + @XmlElement + public Properties getProperties() { + return properties; + } - /** - * Initializes any start-up resources required to execute a particular operation - */ - void init(); + public void setProperties(Properties properties) { + this.properties = properties; + } - /** - * Executes the functionality configured within the method implementation - */ - void execute(); + @XmlElement + public Type getType() { + return type; + } -} + public void setType(Type type) { + this.type = type; + } +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationData.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationData.java deleted file mode 100644 index 9cb0ad63d5..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationData.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * 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 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wso2.carbon.device.mgt.common; - -import java.util.Properties; - -public class OperationData { - - public enum Type { - CONFIG, MESSAGE, STATE - } - - private String name; - private boolean state; - private Properties properties; - private String text; - private Type type; - - public OperationData(String name, Type type) { - this.type = type; - this.name = name; - } - - public OperationData(String name, boolean state) { - this.name = name; - this.type = Type.STATE; - this.state = state; - } - - public OperationData(String name, Properties properties) { - this.name = name; - this.type = Type.CONFIG; - this.properties = properties; - } - - public OperationData(String name, String text) { - this.name = name; - this.type = Type.MESSAGE; - this.text = text; - } - - public Type getType() { - return type; - } - - public boolean getState() { - return state; - } - - public String getText() { - return text; - } - - public Properties getProperties() { - return properties; - } - - public String getName() { - return name; - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationFactory.java deleted file mode 100644 index 0c29aac79b..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationFactory.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * 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 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.wso2.carbon.device.mgt.common; - -public class OperationFactory { - - public static Operation getOperation(String type) { - return null; - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManager.java index f1446bda5d..e11f5740a3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationManager.java @@ -15,8 +15,33 @@ */ package org.wso2.carbon.device.mgt.common; +import java.util.List; + +/** + * This represents the Device Operation management functionality which should be implemented by + * the device type plugins. + */ public interface OperationManager { - boolean executeOperation(); + /** + * Method to add a operation to a device or a set of devices. + * + * @param operation Operation to be added + * @param devices List of DeviceIdentifiers to execute the operation + * @throws OperationManagementException If some unusual behaviour is observed while adding the + * operation + */ + public boolean addOperation(Operation operation, List devices) + throws OperationManagementException; + + /** + * Method to retrieve the list of available operations to a device. + * + * @param deviceId DeviceIdentifier of the device + * @throws OperationManagementException If some unusual behaviour is observed while fetching the + * operation list. + */ + public List getOperations(DeviceIdentifier deviceId) + throws OperationManagementException; -} +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java index 3f3340c1f3..9cf5ed8f3a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementRepository.java @@ -50,5 +50,4 @@ public class DeviceManagementRepository { public Map getProviders() { return providers; } - -} +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index daa67845bb..68d53be206 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -51,6 +51,7 @@ import org.wso2.carbon.user.core.service.RealmService; */ public class DeviceManagementServiceComponent { + public static final String SETUP_OPTION = "setup"; private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); private DeviceManagementRepository pluginRepository = new DeviceManagementRepository(); @@ -67,7 +68,7 @@ public class DeviceManagementServiceComponent { DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager); /* If -Dsetup option enabled then create device management database schema */ - String setupOption = System.getProperty("setup"); + String setupOption = System.getProperty(SETUP_OPTION); if (setupOption != null) { if (log.isDebugEnabled()) { log.debug("-Dsetup is enabled. Device management repository schema initialization is about " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java index e969045d15..4ddddf6ad0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java @@ -15,10 +15,21 @@ */ package org.wso2.carbon.device.mgt.mobile; -import org.wso2.carbon.device.mgt.common.OperationManager; +import org.wso2.carbon.device.mgt.common.*; -public abstract class AbstractMobileOperationManager implements OperationManager { +import java.util.List; +public abstract class AbstractMobileOperationManager implements OperationManager { + @Override + public List getOperations(DeviceIdentifier deviceIdentifier) + throws OperationManagementException { + return null; + } -} + @Override + public boolean addOperation(Operation operation, List devices) throws + OperationManagementException { + return true; + } +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java index 2d85c05df2..e60e0ec17d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceManagementDAOFactory.java @@ -20,7 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.mobile.DataSourceListener; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; -import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileDeviceDAOImpl; +import org.wso2.carbon.device.mgt.mobile.dao.impl.*; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementBundleActivator; @@ -52,6 +52,26 @@ public class MobileDeviceManagementDAOFactory implements DataSourceListener { return new MobileDeviceDAOImpl(dataSource); } + public static OperationDAO getOperationDAO(){ + return new OperationDAOImpl(dataSource); + } + + public static OperationPropertyDAO geOperationPropertyDAO(){ + return new OperationPropertyDAOImpl(dataSource); + } + + public static DeviceOperationDAO getDeviceOperationDAO(){ + return new DeviceOperationDAOImpl(dataSource); + } + + public static FeatureDAO getFeatureDAO(){ + return new FeatureDAOImpl(dataSource); + } + + public static FeaturePropertyDAO getFeaturePropertyDAO(){ + return new FeaturePropertyDAOImpl(dataSource); + } + public static MobileDataSourceConfig getMobileDeviceManagementConfig() { return mobileDataSourceConfig; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/DeviceOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/DeviceOperationDAOImpl.java index 26c5884d99..8f6b6a8058 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/DeviceOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/DeviceOperationDAOImpl.java @@ -49,7 +49,9 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { } } catch (SQLException e) { String msg = "Error occurred while adding device id - '" + - deviceOperation.getDeviceId() + " and operation id - " + deviceOperation.getOperationId() + "of mapping table MBL_DEVICE_OPERATION";; + deviceOperation.getDeviceId() + " and operation id - " + + deviceOperation.getOperationId() + "of mapping table MBL_DEVICE_OPERATION"; + ; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -79,7 +81,8 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { } } catch (SQLException e) { String msg = "Error occurred while updating device id - '" + - deviceOperation.getDeviceId() + " and operation id - " + deviceOperation.getOperationId() + "of mapping table MBL_DEVICE_OPERATION"; + deviceOperation.getDeviceId() + " and operation id - " + + deviceOperation.getOperationId() + "of mapping table MBL_DEVICE_OPERATION"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -102,12 +105,13 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { stmt.setString(1, deviceId); stmt.setInt(2, operationId); int rows = stmt.executeUpdate(); - if(rows>0){ + if (rows > 0) { status = true; } } catch (SQLException e) { - String msg = "Error occurred while deleting mapping table MBL_DEVICE_OPERATION with device id - '" + - deviceId + " and operation id - " + operationId; + String msg = + "Error occurred while deleting mapping table MBL_DEVICE_OPERATION with device id - '" + + deviceId + " and operation id - " + operationId; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -139,8 +143,9 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { break; } } catch (SQLException e) { - String msg = "Error occurred while fetching mapping table MBL_DEVICE_OPERATION entry with device id - '" + - deviceId + " and operation id - " + operationId; + String msg = + "Error occurred while fetching mapping table MBL_DEVICE_OPERATION entry with device id - '" + + deviceId + " and operation id - " + operationId; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -155,7 +160,7 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { Connection conn = null; PreparedStatement stmt = null; DeviceOperation deviceOperation = null; - List deviceOperations=new ArrayList(); + List deviceOperations = new ArrayList(); try { conn = this.getConnection(); String selectDBQuery = @@ -173,8 +178,9 @@ public class DeviceOperationDAOImpl implements DeviceOperationDAO { break; } } catch (SQLException e) { - String msg = "Error occurred while fetching mapping table MBL_DEVICE_OPERATION entry with device id - '" + - deviceId; + String msg = + "Error occurred while fetching mapping table MBL_DEVICE_OPERATION entry with device id - '" + + deviceId; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java index 66c547bdc5..7425fac75e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceDAOImpl.java @@ -64,6 +64,8 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { mobileDevice.setOsVersion(resultSet.getString(5)); mobileDevice.setModel(resultSet.getString(6)); mobileDevice.setVendor(resultSet.getString(7)); + mobileDevice.setLatitude(resultSet.getString(8)); + mobileDevice.setLongitude(resultSet.getString(9)); break; } } catch (SQLException e) { @@ -87,7 +89,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { conn = this.getConnection(); String createDBQuery = "INSERT INTO MBL_DEVICE(MOBILE_DEVICE_ID, REG_ID, IMEI, IMSI, OS_VERSION," + - "DEVICE_MODEL, VENDOR) VALUES (?, ?, ?, ?, ?, ?, ?)"; + "DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; stmt = conn.prepareStatement(createDBQuery); stmt.setString(1, mobileDevice.getMobileDeviceId()); @@ -97,6 +99,8 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { stmt.setString(5, mobileDevice.getOsVersion()); stmt.setString(6, mobileDevice.getModel()); stmt.setString(7, mobileDevice.getVendor()); + stmt.setString(8, mobileDevice.getLatitude()); + stmt.setString(8, mobileDevice.getLongitude()); int rows = stmt.executeUpdate(); if(rows>0){ status = true; @@ -122,7 +126,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { conn = this.getConnection(); String updateDBQuery = "UPDATE MBL_DEVICE SET REG_ID = ?, IMEI = ?, IMSI = ?, OS_VERSION = ?," + - "DEVICE_MODEL = ?, VENDOR = ? WHERE MOBILE_DEVICE_ID = ?"; + "DEVICE_MODEL = ?, VENDOR = ? , LATITUDE = ?, LONGITUDE = ? WHERE MOBILE_DEVICE_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); stmt.setString(1, mobileDevice.getRegId()); stmt.setString(2, mobileDevice.getImei()); @@ -130,7 +134,9 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { stmt.setString(4, mobileDevice.getOsVersion()); stmt.setString(5, mobileDevice.getModel()); stmt.setString(6, mobileDevice.getVendor()); - stmt.setString(7, mobileDevice.getMobileDeviceId()); + stmt.setString(7, mobileDevice.getLatitude()); + stmt.setString(8, mobileDevice.getLongitude()); + stmt.setString(9, mobileDevice.getMobileDeviceId()); int rows = stmt.executeUpdate(); if(rows>0){ status = true; @@ -192,6 +198,8 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO { mobileDevice.setOsVersion(resultSet.getString(5)); mobileDevice.setModel(resultSet.getString(6)); mobileDevice.setVendor(resultSet.getString(7)); + mobileDevice.setLatitude(resultSet.getString(8)); + mobileDevice.setLongitude(resultSet.getString(9)); mobileDevices.add(mobileDevice); } return mobileDevices; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDevice.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDevice.java index 8a783e52a2..8c188c3c9e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDevice.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDevice.java @@ -30,6 +30,8 @@ public class MobileDevice implements Serializable { private String osVersion; private String model; private String vendor; + private String latitude; + private String longitude; public String getMobileDeviceId() { return mobileDeviceId; @@ -86,4 +88,20 @@ public class MobileDevice implements Serializable { public void setVendor(String vendor) { this.vendor = vendor; } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java index 61f3d94f1f..e4a69a72b4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidMobileOperationManager.java @@ -15,13 +15,25 @@ */ package org.wso2.carbon.device.mgt.mobile.impl.android; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.Operation; +import org.wso2.carbon.device.mgt.common.OperationManagementException; import org.wso2.carbon.device.mgt.mobile.AbstractMobileOperationManager; +import java.util.List; + public class AndroidMobileOperationManager extends AbstractMobileOperationManager { - @Override - public boolean executeOperation() { - return false; - } + @Override + public boolean addOperation(Operation operation, List devices) throws + OperationManagementException { + return false; + } + + @Override + public List getOperations(DeviceIdentifier deviceIdentifier) + throws OperationManagementException { + return null; + } -} +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java index 99b8ff6a1c..3a045b7e9d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/util/MobileDeviceManagementUtil.java @@ -41,6 +41,8 @@ public class MobileDeviceManagementUtil { private static final String MOBILE_DEVICE_VENDOR = "vendor"; private static final String MOBILE_DEVICE_OS_VERSION = "osVersion"; private static final String MOBILE_DEVICE_MODEL = "model"; + private static final String MOBILE_DEVICE_LATITUDE = "latitude"; + private static final String MOBILE_DEVICE_LONGITUDE = "longitude"; public static Document convertToDocument(File file) throws DeviceManagementException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -86,6 +88,8 @@ public class MobileDeviceManagementUtil { mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL)); mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION)); mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR)); + mobileDevice.setLatitude(getPropertyValue(device,MOBILE_DEVICE_LATITUDE)); + mobileDevice.setLongitude(getPropertyValue(device,MOBILE_DEVICE_LONGITUDE)); } return mobileDevice; } @@ -101,6 +105,8 @@ public class MobileDeviceManagementUtil { propertyList.add(getProperty(MOBILE_DEVICE_MODEL,mobileDevice.getModel())); propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION,mobileDevice.getOsVersion())); propertyList.add(getProperty(MOBILE_DEVICE_VENDOR,mobileDevice.getVendor())); + propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE,mobileDevice.getLatitude())); + propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE,mobileDevice.getLongitude())); device.setProperties(propertyList); device.setDeviceIdentifier(mobileDevice.getMobileDeviceId()); } diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Operation.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Operation.java new file mode 100644 index 0000000000..f6e580273c --- /dev/null +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Operation.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cdm.api.android; + +import cdm.api.android.common.AndroidAgentException; +import cdm.api.android.util.AndroidAPIUtils; +import cdm.api.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.*; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; + +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import java.util.List; + +/** + * Android Device Operation REST-API implementation. + */ +@Produces({ "application/json", "application/xml" }) +@Consumes({ "application/json", "application/xml" }) +public class Operation { + + private static Log log = LogFactory.getLog(Operation.class); + + @GET + @Path("{id}") + public List getAllOperations( + @PathParam("id") String id) throws + AndroidAgentException { + List operations; + String msg; + DeviceManagementService dmService; + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + } catch (DeviceManagementServiceException deviceMgtServiceEx) { + msg = "Device management service error"; + log.error(msg, deviceMgtServiceEx); + throw new AndroidAgentException(msg, deviceMgtServiceEx); + } + + try { + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + 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); + } + } + + @PUT + public Message updateOperation() throws + AndroidAgentException { + String msg; + DeviceManagementService dmService; + Message responseMsg = new Message(); + + try { + dmService = AndroidAPIUtils.getDeviceManagementService(); + + } catch (DeviceManagementServiceException deviceMgtServiceEx) { + msg = "Device management service error"; + log.error(msg, deviceMgtServiceEx); + throw new AndroidAgentException(msg, deviceMgtServiceEx); + } + + 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); + 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); + } + } +} \ No newline at end of file diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java index caf7cf5382..fd63ede3b0 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java @@ -32,5 +32,4 @@ public class Test { throw new DeviceManagementException("test ex"); } - -} +} \ No newline at end of file diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtils.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtils.java index c771704100..eb38b993eb 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtils.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/util/AndroidAPIUtils.java @@ -50,8 +50,9 @@ public class AndroidAPIUtils { dmService = (DeviceManagementService) ctx.getOSGiService(DeviceManagementService.class, null); if (dmService == null){ - log.error("device management service not initialized"); - throw new DeviceManagementServiceException("device management service not initialized"); + String msg = "Device management service not initialized"; + log.error(msg); + throw new DeviceManagementServiceException(msg); } PrivilegedCarbonContext.endTenantFlow(); return dmService; diff --git a/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/web.xml b/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/web.xml index 1a5ca4fedd..2154304d9e 100644 --- a/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/web.xml +++ b/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/web.xml @@ -25,10 +25,6 @@ org.apache.cxf.transport.servlet.CXFServlet - - service-list-stylesheet - servicelist.css - 1 diff --git a/product/modules/distribution/src/assembly/bin.xml b/product/modules/distribution/src/assembly/bin.xml index 8af63134c0..ac4ba28cdc 100644 --- a/product/modules/distribution/src/assembly/bin.xml +++ b/product/modules/distribution/src/assembly/bin.xml @@ -128,7 +128,8 @@ - ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/resources/rxts/ + + ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/resources/rxts/ wso2cdm-${project.version}/repository/resources/rxts/ @@ -205,8 +206,11 @@ - ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/resources - ${project.artifactId}-${project.version}/repository/resources + + ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/resources + + ${project.artifactId}-${project.version}/repository/resources + @@ -241,6 +245,12 @@ 755 + + ../rest-api/target/wso2cdm-api.war + wso2cdm-${pom.version}/repository/deployment/server/webapps + + 755 + + + + + + + false + + + CXF,Carbon + diff --git a/product/modules/rest-api/src/main/webapp/WEB-INF/cxf-servlet.xml b/product/modules/rest-api/src/main/webapp/WEB-INF/cxf-servlet.xml new file mode 100644 index 0000000000..a3725edfc4 --- /dev/null +++ b/product/modules/rest-api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + diff --git a/product/modules/rest-api/src/main/webapp/WEB-INF/web.xml b/product/modules/rest-api/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..5a0ce211b3 --- /dev/null +++ b/product/modules/rest-api/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,37 @@ + + + + CDM-API + + JAX-WS/JAX-RS CDM Endpoint + JAX-WS/JAX-RS Servlet + CXFServlet + + org.apache.cxf.transport.servlet.CXFServlet + + 1 + + + CXFServlet + /* + + + 60 + + diff --git a/product/pom.xml b/product/pom.xml index 0d2fdedd5e..ce49dcadd1 100644 --- a/product/pom.xml +++ b/product/pom.xml @@ -34,7 +34,7 @@ WSO2 Connected Device Manager (CDM) - Parent - + modules/rest-api modules/agents/windows/jax-rs modules/agents/android/jax-rs modules/p2-profile-gen