forked from community/device-mgt-plugins
parent
46b3a8fd83
commit
928c6f3384
@ -1,265 +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.MobileDeviceDAO;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
|
||||||
|
|
||||||
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 MobileDeviceDAO.
|
|
||||||
*/
|
|
||||||
public class MobileDeviceDAOImpl implements MobileDeviceDAO {
|
|
||||||
|
|
||||||
private DataSource dataSource;
|
|
||||||
private static final Log log = LogFactory.getLog(MobileDeviceDAOImpl.class);
|
|
||||||
|
|
||||||
public MobileDeviceDAOImpl(DataSource dataSource) {
|
|
||||||
this.dataSource = dataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MobileDevice getMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException {
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
MobileDevice mobileDevice = null;
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String selectDBQuery =
|
|
||||||
"SELECT MOBILE_DEVICE_ID, PUSH_TOKEN, IMEI, IMSI, OS_VERSION,DEVICE_MODEL, VENDOR, " +
|
|
||||||
"LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, UNLOCK_TOKEN FROM AD_DEVICE" +
|
|
||||||
" WHERE MOBILE_DEVICE_ID = ?";
|
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
|
||||||
stmt.setString(1, mblDeviceId);
|
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
|
||||||
if (resultSet.next()) {
|
|
||||||
mobileDevice = new MobileDevice();
|
|
||||||
mobileDevice.setMobileDeviceId(resultSet.getString(1));
|
|
||||||
mobileDevice.setPushToken(resultSet.getString(2));
|
|
||||||
mobileDevice.setImei(resultSet.getString(3));
|
|
||||||
mobileDevice.setImsi(resultSet.getString(4));
|
|
||||||
mobileDevice.setOsVersion(resultSet.getString(5));
|
|
||||||
mobileDevice.setModel(resultSet.getString(6));
|
|
||||||
mobileDevice.setVendor(resultSet.getString(7));
|
|
||||||
mobileDevice.setLatitude(resultSet.getString(8));
|
|
||||||
mobileDevice.setLongitude(resultSet.getString(9));
|
|
||||||
mobileDevice.setChallenge(resultSet.getString(10));
|
|
||||||
mobileDevice.setSerial(resultSet.getString(11));
|
|
||||||
mobileDevice.setToken(resultSet.getString(12));
|
|
||||||
mobileDevice.setUnlockToken(resultSet.getString(13));
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Mobile device " + mblDeviceId + " data has fetched from MDM database.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while fetching mobile device '" +
|
|
||||||
mblDeviceId + "'";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
|
||||||
}
|
|
||||||
return mobileDevice;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addMobileDevice(MobileDevice mobileDevice)
|
|
||||||
throws MobileDeviceManagementDAOException {
|
|
||||||
boolean status = false;
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String createDBQuery =
|
|
||||||
"INSERT INTO AD_DEVICE(MOBILE_DEVICE_ID, PUSH_TOKEN, IMEI, IMSI, OS_VERSION," +
|
|
||||||
"DEVICE_MODEL, VENDOR, LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, " +
|
|
||||||
"UNLOCK_TOKEN) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(createDBQuery);
|
|
||||||
stmt.setString(1, mobileDevice.getMobileDeviceId());
|
|
||||||
stmt.setString(2, mobileDevice.getPushToken());
|
|
||||||
stmt.setString(3, mobileDevice.getImei());
|
|
||||||
stmt.setString(4, mobileDevice.getImsi());
|
|
||||||
stmt.setString(5, mobileDevice.getOsVersion());
|
|
||||||
stmt.setString(6, mobileDevice.getModel());
|
|
||||||
stmt.setString(7, mobileDevice.getVendor());
|
|
||||||
stmt.setString(8, mobileDevice.getLatitude());
|
|
||||||
stmt.setString(9, mobileDevice.getLongitude());
|
|
||||||
stmt.setString(10, mobileDevice.getChallenge());
|
|
||||||
stmt.setString(11, mobileDevice.getSerial());
|
|
||||||
stmt.setString(12, mobileDevice.getToken());
|
|
||||||
stmt.setString(13, mobileDevice.getUnlockToken());
|
|
||||||
int rows = stmt.executeUpdate();
|
|
||||||
if (rows > 0) {
|
|
||||||
status = true;
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Mobile device " + mobileDevice.getMobileDeviceId() + " data has added" +
|
|
||||||
" to the MDM database.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while adding the mobile device '" +
|
|
||||||
mobileDevice.getMobileDeviceId() + "' to the mobile db.";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean updateMobileDevice(MobileDevice mobileDevice)
|
|
||||||
throws MobileDeviceManagementDAOException {
|
|
||||||
boolean status = false;
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String updateDBQuery =
|
|
||||||
"UPDATE AD_DEVICE SET PUSH_TOKEN = ?, IMEI = ?, IMSI = ?, OS_VERSION = ?," +
|
|
||||||
"DEVICE_MODEL = ?, VENDOR = ? , LATITUDE = ?, LONGITUDE = ?, CHALLENGE = ?," +
|
|
||||||
"SERIAL = ?, TOKEN = ?, UNLOCK_TOKEN = ? WHERE MOBILE_DEVICE_ID = ?";
|
|
||||||
stmt = conn.prepareStatement(updateDBQuery);
|
|
||||||
stmt.setString(1, mobileDevice.getPushToken());
|
|
||||||
stmt.setString(2, mobileDevice.getImei());
|
|
||||||
stmt.setString(3, mobileDevice.getImsi());
|
|
||||||
stmt.setString(4, mobileDevice.getOsVersion());
|
|
||||||
stmt.setString(5, mobileDevice.getModel());
|
|
||||||
stmt.setString(6, mobileDevice.getVendor());
|
|
||||||
stmt.setString(7, mobileDevice.getLatitude());
|
|
||||||
stmt.setString(8, mobileDevice.getLongitude());
|
|
||||||
stmt.setString(9, mobileDevice.getChallenge());
|
|
||||||
stmt.setString(10, mobileDevice.getSerial());
|
|
||||||
stmt.setString(11, mobileDevice.getToken());
|
|
||||||
stmt.setString(12, mobileDevice.getUnlockToken());
|
|
||||||
stmt.setString(13, mobileDevice.getMobileDeviceId());
|
|
||||||
int rows = stmt.executeUpdate();
|
|
||||||
if (rows > 0) {
|
|
||||||
status = true;
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Mobile device " + mobileDevice.getMobileDeviceId() + " data has" +
|
|
||||||
" updated");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while updating the mobile device '" +
|
|
||||||
mobileDevice.getMobileDeviceId() + "'";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean deleteMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException {
|
|
||||||
boolean status = false;
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String deleteDBQuery =
|
|
||||||
"DELETE FROM AD_DEVICE WHERE MOBILE_DEVICE_ID = ?";
|
|
||||||
stmt = conn.prepareStatement(deleteDBQuery);
|
|
||||||
stmt.setString(1, mblDeviceId);
|
|
||||||
int rows = stmt.executeUpdate();
|
|
||||||
if (rows > 0) {
|
|
||||||
status = true;
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Mobile device " + mblDeviceId + " data has deleted" +
|
|
||||||
" from the MDM database.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while deleting mobile device " + mblDeviceId;
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<MobileDevice> getAllMobileDevices() throws MobileDeviceManagementDAOException {
|
|
||||||
Connection conn = null;
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
MobileDevice mobileDevice;
|
|
||||||
List<MobileDevice> mobileDevices = new ArrayList<MobileDevice>();
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String selectDBQuery =
|
|
||||||
"SELECT MOBILE_DEVICE_ID, PUSH_TOKEN, IMEI, IMSI, OS_VERSION,DEVICE_MODEL, VENDOR," +
|
|
||||||
"LATITUDE, LONGITUDE, CHALLENGE, SERIAL, TOKEN, UNLOCK_TOKEN FROM AD_DEVICE";
|
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
|
||||||
while (resultSet.next()) {
|
|
||||||
mobileDevice = new MobileDevice();
|
|
||||||
mobileDevice.setMobileDeviceId(resultSet.getString(1));
|
|
||||||
mobileDevice.setPushToken(resultSet.getString(2));
|
|
||||||
mobileDevice.setImei(resultSet.getString(3));
|
|
||||||
mobileDevice.setImsi(resultSet.getString(4));
|
|
||||||
mobileDevice.setOsVersion(resultSet.getString(5));
|
|
||||||
mobileDevice.setModel(resultSet.getString(6));
|
|
||||||
mobileDevice.setVendor(resultSet.getString(7));
|
|
||||||
mobileDevice.setLatitude(resultSet.getString(8));
|
|
||||||
mobileDevice.setLongitude(resultSet.getString(9));
|
|
||||||
mobileDevice.setChallenge(resultSet.getString(10));
|
|
||||||
mobileDevice.setSerial(resultSet.getString(11));
|
|
||||||
mobileDevice.setToken(resultSet.getString(12));
|
|
||||||
mobileDevice.setUnlockToken(resultSet.getString(13));
|
|
||||||
mobileDevices.add(mobileDevice);
|
|
||||||
}
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("All Mobile device details have fetched from MDM database.");
|
|
||||||
}
|
|
||||||
return mobileDevices;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while fetching all mobile device data'";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
|
||||||
try {
|
|
||||||
return dataSource.getConnection();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while obtaining a connection from the mobile device " +
|
|
||||||
"management metadata repository datasource";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,300 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.mobile.impl.ios.dao.impl;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
||||||
|
|
||||||
|
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.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class IOSDeviceDAOImpl implements MobileDeviceDAO {
|
||||||
|
|
||||||
|
private DataSource dataSource;
|
||||||
|
private static final Log log = LogFactory.getLog(IOSDeviceDAOImpl.class);
|
||||||
|
|
||||||
|
public IOSDeviceDAOImpl(DataSource dataSource) {
|
||||||
|
this.dataSource = dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String SERIAL = "SERIAL";
|
||||||
|
public static final String PRODUCT = "PRODUCT";
|
||||||
|
public static final String MAC_ADDRESS = "MAC_ADDRESS";
|
||||||
|
public static final String DEVICE_NAME = "DEVICE_NAME";
|
||||||
|
public static final String ICCID = "ICCID";
|
||||||
|
public static final String LATITUDE = "LATITUDE";
|
||||||
|
public static final String LONGITUDE = "LONGITUDE";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MobileDevice getMobileDevice(String deviceID) throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
MobileDevice mobileDevice = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT MOBILE_DEVICE_ID, APNS_PUSH_TOKEN, MAGIC_TOKEN, MDM_TOKEN, UNLOCK_TOKEN, " +
|
||||||
|
"CHALLENGE_TOKEN, DEVICE_INFO, SERIAL, PRODUCT, MAC_ADDRESS, DEVICE_NAME, ICCID," +
|
||||||
|
"LATITUDE, LONGITUDE FROM IOS_DEVICE WHERE MOBILE_DEVICE_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
|
stmt.setString(1, deviceID);
|
||||||
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
|
if (resultSet.next()) {
|
||||||
|
mobileDevice = new MobileDevice();
|
||||||
|
mobileDevice.setMobileDeviceId(resultSet.getString(IOSPluginConstants.MOBILE_DEVICE_ID));
|
||||||
|
|
||||||
|
Map<String, String> tokenMap = new HashMap<String, String>();
|
||||||
|
tokenMap.put(IOSPluginConstants.APNS_PUSH_TOKEN,
|
||||||
|
resultSet.getString(IOSPluginConstants.APNS_PUSH_TOKEN));
|
||||||
|
tokenMap.put(IOSPluginConstants.MAGIC_TOKEN, resultSet.getString(IOSPluginConstants.MAGIC_TOKEN));
|
||||||
|
tokenMap.put(IOSPluginConstants.MDM_TOKEN, resultSet.getString(IOSPluginConstants.MDM_TOKEN));
|
||||||
|
tokenMap.put(IOSPluginConstants.UNLOCK_TOKEN, resultSet.getString(IOSPluginConstants.UNLOCK_TOKEN));
|
||||||
|
tokenMap.put(IOSPluginConstants.CHALLENGE_TOKEN,
|
||||||
|
resultSet.getString(IOSPluginConstants.CHALLENGE_TOKEN));
|
||||||
|
tokenMap.put(IOSPluginConstants.DEVICE_INFO, resultSet.getString(IOSPluginConstants.DEVICE_INFO));
|
||||||
|
tokenMap.put(IOSPluginConstants.SERIAL, resultSet.getString(IOSPluginConstants.SERIAL));
|
||||||
|
tokenMap.put(IOSPluginConstants.PRODUCT, resultSet.getString(IOSPluginConstants.PRODUCT));
|
||||||
|
tokenMap.put(IOSPluginConstants.MAC_ADDRESS, resultSet.getString(IOSPluginConstants.MAC_ADDRESS));
|
||||||
|
tokenMap.put(IOSPluginConstants.DEVICE_NAME, resultSet.getString(IOSPluginConstants.DEVICE_NAME));
|
||||||
|
tokenMap.put(IOSPluginConstants.ICCID, resultSet.getString(IOSPluginConstants.ICCID));
|
||||||
|
tokenMap.put(IOSPluginConstants.LATITUDE, resultSet.getString(IOSPluginConstants.LATITUDE));
|
||||||
|
tokenMap.put(IOSPluginConstants.LONGITUDE, resultSet.getString(IOSPluginConstants.LONGITUDE));
|
||||||
|
|
||||||
|
mobileDevice.setDeviceProperties(tokenMap);
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Mobile device " + deviceID + " data has been fetched from iOS database.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while fetching mobile device '" + deviceID + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mobileDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addMobileDevice(MobileDevice mobileDevice)
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
boolean status = false;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String createDBQuery =
|
||||||
|
"INSERT INTO IOS_DEVICE(MOBILE_DEVICE_ID, APNS_PUSH_TOKEN, MAGIC_TOKEN, MDM_TOKEN, UNLOCK_TOKEN, " +
|
||||||
|
"CHALLENGE_TOKEN, DEVICE_INFO, SERIAL, PRODUCT, MAC_ADDRESS, DEVICE_NAME, ICCID, " +
|
||||||
|
"LATITUDE, LONGITUDE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
|
||||||
|
stmt = conn.prepareStatement(createDBQuery);
|
||||||
|
stmt.setString(1, mobileDevice.getMobileDeviceId());
|
||||||
|
|
||||||
|
if (mobileDevice.getDeviceProperties() == null) {
|
||||||
|
mobileDevice.setDeviceProperties(new HashMap<String, String>());
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt.setString(2, mobileDevice.getDeviceProperties().get(IOSPluginConstants.APNS_PUSH_TOKEN));
|
||||||
|
stmt.setString(3, mobileDevice.getDeviceProperties().get(IOSPluginConstants.MAGIC_TOKEN));
|
||||||
|
stmt.setString(4, mobileDevice.getDeviceProperties().get(IOSPluginConstants.MDM_TOKEN));
|
||||||
|
stmt.setString(5, mobileDevice.getDeviceProperties().get(IOSPluginConstants.UNLOCK_TOKEN));
|
||||||
|
stmt.setString(6, mobileDevice.getDeviceProperties().get(IOSPluginConstants.CHALLENGE_TOKEN));
|
||||||
|
stmt.setString(7, mobileDevice.getDeviceProperties().get(IOSPluginConstants.DEVICE_INFO));
|
||||||
|
stmt.setString(8, mobileDevice.getDeviceProperties().get(IOSPluginConstants.SERIAL));
|
||||||
|
stmt.setString(9, mobileDevice.getDeviceProperties().get(IOSPluginConstants.PRODUCT));
|
||||||
|
stmt.setString(10, mobileDevice.getDeviceProperties().get(IOSPluginConstants.MAC_ADDRESS));
|
||||||
|
stmt.setString(11, mobileDevice.getDeviceProperties().get(IOSPluginConstants.DEVICE_NAME));
|
||||||
|
stmt.setString(12, mobileDevice.getDeviceProperties().get(IOSPluginConstants.ICCID));
|
||||||
|
stmt.setString(13, mobileDevice.getDeviceProperties().get(IOSPluginConstants.LATITUDE));
|
||||||
|
stmt.setString(14, mobileDevice.getDeviceProperties().get(IOSPluginConstants.LONGITUDE));
|
||||||
|
|
||||||
|
int rows = stmt.executeUpdate();
|
||||||
|
if (rows > 0) {
|
||||||
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Mobile device " + mobileDevice.getMobileDeviceId() + " data has been added" +
|
||||||
|
" to the iOS database.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while adding the mobile device '" +
|
||||||
|
mobileDevice.getMobileDeviceId() + "' to the iOS db.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateMobileDevice(MobileDevice mobileDevice)
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
boolean status = false;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String updateDBQuery =
|
||||||
|
"UPDATE IOS_DEVICE SET APNS_PUSH_TOKEN = ?, MAGIC_TOKEN = ?, MDM_TOKEN = ?, UNLOCK_TOKEN = ?, " +
|
||||||
|
"CHALLENGE_TOKEN = ?, DEVICE_INFO = ?, SERIAL = ?, PRODUCT = ?, MAC_ADDRESS = ?, " +
|
||||||
|
"DEVICE_NAME = ?, ICCID = ?, LATITUDE = ?, LONGITUDE = ? WHERE MOBILE_DEVICE_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(updateDBQuery);
|
||||||
|
stmt.setString(1, mobileDevice.getDeviceProperties().get(IOSPluginConstants.APNS_PUSH_TOKEN));
|
||||||
|
stmt.setString(2, mobileDevice.getDeviceProperties().get(IOSPluginConstants.MAGIC_TOKEN));
|
||||||
|
stmt.setString(3, mobileDevice.getDeviceProperties().get(IOSPluginConstants.MDM_TOKEN));
|
||||||
|
stmt.setString(4, mobileDevice.getDeviceProperties().get(IOSPluginConstants.UNLOCK_TOKEN));
|
||||||
|
stmt.setString(5, mobileDevice.getDeviceProperties().get(IOSPluginConstants.CHALLENGE_TOKEN));
|
||||||
|
stmt.setString(6, mobileDevice.getDeviceProperties().get(IOSPluginConstants.DEVICE_INFO));
|
||||||
|
stmt.setString(7, mobileDevice.getDeviceProperties().get(IOSPluginConstants.SERIAL));
|
||||||
|
stmt.setString(8, mobileDevice.getDeviceProperties().get(IOSPluginConstants.PRODUCT));
|
||||||
|
stmt.setString(9, mobileDevice.getDeviceProperties().get(IOSPluginConstants.MAC_ADDRESS));
|
||||||
|
stmt.setString(10, mobileDevice.getDeviceProperties().get(IOSPluginConstants.DEVICE_NAME));
|
||||||
|
stmt.setString(11, mobileDevice.getDeviceProperties().get(IOSPluginConstants.ICCID));
|
||||||
|
stmt.setString(12, mobileDevice.getDeviceProperties().get(IOSPluginConstants.LATITUDE));
|
||||||
|
stmt.setString(13, mobileDevice.getDeviceProperties().get(IOSPluginConstants.LONGITUDE));
|
||||||
|
stmt.setString(14, mobileDevice.getDeviceProperties().get(IOSPluginConstants.MOBILE_DEVICE_ID));
|
||||||
|
|
||||||
|
int rows = stmt.executeUpdate();
|
||||||
|
if (rows > 0) {
|
||||||
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Mobile device " + mobileDevice.getMobileDeviceId() + " data has" +
|
||||||
|
" updated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while updating the mobile device '" +
|
||||||
|
mobileDevice.getMobileDeviceId() + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException {
|
||||||
|
boolean status = false;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String deleteDBQuery =
|
||||||
|
"DELETE FROM IOS_DEVICE WHERE MOBILE_DEVICE_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
|
stmt.setString(1, mblDeviceId);
|
||||||
|
int rows = stmt.executeUpdate();
|
||||||
|
if (rows > 0) {
|
||||||
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Mobile device " + mblDeviceId + " data has deleted" +
|
||||||
|
" from the iOS database.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while deleting mobile device " + mblDeviceId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MobileDevice> getAllMobileDevices() throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
|
||||||
|
List<MobileDevice> mobileDevices = new ArrayList<MobileDevice>();
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT MOBILE_DEVICE_ID, APNS_PUSH_TOKEN, MAGIC_TOKEN, MDM_TOKEN, UNLOCK_TOKEN, " +
|
||||||
|
"CHALLENGE_TOKEN, DEVICE_INFO, SERIAL, PRODUCT, MAC_ADDRESS, DEVICE_NAME, ICCID," +
|
||||||
|
"LATITUDE, LONGITUDE FROM IOS_DEVICE";
|
||||||
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
|
||||||
|
MobileDevice mobileDevice = new MobileDevice();
|
||||||
|
mobileDevice.setMobileDeviceId(resultSet.getString(IOSPluginConstants.MOBILE_DEVICE_ID));
|
||||||
|
|
||||||
|
Map<String, String> tokenMap = new HashMap<String, String>();
|
||||||
|
tokenMap.put(IOSPluginConstants.APNS_PUSH_TOKEN,
|
||||||
|
resultSet.getString(IOSPluginConstants.APNS_PUSH_TOKEN));
|
||||||
|
tokenMap.put(IOSPluginConstants.MAGIC_TOKEN, resultSet.getString(IOSPluginConstants.MAGIC_TOKEN));
|
||||||
|
tokenMap.put(IOSPluginConstants.MDM_TOKEN, resultSet.getString(IOSPluginConstants.MDM_TOKEN));
|
||||||
|
tokenMap.put(IOSPluginConstants.UNLOCK_TOKEN, resultSet.getString(IOSPluginConstants.UNLOCK_TOKEN));
|
||||||
|
tokenMap.put(IOSPluginConstants.CHALLENGE_TOKEN,
|
||||||
|
resultSet.getString(IOSPluginConstants.CHALLENGE_TOKEN));
|
||||||
|
tokenMap.put(IOSPluginConstants.DEVICE_INFO, resultSet.getString(IOSPluginConstants.DEVICE_INFO));
|
||||||
|
tokenMap.put(IOSPluginConstants.SERIAL, resultSet.getString(IOSPluginConstants.SERIAL));
|
||||||
|
tokenMap.put(IOSPluginConstants.PRODUCT, resultSet.getString(IOSPluginConstants.PRODUCT));
|
||||||
|
tokenMap.put(IOSPluginConstants.MAC_ADDRESS, resultSet.getString(IOSPluginConstants.MAC_ADDRESS));
|
||||||
|
tokenMap.put(IOSPluginConstants.DEVICE_NAME, resultSet.getString(IOSPluginConstants.DEVICE_NAME));
|
||||||
|
tokenMap.put(IOSPluginConstants.ICCID, resultSet.getString(IOSPluginConstants.ICCID));
|
||||||
|
tokenMap.put(IOSPluginConstants.LATITUDE, resultSet.getString(IOSPluginConstants.LATITUDE));
|
||||||
|
tokenMap.put(IOSPluginConstants.LONGITUDE, resultSet.getString(IOSPluginConstants.LONGITUDE));
|
||||||
|
|
||||||
|
mobileDevice.setDeviceProperties(tokenMap);
|
||||||
|
|
||||||
|
mobileDevices.add(mobileDevice);
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("All Mobile device details have fetched from iOS database.");
|
||||||
|
}
|
||||||
|
return mobileDevices;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while fetching all mobile device data'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||||
|
try {
|
||||||
|
return dataSource.getConnection();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while obtaining a connection from the mobile device " +
|
||||||
|
"management metadata repository datasource";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.mobile.impl.ios.dao.impl;
|
||||||
|
|
||||||
|
public class IOSPluginConstants {
|
||||||
|
|
||||||
|
public static final String MOBILE_DEVICE_ID = "MOBILE_DEVICE_ID";
|
||||||
|
public static final String APNS_PUSH_TOKEN = "APNS_PUSH_TOKEN";
|
||||||
|
public static final String MAGIC_TOKEN = "MAGIC_TOKEN";
|
||||||
|
public static final String MDM_TOKEN = "MDM_TOKEN";
|
||||||
|
public static final String UNLOCK_TOKEN = "UNLOCK_TOKEN";
|
||||||
|
public static final String CHALLENGE_TOKEN = "CHALLENGE_TOKEN";
|
||||||
|
public static final String DEVICE_INFO = "DEVICE_INFO";
|
||||||
|
public static final String SERIAL = "SERIAL";
|
||||||
|
public static final String PRODUCT = "PRODUCT";
|
||||||
|
public static final String MAC_ADDRESS = "MAC_ADDRESS";
|
||||||
|
public static final String DEVICE_NAME = "DEVICE_NAME";
|
||||||
|
public static final String ICCID = "ICCID";
|
||||||
|
public static final String LATITUDE = "LATITUDE";
|
||||||
|
public static final String LONGITUDE = "LONGITUDE";
|
||||||
|
|
||||||
|
}
|
@ -1,49 +1,34 @@
|
|||||||
|
|
||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
-- Table `MBL_DEVICE`
|
-- Table `IOS_FEATURE`
|
||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
CREATE TABLE IF NOT EXISTS `MBL_DEVICE` (
|
CREATE TABLE IF NOT EXISTS `IOS_FEATURE` (
|
||||||
`MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL ,
|
`FEATURE_ID` INT NOT NULL AUTO_INCREMENT,
|
||||||
`PUSH_TOKEN` VARCHAR(45) NULL DEFAULT NULL ,
|
`CODE` VARCHAR(45) NOT NULL,
|
||||||
`IMEI` VARCHAR(45) NULL DEFAULT NULL ,
|
`NAME` VARCHAR(100) NULL,
|
||||||
`IMSI` VARCHAR(45) NULL DEFAULT NULL ,
|
`DESCRIPTION` VARCHAR(200) NULL,
|
||||||
`OS_VERSION` VARCHAR(45) NULL DEFAULT NULL ,
|
PRIMARY KEY (`FEATURE_ID`) );
|
||||||
`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`) );
|
|
||||||
|
|
||||||
|
|
||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
-- Table `MBL_FEATURE`
|
-- Table `IOS_DEVICE`
|
||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
CREATE TABLE IF NOT EXISTS `MBL_FEATURE` (
|
|
||||||
`FEATURE_ID` INT NOT NULL AUTO_INCREMENT ,
|
|
||||||
`DEVICE_TYPE` VARCHAR(45) NOT NULL ,
|
|
||||||
`CODE` VARCHAR(45) NOT NULL ,
|
|
||||||
`NAME` VARCHAR(100) NULL ,
|
|
||||||
`DESCRIPTION` VARCHAR(200) NULL ,
|
|
||||||
PRIMARY KEY (`FEATURE_ID`) );
|
|
||||||
|
|
||||||
-- -----------------------------------------------------
|
CREATE TABLE IF NOT EXISTS `IOS_DEVICE` (
|
||||||
-- Table `MBL_FEATURE_PROPERTY`
|
`MOBILE_DEVICE_ID` VARCHAR(45) NOT NULL,
|
||||||
-- -----------------------------------------------------
|
`APNS_PUSH_TOKEN` VARCHAR(100) NULL DEFAULT NULL,
|
||||||
CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` (
|
`MAGIC_TOKEN` VARCHAR(100) NULL DEFAULT NULL,
|
||||||
`PROPERTY` VARCHAR(45) NOT NULL ,
|
`MDM_TOKEN` VARCHAR(100) NULL DEFAULT NULL,
|
||||||
`FEATURE_ID` INT NOT NULL ,
|
`UNLOCK_TOKEN` VARCHAR(1000) NULL DEFAULT NULL,
|
||||||
PRIMARY KEY (`PROPERTY`) ,
|
`CHALLENGE_TOKEN` VARCHAR(45) NULL DEFAULT NULL,
|
||||||
CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1`
|
`DEVICE_INFO` VARCHAR(8000) NULL DEFAULT NULL,
|
||||||
FOREIGN KEY (`FEATURE_ID` )
|
`SERIAL` VARCHAR(45) NULL DEFAULT NULL,
|
||||||
REFERENCES `MBL_FEATURE` (`FEATURE_ID` )
|
`PRODUCT` VARCHAR(45) NULL DEFAULT NULL,
|
||||||
ON DELETE NO ACTION
|
`MAC_ADDRESS` VARCHAR(45) NULL DEFAULT NULL,
|
||||||
ON UPDATE NO ACTION);
|
`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 (`MOBILE_DEVICE_ID`) );
|
||||||
|
|
||||||
-- -----------------------------------------------------
|
|
||||||
-- Inserts
|
long
|
||||||
-- -----------------------------------------------------
|
|
||||||
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');
|
|
Loading…
Reference in new issue