mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Refractor Plugin DAO factories
This commit is contained in:
parent
c75a32a36e
commit
fe72fc5b97
@ -20,14 +20,16 @@ package org.wso2.carbon.device.mgt.mobile.dao;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.DataSourceNotAvailableException;
|
import org.wso2.carbon.device.mgt.mobile.DataSourceNotAvailableException;
|
||||||
|
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.JNDILookupDefinition;
|
||||||
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.impl.*;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -36,21 +38,16 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* Factory class used to create MobileDeviceManagement related DAO objects.
|
* Factory class used to create MobileDeviceManagement related DAO objects.
|
||||||
*/
|
*/
|
||||||
public class MobileDeviceManagementDAOFactory {
|
public abstract class MobileDeviceManagementDAOFactory implements MobileDeviceManagementDAOFactoryInterface {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class);
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class);
|
||||||
private static Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap;
|
private static Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap;
|
||||||
private static Map<String, DataSource> dataSourceMap;
|
private static Map<String, DataSource> dataSourceMap;
|
||||||
private String pluginProvider;
|
|
||||||
private DataSource dataSource;
|
|
||||||
private static boolean isInitialized;
|
private static boolean isInitialized;
|
||||||
|
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
||||||
|
protected static DataSource dataSource;
|
||||||
|
|
||||||
public MobileDeviceManagementDAOFactory(String pluginProvider) {
|
public static void init() throws MobileDeviceMgtPluginException {
|
||||||
this.pluginProvider = pluginProvider;
|
|
||||||
this.dataSource = dataSourceMap.get(pluginProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void init() throws DeviceManagementException {
|
|
||||||
|
|
||||||
dataSourceMap = new HashMap<String, DataSource>();
|
dataSourceMap = new HashMap<String, DataSource>();
|
||||||
DataSource dataSource;
|
DataSource dataSource;
|
||||||
@ -68,8 +65,7 @@ public class MobileDeviceManagementDAOFactory {
|
|||||||
* @param config Mobile data source configuration
|
* @param config Mobile data source configuration
|
||||||
* @return data source resolved from the data source definition
|
* @return data source resolved from the data source definition
|
||||||
*/
|
*/
|
||||||
private static DataSource resolveDataSource(MobileDataSourceConfig config)
|
protected static DataSource resolveDataSource(MobileDataSourceConfig config) {
|
||||||
throws DeviceManagementException {
|
|
||||||
DataSource dataSource = null;
|
DataSource dataSource = null;
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
throw new RuntimeException("Device Management Repository data source configuration " +
|
throw new RuntimeException("Device Management Repository data source configuration " +
|
||||||
@ -99,34 +95,6 @@ public class MobileDeviceManagementDAOFactory {
|
|||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MobileDeviceDAO getMobileDeviceDAO() {
|
|
||||||
return new MobileDeviceDAOImpl(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MobileOperationDAO getMobileOperationDAO() {
|
|
||||||
return new MobileOperationDAOImpl(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MobileOperationPropertyDAO getMobileOperationPropertyDAO() {
|
|
||||||
return new MobileOperationPropertyDAOImpl(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() {
|
|
||||||
return new MobileDeviceOperationMappingDAOImpl(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MobileFeatureDAO getFeatureDAO() {
|
|
||||||
return new MobileFeatureDAOImpl(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MobileFeaturePropertyDAO getFeaturePropertyDAO() {
|
|
||||||
return new MobileFeaturePropertyDAOImpl(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MobileDataSourceConfig getMobileDeviceManagementConfig(String pluginType) {
|
|
||||||
return mobileDataSourceConfigMap.get(pluginType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, MobileDataSourceConfig> getMobileDataSourceConfigMap() {
|
public static Map<String, MobileDataSourceConfig> getMobileDataSourceConfigMap() {
|
||||||
return mobileDataSourceConfigMap;
|
return mobileDataSourceConfigMap;
|
||||||
}
|
}
|
||||||
@ -135,14 +103,10 @@ public class MobileDeviceManagementDAOFactory {
|
|||||||
MobileDeviceManagementDAOFactory.mobileDataSourceConfigMap = mobileDataSourceConfigMap;
|
MobileDeviceManagementDAOFactory.mobileDataSourceConfigMap = mobileDataSourceConfigMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataSource getDataSource(String type) {
|
public static DataSource getDataSource(String type) {
|
||||||
return dataSourceMap.get(type);
|
return dataSourceMap.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataSource getDataSource() {
|
|
||||||
return dataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, DataSource> getDataSourceMap() {
|
public static Map<String, DataSource> getDataSourceMap() {
|
||||||
return dataSourceMap;
|
return dataSourceMap;
|
||||||
}
|
}
|
||||||
@ -153,4 +117,51 @@ public class MobileDeviceManagementDAOFactory {
|
|||||||
"is not initialized");
|
"is not initialized");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void beginTransaction() throws MobileDeviceManagementDAOException {
|
||||||
|
try {
|
||||||
|
Connection conn = dataSource.getConnection();
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
currentConnection.set(conn);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new MobileDeviceManagementDAOException("Error occurred while retrieving datasource connection", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Connection getConnection() {
|
||||||
|
return currentConnection.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void commitTransaction() throws MobileDeviceManagementDAOException {
|
||||||
|
try {
|
||||||
|
Connection conn = currentConnection.get();
|
||||||
|
if (conn != null) {
|
||||||
|
conn.commit();
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Datasource connection associated with the current thread is null, hence commit " +
|
||||||
|
"has not been attempted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new MobileDeviceManagementDAOException("Error occurred while committing the transaction", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void rollbackTransaction() throws MobileDeviceManagementDAOException {
|
||||||
|
try {
|
||||||
|
Connection conn = currentConnection.get();
|
||||||
|
if (conn != null) {
|
||||||
|
conn.rollback();
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Datasource connection associated with the current thread is null, hence rollback " +
|
||||||
|
"has not been attempted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new MobileDeviceManagementDAOException("Error occurred while rollbacking the transaction", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ public interface MobileFeatureDAO {
|
|||||||
* @return The id of inserted MobileFeature.
|
* @return The id of inserted MobileFeature.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
int addMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
|
boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a MobileFeature in Mobile-Feature table.
|
* Updates a MobileFeature in Mobile-Feature table.
|
||||||
@ -44,7 +44,7 @@ public interface MobileFeatureDAO {
|
|||||||
* @return The status of the operation.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean updateMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
|
boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a MobileFeature from Mobile-Feature table when the feature id is given.
|
* Deletes a MobileFeature from Mobile-Feature table when the feature id is given.
|
||||||
@ -53,7 +53,7 @@ public interface MobileFeatureDAO {
|
|||||||
* @return The status of the operation.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean deleteMobileFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException;
|
boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a MobileFeature from Mobile-Feature table when the feature code is given.
|
* Deletes a MobileFeature from Mobile-Feature table when the feature code is given.
|
||||||
@ -62,7 +62,7 @@ public interface MobileFeatureDAO {
|
|||||||
* @return The status of the operation.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean deleteMobileFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException;
|
boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a given MobileFeature from Mobile-Feature table when the feature id is given.
|
* Retrieves a given MobileFeature from Mobile-Feature table when the feature id is given.
|
||||||
@ -71,7 +71,7 @@ public interface MobileFeatureDAO {
|
|||||||
* @return MobileFeature object that holds data of the feature represented by featureId.
|
* @return MobileFeature object that holds data of the feature represented by featureId.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
MobileFeature getMobileFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException;
|
MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a given MobileFeature from Mobile-Feature table when the feature code is given.
|
* Retrieves a given MobileFeature from Mobile-Feature table when the feature code is given.
|
||||||
@ -80,7 +80,7 @@ public interface MobileFeatureDAO {
|
|||||||
* @return MobileFeature object that holds data of the feature represented by featureCode.
|
* @return MobileFeature object that holds data of the feature represented by featureCode.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
MobileFeature getMobileFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException;
|
MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all MobileFeatures of a MobileDevice type from Mobile-Feature table.
|
* Retrieves all MobileFeatures of a MobileDevice type from Mobile-Feature table.
|
||||||
@ -89,7 +89,7 @@ public interface MobileFeatureDAO {
|
|||||||
* @return MobileFeature object list.
|
* @return MobileFeature object list.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<MobileFeature> getMobileFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException;
|
List<MobileFeature> getFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all the MobileFeatures from Mobile-Feature table.
|
* Retrieve all the MobileFeatures from Mobile-Feature table.
|
||||||
@ -97,5 +97,5 @@ public interface MobileFeatureDAO {
|
|||||||
* @return MobileFeature object list.
|
* @return MobileFeature object list.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<MobileFeature> getAllMobileFeatures() throws MobileDeviceManagementDAOException;
|
List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,9 +46,9 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int addMobileFeature(MobileFeature mobileFeature)
|
public boolean addFeature(MobileFeature mobileFeature)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
int status = 0;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
@ -63,15 +63,13 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
stmt.setString(4, mobileFeature.getDeviceType());
|
stmt.setString(4, mobileFeature.getDeviceType());
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
ResultSet rs = stmt.getGeneratedKeys();
|
|
||||||
if (rs != null && rs.next()) {
|
|
||||||
status = rs.getInt(1);
|
|
||||||
}
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Added a new MobileFeature " + mobileFeature.getCode() + " to the" +
|
log.debug("Added a new MobileFeature " + mobileFeature.getCode() + " to the" +
|
||||||
" MDM database.");
|
" MDM database.");
|
||||||
}
|
}
|
||||||
|
status = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while adding feature code - '" +
|
String msg = "Error occurred while adding feature code - '" +
|
||||||
mobileFeature.getCode() + "' to feature table";
|
mobileFeature.getCode() + "' to feature table";
|
||||||
@ -84,7 +82,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateMobileFeature(MobileFeature mobileFeature)
|
public boolean updateFeature(MobileFeature mobileFeature)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -119,7 +117,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteMobileFeatureByCode(String mblFeatureCode)
|
public boolean deleteFeatureByCode(String mblFeatureCode)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -149,7 +147,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteMobileFeatureById(int mblFeatureId)
|
public boolean deleteFeatureById(int mblFeatureId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -179,7 +177,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobileFeature getMobileFeatureByCode(String mblFeatureCode)
|
public MobileFeature getFeatureByCode(String mblFeatureCode)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -216,7 +214,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobileFeature getMobileFeatureById(int mblFeatureId)
|
public MobileFeature getFeatureById(int mblFeatureId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -253,7 +251,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MobileFeature> getAllMobileFeatures() throws MobileDeviceManagementDAOException {
|
public List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
MobileFeature mobileFeature;
|
MobileFeature mobileFeature;
|
||||||
@ -287,7 +285,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MobileFeature> getMobileFeatureByDeviceType(String deviceType) throws
|
public List<MobileFeature> getFeatureByDeviceType(String deviceType) throws
|
||||||
MobileDeviceManagementDAOException {
|
MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
|||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -40,10 +40,7 @@ public class AndroidDeviceManager implements DeviceManager {
|
|||||||
private static final Log log = LogFactory.getLog(AndroidDeviceManager.class);
|
private static final Log log = LogFactory.getLog(AndroidDeviceManager.class);
|
||||||
|
|
||||||
public AndroidDeviceManager() {
|
public AndroidDeviceManager() {
|
||||||
mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(
|
mobileDeviceManagementDAOFactory = new AndroidDAOFactory();
|
||||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
||||||
FeatureManagementDAOFactory
|
|
||||||
.init(mobileDeviceManagementDAOFactory.getDataSource(this.getProviderType()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -22,34 +22,44 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
import org.wso2.carbon.device.mgt.common.FeatureManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureDAO;
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureDAO;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOException;
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AndroidFeatureManager implements FeatureManager {
|
public class AndroidFeatureManager implements FeatureManager {
|
||||||
|
|
||||||
private FeatureDAO featureDAO;
|
private MobileFeatureDAO featureDAO;
|
||||||
private static final Log log = LogFactory.getLog(AndroidFeatureManager.class);
|
private static final Log log = LogFactory.getLog(AndroidFeatureManager.class);
|
||||||
|
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
|
||||||
|
|
||||||
public AndroidFeatureManager() {
|
public AndroidFeatureManager() {
|
||||||
this.featureDAO = FeatureManagementDAOFactory.getFeatureDAO();
|
mobileDeviceManagementDAOFactory = new AndroidDAOFactory();
|
||||||
|
this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDao();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addFeature(Feature feature) throws DeviceManagementException {
|
public boolean addFeature(Feature feature) throws DeviceManagementException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.beginTransaction();
|
mobileDeviceManagementDAOFactory.beginTransaction();
|
||||||
featureDAO.addFeature(feature);
|
MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature);
|
||||||
FeatureManagementDAOFactory.commitTransaction();
|
featureDAO.addFeature(mobileFeature);
|
||||||
|
mobileDeviceManagementDAOFactory.commitTransaction();
|
||||||
return true;
|
return true;
|
||||||
} catch (FeatureManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.rollbackTransaction();
|
mobileDeviceManagementDAOFactory.rollbackTransaction();
|
||||||
} catch (FeatureManagementDAOException e1) {
|
} catch (MobileDeviceManagementDAOException e1) {
|
||||||
log.warn("Error occurred while roll-backing the transaction", e);
|
log.warn("Error occurred while roll-backing the transaction", e);
|
||||||
}
|
}
|
||||||
throw new DeviceManagementException("Error occurred while adding the feature", e);
|
throw new DeviceManagementException("Error occurred while adding the feature", e);
|
||||||
@ -59,14 +69,13 @@ public class AndroidFeatureManager implements FeatureManager {
|
|||||||
@Override
|
@Override
|
||||||
public Feature getFeature(String name) throws DeviceManagementException {
|
public Feature getFeature(String name) throws DeviceManagementException {
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.beginTransaction();
|
MobileFeature mobileFeature = featureDAO.getFeatureByCode(name);
|
||||||
Feature feature = featureDAO.getFeature(name);
|
Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature);
|
||||||
FeatureManagementDAOFactory.commitTransaction();
|
|
||||||
return feature;
|
return feature;
|
||||||
} catch (FeatureManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.rollbackTransaction();
|
mobileDeviceManagementDAOFactory.rollbackTransaction();
|
||||||
} catch (FeatureManagementDAOException e1) {
|
} catch (MobileDeviceManagementDAOException e1) {
|
||||||
log.warn("Error occurred while roll-backing the transaction", e);
|
log.warn("Error occurred while roll-backing the transaction", e);
|
||||||
}
|
}
|
||||||
throw new DeviceManagementException("Error occurred while retrieving the feature", e);
|
throw new DeviceManagementException("Error occurred while retrieving the feature", e);
|
||||||
@ -75,15 +84,18 @@ public class AndroidFeatureManager implements FeatureManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Feature> getFeatures() throws DeviceManagementException {
|
public List<Feature> getFeatures() throws DeviceManagementException {
|
||||||
|
|
||||||
|
List<Feature> featureList = new ArrayList<Feature>();
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.beginTransaction();
|
List<MobileFeature> mobileFeatures = featureDAO.getAllFeatures();
|
||||||
List<Feature> features = featureDAO.getFeatures();
|
for (MobileFeature mobileFeature : mobileFeatures) {
|
||||||
FeatureManagementDAOFactory.commitTransaction();
|
featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature));
|
||||||
return features;
|
}
|
||||||
} catch (FeatureManagementDAOException e) {
|
return featureList;
|
||||||
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.rollbackTransaction();
|
mobileDeviceManagementDAOFactory.rollbackTransaction();
|
||||||
} catch (FeatureManagementDAOException e1) {
|
} catch (MobileDeviceManagementDAOException e1) {
|
||||||
log.warn("Error occurred while roll-backing the transaction", e);
|
log.warn("Error occurred while roll-backing the transaction", e);
|
||||||
}
|
}
|
||||||
throw new DeviceManagementException("Error occurred while retrieving the list of features registered " +
|
throw new DeviceManagementException("Error occurred while retrieving the list of features registered " +
|
||||||
@ -92,20 +104,22 @@ public class AndroidFeatureManager implements FeatureManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeFeature(String name) throws DeviceManagementException {
|
public boolean removeFeature(String code) throws DeviceManagementException {
|
||||||
|
boolean status = false;
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.beginTransaction();
|
mobileDeviceManagementDAOFactory.beginTransaction();
|
||||||
featureDAO.removeFeature(name);
|
featureDAO.deleteFeatureByCode(code);
|
||||||
FeatureManagementDAOFactory.commitTransaction();
|
mobileDeviceManagementDAOFactory.commitTransaction();
|
||||||
return true;
|
status = true;
|
||||||
} catch (FeatureManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.rollbackTransaction();
|
mobileDeviceManagementDAOFactory.rollbackTransaction();
|
||||||
} catch (FeatureManagementDAOException e1) {
|
} catch (MobileDeviceManagementDAOException e1) {
|
||||||
log.warn("Error occurred while roll-backing the transaction", e);
|
log.warn("Error occurred while roll-backing the transaction", e);
|
||||||
}
|
}
|
||||||
throw new DeviceManagementException("Error occurred while removing the feature", e);
|
throw new DeviceManagementException("Error occurred while removing the feature", e);
|
||||||
}
|
}
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,24 +20,48 @@ package org.wso2.carbon.device.mgt.mobile.impl.android.dao;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.dao.*;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.FeatureDAOImpl;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
public class AndroidDAOFactory {
|
public class AndroidDAOFactory extends MobileDeviceManagementDAOFactory
|
||||||
|
implements MobileDeviceManagementDAOFactoryInterface {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(AndroidDAOFactory.class);
|
private static final Log log = LogFactory.getLog(AndroidDAOFactory.class);
|
||||||
private static DataSource dataSource;
|
private static DataSource dataSource;
|
||||||
private static boolean isInitialized;
|
|
||||||
private static MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
|
|
||||||
|
|
||||||
public static void init() {
|
public static void init(MobileDataSourceConfig config) {
|
||||||
mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(DeviceManagementConstants
|
dataSource = resolveDataSource(config);
|
||||||
.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataSource getDataSource() {
|
@Override
|
||||||
return mobileDeviceManagementDAOFactory.getDataSource();
|
public MobileDeviceDAO getMobileDeviceDAO() {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MobileOperationDAO getMobileOperationDAO() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MobileOperationPropertyDAO getMobileOperationPropertyDAO() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public MobileFeatureDAO getMobileFeatureDao() {
|
||||||
|
return new FeatureDAOImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MobileFeaturePropertyDAO getFeaturePropertyDAO() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -19,17 +19,18 @@
|
|||||||
package org.wso2.carbon.device.mgt.mobile.impl.android.dao;
|
package org.wso2.carbon.device.mgt.mobile.impl.android.dao;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface FeatureDAO {
|
public interface FeatureDAO {
|
||||||
|
|
||||||
void addFeature(Feature feature) throws FeatureManagementDAOException;
|
void addFeature(MobileFeature feature) throws FeatureManagementDAOException;
|
||||||
|
|
||||||
void removeFeature(String name) throws FeatureManagementDAOException;
|
void removeFeature(String name) throws FeatureManagementDAOException;
|
||||||
|
|
||||||
Feature getFeature(String name) throws FeatureManagementDAOException;
|
MobileFeature getFeature(String name) throws FeatureManagementDAOException;
|
||||||
|
|
||||||
List<Feature> getFeatures() throws FeatureManagementDAOException;
|
List<MobileFeature> getFeatures() throws FeatureManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl.android.dao;
|
package org.wso2.carbon.device.mgt.mobile.impl.android.dao;
|
||||||
|
|
||||||
public class FeatureManagementDAOException extends Exception {
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
|
public class FeatureManagementDAOException extends MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
private static final long serialVersionUID = 2021891706072918865L;
|
private static final long serialVersionUID = 2021891706072918865L;
|
||||||
|
|||||||
@ -20,10 +20,12 @@ package org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl;
|
|||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureDAO;
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOException;
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -32,53 +34,77 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FeatureDAOImpl implements FeatureDAO {
|
public class FeatureDAOImpl implements MobileFeatureDAO {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addFeature(Feature feature) throws FeatureManagementDAOException {
|
public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
|
boolean status = false;
|
||||||
try {
|
try {
|
||||||
Connection conn = FeatureManagementDAOFactory.getConnection();
|
Connection conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
|
String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, feature.getCode());
|
stmt.setString(1, mobileFeature.getCode());
|
||||||
stmt.setString(2, feature.getName());
|
stmt.setString(2, mobileFeature.getName());
|
||||||
stmt.setString(3, feature.getDescription());
|
stmt.setString(3, mobileFeature.getDescription());
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
status = true;
|
||||||
|
status = true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new FeatureManagementDAOException("Error occurred while adding feature '" +
|
throw new org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException(
|
||||||
feature.getName() + "' into the metadata repository", e);
|
"Error occurred while adding feature '" +
|
||||||
|
mobileFeature.getName() + "' into the metadata repository", e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeFeature(String code) throws FeatureManagementDAOException {
|
public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
|
boolean status = false;
|
||||||
try {
|
try {
|
||||||
Connection conn = FeatureManagementDAOFactory.getConnection();
|
Connection conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?";
|
String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, code);
|
stmt.setString(1, mblFeatureCode);
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
|
status = true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new FeatureManagementDAOException("Error occurred while adding feature '" +
|
throw new org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException(
|
||||||
code + "' into the metadata repository", e);
|
"Error occurred while adding feature '" +
|
||||||
|
mblFeatureCode + "' into the metadata repository", e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Feature getFeature(String code) throws FeatureManagementDAOException {
|
public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
Connection conn = FeatureManagementDAOFactory.getConnection();
|
Connection conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?";
|
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, code);
|
stmt.setString(1, mblFeatureCode);
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
Feature feature = null;
|
Feature feature = null;
|
||||||
@ -89,25 +115,35 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|||||||
feature.setName(rs.getString("NAME"));
|
feature.setName(rs.getString("NAME"));
|
||||||
feature.setDescription(rs.getString("DESCRIPTION"));
|
feature.setDescription(rs.getString("DESCRIPTION"));
|
||||||
}
|
}
|
||||||
return feature;
|
MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature);
|
||||||
|
return mobileFeature;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new FeatureManagementDAOException("Error occurred while retrieving feature metadata '" +
|
throw new org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException(
|
||||||
code + "' from the feature metadata repository", e);
|
"Error occurred while retrieving feature metadata '" +
|
||||||
|
mblFeatureCode + "' from the feature metadata repository", e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Feature> getFeatures() throws FeatureManagementDAOException {
|
public List<MobileFeature> getFeatureByDeviceType(String deviceType)
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<Feature> features = new ArrayList<Feature>();
|
List<MobileFeature> features = new ArrayList<MobileFeature>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection conn = FeatureManagementDAOFactory.getConnection();
|
Connection conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE";
|
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
MobileFeature mobileFeature;
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
Feature feature = new Feature();
|
Feature feature = new Feature();
|
||||||
@ -115,6 +151,8 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|||||||
feature.setCode(rs.getString("CODE"));
|
feature.setCode(rs.getString("CODE"));
|
||||||
feature.setName(rs.getString("NAME"));
|
feature.setName(rs.getString("NAME"));
|
||||||
feature.setDescription(rs.getString("DESCRIPTION"));
|
feature.setDescription(rs.getString("DESCRIPTION"));
|
||||||
|
mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature);
|
||||||
|
features.add(mobileFeature);
|
||||||
}
|
}
|
||||||
return features;
|
return features;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -124,5 +162,4 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|||||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
|||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.IOSDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -44,8 +45,7 @@ public class IOSDeviceManager implements DeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IOSDeviceManager() {
|
public IOSDeviceManager() {
|
||||||
mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(DeviceManagementConstants
|
mobileDeviceManagementDAOFactory = new IOSDAOFactory();
|
||||||
.MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS);
|
|
||||||
iosFeatureManager = new IOSFeatureManager();
|
iosFeatureManager = new IOSFeatureManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,69 +23,75 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureDAO;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.IOSDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class IOSFeatureManager implements FeatureManager {
|
public class IOSFeatureManager implements FeatureManager {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(IOSFeatureManager.class);
|
private static final Log log = LogFactory.getLog(IOSFeatureManager.class);
|
||||||
|
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
|
||||||
|
|
||||||
private FeatureDAO featureDAO;
|
private MobileFeatureDAO featureDAO;
|
||||||
|
|
||||||
public IOSFeatureManager() {
|
public IOSFeatureManager() {
|
||||||
this.featureDAO = FeatureManagementDAOFactory.getFeatureDAO();
|
mobileDeviceManagementDAOFactory = new IOSDAOFactory();
|
||||||
|
this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDao();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addFeature(Feature feature) throws DeviceManagementException {
|
public boolean addFeature(Feature feature) throws DeviceManagementException {
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.beginTransaction();
|
mobileDeviceManagementDAOFactory.beginTransaction();
|
||||||
featureDAO.addFeature(feature);
|
MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature);
|
||||||
FeatureManagementDAOFactory.commitTransaction();
|
|
||||||
return true;
|
|
||||||
} catch (FeatureManagementDAOException e) {
|
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.rollbackTransaction();
|
featureDAO.addFeature(mobileFeature);
|
||||||
} catch (FeatureManagementDAOException e1) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
|
log.error("error in feature add ", e);
|
||||||
|
throw new DeviceManagementException("error in feature add", e);
|
||||||
|
}
|
||||||
|
mobileDeviceManagementDAOFactory.commitTransaction();
|
||||||
|
return true;
|
||||||
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
|
try {
|
||||||
|
mobileDeviceManagementDAOFactory.rollbackTransaction();
|
||||||
|
} catch (MobileDeviceManagementDAOException e1) {
|
||||||
log.warn("Error occurred while roll-backing the transaction", e);
|
log.warn("Error occurred while roll-backing the transaction", e);
|
||||||
}
|
}
|
||||||
throw new DeviceManagementException("Error occurred while adding the feature", e);
|
throw new DeviceManagementException("DB transaction error occurred while add the feature", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Feature getFeature(String name) throws DeviceManagementException {
|
public Feature getFeature(String code) throws DeviceManagementException {
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.beginTransaction();
|
MobileFeature mobileFeature = featureDAO.getFeatureByCode(code);
|
||||||
Feature feature = featureDAO.getFeature(name);
|
Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature);
|
||||||
FeatureManagementDAOFactory.commitTransaction();
|
|
||||||
return feature;
|
return feature;
|
||||||
} catch (FeatureManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
try {
|
|
||||||
FeatureManagementDAOFactory.rollbackTransaction();
|
|
||||||
} catch (FeatureManagementDAOException e1) {
|
|
||||||
log.warn("Error occurred while roll-backing the transaction", e);
|
|
||||||
}
|
|
||||||
throw new DeviceManagementException("Error occurred while retrieving the feature", e);
|
throw new DeviceManagementException("Error occurred while retrieving the feature", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Feature> getFeatures() throws DeviceManagementException {
|
public List<Feature> getFeatures() throws DeviceManagementException {
|
||||||
|
|
||||||
|
List<Feature> featureList = new ArrayList<Feature>();
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.beginTransaction();
|
List<MobileFeature> mobileFeatures = featureDAO.getAllFeatures();
|
||||||
List<Feature> features = featureDAO.getFeatures();
|
|
||||||
FeatureManagementDAOFactory.commitTransaction();
|
for (MobileFeature mobileFeature : mobileFeatures) {
|
||||||
return features;
|
featureList.add(MobileDeviceManagementUtil.convertToFeature(mobileFeature));
|
||||||
} catch (FeatureManagementDAOException e) {
|
|
||||||
try {
|
|
||||||
FeatureManagementDAOFactory.rollbackTransaction();
|
|
||||||
} catch (FeatureManagementDAOException e1) {
|
|
||||||
log.warn("Error occurred while roll-backing the transaction", e);
|
|
||||||
}
|
}
|
||||||
|
return featureList;
|
||||||
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
throw new DeviceManagementException("Error occurred while retrieving the list of features registered " +
|
throw new DeviceManagementException("Error occurred while retrieving the list of features registered " +
|
||||||
"for Android platform", e);
|
"for Android platform", e);
|
||||||
}
|
}
|
||||||
@ -94,14 +100,14 @@ public class IOSFeatureManager implements FeatureManager {
|
|||||||
@Override
|
@Override
|
||||||
public boolean removeFeature(String name) throws DeviceManagementException {
|
public boolean removeFeature(String name) throws DeviceManagementException {
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.beginTransaction();
|
mobileDeviceManagementDAOFactory.beginTransaction();
|
||||||
featureDAO.removeFeature(name);
|
featureDAO.deleteFeatureByCode(name);
|
||||||
FeatureManagementDAOFactory.commitTransaction();
|
mobileDeviceManagementDAOFactory.commitTransaction();
|
||||||
return true;
|
return true;
|
||||||
} catch (FeatureManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
try {
|
try {
|
||||||
FeatureManagementDAOFactory.rollbackTransaction();
|
mobileDeviceManagementDAOFactory.rollbackTransaction();
|
||||||
} catch (FeatureManagementDAOException e1) {
|
} catch (MobileDeviceManagementDAOException e1) {
|
||||||
log.warn("Error occurred while roll-backing the transaction", e);
|
log.warn("Error occurred while roll-backing the transaction", e);
|
||||||
}
|
}
|
||||||
throw new DeviceManagementException("Error occurred while removing the feature", e);
|
throw new DeviceManagementException("Error occurred while removing the feature", e);
|
||||||
|
|||||||
@ -18,7 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl.ios.dao;
|
package org.wso2.carbon.device.mgt.mobile.impl.ios.dao;
|
||||||
|
|
||||||
public class FeatureManagementDAOException extends Exception {
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
|
public class FeatureManagementDAOException extends MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
private static final long serialVersionUID = 2021891706072918865L;
|
private static final long serialVersionUID = 2021891706072918865L;
|
||||||
|
|||||||
@ -19,24 +19,43 @@ package org.wso2.carbon.device.mgt.mobile.impl.ios.dao;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.dao.*;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
public class IOSDAOFactory extends MobileDeviceManagementDAOFactory {
|
||||||
|
|
||||||
public class IOSDAOFactory {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(IOSDAOFactory.class);
|
private static final Log log = LogFactory.getLog(IOSDAOFactory.class);
|
||||||
private static DataSource dataSource;
|
|
||||||
private static boolean isInitialized;
|
|
||||||
private static MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
|
|
||||||
|
|
||||||
public static void init() {
|
public static void init(MobileDataSourceConfig config) {
|
||||||
mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(DeviceManagementConstants
|
dataSource = resolveDataSource(config);
|
||||||
.MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataSource getDataSource() {
|
@Override
|
||||||
return mobileDeviceManagementDAOFactory.getDataSource();
|
public MobileDeviceDAO getMobileDeviceDAO() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MobileOperationDAO getMobileOperationDAO() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MobileOperationPropertyDAO getMobileOperationPropertyDAO() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MobileFeatureDAO getMobileFeatureDao() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MobileFeaturePropertyDAO getFeaturePropertyDAO() {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,12 +18,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl.ios.dao.impl;
|
package org.wso2.carbon.device.mgt.mobile.impl.ios.dao.impl;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureDAO;
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException;
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOFactory;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -31,58 +31,79 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FeatureDAOImpl implements FeatureDAO {
|
public class FeatureDAOImpl implements MobileFeatureDAO {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addFeature(Feature feature) throws FeatureManagementDAOException {
|
public boolean addFeature(MobileFeature feature) throws FeatureManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
|
boolean status = false;
|
||||||
try {
|
try {
|
||||||
Connection conn = FeatureManagementDAOFactory.getConnection();
|
Connection conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "INSERT INTO IOS_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
|
String sql = "INSERT INTO IOS_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, feature.getCode());
|
stmt.setString(1, feature.getCode());
|
||||||
stmt.setString(2, feature.getName());
|
stmt.setString(2, feature.getName());
|
||||||
stmt.setString(3, feature.getDescription());
|
stmt.setString(3, feature.getDescription());
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
status = true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new FeatureManagementDAOException("Error occurred while adding feature '" +
|
throw new FeatureManagementDAOException("Error occurred while adding feature '" +
|
||||||
feature.getName() + "' into the metadata repository", e);
|
feature.getName() + "' into the metadata repository", e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeFeature(String code) throws FeatureManagementDAOException {
|
public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
|
boolean status = false;
|
||||||
try {
|
try {
|
||||||
Connection conn = FeatureManagementDAOFactory.getConnection();
|
Connection conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "DELETE FROM IOS_FEATURE WHERE CODE = ?";
|
String sql = "DELETE FROM IOS_FEATURE WHERE CODE = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, code);
|
stmt.setString(1, mblFeatureCode);
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
|
status = true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new FeatureManagementDAOException("Error occurred while adding feature '" +
|
throw new FeatureManagementDAOException("Error occurred while adding feature '" +
|
||||||
code + "' into the metadata repository", e);
|
mblFeatureCode + "' into the metadata repository", e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
}
|
}
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Feature getFeature(String code) throws FeatureManagementDAOException {
|
public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
Connection conn = FeatureManagementDAOFactory.getConnection();
|
Connection conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM IOS_FEATURE WHERE CODE = ?";
|
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM IOS_FEATURE WHERE CODE = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, code);
|
stmt.setString(1, mblFeatureCode);
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
Feature feature = null;
|
MobileFeature feature = null;
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
feature = new Feature();
|
feature = new MobileFeature();
|
||||||
feature.setId(rs.getInt("ID"));
|
feature.setId(rs.getInt("ID"));
|
||||||
feature.setCode(rs.getString("CODE"));
|
feature.setCode(rs.getString("CODE"));
|
||||||
feature.setName(rs.getString("NAME"));
|
feature.setName(rs.getString("NAME"));
|
||||||
@ -91,25 +112,30 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|||||||
return feature;
|
return feature;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new FeatureManagementDAOException("Error occurred while retrieving feature metadata '" +
|
throw new FeatureManagementDAOException("Error occurred while retrieving feature metadata '" +
|
||||||
code + "' from the feature metadata repository", e);
|
mblFeatureCode + "' from the feature metadata repository", e);
|
||||||
} finally {
|
} finally {
|
||||||
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Feature> getFeatures() throws FeatureManagementDAOException {
|
public List<MobileFeature> getFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<Feature> features = new ArrayList<Feature>();
|
List<MobileFeature> features = new ArrayList<MobileFeature>();
|
||||||
try {
|
try {
|
||||||
Connection conn = FeatureManagementDAOFactory.getConnection();
|
Connection conn = MobileDeviceManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM IOS_FEATURE";
|
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM IOS_FEATURE";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
Feature feature = new Feature();
|
MobileFeature feature = new MobileFeature();
|
||||||
feature.setId(rs.getInt("ID"));
|
feature.setId(rs.getInt("ID"));
|
||||||
feature.setCode(rs.getString("CODE"));
|
feature.setCode(rs.getString("CODE"));
|
||||||
feature.setName(rs.getString("NAME"));
|
feature.setName(rs.getString("NAME"));
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
|||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -37,8 +38,7 @@ public class WindowsDeviceManager implements DeviceManager {
|
|||||||
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
|
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
|
||||||
|
|
||||||
public WindowsDeviceManager() {
|
public WindowsDeviceManager() {
|
||||||
mobileDeviceManagementDAOFactory = new MobileDeviceManagementDAOFactory(DeviceManagementConstants
|
mobileDeviceManagementDAOFactory = new WindowsDAOFactory();
|
||||||
.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS);
|
|
||||||
}
|
}
|
||||||
private static final Log log = LogFactory.getLog(WindowsDeviceManager.class);
|
private static final Log log = LogFactory.getLog(WindowsDeviceManager.class);
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfi
|
|||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManager;
|
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManager;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManager;
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManager;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.IOSDAOFactory;
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.IOSDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManager;
|
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManager;
|
||||||
@ -77,8 +78,9 @@ public class MobileDeviceManagementServiceComponent {
|
|||||||
Map<String, MobileDataSourceConfig> dsConfigMap =
|
Map<String, MobileDataSourceConfig> dsConfigMap =
|
||||||
config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap();
|
config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap();
|
||||||
MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(dsConfigMap);
|
MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(dsConfigMap);
|
||||||
MobileDeviceManagementDAOFactory.init();
|
IOSDAOFactory.init(dsConfigMap.get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS));
|
||||||
IOSDAOFactory.init();
|
AndroidDAOFactory
|
||||||
|
.init(dsConfigMap.get(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID));
|
||||||
|
|
||||||
String setupOption = System.getProperty("setup");
|
String setupOption = System.getProperty("setup");
|
||||||
if (setupOption != null) {
|
if (setupOption != null) {
|
||||||
|
|||||||
@ -23,11 +23,9 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
import org.wso2.carbon.device.mgt.mobile.dto.*;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
@ -164,4 +162,24 @@ public class MobileDeviceManagementUtil {
|
|||||||
operation.setProperties(properties);
|
operation.setProperties(properties);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MobileFeature convertToMobileFeature(Feature feature) {
|
||||||
|
MobileFeature mobileFeature = new MobileFeature();
|
||||||
|
mobileFeature.setName(feature.getName());
|
||||||
|
mobileFeature.setCode(feature.getCode());
|
||||||
|
mobileFeature.setDescription(feature.getDescription());
|
||||||
|
mobileFeature.setDeviceType(feature.getDeviceType());
|
||||||
|
|
||||||
|
return mobileFeature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Feature convertToFeature(MobileFeature mobileFeature) {
|
||||||
|
Feature feature = new Feature();
|
||||||
|
feature.setDescription(mobileFeature.getDescription());
|
||||||
|
feature.setDeviceType(mobileFeature.getDeviceType());
|
||||||
|
feature.setCode(mobileFeature.getCode());
|
||||||
|
feature.setName(mobileFeature.getName());
|
||||||
|
|
||||||
|
return feature;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,7 +87,8 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
||||||
mobileFeature.setName(MBL_FEATURE_NAME);
|
mobileFeature.setName(MBL_FEATURE_NAME);
|
||||||
mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE);
|
mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE);
|
||||||
int id = mblFeatureDAO.addMobileFeature(mobileFeature);
|
mblFeatureDAO.addFeature(mobileFeature);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
String query =
|
String query =
|
||||||
@ -110,7 +111,7 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
}
|
}
|
||||||
mblFeatureId = testMblFeature.getId();
|
mblFeatureId = testMblFeature.getId();
|
||||||
Assert.assertTrue(id > 0, "MobileFeature has added ");
|
Assert.assertTrue(mblFeatureId > 0, "MobileFeature has added ");
|
||||||
Assert.assertEquals(MBL_FEATURE_CODE, testMblFeature.getCode(),
|
Assert.assertEquals(MBL_FEATURE_CODE, testMblFeature.getCode(),
|
||||||
"MobileFeature code has persisted ");
|
"MobileFeature code has persisted ");
|
||||||
Assert.assertEquals(MBL_FEATURE_NAME, testMblFeature.getName(),
|
Assert.assertEquals(MBL_FEATURE_NAME, testMblFeature.getName(),
|
||||||
@ -125,7 +126,7 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
public void getMobileFeatureByCodeTest()
|
public void getMobileFeatureByCodeTest()
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
MobileFeature mobileFeature = mblFeatureDAO.getMobileFeatureByCode(MBL_FEATURE_CODE);
|
MobileFeature mobileFeature = mblFeatureDAO.getFeatureByCode(MBL_FEATURE_CODE);
|
||||||
Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(),
|
Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(),
|
||||||
"MobileFeature code has retrieved ");
|
"MobileFeature code has retrieved ");
|
||||||
Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(),
|
Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(),
|
||||||
@ -138,7 +139,7 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
public void getMobileFeatureByIdTest()
|
public void getMobileFeatureByIdTest()
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
MobileFeature mobileFeature = mblFeatureDAO.getMobileFeatureById(mblFeatureId);
|
MobileFeature mobileFeature = mblFeatureDAO.getFeatureById(mblFeatureId);
|
||||||
Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(),
|
Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(),
|
||||||
"MobileFeature code has retrieved ");
|
"MobileFeature code has retrieved ");
|
||||||
Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(),
|
Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(),
|
||||||
@ -151,7 +152,7 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
public void getAllMobileFeaturesTest()
|
public void getAllMobileFeaturesTest()
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
List<MobileFeature> mobileFeatures = mblFeatureDAO.getAllMobileFeatures();
|
List<MobileFeature> mobileFeatures = mblFeatureDAO.getAllFeatures();
|
||||||
Assert.assertNotNull(mobileFeatures, "MobileFeature list is not null");
|
Assert.assertNotNull(mobileFeatures, "MobileFeature list is not null");
|
||||||
Assert.assertTrue(mobileFeatures.size() > 0, "MobileFeature list has 1 MobileFeature");
|
Assert.assertTrue(mobileFeatures.size() > 0, "MobileFeature list has 1 MobileFeature");
|
||||||
}
|
}
|
||||||
@ -170,7 +171,7 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
||||||
mobileFeature.setName(MBL_FEATURE_NAME);
|
mobileFeature.setName(MBL_FEATURE_NAME);
|
||||||
mobileFeature.setId(mblFeatureId);
|
mobileFeature.setId(mblFeatureId);
|
||||||
boolean updated = mblFeatureDAO.updateMobileFeature(mobileFeature);
|
boolean updated = mblFeatureDAO.updateFeature(mobileFeature);
|
||||||
try {
|
try {
|
||||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
String query =
|
String query =
|
||||||
@ -204,7 +205,7 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
|
|
||||||
boolean status = mblFeatureDAO.deleteMobileFeatureById(mblFeatureId);
|
boolean status = mblFeatureDAO.deleteFeatureById(mblFeatureId);
|
||||||
try {
|
try {
|
||||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
String query = "SELECT FEATURE_ID, CODE FROM AD_FEATURE WHERE FEATURE_ID = ?";
|
String query = "SELECT FEATURE_ID, CODE FROM AD_FEATURE WHERE FEATURE_ID = ?";
|
||||||
@ -236,8 +237,8 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
||||||
mobileFeature.setName(MBL_FEATURE_NAME);
|
mobileFeature.setName(MBL_FEATURE_NAME);
|
||||||
mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE);
|
mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE);
|
||||||
mblFeatureDAO.addMobileFeature(mobileFeature);
|
mblFeatureDAO.addFeature(mobileFeature);
|
||||||
boolean status = mblFeatureDAO.deleteMobileFeatureByCode(MBL_FEATURE_CODE);
|
boolean status = mblFeatureDAO.deleteFeatureByCode(MBL_FEATURE_CODE);
|
||||||
try {
|
try {
|
||||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
String query = "SELECT FEATURE_ID, CODE FROM AD_FEATURE WHERE CODE = ?";
|
String query = "SELECT FEATURE_ID, CODE FROM AD_FEATURE WHERE CODE = ?";
|
||||||
|
|||||||
@ -45,6 +45,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MobileFeaturePropertyDAOTestSuite {
|
public class MobileFeaturePropertyDAOTestSuite {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(MobileFeaturePropertyDAOTestSuite.class);
|
private static final Log log = LogFactory.getLog(MobileFeaturePropertyDAOTestSuite.class);
|
||||||
public static final String MBL_FEATURE_NAME = "WIFI";
|
public static final String MBL_FEATURE_NAME = "WIFI";
|
||||||
private static final String MBL_FEATURE_CODE = "500A";
|
private static final String MBL_FEATURE_CODE = "500A";
|
||||||
@ -93,8 +94,10 @@ public class MobileFeaturePropertyDAOTestSuite {
|
|||||||
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
||||||
mobileFeature.setName(MBL_FEATURE_NAME);
|
mobileFeature.setName(MBL_FEATURE_NAME);
|
||||||
mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE);
|
mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE);
|
||||||
mblFeatureId = mblFeatureDAO.addMobileFeature(mobileFeature);
|
mblFeatureDAO.addFeature(mobileFeature);
|
||||||
|
|
||||||
|
MobileFeature persistMblFeature = mblFeatureDAO.getFeatureByCode(MBL_FEATURE_CODE);
|
||||||
|
mblFeatureId = persistMblFeature.getId();
|
||||||
//Add 1st property to the feature
|
//Add 1st property to the feature
|
||||||
MobileFeatureProperty mobileFeatureProperty = new MobileFeatureProperty();
|
MobileFeatureProperty mobileFeatureProperty = new MobileFeatureProperty();
|
||||||
mobileFeatureProperty.setFeatureID(mblFeatureId);
|
mobileFeatureProperty.setFeatureID(mblFeatureId);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user