forked from community/device-mgt-plugins
commit
d24c0be7c5
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
|
||||
import org.wso2.carbon.device.mgt.mobile.config.datasource.JNDILookupDefinition;
|
||||
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Factory class used to create MobileDeviceManagement related DAO objects.
|
||||
*/
|
||||
public abstract class AbstractMobileDeviceManagementDAOFactory implements MobileDeviceManagementDAOFactory {
|
||||
|
||||
private static final Log log = LogFactory.getLog(AbstractMobileDeviceManagementDAOFactory.class);
|
||||
private static Map<String, DataSource> dataSourceMap = new HashMap<>();
|
||||
private static boolean isInitialized;
|
||||
|
||||
public static void init(Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap)
|
||||
throws MobileDeviceMgtPluginException {
|
||||
DataSource dataSource;
|
||||
for (String pluginType : mobileDataSourceConfigMap.keySet()) {
|
||||
if (dataSourceMap.get(pluginType) == null) {
|
||||
dataSource = AbstractMobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfigMap.get
|
||||
(pluginType));
|
||||
dataSourceMap.put(pluginType, dataSource);
|
||||
}
|
||||
}
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
public static void init(String key, MobileDataSourceConfig mobileDataSourceConfig) throws
|
||||
MobileDeviceMgtPluginException {
|
||||
DataSource dataSource = AbstractMobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfig);
|
||||
dataSourceMap.put(key, dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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.getJndiLookupDefinition();
|
||||
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 Map<String, DataSource> getDataSourceMap() {
|
||||
return dataSourceMap;
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
||||
|
||||
public interface MobileDeviceManagementDAOFactoryInterface {
|
||||
|
||||
public MobileDeviceDAO getMobileDeviceDAO();
|
||||
|
||||
public MobileOperationDAO getMobileOperationDAO();
|
||||
|
||||
public MobileOperationPropertyDAO getMobileOperationPropertyDAO();
|
||||
|
||||
public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO();
|
||||
|
||||
public MobileFeatureDAO getMobileFeatureDAO();
|
||||
|
||||
public MobileFeaturePropertyDAO getFeaturePropertyDAO();
|
||||
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.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 {
|
||||
|
||||
/**
|
||||
* Adds a new mobile device operation mapping to the table.
|
||||
*
|
||||
* @param mblDeviceOperationMapping MobileDeviceOperationMapping object that holds data related
|
||||
* to the MobileDeviceOperationMapping to be inserted.
|
||||
* @return The status of the operation.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean addMobileDeviceOperationMapping(MobileDeviceOperationMapping mblDeviceOperationMapping)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Updates a MobileDeviceOperationMapping in MobileDeviceOperationMapping table.
|
||||
*
|
||||
* @param mblDeviceOperation MobileDeviceOperationMapping object that holds data has to be updated.
|
||||
* @return The status of the operation.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateMobileDeviceOperationMapping(MobileDeviceOperationMapping mblDeviceOperation)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Updates a MobileDeviceOperationMapping to In-Progress state in MobileDeviceOperationMapping
|
||||
* table.
|
||||
*
|
||||
* @param mblDeviceId MobileDevice id of the mappings to be updated.
|
||||
* @param operationId Operation id of the mapping to be updated.
|
||||
* @return The status of the operation.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateMobileDeviceOperationMappingToInProgress(String mblDeviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Updates a MobileDeviceOperationMapping to completed state in MobileDeviceOperationMapping
|
||||
* table.
|
||||
*
|
||||
* @param mblDeviceId MobileDevice id of the mappings to be updated.
|
||||
* @param operationId Operation id of the mapping to be updated.
|
||||
* @return The status of the operation.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateMobileDeviceOperationMappingToCompleted(String mblDeviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete a given MobileDeviceOperationMapping from MobileDeviceOperationMapping table.
|
||||
*
|
||||
* @param mblDeviceId MobileDevice id of the mappings to be deleted.
|
||||
* @param operationId Operation id of the mapping to be deleted.
|
||||
* @return The status of the operation.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean deleteMobileDeviceOperationMapping(String mblDeviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieves a given MobileDeviceOperationMapping object from the MobileDeviceOperationMapping
|
||||
* table.
|
||||
*
|
||||
* @param mblDeviceId 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 getMobileDeviceOperationMapping(String mblDeviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieves all the of MobileDeviceOperationMappings relevant to a given mobile device.
|
||||
*
|
||||
* @param mblDeviceId MobileDevice id of the mappings to be retrieved.
|
||||
* @return MobileDeviceOperationMapping object list.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
List<MobileDeviceOperationMapping> getAllMobileDeviceOperationMappingsOfDevice(String mblDeviceId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieves all the pending MobileDeviceOperationMappings of a mobile device.
|
||||
*
|
||||
* @param mblDeviceId MobileDevice id of the mappings to be retrieved.
|
||||
* @return MobileDeviceOperationMapping object list.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
List<MobileDeviceOperationMapping> getAllPendingOperationMappingsOfMobileDevice(String mblDeviceId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
|
||||
|
||||
/**
|
||||
* This class represents the key operations associated with persisting mobile operation related
|
||||
* information.
|
||||
*/
|
||||
public interface MobileOperationDAO {
|
||||
|
||||
/**
|
||||
* Adds a new Mobile operation to the MobileOperation table.
|
||||
* @param mblOperation MobileOperation object that holds data related to the operation to be
|
||||
* inserted.
|
||||
* @return The id of the inserted record, if the insertion was unsuccessful -1 is returned.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
int addMobileOperation(MobileOperation mblOperation) throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Updates a Mobile operation in the MobileOperation table.
|
||||
* @param mblOperation MobileOperation object that holds data has to be updated.
|
||||
* @return The status of the operation.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateMobileOperation(MobileOperation mblOperation) throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Deletes a given MobileOperation from MobileOperation table.
|
||||
* @param mblOperationId Operation code of the MobileOperation to be deleted.
|
||||
* @return The status of the operation.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean deleteMobileOperation(int mblOperationId) throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve a MobileOperation from MobileOperation table.
|
||||
* @param mblOperationId Operation id of the MobileOperation to be retrieved.
|
||||
* @return MobileOperation object that holds data of MobileOperation represented by operationId.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
MobileOperation getMobileOperation(int mblOperationId) throws MobileDeviceManagementDAOException;
|
||||
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class represents the key operations associated with persisting mobile operation property
|
||||
* related information.
|
||||
*
|
||||
*/
|
||||
public interface MobileOperationPropertyDAO {
|
||||
|
||||
/**
|
||||
* Add a new MobileOperationProperty to MobileOperationProperty table.
|
||||
*
|
||||
* @param mblOperationProperty MobileOperationProperty object that holds data related to the
|
||||
* operation property to be inserted.
|
||||
* @return The status of the operation.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean addMobileOperationProperty(MobileOperationProperty mblOperationProperty)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update a MobileOperationProperty in the MobileOperationProperty table.
|
||||
*
|
||||
* @param mblOperationProperty MobileOperationProperty object that holds data has to be updated.
|
||||
* @return The status of the operation.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateMobileOperationProperty(MobileOperationProperty mblOperationProperty)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Deletes MobileOperationProperties of a given operation id from the MobileOperationProperty
|
||||
* table.
|
||||
*
|
||||
* @param mblOperationId Operation id of the MobileOperationProperty to be deleted.
|
||||
* @return The status of the operation.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean deleteMobileOperationProperties(int mblOperationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve a given MobileOperationProperty from MobileOperationProperty table.
|
||||
*
|
||||
* @param mblOperationId Operation id of the mapping to be retrieved.
|
||||
* @param property Property of the mapping to be retrieved.
|
||||
* @return MobileOperationProperty object that holds data of the MobileOperationProperty
|
||||
* represented by mblOperationId and property.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
MobileOperationProperty getMobileOperationProperty(int mblOperationId, String property)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve all the MobileOperationProperties related to the a operation id from
|
||||
* MobileOperationProperty table.
|
||||
*
|
||||
* @param mblOperationId Operation id of the MobileOperationProperty to be retrieved.
|
||||
* @return List of MobileOperationProperty objects.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
List<MobileOperationProperty> getAllMobileOperationPropertiesOfOperation(int mblOperationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
}
|
@ -1,369 +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.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceOperationMappingDAO;
|
||||
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 addMobileDeviceOperationMapping(MobileDeviceOperationMapping mblDeviceOperationMapping)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO AD_DEVICE_OPERATION_MAPPING (DEVICE_ID, OPERATION_ID, SENT_DATE, " +
|
||||
"RECEIVED_DATE, STATUS) VALUES (?, ?, ?, ?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, mblDeviceOperationMapping.getDeviceId());
|
||||
stmt.setLong(2, mblDeviceOperationMapping.getOperationId());
|
||||
stmt.setLong(3, mblDeviceOperationMapping.getSentDate());
|
||||
stmt.setLong(4, mblDeviceOperationMapping.getReceivedDate());
|
||||
stmt.setString(5, mblDeviceOperationMapping.getStatus().name());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Added a MobileDevice-Mapping DeviceId : " + mblDeviceOperationMapping
|
||||
.getDeviceId() + ", " +
|
||||
"OperationId : " + mblDeviceOperationMapping.getOperationId() + " to the MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding device id - '" +
|
||||
mblDeviceOperationMapping.getDeviceId() + " and operation id - " +
|
||||
mblDeviceOperationMapping.getOperationId() +
|
||||
" to mapping table AD_DEVICE_OPERATION";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMobileDeviceOperationMapping(MobileDeviceOperationMapping mblDeviceOperation)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE AD_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ?, " +
|
||||
"STATUS = ? WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setLong(1, mblDeviceOperation.getSentDate());
|
||||
stmt.setLong(2, mblDeviceOperation.getReceivedDate());
|
||||
stmt.setString(3, mblDeviceOperation.getStatus().name());
|
||||
stmt.setString(4, mblDeviceOperation.getDeviceId());
|
||||
stmt.setInt(5, mblDeviceOperation.getOperationId());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Updated MobileDevice-Mapping DeviceId : " + mblDeviceOperation.getDeviceId() + " , " +
|
||||
"OperationId : " + mblDeviceOperation.getOperationId());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating device id - '" +
|
||||
mblDeviceOperation.getDeviceId() + " and operation id - " +
|
||||
mblDeviceOperation.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 updateMobileDeviceOperationMappingToInProgress(String mblDeviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE AD_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, mblDeviceId);
|
||||
stmt.setInt(4, operationId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Updated status of MobileDevice-Mapping DeviceId : " + mblDeviceId + " , " +
|
||||
"OperationId : " + operationId + " to In-Progress state");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while updating the Status of operation to in-progress of device id - '" +
|
||||
mblDeviceId + " 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 updateMobileDeviceOperationMappingToCompleted(String mblDeviceId,
|
||||
int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE AD_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, mblDeviceId);
|
||||
stmt.setInt(4, operationId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Updated status of MobileDevice-Mapping DeviceId : " + mblDeviceId + " , " +
|
||||
"OperationId : " + operationId + " to Completed state");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while updating the Status of operation to completed of device id - '" +
|
||||
mblDeviceId + " 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 deleteMobileDeviceOperationMapping(String mblDeviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND " +
|
||||
"OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setString(1, mblDeviceId);
|
||||
stmt.setInt(2, operationId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deleted MobileDevice-Mapping DeviceId : " + mblDeviceId + " , " +
|
||||
"OperationId : " + operationId + "from MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while deleting the table entry AD_DEVICE_OPERATION with " +
|
||||
" device id - '" + mblDeviceId + " and operation id - " + operationId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileDeviceOperationMapping getMobileDeviceOperationMapping(String mblDeviceId,
|
||||
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 " +
|
||||
"AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, mblDeviceId);
|
||||
stmt.setInt(2, operationId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
if (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));
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Fetched MobileDevice-Mapping of DeviceId : " + mblDeviceId + " , " +
|
||||
"OperationId : " + operationId );
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while fetching table MBL_DEVICE_OPERATION entry with device id - '" +
|
||||
mblDeviceId + " 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> getAllMobileDeviceOperationMappingsOfDevice(
|
||||
String mblDeviceId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileDeviceOperationMapping mblDeviceOperation;
|
||||
List<MobileDeviceOperationMapping> mblDeviceOperations =
|
||||
new ArrayList<MobileDeviceOperationMapping>();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " +
|
||||
"AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, mblDeviceId);
|
||||
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);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Fetched all MobileDevice-Mappings of DeviceId : " + mblDeviceId);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of " +
|
||||
"device id - '" + mblDeviceId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return mblDeviceOperations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileDeviceOperationMapping> getAllPendingOperationMappingsOfMobileDevice(
|
||||
String mblDeviceId)
|
||||
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" +
|
||||
" AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND STATUS = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, mblDeviceId);
|
||||
stmt.setString(2, MobileDeviceOperationMapping.Status.NEW.name());
|
||||
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);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Fetched all pending MobileDevice-Mappings of DeviceId : " + mblDeviceId);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of" +
|
||||
" device id - '" + mblDeviceId;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,192 +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.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileOperationDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Implementation of MobileOperationDAO.
|
||||
*/
|
||||
public class MobileOperationDAOImpl implements MobileOperationDAO {
|
||||
|
||||
public static final String COLUMN_OPERATION_ID = "OPERATION_ID";
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(MobileOperationDAOImpl.class);
|
||||
|
||||
public MobileOperationDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addMobileOperation(MobileOperation mblOperation)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
int status = -1;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO AD_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)";
|
||||
stmt = conn.prepareStatement(createDBQuery, new String[] { COLUMN_OPERATION_ID });
|
||||
stmt.setString(1, mblOperation.getFeatureCode());
|
||||
stmt.setLong(2, mblOperation.getCreatedDate());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
ResultSet rs = stmt.getGeneratedKeys();
|
||||
if (rs != null && rs.next()) {
|
||||
status = rs.getInt(1);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Added a new MobileOperation " + mblOperation.getFeatureCode() +
|
||||
" to MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding the operation - '" +
|
||||
mblOperation.getFeatureCode() + "' to MBL_OPERATION table";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMobileOperation(MobileOperation mblOperation)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE AD_OPERATION SET FEATURE_CODE = ?, CREATED_DATE = ? WHERE " +
|
||||
"OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setString(1, mblOperation.getFeatureCode());
|
||||
stmt.setLong(2, mblOperation.getCreatedDate());
|
||||
stmt.setInt(3, mblOperation.getOperationId());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Updated MobileOperation " + mblOperation.getFeatureCode() +
|
||||
" to MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while updating the MBL_OPERATION table entry with operation id - '" +
|
||||
mblOperation.getOperationId() + "'";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteMobileOperation(int mblOperationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM AD_OPERATION WHERE OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setInt(1, mblOperationId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deleted a new MobileOperation " + mblOperationId +
|
||||
" from MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting MBL_OPERATION entry with operation Id - ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileOperation getMobileOperation(int mblOperationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileOperation operation = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM AD_OPERATION WHERE " +
|
||||
"OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setInt(1, mblOperationId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
operation = new MobileOperation();
|
||||
operation.setOperationId(resultSet.getInt(1));
|
||||
operation.setFeatureCode(resultSet.getString(2));
|
||||
operation.setCreatedDate(resultSet.getLong(3));
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Fetched MobileOperation " + operation.getFeatureCode() +
|
||||
" from MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching operationId - '" +
|
||||
mblOperationId + "' from MBL_OPERATION";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,239 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileOperationPropertyDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
|
||||
|
||||
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 MobileOperationPropertyDAO.
|
||||
*/
|
||||
public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(MobileOperationPropertyDAOImpl.class);
|
||||
|
||||
public MobileOperationPropertyDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addMobileOperationProperty(MobileOperationProperty mblOperationProperty)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO AD_OPERATION_PROPERTY(OPERATION_ID, PROPERTY, VALUE) " +
|
||||
"VALUES ( ?, ?, ?)";
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setInt(1, mblOperationProperty.getOperationId());
|
||||
stmt.setString(2, mblOperationProperty.getProperty());
|
||||
stmt.setString(3, mblOperationProperty.getValue());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Added a new MobileOperationProperty " + mblOperationProperty.getProperty() +
|
||||
" to MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while adding mobile operation property to MBL_OPERATION_PROPERTY " +
|
||||
"table";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMobileOperationProperty(
|
||||
MobileOperationProperty mblOperationProperty)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"UPDATE AD_OPERATION_PROPERTY SET VALUE = ? WHERE OPERATION_ID = ? AND " +
|
||||
"PROPERTY = ?";
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, mblOperationProperty.getValue());
|
||||
stmt.setInt(2, mblOperationProperty.getOperationId());
|
||||
stmt.setString(3, mblOperationProperty.getProperty());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Updated MobileOperationProperty " + mblOperationProperty.getProperty() +
|
||||
" to MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while updating the mobile operation property in" +
|
||||
" MBL_OPERATION_PROPERTY table.";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteMobileOperationProperties(int mblOperationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM AD_OPERATION_PROPERTY WHERE OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setInt(1, mblOperationId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Deleted MobileOperationProperties of operation-id " +
|
||||
mblOperationId +
|
||||
" from MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while deleting MBL_OPERATION_PROPERTY entry with operation Id - ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileOperationProperty getMobileOperationProperty(int mblOperationId,
|
||||
String property)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileOperationProperty mobileOperationProperty = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE " +
|
||||
"OPERATION_ID = ? AND PROPERTY = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setInt(1, mblOperationId);
|
||||
stmt.setString(2, property);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
mobileOperationProperty = new MobileOperationProperty();
|
||||
mobileOperationProperty.setOperationId(resultSet.getInt(1));
|
||||
mobileOperationProperty.setProperty(resultSet.getString(2));
|
||||
mobileOperationProperty.setValue(resultSet.getString(3));
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Fetched MobileOperationProperty of Operation-id : " +
|
||||
mblOperationId +
|
||||
" Property : " + property + " from MDM database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while fetching the mobile operation property of Operation_id : " +
|
||||
mblOperationId + " and Property : " + property;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return mobileOperationProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MobileOperationProperty> getAllMobileOperationPropertiesOfOperation(
|
||||
int mblOperationId) throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
MobileOperationProperty mobileOperationProperty;
|
||||
List<MobileOperationProperty> properties = new ArrayList<MobileOperationProperty>();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE " +
|
||||
"OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setInt(1, mblOperationId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
mobileOperationProperty = new MobileOperationProperty();
|
||||
mobileOperationProperty.setOperationId(resultSet.getInt(1));
|
||||
mobileOperationProperty.setProperty(resultSet.getString(2));
|
||||
mobileOperationProperty.setValue(resultSet.getString(3));
|
||||
properties.add(mobileOperationProperty);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Fetched all MobileOperationProperties of Operation-id : " +
|
||||
mblOperationId +
|
||||
" from MDM database.");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg =
|
||||
"Error occurred while fetching the mobile operation properties of Operation_id " +
|
||||
mblOperationId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,441 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.tomcat.jdbc.pool.DataSource;
|
||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileDeviceOperationMappingDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileOperationDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
||||
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.impl.common.DBTypes;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class for holding unit-tests related to MobileDeviceOperationMappingDAO class.
|
||||
*
|
||||
*/
|
||||
public class MobileDeviceOperationMappingDAOTestSuite {
|
||||
|
||||
private static final Log log =
|
||||
LogFactory.getLog(MobileDeviceOperationMappingDAOTestSuite.class);
|
||||
public static final String TEST_MOBILE_DEVICE_ID = "ABCD";
|
||||
public static final String TEST_MOBILE_IMEI = "2412421412";
|
||||
public static final String TEST_MOBILE_IMSI = "325235235";
|
||||
public static final String TEST_MOBILE_MODEL = "S5";
|
||||
public static final String TEST_MOBILE_VENDOR = "samsung";
|
||||
public static final String TEST_MOBILE_REG_ID = "2414";
|
||||
public static final String TEST_MOBILE_OS_VERSION = "5.0.0";
|
||||
public static final String TEST_MOBILE_LATITUDE = "6.93N";
|
||||
public static final String TEST_MOBILE_LONGITUDE = "80.60E";
|
||||
public static final String TEST_MOBILE_TOKEN = "2412K2HKHK24K12H4";
|
||||
public static final String TEST_MOBILE_SERIAL = "24124IIH4I2K4";
|
||||
public static final String TEST_MOBILE_CHALLENGE = "ASFASFSAFASFATWTWQTTQWTWQTQWTQWTWQT";
|
||||
public static final String TEST_MOBILE_UNLOCK_TOKEN = "FAFWQUWFUQWYWQYRWQURYUURUWQUWRUWRUWE";
|
||||
public static final String TEST_MBL_OPR_FEATURE_CODE1 = "LOCK";
|
||||
public static final String TEST_MBL_OPR_FEATURE_CODE2 = "WIPE";
|
||||
public static final long TEST_MBL_OPR_CREATED_DATE = new java.util.Date().getTime();
|
||||
|
||||
private TestDBConfiguration testDBConfiguration;
|
||||
private MobileOperationDAOImpl mblOperationDAO;
|
||||
private MobileDeviceOperationMappingDAOImpl mblDeviceOperationMappingDAO;
|
||||
private int mblOperationId1;
|
||||
private int mblOperationId2;
|
||||
|
||||
@BeforeClass
|
||||
@Parameters("dbType")
|
||||
public void setUpDB(String dbTypeStr) throws Exception {
|
||||
|
||||
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||
testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType);
|
||||
|
||||
switch (dbType) {
|
||||
case H2:
|
||||
MobileDatabaseUtils.createH2DB(testDBConfiguration);
|
||||
DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||
PoolProperties properties = new PoolProperties();
|
||||
properties.setUrl(testDBConfiguration.getConnectionURL());
|
||||
properties.setDriverClassName(testDBConfiguration.getDriverClassName());
|
||||
properties.setUsername(testDBConfiguration.getUsername());
|
||||
properties.setPassword(testDBConfiguration.getPassword());
|
||||
testDataSource.setPoolProperties(properties);
|
||||
mblOperationDAO = new MobileOperationDAOImpl(testDataSource);
|
||||
mblDeviceOperationMappingDAO =
|
||||
new MobileDeviceOperationMappingDAOImpl(testDataSource);
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void addMobileDeviceOperationMappingTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
List<MobileDeviceOperationMapping> mblOperations =
|
||||
new ArrayList<MobileDeviceOperationMapping>();
|
||||
MobileDeviceOperationMapping mblDvOperationMapping =
|
||||
new MobileDeviceOperationMapping();
|
||||
//Add a new Device to the database
|
||||
MobileDevice mobileDevice = new MobileDevice();
|
||||
mobileDevice.setMobileDeviceId(TEST_MOBILE_DEVICE_ID);
|
||||
mobileDevice.setImei(TEST_MOBILE_IMEI);
|
||||
mobileDevice.setImsi(TEST_MOBILE_IMSI);
|
||||
mobileDevice.setModel(TEST_MOBILE_MODEL);
|
||||
mobileDevice.setVendor(TEST_MOBILE_VENDOR);
|
||||
mobileDevice.setOsVersion(TEST_MOBILE_OS_VERSION);
|
||||
mobileDevice.setLatitude(TEST_MOBILE_LATITUDE);
|
||||
mobileDevice.setLongitude(TEST_MOBILE_LONGITUDE);
|
||||
mobileDevice.setSerial(TEST_MOBILE_SERIAL);
|
||||
|
||||
//Add an Operation to the db
|
||||
MobileOperation mblOperation = new MobileOperation();
|
||||
mblOperation.setFeatureCode(TEST_MBL_OPR_FEATURE_CODE1);
|
||||
mblOperation.setCreatedDate(TEST_MBL_OPR_CREATED_DATE);
|
||||
mblOperationId1 = mblOperationDAO.addMobileOperation(mblOperation);
|
||||
|
||||
//Add a new Operation 2 to the db
|
||||
mblOperation.setFeatureCode(TEST_MBL_OPR_FEATURE_CODE2);
|
||||
mblOperation.setCreatedDate(TEST_MBL_OPR_CREATED_DATE);
|
||||
mblOperationId2 = mblOperationDAO.addMobileOperation(mblOperation);
|
||||
|
||||
//Add a device-operation mapping 1 to the table
|
||||
mblDvOperationMapping.setDeviceId(TEST_MOBILE_DEVICE_ID);
|
||||
mblDvOperationMapping.setOperationId(mblOperationId1);
|
||||
mblDvOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW);
|
||||
boolean status1 =
|
||||
mblDeviceOperationMappingDAO.addMobileDeviceOperationMapping(mblDvOperationMapping);
|
||||
|
||||
//Add a device-operation mapping 2 to the table
|
||||
mblDvOperationMapping.setDeviceId(TEST_MOBILE_DEVICE_ID);
|
||||
mblDvOperationMapping.setOperationId(mblOperationId2);
|
||||
mblDvOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW);
|
||||
boolean status2 =
|
||||
mblDeviceOperationMappingDAO.addMobileDeviceOperationMapping(mblDvOperationMapping);
|
||||
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " +
|
||||
"AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?";
|
||||
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
mblDvOperationMapping = new MobileDeviceOperationMapping();
|
||||
mblDvOperationMapping.setDeviceId(resultSet.getString(1));
|
||||
mblDvOperationMapping.setOperationId(resultSet.getInt(2));
|
||||
mblDvOperationMapping.setSentDate(resultSet.getLong(3));
|
||||
mblDvOperationMapping.setReceivedDate(resultSet.getLong(4));
|
||||
mblDvOperationMapping.setStatus(resultSet.getString(5));
|
||||
mblOperations.add(mblDvOperationMapping);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving Mobile Operation Mappings data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status1, "MobileOperationMapping1 has added ");
|
||||
Assert.assertTrue(status2, "MobileOperationMapping2 has added ");
|
||||
Assert.assertTrue(mblOperations.size() == 2, "MobileOperationMappings have retrieved ");
|
||||
|
||||
for (MobileDeviceOperationMapping mapping : mblOperations) {
|
||||
Assert.assertEquals(TEST_MOBILE_DEVICE_ID, mapping.getDeviceId(),
|
||||
"MobileOperationMapping device id has persisted ");
|
||||
Assert.assertEquals(MobileDeviceOperationMapping.Status.NEW, mapping.getStatus(),
|
||||
"MobileOperationMapping status has persisted ");
|
||||
Assert.assertTrue(mapping.getOperationId() > 0,
|
||||
"MobileOperationMapping operation-id has persisted ");
|
||||
Assert.assertTrue(mapping.getSentDate() == 0,
|
||||
"MobileOperationMapping sent-date has fetched ");
|
||||
Assert.assertTrue(mapping.getReceivedDate() == 0,
|
||||
"MobileOperationMapping received-date has fetched ");
|
||||
}
|
||||
}
|
||||
|
||||
//@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest" })
|
||||
public void getMobileDeviceOperationMappingTest() throws MobileDeviceManagementDAOException {
|
||||
MobileDeviceOperationMapping mblOperationMapping =
|
||||
mblDeviceOperationMappingDAO.getMobileDeviceOperationMapping(
|
||||
TEST_MOBILE_DEVICE_ID, mblOperationId1);
|
||||
Assert.assertNotNull(mblOperationMapping, "MobileOperationMapping 1 has fetched ");
|
||||
Assert.assertEquals(TEST_MOBILE_DEVICE_ID, mblOperationMapping.getDeviceId(),
|
||||
"MobileOperationMapping device id has fetched ");
|
||||
Assert.assertEquals(mblOperationId1, mblOperationMapping.getOperationId(),
|
||||
"MobileOperationMapping device id has fetched ");
|
||||
Assert.assertEquals(MobileDeviceOperationMapping.Status.NEW,
|
||||
mblOperationMapping.getStatus(),
|
||||
"MobileOperationMapping status has fetched ");
|
||||
Assert.assertTrue(mblOperationMapping.getSentDate() == 0,
|
||||
"MobileOperationMapping sent-date has fetched ");
|
||||
Assert.assertTrue(mblOperationMapping.getReceivedDate() == 0,
|
||||
"MobileOperationMapping received-date has fetched ");
|
||||
}
|
||||
|
||||
//@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest" })
|
||||
public void getAllMobileDeviceOperationMappingsOfDeviceTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
List<MobileDeviceOperationMapping> mblOperationMappings =
|
||||
mblDeviceOperationMappingDAO.getAllMobileDeviceOperationMappingsOfDevice(
|
||||
TEST_MOBILE_DEVICE_ID);
|
||||
Assert.assertNotNull(mblOperationMappings, "MobileOperationMappings have fetched ");
|
||||
Assert.assertTrue(mblOperationMappings.size() == 2,
|
||||
"All MobileOperationMappings have fetched ");
|
||||
for (MobileDeviceOperationMapping mblOperationMapping : mblOperationMappings) {
|
||||
Assert.assertEquals(TEST_MOBILE_DEVICE_ID, mblOperationMapping.getDeviceId(),
|
||||
"MobileOperationMapping device id has fetched ");
|
||||
Assert.assertTrue(mblOperationMapping.getOperationId() > 0,
|
||||
"MobileOperationMapping operation-id has fetched ");
|
||||
Assert.assertEquals(MobileDeviceOperationMapping.Status.NEW,
|
||||
mblOperationMapping.getStatus(),
|
||||
"MobileOperationMapping status has fetched ");
|
||||
Assert.assertTrue(mblOperationMapping.getSentDate() == 0,
|
||||
"MobileOperationMapping sent-date has fetched ");
|
||||
Assert.assertTrue(mblOperationMapping.getReceivedDate() == 0,
|
||||
"MobileOperationMapping received-date has fetched ");
|
||||
}
|
||||
}
|
||||
|
||||
/**@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest",
|
||||
"getAllMobileDeviceOperationMappingsOfDeviceTest" })*/
|
||||
public void updateMobileDeviceOperationMappingToInProgressTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
MobileDeviceOperationMapping mblOperationMapping = null;
|
||||
//Update device-operation to In-Progress state
|
||||
boolean status =
|
||||
mblDeviceOperationMappingDAO.updateMobileDeviceOperationMappingToInProgress(
|
||||
TEST_MOBILE_DEVICE_ID, mblOperationId1);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, STATUS FROM " +
|
||||
"AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
||||
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||
preparedStatement.setInt(2, mblOperationId1);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
mblOperationMapping = new MobileDeviceOperationMapping();
|
||||
mblOperationMapping.setDeviceId(resultSet.getString(1));
|
||||
mblOperationMapping.setOperationId(resultSet.getInt(2));
|
||||
mblOperationMapping.setSentDate(resultSet.getLong(3));
|
||||
mblOperationMapping.setStatus(resultSet.getString(4));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving Mobile Operation Mappings data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status, "MobileOperationMapping 1 has updated ");
|
||||
Assert.assertNotNull(mblOperationMapping, "MobileOperationMappings have fetched ");
|
||||
Assert.assertEquals(MobileDeviceOperationMapping.Status.INPROGRESS,
|
||||
mblOperationMapping.getStatus(),
|
||||
"MobileOperationMapping status has updated ");
|
||||
Assert.assertTrue(mblOperationMapping.getSentDate() > 0,
|
||||
"MobileOperationMapping sent-date has updated ");
|
||||
}
|
||||
|
||||
/**
|
||||
@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest",
|
||||
"getAllMobileDeviceOperationMappingsOfDeviceTest" })*/
|
||||
public void updateMobileDeviceOperationMappingToCompletedTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
MobileDeviceOperationMapping mblOperationMapping = null;
|
||||
//Update device-operation to Completed state
|
||||
boolean status =
|
||||
mblDeviceOperationMappingDAO.updateMobileDeviceOperationMappingToCompleted(
|
||||
TEST_MOBILE_DEVICE_ID, mblOperationId1);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, RECEIVED_DATE, STATUS FROM " +
|
||||
"AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
||||
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||
preparedStatement.setInt(2, mblOperationId1);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
mblOperationMapping = new MobileDeviceOperationMapping();
|
||||
mblOperationMapping.setDeviceId(resultSet.getString(1));
|
||||
mblOperationMapping.setOperationId(resultSet.getInt(2));
|
||||
mblOperationMapping.setReceivedDate(resultSet.getLong(3));
|
||||
mblOperationMapping.setStatus(resultSet.getString(4));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving Mobile Operation Mappings data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status, "MobileOperationMapping 1 has updated ");
|
||||
Assert.assertNotNull(mblOperationMapping, "MobileOperationMappings have fetched ");
|
||||
Assert.assertEquals(MobileDeviceOperationMapping.Status.COMPLETED,
|
||||
mblOperationMapping.getStatus(),
|
||||
"MobileOperationMapping status has updated ");
|
||||
Assert.assertTrue(mblOperationMapping.getReceivedDate() > 0,
|
||||
"MobileOperationMapping received-date has updated ");
|
||||
}
|
||||
|
||||
/**
|
||||
@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest",
|
||||
"getAllMobileDeviceOperationMappingsOfDeviceTest",
|
||||
"updateMobileDeviceOperationMappingToInProgressTest",
|
||||
"updateMobileDeviceOperationMappingToCompletedTest" })*/
|
||||
public void updateMobileDeviceOperationMappingTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
MobileDeviceOperationMapping mblOperationMapping = new MobileDeviceOperationMapping();
|
||||
long currentTime = new java.util.Date().getTime();
|
||||
//Update device-operation mapping 1
|
||||
mblOperationMapping.setDeviceId(TEST_MOBILE_DEVICE_ID);
|
||||
mblOperationMapping.setOperationId(mblOperationId1);
|
||||
mblOperationMapping.setStatus(MobileDeviceOperationMapping.Status.INPROGRESS);
|
||||
mblOperationMapping.setSentDate(currentTime);
|
||||
mblOperationMapping.setReceivedDate(currentTime);
|
||||
boolean status =
|
||||
mblDeviceOperationMappingDAO.updateMobileDeviceOperationMapping(
|
||||
mblOperationMapping);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, RECEIVED_DATE, SENT_DATE, STATUS FROM " +
|
||||
"AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
||||
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||
preparedStatement.setInt(2, mblOperationId1);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
mblOperationMapping = new MobileDeviceOperationMapping();
|
||||
mblOperationMapping.setDeviceId(resultSet.getString(1));
|
||||
mblOperationMapping.setOperationId(resultSet.getInt(2));
|
||||
mblOperationMapping.setReceivedDate(resultSet.getLong(3));
|
||||
mblOperationMapping.setSentDate(resultSet.getLong(4));
|
||||
mblOperationMapping.setStatus(resultSet.getString(5));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving Mobile Operation Mappings data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status, "MobileOperationMapping 1 has updated ");
|
||||
Assert.assertNotNull(mblOperationMapping, "MobileOperationMappings have fetched ");
|
||||
Assert.assertEquals(MobileDeviceOperationMapping.Status.INPROGRESS,
|
||||
mblOperationMapping.getStatus(),
|
||||
"MobileOperationMapping status has updated ");
|
||||
Assert.assertTrue(mblOperationMapping.getReceivedDate() == currentTime,
|
||||
"MobileOperationMapping received-date has updated ");
|
||||
Assert.assertTrue(mblOperationMapping.getSentDate() == currentTime,
|
||||
"MobileOperationMapping sent-date has updated ");
|
||||
}
|
||||
|
||||
/**
|
||||
@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest",
|
||||
"getAllMobileDeviceOperationMappingsOfDeviceTest",
|
||||
"updateMobileDeviceOperationMappingToInProgressTest" })*/
|
||||
public void getAllPendingOperationMappingsOfMobileDeviceTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
List<MobileDeviceOperationMapping> mblOperationMappings =
|
||||
mblDeviceOperationMappingDAO.getAllPendingOperationMappingsOfMobileDevice(
|
||||
TEST_MOBILE_DEVICE_ID);
|
||||
Assert.assertNotNull(mblOperationMappings, "Pending MobileOperationMappings have fetched ");
|
||||
Assert.assertTrue(mblOperationMappings.size() == 1,
|
||||
"All MobileOperationMappings have fetched ");
|
||||
for (MobileDeviceOperationMapping mblOperationMapping : mblOperationMappings) {
|
||||
Assert.assertEquals(TEST_MOBILE_DEVICE_ID, mblOperationMapping.getDeviceId(),
|
||||
"MobileOperationMapping device id has fetched ");
|
||||
Assert.assertTrue(mblOperationMapping.getOperationId() == mblOperationId2,
|
||||
"MobileOperationMapping operation-id has fetched ");
|
||||
Assert.assertEquals(MobileDeviceOperationMapping.Status.NEW,
|
||||
mblOperationMapping.getStatus(),
|
||||
"MobileOperationMapping status has fetched ");
|
||||
Assert.assertTrue(mblOperationMapping.getSentDate() == 0,
|
||||
"MobileOperationMapping sent-date has fetched ");
|
||||
Assert.assertTrue(mblOperationMapping.getReceivedDate() == 0,
|
||||
"MobileOperationMapping received-date has fetched ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest",
|
||||
"getAllMobileDeviceOperationMappingsOfDeviceTest",
|
||||
"updateMobileDeviceOperationMappingToInProgressTest",
|
||||
"updateMobileDeviceOperationMappingToCompletedTest",
|
||||
"updateMobileDeviceOperationMappingTest" })*/
|
||||
public void deleteMobileDeviceOperationMappingTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
boolean status =
|
||||
mblDeviceOperationMappingDAO.deleteMobileDeviceOperationMapping(
|
||||
TEST_MOBILE_DEVICE_ID, mblOperationId1);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, RECEIVED_DATE, SENT_DATE, STATUS FROM " +
|
||||
"AD_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
||||
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||
preparedStatement.setInt(2, mblOperationId1);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
status = false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving MobileFeatureProperty data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status, "MobileDeviceOperationMapping 1 has deleted ");
|
||||
}
|
||||
}
|
@ -1,186 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.tomcat.jdbc.pool.DataSource;
|
||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileOperationDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
|
||||
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.dao.util.MobileDatabaseUtils;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* Class for holding unit-tests related to MobileOperationDAO class.
|
||||
*/
|
||||
public class MobileOperationDAOTestSuite {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MobileOperationDAOTestSuite.class);
|
||||
public static final String TEST_MBL_OPR_FEATURE_CODE = "LOCK";
|
||||
public static final String TEST_MBL_OPR_UPDATED_FEATURE_CODE = "MUTE";
|
||||
public static final long TEST_MBL_OPR_CREATED_DATE = new java.util.Date().getTime();
|
||||
private TestDBConfiguration testDBConfiguration;
|
||||
private MobileOperationDAOImpl mblOperationDAO;
|
||||
private int mblOperationId;
|
||||
|
||||
@BeforeClass
|
||||
@Parameters("dbType")
|
||||
public void setUpDB(String dbTypeStr) throws Exception {
|
||||
|
||||
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||
testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType);
|
||||
|
||||
switch (dbType) {
|
||||
case H2:
|
||||
MobileDatabaseUtils.createH2DB(testDBConfiguration);
|
||||
DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||
PoolProperties properties = new PoolProperties();
|
||||
properties.setUrl(testDBConfiguration.getConnectionURL());
|
||||
properties.setDriverClassName(testDBConfiguration.getDriverClassName());
|
||||
properties.setUsername(testDBConfiguration.getUsername());
|
||||
properties.setPassword(testDBConfiguration.getPassword());
|
||||
testDataSource.setPoolProperties(properties);
|
||||
mblOperationDAO = new MobileOperationDAOImpl(testDataSource);
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addMobileOperationTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
MobileOperation mblOperation = new MobileOperation();
|
||||
MobileOperation testMblOperation = new MobileOperation();
|
||||
mblOperation.setFeatureCode(TEST_MBL_OPR_FEATURE_CODE);
|
||||
mblOperation.setCreatedDate(TEST_MBL_OPR_CREATED_DATE);
|
||||
mblOperationId = mblOperationDAO.addMobileOperation(mblOperation);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String selectDBQuery =
|
||||
"SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM AD_OPERATION WHERE OPERATION_ID = ?";
|
||||
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||
preparedStatement.setInt(1, mblOperationId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
testMblOperation.setOperationId(resultSet.getInt(1));
|
||||
testMblOperation.setFeatureCode(resultSet.getString(2));
|
||||
testMblOperation.setCreatedDate(resultSet.getLong(3));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving Mobile Operation data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(mblOperationId > 0, "MobileOperation has added ");
|
||||
Assert.assertEquals(TEST_MBL_OPR_FEATURE_CODE, testMblOperation.getFeatureCode(),
|
||||
"MobileOperation feature code has persisted ");
|
||||
Assert.assertEquals(TEST_MBL_OPR_CREATED_DATE, testMblOperation.getCreatedDate(),
|
||||
"MobileOperation created-date has persisted ");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileOperationTest" })
|
||||
public void getMobileOperationTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
MobileOperation mobileOperation = mblOperationDAO.getMobileOperation(mblOperationId);
|
||||
Assert.assertEquals(TEST_MBL_OPR_CREATED_DATE, mobileOperation.getCreatedDate(),
|
||||
"MobileOperation created-date has retrieved ");
|
||||
Assert.assertEquals(TEST_MBL_OPR_FEATURE_CODE, mobileOperation.getFeatureCode(),
|
||||
"MobileOperation feature-code has retrieved ");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileOperationTest", "getMobileOperationTest" })
|
||||
public void updateMobileOperationTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
long updatedDate = new java.util.Date().getTime();
|
||||
MobileOperation mblOperation = new MobileOperation();
|
||||
MobileOperation testMblOperation = new MobileOperation();
|
||||
mblOperation.setFeatureCode(TEST_MBL_OPR_UPDATED_FEATURE_CODE);
|
||||
mblOperation.setCreatedDate(updatedDate);
|
||||
mblOperation.setOperationId(mblOperationId);
|
||||
boolean status = mblOperationDAO.updateMobileOperation(mblOperation);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String selectDBQuery =
|
||||
"SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM AD_OPERATION WHERE OPERATION_ID = ?";
|
||||
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||
preparedStatement.setInt(1, mblOperationId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
testMblOperation.setOperationId(resultSet.getInt(1));
|
||||
testMblOperation.setFeatureCode(resultSet.getString(2));
|
||||
testMblOperation.setCreatedDate(resultSet.getLong(3));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving Mobile Operation data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status, "MobileOperation has updated ");
|
||||
Assert.assertEquals(TEST_MBL_OPR_UPDATED_FEATURE_CODE, testMblOperation.getFeatureCode(),
|
||||
"MobileOperation feature code has updated ");
|
||||
Assert.assertEquals(updatedDate, testMblOperation.getCreatedDate(),
|
||||
"MobileOperation created-date has updated ");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileOperationTest", "getMobileOperationTest",
|
||||
"updateMobileOperationTest" })
|
||||
public void deleteMobileDeviceTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
boolean deleted = mblOperationDAO.deleteMobileOperation(mblOperationId);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String selectDBQuery =
|
||||
"SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM AD_OPERATION WHERE OPERATION_ID = ?";
|
||||
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||
preparedStatement.setInt(1, mblOperationId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
deleted = false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving Mobile Operation data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(deleted, "MobileOperation has deleted ");
|
||||
}
|
||||
}
|
@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.tomcat.jdbc.pool.DataSource;
|
||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileOperationDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileOperationPropertyDAOImpl;
|
||||
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.impl.common.DBTypes;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class for holding unit-tests related to MobileOperationPropertyDAO class.
|
||||
*
|
||||
*/
|
||||
public class MobileOperationPropertyDAOTestSuite {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MobileOperationPropertyDAOTestSuite.class);
|
||||
public static final String TEST_MBL_OPR_FEATURE_CODE = "LOCK";
|
||||
public static final long TEST_MBL_OPR_CREATED_DATE = new java.util.Date().getTime();
|
||||
public static final String TEST_MBL_OPR_PROPERTY_SSID = "SSID";
|
||||
public static final String TEST_MBL_OPR_PROPERTY_SSID_VALUE = "wso2";
|
||||
public static final String TEST_MBL_OPR_PROPERTY_PWD = "PASSWORD";
|
||||
public static final String TEST_MBL_OPR_PROPERTY_PWD_VALUE = "wso2";
|
||||
public static final String TEST_MBL_OPR_PROPERTY_PWD_UPDATED_VALUE = "wso2mdm";
|
||||
private int mblOperationId;
|
||||
private TestDBConfiguration testDBConfiguration;
|
||||
private MobileOperationPropertyDAOImpl mobileOperationPropertyDAO;
|
||||
private MobileOperationDAOImpl mblOperationDAO;
|
||||
|
||||
@BeforeClass
|
||||
@Parameters("dbType")
|
||||
public void setUpDB(String dbTypeStr) throws Exception {
|
||||
|
||||
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||
testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType);
|
||||
|
||||
switch (dbType) {
|
||||
case H2:
|
||||
MobileDatabaseUtils.createH2DB(testDBConfiguration);
|
||||
DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||
PoolProperties properties = new PoolProperties();
|
||||
properties.setUrl(testDBConfiguration.getConnectionURL());
|
||||
properties.setDriverClassName(testDBConfiguration.getDriverClassName());
|
||||
properties.setUsername(testDBConfiguration.getUsername());
|
||||
properties.setPassword(testDBConfiguration.getPassword());
|
||||
testDataSource.setPoolProperties(properties);
|
||||
mobileOperationPropertyDAO = new MobileOperationPropertyDAOImpl(testDataSource);
|
||||
mblOperationDAO = new MobileOperationDAOImpl(testDataSource);
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addMobileOperationPropertyTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
MobileOperation mblOperation = new MobileOperation();
|
||||
MobileOperationProperty operationProperty = new MobileOperationProperty();
|
||||
List<MobileOperationProperty> properties = new ArrayList<MobileOperationProperty>();
|
||||
//Add a new Operation to the database
|
||||
MobileOperation testMblOperation = new MobileOperation();
|
||||
mblOperation.setFeatureCode(TEST_MBL_OPR_FEATURE_CODE);
|
||||
mblOperation.setCreatedDate(TEST_MBL_OPR_CREATED_DATE);
|
||||
mblOperationId = mblOperationDAO.addMobileOperation(mblOperation);
|
||||
//Add property1
|
||||
operationProperty.setOperationId(mblOperationId);
|
||||
operationProperty.setProperty(TEST_MBL_OPR_PROPERTY_SSID);
|
||||
operationProperty.setValue(TEST_MBL_OPR_PROPERTY_SSID_VALUE);
|
||||
boolean status1 = mobileOperationPropertyDAO.addMobileOperationProperty(operationProperty);
|
||||
|
||||
//add property2
|
||||
operationProperty = new MobileOperationProperty();
|
||||
operationProperty.setOperationId(mblOperationId);
|
||||
operationProperty.setProperty(TEST_MBL_OPR_PROPERTY_PWD);
|
||||
operationProperty.setValue(TEST_MBL_OPR_PROPERTY_PWD_VALUE);
|
||||
boolean status2 = mobileOperationPropertyDAO.addMobileOperationProperty(operationProperty);
|
||||
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String selectDBQuery =
|
||||
"SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE OPERATION_ID = ?";
|
||||
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||
preparedStatement.setInt(1, mblOperationId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
operationProperty = new MobileOperationProperty();
|
||||
operationProperty.setOperationId(resultSet.getInt(1));
|
||||
operationProperty.setProperty(resultSet.getString(2));
|
||||
operationProperty.setValue(resultSet.getString(3));
|
||||
properties.add(operationProperty);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving Mobile Operation Property data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status1, "MobileOperationProperty1 has added ");
|
||||
Assert.assertTrue(status2, "MobileOperationProperty2 has added ");
|
||||
Assert.assertTrue(properties.size() == 2, "MobileOperationProperties have retrieved ");
|
||||
|
||||
for (MobileOperationProperty mobileOperationProperty : properties) {
|
||||
Assert.assertNotNull(mobileOperationProperty.getProperty(),
|
||||
"MobileOperationProperty property has persisted ");
|
||||
Assert.assertNotNull(mobileOperationProperty.getValue(),
|
||||
"MobileOperationProperty value has persisted ");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileOperationPropertyTest" })
|
||||
public void getMobileOperationPropertyTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
MobileOperationProperty mobileOperationProperty = mobileOperationPropertyDAO
|
||||
.getMobileOperationProperty(mblOperationId, TEST_MBL_OPR_PROPERTY_PWD);
|
||||
Assert.assertEquals(mblOperationId, mobileOperationProperty.getOperationId(),
|
||||
"MobileOperationProperty operation-id has retrieved ");
|
||||
Assert.assertEquals(TEST_MBL_OPR_PROPERTY_PWD, mobileOperationProperty.getProperty(),
|
||||
"MobileOperationProperty property has retrieved ");
|
||||
Assert.assertEquals(TEST_MBL_OPR_PROPERTY_PWD_VALUE, mobileOperationProperty.getValue(),
|
||||
"MobileOperationProperty property-value has retrieved ");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileOperationPropertyTest" })
|
||||
public void getAllMobileOperationPropertiesOfOperationTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
List<MobileOperationProperty> mobileOperationProperties = mobileOperationPropertyDAO
|
||||
.getAllMobileOperationPropertiesOfOperation(mblOperationId);
|
||||
Assert.assertTrue(mobileOperationProperties.size() == 2,
|
||||
"MobileOperationProperties of operation has retrieved");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileOperationPropertyTest", "getMobileOperationPropertyTest",
|
||||
"getAllMobileOperationPropertiesOfOperationTest" })
|
||||
public void updateMobileOperationPropertyTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
MobileOperationProperty mblOperationProperty = new MobileOperationProperty();
|
||||
MobileOperationProperty testMblOperationProperty = new MobileOperationProperty();
|
||||
mblOperationProperty.setOperationId(mblOperationId);
|
||||
mblOperationProperty.setProperty(TEST_MBL_OPR_PROPERTY_PWD);
|
||||
mblOperationProperty.setValue(TEST_MBL_OPR_PROPERTY_PWD_UPDATED_VALUE);
|
||||
|
||||
boolean status =
|
||||
mobileOperationPropertyDAO.updateMobileOperationProperty(mblOperationProperty);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String selectDBQuery =
|
||||
"SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE" +
|
||||
" OPERATION_ID = ? AND PROPERTY = ?";
|
||||
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||
preparedStatement.setInt(1, mblOperationId);
|
||||
preparedStatement.setString(2, TEST_MBL_OPR_PROPERTY_PWD);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
testMblOperationProperty.setOperationId(resultSet.getInt(1));
|
||||
testMblOperationProperty.setProperty(resultSet.getString(2));
|
||||
testMblOperationProperty.setValue(resultSet.getString(3));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving MobileOperationProperty data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status, "MobileOperationProperty has updated ");
|
||||
Assert.assertEquals(TEST_MBL_OPR_PROPERTY_PWD_UPDATED_VALUE,
|
||||
testMblOperationProperty.getValue(),
|
||||
"MobileOperationProperty value has updated ");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "addMobileOperationPropertyTest", "getMobileOperationPropertyTest",
|
||||
"getAllMobileOperationPropertiesOfOperationTest",
|
||||
"updateMobileOperationPropertyTest" })
|
||||
public void deleteMobileOperationPropertiesOfOperationTest()
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
boolean status =
|
||||
mobileOperationPropertyDAO.deleteMobileOperationProperties(mblOperationId);
|
||||
try {
|
||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||
String selectDBQuery =
|
||||
"SELECT OPERATION_ID, PROPERTY, VALUE FROM AD_OPERATION_PROPERTY WHERE" +
|
||||
" OPERATION_ID = ?";
|
||||
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||
preparedStatement.setInt(1, mblOperationId);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
status = false;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error in retrieving MobileOperationProperty data ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||
}
|
||||
Assert.assertTrue(status, "MobileOperationProperty has deleted ");
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `AD_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE AD_DEVICE (
|
||||
DEVICE_ID VARCHAR(45) NOT NULL,
|
||||
GCM_TOKEN VARCHAR(45) NULL DEFAULT NULL,
|
||||
DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL,
|
||||
IMEI VARCHAR(45) NULL DEFAULT NULL,
|
||||
IMSI VARCHAR(45) NULL DEFAULT NULL,
|
||||
OS_VERSION VARCHAR(45) NULL DEFAULT NULL,
|
||||
DEVICE_MODEL VARCHAR(45) NULL DEFAULT NULL,
|
||||
VENDOR VARCHAR(45) NULL DEFAULT NULL,
|
||||
LATITUDE VARCHAR(45) NULL DEFAULT NULL,
|
||||
LONGITUDE VARCHAR(45) NULL DEFAULT NULL,
|
||||
SERIAL VARCHAR(45) NULL DEFAULT NULL,
|
||||
MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL,
|
||||
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (DEVICE_ID));
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `AD_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE AD_FEATURE (
|
||||
ID INT NOT NULL IDENTITY,
|
||||
CODE VARCHAR(45) NOT NULL,
|
||||
NAME VARCHAR(100) NULL,
|
||||
DESCRIPTION VARCHAR(200) NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
@ -0,0 +1,31 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `AD_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `AD_DEVICE` (
|
||||
`DEVICE_ID` VARCHAR(45) NOT NULL,
|
||||
`GCM_TOKEN` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL,
|
||||
`IMEI` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`IMSI` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`OS_VERSION` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`VENDOR` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`LATITUDE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`LONGITUDE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`SERIAL` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`DEVICE_ID`))
|
||||
ENGINE = InnoDB;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `AD_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `AD_FEATURE` (
|
||||
`ID` INT NOT NULL AUTO_INCREMENT,
|
||||
`CODE` VARCHAR(45) NOT NULL,
|
||||
`NAME` VARCHAR(100) NULL,
|
||||
`DESCRIPTION` VARCHAR(200) NULL,
|
||||
PRIMARY KEY (`ID`)
|
||||
) ENGINE = InnoDB;
|
||||
|
@ -0,0 +1,49 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `AD_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE AD_DEVICE (
|
||||
DEVICE_ID VARCHAR(45) NOT NULL ,
|
||||
DEVICE_INFO VARCHAR(500) DEFAULT NULL,
|
||||
GCM_TOKEN VARCHAR(45) DEFAULT NULL,
|
||||
IMEI VARCHAR(45) DEFAULT NULL,
|
||||
IMSI VARCHAR(45) DEFAULT NULL,
|
||||
OS_VERSION VARCHAR(45) DEFAULT NULL,
|
||||
DEVICE_MODEL VARCHAR(45) DEFAULT NULL,
|
||||
VENDOR VARCHAR(45) DEFAULT NULL,
|
||||
LATITUDE VARCHAR(45) DEFAULT NULL,
|
||||
LONGITUDE VARCHAR(45) DEFAULT NULL,
|
||||
SERIAL VARCHAR(45) DEFAULT NULL,
|
||||
MAC_ADDRESS VARCHAR(45) DEFAULT NULL,
|
||||
DEVICE_NAME VARCHAR(100) DEFAULT NULL,
|
||||
PRIMARY KEY (DEVICE_ID)
|
||||
);
|
||||
/
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `AD_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE AD_FEATURE (
|
||||
ID INT NOT NULL,
|
||||
CODE VARCHAR(45) NOT NULL,
|
||||
NAME VARCHAR(100) NOT NULL,
|
||||
DESCRIPTION VARCHAR(200) DEFAULT NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
/
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Sequence `AD_FEATURE_ID_INC_SEQ`
|
||||
-- -----------------------------------------------------
|
||||
CREATE SEQUENCE AD_FEATURE_ID_INC_SEQ START WITH 1 INCREMENT BY 1 NOCACHE;
|
||||
/
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Trigger `AD_FEATURE_ID_INC_TRIG`
|
||||
-- -----------------------------------------------------
|
||||
CREATE OR REPLACE TRIGGER AD_FEATURE_ID_INC_TRIG
|
||||
BEFORE INSERT ON AD_FEATURE
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
SELECT AD_FEATURE_ID_INC_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;
|
||||
END;
|
||||
/
|
@ -0,0 +1,30 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table AD_DEVICE
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS AD_DEVICE (
|
||||
DEVICE_ID VARCHAR(45) NOT NULL ,
|
||||
DEVICE_INFO VARCHAR(500) NULL DEFAULT NULL,
|
||||
GCM_TOKEN VARCHAR(45) NULL DEFAULT NULL,
|
||||
IMEI VARCHAR(45) NULL DEFAULT NULL,
|
||||
IMSI VARCHAR(45) NULL DEFAULT NULL,
|
||||
OS_VERSION VARCHAR(45) NULL DEFAULT NULL,
|
||||
DEVICE_MODEL VARCHAR(45) NULL DEFAULT NULL,
|
||||
VENDOR VARCHAR(45) NULL DEFAULT NULL,
|
||||
LATITUDE VARCHAR(45) NULL DEFAULT NULL,
|
||||
LONGITUDE VARCHAR(45) NULL DEFAULT NULL,
|
||||
SERIAL VARCHAR(45) NULL DEFAULT NULL,
|
||||
MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL,
|
||||
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (DEVICE_ID)
|
||||
);
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table AD_FEATURE
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS AD_FEATURE (
|
||||
ID INT NOT NULL AUTO_INCREMENT,
|
||||
CODE VARCHAR(45) NOT NULL,
|
||||
NAME VARCHAR(100) NULL,
|
||||
DESCRIPTION VARCHAR(200) NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
@ -1,56 +0,0 @@
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `AD_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `AD_DEVICE` (
|
||||
`ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL,
|
||||
`GCM_TOKEN` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL,
|
||||
`IMEI` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`IMSI` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`OS_VERSION` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`VENDOR` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`LATITUDE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`LONGITUDE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`SERIAL` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`ANDROID_DEVICE_ID`));
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `AD_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `AD_FEATURE` (
|
||||
`ID` INT NOT NULL AUTO_INCREMENT,
|
||||
`CODE` VARCHAR(45) NOT NULL,
|
||||
`NAME` VARCHAR(100) NULL,
|
||||
`DESCRIPTION` VARCHAR(200) NULL,
|
||||
PRIMARY KEY (`ID`));
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- TODO remove this later
|
||||
-- -----------------------------------------------------
|
||||
|
||||
INSERT INTO AD_FEATURE (CODE, NAME, DESCRIPTION)
|
||||
VALUES
|
||||
('DEVICE_LOCK', 'Device Lock', 'Lock the device'),
|
||||
('DEVICE_LOCATION', 'Location', 'Request coordinates of device location'),
|
||||
('WIFI', 'Wifi', 'Setting up wifi configuration'),
|
||||
('CAMERA', 'Camera', 'Enable or disable camera'),
|
||||
('EMAIL', 'Email', 'Configure email settings'),
|
||||
('DEVICE_MUTE', 'Mute', 'Enable mute in the device'),
|
||||
('DEVICE_INFO', 'Device Info', 'Request device information'),
|
||||
('ENTERPRISE_WIPE', 'Enterprise Wipe', 'Remove enterprise applications'),
|
||||
('CLEAR_PASSWORD', 'Clear Password', 'Clear current password'),
|
||||
('WIPE_DATA', 'Wipe Data', 'Factory reset the device'),
|
||||
('APPLICATION_LIST', 'Application List', 'Request list of current installed applications'),
|
||||
('CHANGE_LOCK_CODE', 'Change Lock-code', 'Change current lock code'),
|
||||
('INSTALL_APPLICATION', 'Install App', 'Install Enterprise or Market application'),
|
||||
('UNINSTALL_APPLICATION', 'Uninstall App', 'Uninstall application'),
|
||||
('BLACKLIST_APPLICATIONS', 'Blacklist app', 'Blacklist applications'),
|
||||
('ENCRYPT_STORAGE', 'Encrypt storage', 'Encrypt storage'),
|
||||
('DEVICE_RING', 'Ring', 'Ring the device'),
|
||||
('PASSCODE_POLICY', 'Password Policy', 'Set passcode policy'),
|
||||
('NOTIFICATION', 'Message', 'Send message');
|
@ -0,0 +1,33 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `IOS_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `IOS_DEVICE` (
|
||||
`DEVICE_ID` VARCHAR(45) NOT NULL,
|
||||
`APNS_PUSH_TOKEN` VARCHAR(100) DEFAULT NULL,
|
||||
`MAGIC_TOKEN` VARCHAR(100) DEFAULT NULL,
|
||||
`MDM_TOKEN` VARCHAR(100) DEFAULT NULL,
|
||||
`UNLOCK_TOKEN` VARCHAR(2000) DEFAULT NULL,
|
||||
`CHALLENGE_TOKEN` VARCHAR(45) DEFAULT NULL,
|
||||
`DEVICE_INFO` VARCHAR(8000) DEFAULT NULL,
|
||||
`SERIAL` VARCHAR(45) DEFAULT NULL,
|
||||
`PRODUCT` VARCHAR(45) DEFAULT NULL,
|
||||
`IMEI` VARCHAR(45) DEFAULT NULL,
|
||||
`VERSION` VARCHAR(45) DEFAULT NULL,
|
||||
`MAC_ADDRESS` VARCHAR(45) DEFAULT NULL,
|
||||
`DEVICE_NAME` VARCHAR(100) DEFAULT NULL,
|
||||
`ICCID` VARCHAR(45) DEFAULT NULL,
|
||||
`LATITUDE` VARCHAR(45) DEFAULT NULL,
|
||||
`LONGITUDE` VARCHAR(45) DEFAULT NULL,
|
||||
PRIMARY KEY (`DEVICE_ID`)
|
||||
);
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `IOS_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `IOS_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`)
|
||||
);
|
@ -0,0 +1,33 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `IOS_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IOS_FEATURE (
|
||||
ID INT NOT NULL IDENTITY,
|
||||
CODE VARCHAR(45) NOT NULL,
|
||||
NAME VARCHAR(100) NULL,
|
||||
DESCRIPTION VARCHAR(200) NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `IOS_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IOS_DEVICE (
|
||||
DEVICE_ID VARCHAR(45) NOT NULL,
|
||||
APNS_PUSH_TOKEN VARCHAR(100) NULL DEFAULT NULL,
|
||||
MAGIC_TOKEN VARCHAR(100) NULL DEFAULT NULL,
|
||||
MDM_TOKEN VARCHAR(100) NULL DEFAULT NULL,
|
||||
UNLOCK_TOKEN VARCHAR(2000) NULL DEFAULT NULL,
|
||||
CHALLENGE_TOKEN VARCHAR(45) NULL DEFAULT NULL,
|
||||
DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL,
|
||||
SERIAL VARCHAR(45) NULL DEFAULT NULL,
|
||||
PRODUCT VARCHAR(45) NULL DEFAULT NULL,
|
||||
IMEI VARCHAR(45) NULL DEFAULT NULL,
|
||||
VERSION VARCHAR(45) NULL DEFAULT NULL,
|
||||
MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL,
|
||||
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
|
||||
ICCID VARCHAR(45) NULL DEFAULT NULL,
|
||||
LATITUDE VARCHAR(45) NULL DEFAULT NULL,
|
||||
LONGITUDE VARCHAR(45) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (DEVICE_ID)
|
||||
);
|
@ -0,0 +1,51 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `IOS_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IOS_DEVICE (
|
||||
DEVICE_ID VARCHAR(45) NOT NULL,
|
||||
APNS_PUSH_TOKEN VARCHAR(100) DEFAULT NULL,
|
||||
MAGIC_TOKEN VARCHAR(100) DEFAULT NULL,
|
||||
MDM_TOKEN VARCHAR(100) DEFAULT NULL,
|
||||
UNLOCK_TOKEN VARCHAR(2000) DEFAULT NULL,
|
||||
CHALLENGE_TOKEN VARCHAR(45) DEFAULT NULL,
|
||||
DEVICE_INFO VARCHAR(8000) DEFAULT NULL,
|
||||
SERIAL VARCHAR(45) DEFAULT NULL,
|
||||
PRODUCT VARCHAR(45) DEFAULT NULL,
|
||||
IMEI VARCHAR(45) DEFAULT NULL,
|
||||
VERSION VARCHAR(45) DEFAULT NULL,
|
||||
MAC_ADDRESS VARCHAR(45) DEFAULT NULL,
|
||||
DEVICE_NAME VARCHAR(100) DEFAULT NULL,
|
||||
ICCID VARCHAR(45) DEFAULT NULL,
|
||||
LATITUDE VARCHAR(45) DEFAULT NULL,
|
||||
LONGITUDE VARCHAR(45) DEFAULT NULL,
|
||||
PRIMARY KEY (DEVICE_ID)
|
||||
);
|
||||
/
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `IOS_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IOS_FEATURE (
|
||||
ID INT NOT NULL,
|
||||
CODE VARCHAR(45) NOT NULL,
|
||||
NAME VARCHAR(100) NOT NULL,
|
||||
DESCRIPTION VARCHAR(200) NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
/
|
||||
|
||||
-- Sequence `IOS_FEATURE_ID_INC_SEQ`
|
||||
-- -----------------------------------------------------
|
||||
CREATE SEQUENCE IOS_FEATURE_ID_INC_SEQ START WITH 1 INCREMENT BY 1 NOCACHE;
|
||||
/
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Trigger `IOS_FEATURE_ID_INC_TRIG`
|
||||
-- -----------------------------------------------------
|
||||
CREATE OR REPLACE TRIGGER IOS_FEATURE_ID_INC_TRIG
|
||||
BEFORE INSERT ON IOS_FEATURE
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
SELECT IOS_FEATURE_ID_INC_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;
|
||||
END;
|
||||
/
|
@ -0,0 +1,33 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table IOS_FEATURE
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS IOS_FEATURE (
|
||||
ID SERIAL NOT NULL,
|
||||
CODE VARCHAR(45) NOT NULL,
|
||||
NAME VARCHAR(100) NULL,
|
||||
DESCRIPTION VARCHAR(200) NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table IOS_DEVICE
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS IOS_DEVICE (
|
||||
DEVICE_ID VARCHAR(45) NOT NULL,
|
||||
APNS_PUSH_TOKEN VARCHAR(100) NULL DEFAULT NULL,
|
||||
MAGIC_TOKEN VARCHAR(100) NULL DEFAULT NULL,
|
||||
MDM_TOKEN VARCHAR(100) NULL DEFAULT NULL,
|
||||
UNLOCK_TOKEN VARCHAR(2000) NULL DEFAULT NULL,
|
||||
CHALLENGE_TOKEN VARCHAR(45) NULL DEFAULT NULL,
|
||||
DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL,
|
||||
SERIAL VARCHAR(45) NULL DEFAULT NULL,
|
||||
PRODUCT VARCHAR(45) NULL DEFAULT NULL,
|
||||
IMEI VARCHAR(45) NULL DEFAULT NULL,
|
||||
VERSION VARCHAR(45) NULL DEFAULT NULL,
|
||||
MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL,
|
||||
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
|
||||
ICCID VARCHAR(45) NULL DEFAULT NULL,
|
||||
LATITUDE VARCHAR(45) NULL DEFAULT NULL,
|
||||
LONGITUDE VARCHAR(45) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (DEVICE_ID)
|
||||
);
|
@ -1,52 +0,0 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `MBL_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `MBL_DEVICE` (
|
||||
`MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL,
|
||||
`PUSH_TOKEN` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`IMEI` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`IMSI` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`OS_VERSION` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`VENDOR` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`LATITUDE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`LONGITUDE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`CHALLENGE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`TOKEN` VARCHAR(50) NULL DEFAULT NULL,
|
||||
`UNLOCK_TOKEN` VARCHAR(2000) NULL DEFAULT NULL,
|
||||
`SERIAL` VARCHAR(45) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`MOBILE_DEVICE_ID`))
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `MBL_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `MBL_FEATURE` (
|
||||
`FEATURE_ID` INT NOT NULL AUTO_INCREMENT,
|
||||
`DEVICE_TYPE` VARCHAR(45) NOT NULL,
|
||||
`CODE` VARCHAR(45) NULL,
|
||||
`NAME` VARCHAR(100) NULL,
|
||||
`DESCRIPTION` VARCHAR(200) NULL,
|
||||
PRIMARY KEY (`FEATURE_ID`))
|
||||
ENGINE = InnoDB;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `MBL_FEATURE_PROPERTY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` (
|
||||
`PROPERTY` VARCHAR(45) NOT NULL ,
|
||||
`FEATURE_ID` INT 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)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Inserts
|
||||
-- -----------------------------------------------------
|
||||
INSERT INTO MBL_FEATURE (DEVICE_TYPE,NAME,CODE, DESCRIPTION) VALUES ('android','DEVICE_LOCK','503A','Device Lock'),('android','WIPE','504A','Device Wipe'),('android','CLEARPASSCODE','505A','Clear Passcode'),('android','APPLIST','502A','Get All Applications'),('android','LOCATION','501A','Location'),('android','INFO','500A','Device Information'),('android','NOTIFICATION','506A','Message'),('android','WIFI','507A','Setup Wifi'),('android','CAMERA','508A','Camera Control'),('android','MUTE','513A','Mute Device'),('android','INSTALLAPP','509A','Install Application'),('android','UNINSTALLAPP','510A','Uninstall Application'),('android','ENCRYPT','511A','Encrypt Storage'),('android','APN','512A','APN'),('android','WEBCLIP','518A','Create Webclips'),('android','PASSWORDPOLICY','519A','Passcode Policy'),('android','EMAIL','520A','Email Configuration'),('android','GOOGLECALENDAR','521A','Calender Subscription'),('android','VPN','523A','VPN'),('android','LDAP','524A','LDAP'),('android','CHANGEPASSWORD','526A','Set Passcode'),('android','ENTERPRISEWIPE','527A','Enterprise Wipe'),('android','POLICY','500P','Policy Enforcement'),('android','MONITORING','501P','Policy Monitoring '),('android','BLACKLISTAPPS','528B','Blacklist Apps'),('android','REVOKEPOLICY','502P','Revoke Policy');
|
||||
|
@ -0,0 +1,30 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WIN_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WIN_DEVICE` (
|
||||
`DEVICE_ID` VARCHAR(45) NOT NULL,
|
||||
`CHANNEL_URI` VARCHAR(100) NULL DEFAULT NULL,
|
||||
`DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL,
|
||||
`IMEI` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`IMSI` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`OS_VERSION` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`VENDOR` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`LATITUDE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`LONGITUDE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`SERIAL` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`DEVICE_ID`)
|
||||
);
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WIN_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WIN_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`)
|
||||
);
|
@ -0,0 +1,30 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WINDOWS_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE WINDOWS_FEATURE (
|
||||
ID INT NOT NULL IDENTITY,
|
||||
CODE VARCHAR(45) NOT NULL,
|
||||
NAME VARCHAR(100) NULL,
|
||||
DESCRIPTION VARCHAR(200) NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WINDOWS_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE WINDOWS_DEVICE (
|
||||
DEVICE_ID VARCHAR(45) NOT NULL,
|
||||
CHANNEL_URI VARCHAR(100) NULL DEFAULT NULL,
|
||||
DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL,
|
||||
IMEI VARCHAR(45) NULL DEFAULT NULL,
|
||||
IMSI VARCHAR(45) NULL DEFAULT NULL,
|
||||
OS_VERSION VARCHAR(45) NULL DEFAULT NULL,
|
||||
DEVICE_MODEL VARCHAR(45) NULL DEFAULT NULL,
|
||||
VENDOR VARCHAR(45) NULL DEFAULT NULL,
|
||||
LATITUDE VARCHAR(45) NULL DEFAULT NULL,
|
||||
LONGITUDE VARCHAR(45) NULL DEFAULT NULL,
|
||||
SERIAL VARCHAR(45) NULL DEFAULT NULL,
|
||||
MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL,
|
||||
DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (DEVICE_ID)
|
||||
);
|
@ -0,0 +1,48 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WIN_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WIN_DEVICE` (
|
||||
`DEVICE_ID` VARCHAR(45) NOT NULL,
|
||||
`PUSH_TOKEN` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`IMEI` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`IMSI` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`OS_VERSION` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`DEVICE_MODEL` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`VENDOR` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`LATITUDE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`LONGITUDE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`CHALLENGE` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`TOKEN` VARCHAR(50) NULL DEFAULT NULL,
|
||||
`UNLOCK_TOKEN` VARCHAR(2000) NULL DEFAULT NULL,
|
||||
`SERIAL` VARCHAR(45) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`DEVICE_ID`))
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WIN_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WIN_FEATURE` (
|
||||
`FEATURE_ID` INT NOT NULL AUTO_INCREMENT,
|
||||
`DEVICE_TYPE` VARCHAR(45) NOT NULL,
|
||||
`CODE` VARCHAR(45) NULL,
|
||||
`NAME` VARCHAR(100) NULL,
|
||||
`DESCRIPTION` VARCHAR(200) NULL,
|
||||
PRIMARY KEY (`FEATURE_ID`))
|
||||
ENGINE = InnoDB;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WIN_FEATURE_PROPERTY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WIN_FEATURE_PROPERTY` (
|
||||
`PROPERTY` VARCHAR(45) NOT NULL ,
|
||||
`FEATURE_ID` INT NOT NULL ,
|
||||
PRIMARY KEY (`PROPERTY`),
|
||||
CONSTRAINT `fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1`
|
||||
FOREIGN KEY (`FEATURE_ID`)
|
||||
REFERENCES `WIN_FEATURE` (`FEATURE_ID`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
@ -0,0 +1,64 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WIN_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE WIN_DEVICE (
|
||||
DEVICE_ID VARCHAR(45) NOT NULL,
|
||||
PUSH_TOKEN VARCHAR(45) DEFAULT NULL,
|
||||
IMEI VARCHAR(45) DEFAULT NULL,
|
||||
IMSI VARCHAR(45) DEFAULT NULL,
|
||||
OS_VERSION VARCHAR(45) DEFAULT NULL,
|
||||
DEVICE_MODEL VARCHAR(45) DEFAULT NULL,
|
||||
VENDOR VARCHAR(45) DEFAULT NULL,
|
||||
LATITUDE VARCHAR(45) DEFAULT NULL,
|
||||
LONGITUDE VARCHAR(45) DEFAULT NULL,
|
||||
CHALLENGE VARCHAR(45) DEFAULT NULL,
|
||||
TOKEN VARCHAR(50) DEFAULT NULL,
|
||||
UNLOCK_TOKEN VARCHAR(2000) DEFAULT NULL,
|
||||
SERIAL VARCHAR(45) DEFAULT NULL,
|
||||
PRIMARY KEY (DEVICE_ID)
|
||||
);
|
||||
/
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WIN_FEATURE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE WIN_FEATURE (
|
||||
ID INT NOT NULL,
|
||||
DEVICE_TYPE VARCHAR(45) NOT NULL,
|
||||
CODE VARCHAR(45) NOT NULL,
|
||||
NAME VARCHAR(100) NOT NULL,
|
||||
DESCRIPTION VARCHAR(200) NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
/
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WIN_FEATURE_PROPERTY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE WIN_FEATURE_PROPERTY (
|
||||
PROPERTY VARCHAR(45) NOT NULL,
|
||||
FEATURE_ID INT NOT NULL,
|
||||
PRIMARY KEY (PROPERTY),
|
||||
CONSTRAINT fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1
|
||||
FOREIGN KEY (FEATURE_ID)
|
||||
REFERENCES WIN_FEATURE (ID)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
/
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Sequence `WIN_FEATURE_ID_INC_SEQ`
|
||||
-- -----------------------------------------------------
|
||||
CREATE SEQUENCE WIN_FEATURE_ID_INC_SEQ START WITH 1 INCREMENT BY 1 NOCACHE;
|
||||
/
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Trigger `WIN_FEATURE_ID_INC_TRIG`
|
||||
-- -----------------------------------------------------
|
||||
CREATE OR REPLACE TRIGGER WIN_FEATURE_ID_INC_TRIG
|
||||
BEFORE INSERT ON WIN_FEATURE
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
SELECT WIN_FEATURE_ID_INC_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;
|
||||
END;
|
||||
/
|
@ -0,0 +1,45 @@
|
||||
-- -----------------------------------------------------
|
||||
-- Table WIN_DEVICE
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS WIN_DEVICE (
|
||||
DEVICE_ID VARCHAR(45) NOT NULL,
|
||||
PUSH_TOKEN VARCHAR(45) NULL DEFAULT NULL,
|
||||
IMEI VARCHAR(45) NULL DEFAULT NULL,
|
||||
IMSI VARCHAR(45) NULL DEFAULT NULL,
|
||||
OS_VERSION VARCHAR(45) NULL DEFAULT NULL,
|
||||
DEVICE_MODEL VARCHAR(45) NULL DEFAULT NULL,
|
||||
VENDOR VARCHAR(45) NULL DEFAULT NULL,
|
||||
LATITUDE VARCHAR(45) NULL DEFAULT NULL,
|
||||
LONGITUDE VARCHAR(45) NULL DEFAULT NULL,
|
||||
CHALLENGE VARCHAR(45) NULL DEFAULT NULL,
|
||||
TOKEN VARCHAR(50) NULL DEFAULT NULL,
|
||||
UNLOCK_TOKEN VARCHAR(2000) NULL DEFAULT NULL,
|
||||
SERIAL VARCHAR(45) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (DEVICE_ID)
|
||||
);
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table WIN_FEATURE
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS WIN_FEATURE (
|
||||
ID SERIAL NOT NULL,
|
||||
DEVICE_TYPE VARCHAR(45) NOT NULL,
|
||||
CODE VARCHAR(45) NULL,
|
||||
NAME VARCHAR(100) NULL,
|
||||
DESCRIPTION VARCHAR(200) NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WIN_FEATURE_PROPERTY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS WIN_FEATURE_PROPERTY (
|
||||
PROPERTY VARCHAR(45) NOT NULL ,
|
||||
FEATURE_ID INT NOT NULL ,
|
||||
PRIMARY KEY (PROPERTY),
|
||||
CONSTRAINT fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1
|
||||
FOREIGN KEY (FEATURE_ID)
|
||||
REFERENCES WIN_FEATURE (ID)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION
|
||||
);
|
Loading…
Reference in new issue