Added new changes in operation management

revert-dabc3590
harshanL 10 years ago
parent 2883f0dda2
commit 163fe58120

@ -28,7 +28,7 @@ public class MobileDataSourceConfig {
private JNDILookupDefinition jndiLookupDefinition; private JNDILookupDefinition jndiLookupDefinition;
@XmlElement(name = "JndiLookupDefinition", nillable = true) @XmlElement(name = "JndiLookupDefinition", nillable = true)
public JNDILookupDefinition getJndiLookupDefintion() { public JNDILookupDefinition getJndiLookupDefinition() {
return jndiLookupDefinition; return jndiLookupDefinition;
} }

@ -62,7 +62,7 @@ public class MobileDeviceManagementDAOFactory {
throw new RuntimeException("Device Management Repository data source configuration " + throw new RuntimeException("Device Management Repository data source configuration " +
"is null and thus, is not initialized"); "is null and thus, is not initialized");
} }
JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion(); JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
if (jndiConfig != null) { if (jndiConfig != null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Initializing Device Management Repository data source using the JNDI " + log.debug("Initializing Device Management Repository data source using the JNDI " +
@ -98,16 +98,16 @@ public class MobileDeviceManagementDAOFactory {
return new MobileOperationPropertyDAOImpl(dataSource); return new MobileOperationPropertyDAOImpl(dataSource);
} }
public static MobileDeviceOperationDAO getMobileDeviceOperationDAO() { public static MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() {
return new MobileDeviceOperationDAOImpl(dataSource); return new MobileDeviceOperationMappingDAOImpl(dataSource);
} }
public static FeatureDAO getFeatureDAO() { public static MobileFeatureDAO getFeatureDAO() {
return new FeatureDAOImpl(dataSource); return new MobileFeatureDAOImpl(dataSource);
} }
public static FeaturePropertyDAO getFeaturePropertyDAO() { public static MobileFeaturePropertyDAO getFeaturePropertyDAO() {
return new FeaturePropertyDAOImpl(dataSource); return new MobileFeaturePropertyDAOImpl(dataSource);
} }
public static MobileDataSourceConfig getMobileDeviceManagementConfig() { public static MobileDataSourceConfig getMobileDeviceManagementConfig() {

@ -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<MobileDeviceOperation> getAllMobileDeviceOperationsOfDevice(String deviceId)
throws MobileDeviceManagementDAOException;
}

@ -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<MobileDeviceOperationMapping> 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<MobileDeviceOperationMapping> getAllPendingOperationsOfMobileDevice(String deviceId)
throws MobileDeviceManagementDAOException;
}

@ -16,33 +16,33 @@
package org.wso2.carbon.device.mgt.mobile.dao; 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; 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. * information.
*/ */
public interface FeatureDAO { public interface MobileFeatureDAO {
/** /**
* Add a new feature to feature table. * 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. * @return The status of the operation. If the insert was successful or not.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
boolean addFeature(Feature feature) throws MobileDeviceManagementDAOException; boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
/** /**
* Update a feature in the feature table. * 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. * @return The status of the operation. If the update was successful or not.
* @throws MobileDeviceManagementDAOException * @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. * 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. * @return Feature object that holds data of the feature represented by featureId.
* @throws MobileDeviceManagementDAOException * @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. * 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. * @return Feature object that holds data of the feature represented by featureCode.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
Feature getFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException; MobileFeature getFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException;
/** /**
* Retrieve all the features from plugin specific database. * Retrieve all the features from plugin specific database.
@ -86,5 +86,5 @@ public interface FeatureDAO {
* @return Feature object list. * @return Feature object list.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
List<Feature> getAllFeatures() throws MobileDeviceManagementDAOException; List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException;
} }

@ -16,33 +16,33 @@
package org.wso2.carbon.device.mgt.mobile.dao; 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; 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. * information.
*/ */
public interface FeaturePropertyDAO { public interface MobileFeaturePropertyDAO {
/** /**
* Add a new feature property to feature property table. * 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. * @return The status of the operation. If the insert was successful or not.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
boolean addFeatureProperty(FeatureProperty featureProperty) boolean addFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
/** /**
* Update a feature property in the feature property table. * 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. * @return The status of the operation. If the update was successful or not.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
boolean updateFeatureProperty(FeatureProperty featureProperty) boolean updateFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
/** /**
@ -61,7 +61,7 @@ public interface FeaturePropertyDAO {
* @return Feature property object that holds data of the feature property represented by propertyId. * @return Feature property object that holds data of the feature property represented by propertyId.
* @throws MobileDeviceManagementDAOException * @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 . * 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. * @return Feature property object that holds data of the feature property represented by propertyId.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
List<FeatureProperty> getFeaturePropertyOfFeature(String featureId) List<MobileFeatureProperty> getFeaturePropertyOfFeature(String featureId)
throws MobileDeviceManagementDAOException; throws MobileDeviceManagementDAOException;
} }

@ -19,7 +19,7 @@ package org.wso2.carbon.device.mgt.mobile.dao;
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation; 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. * information.
*/ */
public interface MobileOperationDAO { public interface MobileOperationDAO {

@ -21,7 +21,7 @@ import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
import java.util.List; 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. * information.
*/ */
public interface MobileOperationPropertyDAO { public interface MobileOperationPropertyDAO {

@ -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<MobileDeviceOperation> getAllMobileDeviceOperationsOfDevice(String deviceId)
throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
MobileDeviceOperation deviceOperation = null;
List<MobileDeviceOperation> deviceOperations = new ArrayList<MobileDeviceOperation>();
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);
}
}
}

@ -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<MobileDeviceOperationMapping> getAllMobileDeviceOperationsOfDevice(String deviceId)
throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
MobileDeviceOperationMapping mblDeviceOperation = null;
List<MobileDeviceOperationMapping> mblDeviceOperations = new ArrayList<MobileDeviceOperationMapping>();
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<MobileDeviceOperationMapping> getAllPendingOperationsOfMobileDevice(String deviceId)
throws MobileDeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
MobileDeviceOperationMapping mblDeviceOperation = null;
List<MobileDeviceOperationMapping> mblDeviceOperations = new ArrayList<MobileDeviceOperationMapping>();
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);
}
}
}

@ -18,10 +18,10 @@ package org.wso2.carbon.device.mgt.mobile.dao.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.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.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; 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 javax.sql.DataSource;
import java.sql.Connection; import java.sql.Connection;
@ -32,19 +32,19 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Implementation of FeatureDAO. * Implementation of MobileFeatureDAO.
*/ */
public class FeatureDAOImpl implements FeatureDAO { public class MobileFeatureDAOImpl implements MobileFeatureDAO {
private DataSource dataSource; 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; this.dataSource = dataSource;
} }
@Override @Override
public boolean addFeature(Feature feature) throws MobileDeviceManagementDAOException { public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -54,16 +54,16 @@ public class FeatureDAOImpl implements FeatureDAO {
"INSERT INTO MBL_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; "INSERT INTO MBL_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(createDBQuery); stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, feature.getCode()); stmt.setString(1, mobileFeature.getCode());
stmt.setString(2, feature.getName()); stmt.setString(2, mobileFeature.getName());
stmt.setString(3, feature.getDescription()); stmt.setString(3, mobileFeature.getDescription());
int rows = stmt.executeUpdate(); int rows = stmt.executeUpdate();
if (rows > 0) { if (rows > 0) {
status = true; status = true;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while adding feature code - '" + String msg = "Error occurred while adding feature code - '" +
feature.getCode() + "' to feature table"; mobileFeature.getCode() + "' to feature table";
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -73,7 +73,7 @@ public class FeatureDAOImpl implements FeatureDAO {
} }
@Override @Override
public boolean updateFeature(Feature feature) public boolean updateFeature(MobileFeature mobileFeature)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
@ -83,17 +83,17 @@ public class FeatureDAOImpl implements FeatureDAO {
String updateDBQuery = String updateDBQuery =
"UPDATE MBL_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ? WHERE FEATURE_ID = ?"; "UPDATE MBL_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ? WHERE FEATURE_ID = ?";
stmt = conn.prepareStatement(updateDBQuery); stmt = conn.prepareStatement(updateDBQuery);
stmt.setString(1, feature.getCode()); stmt.setString(1, mobileFeature.getCode());
stmt.setString(2, feature.getName()); stmt.setString(2, mobileFeature.getName());
stmt.setString(3, feature.getDescription()); stmt.setString(3, mobileFeature.getDescription());
stmt.setInt(4, feature.getId()); stmt.setInt(4, mobileFeature.getId());
int rows = stmt.executeUpdate(); int rows = stmt.executeUpdate();
if (rows > 0) { if (rows > 0) {
status = true; status = true;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while updating the feature with feature code - '" + String msg = "Error occurred while updating the feature with feature code - '" +
feature.getId() + "'"; mobileFeature.getId() + "'";
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -155,11 +155,11 @@ public class FeatureDAOImpl implements FeatureDAO {
} }
@Override @Override
public Feature getFeatureByCode(String featureCode) public MobileFeature getFeatureByCode(String featureCode)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
Feature feature = null; MobileFeature mobileFeature = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQuery = String selectDBQuery =
@ -168,11 +168,11 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt.setString(1, featureCode); stmt.setString(1, featureCode);
ResultSet resultSet = stmt.executeQuery(); ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
feature = new Feature(); mobileFeature = new MobileFeature();
feature.setId(resultSet.getInt(1)); mobileFeature.setId(resultSet.getInt(1));
feature.setCode(resultSet.getString(2)); mobileFeature.setCode(resultSet.getString(2));
feature.setName(resultSet.getString(3)); mobileFeature.setName(resultSet.getString(3));
feature.setDescription(resultSet.getString(4)); mobileFeature.setDescription(resultSet.getString(4));
break; break;
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -183,15 +183,15 @@ public class FeatureDAOImpl implements FeatureDAO {
} finally { } finally {
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
} }
return feature; return mobileFeature;
} }
@Override @Override
public Feature getFeatureById(String featureID) public MobileFeature getFeatureById(String featureID)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
Feature feature = null; MobileFeature mobileFeature = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQuery = String selectDBQuery =
@ -200,11 +200,11 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt.setString(1, featureID); stmt.setString(1, featureID);
ResultSet resultSet = stmt.executeQuery(); ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
feature = new Feature(); mobileFeature = new MobileFeature();
feature.setId(resultSet.getInt(1)); mobileFeature.setId(resultSet.getInt(1));
feature.setCode(resultSet.getString(2)); mobileFeature.setCode(resultSet.getString(2));
feature.setName(resultSet.getString(3)); mobileFeature.setName(resultSet.getString(3));
feature.setDescription(resultSet.getString(4)); mobileFeature.setDescription(resultSet.getString(4));
break; break;
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -215,15 +215,15 @@ public class FeatureDAOImpl implements FeatureDAO {
} finally { } finally {
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
} }
return feature; return mobileFeature;
} }
@Override @Override
public List<Feature> getAllFeatures() throws MobileDeviceManagementDAOException { public List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
Feature feature; MobileFeature mobileFeature;
List<Feature> features = new ArrayList<Feature>(); List<MobileFeature> mobileFeatures = new ArrayList<MobileFeature>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQuery = String selectDBQuery =
@ -231,14 +231,14 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt = conn.prepareStatement(selectDBQuery); stmt = conn.prepareStatement(selectDBQuery);
ResultSet resultSet = stmt.executeQuery(); ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
feature = new Feature(); mobileFeature = new MobileFeature();
feature.setId(resultSet.getInt(1)); mobileFeature.setId(resultSet.getInt(1));
feature.setCode(resultSet.getString(2)); mobileFeature.setCode(resultSet.getString(2));
feature.setName(resultSet.getString(3)); mobileFeature.setName(resultSet.getString(3));
feature.setDescription(resultSet.getString(4)); mobileFeature.setDescription(resultSet.getString(4));
features.add(feature); mobileFeatures.add(mobileFeature);
} }
return features; return mobileFeatures;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while fetching all features.'"; String msg = "Error occurred while fetching all features.'";
log.error(msg, e); log.error(msg, e);

