diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java index 2b9c570c9f..16c9ac7030 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/config/datasource/MobileDataSourceConfig.java @@ -28,7 +28,7 @@ public class MobileDataSourceConfig { private JNDILookupDefinition jndiLookupDefinition; @XmlElement(name = "JndiLookupDefinition", nillable = true) - public JNDILookupDefinition getJndiLookupDefintion() { + public JNDILookupDefinition getJndiLookupDefinition() { return jndiLookupDefinition; } 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 8415271d2f..831a14452d 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 @@ -62,7 +62,7 @@ public class MobileDeviceManagementDAOFactory { throw new RuntimeException("Device Management Repository data source configuration " + "is null and thus, is not initialized"); } - JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion(); + JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); if (jndiConfig != null) { if (log.isDebugEnabled()) { log.debug("Initializing Device Management Repository data source using the JNDI " + @@ -98,16 +98,16 @@ public class MobileDeviceManagementDAOFactory { return new MobileOperationPropertyDAOImpl(dataSource); } - public static MobileDeviceOperationDAO getMobileDeviceOperationDAO() { - return new MobileDeviceOperationDAOImpl(dataSource); + public static MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() { + return new MobileDeviceOperationMappingDAOImpl(dataSource); } - public static FeatureDAO getFeatureDAO() { - return new FeatureDAOImpl(dataSource); + public static MobileFeatureDAO getFeatureDAO() { + return new MobileFeatureDAOImpl(dataSource); } - public static FeaturePropertyDAO getFeaturePropertyDAO() { - return new FeaturePropertyDAOImpl(dataSource); + public static MobileFeaturePropertyDAO getFeaturePropertyDAO() { + return new MobileFeaturePropertyDAOImpl(dataSource); } public static MobileDataSourceConfig getMobileDeviceManagementConfig() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationDAO.java deleted file mode 100644 index ad2710e2f6..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationDAO.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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 org.wso2.carbon.device.mgt.mobile.dao; - -import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperation; - -import java.util.List; - -/** - * This class represents the mapping between device and operations. - */ -public interface MobileDeviceOperationDAO { - /** - * Add a new mapping to plugin device_operation table. - * - * @param deviceOperation DeviceOperation object that holds data related to the DeviceOperation - * to be inserted. - * @return The status of the operation. If the insert was successful or not. - * @throws MobileDeviceManagementDAOException - */ - boolean addMobileDeviceOperation(MobileDeviceOperation deviceOperation) - throws MobileDeviceManagementDAOException; - - /** - * Update a feature in the feature table. - * - * @param deviceOperation DeviceOperation object that holds data has to be updated. - * @return The status of the operation. If the update was successful or not. - * @throws MobileDeviceManagementDAOException - */ - boolean updateMobileDeviceOperation(MobileDeviceOperation deviceOperation) - throws MobileDeviceManagementDAOException; - - /** - * Delete a given device operation from device operation table. - * - * @param deviceId Device id of the mapping to be deleted. - * @param operationId Operation id of the mapping to be deleted. - * @return The status of the operation. If the deletion was successful or not. - * @throws MobileDeviceManagementDAOException - */ - boolean deleteMobileDeviceOperation(String deviceId, int operationId) - throws MobileDeviceManagementDAOException; - - /** - * Retrieve a given device operation from plugin database. - * - * @param deviceId Device id of the mapping to be retrieved. - * @param operationId Operation id of the mapping to be retrieved. - * @return DeviceOperation object that holds data of the device operation mapping represented by - * deviceId and operationId. - * @throws MobileDeviceManagementDAOException - */ - MobileDeviceOperation getMobileDeviceOperation(String deviceId, int operationId) - throws MobileDeviceManagementDAOException; - - /** - * Retrieve all the device operation mapping from plugin database. - * - * @return Device operation mapping object list. - * @throws MobileDeviceManagementDAOException - */ - List getAllMobileDeviceOperationsOfDevice(String deviceId) - throws MobileDeviceManagementDAOException; -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java new file mode 100644 index 0000000000..4f8c798026 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileDeviceOperationMappingDAO.java @@ -0,0 +1,110 @@ +/* + * 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 org.wso2.carbon.device.mgt.mobile.dao; + +import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping; + +import java.util.List; + +/** + * This class represents the mapping between mobile device and operations. + */ +public interface MobileDeviceOperationMappingDAO { + /** + * Add a new mobile device operation mapping to the table. + * + * @param deviceOperation MobileDeviceOperation object that holds data related to the MobileDeviceOperation + * to be inserted. + * @return The status of the operation. If the insert was successful or not. + * @throws MobileDeviceManagementDAOException + */ + boolean addMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation) + throws MobileDeviceManagementDAOException; + + /** + * Updates a mobile device operation mapping. + * + * @param deviceOperation MobileDeviceOperation object that holds data has to be updated. + * @return The status of the operation. If the update was successful or not. + * @throws MobileDeviceManagementDAOException + */ + boolean updateMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation) + throws MobileDeviceManagementDAOException; + + /** + * Updates a mobile device operation mapping to In-Progress state. + * + * @param deviceId Device id of the mapping to be deleted. + * @param operationId Operation id of the mapping to be deleted. + * @return The status of the operation. If the update was successful or not. + * @throws MobileDeviceManagementDAOException + */ + boolean updateMobileDeviceOperationToInProgress(String deviceId, int operationId) + throws MobileDeviceManagementDAOException; + + /** + * Updates a mobile device operation mapping to completed state. + * + * @param deviceId Device id of the mapping to be deleted. + * @param operationId Operation id of the mapping to be deleted. + * @return The status of the operation. If the update was successful or not. + * @throws MobileDeviceManagementDAOException + */ + boolean updateMobileDeviceOperationToCompleted(String deviceId, int operationId) + throws MobileDeviceManagementDAOException; + + /** + * Delete a given mobile device operation mapping from table. + * + * @param deviceId Device id of the mapping to be deleted. + * @param operationId Operation id of the mapping to be deleted. + * @return The status of the operation. If the deletion was successful or not. + * @throws MobileDeviceManagementDAOException + */ + boolean deleteMobileDeviceOperation(String deviceId, int operationId) + throws MobileDeviceManagementDAOException; + + /** + * Retrieves a given mobile device operation from the plugin database. + * + * @param deviceId Device id of the mapping to be retrieved. + * @param operationId Operation id of the mapping to be retrieved. + * @return MobileDeviceOperation object that holds data of the device operation mapping represented by + * deviceId and operationId. + * @throws MobileDeviceManagementDAOException + */ + MobileDeviceOperationMapping getMobileDeviceOperation(String deviceId, int operationId) + throws MobileDeviceManagementDAOException; + + /** + * Retrieves all the of mobile device operation mappings relavent to the given mobile device. + * + * @return Device operation mapping object list. + * @throws MobileDeviceManagementDAOException + */ + List getAllMobileDeviceOperationsOfDevice(String deviceId) + throws MobileDeviceManagementDAOException; + + /** + * Retrieves all the pending device operation mappings of a mobiel device. + * + * @return Device operation mapping object list. + * @throws MobileDeviceManagementDAOException + */ + List getAllPendingOperationsOfMobileDevice(String deviceId) + throws MobileDeviceManagementDAOException; +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/FeatureDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java similarity index 77% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/FeatureDAO.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java index 0997dd0321..8b516443ac 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/FeatureDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeatureDAO.java @@ -16,33 +16,33 @@ package org.wso2.carbon.device.mgt.mobile.dao; -import org.wso2.carbon.device.mgt.mobile.dto.Feature; +import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; import java.util.List; /** - * This class represents the key operations associated with persisting feature related + * This class represents the key operations associated with persisting mobile feature related * information. */ -public interface FeatureDAO { +public interface MobileFeatureDAO { /** * Add a new feature to feature table. * - * @param feature Feature object that holds data related to the feature to be inserted. + * @param mobileFeature Feature object that holds data related to the feature to be inserted. * @return The status of the operation. If the insert was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean addFeature(Feature feature) throws MobileDeviceManagementDAOException; + boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException; /** * Update a feature in the feature table. * - * @param feature Feature object that holds data has to be updated. + * @param mobileFeature Feature object that holds data has to be updated. * @return The status of the operation. If the update was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean updateFeature(Feature feature) throws MobileDeviceManagementDAOException; + boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException; /** * Delete a feature from feature table when the feature id is given. @@ -69,7 +69,7 @@ public interface FeatureDAO { * @return Feature object that holds data of the feature represented by featureId. * @throws MobileDeviceManagementDAOException */ - Feature getFeatureById(String featureId) throws MobileDeviceManagementDAOException; + MobileFeature getFeatureById(String featureId) throws MobileDeviceManagementDAOException; /** * Retrieve a given feature from feature table when the feature code is given. @@ -78,7 +78,7 @@ public interface FeatureDAO { * @return Feature object that holds data of the feature represented by featureCode. * @throws MobileDeviceManagementDAOException */ - Feature getFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException; + MobileFeature getFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException; /** * Retrieve all the features from plugin specific database. @@ -86,5 +86,5 @@ public interface FeatureDAO { * @return Feature object list. * @throws MobileDeviceManagementDAOException */ - List getAllFeatures() throws MobileDeviceManagementDAOException; + List getAllFeatures() throws MobileDeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/FeaturePropertyDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java similarity index 77% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/FeaturePropertyDAO.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java index adf014dc7d..a61a598a97 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/FeaturePropertyDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileFeaturePropertyDAO.java @@ -16,33 +16,33 @@ package org.wso2.carbon.device.mgt.mobile.dao; -import org.wso2.carbon.device.mgt.mobile.dto.FeatureProperty; +import org.wso2.carbon.device.mgt.mobile.dto.MobileFeatureProperty; import java.util.List; /** - * This class represents the key operations associated with persisting feature property related + * This class represents the key operations associated with persisting mobile feature property related * information. */ -public interface FeaturePropertyDAO { +public interface MobileFeaturePropertyDAO { /** * Add a new feature property to feature property table. * - * @param featureProperty Feature property object that holds data related to the feature property to be inserted. + * @param mobileFeatureProperty Feature property object that holds data related to the feature property to be inserted. * @return The status of the operation. If the insert was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean addFeatureProperty(FeatureProperty featureProperty) + boolean addFeatureProperty(MobileFeatureProperty mobileFeatureProperty) throws MobileDeviceManagementDAOException; /** * Update a feature property in the feature property table. * - * @param featureProperty Feature property object that holds data has to be updated. + * @param mobileFeatureProperty Feature property object that holds data has to be updated. * @return The status of the operation. If the update was successful or not. * @throws MobileDeviceManagementDAOException */ - boolean updateFeatureProperty(FeatureProperty featureProperty) + boolean updateFeatureProperty(MobileFeatureProperty mobileFeatureProperty) throws MobileDeviceManagementDAOException; /** @@ -61,7 +61,7 @@ public interface FeaturePropertyDAO { * @return Feature property object that holds data of the feature property represented by propertyId. * @throws MobileDeviceManagementDAOException */ - FeatureProperty getFeatureProperty(String property) throws MobileDeviceManagementDAOException; + MobileFeatureProperty getFeatureProperty(String property) throws MobileDeviceManagementDAOException; /** * Retrieve a list of feature property corresponds to a feature id . @@ -70,7 +70,7 @@ public interface FeaturePropertyDAO { * @return Feature property object that holds data of the feature property represented by propertyId. * @throws MobileDeviceManagementDAOException */ - List getFeaturePropertyOfFeature(String featureId) + List getFeaturePropertyOfFeature(String featureId) throws MobileDeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationDAO.java index bdd69c7edf..d43ec82fea 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationDAO.java @@ -19,7 +19,7 @@ package org.wso2.carbon.device.mgt.mobile.dao; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; /** - * This class represents the key operations associated with persisting operation related + * This class represents the key operations associated with persisting mobile operation related * information. */ public interface MobileOperationDAO { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationPropertyDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationPropertyDAO.java index 4d8ef7eebb..3bb7c64611 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationPropertyDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/MobileOperationPropertyDAO.java @@ -21,7 +21,7 @@ import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty; import java.util.List; /** - * This class represents the key operations associated with persisting operation property related + * This class represents the key operations associated with persisting mobile operation property related * information. */ public interface MobileOperationPropertyDAO { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationDAOImpl.java deleted file mode 100644 index f15af1ac53..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationDAOImpl.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * 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 org.wso2.carbon.device.mgt.mobile.dao.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceOperationDAO; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperation; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -/** - * Implementation of MobileDeviceOperationDAO. - */ -public class MobileDeviceOperationDAOImpl implements MobileDeviceOperationDAO { - - private DataSource dataSource; - private static final Log log = LogFactory.getLog(MobileDeviceOperationDAOImpl.class); - - public MobileDeviceOperationDAOImpl(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Override - public boolean addMobileDeviceOperation(MobileDeviceOperation deviceOperation) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String createDBQuery = - "INSERT INTO MBL_DEVICE_OPERATION_MAPPING (DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE) VALUES (?, ?, ?, ?)"; - - stmt = conn.prepareStatement(createDBQuery); - stmt.setString(1, deviceOperation.getDeviceId()); - stmt.setLong(2, deviceOperation.getOperationId()); - stmt.setLong(3, deviceOperation.getSentDate()); - stmt.setLong(4, deviceOperation.getReceivedDate()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - } - } catch (SQLException e) { - String msg = "Error occurred while adding device id - '" + - deviceOperation.getDeviceId() + " and operation id - " + - deviceOperation.getOperationId() + - " to mapping table MBL_DEVICE_OPERATION"; - ; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean updateMobileDeviceOperation(MobileDeviceOperation deviceOperation) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String updateDBQuery = - "UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ? WHERE DEVICE_ID = ? AND OPERATION_ID=?"; - stmt = conn.prepareStatement(updateDBQuery); - stmt.setLong(1, deviceOperation.getSentDate()); - stmt.setLong(2, deviceOperation.getReceivedDate()); - stmt.setString(3, deviceOperation.getDeviceId()); - stmt.setInt(4, deviceOperation.getOperationId()); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - } - } catch (SQLException e) { - String msg = "Error occurred while updating device id - '" + - deviceOperation.getDeviceId() + " and operation id - " + - deviceOperation.getOperationId() + " in table MBL_DEVICE_OPERATION"; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public boolean deleteMobileDeviceOperation(String deviceId, int operationId) - throws MobileDeviceManagementDAOException { - boolean status = false; - Connection conn = null; - PreparedStatement stmt = null; - try { - conn = this.getConnection(); - String deleteDBQuery = - "DELETE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?"; - stmt = conn.prepareStatement(deleteDBQuery); - stmt.setString(1, deviceId); - stmt.setInt(2, operationId); - int rows = stmt.executeUpdate(); - if (rows > 0) { - status = true; - } - } catch (SQLException e) { - String msg = - "Error occurred while deleting the table entry MBL_DEVICE_OPERATION with device id - '" + - deviceId + " and operation id - " + operationId; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return status; - } - - @Override - public MobileDeviceOperation getMobileDeviceOperation(String deviceId, int operationId) - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - MobileDeviceOperation deviceOperation = null; - try { - conn = this.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setString(1, deviceId); - stmt.setInt(2, operationId); - ResultSet resultSet = stmt.executeQuery(); - while (resultSet.next()) { - deviceOperation = new MobileDeviceOperation(); - deviceOperation.setDeviceId(resultSet.getString(1)); - deviceOperation.setOperationId(resultSet.getInt(2)); - deviceOperation.setSentDate(resultSet.getInt(3)); - deviceOperation.setReceivedDate(resultSet.getInt(4)); - break; - } - } catch (SQLException e) { - String msg = - "Error occurred while fetching table MBL_DEVICE_OPERATION entry with device id - '" + - deviceId + " and operation id - " + operationId; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return deviceOperation; - } - - @Override - public List getAllMobileDeviceOperationsOfDevice(String deviceId) - throws MobileDeviceManagementDAOException { - Connection conn = null; - PreparedStatement stmt = null; - MobileDeviceOperation deviceOperation = null; - List deviceOperations = new ArrayList(); - try { - conn = this.getConnection(); - String selectDBQuery = - "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?"; - stmt = conn.prepareStatement(selectDBQuery); - stmt.setString(1, deviceId); - ResultSet resultSet = stmt.executeQuery(); - while (resultSet.next()) { - deviceOperation = new MobileDeviceOperation(); - deviceOperation.setDeviceId(resultSet.getString(1)); - deviceOperation.setOperationId(resultSet.getInt(2)); - deviceOperation.setSentDate(resultSet.getInt(3)); - deviceOperation.setReceivedDate(resultSet.getInt(4)); - deviceOperations.add(deviceOperation); - } - } catch (SQLException e) { - String msg = - "Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of device id - '" + - deviceId; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } finally { - MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); - } - return deviceOperations; - } - - private Connection getConnection() throws MobileDeviceManagementDAOException { - try { - return dataSource.getConnection(); - } catch (SQLException e) { - String msg = "Error occurred while obtaining a connection from the mobile device " + - "management metadata repository datasource."; - log.error(msg, e); - throw new MobileDeviceManagementDAOException(msg, e); - } - } -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java new file mode 100644 index 0000000000..387b09d17a --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileDeviceOperationMappingDAOImpl.java @@ -0,0 +1,331 @@ +/* + * 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 org.wso2.carbon.device.mgt.mobile.dao.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceOperationMappingDAO; +import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; +import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * Implementation of MobileDeviceOperationMappingDAO. + */ +public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperationMappingDAO { + + private DataSource dataSource; + private static final Log log = LogFactory.getLog(MobileDeviceOperationMappingDAOImpl.class); + + public MobileDeviceOperationMappingDAOImpl(DataSource dataSource) { + this.dataSource = dataSource; + } + + @Override + public boolean addMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation) + throws MobileDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + String createDBQuery = + "INSERT INTO MBL_DEVICE_OPERATION_MAPPING (DEVICE_ID, OPERATION_ID, SENT_DATE, " + + "RECEIVED_DATE, STATUS) VALUES (?, ?, ?, ?, ?)"; + + stmt = conn.prepareStatement(createDBQuery); + stmt.setString(1, deviceOperation.getDeviceId()); + stmt.setLong(2, deviceOperation.getOperationId()); + stmt.setLong(3, deviceOperation.getSentDate()); + stmt.setLong(4, deviceOperation.getReceivedDate()); + stmt.setString(5, deviceOperation.getStatus().name()); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + } + } catch (SQLException e) { + String msg = "Error occurred while adding device id - '" + + deviceOperation.getDeviceId() + " and operation id - " + + deviceOperation.getOperationId() + + " to mapping table MBL_DEVICE_OPERATION"; + ; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return status; + } + + @Override + public boolean updateMobileDeviceOperation(MobileDeviceOperationMapping deviceOperation) + throws MobileDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + String updateDBQuery = + "UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ?, STATUS = ? " + + "WHERE DEVICE_ID = ? AND OPERATION_ID=?"; + stmt = conn.prepareStatement(updateDBQuery); + stmt.setLong(1, deviceOperation.getSentDate()); + stmt.setLong(2, deviceOperation.getReceivedDate()); + stmt.setString(3, deviceOperation.getStatus().name()); + stmt.setString(4, deviceOperation.getDeviceId()); + stmt.setInt(5, deviceOperation.getOperationId()); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + } + } catch (SQLException e) { + String msg = "Error occurred while updating device id - '" + + deviceOperation.getDeviceId() + " and operation id - " + + deviceOperation.getOperationId() + " in table MBL_DEVICE_OPERATION"; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return status; + } + + @Override + public boolean updateMobileDeviceOperationToInProgress(String deviceId, int operationId) + throws MobileDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + String updateDBQuery = + "UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, STATUS = ? " + + "WHERE DEVICE_ID = ? AND OPERATION_ID=?"; + stmt = conn.prepareStatement(updateDBQuery); + stmt.setLong(1, new Date().getTime()); + stmt.setString(2, MobileDeviceOperationMapping.Status.INPROGRESS.name()); + stmt.setString(3, deviceId); + stmt.setInt(4, operationId); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + } + } catch (SQLException e) { + String msg = + "Error occurred while updating the Status of operation to in-progress of device id - '" + + deviceId + " and operation id - " + + operationId + " in table MBL_DEVICE_OPERATION"; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return status; + } + + @Override + public boolean updateMobileDeviceOperationToCompleted(String deviceId, + int operationId) + throws MobileDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + String updateDBQuery = + "UPDATE MBL_DEVICE_OPERATION_MAPPING SET RECEIVED_DATE = ?, STATUS = ? " + + "WHERE DEVICE_ID = ? AND OPERATION_ID=?"; + stmt = conn.prepareStatement(updateDBQuery); + stmt.setLong(1, new Date().getTime()); + stmt.setString(2, MobileDeviceOperationMapping.Status.COMPLETED.name()); + stmt.setString(3, deviceId); + stmt.setInt(4, operationId); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + } + } catch (SQLException e) { + String msg = + "Error occurred while updating the Status of operation to completed of device id - '" + + deviceId + " and operation id - " + + operationId + " in table MBL_DEVICE_OPERATION"; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return status; + } + + @Override + public boolean deleteMobileDeviceOperation(String deviceId, int operationId) + throws MobileDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + String deleteDBQuery = + "DELETE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?"; + stmt = conn.prepareStatement(deleteDBQuery); + stmt.setString(1, deviceId); + stmt.setInt(2, operationId); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + } + } catch (SQLException e) { + String msg = + "Error occurred while deleting the table entry MBL_DEVICE_OPERATION with " + + " device id - '" + deviceId + " and operation id - " + operationId; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return status; + } + + @Override + public MobileDeviceOperationMapping getMobileDeviceOperation(String deviceId, int operationId) + throws MobileDeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + MobileDeviceOperationMapping mblDeviceOperation = null; + try { + conn = this.getConnection(); + String selectDBQuery = + "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " + + "MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?"; + stmt = conn.prepareStatement(selectDBQuery); + stmt.setString(1, deviceId); + stmt.setInt(2, operationId); + ResultSet resultSet = stmt.executeQuery(); + while (resultSet.next()) { + mblDeviceOperation = new MobileDeviceOperationMapping(); + mblDeviceOperation.setDeviceId(resultSet.getString(1)); + mblDeviceOperation.setOperationId(resultSet.getInt(2)); + mblDeviceOperation.setSentDate(resultSet.getInt(3)); + mblDeviceOperation.setReceivedDate(resultSet.getInt(4)); + mblDeviceOperation.setStatus(resultSet.getString(5)); + break; + } + } catch (SQLException e) { + String msg = + "Error occurred while fetching table MBL_DEVICE_OPERATION entry with device id - '" + + deviceId + " and operation id - " + operationId; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return mblDeviceOperation; + } + + @Override + public List getAllMobileDeviceOperationsOfDevice(String deviceId) + throws MobileDeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + MobileDeviceOperationMapping mblDeviceOperation = null; + List mblDeviceOperations = new ArrayList(); + try { + conn = this.getConnection(); + String selectDBQuery = + "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " + + "MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?"; + stmt = conn.prepareStatement(selectDBQuery); + stmt.setString(1, deviceId); + ResultSet resultSet = stmt.executeQuery(); + while (resultSet.next()) { + mblDeviceOperation = new MobileDeviceOperationMapping(); + mblDeviceOperation.setDeviceId(resultSet.getString(1)); + mblDeviceOperation.setOperationId(resultSet.getInt(2)); + mblDeviceOperation.setSentDate(resultSet.getInt(3)); + mblDeviceOperation.setReceivedDate(resultSet.getInt(4)); + mblDeviceOperation.setStatus(resultSet.getString(5)); + mblDeviceOperations.add(mblDeviceOperation); + } + } catch (SQLException e) { + String msg = + "Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of " + + "device id - '" + deviceId; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return mblDeviceOperations; + } + + @Override + public List getAllPendingOperationsOfMobileDevice(String deviceId) + throws MobileDeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + MobileDeviceOperationMapping mblDeviceOperation = null; + List mblDeviceOperations = new ArrayList(); + try { + + conn = this.getConnection(); + String selectDBQuery = + "SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM" + + " MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND STATUS = 'NEW'"; + stmt = conn.prepareStatement(selectDBQuery); + stmt.setString(1, deviceId); + ResultSet resultSet = stmt.executeQuery(); + while (resultSet.next()) { + mblDeviceOperation = new MobileDeviceOperationMapping(); + mblDeviceOperation.setDeviceId(resultSet.getString(1)); + mblDeviceOperation.setOperationId(resultSet.getInt(2)); + mblDeviceOperation.setSentDate(resultSet.getInt(3)); + mblDeviceOperation.setReceivedDate(resultSet.getInt(4)); + mblDeviceOperation.setStatus(resultSet.getString(5)); + mblDeviceOperations.add(mblDeviceOperation); + } + } catch (SQLException e) { + String msg = + "Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of" + + " device id - '" + deviceId; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } finally { + MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return mblDeviceOperations; + } + + private Connection getConnection() throws MobileDeviceManagementDAOException { + try { + return dataSource.getConnection(); + } catch (SQLException e) { + String msg = "Error occurred while obtaining a connection from the mobile device " + + "management metadata repository datasource."; + log.error(msg, e); + throw new MobileDeviceManagementDAOException(msg, e); + } + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java similarity index 74% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeatureDAOImpl.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java index 429349e186..6f983089d8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeatureDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeatureDAOImpl.java @@ -18,10 +18,10 @@ package org.wso2.carbon.device.mgt.mobile.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.dao.FeatureDAO; +import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.Feature; +import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; import javax.sql.DataSource; import java.sql.Connection; @@ -32,19 +32,19 @@ import java.util.ArrayList; import java.util.List; /** - * Implementation of FeatureDAO. + * Implementation of MobileFeatureDAO. */ -public class FeatureDAOImpl implements FeatureDAO { +public class MobileFeatureDAOImpl implements MobileFeatureDAO { private DataSource dataSource; - private static final Log log = LogFactory.getLog(FeatureDAOImpl.class); + private static final Log log = LogFactory.getLog(MobileFeatureDAOImpl.class); - public FeatureDAOImpl(DataSource dataSource) { + public MobileFeatureDAOImpl(DataSource dataSource) { this.dataSource = dataSource; } @Override - public boolean addFeature(Feature feature) throws MobileDeviceManagementDAOException { + public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; PreparedStatement stmt = null; @@ -54,16 +54,16 @@ public class FeatureDAOImpl implements FeatureDAO { "INSERT INTO MBL_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; stmt = conn.prepareStatement(createDBQuery); - stmt.setString(1, feature.getCode()); - stmt.setString(2, feature.getName()); - stmt.setString(3, feature.getDescription()); + stmt.setString(1, mobileFeature.getCode()); + stmt.setString(2, mobileFeature.getName()); + stmt.setString(3, mobileFeature.getDescription()); int rows = stmt.executeUpdate(); if (rows > 0) { status = true; } } catch (SQLException e) { String msg = "Error occurred while adding feature code - '" + - feature.getCode() + "' to feature table"; + mobileFeature.getCode() + "' to feature table"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -73,7 +73,7 @@ public class FeatureDAOImpl implements FeatureDAO { } @Override - public boolean updateFeature(Feature feature) + public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -83,17 +83,17 @@ public class FeatureDAOImpl implements FeatureDAO { String updateDBQuery = "UPDATE MBL_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ? WHERE FEATURE_ID = ?"; stmt = conn.prepareStatement(updateDBQuery); - stmt.setString(1, feature.getCode()); - stmt.setString(2, feature.getName()); - stmt.setString(3, feature.getDescription()); - stmt.setInt(4, feature.getId()); + stmt.setString(1, mobileFeature.getCode()); + stmt.setString(2, mobileFeature.getName()); + stmt.setString(3, mobileFeature.getDescription()); + stmt.setInt(4, mobileFeature.getId()); int rows = stmt.executeUpdate(); if (rows > 0) { status = true; } } catch (SQLException e) { String msg = "Error occurred while updating the feature with feature code - '" + - feature.getId() + "'"; + mobileFeature.getId() + "'"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -155,11 +155,11 @@ public class FeatureDAOImpl implements FeatureDAO { } @Override - public Feature getFeatureByCode(String featureCode) + public MobileFeature getFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; - Feature feature = null; + MobileFeature mobileFeature = null; try { conn = this.getConnection(); String selectDBQuery = @@ -168,11 +168,11 @@ public class FeatureDAOImpl implements FeatureDAO { stmt.setString(1, featureCode); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { - feature = new Feature(); - feature.setId(resultSet.getInt(1)); - feature.setCode(resultSet.getString(2)); - feature.setName(resultSet.getString(3)); - feature.setDescription(resultSet.getString(4)); + mobileFeature = new MobileFeature(); + mobileFeature.setId(resultSet.getInt(1)); + mobileFeature.setCode(resultSet.getString(2)); + mobileFeature.setName(resultSet.getString(3)); + mobileFeature.setDescription(resultSet.getString(4)); break; } } catch (SQLException e) { @@ -183,15 +183,15 @@ public class FeatureDAOImpl implements FeatureDAO { } finally { MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); } - return feature; + return mobileFeature; } @Override - public Feature getFeatureById(String featureID) + public MobileFeature getFeatureById(String featureID) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; - Feature feature = null; + MobileFeature mobileFeature = null; try { conn = this.getConnection(); String selectDBQuery = @@ -200,11 +200,11 @@ public class FeatureDAOImpl implements FeatureDAO { stmt.setString(1, featureID); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { - feature = new Feature(); - feature.setId(resultSet.getInt(1)); - feature.setCode(resultSet.getString(2)); - feature.setName(resultSet.getString(3)); - feature.setDescription(resultSet.getString(4)); + mobileFeature = new MobileFeature(); + mobileFeature.setId(resultSet.getInt(1)); + mobileFeature.setCode(resultSet.getString(2)); + mobileFeature.setName(resultSet.getString(3)); + mobileFeature.setDescription(resultSet.getString(4)); break; } } catch (SQLException e) { @@ -215,15 +215,15 @@ public class FeatureDAOImpl implements FeatureDAO { } finally { MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); } - return feature; + return mobileFeature; } @Override - public List getAllFeatures() throws MobileDeviceManagementDAOException { + public List getAllFeatures() throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; - Feature feature; - List features = new ArrayList(); + MobileFeature mobileFeature; + List mobileFeatures = new ArrayList(); try { conn = this.getConnection(); String selectDBQuery = @@ -231,14 +231,14 @@ public class FeatureDAOImpl implements FeatureDAO { stmt = conn.prepareStatement(selectDBQuery); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { - feature = new Feature(); - feature.setId(resultSet.getInt(1)); - feature.setCode(resultSet.getString(2)); - feature.setName(resultSet.getString(3)); - feature.setDescription(resultSet.getString(4)); - features.add(feature); + mobileFeature = new MobileFeature(); + mobileFeature.setId(resultSet.getInt(1)); + mobileFeature.setCode(resultSet.getString(2)); + mobileFeature.setName(resultSet.getString(3)); + mobileFeature.setDescription(resultSet.getString(4)); + mobileFeatures.add(mobileFeature); } - return features; + return mobileFeatures; } catch (SQLException e) { String msg = "Error occurred while fetching all features.'"; log.error(msg, e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeaturePropertyDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java similarity index 75% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeaturePropertyDAOImpl.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java index 4c623fad3e..f99a2c7f04 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/FeaturePropertyDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/MobileFeaturePropertyDAOImpl.java @@ -18,10 +18,10 @@ package org.wso2.carbon.device.mgt.mobile.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.mobile.dao.FeaturePropertyDAO; +import org.wso2.carbon.device.mgt.mobile.dao.MobileFeaturePropertyDAO; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.dto.FeatureProperty; +import org.wso2.carbon.device.mgt.mobile.dto.MobileFeatureProperty; import javax.sql.DataSource; import java.sql.Connection; @@ -32,19 +32,19 @@ import java.util.ArrayList; import java.util.List; /** - * Implementation of FeaturePropertyDAO. + * Implementation of MobileFeaturePropertyDAO. */ -public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { +public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO { private DataSource dataSource; - private static final Log log = LogFactory.getLog(FeaturePropertyDAOImpl.class); + private static final Log log = LogFactory.getLog(MobileFeaturePropertyDAOImpl.class); - public FeaturePropertyDAOImpl(DataSource dataSource) { + public MobileFeaturePropertyDAOImpl(DataSource dataSource) { this.dataSource = dataSource; } @Override - public boolean addFeatureProperty(FeatureProperty featureProperty) + public boolean addFeatureProperty(MobileFeatureProperty mobileFeatureProperty) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -55,15 +55,15 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { "INSERT INTO MBL_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)"; stmt = conn.prepareStatement(createDBQuery); - stmt.setString(1, featureProperty.getProperty()); - stmt.setString(2, featureProperty.getFeatureID()); + stmt.setString(1, mobileFeatureProperty.getProperty()); + stmt.setString(2, mobileFeatureProperty.getFeatureID()); int rows = stmt.executeUpdate(); if (rows > 0) { status = true; } } catch (SQLException e) { String msg = "Error occurred while adding property id - '" + - featureProperty.getFeatureID() + "'"; + mobileFeatureProperty.getFeatureID() + "'"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -73,7 +73,7 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { } @Override - public boolean updateFeatureProperty(FeatureProperty featureProperty) + public boolean updateFeatureProperty(MobileFeatureProperty mobileFeatureProperty) throws MobileDeviceManagementDAOException { boolean status = false; Connection conn = null; @@ -83,15 +83,15 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { String updateDBQuery = "UPDATE MBL_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?"; stmt = conn.prepareStatement(updateDBQuery); - stmt.setString(1, featureProperty.getFeatureID()); - stmt.setString(2, featureProperty.getProperty()); + stmt.setString(1, mobileFeatureProperty.getFeatureID()); + stmt.setString(2, mobileFeatureProperty.getProperty()); int rows = stmt.executeUpdate(); if (rows > 0) { status = true; } } catch (SQLException e) { String msg = "Error occurred while updating the feature property with property - '" + - featureProperty.getProperty() + "'"; + mobileFeatureProperty.getProperty() + "'"; log.error(msg, e); throw new MobileDeviceManagementDAOException(msg, e); } finally { @@ -128,11 +128,11 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { } @Override - public FeatureProperty getFeatureProperty(String property) + public MobileFeatureProperty getFeatureProperty(String property) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; - FeatureProperty featureProperty = null; + MobileFeatureProperty mobileFeatureProperty = null; try { conn = this.getConnection(); String selectDBQuery = @@ -141,9 +141,9 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { stmt.setString(1, property); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { - featureProperty = new FeatureProperty(); - featureProperty.setProperty(resultSet.getString(1)); - featureProperty.setFeatureID(resultSet.getString(2)); + mobileFeatureProperty = new MobileFeatureProperty(); + mobileFeatureProperty.setProperty(resultSet.getString(1)); + mobileFeatureProperty.setFeatureID(resultSet.getString(2)); break; } } catch (SQLException e) { @@ -154,16 +154,16 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { } finally { MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); } - return featureProperty; + return mobileFeatureProperty; } @Override - public List getFeaturePropertyOfFeature(String featureId) + public List getFeaturePropertyOfFeature(String featureId) throws MobileDeviceManagementDAOException { Connection conn = null; PreparedStatement stmt = null; - FeatureProperty featureProperty = null; - List FeatureProperties = new ArrayList(); + MobileFeatureProperty mobileFeatureProperty = null; + List FeatureProperties = new ArrayList(); try { conn = this.getConnection(); String selectDBQuery = @@ -172,10 +172,10 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { stmt.setString(1, featureId); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { - featureProperty = new FeatureProperty(); - featureProperty.setProperty(resultSet.getString(1)); - featureProperty.setFeatureID(resultSet.getString(2)); - FeatureProperties.add(featureProperty); + mobileFeatureProperty = new MobileFeatureProperty(); + mobileFeatureProperty.setProperty(resultSet.getString(1)); + mobileFeatureProperty.setFeatureID(resultSet.getString(2)); + FeatureProperties.add(mobileFeatureProperty); } return FeatureProperties; } catch (SQLException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java index 146a33bcbf..af181b321b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/util/MobileDeviceManagementDAOUtil.java @@ -39,40 +39,6 @@ public class MobileDeviceManagementDAOUtil { private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOUtil.class); - /** - * Resolve data source from the data source definition. - * - * @param config Mobile data source configuration - * @return data source resolved from the data source definition - */ - public static DataSource resolveDataSource(MobileDataSourceConfig config) throws DeviceManagementException { - DataSource dataSource = null; - if (config == null) { - throw new RuntimeException("Device Management Repository data source configuration " + - "is null and thus, is not initialized"); - } - JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion(); - if (jndiConfig != null) { - if (log.isDebugEnabled()) { - log.debug("Initializing Device Management Repository data source using the JNDI " + - "Lookup Definition"); - } - List jndiPropertyList = - jndiConfig.getJndiProperties(); - if (jndiPropertyList != null) { - Hashtable jndiProperties = new Hashtable(); - for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { - jndiProperties.put(prop.getName(), prop.getValue()); - } - dataSource = - MobileDeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); - } else { - dataSource = MobileDeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); - } - } - return dataSource; - } - public static DataSource lookupDataSource(String dataSourceName, final Hashtable jndiProperties) throws DeviceManagementException { @@ -113,27 +79,6 @@ public class MobileDeviceManagementDAOUtil { } } - /** - * Initializes the creation of mobile device management schema if -Dsetup has provided. - * - * @param dataSource Mobile data source - */ - public static void createDataSource(DataSource dataSource) { - String setupOption = System.getProperty("setup"); - if (setupOption != null) { - if (log.isDebugEnabled()) { - log.debug( - "-Dsetup is enabled. Mobile Device management repository schema initialization is about " + - "to begin"); - } - try { - MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema(dataSource); - } catch (DeviceManagementException e) { - log.error("Exception occurred while initializing mobile device management database schema", e); - } - } - } - /** * Creates the mobile device management schema. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDeviceOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDeviceOperationMapping.java similarity index 70% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDeviceOperation.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDeviceOperationMapping.java index c565accdb4..f21ee7d4f6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDeviceOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileDeviceOperationMapping.java @@ -17,14 +17,37 @@ package org.wso2.carbon.device.mgt.mobile.dto; /** - * DTO of Mobile Device Operations. + * DTO of Mobile Device Operation Mappings. */ -public class MobileDeviceOperation { +public class MobileDeviceOperationMapping { private String deviceId; private int operationId; private long sentDate; private long receivedDate; + private Status status; + + public enum Status { + NEW, INPROGRESS, COMPLETED + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + + public void setStatus(String status) { + if(Status.NEW.name().equals(status)){ + this.status = Status.NEW; + }else if(Status.INPROGRESS.name().equals(status)){ + this.status = Status.INPROGRESS; + }else if(Status.COMPLETED.name().equals(status)){ + this.status = Status.COMPLETED; + } + } public String getDeviceId() { return deviceId; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeature.java similarity index 94% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/Feature.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeature.java index 2fb173b568..38b6944d61 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/Feature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeature.java @@ -19,9 +19,9 @@ package org.wso2.carbon.device.mgt.mobile.dto; import java.io.Serializable; /** - * DTO of features. + * DTO of Mobile features. */ -public class Feature implements Serializable { +public class MobileFeature implements Serializable { private int id; private String code; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/FeatureProperty.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeatureProperty.java similarity index 89% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/FeatureProperty.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeatureProperty.java index a29cebaff6..5068006cad 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/FeatureProperty.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dto/MobileFeatureProperty.java @@ -17,9 +17,9 @@ package org.wso2.carbon.device.mgt.mobile.dto; /** - * DTO of feature property. Represents a property of a feature. + * DTO of Mobile feature property. Represents a property of a mobile feature. */ -public class FeatureProperty { +public class MobileFeatureProperty { private String property; private String featureID; 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 76c6332434..aeb22ba7bc 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 @@ -23,12 +23,13 @@ import org.wso2.carbon.device.mgt.common.OperationManagementException; import org.wso2.carbon.device.mgt.mobile.AbstractMobileOperationManager; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperation; +import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import java.util.ArrayList; +import java.util.Date; import java.util.List; public class AndroidMobileOperationManager extends AbstractMobileOperationManager { @@ -40,7 +41,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage OperationManagementException { boolean status = false; try { - MobileDeviceOperation mobileDeviceOperation = null; + MobileDeviceOperationMapping mobileDeviceOperationMapping = null; MobileOperation mobileOperation = MobileDeviceManagementUtil.convertToMobileOperation(operation); int operationId = MobileDeviceManagementDAOFactory.getMobileOperationDAO() @@ -53,12 +54,13 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage operationProperty); } for (DeviceIdentifier deviceIdentifier : devices) { - mobileDeviceOperation = new MobileDeviceOperation(); - mobileDeviceOperation.setOperationId(operationId); - mobileDeviceOperation.setDeviceId(deviceIdentifier.getId()); + mobileDeviceOperationMapping = new MobileDeviceOperationMapping(); + mobileDeviceOperationMapping.setOperationId(operationId); + mobileDeviceOperationMapping.setDeviceId(deviceIdentifier.getId()); + mobileDeviceOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW); status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() .addMobileDeviceOperation( - mobileDeviceOperation); + mobileDeviceOperationMapping); } } } catch (MobileDeviceManagementDAOException e) { @@ -74,17 +76,18 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage public List getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException { List operations = new ArrayList(); - List mobileDeviceOperations = null; + List mobileDeviceOperationMappings = null; List operationProperties = null; MobileOperation mobileOperation = null; try { - mobileDeviceOperations = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() + mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() .getAllMobileDeviceOperationsOfDevice( deviceIdentifier .getId()); - if (mobileDeviceOperations.size() > 0) { + if (mobileDeviceOperationMappings.size() > 0) { List operationIds = MobileDeviceManagementUtil - .getMobileOperationIdsFromMobileDeviceOperations(mobileDeviceOperations); + .getMobileOperationIdsFromMobileDeviceOperations( + mobileDeviceOperationMappings); for (Integer operationId : operationIds) { mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO() .getMobileOperation( @@ -107,4 +110,49 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage } return operations; } + + @Override + public List getPendingOperations(DeviceIdentifier deviceIdentifier) + throws OperationManagementException { + List operations = new ArrayList(); + List mobileDeviceOperationMappings = null; + List operationProperties = null; + MobileOperation mobileOperation = null; + try { + //Get the list of pending operations for the given device + mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() + .getAllPendingOperationsOfMobileDevice( + deviceIdentifier + .getId()); + //Go through each operation mapping for retrieving the data corresponding to each operation + for (MobileDeviceOperationMapping operation : mobileDeviceOperationMappings) { + //Get the MobileOperation data + mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO() + .getMobileOperation(operation + .getOperationId()); + //Get properties of the operation + operationProperties = + MobileDeviceManagementDAOFactory.getMobileOperationPropertyDAO() + .getAllMobileOperationPropertiesOfOperation( + operation.getOperationId()); + mobileOperation.setProperties(operationProperties); + operations.add(MobileDeviceManagementUtil + .convertMobileOperationToOperation(mobileOperation)); + //Update the MobileDeviceOperationMapping data to the In-Progress state + operation.setStatus(MobileDeviceOperationMapping.Status.INPROGRESS); + operation.setSentDate(new Date().getTime()); + MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() + .updateMobileDeviceOperationToInProgress( + operation.getDeviceId(), + operation.getOperationId()); + } + } catch (MobileDeviceManagementDAOException e) { + String msg = + "Error while fetching the operations for the android device " + + deviceIdentifier.getId(); + log.error(msg, e); + throw new OperationManagementException(msg, e); + } + return operations; + } } \ 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 d771cb485c..78b120e480 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 @@ -23,7 +23,7 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.Operation; import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; -import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperation; +import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty; @@ -115,10 +115,10 @@ public class MobileDeviceManagementUtil { } public static List getMobileOperationIdsFromMobileDeviceOperations( - List mobileDeviceOperations) { + List mobileDeviceOperationMappings) { List mobileOperationIds = new ArrayList(); - for(MobileDeviceOperation mobileDeviceOperation:mobileDeviceOperations){ - mobileOperationIds.add(mobileDeviceOperation.getOperationId()); + for(MobileDeviceOperationMapping mobileDeviceOperationMapping : mobileDeviceOperationMappings){ + mobileOperationIds.add(mobileDeviceOperationMapping.getOperationId()); } return mobileOperationIds; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/MobileDeviceManagementConfigTests.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/MobileDeviceManagementConfigTests.java new file mode 100644 index 0000000000..db177105fc --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/MobileDeviceManagementConfigTests.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2014 - 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 org.wso2.carbon.device.mgt.mobile.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; +import org.xml.sax.SAXException; + +import javax.xml.XMLConstants; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import java.io.File; + +public class MobileDeviceManagementConfigTests { + + private static final Log log = LogFactory.getLog(MobileDeviceManagementConfigTests.class); + private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY = + "./src/test/resources/config/malformed-mobile-config-no-mgt-repo.xml"; + private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG = + "./src/test/resources/config/malformed-mobile-config-no-ds-config.xml"; + private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG = + "./src/test/resources/config/malformed-mobile-config-no-jndi-config.xml"; + private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_APIS_CONFIG = + "./src/test/resources/config/malformed-mobile-config-no-apis-config.xml"; + private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_API_CONFIG = + "./src/test/resources/config/malformed-mobile-config-no-api-config.xml"; + private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_API_PUBLISHER_CONFIG = + "./src/test/resources/config/malformed-mobile-config-no-api-publisher-config.xml"; + private static final String TEST_CONFIG_SCHEMA_LOCATION = + "./src/test/resources/config/schema/MobileDeviceManagementConfigSchema.xsd"; + + private Schema schema; + + @BeforeClass + private void initSchema() { + File deviceManagementSchemaConfig = new File(MobileDeviceManagementConfigTests.TEST_CONFIG_SCHEMA_LOCATION); + SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + try { + schema = factory.newSchema(deviceManagementSchemaConfig); + } catch (SAXException e) { + Assert.fail("Invalid schema found", e); + } + } + + @Test() + public void testMandateManagementRepositoryElement() { + File malformedConfig = + new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY); + this.validateMalformedConfig(malformedConfig); + } + + @Test + public void testMandateDataSourceConfigurationElement() { + File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG); + this.validateMalformedConfig(malformedConfig); + } + + @Test + public void testMandateJndiLookupDefinitionElement() { + File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG); + this.validateMalformedConfig(malformedConfig); + } + + @Test + public void testMandateAPIPublisherElement() { + File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_PUBLISHER_CONFIG); + this.validateMalformedConfig(malformedConfig); + } + + @Test + public void testMandateAPIsElement() { + File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_APIS_CONFIG); + this.validateMalformedConfig(malformedConfig); + } + + @Test + public void testMandateAPIElement() { + File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_CONFIG); + this.validateMalformedConfig(malformedConfig); + } + + private void validateMalformedConfig(File malformedConfig) { + try { + JAXBContext ctx = JAXBContext.newInstance(MobileDeviceManagementConfig.class); + Unmarshaller um = ctx.createUnmarshaller(); + um.setSchema(this.getSchema()); + um.unmarshal(malformedConfig); + Assert.assertTrue(false); + } catch (JAXBException e) { + log.error("Error occurred while unmarsharlling mobile device management config", e); + Assert.assertTrue(true); + } + } + + private Schema getSchema() { + return schema; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/TestUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/TestUtils.java new file mode 100644 index 0000000000..12a3b6ca42 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/TestUtils.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2014 - 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 org.wso2.carbon.device.mgt.mobile.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +public class TestUtils { + + private static final Log log = LogFactory.getLog(TestUtils.class); + + public static void cleanupResources(Connection conn, Statement stmt, ResultSet rs) { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing result set", e); + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing prepared statement", e); + } + } + if (conn != null) { + try { + conn.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing database connection", e); + } + } + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/org/wso2/carbon/device/mgt/mobile/impl/common/DBTypes.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/common/DBTypes.java similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/org/wso2/carbon/device/mgt/mobile/impl/common/DBTypes.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/common/DBTypes.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/org/wso2/carbon/device/mgt/mobile/impl/common/TestDBConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/common/TestDBConfiguration.java similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/org/wso2/carbon/device/mgt/mobile/impl/common/TestDBConfiguration.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/common/TestDBConfiguration.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/org/wso2/carbon/device/mgt/mobile/impl/common/TestDBConfigurations.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/common/TestDBConfigurations.java similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/org/wso2/carbon/device/mgt/mobile/impl/common/TestDBConfigurations.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/common/TestDBConfigurations.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeatureDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeatureDAOTestSuite.java new file mode 100644 index 0000000000..620127c5ac --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeatureDAOTestSuite.java @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.mobile.impl.dao; + +import org.apache.commons.dbcp.BasicDataSource; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeatureDAOImpl; +import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature; +import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes; +import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration; +import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfigurations; +import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.Statement; +import java.util.Iterator; + +public class FeatureDAOTestSuite { + + private TestDBConfiguration testDBConfiguration; + private Connection conn = null; + private Statement stmt = null; + private MobileFeatureDAOImpl featureDAO; + + @BeforeClass + @Parameters("dbType") + public void setUpDB(String dbTypeStr) throws Exception { + + DBTypes dbType = DBTypes.valueOf(dbTypeStr); + testDBConfiguration = getTestDBConfiguration(dbType); + + switch (dbType) { + case H2: + createH2DB(testDBConfiguration); + BasicDataSource testDataSource = new BasicDataSource(); + testDataSource.setDriverClassName(testDBConfiguration.getDriverClass()); + testDataSource.setUrl(testDBConfiguration.getConnectionUrl()); + testDataSource.setUsername(testDBConfiguration.getUserName()); + testDataSource.setPassword(testDBConfiguration.getPwd()); + featureDAO = new MobileFeatureDAOImpl(testDataSource); + default: + } + } + + private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws + MobileDeviceManagementDAOException, + DeviceManagementException { + + File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml"); + Document doc = null; + testDBConfiguration = null; + TestDBConfigurations testDBConfigurations = null; + + doc = MobileDeviceManagementUtil.convertToDocument(deviceMgtConfig); + JAXBContext testDBContext = null; + + try { + testDBContext = JAXBContext.newInstance(TestDBConfigurations.class); + Unmarshaller unmarshaller = testDBContext.createUnmarshaller(); + testDBConfigurations = (TestDBConfigurations) unmarshaller.unmarshal(doc); + } catch (JAXBException e) { + throw new MobileDeviceManagementDAOException("Error parsing test db configurations", e); + } + + Iterator itrDBConfigs = + testDBConfigurations.getDbTypesList().iterator(); + while (itrDBConfigs.hasNext()) { + testDBConfiguration = itrDBConfigs.next(); + if (testDBConfiguration.getDbType().equals(dbType.toString())) { + break; + } + } + + return testDBConfiguration; + } + + private void createH2DB(TestDBConfiguration testDBConf) throws Exception { + Class.forName(testDBConf.getDriverClass()); + conn = DriverManager.getConnection(testDBConf.getConnectionUrl()); + stmt = conn.createStatement(); + stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'"); + stmt.close(); + conn.close(); + } + + @Test + public void addFeature() throws MobileDeviceManagementDAOException, DeviceManagementException { + + MobileFeature mobileFeature = new MobileFeature(); + mobileFeature.setCode("Camera"); + mobileFeature.setDescription("Camera enable or disable"); + mobileFeature.setName("Camera"); + boolean added = featureDAO.addFeature(mobileFeature); + // Long deviceId = null; + // try { + // conn = DeviceManagementDAOFactory.getDataSource().getConnection(); + // stmt = conn.createStatement(); + // ResultSet resultSet = stmt + // .executeQuery("SELECT ID from DM_DEVICE DEVICE where DEVICE.DEVICE_IDENTIFICATION='111'"); + // + // while (resultSet.next()) { + // deviceId = resultSet.getLong(1); + // } + // conn.close(); + // } catch (SQLException sqlEx) { + // throw new DeviceManagementDAOException("error in fetch device by device identification id", sqlEx); + // } + + Assert.assertTrue(added, "Device Id is null"); + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeaturePropertyDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeaturePropertyDAOTestSuite.java new file mode 100644 index 0000000000..1937493681 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/FeaturePropertyDAOTestSuite.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2014 - 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 org.wso2.carbon.device.mgt.mobile.impl.dao; + +public class FeaturePropertyDAOTestSuite { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAOTestSuite.java new file mode 100644 index 0000000000..0c390a104e --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAOTestSuite.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2014 - 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 org.wso2.carbon.device.mgt.mobile.impl.dao; + +public class MobileDeviceDAOTestSuite { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceOperationDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceOperationDAOTestSuite.java new file mode 100644 index 0000000000..2ae371e76a --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceOperationDAOTestSuite.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2014 - 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 org.wso2.carbon.device.mgt.mobile.impl.dao; + +public class MobileDeviceOperationDAOTestSuite { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java new file mode 100644 index 0000000000..ebc277e31c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationDAOTestSuite.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2014 - 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 org.wso2.carbon.device.mgt.mobile.impl.dao; + +public class MobileOperationDAOTestSuite { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationPropertyDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationPropertyDAOTestSuite.java new file mode 100644 index 0000000000..4c43ed27bf --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileOperationPropertyDAOTestSuite.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2014 - 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 org.wso2.carbon.device.mgt.mobile.impl.dao; + +public class MobileOperationPropertyDAOTestSuite { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/org/wso2/carbon/device/mgt/mobile/impl/dao/FeatureDAOTestSuite.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/org/wso2/carbon/device/mgt/mobile/impl/dao/FeatureDAOTestSuite.java deleted file mode 100644 index e90733b30c..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/org/wso2/carbon/device/mgt/mobile/impl/dao/FeatureDAOTestSuite.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you 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.mobile.impl.dao; - -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; -import org.w3c.dom.Document; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes; -import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration; -import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfigurations; -import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; -import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; -import org.wso2.carbon.device.mgt.mobile.dao.impl.FeatureDAOImpl; -import org.wso2.carbon.device.mgt.mobile.dto.*; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import java.io.File; -import java.sql.*; -import java.util.Date; -import java.util.Iterator; - -public class FeatureDAOTestSuite { - - private TestDBConfiguration testDBConfiguration; - private Connection conn = null; - private Statement stmt = null; - private FeatureDAOImpl featureDAO; - - @BeforeClass - @Parameters("dbType") - public void setUpDB(String dbTypeStr) throws Exception { - - DBTypes dbType = DBTypes.valueOf(dbTypeStr); - testDBConfiguration = getTestDBConfiguration(dbType); - - switch (dbType) { - case H2: - createH2DB(testDBConfiguration); - BasicDataSource testDataSource = new BasicDataSource(); - testDataSource.setDriverClassName(testDBConfiguration.getDriverClass()); - testDataSource.setUrl(testDBConfiguration.getConnectionUrl()); - testDataSource.setUsername(testDBConfiguration.getUserName()); - testDataSource.setPassword(testDBConfiguration.getPwd()); - featureDAO = new FeatureDAOImpl(testDataSource); - default: - } - } - - private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws - MobileDeviceManagementDAOException, - DeviceManagementException { - - File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml"); - Document doc = null; - testDBConfiguration = null; - TestDBConfigurations testDBConfigurations = null; - - doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig); - JAXBContext testDBContext = null; - - try { - testDBContext = JAXBContext.newInstance(TestDBConfigurations.class); - Unmarshaller unmarshaller = testDBContext.createUnmarshaller(); - testDBConfigurations = (TestDBConfigurations) unmarshaller.unmarshal(doc); - } catch (JAXBException e) { - throw new MobileDeviceManagementDAOException("Error parsing test db configurations", e); - } - - Iterator itrDBConfigs = testDBConfigurations.getDbTypesList().iterator(); - while (itrDBConfigs.hasNext()) { - testDBConfiguration = itrDBConfigs.next(); - if (testDBConfiguration.getDbType().equals(dbType.toString())) { - break; - } - } - - return testDBConfiguration; - } - - private void createH2DB(TestDBConfiguration testDBConf) throws Exception { - - Class.forName(testDBConf.getDriverClass()); - conn = DriverManager.getConnection(testDBConf.getConnectionUrl()); - stmt = conn.createStatement(); - stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'"); - stmt.close(); - conn.close(); - - } - - - @Test - public void addFeature() throws MobileDeviceManagementDAOException, DeviceManagementException { - - - - Feature feature = new Feature(); - feature.setCode("Camera"); - feature.setDescription("Camera enable or disable"); - feature.setName("Camera"); - boolean added = featureDAO.addFeature(feature); -// Long deviceId = null; -// try { -// conn = DeviceManagementDAOFactory.getDataSource().getConnection(); -// stmt = conn.createStatement(); -// ResultSet resultSet = stmt -// .executeQuery("SELECT ID from DM_DEVICE DEVICE where DEVICE.DEVICE_IDENTIFICATION='111'"); -// -// while (resultSet.next()) { -// deviceId = resultSet.getLong(1); -// } -// conn.close(); -// } catch (SQLException sqlEx) { -// throw new DeviceManagementDAOException("error in fetch device by device identification id", sqlEx); -// } - - Assert.assertTrue(added, "Device Id is null"); - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-config.xml new file mode 100644 index 0000000000..bb498e902f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-config.xml @@ -0,0 +1,40 @@ + + + + + + + + jdbc/MobileDM_DS + + + + + + + + enrollment + admin + enrollment + 1.0.0 + http://localhost:9763/ + http,https + + + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-publisher-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-publisher-config.xml new file mode 100644 index 0000000000..8b2fc6209e --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-api-publisher-config.xml @@ -0,0 +1,40 @@ + + + + + + + + jdbc/MobileDM_DS + + + + + + + + enrollment + admin + enrollment + 1.0.0 + http://localhost:9763/ + http,https + + + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-apis-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-apis-config.xml new file mode 100644 index 0000000000..081b0dc074 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-apis-config.xml @@ -0,0 +1,40 @@ + + + + + + + + jdbc/MobileDM_DS + + + + + + + + enrollment + admin + enrollment + 1.0.0 + http://localhost:9763/ + http,https + + + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-ds-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-ds-config.xml new file mode 100644 index 0000000000..d4080aa442 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-ds-config.xml @@ -0,0 +1,40 @@ + + + + + + + + jdbc/MobileDM_DS + + + + + + + + enrollment + admin + enrollment + 1.0.0 + http://localhost:9763/ + http,https + + + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-jndi.config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-jndi.config.xml new file mode 100644 index 0000000000..67e41f5a0f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-jndi.config.xml @@ -0,0 +1,40 @@ + + + + + + + + jdbc/MobileDM_DS + + + + + + + + enrollment + admin + enrollment + 1.0.0 + http://localhost:9763/ + http,https + + + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-mgt-repo.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-mgt-repo.xml new file mode 100644 index 0000000000..ce26db6fd1 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/malformed-mobile-config-no-mgt-repo.xml @@ -0,0 +1,40 @@ + + + + + + + + jdbc/MobileDM_DS + + + + + + + + enrollment + admin + enrollment + 1.0.0 + http://localhost:9763/ + http,https + + + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/schema/MobileDeviceManagementConfigSchema.xsd b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/schema/MobileDeviceManagementConfigSchema.xsd new file mode 100644 index 0000000000..65204b6ba8 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/config/schema/MobileDeviceManagementConfigSchema.xsd @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/CreateH2TestDB.sql b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/CreateH2TestDB.sql index afcd19ca06..39610edd9a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/sql/CreateH2TestDB.sql @@ -1,24 +1,82 @@ -CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE -( - ID INT auto_increment NOT NULL, - NAME VARCHAR(300) NULL DEFAULT NULL, - PRIMARY KEY (ID) -); -CREATE TABLE IF NOT EXISTS DM_DEVICE -( - ID INT auto_increment NOT NULL, - DESCRIPTION TEXT NULL DEFAULT NULL, - NAME VARCHAR(100) NULL DEFAULT NULL, - DATE_OF_ENROLLMENT BIGINT NULL DEFAULT NULL, - DATE_OF_LAST_UPDATE BIGINT NULL DEFAULT NULL, - OWNERSHIP VARCHAR(45) NULL DEFAULT NULL, - STATUS VARCHAR(15) NULL DEFAULT NULL, - DEVICE_TYPE_ID INT(11) NULL DEFAULT NULL, - DEVICE_IDENTIFICATION VARCHAR(300) NULL DEFAULT NULL, - OWNER VARCHAR(45) NULL DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (ID), - CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION -); \ No newline at end of file +-- ----------------------------------------------------- +-- Table `MBL_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_DEVICE` ( + `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL , + `REG_ID` VARCHAR(45) NULL DEFAULT NULL , + `IMEI` VARCHAR(45) NULL DEFAULT NULL , + `IMSI` VARCHAR(45) NULL DEFAULT NULL , + `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL , + `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL , + `VENDOR` VARCHAR(45) NULL DEFAULT NULL , + `LATITUDE` VARCHAR(45) NULL DEFAULT NULL, + `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL, + PRIMARY KEY (`MOBILE_DEVICE_ID`) ); + + +-- ----------------------------------------------------- +-- Table `MBL_FEATURE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( + `FEATURE_ID` INT NOT NULL AUTO_INCREMENT , + `CODE` VARCHAR(45) NOT NULL , + `NAME` VARCHAR(100) NULL , + `DESCRIPTION` VARCHAR(200) NULL , + PRIMARY KEY (`FEATURE_ID`) ); + +-- ----------------------------------------------------- +-- Table `MBL_OPERATION` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( + `OPERATION_ID` INT NOT NULL AUTO_INCREMENT , + `FEATURE_CODE` VARCHAR(45) NOT NULL , + `CREATED_DATE` BIGINT NULL , + PRIMARY KEY (`OPERATION_ID`)); + +-- ----------------------------------------------------- +-- Table `MBL_DEVICE_OPERATION_MAPPING` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` ( + `DEVICE_ID` VARCHAR(45) NOT NULL , + `OPERATION_ID` INT NOT NULL , + `SENT_DATE` BIGINT NULL , + `RECEIVED_DATE` BIGINT NULL , + PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , + CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` + FOREIGN KEY (`DEVICE_ID` ) + REFERENCES `MBL_DEVICE` (`MOBILE_DEVICE_ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1` + FOREIGN KEY (`OPERATION_ID` ) + REFERENCES `MBL_OPERATION` (`OPERATION_ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +-- ----------------------------------------------------- +-- Table `MBL_OPERATION_PROPERTY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` ( + `OPERATION_ID` INT NOT NULL , + `PROPERTY` VARCHAR(45) NOT NULL , + `VALUE` TEXT NULL , + PRIMARY KEY (`OPERATION_ID`, `PROPERTY`) , + CONSTRAINT `fk_MBL_OPERATION_PROPERTY_MBL_OPERATION1` + FOREIGN KEY (`OPERATION_ID` ) + REFERENCES `MBL_OPERATION` (`OPERATION_ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); + +-- ----------------------------------------------------- +-- Table `MBL_FEATURE_PROPERTY` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` ( + `PROPERTY` VARCHAR(45) NOT NULL , + `FEATURE_ID` VARCHAR(45) NOT NULL , + PRIMARY KEY (`PROPERTY`) , + CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1` + FOREIGN KEY (`FEATURE_ID` ) + REFERENCES `MBL_FEATURE` (`FEATURE_ID` ) + ON DELETE NO ACTION + ON UPDATE NO ACTION); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testdbconfig.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testdbconfig.xml index 34e89a1392..d28ebbf8c5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testdbconfig.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testdbconfig.xml @@ -16,7 +16,7 @@ - jdbc:h2:mem:cdm-test-db;DB_CLOSE_DELAY=-1 + jdbc:h2:mem:cdm-mobile-test-db;DB_CLOSE_DELAY=-1 org.h2.Driver diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml index 8bdba93ad7..2048666886 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/test/resources/testng.xml @@ -15,13 +15,12 @@ - + - diff --git a/product/modules/distribution/src/assembly/bin.xml b/product/modules/distribution/src/assembly/bin.xml index d9f01fee5b..7420ae1f65 100644 --- a/product/modules/distribution/src/assembly/bin.xml +++ b/product/modules/distribution/src/assembly/bin.xml @@ -460,5 +460,15 @@ 644 + + + + ../distribution/src/repository/database/WSO2MobileDM_DB.h2.db + + ${pom.artifactId}-${pom.version}/repository/database + WSO2MobileDM_DB.h2.db + 644 + + diff --git a/product/modules/distribution/src/repository/database/WSO2MobileDM_DB.h2.db b/product/modules/distribution/src/repository/database/WSO2MobileDM_DB.h2.db new file mode 100644 index 0000000000..78086440fd Binary files /dev/null and b/product/modules/distribution/src/repository/database/WSO2MobileDM_DB.h2.db differ diff --git a/product/modules/distribution/src/repository/dbscripts/cdm/h2.sql b/product/modules/distribution/src/repository/dbscripts/cdm/h2.sql index 783acaa8de..3ceea15a02 100644 --- a/product/modules/distribution/src/repository/dbscripts/cdm/h2.sql +++ b/product/modules/distribution/src/repository/dbscripts/cdm/h2.sql @@ -23,4 +23,4 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION ); -- TO:DO - Remove this INSERT sql statement. -Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android'); +Insert into DM_DEVICE_TYPE (NAME) VALUES ('android'); diff --git a/product/modules/distribution/src/repository/dbscripts/cdm/plugins/h2.sql b/product/modules/distribution/src/repository/dbscripts/cdm/plugins/h2.sql index fd239aa58f..aab99bd146 100644 --- a/product/modules/distribution/src/repository/dbscripts/cdm/plugins/h2.sql +++ b/product/modules/distribution/src/repository/dbscripts/cdm/plugins/h2.sql @@ -31,13 +31,8 @@ CREATE TABLE IF NOT EXISTS `MBL_FEATURE` ( CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( `OPERATION_ID` INT NOT NULL AUTO_INCREMENT , `FEATURE_CODE` VARCHAR(45) NOT NULL , - `CREATED_DATE` INT NULL , - PRIMARY KEY (`OPERATION_ID`) , - CONSTRAINT `fk_MBL_OPERATION_MBL_FEATURES1` - FOREIGN KEY (`FEATURE_CODE` ) - REFERENCES `MBL_FEATURE` (`CODE` ) - ON DELETE NO ACTION - ON UPDATE NO ACTION); + `CREATED_DATE` BIGINT NULL , + PRIMARY KEY (`OPERATION_ID`)); -- ----------------------------------------------------- -- Table `MBL_DEVICE_OPERATION_MAPPING` @@ -45,8 +40,9 @@ CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` ( `DEVICE_ID` VARCHAR(45) NOT NULL , `OPERATION_ID` INT NOT NULL , - `SENT_DATE` INT NULL , - `RECEIVED_DATE` INT NULL , + `SENT_DATE` BIGINT NULL , + `RECEIVED_DATE` BIGINT NULL , + `STATUS` VARCHAR(10) NOT NULL , PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` FOREIGN KEY (`DEVICE_ID` ) diff --git a/product/modules/distribution/src/repository/dbscripts/cdm/plugins/mysql.sql b/product/modules/distribution/src/repository/dbscripts/cdm/plugins/mysql.sql index 10adee8d0a..3e6ee30a5f 100644 --- a/product/modules/distribution/src/repository/dbscripts/cdm/plugins/mysql.sql +++ b/product/modules/distribution/src/repository/dbscripts/cdm/plugins/mysql.sql @@ -46,6 +46,7 @@ CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` ( `OPERATION_ID` INT NOT NULL, `SENT_DATE` INT NULL, `RECEIVED_DATE` INT NULL, + `STATUS` VARCHAR(10) NOT NULL, PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`), INDEX `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1_idx` (`OPERATION_ID` ASC), CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Enrollment.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Enrollment.java index a5fb3b8de7..d2e2438f8f 100644 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Enrollment.java +++ b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Enrollment.java @@ -39,112 +39,113 @@ import javax.ws.rs.core.Response; @Consumes({ "application/json", "application/xml" }) public class Enrollment { - private static Log log = LogFactory.getLog(Enrollment.class); - - @POST - public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException { - - Message responseMsg = new Message(); - - try { - device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); - AndroidAPIUtils.getDeviceManagementService().enrollDevice(device); - Response.status(Response.Status.CREATED); - responseMsg.setResponseMessage("Device enrollment succeeded"); - return responseMsg; - } catch (DeviceManagementServiceException deviceServiceMgtEx) { - String errorMsg = "Device management service error"; - log.error(errorMsg, deviceServiceMgtEx); - throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); - } catch (DeviceManagementException deviceMgtEx) { - String errorMsg = "Error occurred while enrolling the device"; - log.error(errorMsg, deviceMgtEx); - throw new AndroidAgentException(errorMsg, deviceMgtEx); - } - } - - @GET - @Path("{id}") - public Message isEnrolled(@PathParam("id") String id) throws AndroidAgentException { - - boolean result; - Message responseMsg = new Message(); - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - - try { - result = AndroidAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier); - if (result) { - responseMsg.setResponseMessage("Device has already enrolled"); - } else { - Response.status(Response.Status.NOT_FOUND); - responseMsg.setResponseMessage("Device not found"); - } - return responseMsg; - } catch (DeviceManagementServiceException deviceServiceMgtEx) { - String errorMsg = "Device management service error"; - log.error(errorMsg, deviceServiceMgtEx); - throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); - } catch (DeviceManagementException deviceMgtEx) { - String errorMsg = "Error occurred while enrollment of the device."; - log.error(errorMsg, deviceMgtEx); - throw new AndroidAgentException(errorMsg, deviceMgtEx); - } - } - - @PUT - @Path("{id}") - public Message modifyEnrollment(@PathParam("id") String id, org.wso2.carbon.device.mgt.common.Device device) - throws AndroidAgentException { - - 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(Response.Status.ACCEPTED); - } else { - responseMsg.setResponseMessage("Device not found for enrollment"); - Response.status(Response.Status.NOT_MODIFIED); - } - return responseMsg; - } catch (DeviceManagementServiceException deviceServiceMgtEx) { - String errorMsg = "Device management service error"; - log.error(errorMsg, deviceServiceMgtEx); - throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); - } catch (DeviceManagementException deviceMgtEx) { - String errorMsg = "Error occurred while modifying enrollment of the device"; - log.error(errorMsg, deviceMgtEx); - throw new AndroidAgentException(errorMsg, deviceMgtEx); - } - } - - @DELETE - @Path("{id}") - public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException { - - Message responseMsg = new Message(); - boolean result; - DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); - - try { - result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); - if (result) { - responseMsg.setResponseMessage("Device has removed successfully"); - } else { - responseMsg.setResponseMessage("Device not found"); - Response.status(Response.Status.NOT_FOUND); - } - return responseMsg; - } catch (DeviceManagementServiceException deviceServiceMgtEx) { - String errorMsg = "Device management service error"; - log.error(errorMsg, deviceServiceMgtEx); - throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); - } catch (DeviceManagementException deviceMgtEx) { - String errorMsg = "Error occurred while dis enrolling the device"; - log.error(errorMsg, deviceMgtEx); - throw new AndroidAgentException(errorMsg, deviceMgtEx); - } - } + private static Log log = LogFactory.getLog(Enrollment.class); + + @POST + public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device) + throws AndroidAgentException { + + Message responseMsg = new Message(); + + try { + device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); + AndroidAPIUtils.getDeviceManagementService().enrollDevice(device); + Response.status(Response.Status.CREATED); + responseMsg.setResponseMessage("Device enrollment succeeded"); + return responseMsg; + } catch (DeviceManagementServiceException deviceServiceMgtEx) { + String errorMsg = "Device management service error"; + log.error(errorMsg, deviceServiceMgtEx); + throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); + } catch (DeviceManagementException deviceMgtEx) { + String errorMsg = "Error occurred while enrolling the device"; + log.error(errorMsg, deviceMgtEx); + throw new AndroidAgentException(errorMsg, deviceMgtEx); + } + } + + @GET + @Path("{id}") + public Message isEnrolled(@PathParam("id") String id) throws AndroidAgentException { + + boolean result; + Message responseMsg = new Message(); + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + + try { + result = AndroidAPIUtils.getDeviceManagementService().isEnrolled(deviceIdentifier); + if (result) { + responseMsg.setResponseMessage("Device has already enrolled"); + } else { + Response.status(Response.Status.NOT_FOUND); + responseMsg.setResponseMessage("Device not found"); + } + return responseMsg; + } catch (DeviceManagementServiceException deviceServiceMgtEx) { + String errorMsg = "Device management service error"; + log.error(errorMsg, deviceServiceMgtEx); + throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); + } catch (DeviceManagementException deviceMgtEx) { + String errorMsg = "Error occurred while enrollment of the device."; + log.error(errorMsg, deviceMgtEx); + throw new AndroidAgentException(errorMsg, deviceMgtEx); + } + } + + @PUT + @Path("{id}") + public Message modifyEnrollment(@PathParam("id") String id, + org.wso2.carbon.device.mgt.common.Device device) + throws AndroidAgentException { + + 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(Response.Status.ACCEPTED); + } else { + responseMsg.setResponseMessage("Device not found for enrollment"); + Response.status(Response.Status.NOT_MODIFIED); + } + return responseMsg; + } catch (DeviceManagementServiceException deviceServiceMgtEx) { + String errorMsg = "Device management service error"; + log.error(errorMsg, deviceServiceMgtEx); + throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); + } catch (DeviceManagementException deviceMgtEx) { + String errorMsg = "Error occurred while modifying enrollment of the device"; + log.error(errorMsg, deviceMgtEx); + throw new AndroidAgentException(errorMsg, deviceMgtEx); + } + } + + @DELETE + @Path("{id}") + public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException { + Message responseMsg = new Message(); + boolean result; + DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); + + try { + result = AndroidAPIUtils.getDeviceManagementService().disenrollDevice(deviceIdentifier); + if (result) { + responseMsg.setResponseMessage("Device has removed successfully"); + } else { + responseMsg.setResponseMessage("Device not found"); + Response.status(Response.Status.NOT_FOUND); + } + return responseMsg; + } catch (DeviceManagementServiceException deviceServiceMgtEx) { + String errorMsg = "Device management service error"; + log.error(errorMsg, deviceServiceMgtEx); + throw new AndroidAgentException(errorMsg, deviceServiceMgtEx); + } catch (DeviceManagementException deviceMgtEx) { + String errorMsg = "Error occurred while dis enrolling the device"; + log.error(errorMsg, deviceMgtEx); + throw new AndroidAgentException(errorMsg, deviceMgtEx); + } + } } diff --git a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Operation.java b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Operation.java index 4255364977..dfbac2846f 100644 --- a/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Operation.java +++ b/product/modules/mobileservices/agents/android/jax-rs/src/main/java/org/wso2/cdmserver/mobileservices/android/Operation.java @@ -39,7 +39,7 @@ public class Operation { @GET @Path("{id}") - public List getAllOperations( + public List getPendingOperations( @PathParam("id") String id) throws AndroidAgentException { @@ -52,7 +52,7 @@ public class Operation { DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); operations = dmService.getOperationManager( DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID) - .getOperations(deviceIdentifier); + .getPendingOperations(deviceIdentifier); Response.status(HttpStatus.SC_OK); return operations; } catch (DeviceManagementServiceException deviceMgtServiceEx) { diff --git a/product/modules/mobileservices/agents/windows/jax-rs/src/main/java/cdm/api/windows/wstep/beans/package-info.java b/product/modules/mobileservices/agents/windows/jax-rs/src/main/java/cdm/api/windows/wstep/beans/package-info.java deleted file mode 100644 index 453eefdd21..0000000000 --- a/product/modules/mobileservices/agents/windows/jax-rs/src/main/java/cdm/api/windows/wstep/beans/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you 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. - */ - -@XmlSchema(namespace = "http://www.w3.org/2003/05/soap-envelope", - xmlns = { - @XmlNs(prefix = "", namespaceURI = "http://www.w3.org/2003/05/soap-envelope"), - }, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) - -package com.ex.wstep; - -import javax.xml.bind.annotation.XmlNs; -import javax.xml.bind.annotation.XmlSchema; \ No newline at end of file