Implementing IOS feature DAO and device DAO

revert-dabc3590
Dilshan Edirisuriya 10 years ago
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);
}
}
}

@ -19,127 +19,101 @@
package org.wso2.carbon.device.mgt.mobile.dto; package org.wso2.carbon.device.mgt.mobile.dto;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map;
/** /**
* DTO of MobileDevice. * DTO of MobileDevice.
*/ */
public class MobileDevice implements Serializable { public class MobileDevice implements Serializable {
private String mobileDeviceId; private String mobileDeviceId;
private String pushToken; private String osVersion;
private String imei; private String model;
private String imsi; private String vendor;
private String osVersion; private String latitude;
private String model; private String longitude;
private String vendor; private String imei;
private String latitude; private String imsi;
private String longitude; private String serial;
private String serial; private Map<String, String> deviceProperties;
private String unlockToken;
private String token; public String getMobileDeviceId() {
private String challenge; return mobileDeviceId;
}
public String getUnlockToken() {
return unlockToken; public void setMobileDeviceId(String mobileDeviceId) {
} this.mobileDeviceId = mobileDeviceId;
}
public void setUnlockToken(String unlockToken) {
this.unlockToken = unlockToken; public String getOsVersion() {
} return osVersion;
}
public String getToken() {
return token; public void setOsVersion(String osVersion) {
} this.osVersion = osVersion;
}
public void setToken(String token) {
this.token = token; public String getModel() {
} return model;
}
public String getChallenge() {
return challenge; public void setModel(String model) {
} this.model = model;
}
public void setChallenge(String challenge) {
this.challenge = challenge; public String getVendor() {
} return vendor;
}
public String getSerial() {
return serial; public void setVendor(String vendor) {
} this.vendor = vendor;
}
public void setSerial(String serial) {
this.serial = serial; public String getLatitude() {
} return latitude;
}
public String getMobileDeviceId() {
return mobileDeviceId; public void setLatitude(String latitude) {
} this.latitude = latitude;
}
public void setMobileDeviceId(String mobileDeviceId) {
this.mobileDeviceId = mobileDeviceId; public String getLongitude() {
} return longitude;
}
public String getPushToken() {
return pushToken; public void setLongitude(String longitude) {
} this.longitude = longitude;
}
public void setPushToken(String pushToken) {
this.pushToken = pushToken; public String getImei() {
} return imei;
}
public String getImei() {
return imei; public void setImei(String imei) {
} this.imei = imei;
}
public void setImei(String imei) {
this.imei = imei; public String getImsi() {
} return imsi;
}
public String getImsi() {
return imsi; public void setImsi(String imsi) {
} this.imsi = imsi;
}
public void setImsi(String imsi) {
this.imsi = imsi; public String getSerial() {
} return serial;
}
public String getOsVersion() {
return osVersion; public void setSerial(String serial) {
} this.serial = serial;
}
public void setOsVersion(String osVersion) {
this.osVersion = osVersion; public Map<String, String> getDeviceProperties() {
} return deviceProperties;
}
public String getModel() {
return model; public void setDeviceProperties(Map<String, String> deviceProperties) {
} this.deviceProperties = deviceProperties;
}
public void setModel(String model) {
this.model = model;
}
public String getVendor() {
return vendor;
}
public void setVendor(String vendor) {
this.vendor = vendor;
}
public String getLatitude() {
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
} }

@ -21,6 +21,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
import org.wso2.carbon.device.mgt.mobile.dao.*; import org.wso2.carbon.device.mgt.mobile.dao.*;
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.impl.FeatureDAOImpl;
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.impl.IOSDeviceDAOImpl;
public class IOSDAOFactory extends MobileDeviceManagementDAOFactory { public class IOSDAOFactory extends MobileDeviceManagementDAOFactory {
@ -32,7 +34,7 @@ public class IOSDAOFactory extends MobileDeviceManagementDAOFactory {
@Override @Override
public MobileDeviceDAO getMobileDeviceDAO() { public MobileDeviceDAO getMobileDeviceDAO() {
return null; return new IOSDeviceDAOImpl(dataSource);
} }
@Override @Override
@ -52,7 +54,7 @@ public class IOSDAOFactory extends MobileDeviceManagementDAOFactory {
@Override @Override
public MobileFeatureDAO getMobileFeatureDao() { public MobileFeatureDAO getMobileFeatureDao() {
return null; return new FeatureDAOImpl();
} }
public MobileFeaturePropertyDAO getFeaturePropertyDAO() { public MobileFeaturePropertyDAO getFeaturePropertyDAO() {

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

@ -40,16 +40,12 @@ public class MobileDeviceManagementUtil {
private static final Log log = LogFactory.getLog(MobileDeviceManagementUtil.class); private static final Log log = LogFactory.getLog(MobileDeviceManagementUtil.class);
private static final String MOBILE_DEVICE_IMEI = "imei"; private static final String MOBILE_DEVICE_IMEI = "imei";
private static final String MOBILE_DEVICE_IMSI = "imsi"; private static final String MOBILE_DEVICE_IMSI = "imsi";
private static final String MOBILE_DEVICE_PUSH_TOKEN = "pushToken";
private static final String MOBILE_DEVICE_VENDOR = "vendor"; private static final String MOBILE_DEVICE_VENDOR = "vendor";
private static final String MOBILE_DEVICE_OS_VERSION = "osVersion"; private static final String MOBILE_DEVICE_OS_VERSION = "osVersion";
private static final String MOBILE_DEVICE_MODEL = "model"; private static final String MOBILE_DEVICE_MODEL = "model";
private static final String MOBILE_DEVICE_LATITUDE = "latitude"; private static final String MOBILE_DEVICE_LATITUDE = "latitude";
private static final String MOBILE_DEVICE_LONGITUDE = "longitude"; private static final String MOBILE_DEVICE_LONGITUDE = "longitude";
private static final String MOBILE_DEVICE_TOKEN = "token";
private static final String MOBILE_DEVICE_SERIAL = "serial"; private static final String MOBILE_DEVICE_SERIAL = "serial";
private static final String MOBILE_DEVICE_UNLOCK_TOKEN = "unlockToken";
private static final String MOBILE_DEVICE_CHALLENGE = "challenge";
public static Document convertToDocument(File file) throws DeviceManagementException { public static Document convertToDocument(File file) throws DeviceManagementException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@ -89,16 +85,11 @@ public class MobileDeviceManagementUtil {
mobileDevice.setMobileDeviceId(device.getDeviceIdentifier()); mobileDevice.setMobileDeviceId(device.getDeviceIdentifier());
mobileDevice.setImei(getPropertyValue(device, MOBILE_DEVICE_IMEI)); mobileDevice.setImei(getPropertyValue(device, MOBILE_DEVICE_IMEI));
mobileDevice.setImsi(getPropertyValue(device, MOBILE_DEVICE_IMSI)); mobileDevice.setImsi(getPropertyValue(device, MOBILE_DEVICE_IMSI));
mobileDevice.setPushToken(getPropertyValue(device, MOBILE_DEVICE_PUSH_TOKEN));
mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL)); mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL));
mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION)); mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION));
mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR)); mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR));
mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE)); mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE));
mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE)); mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE));
mobileDevice.setChallenge(getPropertyValue(device, MOBILE_DEVICE_CHALLENGE));
mobileDevice.setToken(getPropertyValue(device, MOBILE_DEVICE_TOKEN));
mobileDevice.setSerial(getPropertyValue(device, MOBILE_DEVICE_SERIAL));
mobileDevice.setUnlockToken(getPropertyValue(device, MOBILE_DEVICE_UNLOCK_TOKEN));
} }
return mobileDevice; return mobileDevice;
} }
@ -110,16 +101,12 @@ public class MobileDeviceManagementUtil {
List<Device.Property> propertyList = new ArrayList<Device.Property>(); List<Device.Property> propertyList = new ArrayList<Device.Property>();
propertyList.add(getProperty(MOBILE_DEVICE_IMEI, mobileDevice.getImei())); propertyList.add(getProperty(MOBILE_DEVICE_IMEI, mobileDevice.getImei()));
propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi())); propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi()));
propertyList.add(getProperty(MOBILE_DEVICE_PUSH_TOKEN, mobileDevice.getPushToken()));
propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel())); propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel()));
propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion())); propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion()));
propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor())); propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor()));
propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude())); propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude()));
propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude())); propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude()));
propertyList.add(getProperty(MOBILE_DEVICE_CHALLENGE, mobileDevice.getChallenge()));
propertyList.add(getProperty(MOBILE_DEVICE_TOKEN, mobileDevice.getToken()));
propertyList.add(getProperty(MOBILE_DEVICE_SERIAL, mobileDevice.getSerial())); propertyList.add(getProperty(MOBILE_DEVICE_SERIAL, mobileDevice.getSerial()));
propertyList.add(getProperty(MOBILE_DEVICE_UNLOCK_TOKEN, mobileDevice.getUnlockToken()));
device.setProperties(propertyList); device.setProperties(propertyList);
device.setDeviceIdentifier(mobileDevice.getMobileDeviceId()); device.setDeviceIdentifier(mobileDevice.getMobileDeviceId());
} }

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