@ -18,10 +18,10 @@ package org.wso2.carbon.device.mgt.mobile.dao.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.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.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; 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 javax.sql.DataSource;
import java.sql.Connection; import java.sql.Connection;
@ -32,19 +32,19 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Implementation of FeaturePropertyDAO. * Implementation of MobileFeaturePropertyDAO.
*/ */
public class FeaturePropertyDAOImpl implements FeaturePropertyDAO { public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
private DataSource dataSource; 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; this.dataSource = dataSource;
} }
@Override @Override
public boolean addFeatureProperty(FeatureProperty featureProperty) public boolean addFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
@ -55,15 +55,15 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
"INSERT INTO MBL_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)"; "INSERT INTO MBL_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)";
stmt = conn.prepareStatement(createDBQuery); stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, featureProperty.getProperty()); stmt.setString(1, mobileFeatureProperty.getProperty());
stmt.setString(2, featureProperty.getFeatureID()); stmt.setString(2, mobileFeatureProperty.getFeatureID());
int rows = stmt.executeUpdate(); int rows = stmt.executeUpdate();
if (rows > 0) { if (rows > 0) {
status = true; status = true;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while adding property id - '" + String msg = "Error occurred while adding property id - '" +
featureProperty.getFeatureID() + "'"; mobileFeatureProperty.getFeatureID() + "'";
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -73,7 +73,7 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
} }
@Override @Override
public boolean updateFeatureProperty(FeatureProperty featureProperty) public boolean updateFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn = null;
@ -83,15 +83,15 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
String updateDBQuery = String updateDBQuery =
"UPDATE MBL_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?"; "UPDATE MBL_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?";
stmt = conn.prepareStatement(updateDBQuery); stmt = conn.prepareStatement(updateDBQuery);
stmt.setString(1, featureProperty.getFeatureID()); stmt.setString(1, mobileFeatureProperty.getFeatureID());
stmt.setString(2, featureProperty.getProperty()); stmt.setString(2, mobileFeatureProperty.getProperty());
int rows = stmt.executeUpdate(); int rows = stmt.executeUpdate();
if (rows > 0) { if (rows > 0) {
status = true; status = true;
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while updating the feature property with property - '" + String msg = "Error occurred while updating the feature property with property - '" +
featureProperty.getProperty() + "'"; mobileFeatureProperty.getProperty() + "'";
log.error(msg, e); log.error(msg, e);
throw new MobileDeviceManagementDAOException(msg, e); throw new MobileDeviceManagementDAOException(msg, e);
} finally { } finally {
@ -128,11 +128,11 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
} }
@Override @Override
public FeatureProperty getFeatureProperty(String property) public MobileFeatureProperty getFeatureProperty(String property)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
FeatureProperty featureProperty = null; MobileFeatureProperty mobileFeatureProperty = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQuery = String selectDBQuery =
@ -141,9 +141,9 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
stmt.setString(1, property); stmt.setString(1, property);
ResultSet resultSet = stmt.executeQuery(); ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
featureProperty = new FeatureProperty(); mobileFeatureProperty = new MobileFeatureProperty();
featureProperty.setProperty(resultSet.getString(1)); mobileFeatureProperty.setProperty(resultSet.getString(1));
featureProperty.setFeatureID(resultSet.getString(2)); mobileFeatureProperty.setFeatureID(resultSet.getString(2));
break; break;
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -154,16 +154,16 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
} finally { } finally {
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null); MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
} }
return featureProperty; return mobileFeatureProperty;
} }
@Override @Override
public List<FeatureProperty> getFeaturePropertyOfFeature(String featureId) public List<MobileFeatureProperty> getFeaturePropertyOfFeature(String featureId)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {
Connection conn = null; Connection conn = null;
PreparedStatement stmt = null; PreparedStatement stmt = null;
FeatureProperty featureProperty = null; MobileFeatureProperty mobileFeatureProperty = null;
List<FeatureProperty> FeatureProperties = new ArrayList<FeatureProperty>(); List<MobileFeatureProperty> FeatureProperties = new ArrayList<MobileFeatureProperty>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQuery = String selectDBQuery =
@ -172,10 +172,10 @@ public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
stmt.setString(1, featureId); stmt.setString(1, featureId);
ResultSet resultSet = stmt.executeQuery(); ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
featureProperty = new FeatureProperty(); mobileFeatureProperty = new MobileFeatureProperty();
featureProperty.setProperty(resultSet.getString(1)); mobileFeatureProperty.setProperty(resultSet.getString(1));
featureProperty.setFeatureID(resultSet.getString(2)); mobileFeatureProperty.setFeatureID(resultSet.getString(2));
FeatureProperties.add(featureProperty); FeatureProperties.add(mobileFeatureProperty);
} }
return FeatureProperties; return FeatureProperties;
} catch (SQLException e) { } catch (SQLException e) {

@ -39,40 +39,6 @@ public class MobileDeviceManagementDAOUtil {
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOUtil.class); 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<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
jndiConfig.getJndiProperties();
if (jndiPropertyList != null) {
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
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, public static DataSource lookupDataSource(String dataSourceName,
final Hashtable<Object, Object> jndiProperties) final Hashtable<Object, Object> jndiProperties)
throws DeviceManagementException { 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. * Creates the mobile device management schema.
* *

@ -17,14 +17,37 @@
package org.wso2.carbon.device.mgt.mobile.dto; 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 String deviceId;
private int operationId; private int operationId;
private long sentDate; private long sentDate;
private long receivedDate; 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() { public String getDeviceId() {
return deviceId; return deviceId;

@ -19,9 +19,9 @@ package org.wso2.carbon.device.mgt.mobile.dto;
import java.io.Serializable; 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 int id;
private String code; private String code;

@ -17,9 +17,9 @@
package org.wso2.carbon.device.mgt.mobile.dto; 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 property;
private String featureID; private String featureID;

@ -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.AbstractMobileOperationManager;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; 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.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.MobileOperation;
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
public class AndroidMobileOperationManager extends AbstractMobileOperationManager { public class AndroidMobileOperationManager extends AbstractMobileOperationManager {
@ -40,7 +41,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
OperationManagementException { OperationManagementException {
boolean status = false; boolean status = false;
try { try {
MobileDeviceOperation mobileDeviceOperation = null; MobileDeviceOperationMapping mobileDeviceOperationMapping = null;
MobileOperation mobileOperation = MobileOperation mobileOperation =
MobileDeviceManagementUtil.convertToMobileOperation(operation); MobileDeviceManagementUtil.convertToMobileOperation(operation);
int operationId = MobileDeviceManagementDAOFactory.getMobileOperationDAO() int operationId = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
@ -53,12 +54,13 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
operationProperty); operationProperty);
} }
for (DeviceIdentifier deviceIdentifier : devices) { for (DeviceIdentifier deviceIdentifier : devices) {
mobileDeviceOperation = new MobileDeviceOperation(); mobileDeviceOperationMapping = new MobileDeviceOperationMapping();
mobileDeviceOperation.setOperationId(operationId); mobileDeviceOperationMapping.setOperationId(operationId);
mobileDeviceOperation.setDeviceId(deviceIdentifier.getId()); mobileDeviceOperationMapping.setDeviceId(deviceIdentifier.getId());
mobileDeviceOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW);
status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() status = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
.addMobileDeviceOperation( .addMobileDeviceOperation(
mobileDeviceOperation); mobileDeviceOperationMapping);
} }
} }
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
@ -74,17 +76,18 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier) public List<Operation> getOperations(DeviceIdentifier deviceIdentifier)
throws OperationManagementException { throws OperationManagementException {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
List<MobileDeviceOperation> mobileDeviceOperations = null; List<MobileDeviceOperationMapping> mobileDeviceOperationMappings = null;
List<MobileOperationProperty> operationProperties = null; List<MobileOperationProperty> operationProperties = null;
MobileOperation mobileOperation = null; MobileOperation mobileOperation = null;
try { try {
mobileDeviceOperations = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO() mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
.getAllMobileDeviceOperationsOfDevice( .getAllMobileDeviceOperationsOfDevice(
deviceIdentifier deviceIdentifier
.getId()); .getId());
if (mobileDeviceOperations.size() > 0) { if (mobileDeviceOperationMappings.size() > 0) {
List<Integer> operationIds = MobileDeviceManagementUtil List<Integer> operationIds = MobileDeviceManagementUtil
.getMobileOperationIdsFromMobileDeviceOperations(mobileDeviceOperations); .getMobileOperationIdsFromMobileDeviceOperations(
mobileDeviceOperationMappings);
for (Integer operationId : operationIds) { for (Integer operationId : operationIds) {
mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO() mobileOperation = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
.getMobileOperation( .getMobileOperation(
@ -107,4 +110,49 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
} }
return operations; return operations;
} }
@Override
public List<Operation> getPendingOperations(DeviceIdentifier deviceIdentifier)
throws OperationManagementException {
List<Operation> operations = new ArrayList<Operation>();
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings = null;
List<MobileOperationProperty> 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;
}
} }

@ -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.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.Operation; 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.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.MobileOperation;
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty; import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
@ -115,10 +115,10 @@ public class MobileDeviceManagementUtil {
} }
public static List<Integer> getMobileOperationIdsFromMobileDeviceOperations( public static List<Integer> getMobileOperationIdsFromMobileDeviceOperations(
List<MobileDeviceOperation> mobileDeviceOperations) { List<MobileDeviceOperationMapping> mobileDeviceOperationMappings) {
List<Integer> mobileOperationIds = new ArrayList<Integer>(); List<Integer> mobileOperationIds = new ArrayList<Integer>();
for(MobileDeviceOperation mobileDeviceOperation:mobileDeviceOperations){ for(MobileDeviceOperationMapping mobileDeviceOperationMapping : mobileDeviceOperationMappings){
mobileOperationIds.add(mobileDeviceOperation.getOperationId()); mobileOperationIds.add(mobileDeviceOperationMapping.getOperationId());
} }
return mobileOperationIds; return mobileOperationIds;
} }

@ -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;
}
}

@ -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);
}
}
}
}

@ -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<TestDBConfiguration> 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");
}
}

@ -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 {
}

@ -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 {
}

@ -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 {
}

@ -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 {
}

@ -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 {
}

@ -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<TestDBConfiguration> 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");
}
}

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<MobileDeviceMgtConfiguration>
<ManagementRepository>
<DataSourceConfiguration>
<JndiLookupDefinition>
<Name>jdbc/MobileDM_DS</Name>
</JndiLookupDefinition>
</DataSourceConfiguration>
</ManagementRepository>
<APIPublisher>
<APIs>
<MalformedAPI>
<Name>enrollment</Name>
<Owner>admin</Owner>
<Context>enrollment</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/</Endpoint>
<Transports>http,https</Transports>
</MalformedAPI>
</APIs>
</APIPublisher>
</MobileDeviceMgtConfiguration>

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<MobileDeviceMgtConfiguration>
<ManagementRepository>
<DataSourceConfiguration>
<JndiLookupDefinition>
<Name>jdbc/MobileDM_DS</Name>
</JndiLookupDefinition>
</DataSourceConfiguration>
</ManagementRepository>
<MalformedAPIPublisher>
<APIs>
<API>
<Name>enrollment</Name>
<Owner>admin</Owner>
<Context>enrollment</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/</Endpoint>
<Transports>http,https</Transports>
</API>
</APIs>
</MalformedAPIPublisher>
</MobileDeviceMgtConfiguration>

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<MobileDeviceMgtConfiguration>
<ManagementRepository>
<DataSourceConfiguration>
<JndiLookupDefinition>
<Name>jdbc/MobileDM_DS</Name>
</JndiLookupDefinition>
</DataSourceConfiguration>
</ManagementRepository>
<APIPublisher>
<MalformedAPIs>
<API>
<Name>enrollment</Name>
<Owner>admin</Owner>
<Context>enrollment</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/</Endpoint>
<Transports>http,https</Transports>
</API>
</MalformedAPIs>
</APIPublisher>
</MobileDeviceMgtConfiguration>

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<MobileDeviceMgtConfiguration>
<ManagementRepository>
<MalformedDataSourceConfiguration>
<JndiLookupDefinition>
<Name>jdbc/MobileDM_DS</Name>
</JndiLookupDefinition>
</MalformedDataSourceConfiguration>
</ManagementRepository>
<APIPublisher>
<APIs>
<API>
<Name>enrollment</Name>
<Owner>admin</Owner>
<Context>enrollment</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/</Endpoint>
<Transports>http,https</Transports>
</API>
</APIs>
</APIPublisher>
</MobileDeviceMgtConfiguration>

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<MobileDeviceMgtConfiguration>
<ManagementRepository>
<DataSourceConfiguration>
<MalformedJndiLookupDefinition>
<Name>jdbc/MobileDM_DS</Name>
</MalformedJndiLookupDefinition>
</DataSourceConfiguration>
</ManagementRepository>
<APIPublisher>
<APIs>
<API>
<Name>enrollment</Name>
<Owner>admin</Owner>
<Context>enrollment</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/</Endpoint>
<Transports>http,https</Transports>
</API>
</APIs>
</APIPublisher>
</MobileDeviceMgtConfiguration>

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<MobileDeviceMgtConfiguration>
<MalformedManagementRepository>
<DataSourceConfiguration>
<JndiLookupDefinition>
<Name>jdbc/MobileDM_DS</Name>
</JndiLookupDefinition>
</DataSourceConfiguration>
</MalformedManagementRepository>
<APIPublisher>
<APIs>
<API>
<Name>enrollment</Name>
<Owner>admin</Owner>
<Context>enrollment</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/</Endpoint>
<Transports>http,https</Transports>
</API>
</APIs>
</APIPublisher>
</MobileDeviceMgtConfiguration>

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="MobileDeviceMgtConfiguration">
<xs:complexType>
<xs:sequence>
<xs:element name="ManagementRepository" minOccurs="1" maxOccurs="1"
type="DataSourceConfigurationType"/>
<xs:element name="APIPublisher" minOccurs="1" maxOccurs="1"
type="APIsConfigurationType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="JndiLookupDefinitionType">
<xs:sequence>
<xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="DataSourceConfigurationType">
<xs:sequence>
<xs:element name="JndiLookupDefinition" minOccurs="1" maxOccurs="1"
type="JndiLookupDefinitionType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ManagementRepositoryType">
<xs:sequence>
<xs:element name="DataSourceConfiguration" minOccurs="1" maxOccurs="1"
type="DataSourceConfigurationType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="APIConfigurationType">
<xs:all>
<xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="Owner" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="Context" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="Version" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="Endpoint" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="Transports" type="xs:string" minOccurs="1" maxOccurs="1"/>
</xs:all>
</xs:complexType>
<xs:complexType name="APIsConfigurationType">
<xs:sequence>
<xs:element name="API" maxOccurs="unbounded"
type="APIConfigurationType"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

@ -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 -- -----------------------------------------------------
( -- Table `MBL_DEVICE`
ID INT auto_increment NOT NULL, -- -----------------------------------------------------
DESCRIPTION TEXT NULL DEFAULT NULL, CREATE TABLE IF NOT EXISTS `MBL_DEVICE` (
NAME VARCHAR(100) NULL DEFAULT NULL, `MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL ,
DATE_OF_ENROLLMENT BIGINT NULL DEFAULT NULL, `REG_ID` VARCHAR(45) NULL DEFAULT NULL ,
DATE_OF_LAST_UPDATE BIGINT NULL DEFAULT NULL, `IMEI` VARCHAR(45) NULL DEFAULT NULL ,
OWNERSHIP VARCHAR(45) NULL DEFAULT NULL, `IMSI` VARCHAR(45) NULL DEFAULT NULL ,
STATUS VARCHAR(15) NULL DEFAULT NULL, `OS_VERSION` VARCHAR(45) NULL DEFAULT NULL ,
DEVICE_TYPE_ID INT(11) NULL DEFAULT NULL, `DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL ,
DEVICE_IDENTIFICATION VARCHAR(300) NULL DEFAULT NULL, `VENDOR` VARCHAR(45) NULL DEFAULT NULL ,
OWNER VARCHAR(45) NULL DEFAULT NULL, `LATITUDE` VARCHAR(45) NULL DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0, `LONGITUDE` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (ID), PRIMARY KEY (`MOBILE_DEVICE_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
); -- -----------------------------------------------------
-- 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);

@ -16,7 +16,7 @@
<DeviceMgtTestDBConfigurations> <DeviceMgtTestDBConfigurations>
<DBType typeName="H2"> <DBType typeName="H2">
<connectionurl>jdbc:h2:mem:cdm-test-db;DB_CLOSE_DELAY=-1</connectionurl> <connectionurl>jdbc:h2:mem:cdm-mobile-test-db;DB_CLOSE_DELAY=-1</connectionurl>
<driverclass>org.h2.Driver</driverclass> <driverclass>org.h2.Driver</driverclass>
<userName></userName> <userName></userName>
<pwd></pwd> <pwd></pwd>

@ -15,13 +15,12 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="EMM-core-initializer"> <suite name="CDM-Mobile-Tests">
<parameter name="useDefaultListeners" value="false"/> <parameter name="useDefaultListeners" value="false"/>
<test name="DAO Unit Tests" preserve-order="true"> <test name="DAO Unit Tests" preserve-order="true">
<parameter name="dbType" value="H2"/> <parameter name="dbType" value="H2"/>
<classes> <classes>
<class name="org.wso2.carbon.device.mgt.mobile.impl.dao.FeatureDAOTestSuite"/> <class name="org.wso2.carbon.device.mgt.mobile.impl.dao.FeatureDAOTestSuite"/>
</classes> </classes>
</test> </test>

@ -460,5 +460,15 @@
<fileMode>644</fileMode> <fileMode>644</fileMode>
</file> </file>
<!-- Copying H2 database related files corresponding to default Mobile Device management repository schema -->
<file>
<source>
../distribution/src/repository/database/WSO2MobileDM_DB.h2.db
</source>
<outputDirectory>${pom.artifactId}-${pom.version}/repository/database</outputDirectory>
<destName>WSO2MobileDM_DB.h2.db</destName>
<fileMode>644</fileMode>
</file>
</files> </files>
</assembly> </assembly>

@ -23,4 +23,4 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE
REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
-- TO:DO - Remove this INSERT sql statement. -- 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');

@ -31,13 +31,8 @@ CREATE TABLE IF NOT EXISTS `MBL_FEATURE` (
CREATE TABLE IF NOT EXISTS `MBL_OPERATION` ( CREATE TABLE IF NOT EXISTS `MBL_OPERATION` (
`OPERATION_ID` INT NOT NULL AUTO_INCREMENT , `OPERATION_ID` INT NOT NULL AUTO_INCREMENT ,
`FEATURE_CODE` VARCHAR(45) NOT NULL , `FEATURE_CODE` VARCHAR(45) NOT NULL ,
`CREATED_DATE` INT NULL , `CREATED_DATE` BIGINT NULL ,
PRIMARY KEY (`OPERATION_ID`) , 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);
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `MBL_DEVICE_OPERATION_MAPPING` -- 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` ( CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` (
`DEVICE_ID` VARCHAR(45) NOT NULL , `DEVICE_ID` VARCHAR(45) NOT NULL ,
`OPERATION_ID` INT NOT NULL , `OPERATION_ID` INT NOT NULL ,
`SENT_DATE` INT NULL , `SENT_DATE` BIGINT NULL ,
`RECEIVED_DATE` INT NULL , `RECEIVED_DATE` BIGINT NULL ,
`STATUS` VARCHAR(10) NOT NULL ,
PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) , PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`) ,
CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE`
FOREIGN KEY (`DEVICE_ID` ) FOREIGN KEY (`DEVICE_ID` )

@ -46,6 +46,7 @@ CREATE TABLE IF NOT EXISTS `MBL_DEVICE_OPERATION_MAPPING` (
`OPERATION_ID` INT NOT NULL, `OPERATION_ID` INT NOT NULL,
`SENT_DATE` INT NULL, `SENT_DATE` INT NULL,
`RECEIVED_DATE` INT NULL, `RECEIVED_DATE` INT NULL,
`STATUS` VARCHAR(10) NOT NULL,
PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`), PRIMARY KEY (`DEVICE_ID`, `OPERATION_ID`),
INDEX `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1_idx` (`OPERATION_ID` ASC), INDEX `fk_MBL_DEVICE_OPERATION_MBL_OPERATION1_idx` (`OPERATION_ID` ASC),
CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE` CONSTRAINT `fk_MBL_DEVICE_OPERATION_MBL_DEVICE`

@ -42,7 +42,8 @@ public class Enrollment {
private static Log log = LogFactory.getLog(Enrollment.class); private static Log log = LogFactory.getLog(Enrollment.class);
@POST @POST
public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException { public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device)
throws AndroidAgentException {
Message responseMsg = new Message(); Message responseMsg = new Message();
@ -93,7 +94,8 @@ public class Enrollment {
@PUT @PUT
@Path("{id}") @Path("{id}")
public Message modifyEnrollment(@PathParam("id") String id, org.wso2.carbon.device.mgt.common.Device device) public Message modifyEnrollment(@PathParam("id") String id,
org.wso2.carbon.device.mgt.common.Device device)
throws AndroidAgentException { throws AndroidAgentException {
boolean result; boolean result;
@ -123,7 +125,6 @@ public class Enrollment {
@DELETE @DELETE
@Path("{id}") @Path("{id}")
public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException { public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException {
Message responseMsg = new Message(); Message responseMsg = new Message();
boolean result; boolean result;
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);

@ -39,7 +39,7 @@ public class Operation {
@GET @GET
@Path("{id}") @Path("{id}")
public List<org.wso2.carbon.device.mgt.common.Operation> getAllOperations( public List<org.wso2.carbon.device.mgt.common.Operation> getPendingOperations(
@PathParam("id") String id) @PathParam("id") String id)
throws AndroidAgentException { throws AndroidAgentException {
@ -52,7 +52,7 @@ public class Operation {
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
operations = dmService.getOperationManager( operations = dmService.getOperationManager(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID) DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID)
.getOperations(deviceIdentifier); .getPendingOperations(deviceIdentifier);
Response.status(HttpStatus.SC_OK); Response.status(HttpStatus.SC_OK);
return operations; return operations;
} catch (DeviceManagementServiceException deviceMgtServiceEx) { } catch (DeviceManagementServiceException deviceMgtServiceEx) {

@ -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;
Loading…
Cancel
Save