mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt-plugins
This commit is contained in:
commit
0a78e46f21
@ -18,7 +18,9 @@
|
|||||||
~ under the License.
|
~ under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>device-mgt</artifactId>
|
<artifactId>device-mgt</artifactId>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
@ -51,9 +53,11 @@
|
|||||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||||
<Bundle-Version>${carbon.mobile.device.mgt.version}</Bundle-Version>
|
<Bundle-Version>${carbon.mobile.device.mgt.version}</Bundle-Version>
|
||||||
<Bundle-Description>Device Management Mobile Impl Bundle</Bundle-Description>
|
<Bundle-Description>Device Management Mobile Impl Bundle
|
||||||
|
</Bundle-Description>
|
||||||
<!--<Bundle-Activator>org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementBundleActivator</Bundle-Activator>-->
|
<!--<Bundle-Activator>org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementBundleActivator</Bundle-Activator>-->
|
||||||
<Private-Package>org.wso2.carbon.device.mgt.mobile.internal</Private-Package>
|
<Private-Package>org.wso2.carbon.device.mgt.mobile.internal
|
||||||
|
</Private-Package>
|
||||||
<Import-Package>
|
<Import-Package>
|
||||||
org.osgi.framework,
|
org.osgi.framework,
|
||||||
org.osgi.service.component,
|
org.osgi.service.component,
|
||||||
@ -73,7 +77,8 @@
|
|||||||
<version>2.18</version>
|
<version>2.18</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
|
<log4j.configuration>file:src/test/resources/log4j.properties
|
||||||
|
</log4j.configuration>
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
<suiteXmlFiles>
|
<suiteXmlFiles>
|
||||||
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
|
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
|
||||||
|
|||||||
@ -25,13 +25,15 @@ import java.util.List;
|
|||||||
public abstract class AbstractMobileOperationManager implements OperationManager {
|
public abstract class AbstractMobileOperationManager implements OperationManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
|
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier)
|
||||||
|
throws OperationManagementException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addOperation(Operation operation,
|
public boolean addOperation(Operation operation,
|
||||||
List<DeviceIdentifier> devices) throws OperationManagementException {
|
List<DeviceIdentifier> devices)
|
||||||
|
throws OperationManagementException {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,11 +35,14 @@ public class MobileDeviceConfigurationManager {
|
|||||||
|
|
||||||
private static final String MOBILE_DEVICE_CONFIG_XML_NAME = "mobile-config.xml";
|
private static final String MOBILE_DEVICE_CONFIG_XML_NAME = "mobile-config.xml";
|
||||||
private static final String MOBILE_DEVICE_PLUGIN_DIRECTORY = "mobile";
|
private static final String MOBILE_DEVICE_PLUGIN_DIRECTORY = "mobile";
|
||||||
|
private static final String DEVICE_MGT_PLUGIN_CONFIGS_DIRECTORY = "device-mgt-plugin-configs";
|
||||||
private MobileDeviceManagementConfig currentMobileDeviceConfig;
|
private MobileDeviceManagementConfig currentMobileDeviceConfig;
|
||||||
private static MobileDeviceConfigurationManager mobileDeviceConfigManager;
|
private static MobileDeviceConfigurationManager mobileDeviceConfigManager;
|
||||||
|
|
||||||
private final String mobileDeviceMgtConfigXMLPath =
|
private final String mobileDeviceMgtConfigXMLPath =
|
||||||
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugin-configs" + File.separator +
|
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator +
|
||||||
|
DEVICE_MGT_PLUGIN_CONFIGS_DIRECTORY +
|
||||||
|
File.separator +
|
||||||
MOBILE_DEVICE_PLUGIN_DIRECTORY + File.separator + MOBILE_DEVICE_CONFIG_XML_NAME;
|
MOBILE_DEVICE_PLUGIN_DIRECTORY + File.separator + MOBILE_DEVICE_CONFIG_XML_NAME;
|
||||||
|
|
||||||
public static MobileDeviceConfigurationManager getInstance() {
|
public static MobileDeviceConfigurationManager getInstance() {
|
||||||
|
|||||||
@ -27,14 +27,48 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface MobileDeviceDAO {
|
public interface MobileDeviceDAO {
|
||||||
|
|
||||||
MobileDevice getMobileDevice(String deviceId) throws MobileDeviceManagementDAOException;
|
/**
|
||||||
|
* Fetches a MobileDevice from MDM database.
|
||||||
|
*
|
||||||
|
* @param mblDeviceId Id of the Mobile-Device.
|
||||||
|
* @return MobileDevice corresponding to given device-id.
|
||||||
|
* @throws MobileDeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
MobileDevice getMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new MobileDevice to the MDM database.
|
||||||
|
*
|
||||||
|
* @param mobileDevice MobileDevice to be added.
|
||||||
|
* @return The status of the operation.
|
||||||
|
* @throws MobileDeviceManagementDAOException
|
||||||
|
*/
|
||||||
boolean addMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException;
|
boolean addMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates MobileDevice information in MDM database.
|
||||||
|
*
|
||||||
|
* @param mobileDevice MobileDevice to be updated.
|
||||||
|
* @return The status of the operation.
|
||||||
|
* @throws MobileDeviceManagementDAOException
|
||||||
|
*/
|
||||||
boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException;
|
boolean updateMobileDevice(MobileDevice mobileDevice) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
boolean deleteMobileDevice(String deviceId) throws MobileDeviceManagementDAOException;
|
/**
|
||||||
|
* Deletes a given MobileDevice from MDM database.
|
||||||
|
*
|
||||||
|
* @param mblDeviceId Id of MobileDevice to be deleted.
|
||||||
|
* @return The status of the operation.
|
||||||
|
* @throws MobileDeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
boolean deleteMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches all MobileDevices from MDM database.
|
||||||
|
*
|
||||||
|
* @return List of MobileDevices.
|
||||||
|
* @throws MobileDeviceManagementDAOException
|
||||||
|
*/
|
||||||
List<MobileDevice> getAllMobileDevices() throws MobileDeviceManagementDAOException;
|
List<MobileDevice> getAllMobileDevices() throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,87 +26,93 @@ import java.util.List;
|
|||||||
* This class represents the mapping between mobile device and operations.
|
* This class represents the mapping between mobile device and operations.
|
||||||
*/
|
*/
|
||||||
public interface MobileDeviceOperationMappingDAO {
|
public interface MobileDeviceOperationMappingDAO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new mobile device operation mapping to the table.
|
* Adds a new mobile device operation mapping to the table.
|
||||||
*
|
*
|
||||||
* @param deviceOperation MobileDeviceOperation object that holds data related to the MobileDeviceOperation
|
* @param mblDeviceOperationMapping MobileDeviceOperationMapping object that holds data related
|
||||||
* to be inserted.
|
* to the MobileDeviceOperationMapping to be inserted.
|
||||||
* @return The status of the operation. If the insert was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean addMobileDeviceOperationMapping(MobileDeviceOperationMapping deviceOperation)
|
boolean addMobileDeviceOperationMapping(MobileDeviceOperationMapping mblDeviceOperationMapping)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a mobile device operation mapping.
|
* Updates a MobileDeviceOperationMapping in MobileDeviceOperationMapping table.
|
||||||
*
|
*
|
||||||
* @param deviceOperation MobileDeviceOperation object that holds data has to be updated.
|
* @param mblDeviceOperation MobileDeviceOperationMapping object that holds data has to be updated.
|
||||||
* @return The status of the operation. If the update was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean updateMobileDeviceOperationMapping(MobileDeviceOperationMapping deviceOperation)
|
boolean updateMobileDeviceOperationMapping(MobileDeviceOperationMapping mblDeviceOperation)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a mobile device operation mapping to In-Progress state.
|
* Updates a MobileDeviceOperationMapping to In-Progress state in MobileDeviceOperationMapping
|
||||||
|
* table.
|
||||||
*
|
*
|
||||||
* @param deviceId Device id of the mapping to be deleted.
|
* @param mblDeviceId MobileDevice id of the mappings to be updated.
|
||||||
|
* @param operationId Operation id of the mapping to be updated.
|
||||||
|
* @return The status of the operation.
|
||||||
|
* @throws MobileDeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
boolean updateMobileDeviceOperationMappingToInProgress(String mblDeviceId, int operationId)
|
||||||
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a MobileDeviceOperationMapping to completed state in MobileDeviceOperationMapping
|
||||||
|
* table.
|
||||||
|
*
|
||||||
|
* @param mblDeviceId MobileDevice id of the mappings to be updated.
|
||||||
|
* @param operationId Operation id of the mapping to be updated.
|
||||||
|
* @return The status of the operation.
|
||||||
|
* @throws MobileDeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
boolean updateMobileDeviceOperationMappingToCompleted(String mblDeviceId, int operationId)
|
||||||
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a given MobileDeviceOperationMapping from MobileDeviceOperationMapping table.
|
||||||
|
*
|
||||||
|
* @param mblDeviceId MobileDevice id of the mappings to be deleted.
|
||||||
* @param operationId Operation id of the mapping to be deleted.
|
* @param operationId Operation id of the mapping to be deleted.
|
||||||
* @return The status of the operation. If the update was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean updateMobileDeviceOperationMappingToInProgress(String deviceId, int operationId)
|
boolean deleteMobileDeviceOperationMapping(String mblDeviceId, int operationId)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a mobile device operation mapping to completed state.
|
* Retrieves a given MobileDeviceOperationMapping object from the MobileDeviceOperationMapping
|
||||||
|
* table.
|
||||||
*
|
*
|
||||||
* @param deviceId Device id of the mapping to be deleted.
|
* @param mblDeviceId Device id of the mapping to be retrieved.
|
||||||
* @param operationId Operation id of the mapping to be deleted.
|
|
||||||
* @return The status of the operation. If the update was successful or not.
|
|
||||||
* @throws MobileDeviceManagementDAOException
|
|
||||||
*/
|
|
||||||
boolean updateMobileDeviceOperationMappingToCompleted(String deviceId, int operationId)
|
|
||||||
throws MobileDeviceManagementDAOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a given mobile device operation mapping from table.
|
|
||||||
*
|
|
||||||
* @param deviceId Device id of the mapping to be deleted.
|
|
||||||
* @param operationId Operation id of the mapping to be deleted.
|
|
||||||
* @return The status of the operation. If the deletion was successful or not.
|
|
||||||
* @throws MobileDeviceManagementDAOException
|
|
||||||
*/
|
|
||||||
boolean deleteMobileDeviceOperationMapping(String deviceId, int operationId)
|
|
||||||
throws MobileDeviceManagementDAOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves a given mobile device operation from the plugin database.
|
|
||||||
*
|
|
||||||
* @param deviceId Device id of the mapping to be retrieved.
|
|
||||||
* @param operationId Operation id of the mapping to be retrieved.
|
* @param operationId Operation id of the mapping to be retrieved.
|
||||||
* @return MobileDeviceOperation object that holds data of the device operation mapping represented by
|
* @return MobileDeviceOperation object that holds data of the device operation mapping
|
||||||
* deviceId and operationId.
|
* represented by deviceId and operationId.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
MobileDeviceOperationMapping getMobileDeviceOperationMapping(String deviceId, int operationId)
|
MobileDeviceOperationMapping getMobileDeviceOperationMapping(String mblDeviceId, int operationId)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all the of mobile device operation mappings relavent to the given mobile device.
|
* Retrieves all the of MobileDeviceOperationMappings relevant to a given mobile device.
|
||||||
*
|
*
|
||||||
* @return Device operation mapping object list.
|
* @param mblDeviceId MobileDevice id of the mappings to be retrieved.
|
||||||
|
* @return MobileDeviceOperationMapping object list.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<MobileDeviceOperationMapping> getAllMobileDeviceOperationNappingsOfDevice(String deviceId)
|
List<MobileDeviceOperationMapping> getAllMobileDeviceOperationMappingsOfDevice(String mblDeviceId)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all the pending device operation mappings of a mobiel device.
|
* Retrieves all the pending MobileDeviceOperationMappings of a mobile device.
|
||||||
*
|
*
|
||||||
* @return Device operation mapping object list.
|
* @param mblDeviceId MobileDevice id of the mappings to be retrieved.
|
||||||
|
* @return MobileDeviceOperationMapping object list.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<MobileDeviceOperationMapping> getAllPendingOperationMappingsOfMobileDevice(String deviceId)
|
List<MobileDeviceOperationMapping> getAllPendingOperationMappingsOfMobileDevice(String mblDeviceId)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,73 +29,73 @@ import java.util.List;
|
|||||||
public interface MobileFeatureDAO {
|
public interface MobileFeatureDAO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new feature to feature table.
|
* Adds a new MobileFeature to Mobile-Feature table.
|
||||||
*
|
*
|
||||||
* @param mobileFeature Feature object that holds data related to the feature to be inserted.
|
* @param mobileFeature MobileFeature object that holds data related to the feature to be inserted.
|
||||||
* @return The status of the operation. If the insert was successful or not.
|
* @return The id of inserted MobileFeature.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean addMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
|
int addMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a feature in the feature table.
|
* Updates a MobileFeature in Mobile-Feature table.
|
||||||
*
|
*
|
||||||
* @param mobileFeature Feature object that holds data has to be updated.
|
* @param mobileFeature MobileFeature object that holds data has to be updated.
|
||||||
* @return The status of the operation. If the update was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean updateMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
|
boolean updateMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a feature from feature table when the feature id is given.
|
* Deletes a MobileFeature from Mobile-Feature table when the feature id is given.
|
||||||
*
|
*
|
||||||
* @param featureId Feature id of the feature to be deleted.
|
* @param mblFeatureId MobileFeature id of the MobileFeature to be deleted.
|
||||||
* @return The status of the operation. If the operationId was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean deleteMobileFeatureById(int featureId) throws MobileDeviceManagementDAOException;
|
boolean deleteMobileFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a feature from feature table when the feature code is given.
|
* Deletes a MobileFeature from Mobile-Feature table when the feature code is given.
|
||||||
*
|
*
|
||||||
* @param featureCode Feature code of the feature to be deleted.
|
* @param mblFeatureCode MobileFeature code of the feature to be deleted.
|
||||||
* @return The status of the operation. If the operationId was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean deleteMobileFeatureByCode(String featureCode) throws MobileDeviceManagementDAOException;
|
boolean deleteMobileFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a given feature from feature table when the feature id is given.
|
* Retrieves a given MobileFeature from Mobile-Feature table when the feature id is given.
|
||||||
*
|
*
|
||||||
* @param featureId Feature id of the feature to be retrieved.
|
* @param mblFeatureId Feature id of the feature to be retrieved.
|
||||||
* @return Feature 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 featureId) throws MobileDeviceManagementDAOException;
|
MobileFeature getMobileFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a given feature from feature table when the feature code is given.
|
* Retrieves a given MobileFeature from Mobile-Feature table when the feature code is given.
|
||||||
*
|
*
|
||||||
* @param featureCode Feature code of the feature to be retrieved.
|
* @param mblFeatureCode Feature code of the feature to be retrieved.
|
||||||
* @return Feature 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 featureCode) throws MobileDeviceManagementDAOException;
|
MobileFeature getMobileFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all the features from plugin specific database.
|
* Retrieves all MobileFeatures of a MobileDevice type from Mobile-Feature table.
|
||||||
*
|
*
|
||||||
* @return Feature object list.
|
* @param deviceType MobileDevice type of the MobileFeatures to be retrieved
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @return MobileFeature object list.
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve all the features from plugin specific database for a Device Type.
|
|
||||||
* @param deviceType - Device type.
|
|
||||||
* @return Feature object list.
|
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<MobileFeature> getMobileFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException;
|
List<MobileFeature> getMobileFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve all the MobileFeatures from Mobile-Feature table.
|
||||||
|
*
|
||||||
|
* @return MobileFeature object list.
|
||||||
|
* @throws MobileDeviceManagementDAOException
|
||||||
|
*/
|
||||||
List<MobileFeature> getAllMobileFeatures() throws MobileDeviceManagementDAOException;
|
List<MobileFeature> getAllMobileFeatures() throws MobileDeviceManagementDAOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,56 +23,72 @@ import org.wso2.carbon.device.mgt.mobile.dto.MobileFeatureProperty;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the key operations associated with persisting mobile feature property related
|
* This class represents the key operations associated with persisting mobile feature property
|
||||||
* information.
|
* related information.
|
||||||
*/
|
*/
|
||||||
public interface MobileFeaturePropertyDAO {
|
public interface MobileFeaturePropertyDAO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new feature property to feature property table.
|
* Add a new MobileFeatureProperty to MobileFeatureProperty table.
|
||||||
*
|
*
|
||||||
* @param mobileFeatureProperty Feature property object that holds data related to the feature property to be inserted.
|
* @param mblFeatureProperty MobileFeatureProperty object that holds data related to the feature
|
||||||
* @return The status of the operation. If the insert was successful or not.
|
* property to be inserted.
|
||||||
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean addMobileFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
|
boolean addMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a feature property in the feature property table.
|
* Updates a MobileFeatureProperty in the MobileFeatureProperty table.
|
||||||
*
|
*
|
||||||
* @param mobileFeatureProperty Feature property object that holds data has to be updated.
|
* @param mblFeatureProperty MobileFeatureProperty object that holds data has to be updated.
|
||||||
* @return The status of the operation. If the update was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean updateMobileFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
|
boolean updateMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a given feature property from feature property table.
|
* Deletes a given MobileFeatureProperty from MobileFeatureProperty table.
|
||||||
*
|
*
|
||||||
* @param property Property of the feature property to be deleted.
|
* @param property Property of the MobileFeatureProperty to be deleted.
|
||||||
* @return The status of the operation. If the operationId was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean deleteMobileFeatureProperty(String property) throws MobileDeviceManagementDAOException;
|
boolean deleteMobileFeatureProperty(String property) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a given feature property from feature property table.
|
* Deletes MobileFeatureProperties of a given feature from MobileFeatureProperty table.
|
||||||
*
|
*
|
||||||
* @param property Property of the feature property to be retrieved.
|
* @param mblFeatureId Feature-id of the MobileFeature corresponding properties should be deleted.
|
||||||
* @return Feature property object that holds data of the feature property represented by propertyId.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
MobileFeatureProperty getMobileFeatureProperty(String property) throws MobileDeviceManagementDAOException;
|
boolean deleteMobileFeaturePropertiesOfFeature(Integer mblFeatureId)
|
||||||
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a list of feature property corresponds to a feature id .
|
* Retrieves a given MobileFeatureProperty from MobileFeatureProperty table.
|
||||||
*
|
*
|
||||||
* @param featureId feature id of the feature property to be retrieved.
|
* @param property Property of the feature property to be retrieved.
|
||||||
* @return Feature property object that holds data of the feature property represented by propertyId.
|
* @return MobileFeatureProperty object that holds data of the feature property represented by
|
||||||
|
* property.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<MobileFeatureProperty> getFeaturePropertyOfFeature(Integer featureId)
|
MobileFeatureProperty getMobileFeatureProperty(String property)
|
||||||
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a list of MobileFeatureProperties corresponds to a given feature id from
|
||||||
|
* MobileFeatureProperty table.
|
||||||
|
*
|
||||||
|
* @param mblFeatureId feature id of the MobileFeatureProperties to be retrieved.
|
||||||
|
* @return List of MobileFeatureProperty objects that holds data of the MobileFeatureProperties
|
||||||
|
* represented by featureId.
|
||||||
|
* @throws MobileDeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
List<MobileFeatureProperty> getFeaturePropertiesOfFeature(Integer mblFeatureId)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,35 +27,36 @@ import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
|
|||||||
public interface MobileOperationDAO {
|
public interface MobileOperationDAO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new Mobile operation to plugin operation table.
|
* Adds a new Mobile operation to the MobileOperation table.
|
||||||
* @param operation Operation object that holds data related to the operation to be inserted.
|
* @param mblOperation MobileOperation object that holds data related to the operation to be
|
||||||
* @return The last inserted Id is returned, if the insertion was unsuccessful -1 is returned.
|
* inserted.
|
||||||
|
* @return The id of the inserted record, if the insertion was unsuccessful -1 is returned.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
int addMobileOperation(MobileOperation operation) throws MobileDeviceManagementDAOException;
|
int addMobileOperation(MobileOperation mblOperation) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a Mobile operation in the operation table.
|
* Updates a Mobile operation in the MobileOperation table.
|
||||||
* @param operation Operation object that holds data has to be updated.
|
* @param mblOperation MobileOperation object that holds data has to be updated.
|
||||||
* @return The status of the operation. If the update was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean updateMobileOperation(MobileOperation operation) throws MobileDeviceManagementDAOException;
|
boolean updateMobileOperation(MobileOperation mblOperation) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a given Mobile operation from plugin database.
|
* Deletes a given MobileOperation from MobileOperation table.
|
||||||
* @param operationId Operation code of the operation to be deleted.
|
* @param mblOperationId Operation code of the MobileOperation to be deleted.
|
||||||
* @return The status of the operation. If the operationId was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean deleteMobileOperation(int operationId) throws MobileDeviceManagementDAOException;
|
boolean deleteMobileOperation(int mblOperationId) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a given Mobile operation from plugin database.
|
* Retrieve a MobileOperation from MobileOperation table.
|
||||||
* @param operationId Operation id of the operation to be retrieved.
|
* @param mblOperationId Operation id of the MobileOperation to be retrieved.
|
||||||
* @return Operation object that holds data of the feature represented by operationId.
|
* @return MobileOperation object that holds data of MobileOperation represented by operationId.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
MobileOperation getMobileOperation(int operationId) throws MobileDeviceManagementDAOException;
|
MobileOperation getMobileOperation(int mblOperationId) throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,60 +23,65 @@ import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the key operations associated with persisting mobile operation property related
|
*
|
||||||
* information.
|
* This class represents the key operations associated with persisting mobile operation property
|
||||||
|
* related information.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public interface MobileOperationPropertyDAO {
|
public interface MobileOperationPropertyDAO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new mapping to plugin operation property table.
|
* Add a new MobileOperationProperty to MobileOperationProperty table.
|
||||||
*
|
*
|
||||||
* @param operationProperty OperationProperty object that holds data related to the operation
|
* @param mblOperationProperty MobileOperationProperty object that holds data related to the
|
||||||
* property to be inserted.
|
* operation property to be inserted.
|
||||||
* @return The status of the operation. If the insert was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean addMobileOperationProperty(MobileOperationProperty operationProperty)
|
boolean addMobileOperationProperty(MobileOperationProperty mblOperationProperty)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a feature in the feature table.
|
* Update a MobileOperationProperty in the MobileOperationProperty table.
|
||||||
*
|
*
|
||||||
* @param operationProperty DeviceOperation object that holds data has to be updated.
|
* @param mblOperationProperty MobileOperationProperty object that holds data has to be updated.
|
||||||
* @return The status of the operation. If the update was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean updateMobileOperationProperty(MobileOperationProperty operationProperty)
|
boolean updateMobileOperationProperty(MobileOperationProperty mblOperationProperty)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes mobile operation properties of a given operation id from the plugin database.
|
* Deletes MobileOperationProperties of a given operation id from the MobileOperationProperty
|
||||||
|
* table.
|
||||||
*
|
*
|
||||||
* @param operationId Operation id of the mapping to be deleted.
|
* @param mblOperationId Operation id of the MobileOperationProperty to be deleted.
|
||||||
* @return The status of the operation. If the deletion was successful or not.
|
* @return The status of the operation.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
boolean deleteMobileOperationProperties(int operationId)
|
boolean deleteMobileOperationProperties(int mblOperationId)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a given mobile operation property from plugin database.
|
* Retrieve a given MobileOperationProperty from MobileOperationProperty table.
|
||||||
*
|
*
|
||||||
* @param operationId Operation id of the mapping to be retrieved.
|
* @param mblOperationId Operation id of the mapping to be retrieved.
|
||||||
* @param property Property of the mapping to be retrieved.
|
* @param property Property of the mapping to be retrieved.
|
||||||
* @return DeviceOperation object that holds data of the device operation mapping represented by
|
* @return MobileOperationProperty object that holds data of the MobileOperationProperty
|
||||||
* deviceId and operationId.
|
* represented by mblOperationId and property.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
MobileOperationProperty getMobileOperationProperty(int operationId, String property)
|
MobileOperationProperty getMobileOperationProperty(int mblOperationId, String property)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all the mobile operation properties related to the a operation id.
|
* Retrieve all the MobileOperationProperties related to the a operation id from
|
||||||
|
* MobileOperationProperty table.
|
||||||
*
|
*
|
||||||
* @param operationId Operation id of the mapping to be retrieved.
|
* @param mblOperationId Operation id of the MobileOperationProperty to be retrieved.
|
||||||
* @return Device operation mapping object list.
|
* @return List of MobileOperationProperty objects.
|
||||||
* @throws MobileDeviceManagementDAOException
|
* @throws MobileDeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<MobileOperationProperty> getAllMobileOperationPropertiesOfOperation(int operationId)
|
List<MobileOperationProperty> getAllMobileOperationPropertiesOfOperation(int mblOperationId)
|
||||||
throws MobileDeviceManagementDAOException;
|
throws MobileDeviceManagementDAOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,18 +46,19 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobileDevice getMobileDevice(String deviceId) throws MobileDeviceManagementDAOException {
|
public MobileDevice getMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
MobileDevice mobileDevice = null;
|
MobileDevice mobileDevice = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT * FROM MBL_DEVICE WHERE MOBILE_DEVICE_ID = ?";
|
"SELECT MOBILE_DEVICE_ID, REG_ID, IMEI, IMSI, OS_VERSION,DEVICE_MODEL, VENDOR, " +
|
||||||
|
"LATITUDE, LONGITUDE FROM MBL_DEVICE WHERE MOBILE_DEVICE_ID = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setString(1, deviceId);
|
stmt.setString(1, mblDeviceId);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
mobileDevice = new MobileDevice();
|
mobileDevice = new MobileDevice();
|
||||||
mobileDevice.setMobileDeviceId(resultSet.getString(1));
|
mobileDevice.setMobileDeviceId(resultSet.getString(1));
|
||||||
mobileDevice.setRegId(resultSet.getString(2));
|
mobileDevice.setRegId(resultSet.getString(2));
|
||||||
@ -68,11 +69,13 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
|
|||||||
mobileDevice.setVendor(resultSet.getString(7));
|
mobileDevice.setVendor(resultSet.getString(7));
|
||||||
mobileDevice.setLatitude(resultSet.getString(8));
|
mobileDevice.setLatitude(resultSet.getString(8));
|
||||||
mobileDevice.setLongitude(resultSet.getString(9));
|
mobileDevice.setLongitude(resultSet.getString(9));
|
||||||
break;
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Mobile device " + mblDeviceId + " data has fetched from MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while fetching mobile device '" +
|
String msg = "Error occurred while fetching mobile device '" +
|
||||||
deviceId + "'";
|
mblDeviceId + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -106,6 +109,10 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
|
|||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Mobile device " + mobileDevice.getMobileDeviceId() + " data has added" +
|
||||||
|
" to the MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while adding the mobile device '" +
|
String msg = "Error occurred while adding the mobile device '" +
|
||||||
@ -128,7 +135,8 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
|
|||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String updateDBQuery =
|
String updateDBQuery =
|
||||||
"UPDATE MBL_DEVICE SET REG_ID = ?, IMEI = ?, IMSI = ?, OS_VERSION = ?," +
|
"UPDATE MBL_DEVICE SET REG_ID = ?, IMEI = ?, IMSI = ?, OS_VERSION = ?," +
|
||||||
"DEVICE_MODEL = ?, VENDOR = ? , LATITUDE = ?, LONGITUDE = ? WHERE MOBILE_DEVICE_ID = ?";
|
"DEVICE_MODEL = ?, VENDOR = ? , LATITUDE = ?, LONGITUDE = ? " +
|
||||||
|
"WHERE MOBILE_DEVICE_ID = ?";
|
||||||
stmt = conn.prepareStatement(updateDBQuery);
|
stmt = conn.prepareStatement(updateDBQuery);
|
||||||
stmt.setString(1, mobileDevice.getRegId());
|
stmt.setString(1, mobileDevice.getRegId());
|
||||||
stmt.setString(2, mobileDevice.getImei());
|
stmt.setString(2, mobileDevice.getImei());
|
||||||
@ -142,6 +150,10 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
|
|||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Mobile device " + mobileDevice.getMobileDeviceId() + " data has" +
|
||||||
|
" updated");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while updating the mobile device '" +
|
String msg = "Error occurred while updating the mobile device '" +
|
||||||
@ -155,7 +167,7 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteMobileDevice(String deviceId) throws MobileDeviceManagementDAOException {
|
public boolean deleteMobileDevice(String mblDeviceId) throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -164,13 +176,17 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
|
|||||||
String deleteDBQuery =
|
String deleteDBQuery =
|
||||||
"DELETE FROM MBL_DEVICE WHERE MOBILE_DEVICE_ID = ?";
|
"DELETE FROM MBL_DEVICE WHERE MOBILE_DEVICE_ID = ?";
|
||||||
stmt = conn.prepareStatement(deleteDBQuery);
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
stmt.setString(1,deviceId);
|
stmt.setString(1, mblDeviceId);
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Mobile device " + mblDeviceId + " data has deleted" +
|
||||||
|
" from the MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while deleting mobile device " + deviceId;
|
String msg = "Error occurred while deleting mobile device " + mblDeviceId;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -188,7 +204,8 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT * FROM MBL_DEVICE";
|
"SELECT MOBILE_DEVICE_ID, REG_ID, IMEI, IMSI, OS_VERSION,DEVICE_MODEL, VENDOR," +
|
||||||
|
"LATITUDE, LONGITUDE FROM MBL_DEVICE";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
@ -204,6 +221,9 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
|
|||||||
mobileDevice.setLongitude(resultSet.getString(9));
|
mobileDevice.setLongitude(resultSet.getString(9));
|
||||||
mobileDevices.add(mobileDevice);
|
mobileDevices.add(mobileDevice);
|
||||||
}
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("All Mobile device details have fetched from MDM database.");
|
||||||
|
}
|
||||||
return mobileDevices;
|
return mobileDevices;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while fetching all mobile device data'";
|
String msg = "Error occurred while fetching all mobile device data'";
|
||||||
|
|||||||
@ -20,8 +20,8 @@ package org.wso2.carbon.device.mgt.mobile.dao.impl;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceOperationMappingDAO;
|
|
||||||
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.MobileDeviceOperationMappingDAO;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping;
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping;
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addMobileDeviceOperationMapping(MobileDeviceOperationMapping deviceOperation)
|
public boolean addMobileDeviceOperationMapping(MobileDeviceOperationMapping mblDeviceOperationMapping)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -59,21 +59,25 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
"RECEIVED_DATE, STATUS) VALUES (?, ?, ?, ?, ?)";
|
"RECEIVED_DATE, STATUS) VALUES (?, ?, ?, ?, ?)";
|
||||||
|
|
||||||
stmt = conn.prepareStatement(createDBQuery);
|
stmt = conn.prepareStatement(createDBQuery);
|
||||||
stmt.setString(1, deviceOperation.getDeviceId());
|
stmt.setString(1, mblDeviceOperationMapping.getDeviceId());
|
||||||
stmt.setLong(2, deviceOperation.getOperationId());
|
stmt.setLong(2, mblDeviceOperationMapping.getOperationId());
|
||||||
stmt.setLong(3, deviceOperation.getSentDate());
|
stmt.setLong(3, mblDeviceOperationMapping.getSentDate());
|
||||||
stmt.setLong(4, deviceOperation.getReceivedDate());
|
stmt.setLong(4, mblDeviceOperationMapping.getReceivedDate());
|
||||||
stmt.setString(5, deviceOperation.getStatus().name());
|
stmt.setString(5, mblDeviceOperationMapping.getStatus().name());
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Added a MobileDevice-Mapping DeviceId : " + mblDeviceOperationMapping
|
||||||
|
.getDeviceId() + ", " +
|
||||||
|
"OperationId : " + mblDeviceOperationMapping.getOperationId() + " to the MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while adding device id - '" +
|
String msg = "Error occurred while adding device id - '" +
|
||||||
deviceOperation.getDeviceId() + " and operation id - " +
|
mblDeviceOperationMapping.getDeviceId() + " and operation id - " +
|
||||||
deviceOperation.getOperationId() +
|
mblDeviceOperationMapping.getOperationId() +
|
||||||
" to mapping table MBL_DEVICE_OPERATION";
|
" to mapping table MBL_DEVICE_OPERATION";
|
||||||
;
|
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -83,7 +87,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateMobileDeviceOperationMapping(MobileDeviceOperationMapping deviceOperation)
|
public boolean updateMobileDeviceOperationMapping(MobileDeviceOperationMapping mblDeviceOperation)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -91,22 +95,26 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String updateDBQuery =
|
String updateDBQuery =
|
||||||
"UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ?, STATUS = ? " +
|
"UPDATE MBL_DEVICE_OPERATION_MAPPING SET SENT_DATE = ?, RECEIVED_DATE = ?, " +
|
||||||
"WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
"STATUS = ? WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
||||||
stmt = conn.prepareStatement(updateDBQuery);
|
stmt = conn.prepareStatement(updateDBQuery);
|
||||||
stmt.setLong(1, deviceOperation.getSentDate());
|
stmt.setLong(1, mblDeviceOperation.getSentDate());
|
||||||
stmt.setLong(2, deviceOperation.getReceivedDate());
|
stmt.setLong(2, mblDeviceOperation.getReceivedDate());
|
||||||
stmt.setString(3, deviceOperation.getStatus().name());
|
stmt.setString(3, mblDeviceOperation.getStatus().name());
|
||||||
stmt.setString(4, deviceOperation.getDeviceId());
|
stmt.setString(4, mblDeviceOperation.getDeviceId());
|
||||||
stmt.setInt(5, deviceOperation.getOperationId());
|
stmt.setInt(5, mblDeviceOperation.getOperationId());
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Updated MobileDevice-Mapping DeviceId : " + mblDeviceOperation.getDeviceId() + " , " +
|
||||||
|
"OperationId : " + mblDeviceOperation.getOperationId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while updating device id - '" +
|
String msg = "Error occurred while updating device id - '" +
|
||||||
deviceOperation.getDeviceId() + " and operation id - " +
|
mblDeviceOperation.getDeviceId() + " and operation id - " +
|
||||||
deviceOperation.getOperationId() + " in table MBL_DEVICE_OPERATION";
|
mblDeviceOperation.getOperationId() + " in table MBL_DEVICE_OPERATION";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -116,7 +124,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateMobileDeviceOperationMappingToInProgress(String deviceId, int operationId)
|
public boolean updateMobileDeviceOperationMappingToInProgress(String mblDeviceId, int operationId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -129,16 +137,20 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
stmt = conn.prepareStatement(updateDBQuery);
|
stmt = conn.prepareStatement(updateDBQuery);
|
||||||
stmt.setLong(1, new Date().getTime());
|
stmt.setLong(1, new Date().getTime());
|
||||||
stmt.setString(2, MobileDeviceOperationMapping.Status.INPROGRESS.name());
|
stmt.setString(2, MobileDeviceOperationMapping.Status.INPROGRESS.name());
|
||||||
stmt.setString(3, deviceId);
|
stmt.setString(3, mblDeviceId);
|
||||||
stmt.setInt(4, operationId);
|
stmt.setInt(4, operationId);
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Updated status of MobileDevice-Mapping DeviceId : " + mblDeviceId + " , " +
|
||||||
|
"OperationId : " + operationId + " to In-Progress state");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg =
|
String msg =
|
||||||
"Error occurred while updating the Status of operation to in-progress of device id - '" +
|
"Error occurred while updating the Status of operation to in-progress of device id - '" +
|
||||||
deviceId + " and operation id - " +
|
mblDeviceId + " and operation id - " +
|
||||||
operationId + " in table MBL_DEVICE_OPERATION";
|
operationId + " in table MBL_DEVICE_OPERATION";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
@ -149,7 +161,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateMobileDeviceOperationMappingToCompleted(String deviceId,
|
public boolean updateMobileDeviceOperationMappingToCompleted(String mblDeviceId,
|
||||||
int operationId)
|
int operationId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
@ -163,16 +175,20 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
stmt = conn.prepareStatement(updateDBQuery);
|
stmt = conn.prepareStatement(updateDBQuery);
|
||||||
stmt.setLong(1, new Date().getTime());
|
stmt.setLong(1, new Date().getTime());
|
||||||
stmt.setString(2, MobileDeviceOperationMapping.Status.COMPLETED.name());
|
stmt.setString(2, MobileDeviceOperationMapping.Status.COMPLETED.name());
|
||||||
stmt.setString(3, deviceId);
|
stmt.setString(3, mblDeviceId);
|
||||||
stmt.setInt(4, operationId);
|
stmt.setInt(4, operationId);
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Updated status of MobileDevice-Mapping DeviceId : " + mblDeviceId + " , " +
|
||||||
|
"OperationId : " + operationId + " to Completed state");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg =
|
String msg =
|
||||||
"Error occurred while updating the Status of operation to completed of device id - '" +
|
"Error occurred while updating the Status of operation to completed of device id - '" +
|
||||||
deviceId + " and operation id - " +
|
mblDeviceId + " and operation id - " +
|
||||||
operationId + " in table MBL_DEVICE_OPERATION";
|
operationId + " in table MBL_DEVICE_OPERATION";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
@ -183,7 +199,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteMobileDeviceOperationMapping(String deviceId, int operationId)
|
public boolean deleteMobileDeviceOperationMapping(String mblDeviceId, int operationId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -191,18 +207,23 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String deleteDBQuery =
|
String deleteDBQuery =
|
||||||
"DELETE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID=?";
|
"DELETE FROM MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND " +
|
||||||
|
"OPERATION_ID = ?";
|
||||||
stmt = conn.prepareStatement(deleteDBQuery);
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
stmt.setString(1, deviceId);
|
stmt.setString(1, mblDeviceId);
|
||||||
stmt.setInt(2, operationId);
|
stmt.setInt(2, operationId);
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Deleted MobileDevice-Mapping DeviceId : " + mblDeviceId + " , " +
|
||||||
|
"OperationId : " + operationId + "from MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg =
|
String msg =
|
||||||
"Error occurred while deleting the table entry MBL_DEVICE_OPERATION with " +
|
"Error occurred while deleting the table entry MBL_DEVICE_OPERATION with " +
|
||||||
" device id - '" + deviceId + " and operation id - " + operationId;
|
" device id - '" + mblDeviceId + " and operation id - " + operationId;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -212,7 +233,7 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobileDeviceOperationMapping getMobileDeviceOperationMapping(String deviceId,
|
public MobileDeviceOperationMapping getMobileDeviceOperationMapping(String mblDeviceId,
|
||||||
int operationId)
|
int operationId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -224,22 +245,25 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " +
|
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " +
|
||||||
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setString(1, deviceId);
|
stmt.setString(1, mblDeviceId);
|
||||||
stmt.setInt(2, operationId);
|
stmt.setInt(2, operationId);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
mblDeviceOperation = new MobileDeviceOperationMapping();
|
mblDeviceOperation = new MobileDeviceOperationMapping();
|
||||||
mblDeviceOperation.setDeviceId(resultSet.getString(1));
|
mblDeviceOperation.setDeviceId(resultSet.getString(1));
|
||||||
mblDeviceOperation.setOperationId(resultSet.getInt(2));
|
mblDeviceOperation.setOperationId(resultSet.getInt(2));
|
||||||
mblDeviceOperation.setSentDate(resultSet.getInt(3));
|
mblDeviceOperation.setSentDate(resultSet.getInt(3));
|
||||||
mblDeviceOperation.setReceivedDate(resultSet.getInt(4));
|
mblDeviceOperation.setReceivedDate(resultSet.getInt(4));
|
||||||
mblDeviceOperation.setStatus(resultSet.getString(5));
|
mblDeviceOperation.setStatus(resultSet.getString(5));
|
||||||
break;
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetched MobileDevice-Mapping of DeviceId : " + mblDeviceId + " , " +
|
||||||
|
"OperationId : " + operationId );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg =
|
String msg =
|
||||||
"Error occurred while fetching table MBL_DEVICE_OPERATION entry with device id - '" +
|
"Error occurred while fetching table MBL_DEVICE_OPERATION entry with device id - '" +
|
||||||
deviceId + " and operation id - " + operationId;
|
mblDeviceId + " and operation id - " + operationId;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -249,20 +273,21 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MobileDeviceOperationMapping> getAllMobileDeviceOperationNappingsOfDevice(
|
public List<MobileDeviceOperationMapping> getAllMobileDeviceOperationMappingsOfDevice(
|
||||||
String deviceId)
|
String mblDeviceId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
MobileDeviceOperationMapping mblDeviceOperation = null;
|
MobileDeviceOperationMapping mblDeviceOperation;
|
||||||
List<MobileDeviceOperationMapping> mblDeviceOperations = new ArrayList<MobileDeviceOperationMapping>();
|
List<MobileDeviceOperationMapping> mblDeviceOperations =
|
||||||
|
new ArrayList<MobileDeviceOperationMapping>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " +
|
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " +
|
||||||
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?";
|
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setString(1, deviceId);
|
stmt.setString(1, mblDeviceId);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
mblDeviceOperation = new MobileDeviceOperationMapping();
|
mblDeviceOperation = new MobileDeviceOperationMapping();
|
||||||
@ -273,10 +298,13 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
mblDeviceOperation.setStatus(resultSet.getString(5));
|
mblDeviceOperation.setStatus(resultSet.getString(5));
|
||||||
mblDeviceOperations.add(mblDeviceOperation);
|
mblDeviceOperations.add(mblDeviceOperation);
|
||||||
}
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetched all MobileDevice-Mappings of DeviceId : " + mblDeviceId);
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg =
|
String msg =
|
||||||
"Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of " +
|
"Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of " +
|
||||||
"device id - '" + deviceId;
|
"device id - '" + mblDeviceId;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -287,20 +315,22 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MobileDeviceOperationMapping> getAllPendingOperationMappingsOfMobileDevice(
|
public List<MobileDeviceOperationMapping> getAllPendingOperationMappingsOfMobileDevice(
|
||||||
String deviceId)
|
String mblDeviceId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
MobileDeviceOperationMapping mblDeviceOperation = null;
|
MobileDeviceOperationMapping mblDeviceOperation = null;
|
||||||
List<MobileDeviceOperationMapping> mblDeviceOperations = new ArrayList<MobileDeviceOperationMapping>();
|
List<MobileDeviceOperationMapping> mblDeviceOperations =
|
||||||
|
new ArrayList<MobileDeviceOperationMapping>();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM" +
|
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM" +
|
||||||
" MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND STATUS = 'NEW'";
|
" MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND STATUS = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setString(1, deviceId);
|
stmt.setString(1, mblDeviceId);
|
||||||
|
stmt.setString(2, MobileDeviceOperationMapping.Status.NEW.name());
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
mblDeviceOperation = new MobileDeviceOperationMapping();
|
mblDeviceOperation = new MobileDeviceOperationMapping();
|
||||||
@ -311,10 +341,13 @@ public class MobileDeviceOperationMappingDAOImpl implements MobileDeviceOperatio
|
|||||||
mblDeviceOperation.setStatus(resultSet.getString(5));
|
mblDeviceOperation.setStatus(resultSet.getString(5));
|
||||||
mblDeviceOperations.add(mblDeviceOperation);
|
mblDeviceOperations.add(mblDeviceOperation);
|
||||||
}
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetched all pending MobileDevice-Mappings of DeviceId : " + mblDeviceId);
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg =
|
String msg =
|
||||||
"Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of" +
|
"Error occurred while fetching mapping table MBL_DEVICE_OPERATION entries of" +
|
||||||
" device id - '" + deviceId;
|
" device id - '" + mblDeviceId;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@ -46,8 +46,9 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addMobileFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
|
public int addMobileFeature(MobileFeature mobileFeature)
|
||||||
boolean status = false;
|
throws MobileDeviceManagementDAOException {
|
||||||
|
int status = 0;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
@ -62,7 +63,14 @@ 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) {
|
||||||
status = true;
|
ResultSet rs = stmt.getGeneratedKeys();
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
|
status = rs.getInt(1);
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Added a new MobileFeature " + mobileFeature.getCode() + " to the" +
|
||||||
|
" MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while adding feature code - '" +
|
String msg = "Error occurred while adding feature code - '" +
|
||||||
@ -84,7 +92,8 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String updateDBQuery =
|
String updateDBQuery =
|
||||||
"UPDATE MBL_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ?, DEVICE_TYPE = ? WHERE FEATURE_ID = ?";
|
"UPDATE MBL_FEATURE SET CODE = ?, NAME = ?, DESCRIPTION = ?, DEVICE_TYPE = ?" +
|
||||||
|
" WHERE FEATURE_ID = ?";
|
||||||
stmt = conn.prepareStatement(updateDBQuery);
|
stmt = conn.prepareStatement(updateDBQuery);
|
||||||
stmt.setString(1, mobileFeature.getCode());
|
stmt.setString(1, mobileFeature.getCode());
|
||||||
stmt.setString(2, mobileFeature.getName());
|
stmt.setString(2, mobileFeature.getName());
|
||||||
@ -94,6 +103,9 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Updated MobileFeature " + mobileFeature.getCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while updating the feature with feature code - '" +
|
String msg = "Error occurred while updating the feature with feature code - '" +
|
||||||
@ -107,7 +119,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteMobileFeatureByCode(String featureCode)
|
public boolean deleteMobileFeatureByCode(String mblFeatureCode)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -117,13 +129,17 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
String deleteDBQuery =
|
String deleteDBQuery =
|
||||||
"DELETE FROM MBL_FEATURE WHERE CODE = ?";
|
"DELETE FROM MBL_FEATURE WHERE CODE = ?";
|
||||||
stmt = conn.prepareStatement(deleteDBQuery);
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
stmt.setString(1, featureCode);
|
stmt.setString(1, mblFeatureCode);
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Deleted MobileFeature code " + mblFeatureCode + " from the" +
|
||||||
|
" MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while deleting feature with code - " + featureCode;
|
String msg = "Error occurred while deleting feature with code - " + mblFeatureCode;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -133,7 +149,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteMobileFeatureById(int featureId)
|
public boolean deleteMobileFeatureById(int mblFeatureId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -143,13 +159,17 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
String deleteDBQuery =
|
String deleteDBQuery =
|
||||||
"DELETE FROM MBL_FEATURE WHERE FEATURE_ID = ?";
|
"DELETE FROM MBL_FEATURE WHERE FEATURE_ID = ?";
|
||||||
stmt = conn.prepareStatement(deleteDBQuery);
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
stmt.setInt(1, featureId);
|
stmt.setInt(1, mblFeatureId);
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Deleted MobileFeature id " + mblFeatureId + " from the" +
|
||||||
|
" MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while deleting feature with id - " + featureId;
|
String msg = "Error occurred while deleting feature with id - " + mblFeatureId;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -159,7 +179,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobileFeature getMobileFeatureByCode(String featureCode)
|
public MobileFeature getMobileFeatureByCode(String mblFeatureCode)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -167,22 +187,26 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT FEATURE_ID,DEVICE_TYPE, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = ?";
|
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE " +
|
||||||
|
"WHERE CODE = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setString(1, featureCode);
|
stmt.setString(1, mblFeatureCode);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
mobileFeature = new MobileFeature();
|
mobileFeature = new MobileFeature();
|
||||||
mobileFeature.setId(resultSet.getInt(1));
|
mobileFeature.setId(resultSet.getInt(1));
|
||||||
mobileFeature.setDeviceType(resultSet.getString(2));
|
mobileFeature.setCode(resultSet.getString(2));
|
||||||
mobileFeature.setCode(resultSet.getString(3));
|
mobileFeature.setName(resultSet.getString(3));
|
||||||
mobileFeature.setName(resultSet.getString(4));
|
mobileFeature.setDescription(resultSet.getString(4));
|
||||||
mobileFeature.setDescription(resultSet.getString(5));
|
mobileFeature.setDeviceType(resultSet.getString(5));
|
||||||
break;
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetched MobileFeature " + mblFeatureCode + " from the" +
|
||||||
|
" MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while fetching feature code - '" +
|
String msg = "Error occurred while fetching feature code - '" +
|
||||||
featureCode + "'";
|
mblFeatureCode + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -192,7 +216,7 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobileFeature getMobileFeatureById(int featureID)
|
public MobileFeature getMobileFeatureById(int mblFeatureId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -200,22 +224,26 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT FEATURE_ID,DEVICE_TYPE, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE FEATURE_ID = ?";
|
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE" +
|
||||||
|
" WHERE FEATURE_ID = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setInt(1, featureID);
|
stmt.setInt(1, mblFeatureId);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
mobileFeature = new MobileFeature();
|
mobileFeature = new MobileFeature();
|
||||||
mobileFeature.setId(resultSet.getInt(1));
|
mobileFeature.setId(resultSet.getInt(1));
|
||||||
mobileFeature.setDeviceType(resultSet.getString(2));
|
mobileFeature.setCode(resultSet.getString(2));
|
||||||
mobileFeature.setCode(resultSet.getString(3));
|
mobileFeature.setName(resultSet.getString(3));
|
||||||
mobileFeature.setName(resultSet.getString(4));
|
mobileFeature.setDescription(resultSet.getString(4));
|
||||||
mobileFeature.setDescription(resultSet.getString(5));
|
mobileFeature.setDeviceType(resultSet.getString(5));
|
||||||
break;
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetched MobileFeatureId" + mblFeatureId + " from the" +
|
||||||
|
" MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while fetching feature id - '" +
|
String msg = "Error occurred while fetching feature id - '" +
|
||||||
featureID + "'";
|
mblFeatureId + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -233,18 +261,21 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT FEATURE_ID,DEVICE_TYPE, CODE, NAME, DESCRIPTION FROM MBL_FEATURE";
|
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
mobileFeature = new MobileFeature();
|
mobileFeature = new MobileFeature();
|
||||||
mobileFeature.setId(resultSet.getInt(1));
|
mobileFeature.setId(resultSet.getInt(1));
|
||||||
mobileFeature.setDeviceType(resultSet.getString(2));
|
mobileFeature.setCode(resultSet.getString(2));
|
||||||
mobileFeature.setCode(resultSet.getString(3));
|
mobileFeature.setName(resultSet.getString(3));
|
||||||
mobileFeature.setName(resultSet.getString(4));
|
mobileFeature.setDescription(resultSet.getString(4));
|
||||||
mobileFeature.setDescription(resultSet.getString(5));
|
mobileFeature.setDeviceType(resultSet.getString(5));
|
||||||
mobileFeatures.add(mobileFeature);
|
mobileFeatures.add(mobileFeature);
|
||||||
}
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetched all MobileFeatures from the MDM database.");
|
||||||
|
}
|
||||||
return mobileFeatures;
|
return mobileFeatures;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while fetching all features.'";
|
String msg = "Error occurred while fetching all features.'";
|
||||||
@ -256,7 +287,8 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MobileFeature> getMobileFeatureByDeviceType(String deviceType) throws MobileDeviceManagementDAOException {
|
public List<MobileFeature> getMobileFeatureByDeviceType(String deviceType) throws
|
||||||
|
MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
MobileFeature mobileFeature;
|
MobileFeature mobileFeature;
|
||||||
@ -264,19 +296,24 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT FEATURE_ID, DEVICE_TYPE, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE DEVICE_TYPE = ?";
|
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE" +
|
||||||
|
" WHERE DEVICE_TYPE = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setString(1, deviceType);
|
stmt.setString(1, deviceType);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
mobileFeature = new MobileFeature();
|
mobileFeature = new MobileFeature();
|
||||||
mobileFeature.setId(resultSet.getInt(1));
|
mobileFeature.setId(resultSet.getInt(1));
|
||||||
mobileFeature.setDeviceType(resultSet.getString(2));
|
mobileFeature.setCode(resultSet.getString(2));
|
||||||
mobileFeature.setCode(resultSet.getString(3));
|
mobileFeature.setName(resultSet.getString(3));
|
||||||
mobileFeature.setName(resultSet.getString(4));
|
mobileFeature.setDescription(resultSet.getString(4));
|
||||||
mobileFeature.setDescription(resultSet.getString(5));
|
mobileFeature.setDeviceType(resultSet.getString(5));
|
||||||
mobileFeatures.add(mobileFeature);
|
mobileFeatures.add(mobileFeature);
|
||||||
}
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetched all MobileFeatures of type " + deviceType + " from the MDM" +
|
||||||
|
" database.");
|
||||||
|
}
|
||||||
return mobileFeatures;
|
return mobileFeatures;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while fetching all features.'";
|
String msg = "Error occurred while fetching all features.'";
|
||||||
|
|||||||
@ -46,7 +46,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addMobileFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
|
public boolean addMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -57,15 +57,19 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
|
|||||||
"INSERT INTO MBL_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)";
|
"INSERT INTO MBL_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)";
|
||||||
|
|
||||||
stmt = conn.prepareStatement(createDBQuery);
|
stmt = conn.prepareStatement(createDBQuery);
|
||||||
stmt.setString(1, mobileFeatureProperty.getProperty());
|
stmt.setString(1, mblFeatureProperty.getProperty());
|
||||||
stmt.setInt(2, mobileFeatureProperty.getFeatureID());
|
stmt.setInt(2, mblFeatureProperty.getFeatureID());
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Added MobileFeatureProperty " + mblFeatureProperty.getProperty() +
|
||||||
|
" to the MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while adding property id - '" +
|
String msg = "Error occurred while adding property id - '" +
|
||||||
mobileFeatureProperty.getFeatureID() + "'";
|
mblFeatureProperty.getFeatureID() + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -75,7 +79,7 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateMobileFeatureProperty(MobileFeatureProperty mobileFeatureProperty)
|
public boolean updateMobileFeatureProperty(MobileFeatureProperty mblFeatureProperty)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -85,15 +89,18 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
|
|||||||
String updateDBQuery =
|
String updateDBQuery =
|
||||||
"UPDATE MBL_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?";
|
"UPDATE MBL_FEATURE_PROPERTY SET FEATURE_ID = ? WHERE PROPERTY = ?";
|
||||||
stmt = conn.prepareStatement(updateDBQuery);
|
stmt = conn.prepareStatement(updateDBQuery);
|
||||||
stmt.setInt(1, mobileFeatureProperty.getFeatureID());
|
stmt.setInt(1, mblFeatureProperty.getFeatureID());
|
||||||
stmt.setString(2, mobileFeatureProperty.getProperty());
|
stmt.setString(2, mblFeatureProperty.getProperty());
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Updated MobileFeatureProperty " + mblFeatureProperty.getProperty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while updating the feature property with property - '" +
|
String msg = "Error occurred while updating the feature property with property - '" +
|
||||||
mobileFeatureProperty.getProperty() + "'";
|
mblFeatureProperty.getProperty() + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -117,6 +124,9 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
|
|||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Deleted MobileFeatureProperty " + property + " from MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while deleting feature property with property - " +
|
String msg = "Error occurred while deleting feature property with property - " +
|
||||||
@ -129,6 +139,37 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteMobileFeaturePropertiesOfFeature(Integer mblFeatureId)
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
boolean status = false;
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String deleteDBQuery =
|
||||||
|
"DELETE FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
|
stmt.setInt(1, mblFeatureId);
|
||||||
|
int rows = stmt.executeUpdate();
|
||||||
|
if (rows > 0) {
|
||||||
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Deleted all MobileFeatureProperties of FeatureId " + mblFeatureId +
|
||||||
|
" from MDM database.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while deleting feature properties of feature - " +
|
||||||
|
mblFeatureId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobileFeatureProperty getMobileFeatureProperty(String property)
|
public MobileFeatureProperty getMobileFeatureProperty(String property)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
@ -142,11 +183,14 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
|
|||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setString(1, property);
|
stmt.setString(1, property);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
mobileFeatureProperty = new MobileFeatureProperty();
|
mobileFeatureProperty = new MobileFeatureProperty();
|
||||||
mobileFeatureProperty.setProperty(resultSet.getString(1));
|
mobileFeatureProperty.setProperty(resultSet.getString(1));
|
||||||
mobileFeatureProperty.setFeatureID(resultSet.getInt(2));
|
mobileFeatureProperty.setFeatureID(resultSet.getInt(2));
|
||||||
break;
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetched MobileFeatureProperty " + mobileFeatureProperty.getProperty() +
|
||||||
|
" from MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while fetching property - '" +
|
String msg = "Error occurred while fetching property - '" +
|
||||||
@ -160,18 +204,18 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MobileFeatureProperty> getFeaturePropertyOfFeature(Integer featureId)
|
public List<MobileFeatureProperty> getFeaturePropertiesOfFeature(Integer mblFeatureId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
MobileFeatureProperty mobileFeatureProperty = null;
|
MobileFeatureProperty mobileFeatureProperty;
|
||||||
List<MobileFeatureProperty> FeatureProperties = new ArrayList<MobileFeatureProperty>();
|
List<MobileFeatureProperty> FeatureProperties = new ArrayList<MobileFeatureProperty>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
|
"SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setInt(1, featureId);
|
stmt.setInt(1, mblFeatureId);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
mobileFeatureProperty = new MobileFeatureProperty();
|
mobileFeatureProperty = new MobileFeatureProperty();
|
||||||
@ -179,6 +223,10 @@ public class MobileFeaturePropertyDAOImpl implements MobileFeaturePropertyDAO {
|
|||||||
mobileFeatureProperty.setFeatureID(resultSet.getInt(2));
|
mobileFeatureProperty.setFeatureID(resultSet.getInt(2));
|
||||||
FeatureProperties.add(mobileFeatureProperty);
|
FeatureProperties.add(mobileFeatureProperty);
|
||||||
}
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetched all MobileFeatureProperties of featureId " + mblFeatureId +
|
||||||
|
" from MDM database.");
|
||||||
|
}
|
||||||
return FeatureProperties;
|
return FeatureProperties;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while fetching all feature property.'";
|
String msg = "Error occurred while fetching all feature property.'";
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import java.sql.SQLException;
|
|||||||
*/
|
*/
|
||||||
public class MobileOperationDAOImpl implements MobileOperationDAO {
|
public class MobileOperationDAOImpl implements MobileOperationDAO {
|
||||||
|
|
||||||
|
public static final String COLUMN_OPERATION_ID = "OPERATION_ID";
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
private static final Log log = LogFactory.getLog(MobileOperationDAOImpl.class);
|
private static final Log log = LogFactory.getLog(MobileOperationDAOImpl.class);
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int addMobileOperation(MobileOperation operation)
|
public int addMobileOperation(MobileOperation mblOperation)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
int status = -1;
|
int status = -1;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -53,19 +54,23 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
|
|||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String createDBQuery =
|
String createDBQuery =
|
||||||
"INSERT INTO MBL_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)";
|
"INSERT INTO MBL_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)";
|
||||||
stmt = conn.prepareStatement(createDBQuery, new String[] { "OPERATION_ID" });
|
stmt = conn.prepareStatement(createDBQuery, new String[] { COLUMN_OPERATION_ID });
|
||||||
stmt.setString(1, operation.getFeatureCode());
|
stmt.setString(1, mblOperation.getFeatureCode());
|
||||||
stmt.setLong(2, operation.getCreatedDate());
|
stmt.setLong(2, mblOperation.getCreatedDate());
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
ResultSet rs = stmt.getGeneratedKeys();
|
ResultSet rs = stmt.getGeneratedKeys();
|
||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
status = rs.getInt(1);
|
status = rs.getInt(1);
|
||||||
}
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Added a new MobileOperation " + mblOperation.getFeatureCode() +
|
||||||
|
" to MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while adding the operation - '" +
|
String msg = "Error occurred while adding the operation - '" +
|
||||||
operation.getFeatureCode() + "' to MBL_OPERATION table";
|
mblOperation.getFeatureCode() + "' to MBL_OPERATION table";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -75,7 +80,7 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateMobileOperation(MobileOperation operation)
|
public boolean updateMobileOperation(MobileOperation mblOperation)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -83,18 +88,24 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String updateDBQuery =
|
String updateDBQuery =
|
||||||
"UPDATE MBL_OPERATION SET FEATURE_CODE = ?, CREATED_DATE = ? WHERE OPERATION_ID = ?";
|
"UPDATE MBL_OPERATION SET FEATURE_CODE = ?, CREATED_DATE = ? WHERE " +
|
||||||
|
"OPERATION_ID = ?";
|
||||||
stmt = conn.prepareStatement(updateDBQuery);
|
stmt = conn.prepareStatement(updateDBQuery);
|
||||||
stmt.setString(1, operation.getFeatureCode());
|
stmt.setString(1, mblOperation.getFeatureCode());
|
||||||
stmt.setLong(2, operation.getCreatedDate());
|
stmt.setLong(2, mblOperation.getCreatedDate());
|
||||||
stmt.setInt(3, operation.getOperationId());
|
stmt.setInt(3, mblOperation.getOperationId());
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Updated MobileOperation " + mblOperation.getFeatureCode() +
|
||||||
|
" to MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while updating the MBL_OPERATION table entry with operation id - '" +
|
String msg =
|
||||||
operation.getOperationId() + "'";
|
"Error occurred while updating the MBL_OPERATION table entry with operation id - '" +
|
||||||
|
mblOperation.getOperationId() + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -104,7 +115,7 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteMobileOperation(int operationId)
|
public boolean deleteMobileOperation(int mblOperationId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -114,10 +125,14 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
|
|||||||
String deleteDBQuery =
|
String deleteDBQuery =
|
||||||
"DELETE FROM MBL_OPERATION WHERE OPERATION_ID = ?";
|
"DELETE FROM MBL_OPERATION WHERE OPERATION_ID = ?";
|
||||||
stmt = conn.prepareStatement(deleteDBQuery);
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
stmt.setInt(1, operationId);
|
stmt.setInt(1, mblOperationId);
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Deleted a new MobileOperation " + mblOperationId +
|
||||||
|
" from MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while deleting MBL_OPERATION entry with operation Id - ";
|
String msg = "Error occurred while deleting MBL_OPERATION entry with operation Id - ";
|
||||||
@ -130,7 +145,7 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobileOperation getMobileOperation(int operationId)
|
public MobileOperation getMobileOperation(int mblOperationId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -138,20 +153,24 @@ public class MobileOperationDAOImpl implements MobileOperationDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE OPERATION_ID = ?";
|
"SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE " +
|
||||||
|
"OPERATION_ID = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setInt(1, operationId);
|
stmt.setInt(1, mblOperationId);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
operation = new MobileOperation();
|
operation = new MobileOperation();
|
||||||
operation.setOperationId(resultSet.getInt(1));
|
operation.setOperationId(resultSet.getInt(1));
|
||||||
operation.setFeatureCode(resultSet.getString(2));
|
operation.setFeatureCode(resultSet.getString(2));
|
||||||
operation.setCreatedDate(resultSet.getLong(3));
|
operation.setCreatedDate(resultSet.getLong(3));
|
||||||
break;
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetched MobileOperation " + operation.getFeatureCode() +
|
||||||
|
" from MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while fetching operationId - '" +
|
String msg = "Error occurred while fetching operationId - '" +
|
||||||
operationId + "' from MBL_OPERATION";
|
mblOperationId + "' from MBL_OPERATION";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
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.MobileOperationPropertyDAO;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileOperationPropertyDAO;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
@ -47,7 +46,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addMobileOperationProperty(MobileOperationProperty operationProperty)
|
public boolean addMobileOperationProperty(MobileOperationProperty mblOperationProperty)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -55,19 +54,24 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String createDBQuery =
|
String createDBQuery =
|
||||||
"INSERT INTO MBL_OPERATION_PROPERTY(OPERATION_ID, PROPERTY, VALUE) VALUES ( ?, ?, ?)";
|
"INSERT INTO MBL_OPERATION_PROPERTY(OPERATION_ID, PROPERTY, VALUE) " +
|
||||||
|
"VALUES ( ?, ?, ?)";
|
||||||
stmt = conn.prepareStatement(createDBQuery);
|
stmt = conn.prepareStatement(createDBQuery);
|
||||||
stmt.setInt(1, operationProperty.getOperationId());
|
stmt.setInt(1, mblOperationProperty.getOperationId());
|
||||||
stmt.setString(2, operationProperty.getProperty());
|
stmt.setString(2, mblOperationProperty.getProperty());
|
||||||
stmt.setString(3, operationProperty.getValue());
|
stmt.setString(3, mblOperationProperty.getValue());
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Added a new MobileOperationProperty " + mblOperationProperty.getProperty() +
|
||||||
|
" to MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg =
|
String msg =
|
||||||
"Error occurred while adding mobile operation property to MBL_OPERATION_PROPERTY table";
|
"Error occurred while adding mobile operation property to MBL_OPERATION_PROPERTY " +
|
||||||
|
"table";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -78,7 +82,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateMobileOperationProperty(
|
public boolean updateMobileOperationProperty(
|
||||||
MobileOperationProperty operationProperty)
|
MobileOperationProperty mblOperationProperty)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -86,19 +90,24 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String createDBQuery =
|
String createDBQuery =
|
||||||
"UPDATE MBL_OPERATION_PROPERTY SET VALUE = ? WHERE OPERATION_ID = ? AND PROPERTY = ?";
|
"UPDATE MBL_OPERATION_PROPERTY SET VALUE = ? WHERE OPERATION_ID = ? AND " +
|
||||||
|
"PROPERTY = ?";
|
||||||
stmt = conn.prepareStatement(createDBQuery);
|
stmt = conn.prepareStatement(createDBQuery);
|
||||||
stmt.setString(1, operationProperty.getValue());
|
stmt.setString(1, mblOperationProperty.getValue());
|
||||||
stmt.setInt(2, operationProperty.getOperationId());
|
stmt.setInt(2, mblOperationProperty.getOperationId());
|
||||||
stmt.setString(3, operationProperty.getProperty());
|
stmt.setString(3, mblOperationProperty.getProperty());
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Updated MobileOperationProperty " + mblOperationProperty.getProperty() +
|
||||||
|
" to MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg =
|
String msg =
|
||||||
"Error occurred while updating the mobile operation property in MBL_OPERATION_PROPERTY table.";
|
"Error occurred while updating the mobile operation property in" +
|
||||||
|
" MBL_OPERATION_PROPERTY table.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -108,7 +117,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteMobileOperationProperties(int operationId)
|
public boolean deleteMobileOperationProperties(int mblOperationId)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -118,10 +127,15 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
|
|||||||
String deleteDBQuery =
|
String deleteDBQuery =
|
||||||
"DELETE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ?";
|
"DELETE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ?";
|
||||||
stmt = conn.prepareStatement(deleteDBQuery);
|
stmt = conn.prepareStatement(deleteDBQuery);
|
||||||
stmt.setInt(1, operationId);
|
stmt.setInt(1, mblOperationId);
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Deleted MobileOperationProperties of operation-id " +
|
||||||
|
mblOperationId +
|
||||||
|
" from MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg =
|
String msg =
|
||||||
@ -135,7 +149,7 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MobileOperationProperty getMobileOperationProperty(int operationId,
|
public MobileOperationProperty getMobileOperationProperty(int mblOperationId,
|
||||||
String property)
|
String property)
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
@ -144,22 +158,27 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ? AND PROPERTY = ?";
|
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE " +
|
||||||
|
"OPERATION_ID = ? AND PROPERTY = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setInt(1, operationId);
|
stmt.setInt(1, mblOperationId);
|
||||||
stmt.setString(2, property);
|
stmt.setString(2, property);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
mobileOperationProperty = new MobileOperationProperty();
|
mobileOperationProperty = new MobileOperationProperty();
|
||||||
mobileOperationProperty.setOperationId(resultSet.getInt(1));
|
mobileOperationProperty.setOperationId(resultSet.getInt(1));
|
||||||
mobileOperationProperty.setProperty(resultSet.getString(2));
|
mobileOperationProperty.setProperty(resultSet.getString(2));
|
||||||
mobileOperationProperty.setValue(resultSet.getString(3));
|
mobileOperationProperty.setValue(resultSet.getString(3));
|
||||||
break;
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetched MobileOperationProperty of Operation-id : " +
|
||||||
|
mblOperationId +
|
||||||
|
" Property : " + property + " from MDM database.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg =
|
String msg =
|
||||||
"Error occurred while fetching the mobile operation property of Operation_id : " +
|
"Error occurred while fetching the mobile operation property of Operation_id : " +
|
||||||
operationId + " and Property : " + property;
|
mblOperationId + " and Property : " + property;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -170,17 +189,18 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MobileOperationProperty> getAllMobileOperationPropertiesOfOperation(
|
public List<MobileOperationProperty> getAllMobileOperationPropertiesOfOperation(
|
||||||
int operationId) throws MobileDeviceManagementDAOException {
|
int mblOperationId) throws MobileDeviceManagementDAOException {
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
MobileOperationProperty mobileOperationProperty = null;
|
MobileOperationProperty mobileOperationProperty;
|
||||||
List<MobileOperationProperty> properties = new ArrayList<MobileOperationProperty>();
|
List<MobileOperationProperty> properties = new ArrayList<MobileOperationProperty>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String selectDBQuery =
|
String selectDBQuery =
|
||||||
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ?";
|
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE " +
|
||||||
|
"OPERATION_ID = ?";
|
||||||
stmt = conn.prepareStatement(selectDBQuery);
|
stmt = conn.prepareStatement(selectDBQuery);
|
||||||
stmt.setInt(1, operationId);
|
stmt.setInt(1, mblOperationId);
|
||||||
ResultSet resultSet = stmt.executeQuery();
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
mobileOperationProperty = new MobileOperationProperty();
|
mobileOperationProperty = new MobileOperationProperty();
|
||||||
@ -189,10 +209,15 @@ public class MobileOperationPropertyDAOImpl implements MobileOperationPropertyDA
|
|||||||
mobileOperationProperty.setValue(resultSet.getString(3));
|
mobileOperationProperty.setValue(resultSet.getString(3));
|
||||||
properties.add(mobileOperationProperty);
|
properties.add(mobileOperationProperty);
|
||||||
}
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetched all MobileOperationProperties of Operation-id : " +
|
||||||
|
mblOperationId +
|
||||||
|
" from MDM database.");
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg =
|
String msg =
|
||||||
"Error occurred while fetching the mobile operation properties of Operation_id " +
|
"Error occurred while fetching the mobile operation properties of Operation_id " +
|
||||||
operationId;
|
mblOperationId;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new MobileDeviceManagementDAOException(msg, e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@ -21,8 +21,6 @@ package org.wso2.carbon.device.mgt.mobile.dao.util;
|
|||||||
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.common.DeviceManagementException;
|
||||||
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.util.MobileDeviceManagementSchemaInitializer;
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementSchemaInitializer;
|
||||||
|
|
||||||
import javax.naming.InitialContext;
|
import javax.naming.InitialContext;
|
||||||
@ -32,7 +30,6 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method required by MobileDeviceManagement DAO classes.
|
* Utility method required by MobileDeviceManagement DAO classes.
|
||||||
@ -94,8 +91,8 @@ public class MobileDeviceManagementDAOUtil {
|
|||||||
try {
|
try {
|
||||||
initializer.createRegistryDatabase();
|
initializer.createRegistryDatabase();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new DeviceManagementException("Error occurred while initializing Mobile Device Management " +
|
throw new DeviceManagementException("Error occurred while initializing Mobile Device " +
|
||||||
"database schema", e);
|
"Management database schema", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -52,6 +52,9 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
boolean status;
|
boolean status;
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||||
try {
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
||||||
|
}
|
||||||
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
|
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
|
||||||
mobileDevice);
|
mobileDevice);
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
@ -68,6 +71,9 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
boolean status;
|
boolean status;
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||||
try {
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Modifying the Android device enrollment data");
|
||||||
|
}
|
||||||
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
||||||
.updateMobileDevice(mobileDevice);
|
.updateMobileDevice(mobileDevice);
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
@ -83,6 +89,9 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
boolean status;
|
boolean status;
|
||||||
try {
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Dis-enrolling Android device : " + deviceId);
|
||||||
|
}
|
||||||
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
||||||
.deleteMobileDevice(deviceId.getId());
|
.deleteMobileDevice(deviceId.getId());
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
@ -97,6 +106,9 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
boolean isEnrolled = false;
|
boolean isEnrolled = false;
|
||||||
try {
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
||||||
|
}
|
||||||
MobileDevice mobileDevice =
|
MobileDevice mobileDevice =
|
||||||
MobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice(
|
MobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice(
|
||||||
deviceId.getId());
|
deviceId.getId());
|
||||||
@ -127,6 +139,9 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
Device device;
|
Device device;
|
||||||
try {
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting the details of Android device : " + deviceId.getId());
|
||||||
|
}
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
MobileDevice mobileDevice = MobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
||||||
getMobileDevice(deviceId.getId());
|
getMobileDevice(deviceId.getId());
|
||||||
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
|
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
|
||||||
@ -149,6 +164,9 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
boolean status;
|
boolean status;
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||||
try {
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("updating the details of Android device : " + device.getDeviceIdentifier());
|
||||||
|
}
|
||||||
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
status = MobileDeviceManagementDAOFactory.getMobileDeviceDAO()
|
||||||
.updateMobileDevice(mobileDevice);
|
.updateMobileDevice(mobileDevice);
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
@ -163,6 +181,9 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
|
|||||||
public List<Device> getAllDevices() throws DeviceManagementException {
|
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||||
List<Device> devices = null;
|
List<Device> devices = null;
|
||||||
try {
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Fetching the details of all Android devices");
|
||||||
|
}
|
||||||
List<MobileDevice> mobileDevices =
|
List<MobileDevice> mobileDevices =
|
||||||
MobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
MobileDeviceManagementDAOFactory.getMobileDeviceDAO().
|
||||||
getAllMobileDevices();
|
getAllMobileDevices();
|
||||||
|
|||||||
@ -42,7 +42,7 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
|
|||||||
OperationManagementException {
|
OperationManagementException {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
try {
|
try {
|
||||||
MobileDeviceOperationMapping mobileDeviceOperationMapping = null;
|
MobileDeviceOperationMapping mobileDeviceOperationMapping;
|
||||||
MobileOperation mobileOperation =
|
MobileOperation mobileOperation =
|
||||||
MobileDeviceManagementUtil.convertToMobileOperation(operation);
|
MobileDeviceManagementUtil.convertToMobileOperation(operation);
|
||||||
int operationId = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
|
int operationId = MobileDeviceManagementDAOFactory.getMobileOperationDAO()
|
||||||
@ -77,12 +77,13 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
|
|||||||
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier)
|
public List<Operation> getOperations(DeviceIdentifier deviceIdentifier)
|
||||||
throws OperationManagementException {
|
throws OperationManagementException {
|
||||||
List<Operation> operations = new ArrayList<Operation>();
|
List<Operation> operations = new ArrayList<Operation>();
|
||||||
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings = null;
|
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings;
|
||||||
List<MobileOperationProperty> operationProperties = null;
|
List<MobileOperationProperty> operationProperties;
|
||||||
MobileOperation mobileOperation = null;
|
MobileOperation mobileOperation;
|
||||||
try {
|
try {
|
||||||
mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
mobileDeviceOperationMappings =
|
||||||
.getAllMobileDeviceOperationNappingsOfDevice(
|
MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
||||||
|
.getAllMobileDeviceOperationMappingsOfDevice(
|
||||||
deviceIdentifier
|
deviceIdentifier
|
||||||
.getId());
|
.getId());
|
||||||
if (mobileDeviceOperationMappings.size() > 0) {
|
if (mobileDeviceOperationMappings.size() > 0) {
|
||||||
@ -116,12 +117,13 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
|
|||||||
public List<Operation> getPendingOperations(DeviceIdentifier deviceIdentifier)
|
public List<Operation> getPendingOperations(DeviceIdentifier deviceIdentifier)
|
||||||
throws OperationManagementException {
|
throws OperationManagementException {
|
||||||
List<Operation> operations = new ArrayList<Operation>();
|
List<Operation> operations = new ArrayList<Operation>();
|
||||||
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings = null;
|
List<MobileDeviceOperationMapping> mobileDeviceOperationMappings;
|
||||||
List<MobileOperationProperty> operationProperties = null;
|
List<MobileOperationProperty> operationProperties ;
|
||||||
MobileOperation mobileOperation = null;
|
MobileOperation mobileOperation;
|
||||||
try {
|
try {
|
||||||
//Get the list of pending operations for the given device
|
//Get the list of pending operations for the given device
|
||||||
mobileDeviceOperationMappings = MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
mobileDeviceOperationMappings =
|
||||||
|
MobileDeviceManagementDAOFactory.getMobileDeviceOperationDAO()
|
||||||
.getAllPendingOperationMappingsOfMobileDevice(
|
.getAllPendingOperationMappingsOfMobileDevice(
|
||||||
deviceIdentifier
|
deviceIdentifier
|
||||||
.getId());
|
.getId());
|
||||||
@ -158,21 +160,25 @@ public class AndroidMobileOperationManager extends AbstractMobileOperationManage
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Feature> getFeaturesForDeviceType(String deviceType) throws FeatureManagementException {
|
public List<Feature> getFeaturesForDeviceType(String deviceType)
|
||||||
|
throws FeatureManagementException {
|
||||||
MobileFeatureDAO featureDAO = MobileDeviceManagementDAOFactory.getFeatureDAO();
|
MobileFeatureDAO featureDAO = MobileDeviceManagementDAOFactory.getFeatureDAO();
|
||||||
MobileFeaturePropertyDAO featurePropertyDAO = MobileDeviceManagementDAOFactory.getFeaturePropertyDAO();
|
MobileFeaturePropertyDAO featurePropertyDAO =
|
||||||
|
MobileDeviceManagementDAOFactory.getFeaturePropertyDAO();
|
||||||
List<Feature> features = new ArrayList<Feature>();
|
List<Feature> features = new ArrayList<Feature>();
|
||||||
try {
|
try {
|
||||||
List<MobileFeature> mobileFeatures = featureDAO.getMobileFeatureByDeviceType(deviceType);
|
List<MobileFeature> mobileFeatures =
|
||||||
|
featureDAO.getMobileFeatureByDeviceType(deviceType);
|
||||||
for (MobileFeature mobileFeature : mobileFeatures) {
|
for (MobileFeature mobileFeature : mobileFeatures) {
|
||||||
Feature feature = new Feature();
|
Feature feature = new Feature();
|
||||||
feature.setId(mobileFeature.getId());
|
feature.setId(mobileFeature.getId());
|
||||||
feature.setDeviceType(mobileFeature.getDeviceType());
|
feature.setDeviceType(mobileFeature.getDeviceType());
|
||||||
feature.setName(mobileFeature.getName());
|
feature.setName(mobileFeature.getName());
|
||||||
feature.setDescription(mobileFeature.getDescription());
|
feature.setDescription(mobileFeature.getDescription());
|
||||||
List<Feature.MetadataEntry> metadataEntries = new ArrayList<Feature.MetadataEntry>();
|
List<Feature.MetadataEntry> metadataEntries =
|
||||||
|
new ArrayList<Feature.MetadataEntry>();
|
||||||
List<MobileFeatureProperty> properties =
|
List<MobileFeatureProperty> properties =
|
||||||
featurePropertyDAO.getFeaturePropertyOfFeature(mobileFeature.getId());
|
featurePropertyDAO.getFeaturePropertiesOfFeature(mobileFeature.getId());
|
||||||
for (MobileFeatureProperty property : properties) {
|
for (MobileFeatureProperty property : properties) {
|
||||||
Feature.MetadataEntry metaEntry = new Feature.MetadataEntry();
|
Feature.MetadataEntry metaEntry = new Feature.MetadataEntry();
|
||||||
metaEntry.setId(property.getFeatureID());
|
metaEntry.setId(property.getFeatureID());
|
||||||
|
|||||||
@ -40,15 +40,20 @@ import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerServic
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BundleActivator of MobileDeviceManagement component.
|
||||||
|
*/
|
||||||
public class MobileDeviceManagementBundleActivator implements BundleActivator, BundleListener {
|
public class MobileDeviceManagementBundleActivator implements BundleActivator, BundleListener {
|
||||||
|
|
||||||
private ServiceRegistration androidServiceRegRef;
|
private ServiceRegistration androidServiceRegRef;
|
||||||
private ServiceRegistration iOSServiceRegRef;
|
private ServiceRegistration iOSServiceRegRef;
|
||||||
private ServiceRegistration windowsServiceRegRef;
|
private ServiceRegistration windowsServiceRegRef;
|
||||||
|
|
||||||
private static List<DataSourceListener> dataSourceListeners = new ArrayList<DataSourceListener>();
|
private static List<DataSourceListener> dataSourceListeners =
|
||||||
|
new ArrayList<DataSourceListener>();
|
||||||
|
|
||||||
private static final String SYMBOLIC_NAME_DATA_SOURCE_COMPONENT = "org.wso2.carbon.ndatasource.core";
|
private static final String SYMBOLIC_NAME_DATA_SOURCE_COMPONENT =
|
||||||
|
"org.wso2.carbon.ndatasource.core";
|
||||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class);
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,8 +66,8 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator, B
|
|||||||
|
|
||||||
/* Initialize the datasource configuration */
|
/* Initialize the datasource configuration */
|
||||||
MobileDeviceConfigurationManager.getInstance().initConfig();
|
MobileDeviceConfigurationManager.getInstance().initConfig();
|
||||||
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
|
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance().
|
||||||
.getMobileDeviceManagementConfig();
|
getMobileDeviceManagementConfig();
|
||||||
MobileDataSourceConfig dsConfig =
|
MobileDataSourceConfig dsConfig =
|
||||||
config.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
|
config.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
|
||||||
|
|
||||||
@ -138,10 +143,12 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator, B
|
|||||||
getApiPublisherConfig().getAPIs();
|
getApiPublisherConfig().getAPIs();
|
||||||
for (APIConfig apiConfig : apiConfigs) {
|
for (APIConfig apiConfig : apiConfigs) {
|
||||||
try {
|
try {
|
||||||
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
|
APIProvider provider =
|
||||||
|
APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
|
||||||
apiConfig.init(provider);
|
apiConfig.init(provider);
|
||||||
} catch (APIManagementException e) {
|
} catch (APIManagementException e) {
|
||||||
throw new DeviceManagementException("Error occurred while initializing API Config '" +
|
throw new DeviceManagementException(
|
||||||
|
"Error occurred while initializing API Config '" +
|
||||||
apiConfig.getName() + "'", e);
|
apiConfig.getName() + "'", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,11 +23,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
import org.osgi.framework.ServiceRegistration;
|
import org.osgi.framework.ServiceRegistration;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
import org.wso2.carbon.apimgt.api.APIManagementException;
|
|
||||||
import org.wso2.carbon.apimgt.api.APIProvider;
|
|
||||||
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
|
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
|
||||||
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
|
|
||||||
import org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil;
|
|
||||||
import org.wso2.carbon.core.ServerStartupObserver;
|
import org.wso2.carbon.core.ServerStartupObserver;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||||
@ -95,7 +91,9 @@ public class MobileDeviceManagementServiceComponent {
|
|||||||
MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema(
|
MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema(
|
||||||
MobileDeviceManagementDAOFactory.getDataSource());
|
MobileDeviceManagementDAOFactory.getDataSource());
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
log.error("Exception occurred while initializing mobile device management database schema", e);
|
log.error(
|
||||||
|
"Exception occurred while initializing mobile device management database schema",
|
||||||
|
e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,12 +108,15 @@ public class MobileDeviceManagementServiceComponent {
|
|||||||
new WindowsDeviceManagerService(), null);
|
new WindowsDeviceManagerService(), null);
|
||||||
|
|
||||||
serverStartupObserverRef = bundleContext.registerService(ServerStartupObserver.class,
|
serverStartupObserverRef = bundleContext.registerService(ServerStartupObserver.class,
|
||||||
new MobileDeviceManagementStartupObserver(), null);
|
new MobileDeviceManagementStartupObserver(),
|
||||||
|
null);
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Mobile Device Management Service Component has been successfully activated");
|
log.debug(
|
||||||
|
"Mobile Device Management Service Component has been successfully activated");
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error("Error occurred while activating Mobile Device Management Service Component", e);
|
log.error("Error occurred while activating Mobile Device Management Service Component",
|
||||||
|
e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,11 @@ import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
|
|||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Provides methods for initializing the database script.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public final class MobileDeviceManagementSchemaInitializer extends DatabaseCreator {
|
public final class MobileDeviceManagementSchemaInitializer extends DatabaseCreator {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementSchemaInitializer.class);
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementSchemaInitializer.class);
|
||||||
|
|||||||
@ -71,14 +71,13 @@ public class MobileDeviceManagementUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Device.Property getProperty(String property, String value) {
|
private static Device.Property getProperty(String property, String value) {
|
||||||
Device.Property prop = null;
|
|
||||||
if (property != null) {
|
if (property != null) {
|
||||||
prop = new Device.Property();
|
Device.Property prop = new Device.Property();
|
||||||
prop.setName(property);
|
prop.setName(property);
|
||||||
prop.setValue(value);
|
prop.setValue(value);
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
return prop;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MobileDevice convertToMobileDevice(Device device) {
|
public static MobileDevice convertToMobileDevice(Device device) {
|
||||||
@ -119,7 +118,7 @@ public class MobileDeviceManagementUtil {
|
|||||||
|
|
||||||
public static MobileOperation convertToMobileOperation(org.wso2.carbon.device.mgt.common.Operation operation) {
|
public static MobileOperation convertToMobileOperation(org.wso2.carbon.device.mgt.common.Operation operation) {
|
||||||
MobileOperation mobileOperation = new MobileOperation();
|
MobileOperation mobileOperation = new MobileOperation();
|
||||||
MobileOperationProperty operationProperty = null;
|
MobileOperationProperty operationProperty;
|
||||||
List<MobileOperationProperty> properties = new LinkedList<MobileOperationProperty>();
|
List<MobileOperationProperty> properties = new LinkedList<MobileOperationProperty>();
|
||||||
mobileOperation.setFeatureCode(operation.getCode());
|
mobileOperation.setFeatureCode(operation.getCode());
|
||||||
mobileOperation.setCreatedDate(new Date().getTime());
|
mobileOperation.setCreatedDate(new Date().getTime());
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import org.testng.annotations.BeforeClass;
|
|||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig;
|
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
import org.xml.sax.SAXParseException;
|
||||||
|
|
||||||
import javax.xml.XMLConstants;
|
import javax.xml.XMLConstants;
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
@ -34,6 +35,10 @@ import javax.xml.validation.Schema;
|
|||||||
import javax.xml.validation.SchemaFactory;
|
import javax.xml.validation.SchemaFactory;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for holding unit-tests related to MobileDeviceManagementConfig class.
|
||||||
|
*/
|
||||||
|
|
||||||
public class MobileDeviceManagementConfigTests {
|
public class MobileDeviceManagementConfigTests {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementConfigTests.class);
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementConfigTests.class);
|
||||||
@ -56,7 +61,8 @@ public class MobileDeviceManagementConfigTests {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
private void initSchema() {
|
private void initSchema() {
|
||||||
File deviceManagementSchemaConfig = new File(MobileDeviceManagementConfigTests.TEST_CONFIG_SCHEMA_LOCATION);
|
File deviceManagementSchemaConfig =
|
||||||
|
new File(MobileDeviceManagementConfigTests.TEST_CONFIG_SCHEMA_LOCATION);
|
||||||
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||||
try {
|
try {
|
||||||
schema = factory.newSchema(deviceManagementSchemaConfig);
|
schema = factory.newSchema(deviceManagementSchemaConfig);
|
||||||
@ -65,43 +71,52 @@ public class MobileDeviceManagementConfigTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test()
|
@Test
|
||||||
public void testMandateManagementRepositoryElement() {
|
public void testMandateManagementRepositoryElement() {
|
||||||
File malformedConfig =
|
File malformedConfig =
|
||||||
new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY);
|
new File(
|
||||||
|
MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY);
|
||||||
this.validateMalformedConfig(malformedConfig);
|
this.validateMalformedConfig(malformedConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMandateDataSourceConfigurationElement() {
|
public void testMandateDataSourceConfigurationElement() {
|
||||||
File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG);
|
File malformedConfig = new File(
|
||||||
|
MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG);
|
||||||
this.validateMalformedConfig(malformedConfig);
|
this.validateMalformedConfig(malformedConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMandateJndiLookupDefinitionElement() {
|
public void testMandateJndiLookupDefinitionElement() {
|
||||||
File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG);
|
File malformedConfig = new File(
|
||||||
|
MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG);
|
||||||
this.validateMalformedConfig(malformedConfig);
|
this.validateMalformedConfig(malformedConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMandateAPIPublisherElement() {
|
public void testMandateAPIPublisherElement() {
|
||||||
File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_PUBLISHER_CONFIG);
|
File malformedConfig = new File(
|
||||||
|
MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_PUBLISHER_CONFIG);
|
||||||
this.validateMalformedConfig(malformedConfig);
|
this.validateMalformedConfig(malformedConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMandateAPIsElement() {
|
public void testMandateAPIsElement() {
|
||||||
File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_APIS_CONFIG);
|
File malformedConfig = new File(
|
||||||
|
MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_APIS_CONFIG);
|
||||||
this.validateMalformedConfig(malformedConfig);
|
this.validateMalformedConfig(malformedConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMandateAPIElement() {
|
public void testMandateAPIElement() {
|
||||||
File malformedConfig = new File(MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_CONFIG);
|
File malformedConfig = new File(
|
||||||
|
MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_CONFIG);
|
||||||
this.validateMalformedConfig(malformedConfig);
|
this.validateMalformedConfig(malformedConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates a given malformed-configuration file.
|
||||||
|
*/
|
||||||
private void validateMalformedConfig(File malformedConfig) {
|
private void validateMalformedConfig(File malformedConfig) {
|
||||||
try {
|
try {
|
||||||
JAXBContext ctx = JAXBContext.newInstance(MobileDeviceManagementConfig.class);
|
JAXBContext ctx = JAXBContext.newInstance(MobileDeviceManagementConfig.class);
|
||||||
@ -110,7 +125,11 @@ public class MobileDeviceManagementConfigTests {
|
|||||||
um.unmarshal(malformedConfig);
|
um.unmarshal(malformedConfig);
|
||||||
Assert.assertTrue(false);
|
Assert.assertTrue(false);
|
||||||
} catch (JAXBException e) {
|
} catch (JAXBException e) {
|
||||||
log.error("Error occurred while unmarsharlling mobile device management config", e);
|
Throwable linkedException = e.getLinkedException();
|
||||||
|
if (!(linkedException instanceof SAXParseException)) {
|
||||||
|
log.error("Unexpected error occurred while unmarshalling mobile device management config", e);
|
||||||
|
Assert.assertTrue(false);
|
||||||
|
}
|
||||||
Assert.assertTrue(true);
|
Assert.assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* you may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
public class TestUtils {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(TestUtils.class);
|
|
||||||
|
|
||||||
public static void cleanupResources(Connection conn, Statement stmt, ResultSet rs) {
|
|
||||||
if (rs != null) {
|
|
||||||
try {
|
|
||||||
rs.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.warn("Error occurred while closing result set", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (stmt != null) {
|
|
||||||
try {
|
|
||||||
stmt.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.warn("Error occurred while closing prepared statement", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (conn != null) {
|
|
||||||
try {
|
|
||||||
conn.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.warn("Error occurred while closing database connection", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -18,5 +18,243 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl.dao;
|
package org.wso2.carbon.device.mgt.mobile.impl.dao;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.tomcat.jdbc.pool.DataSource;
|
||||||
|
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Parameters;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileDeviceDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Class for holding unit-tests related to MobileDeviceDAO class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
public class MobileDeviceDAOTestSuite {
|
public class MobileDeviceDAOTestSuite {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(MobileDeviceDAOTestSuite.class);
|
||||||
|
public static final String TEST_MOBILE_DEVICE_ID = "ABCD";
|
||||||
|
public static final String TEST_MOBILE_IMEI = "2412421412";
|
||||||
|
public static final String TEST_MOBILE_IMSI = "325235235";
|
||||||
|
public static final String TEST_MOBILE_MODEL = "S5";
|
||||||
|
public static final String TEST_MOBILE_VENDOR = "samsung";
|
||||||
|
public static final String TEST_MOBILE_UPDATED_VENDOR = "sony";
|
||||||
|
public static final String TEST_MOBILE_REG_ID = "2414";
|
||||||
|
public static final String TEST_MOBILE_OS_VERSION = "5.0.0";
|
||||||
|
public static final String TEST_MOBILE_LATITUDE = "6.93N";
|
||||||
|
public static final String TEST_MOBILE_LONGITUDE = "80.60E";
|
||||||
|
private TestDBConfiguration testDBConfiguration;
|
||||||
|
private MobileDeviceDAOImpl mblDeviceDAO;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@Parameters("dbType")
|
||||||
|
public void setUpDB(String dbTypeStr) throws Exception {
|
||||||
|
|
||||||
|
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||||
|
testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType);
|
||||||
|
|
||||||
|
switch (dbType) {
|
||||||
|
case H2:
|
||||||
|
MobileDatabaseUtils.createH2DB(testDBConfiguration);
|
||||||
|
DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||||
|
PoolProperties properties = new PoolProperties();
|
||||||
|
properties.setUrl(testDBConfiguration.getConnectionURL());
|
||||||
|
properties.setDriverClassName(testDBConfiguration.getDriverClassName());
|
||||||
|
properties.setUsername(testDBConfiguration.getUsername());
|
||||||
|
properties.setPassword(testDBConfiguration.getPassword());
|
||||||
|
testDataSource.setPoolProperties(properties);
|
||||||
|
mblDeviceDAO = new MobileDeviceDAOImpl(testDataSource);
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addMobileDeviceTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
MobileDevice mobileDevice = new MobileDevice();
|
||||||
|
MobileDevice testMblDevice = new MobileDevice();
|
||||||
|
mobileDevice.setMobileDeviceId(TEST_MOBILE_DEVICE_ID);
|
||||||
|
mobileDevice.setImei(TEST_MOBILE_IMEI);
|
||||||
|
mobileDevice.setImsi(TEST_MOBILE_IMSI);
|
||||||
|
mobileDevice.setModel(TEST_MOBILE_MODEL);
|
||||||
|
mobileDevice.setVendor(TEST_MOBILE_VENDOR);
|
||||||
|
mobileDevice.setRegId(TEST_MOBILE_REG_ID);
|
||||||
|
mobileDevice.setOsVersion(TEST_MOBILE_OS_VERSION);
|
||||||
|
mobileDevice.setLatitude(TEST_MOBILE_LATITUDE);
|
||||||
|
mobileDevice.setLongitude(TEST_MOBILE_LONGITUDE);
|
||||||
|
|
||||||
|
boolean added = mblDeviceDAO.addMobileDevice(mobileDevice);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT MOBILE_DEVICE_ID, REG_ID, IMEI, IMSI, OS_VERSION,DEVICE_MODEL, VENDOR, " +
|
||||||
|
"LATITUDE, LONGITUDE FROM MBL_DEVICE WHERE MOBILE_DEVICE_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
testMblDevice.setMobileDeviceId(resultSet.getString(1));
|
||||||
|
testMblDevice.setRegId(resultSet.getString(2));
|
||||||
|
testMblDevice.setImei(resultSet.getString(3));
|
||||||
|
testMblDevice.setImsi(resultSet.getString(4));
|
||||||
|
testMblDevice.setOsVersion(resultSet.getString(5));
|
||||||
|
testMblDevice.setModel(resultSet.getString(6));
|
||||||
|
testMblDevice.setVendor(resultSet.getString(7));
|
||||||
|
testMblDevice.setLatitude(resultSet.getString(8));
|
||||||
|
testMblDevice.setLongitude(resultSet.getString(9));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving Mobile Device data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(added, "MobileDevice has added");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_DEVICE_ID, testMblDevice.getMobileDeviceId(),
|
||||||
|
"MobileDevice id has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_IMEI, testMblDevice.getImei(),
|
||||||
|
"MobileDevice IMEI has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_IMSI, testMblDevice.getImsi(),
|
||||||
|
"MobileDevice IMSI has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_LATITUDE, testMblDevice.getLatitude(),
|
||||||
|
"MobileDevice latitude has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_LONGITUDE, testMblDevice.getLongitude(),
|
||||||
|
"MobileDevice longitude has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_MODEL, testMblDevice.getModel(),
|
||||||
|
"MobileDevice model has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_OS_VERSION, testMblDevice.getOsVersion(),
|
||||||
|
"MobileDevice os-version has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_REG_ID, testMblDevice.getRegId(),
|
||||||
|
"MobileDevice reg-id has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_VENDOR, testMblDevice.getVendor(),
|
||||||
|
"MobileDevice vendor has persisted ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileDeviceTest" })
|
||||||
|
public void getMobileDeviceTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
MobileDevice testMblDevice = mblDeviceDAO.getMobileDevice(TEST_MOBILE_DEVICE_ID);
|
||||||
|
Assert.assertEquals(TEST_MOBILE_DEVICE_ID, testMblDevice.getMobileDeviceId(),
|
||||||
|
"MobileDevice id has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_IMEI, testMblDevice.getImei(),
|
||||||
|
"MobileDevice IMEI has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_IMSI, testMblDevice.getImsi(),
|
||||||
|
"MobileDevice IMSI has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_LATITUDE, testMblDevice.getLatitude(),
|
||||||
|
"MobileDevice latitude has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_LONGITUDE, testMblDevice.getLongitude(),
|
||||||
|
"MobileDevice longitude has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_MODEL, testMblDevice.getModel(),
|
||||||
|
"MobileDevice model has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_OS_VERSION, testMblDevice.getOsVersion(),
|
||||||
|
"MobileDevice os-version has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_REG_ID, testMblDevice.getRegId(),
|
||||||
|
"MobileDevice reg-id has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_VENDOR, testMblDevice.getVendor(),
|
||||||
|
"MobileDevice vendor has persisted ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileDeviceTest" })
|
||||||
|
public void getAllMobileDevicesTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
List<MobileDevice> mblDevices = mblDeviceDAO.getAllMobileDevices();
|
||||||
|
Assert.assertNotNull(mblDevices, "MobileDevice list is not null");
|
||||||
|
Assert.assertTrue(mblDevices.size() == 1, "MobileDevice list has 1 MobileDevice");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileDeviceTest", "getMobileDeviceTest",
|
||||||
|
"getAllMobileDevicesTest" })
|
||||||
|
public void updateMobileDeviceTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
MobileDevice mobileDevice = new MobileDevice();
|
||||||
|
MobileDevice testMblDevice = new MobileDevice();
|
||||||
|
mobileDevice.setMobileDeviceId(TEST_MOBILE_DEVICE_ID);
|
||||||
|
mobileDevice.setImei(TEST_MOBILE_IMEI);
|
||||||
|
mobileDevice.setImsi(TEST_MOBILE_IMSI);
|
||||||
|
mobileDevice.setModel(TEST_MOBILE_MODEL);
|
||||||
|
mobileDevice.setVendor(TEST_MOBILE_UPDATED_VENDOR);
|
||||||
|
mobileDevice.setRegId(TEST_MOBILE_REG_ID);
|
||||||
|
mobileDevice.setOsVersion(TEST_MOBILE_OS_VERSION);
|
||||||
|
mobileDevice.setLatitude(TEST_MOBILE_LATITUDE);
|
||||||
|
mobileDevice.setLongitude(TEST_MOBILE_LONGITUDE);
|
||||||
|
|
||||||
|
boolean updated = mblDeviceDAO.updateMobileDevice(mobileDevice);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT MOBILE_DEVICE_ID, REG_ID, IMEI, IMSI, OS_VERSION,DEVICE_MODEL, VENDOR, " +
|
||||||
|
"LATITUDE, LONGITUDE FROM MBL_DEVICE WHERE MOBILE_DEVICE_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
testMblDevice.setMobileDeviceId(resultSet.getString(1));
|
||||||
|
testMblDevice.setRegId(resultSet.getString(2));
|
||||||
|
testMblDevice.setImei(resultSet.getString(3));
|
||||||
|
testMblDevice.setImsi(resultSet.getString(4));
|
||||||
|
testMblDevice.setOsVersion(resultSet.getString(5));
|
||||||
|
testMblDevice.setModel(resultSet.getString(6));
|
||||||
|
testMblDevice.setVendor(resultSet.getString(7));
|
||||||
|
testMblDevice.setLatitude(resultSet.getString(8));
|
||||||
|
testMblDevice.setLongitude(resultSet.getString(9));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving Mobile Device data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(updated, "MobileDevice has updated ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_UPDATED_VENDOR, testMblDevice.getVendor(),
|
||||||
|
"MobileDevice vendor has updated ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileDeviceTest", "getMobileDeviceTest",
|
||||||
|
"getAllMobileDevicesTest", "updateMobileDeviceTest" })
|
||||||
|
public void deleteMobileDeviceTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
boolean deleted = mblDeviceDAO.deleteMobileDevice(TEST_MOBILE_DEVICE_ID);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT MOBILE_DEVICE_ID, REG_ID, IMEI, IMSI, OS_VERSION,DEVICE_MODEL, VENDOR, " +
|
||||||
|
"LATITUDE, LONGITUDE FROM MBL_DEVICE WHERE MOBILE_DEVICE_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
deleted = false;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving Mobile Device data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(deleted, "MobileDevice has deleted ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* you may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl.dao;
|
|
||||||
|
|
||||||
public class MobileDeviceOperationDAOTestSuite {
|
|
||||||
}
|
|
||||||
@ -0,0 +1,434 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.mobile.impl.dao;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.tomcat.jdbc.pool.DataSource;
|
||||||
|
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Parameters;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileDeviceDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileDeviceOperationMappingDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileOperationDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileDeviceOperationMapping;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Class for holding unit-tests related to MobileDeviceOperationMappingDAO class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MobileDeviceOperationMappingDAOTestSuite {
|
||||||
|
|
||||||
|
private static final Log log =
|
||||||
|
LogFactory.getLog(MobileDeviceOperationMappingDAOTestSuite.class);
|
||||||
|
public static final String TEST_MOBILE_DEVICE_ID = "ABCD";
|
||||||
|
public static final String TEST_MOBILE_IMEI = "2412421412";
|
||||||
|
public static final String TEST_MOBILE_IMSI = "325235235";
|
||||||
|
public static final String TEST_MOBILE_MODEL = "S5";
|
||||||
|
public static final String TEST_MOBILE_VENDOR = "samsung";
|
||||||
|
public static final String TEST_MOBILE_REG_ID = "2414";
|
||||||
|
public static final String TEST_MOBILE_OS_VERSION = "5.0.0";
|
||||||
|
public static final String TEST_MOBILE_LATITUDE = "6.93N";
|
||||||
|
public static final String TEST_MOBILE_LONGITUDE = "80.60E";
|
||||||
|
public static final String TEST_MBL_OPR_FEATURE_CODE1 = "LOCK";
|
||||||
|
public static final String TEST_MBL_OPR_FEATURE_CODE2 = "WIPE";
|
||||||
|
public static final long TEST_MBL_OPR_CREATED_DATE = new java.util.Date().getTime();
|
||||||
|
|
||||||
|
private TestDBConfiguration testDBConfiguration;
|
||||||
|
private MobileDeviceDAOImpl mblDeviceDAO;
|
||||||
|
private MobileOperationDAOImpl mblOperationDAO;
|
||||||
|
private MobileDeviceOperationMappingDAOImpl mblDeviceOperationMappingDAO;
|
||||||
|
private int mblOperationId1;
|
||||||
|
private int mblOperationId2;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@Parameters("dbType")
|
||||||
|
public void setUpDB(String dbTypeStr) throws Exception {
|
||||||
|
|
||||||
|
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||||
|
testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType);
|
||||||
|
|
||||||
|
switch (dbType) {
|
||||||
|
case H2:
|
||||||
|
MobileDatabaseUtils.createH2DB(testDBConfiguration);
|
||||||
|
DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||||
|
PoolProperties properties = new PoolProperties();
|
||||||
|
properties.setUrl(testDBConfiguration.getConnectionURL());
|
||||||
|
properties.setDriverClassName(testDBConfiguration.getDriverClassName());
|
||||||
|
properties.setUsername(testDBConfiguration.getUsername());
|
||||||
|
properties.setPassword(testDBConfiguration.getPassword());
|
||||||
|
testDataSource.setPoolProperties(properties);
|
||||||
|
mblDeviceDAO = new MobileDeviceDAOImpl(testDataSource);
|
||||||
|
mblOperationDAO = new MobileOperationDAOImpl(testDataSource);
|
||||||
|
mblDeviceOperationMappingDAO =
|
||||||
|
new MobileDeviceOperationMappingDAOImpl(testDataSource);
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addMobileDeviceOperationMappingTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
List<MobileDeviceOperationMapping> mblOperations =
|
||||||
|
new ArrayList<MobileDeviceOperationMapping>();
|
||||||
|
MobileDeviceOperationMapping mblDvOperationMapping =
|
||||||
|
new MobileDeviceOperationMapping();
|
||||||
|
//Add a new Device to the database
|
||||||
|
MobileDevice mobileDevice = new MobileDevice();
|
||||||
|
mobileDevice.setMobileDeviceId(TEST_MOBILE_DEVICE_ID);
|
||||||
|
mobileDevice.setImei(TEST_MOBILE_IMEI);
|
||||||
|
mobileDevice.setImsi(TEST_MOBILE_IMSI);
|
||||||
|
mobileDevice.setModel(TEST_MOBILE_MODEL);
|
||||||
|
mobileDevice.setVendor(TEST_MOBILE_VENDOR);
|
||||||
|
mobileDevice.setRegId(TEST_MOBILE_REG_ID);
|
||||||
|
mobileDevice.setOsVersion(TEST_MOBILE_OS_VERSION);
|
||||||
|
mobileDevice.setLatitude(TEST_MOBILE_LATITUDE);
|
||||||
|
mobileDevice.setLongitude(TEST_MOBILE_LONGITUDE);
|
||||||
|
mblDeviceDAO.addMobileDevice(mobileDevice);
|
||||||
|
|
||||||
|
//Add an Operation to the db
|
||||||
|
MobileOperation mblOperation = new MobileOperation();
|
||||||
|
mblOperation.setFeatureCode(TEST_MBL_OPR_FEATURE_CODE1);
|
||||||
|
mblOperation.setCreatedDate(TEST_MBL_OPR_CREATED_DATE);
|
||||||
|
mblOperationId1 = mblOperationDAO.addMobileOperation(mblOperation);
|
||||||
|
|
||||||
|
//Add a new Operation 2 to the db
|
||||||
|
mblOperation.setFeatureCode(TEST_MBL_OPR_FEATURE_CODE2);
|
||||||
|
mblOperation.setCreatedDate(TEST_MBL_OPR_CREATED_DATE);
|
||||||
|
mblOperationId2 = mblOperationDAO.addMobileOperation(mblOperation);
|
||||||
|
|
||||||
|
//Add a device-operation mapping 1 to the table
|
||||||
|
mblDvOperationMapping.setDeviceId(TEST_MOBILE_DEVICE_ID);
|
||||||
|
mblDvOperationMapping.setOperationId(mblOperationId1);
|
||||||
|
mblDvOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW);
|
||||||
|
boolean status1 =
|
||||||
|
mblDeviceOperationMappingDAO.addMobileDeviceOperationMapping(mblDvOperationMapping);
|
||||||
|
|
||||||
|
//Add a device-operation mapping 2 to the table
|
||||||
|
mblDvOperationMapping.setDeviceId(TEST_MOBILE_DEVICE_ID);
|
||||||
|
mblDvOperationMapping.setOperationId(mblOperationId2);
|
||||||
|
mblDvOperationMapping.setStatus(MobileDeviceOperationMapping.Status.NEW);
|
||||||
|
boolean status2 =
|
||||||
|
mblDeviceOperationMappingDAO.addMobileDeviceOperationMapping(mblDvOperationMapping);
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE, STATUS FROM " +
|
||||||
|
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
mblDvOperationMapping = new MobileDeviceOperationMapping();
|
||||||
|
mblDvOperationMapping.setDeviceId(resultSet.getString(1));
|
||||||
|
mblDvOperationMapping.setOperationId(resultSet.getInt(2));
|
||||||
|
mblDvOperationMapping.setSentDate(resultSet.getLong(3));
|
||||||
|
mblDvOperationMapping.setReceivedDate(resultSet.getLong(4));
|
||||||
|
mblDvOperationMapping.setStatus(resultSet.getString(5));
|
||||||
|
mblOperations.add(mblDvOperationMapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving Mobile Operation Mappings data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status1, "MobileOperationMapping1 has added ");
|
||||||
|
Assert.assertTrue(status2, "MobileOperationMapping2 has added ");
|
||||||
|
Assert.assertTrue(mblOperations.size() == 2, "MobileOperationMappings have retrieved ");
|
||||||
|
|
||||||
|
for (MobileDeviceOperationMapping mapping : mblOperations) {
|
||||||
|
Assert.assertEquals(TEST_MOBILE_DEVICE_ID, mapping.getDeviceId(),
|
||||||
|
"MobileOperationMapping device id has persisted ");
|
||||||
|
Assert.assertEquals(MobileDeviceOperationMapping.Status.NEW, mapping.getStatus(),
|
||||||
|
"MobileOperationMapping status has persisted ");
|
||||||
|
Assert.assertTrue(mapping.getOperationId() > 0,
|
||||||
|
"MobileOperationMapping operation-id has persisted ");
|
||||||
|
Assert.assertTrue(mapping.getSentDate() == 0,
|
||||||
|
"MobileOperationMapping sent-date has fetched ");
|
||||||
|
Assert.assertTrue(mapping.getReceivedDate() == 0,
|
||||||
|
"MobileOperationMapping received-date has fetched ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest" })
|
||||||
|
public void getMobileDeviceOperationMappingTest() throws MobileDeviceManagementDAOException {
|
||||||
|
MobileDeviceOperationMapping mblOperationMapping =
|
||||||
|
mblDeviceOperationMappingDAO.getMobileDeviceOperationMapping(
|
||||||
|
TEST_MOBILE_DEVICE_ID, mblOperationId1);
|
||||||
|
Assert.assertNotNull(mblOperationMapping, "MobileOperationMapping 1 has fetched ");
|
||||||
|
Assert.assertEquals(TEST_MOBILE_DEVICE_ID, mblOperationMapping.getDeviceId(),
|
||||||
|
"MobileOperationMapping device id has fetched ");
|
||||||
|
Assert.assertEquals(mblOperationId1, mblOperationMapping.getOperationId(),
|
||||||
|
"MobileOperationMapping device id has fetched ");
|
||||||
|
Assert.assertEquals(MobileDeviceOperationMapping.Status.NEW,
|
||||||
|
mblOperationMapping.getStatus(),
|
||||||
|
"MobileOperationMapping status has fetched ");
|
||||||
|
Assert.assertTrue(mblOperationMapping.getSentDate() == 0,
|
||||||
|
"MobileOperationMapping sent-date has fetched ");
|
||||||
|
Assert.assertTrue(mblOperationMapping.getReceivedDate() == 0,
|
||||||
|
"MobileOperationMapping received-date has fetched ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest" })
|
||||||
|
public void getAllMobileDeviceOperationMappingsOfDeviceTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
List<MobileDeviceOperationMapping> mblOperationMappings =
|
||||||
|
mblDeviceOperationMappingDAO.getAllMobileDeviceOperationMappingsOfDevice(
|
||||||
|
TEST_MOBILE_DEVICE_ID);
|
||||||
|
Assert.assertNotNull(mblOperationMappings, "MobileOperationMappings have fetched ");
|
||||||
|
Assert.assertTrue(mblOperationMappings.size() == 2,
|
||||||
|
"All MobileOperationMappings have fetched ");
|
||||||
|
for (MobileDeviceOperationMapping mblOperationMapping : mblOperationMappings) {
|
||||||
|
Assert.assertEquals(TEST_MOBILE_DEVICE_ID, mblOperationMapping.getDeviceId(),
|
||||||
|
"MobileOperationMapping device id has fetched ");
|
||||||
|
Assert.assertTrue(mblOperationMapping.getOperationId() > 0,
|
||||||
|
"MobileOperationMapping operation-id has fetched ");
|
||||||
|
Assert.assertEquals(MobileDeviceOperationMapping.Status.NEW,
|
||||||
|
mblOperationMapping.getStatus(),
|
||||||
|
"MobileOperationMapping status has fetched ");
|
||||||
|
Assert.assertTrue(mblOperationMapping.getSentDate() == 0,
|
||||||
|
"MobileOperationMapping sent-date has fetched ");
|
||||||
|
Assert.assertTrue(mblOperationMapping.getReceivedDate() == 0,
|
||||||
|
"MobileOperationMapping received-date has fetched ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest",
|
||||||
|
"getAllMobileDeviceOperationMappingsOfDeviceTest" })
|
||||||
|
public void updateMobileDeviceOperationMappingToInProgressTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
MobileDeviceOperationMapping mblOperationMapping = null;
|
||||||
|
//Update device-operation to In-Progress state
|
||||||
|
boolean status =
|
||||||
|
mblDeviceOperationMappingDAO.updateMobileDeviceOperationMappingToInProgress(
|
||||||
|
TEST_MOBILE_DEVICE_ID, mblOperationId1);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, STATUS FROM " +
|
||||||
|
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||||
|
preparedStatement.setInt(2, mblOperationId1);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
mblOperationMapping = new MobileDeviceOperationMapping();
|
||||||
|
mblOperationMapping.setDeviceId(resultSet.getString(1));
|
||||||
|
mblOperationMapping.setOperationId(resultSet.getInt(2));
|
||||||
|
mblOperationMapping.setSentDate(resultSet.getLong(3));
|
||||||
|
mblOperationMapping.setStatus(resultSet.getString(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving Mobile Operation Mappings data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status, "MobileOperationMapping 1 has updated ");
|
||||||
|
Assert.assertNotNull(mblOperationMapping, "MobileOperationMappings have fetched ");
|
||||||
|
Assert.assertEquals(MobileDeviceOperationMapping.Status.INPROGRESS,
|
||||||
|
mblOperationMapping.getStatus(),
|
||||||
|
"MobileOperationMapping status has updated ");
|
||||||
|
Assert.assertTrue(mblOperationMapping.getSentDate() > 0,
|
||||||
|
"MobileOperationMapping sent-date has updated ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest",
|
||||||
|
"getAllMobileDeviceOperationMappingsOfDeviceTest" })
|
||||||
|
public void updateMobileDeviceOperationMappingToCompletedTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
MobileDeviceOperationMapping mblOperationMapping = null;
|
||||||
|
//Update device-operation to Completed state
|
||||||
|
boolean status =
|
||||||
|
mblDeviceOperationMappingDAO.updateMobileDeviceOperationMappingToCompleted(
|
||||||
|
TEST_MOBILE_DEVICE_ID, mblOperationId1);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT DEVICE_ID, OPERATION_ID, RECEIVED_DATE, STATUS FROM " +
|
||||||
|
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||||
|
preparedStatement.setInt(2, mblOperationId1);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
mblOperationMapping = new MobileDeviceOperationMapping();
|
||||||
|
mblOperationMapping.setDeviceId(resultSet.getString(1));
|
||||||
|
mblOperationMapping.setOperationId(resultSet.getInt(2));
|
||||||
|
mblOperationMapping.setReceivedDate(resultSet.getLong(3));
|
||||||
|
mblOperationMapping.setStatus(resultSet.getString(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving Mobile Operation Mappings data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status, "MobileOperationMapping 1 has updated ");
|
||||||
|
Assert.assertNotNull(mblOperationMapping, "MobileOperationMappings have fetched ");
|
||||||
|
Assert.assertEquals(MobileDeviceOperationMapping.Status.COMPLETED,
|
||||||
|
mblOperationMapping.getStatus(),
|
||||||
|
"MobileOperationMapping status has updated ");
|
||||||
|
Assert.assertTrue(mblOperationMapping.getReceivedDate() > 0,
|
||||||
|
"MobileOperationMapping received-date has updated ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest",
|
||||||
|
"getAllMobileDeviceOperationMappingsOfDeviceTest",
|
||||||
|
"updateMobileDeviceOperationMappingToInProgressTest",
|
||||||
|
"updateMobileDeviceOperationMappingToCompletedTest" })
|
||||||
|
public void updateMobileDeviceOperationMappingTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
MobileDeviceOperationMapping mblOperationMapping = new MobileDeviceOperationMapping();
|
||||||
|
long currentTime = new java.util.Date().getTime();
|
||||||
|
//Update device-operation mapping 1
|
||||||
|
mblOperationMapping.setDeviceId(TEST_MOBILE_DEVICE_ID);
|
||||||
|
mblOperationMapping.setOperationId(mblOperationId1);
|
||||||
|
mblOperationMapping.setStatus(MobileDeviceOperationMapping.Status.INPROGRESS);
|
||||||
|
mblOperationMapping.setSentDate(currentTime);
|
||||||
|
mblOperationMapping.setReceivedDate(currentTime);
|
||||||
|
boolean status =
|
||||||
|
mblDeviceOperationMappingDAO.updateMobileDeviceOperationMapping(
|
||||||
|
mblOperationMapping);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT DEVICE_ID, OPERATION_ID, RECEIVED_DATE, SENT_DATE, STATUS FROM " +
|
||||||
|
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||||
|
preparedStatement.setInt(2, mblOperationId1);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
mblOperationMapping = new MobileDeviceOperationMapping();
|
||||||
|
mblOperationMapping.setDeviceId(resultSet.getString(1));
|
||||||
|
mblOperationMapping.setOperationId(resultSet.getInt(2));
|
||||||
|
mblOperationMapping.setReceivedDate(resultSet.getLong(3));
|
||||||
|
mblOperationMapping.setSentDate(resultSet.getLong(4));
|
||||||
|
mblOperationMapping.setStatus(resultSet.getString(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving Mobile Operation Mappings data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status, "MobileOperationMapping 1 has updated ");
|
||||||
|
Assert.assertNotNull(mblOperationMapping, "MobileOperationMappings have fetched ");
|
||||||
|
Assert.assertEquals(MobileDeviceOperationMapping.Status.INPROGRESS,
|
||||||
|
mblOperationMapping.getStatus(),
|
||||||
|
"MobileOperationMapping status has updated ");
|
||||||
|
Assert.assertTrue(mblOperationMapping.getReceivedDate() == currentTime,
|
||||||
|
"MobileOperationMapping received-date has updated ");
|
||||||
|
Assert.assertTrue(mblOperationMapping.getSentDate() == currentTime,
|
||||||
|
"MobileOperationMapping sent-date has updated ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest",
|
||||||
|
"getAllMobileDeviceOperationMappingsOfDeviceTest",
|
||||||
|
"updateMobileDeviceOperationMappingToInProgressTest" })
|
||||||
|
public void getAllPendingOperationMappingsOfMobileDeviceTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
List<MobileDeviceOperationMapping> mblOperationMappings =
|
||||||
|
mblDeviceOperationMappingDAO.getAllPendingOperationMappingsOfMobileDevice(
|
||||||
|
TEST_MOBILE_DEVICE_ID);
|
||||||
|
Assert.assertNotNull(mblOperationMappings, "Pending MobileOperationMappings have fetched ");
|
||||||
|
Assert.assertTrue(mblOperationMappings.size() == 1,
|
||||||
|
"All MobileOperationMappings have fetched ");
|
||||||
|
for (MobileDeviceOperationMapping mblOperationMapping : mblOperationMappings) {
|
||||||
|
Assert.assertEquals(TEST_MOBILE_DEVICE_ID, mblOperationMapping.getDeviceId(),
|
||||||
|
"MobileOperationMapping device id has fetched ");
|
||||||
|
Assert.assertTrue(mblOperationMapping.getOperationId() == mblOperationId2,
|
||||||
|
"MobileOperationMapping operation-id has fetched ");
|
||||||
|
Assert.assertEquals(MobileDeviceOperationMapping.Status.NEW,
|
||||||
|
mblOperationMapping.getStatus(),
|
||||||
|
"MobileOperationMapping status has fetched ");
|
||||||
|
Assert.assertTrue(mblOperationMapping.getSentDate() == 0,
|
||||||
|
"MobileOperationMapping sent-date has fetched ");
|
||||||
|
Assert.assertTrue(mblOperationMapping.getReceivedDate() == 0,
|
||||||
|
"MobileOperationMapping received-date has fetched ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileDeviceOperationMappingTest",
|
||||||
|
"getAllMobileDeviceOperationMappingsOfDeviceTest",
|
||||||
|
"updateMobileDeviceOperationMappingToInProgressTest",
|
||||||
|
"updateMobileDeviceOperationMappingToCompletedTest",
|
||||||
|
"updateMobileDeviceOperationMappingTest" })
|
||||||
|
public void deleteMobileDeviceOperationMappingTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
boolean status =
|
||||||
|
mblDeviceOperationMappingDAO.deleteMobileDeviceOperationMapping(
|
||||||
|
TEST_MOBILE_DEVICE_ID, mblOperationId1);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT DEVICE_ID, OPERATION_ID, RECEIVED_DATE, SENT_DATE, STATUS FROM " +
|
||||||
|
"MBL_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setString(1, TEST_MOBILE_DEVICE_ID);
|
||||||
|
preparedStatement.setInt(2, mblOperationId1);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
status = false;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving MobileFeatureProperty data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status, "MobileDeviceOperationMapping 1 has deleted ");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,41 +20,36 @@ package org.wso2.carbon.device.mgt.mobile.impl.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.apache.tomcat.jdbc.pool.DataSource;
|
||||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Parameters;
|
import org.testng.annotations.Parameters;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeatureDAOImpl;
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeatureDAOImpl;
|
||||||
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.TestUtils;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes;
|
import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
|
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfigurations;
|
import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils;
|
||||||
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import javax.xml.bind.JAXBContext;
|
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
import javax.xml.bind.Unmarshaller;
|
|
||||||
import java.io.File;
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Class for holding unit-tests related to MobileFeatureDAO class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class MobileFeatureDAOTestSuite {
|
public class MobileFeatureDAOTestSuite {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(MobileFeatureDAOTestSuite.class);
|
private static final Log log = LogFactory.getLog(MobileFeatureDAOTestSuite.class);
|
||||||
public static final String MBL_FEATURE_NAME = "Camera";
|
public static final String MBL_FEATURE_NAME = "Camera";
|
||||||
private static final String MBL_FEATURE_CODE = "500A";
|
private static final String MBL_FEATURE_CODE = "500A";
|
||||||
public static final String MBL_FEATURE_DESCRIPTION = "Camera enable or disable";
|
public static final String MBL_FEATURE_DESCRIPTION = "Camera enable or disable";
|
||||||
|
public static final String MBL_FEATURE_DEVICE_TYPE = "Android";
|
||||||
public static final String MBL_FEATURE_UPDATED_CODE = "501B";
|
public static final String MBL_FEATURE_UPDATED_CODE = "501B";
|
||||||
private TestDBConfiguration testDBConfiguration;
|
private TestDBConfiguration testDBConfiguration;
|
||||||
private Connection conn = null;
|
|
||||||
private Statement stmt = null;
|
|
||||||
private MobileFeatureDAOImpl mblFeatureDAO;
|
private MobileFeatureDAOImpl mblFeatureDAO;
|
||||||
private int mblFeatureId;
|
private int mblFeatureId;
|
||||||
|
|
||||||
@ -63,105 +58,67 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
public void setUpDB(String dbTypeStr) throws Exception {
|
public void setUpDB(String dbTypeStr) throws Exception {
|
||||||
|
|
||||||
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||||
testDBConfiguration = getTestDBConfiguration(dbType);
|
testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType);
|
||||||
|
|
||||||
switch (dbType) {
|
switch (dbType) {
|
||||||
case H2:
|
case H2:
|
||||||
createH2DB(testDBConfiguration);
|
MobileDatabaseUtils.createH2DB(testDBConfiguration);
|
||||||
DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||||
PoolProperties properties = new PoolProperties();
|
PoolProperties properties = new PoolProperties();
|
||||||
properties.setUrl(testDBConfiguration.getConnectionURL());
|
properties.setUrl(testDBConfiguration.getConnectionURL());
|
||||||
properties.setDriverClassName(testDBConfiguration.getDriverClassName());
|
properties.setDriverClassName(testDBConfiguration.getDriverClassName());
|
||||||
properties.setUsername(testDBConfiguration.getUsername());
|
properties.setUsername(testDBConfiguration.getUsername());
|
||||||
properties.setPassword(testDBConfiguration.getPassword());
|
properties.setPassword(testDBConfiguration.getPassword());
|
||||||
|
testDataSource.setPoolProperties(properties);
|
||||||
mblFeatureDAO = new MobileFeatureDAOImpl(testDataSource);
|
mblFeatureDAO = new MobileFeatureDAOImpl(testDataSource);
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws
|
|
||||||
MobileDeviceManagementDAOException,
|
|
||||||
DeviceManagementException {
|
|
||||||
|
|
||||||
File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml");
|
|
||||||
Document doc = null;
|
|
||||||
testDBConfiguration = null;
|
|
||||||
TestDBConfigurations testDBConfigurations = null;
|
|
||||||
|
|
||||||
doc = MobileDeviceManagementUtil.convertToDocument(deviceMgtConfig);
|
|
||||||
JAXBContext testDBContext = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
testDBContext = JAXBContext.newInstance(TestDBConfigurations.class);
|
|
||||||
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();
|
|
||||||
testDBConfigurations = (TestDBConfigurations) unmarshaller.unmarshal(doc);
|
|
||||||
} catch (JAXBException e) {
|
|
||||||
throw new MobileDeviceManagementDAOException("Error parsing test db configurations", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<TestDBConfiguration> itrDBConfigs =
|
|
||||||
testDBConfigurations.getDbTypesList().iterator();
|
|
||||||
while (itrDBConfigs.hasNext()) {
|
|
||||||
testDBConfiguration = itrDBConfigs.next();
|
|
||||||
if (testDBConfiguration.getType().equals(dbType.toString())) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return testDBConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createH2DB(TestDBConfiguration testDBConf) throws Exception {
|
|
||||||
try {
|
|
||||||
Class.forName(testDBConf.getDriverClassName());
|
|
||||||
conn = DriverManager.getConnection(testDBConf.getConnectionURL());
|
|
||||||
stmt = conn.createStatement();
|
|
||||||
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'");
|
|
||||||
} finally {
|
|
||||||
stmt.close();
|
|
||||||
conn.close();
|
|
||||||
TestUtils.cleanupResources(conn, stmt, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addMobileFeatureTest()
|
public void addMobileFeatureTest()
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
MobileFeature mobileFeature = new MobileFeature();
|
MobileFeature mobileFeature = new MobileFeature();
|
||||||
MobileFeature testMblFeature = new MobileFeature();
|
MobileFeature testMblFeature = new MobileFeature();
|
||||||
mobileFeature.setCode(MBL_FEATURE_CODE);
|
mobileFeature.setCode(MBL_FEATURE_CODE);
|
||||||
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
||||||
mobileFeature.setName(MBL_FEATURE_NAME);
|
mobileFeature.setName(MBL_FEATURE_NAME);
|
||||||
boolean added = mblFeatureDAO.addMobileFeature(mobileFeature);
|
mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE);
|
||||||
|
int id = mblFeatureDAO.addMobileFeature(mobileFeature);
|
||||||
try {
|
try {
|
||||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
stmt = conn.createStatement();
|
String query =
|
||||||
ResultSet resultSet = stmt
|
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION, DEVICE_TYPE FROM MBL_FEATURE WHERE CODE = ?";
|
||||||
.executeQuery(
|
preparedStatement = conn.prepareStatement(query);
|
||||||
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = '500A'");
|
preparedStatement.setString(1, MBL_FEATURE_CODE);
|
||||||
while (resultSet.next()) {
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
testMblFeature.setId(resultSet.getInt(1));
|
testMblFeature.setId(resultSet.getInt(1));
|
||||||
testMblFeature.setCode(resultSet.getString(2));
|
testMblFeature.setCode(resultSet.getString(2));
|
||||||
testMblFeature.setName(resultSet.getString(3));
|
testMblFeature.setName(resultSet.getString(3));
|
||||||
testMblFeature.setDescription(resultSet.getString(4));
|
testMblFeature.setDescription(resultSet.getString(4));
|
||||||
|
testMblFeature.setDeviceType(resultSet.getString(5));
|
||||||
}
|
}
|
||||||
conn.close();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Error in retrieving Mobile Feature data ", e);
|
String msg = "Error in retrieving Mobile Feature data ";
|
||||||
throw new MobileDeviceManagementDAOException("Error in retrieving Mobile Feature data ",
|
log.error(msg, e);
|
||||||
e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
TestUtils.cleanupResources(conn, stmt, null);
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
}
|
}
|
||||||
mblFeatureId = testMblFeature.getId();
|
mblFeatureId = testMblFeature.getId();
|
||||||
Assert.assertTrue(added, "MobileFeature is added");
|
Assert.assertTrue(id > 0, "MobileFeature has added ");
|
||||||
Assert.assertEquals(MBL_FEATURE_CODE, testMblFeature.getCode(),
|
Assert.assertEquals(MBL_FEATURE_CODE, testMblFeature.getCode(),
|
||||||
"MobileFeature code has persisted successfully");
|
"MobileFeature code has persisted ");
|
||||||
Assert.assertEquals(MBL_FEATURE_NAME, testMblFeature.getName(),
|
Assert.assertEquals(MBL_FEATURE_NAME, testMblFeature.getName(),
|
||||||
"MobileFeature name has persisted successfully");
|
"MobileFeature name has persisted ");
|
||||||
Assert.assertEquals(MBL_FEATURE_DESCRIPTION, testMblFeature.getDescription(),
|
Assert.assertEquals(MBL_FEATURE_DESCRIPTION, testMblFeature.getDescription(),
|
||||||
"MobileFeature description has persisted successfully");
|
"MobileFeature description has persisted ");
|
||||||
|
Assert.assertEquals(MBL_FEATURE_DEVICE_TYPE, testMblFeature.getDeviceType(),
|
||||||
|
"MobileFeature device-type has persisted ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = { "addMobileFeatureTest" })
|
@Test(dependsOnMethods = { "addMobileFeatureTest" })
|
||||||
@ -170,35 +127,11 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
|
|
||||||
MobileFeature mobileFeature = mblFeatureDAO.getMobileFeatureByCode(MBL_FEATURE_CODE);
|
MobileFeature mobileFeature = mblFeatureDAO.getMobileFeatureByCode(MBL_FEATURE_CODE);
|
||||||
Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(),
|
Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(),
|
||||||
"MobileFeature code has retrieved successfully");
|
"MobileFeature code has retrieved ");
|
||||||
Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(),
|
Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(),
|
||||||
"MobileFeature name has retrieved successfully");
|
"MobileFeature name has retrieved ");
|
||||||
Assert.assertEquals(MBL_FEATURE_DESCRIPTION, mobileFeature.getDescription(),
|
Assert.assertEquals(MBL_FEATURE_DESCRIPTION, mobileFeature.getDescription(),
|
||||||
"MobileFeature description has retrieved successfully");
|
"MobileFeature description has retrieved ");
|
||||||
}
|
|
||||||
|
|
||||||
@Test(dependsOnMethods = {"addMobileFeatureTest"})
|
|
||||||
public void deleteMobileFeatureByCodeTest()
|
|
||||||
throws MobileDeviceManagementDAOException {
|
|
||||||
boolean status = mblFeatureDAO.deleteMobileFeatureByCode(MBL_FEATURE_CODE);
|
|
||||||
try {
|
|
||||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
|
||||||
stmt = conn.createStatement();
|
|
||||||
ResultSet resultSet = stmt
|
|
||||||
.executeQuery(
|
|
||||||
"SELECT FEATURE_ID, CODE FROM MBL_FEATURE WHERE CODE = '500A'");
|
|
||||||
while (resultSet.next()) {
|
|
||||||
status = false;
|
|
||||||
}
|
|
||||||
conn.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("Error in deleting Mobile Feature data ", e);
|
|
||||||
throw new MobileDeviceManagementDAOException("Error in deleting Mobile Feature data ",
|
|
||||||
e);
|
|
||||||
} finally {
|
|
||||||
TestUtils.cleanupResources(conn, stmt, null);
|
|
||||||
}
|
|
||||||
Assert.assertTrue(status, "MobileFeature has deleted successfully");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = { "addMobileFeatureTest" })
|
@Test(dependsOnMethods = { "addMobileFeatureTest" })
|
||||||
@ -207,11 +140,11 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
|
|
||||||
MobileFeature mobileFeature = mblFeatureDAO.getMobileFeatureById(mblFeatureId);
|
MobileFeature mobileFeature = mblFeatureDAO.getMobileFeatureById(mblFeatureId);
|
||||||
Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(),
|
Assert.assertEquals(MBL_FEATURE_CODE, mobileFeature.getCode(),
|
||||||
"MobileFeature code has retrieved successfully");
|
"MobileFeature code has retrieved ");
|
||||||
Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(),
|
Assert.assertEquals(MBL_FEATURE_NAME, mobileFeature.getName(),
|
||||||
"MobileFeature name has retrieved successfully");
|
"MobileFeature name has retrieved ");
|
||||||
Assert.assertEquals(MBL_FEATURE_DESCRIPTION, mobileFeature.getDescription(),
|
Assert.assertEquals(MBL_FEATURE_DESCRIPTION, mobileFeature.getDescription(),
|
||||||
"MobileFeature description has retrieved successfully");
|
"MobileFeature description has retrieved ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = { "addMobileFeatureTest" })
|
@Test(dependsOnMethods = { "addMobileFeatureTest" })
|
||||||
@ -223,38 +156,13 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
Assert.assertTrue(mobileFeatures.size() > 0, "MobileFeature list has 1 MobileFeature");
|
Assert.assertTrue(mobileFeatures.size() > 0, "MobileFeature list has 1 MobileFeature");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = {"addMobileFeatureTest"})
|
@Test(dependsOnMethods = { "addMobileFeatureTest", "getMobileFeatureByCodeTest",
|
||||||
public void deleteMobileFeatureByIdTest()
|
"getMobileFeatureByIdTest", "getAllMobileFeaturesTest" })
|
||||||
throws MobileDeviceManagementDAOException {
|
|
||||||
Connection conn = null;
|
|
||||||
Statement stmt = null;
|
|
||||||
|
|
||||||
boolean status = mblFeatureDAO.deleteMobileFeatureById(mblFeatureId);
|
|
||||||
try {
|
|
||||||
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
|
||||||
ResultSet resultSet = stmt
|
|
||||||
.executeQuery(
|
|
||||||
"SELECT FEATURE_ID, CODE FROM MBL_FEATURE WHERE FEATURE_ID = " +
|
|
||||||
mblFeatureId);
|
|
||||||
while (resultSet.next()) {
|
|
||||||
status = false;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("Error in deleting Mobile Feature data ", e);
|
|
||||||
throw new MobileDeviceManagementDAOException("Error in deleting Mobile Feature data ",
|
|
||||||
e);
|
|
||||||
} finally {
|
|
||||||
TestUtils.cleanupResources(conn, stmt, null);
|
|
||||||
}
|
|
||||||
Assert.assertTrue(status, "MobileFeature has deleted successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(dependsOnMethods = {"deleteMobileFeatureByCodeTest", "addMobileFeatureTest"})
|
|
||||||
public void updateMobileFeatureTest()
|
public void updateMobileFeatureTest()
|
||||||
throws MobileDeviceManagementDAOException {
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
Statement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
|
|
||||||
MobileFeature mobileFeature = new MobileFeature();
|
MobileFeature mobileFeature = new MobileFeature();
|
||||||
MobileFeature testMblFeature = new MobileFeature();
|
MobileFeature testMblFeature = new MobileFeature();
|
||||||
@ -264,28 +172,88 @@ public class MobileFeatureDAOTestSuite {
|
|||||||
mobileFeature.setId(mblFeatureId);
|
mobileFeature.setId(mblFeatureId);
|
||||||
boolean updated = mblFeatureDAO.updateMobileFeature(mobileFeature);
|
boolean updated = mblFeatureDAO.updateMobileFeature(mobileFeature);
|
||||||
try {
|
try {
|
||||||
conn = DriverManager.getConnection(testDBConfiguration.getDriverClassName());
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
stmt = conn.createStatement();
|
String query =
|
||||||
ResultSet resultSet = stmt
|
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = ?";
|
||||||
.executeQuery(
|
stmt = conn.prepareStatement(query);
|
||||||
"SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM MBL_FEATURE WHERE CODE = '" +
|
stmt.setString(1, MBL_FEATURE_UPDATED_CODE);
|
||||||
MBL_FEATURE_UPDATED_CODE + "'");
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
while (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
testMblFeature.setId(resultSet.getInt(1));
|
testMblFeature.setId(resultSet.getInt(1));
|
||||||
testMblFeature.setCode(resultSet.getString(2));
|
testMblFeature.setCode(resultSet.getString(2));
|
||||||
testMblFeature.setName(resultSet.getString(3));
|
testMblFeature.setName(resultSet.getString(3));
|
||||||
testMblFeature.setDescription(resultSet.getString(4));
|
testMblFeature.setDescription(resultSet.getString(4));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Error in updating Mobile Feature data ", e);
|
String msg = "Error in updating Mobile Feature data ";
|
||||||
throw new MobileDeviceManagementDAOException("Error in updating Mobile Feature data ",
|
log.error(msg, e);
|
||||||
e);
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
TestUtils.cleanupResources(conn, stmt, null);
|
MobileDatabaseUtils.cleanupResources(conn, stmt, null);
|
||||||
}
|
}
|
||||||
Assert.assertTrue(updated, "MobileFeature has updated");
|
Assert.assertTrue(updated, "MobileFeature has updated");
|
||||||
Assert.assertEquals(MBL_FEATURE_UPDATED_CODE, testMblFeature.getCode(),
|
Assert.assertEquals(MBL_FEATURE_UPDATED_CODE, testMblFeature.getCode(),
|
||||||
"MobileFeature data has updated successfully");
|
"MobileFeature data has updated ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileFeatureTest", "getMobileFeatureByCodeTest",
|
||||||
|
"getMobileFeatureByIdTest", "getAllMobileFeaturesTest",
|
||||||
|
"updateMobileFeatureTest" })
|
||||||
|
public void deleteMobileFeatureByIdTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
|
||||||
|
boolean status = mblFeatureDAO.deleteMobileFeatureById(mblFeatureId);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String query = "SELECT FEATURE_ID, CODE FROM MBL_FEATURE WHERE FEATURE_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setInt(1, mblFeatureId);
|
||||||
|
ResultSet resultSet = stmt.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
status = false;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in deleting Mobile Feature data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status, "MobileFeature has deleted ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileFeatureTest", "getMobileFeatureByCodeTest",
|
||||||
|
"getMobileFeatureByIdTest", "getAllMobileFeaturesTest",
|
||||||
|
"updateMobileFeatureTest", "deleteMobileFeatureByIdTest" })
|
||||||
|
public void deleteMobileFeatureByCodeTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
MobileFeature mobileFeature = new MobileFeature();
|
||||||
|
mobileFeature.setCode(MBL_FEATURE_CODE);
|
||||||
|
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
||||||
|
mobileFeature.setName(MBL_FEATURE_NAME);
|
||||||
|
mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE);
|
||||||
|
mblFeatureDAO.addMobileFeature(mobileFeature);
|
||||||
|
boolean status = mblFeatureDAO.deleteMobileFeatureByCode(MBL_FEATURE_CODE);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String query = "SELECT FEATURE_ID, CODE FROM MBL_FEATURE WHERE CODE = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(query);
|
||||||
|
preparedStatement.setString(1, MBL_FEATURE_CODE);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
status = false;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in deleting Mobile Feature data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status, "MobileFeature has deleted ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,5 +18,221 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl.dao;
|
package org.wso2.carbon.device.mgt.mobile.impl.dao;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.tomcat.jdbc.pool.DataSource;
|
||||||
|
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Parameters;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeatureDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileFeaturePropertyDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeatureProperty;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Class for holding unit-tests related to MobileFeaturePropertyDAO class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class MobileFeaturePropertyDAOTestSuite {
|
public class MobileFeaturePropertyDAOTestSuite {
|
||||||
|
private static final Log log = LogFactory.getLog(MobileFeaturePropertyDAOTestSuite.class);
|
||||||
|
public static final String MBL_FEATURE_NAME = "WIFI";
|
||||||
|
private static final String MBL_FEATURE_CODE = "500A";
|
||||||
|
public static final String MBL_FEATURE_DESCRIPTION = "Wifi config";
|
||||||
|
public static final String MBL_FEATURE_DEVICE_TYPE = "Android";
|
||||||
|
public static final String MBL_FEATURE_PROP_1 = "SSID";
|
||||||
|
public static final String MBL_FEATURE_PROP_2 = "PASSWORD";
|
||||||
|
private TestDBConfiguration testDBConfiguration;
|
||||||
|
private MobileFeatureDAOImpl mblFeatureDAO;
|
||||||
|
private MobileFeaturePropertyDAOImpl mobileFeaturePropertyDAO;
|
||||||
|
private int mblFeatureId;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@Parameters("dbType")
|
||||||
|
public void setUpDB(String dbTypeStr) throws Exception {
|
||||||
|
|
||||||
|
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||||
|
testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType);
|
||||||
|
|
||||||
|
switch (dbType) {
|
||||||
|
case H2:
|
||||||
|
MobileDatabaseUtils.createH2DB(testDBConfiguration);
|
||||||
|
DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||||
|
PoolProperties properties = new PoolProperties();
|
||||||
|
properties.setUrl(testDBConfiguration.getConnectionURL());
|
||||||
|
properties.setDriverClassName(testDBConfiguration.getDriverClassName());
|
||||||
|
properties.setUsername(testDBConfiguration.getUsername());
|
||||||
|
properties.setPassword(testDBConfiguration.getPassword());
|
||||||
|
testDataSource.setPoolProperties(properties);
|
||||||
|
mblFeatureDAO = new MobileFeatureDAOImpl(testDataSource);
|
||||||
|
mobileFeaturePropertyDAO = new MobileFeaturePropertyDAOImpl(testDataSource);
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addMobileFeaturePropertyTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
List<MobileFeatureProperty> propertyList = new ArrayList<MobileFeatureProperty>();
|
||||||
|
//Add a new MobileFeature to the database
|
||||||
|
MobileFeature mobileFeature = new MobileFeature();
|
||||||
|
mobileFeature.setCode(MBL_FEATURE_CODE);
|
||||||
|
mobileFeature.setDescription(MBL_FEATURE_DESCRIPTION);
|
||||||
|
mobileFeature.setName(MBL_FEATURE_NAME);
|
||||||
|
mobileFeature.setDeviceType(MBL_FEATURE_DEVICE_TYPE);
|
||||||
|
mblFeatureId = mblFeatureDAO.addMobileFeature(mobileFeature);
|
||||||
|
|
||||||
|
//Add 1st property to the feature
|
||||||
|
MobileFeatureProperty mobileFeatureProperty = new MobileFeatureProperty();
|
||||||
|
mobileFeatureProperty.setFeatureID(mblFeatureId);
|
||||||
|
mobileFeatureProperty.setProperty(MBL_FEATURE_PROP_1);
|
||||||
|
boolean status1 = mobileFeaturePropertyDAO.addMobileFeatureProperty(mobileFeatureProperty);
|
||||||
|
|
||||||
|
//Add 2nd property to the feature
|
||||||
|
mobileFeatureProperty.setProperty(MBL_FEATURE_PROP_2);
|
||||||
|
boolean status2 = mobileFeaturePropertyDAO.addMobileFeatureProperty(mobileFeatureProperty);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String query =
|
||||||
|
"SELECT FEATURE_ID, PROPERTY FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(query);
|
||||||
|
preparedStatement.setInt(1, mblFeatureId);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
mobileFeatureProperty = new MobileFeatureProperty();
|
||||||
|
mobileFeatureProperty.setFeatureID(resultSet.getInt(1));
|
||||||
|
mobileFeatureProperty.setProperty(resultSet.getString(2));
|
||||||
|
propertyList.add(mobileFeatureProperty);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving Mobile Feature data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status1, "MobileFeatureProperty1 has added ");
|
||||||
|
Assert.assertTrue(status2, "MobileFeatureProperty2 has added ");
|
||||||
|
Assert.assertTrue(propertyList.size() == 2, "MobileFeatureProperties have retrieved ");
|
||||||
|
|
||||||
|
for (MobileFeatureProperty mblFeatureProperty : propertyList) {
|
||||||
|
Assert.assertNotNull(mblFeatureProperty.getProperty(),
|
||||||
|
"MobileFeatureProperty property has persisted ");
|
||||||
|
Assert.assertNotNull(mblFeatureProperty.getFeatureID(),
|
||||||
|
"MobileFeatureProperty feature-id has persisted ");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileFeaturePropertyTest" })
|
||||||
|
public void getMobileFeaturePropertyTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
MobileFeatureProperty mobileFeatureProperty =
|
||||||
|
mobileFeaturePropertyDAO.getMobileFeatureProperty(MBL_FEATURE_PROP_1);
|
||||||
|
Assert.assertNotNull(mobileFeatureProperty, "MobileFeatureProperty has retrieved ");
|
||||||
|
Assert.assertEquals(MBL_FEATURE_PROP_1, mobileFeatureProperty.getProperty(),
|
||||||
|
"MobileFeatureProperty property has retrieved ");
|
||||||
|
Assert.assertTrue(mblFeatureId == mobileFeatureProperty.getFeatureID(),
|
||||||
|
"MobileFeatureProperty featureId has retrieved ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileFeaturePropertyTest" })
|
||||||
|
public void getFeaturePropertyOfFeatureTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
List<MobileFeatureProperty> mobileFeatureProperties =
|
||||||
|
mobileFeaturePropertyDAO.getFeaturePropertiesOfFeature(mblFeatureId);
|
||||||
|
Assert.assertNotNull(mobileFeatureProperties, "MobileFeatureProperty list has retrieved ");
|
||||||
|
Assert.assertTrue(mobileFeatureProperties.size() == 2,
|
||||||
|
"MobileFeatureProperties have fetched ");
|
||||||
|
for (MobileFeatureProperty mblFeatureProperty : mobileFeatureProperties) {
|
||||||
|
Assert.assertNotNull(mblFeatureProperty.getProperty(),
|
||||||
|
"MobileFeatureProperty property has fetched ");
|
||||||
|
Assert.assertNotNull(mblFeatureProperty.getFeatureID(),
|
||||||
|
"MobileFeatureProperty feature-id has fetched ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileFeaturePropertyTest", "getMobileFeaturePropertyTest",
|
||||||
|
"getFeaturePropertyOfFeatureTest" }, expectedExceptions = MobileDeviceManagementDAOException.class)
|
||||||
|
public void updateMobileFeaturePropertyTest() throws MobileDeviceManagementDAOException {
|
||||||
|
//Update 1st property to a non-exist feature
|
||||||
|
MobileFeatureProperty mobileFeatureProperty = new MobileFeatureProperty();
|
||||||
|
mobileFeatureProperty.setFeatureID(2);
|
||||||
|
mobileFeatureProperty.setProperty(MBL_FEATURE_PROP_1);
|
||||||
|
mobileFeaturePropertyDAO.updateMobileFeatureProperty(mobileFeatureProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileFeaturePropertyTest", "getMobileFeaturePropertyTest",
|
||||||
|
"getFeaturePropertyOfFeatureTest" })
|
||||||
|
public void deleteMobileFeaturePropertyTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
boolean status =
|
||||||
|
mobileFeaturePropertyDAO.deleteMobileFeatureProperty(MBL_FEATURE_PROP_2);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String query =
|
||||||
|
"SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE PROPERTY = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(query);
|
||||||
|
preparedStatement.setString(1, MBL_FEATURE_PROP_2);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
if (resultSet.next()) {
|
||||||
|
status = false;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving MobileFeatureProperty data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status, "MobileFeatureProperty has deleted ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileFeaturePropertyTest", "getMobileFeaturePropertyTest",
|
||||||
|
"getFeaturePropertyOfFeatureTest" , "updateMobileFeaturePropertyTest",
|
||||||
|
"deleteMobileFeaturePropertyTest"})
|
||||||
|
public void deleteMobileFeaturePropertiesOfFeatureTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
boolean status =
|
||||||
|
mobileFeaturePropertyDAO.deleteMobileFeaturePropertiesOfFeature(mblFeatureId);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String query =
|
||||||
|
"SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(query);
|
||||||
|
preparedStatement.setInt(1, mblFeatureId);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
if (resultSet.next()) {
|
||||||
|
status = false;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving MobileFeatureProperty data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status, "MobileFeatureProperties has deleted ");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,5 +18,169 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl.dao;
|
package org.wso2.carbon.device.mgt.mobile.impl.dao;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.tomcat.jdbc.pool.DataSource;
|
||||||
|
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Parameters;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileOperationDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for holding unit-tests related to MobileOperationDAO class.
|
||||||
|
*/
|
||||||
public class MobileOperationDAOTestSuite {
|
public class MobileOperationDAOTestSuite {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(MobileOperationDAOTestSuite.class);
|
||||||
|
public static final String TEST_MBL_OPR_FEATURE_CODE = "LOCK";
|
||||||
|
public static final String TEST_MBL_OPR_UPDATED_FEATURE_CODE = "MUTE";
|
||||||
|
public static final long TEST_MBL_OPR_CREATED_DATE = new java.util.Date().getTime();
|
||||||
|
private TestDBConfiguration testDBConfiguration;
|
||||||
|
private MobileOperationDAOImpl mblOperationDAO;
|
||||||
|
private int mblOperationId;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@Parameters("dbType")
|
||||||
|
public void setUpDB(String dbTypeStr) throws Exception {
|
||||||
|
|
||||||
|
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||||
|
testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType);
|
||||||
|
|
||||||
|
switch (dbType) {
|
||||||
|
case H2:
|
||||||
|
MobileDatabaseUtils.createH2DB(testDBConfiguration);
|
||||||
|
DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||||
|
PoolProperties properties = new PoolProperties();
|
||||||
|
properties.setUrl(testDBConfiguration.getConnectionURL());
|
||||||
|
properties.setDriverClassName(testDBConfiguration.getDriverClassName());
|
||||||
|
properties.setUsername(testDBConfiguration.getUsername());
|
||||||
|
properties.setPassword(testDBConfiguration.getPassword());
|
||||||
|
testDataSource.setPoolProperties(properties);
|
||||||
|
mblOperationDAO = new MobileOperationDAOImpl(testDataSource);
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addMobileOperationTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
MobileOperation mblOperation = new MobileOperation();
|
||||||
|
MobileOperation testMblOperation = new MobileOperation();
|
||||||
|
mblOperation.setFeatureCode(TEST_MBL_OPR_FEATURE_CODE);
|
||||||
|
mblOperation.setCreatedDate(TEST_MBL_OPR_CREATED_DATE);
|
||||||
|
mblOperationId = mblOperationDAO.addMobileOperation(mblOperation);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE OPERATION_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setInt(1, mblOperationId);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
testMblOperation.setOperationId(resultSet.getInt(1));
|
||||||
|
testMblOperation.setFeatureCode(resultSet.getString(2));
|
||||||
|
testMblOperation.setCreatedDate(resultSet.getLong(3));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving Mobile Operation data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(mblOperationId > 0, "MobileOperation has added ");
|
||||||
|
Assert.assertEquals(TEST_MBL_OPR_FEATURE_CODE, testMblOperation.getFeatureCode(),
|
||||||
|
"MobileOperation feature code has persisted ");
|
||||||
|
Assert.assertEquals(TEST_MBL_OPR_CREATED_DATE, testMblOperation.getCreatedDate(),
|
||||||
|
"MobileOperation created-date has persisted ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileOperationTest" })
|
||||||
|
public void getMobileOperationTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
|
MobileOperation mobileOperation = mblOperationDAO.getMobileOperation(mblOperationId);
|
||||||
|
Assert.assertEquals(TEST_MBL_OPR_CREATED_DATE, mobileOperation.getCreatedDate(),
|
||||||
|
"MobileOperation created-date has retrieved ");
|
||||||
|
Assert.assertEquals(TEST_MBL_OPR_FEATURE_CODE, mobileOperation.getFeatureCode(),
|
||||||
|
"MobileOperation feature-code has retrieved ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileOperationTest", "getMobileOperationTest" })
|
||||||
|
public void updateMobileOperationTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
long updatedDate = new java.util.Date().getTime();
|
||||||
|
MobileOperation mblOperation = new MobileOperation();
|
||||||
|
MobileOperation testMblOperation = new MobileOperation();
|
||||||
|
mblOperation.setFeatureCode(TEST_MBL_OPR_UPDATED_FEATURE_CODE);
|
||||||
|
mblOperation.setCreatedDate(updatedDate);
|
||||||
|
mblOperation.setOperationId(mblOperationId);
|
||||||
|
boolean status = mblOperationDAO.updateMobileOperation(mblOperation);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE OPERATION_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setInt(1, mblOperationId);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
testMblOperation.setOperationId(resultSet.getInt(1));
|
||||||
|
testMblOperation.setFeatureCode(resultSet.getString(2));
|
||||||
|
testMblOperation.setCreatedDate(resultSet.getLong(3));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving Mobile Operation data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status, "MobileOperation has updated ");
|
||||||
|
Assert.assertEquals(TEST_MBL_OPR_UPDATED_FEATURE_CODE, testMblOperation.getFeatureCode(),
|
||||||
|
"MobileOperation feature code has updated ");
|
||||||
|
Assert.assertEquals(updatedDate, testMblOperation.getCreatedDate(),
|
||||||
|
"MobileOperation created-date has updated ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileOperationTest", "getMobileOperationTest",
|
||||||
|
"updateMobileOperationTest" })
|
||||||
|
public void deleteMobileDeviceTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
boolean deleted = mblOperationDAO.deleteMobileOperation(mblOperationId);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE OPERATION_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setInt(1, mblOperationId);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
deleted = false;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving Mobile Operation data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(deleted, "MobileOperation has deleted ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,5 +18,220 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl.dao;
|
package org.wso2.carbon.device.mgt.mobile.impl.dao;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.tomcat.jdbc.pool.DataSource;
|
||||||
|
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Parameters;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileOperationDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.MobileOperationPropertyDAOImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperation;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileOperationProperty;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDatabaseUtils;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Class for holding unit-tests related to MobileOperationPropertyDAO class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class MobileOperationPropertyDAOTestSuite {
|
public class MobileOperationPropertyDAOTestSuite {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(MobileOperationPropertyDAOTestSuite.class);
|
||||||
|
public static final String TEST_MBL_OPR_FEATURE_CODE = "LOCK";
|
||||||
|
public static final long TEST_MBL_OPR_CREATED_DATE = new java.util.Date().getTime();
|
||||||
|
public static final String TEST_MBL_OPR_PROPERTY_SSID = "SSID";
|
||||||
|
public static final String TEST_MBL_OPR_PROPERTY_SSID_VALUE = "wso2";
|
||||||
|
public static final String TEST_MBL_OPR_PROPERTY_PWD = "PASSWORD";
|
||||||
|
public static final String TEST_MBL_OPR_PROPERTY_PWD_VALUE = "wso2";
|
||||||
|
public static final String TEST_MBL_OPR_PROPERTY_PWD_UPDATED_VALUE = "wso2mdm";
|
||||||
|
private int mblOperationId;
|
||||||
|
private TestDBConfiguration testDBConfiguration;
|
||||||
|
private MobileOperationPropertyDAOImpl mobileOperationPropertyDAO;
|
||||||
|
private MobileOperationDAOImpl mblOperationDAO;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@Parameters("dbType")
|
||||||
|
public void setUpDB(String dbTypeStr) throws Exception {
|
||||||
|
|
||||||
|
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||||
|
testDBConfiguration = MobileDatabaseUtils.getTestDBConfiguration(dbType);
|
||||||
|
|
||||||
|
switch (dbType) {
|
||||||
|
case H2:
|
||||||
|
MobileDatabaseUtils.createH2DB(testDBConfiguration);
|
||||||
|
DataSource testDataSource = new org.apache.tomcat.jdbc.pool.DataSource();
|
||||||
|
PoolProperties properties = new PoolProperties();
|
||||||
|
properties.setUrl(testDBConfiguration.getConnectionURL());
|
||||||
|
properties.setDriverClassName(testDBConfiguration.getDriverClassName());
|
||||||
|
properties.setUsername(testDBConfiguration.getUsername());
|
||||||
|
properties.setPassword(testDBConfiguration.getPassword());
|
||||||
|
testDataSource.setPoolProperties(properties);
|
||||||
|
mobileOperationPropertyDAO = new MobileOperationPropertyDAOImpl(testDataSource);
|
||||||
|
mblOperationDAO = new MobileOperationDAOImpl(testDataSource);
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addMobileOperationPropertyTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
MobileOperation mblOperation = new MobileOperation();
|
||||||
|
MobileOperationProperty operationProperty = new MobileOperationProperty();
|
||||||
|
List<MobileOperationProperty> properties = new ArrayList<MobileOperationProperty>();
|
||||||
|
//Add a new Operation to the database
|
||||||
|
MobileOperation testMblOperation = new MobileOperation();
|
||||||
|
mblOperation.setFeatureCode(TEST_MBL_OPR_FEATURE_CODE);
|
||||||
|
mblOperation.setCreatedDate(TEST_MBL_OPR_CREATED_DATE);
|
||||||
|
mblOperationId = mblOperationDAO.addMobileOperation(mblOperation);
|
||||||
|
//Add property1
|
||||||
|
operationProperty.setOperationId(mblOperationId);
|
||||||
|
operationProperty.setProperty(TEST_MBL_OPR_PROPERTY_SSID);
|
||||||
|
operationProperty.setValue(TEST_MBL_OPR_PROPERTY_SSID_VALUE);
|
||||||
|
boolean status1 = mobileOperationPropertyDAO.addMobileOperationProperty(operationProperty);
|
||||||
|
|
||||||
|
//add property2
|
||||||
|
operationProperty = new MobileOperationProperty();
|
||||||
|
operationProperty.setOperationId(mblOperationId);
|
||||||
|
operationProperty.setProperty(TEST_MBL_OPR_PROPERTY_PWD);
|
||||||
|
operationProperty.setValue(TEST_MBL_OPR_PROPERTY_PWD_VALUE);
|
||||||
|
boolean status2 = mobileOperationPropertyDAO.addMobileOperationProperty(operationProperty);
|
||||||
|
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE OPERATION_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setInt(1, mblOperationId);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
operationProperty = new MobileOperationProperty();
|
||||||
|
operationProperty.setOperationId(resultSet.getInt(1));
|
||||||
|
operationProperty.setProperty(resultSet.getString(2));
|
||||||
|
operationProperty.setValue(resultSet.getString(3));
|
||||||
|
properties.add(operationProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving Mobile Operation Property data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status1, "MobileOperationProperty1 has added ");
|
||||||
|
Assert.assertTrue(status2, "MobileOperationProperty2 has added ");
|
||||||
|
Assert.assertTrue(properties.size() == 2, "MobileOperationProperties have retrieved ");
|
||||||
|
|
||||||
|
for (MobileOperationProperty mobileOperationProperty : properties) {
|
||||||
|
Assert.assertNotNull(mobileOperationProperty.getProperty(),
|
||||||
|
"MobileOperationProperty property has persisted ");
|
||||||
|
Assert.assertNotNull(mobileOperationProperty.getValue(),
|
||||||
|
"MobileOperationProperty value has persisted ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileOperationPropertyTest" })
|
||||||
|
public void getMobileOperationPropertyTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
MobileOperationProperty mobileOperationProperty = mobileOperationPropertyDAO
|
||||||
|
.getMobileOperationProperty(mblOperationId, TEST_MBL_OPR_PROPERTY_PWD);
|
||||||
|
Assert.assertEquals(mblOperationId, mobileOperationProperty.getOperationId(),
|
||||||
|
"MobileOperationProperty operation-id has retrieved ");
|
||||||
|
Assert.assertEquals(TEST_MBL_OPR_PROPERTY_PWD, mobileOperationProperty.getProperty(),
|
||||||
|
"MobileOperationProperty property has retrieved ");
|
||||||
|
Assert.assertEquals(TEST_MBL_OPR_PROPERTY_PWD_VALUE, mobileOperationProperty.getValue(),
|
||||||
|
"MobileOperationProperty property-value has retrieved ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileOperationPropertyTest" })
|
||||||
|
public void getAllMobileOperationPropertiesOfOperationTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
List<MobileOperationProperty> mobileOperationProperties = mobileOperationPropertyDAO
|
||||||
|
.getAllMobileOperationPropertiesOfOperation(mblOperationId);
|
||||||
|
Assert.assertTrue(mobileOperationProperties.size() == 2,
|
||||||
|
"MobileOperationProperties of operation has retrieved");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileOperationPropertyTest", "getMobileOperationPropertyTest",
|
||||||
|
"getAllMobileOperationPropertiesOfOperationTest" })
|
||||||
|
public void updateMobileOperationPropertyTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
MobileOperationProperty mblOperationProperty = new MobileOperationProperty();
|
||||||
|
MobileOperationProperty testMblOperationProperty = new MobileOperationProperty();
|
||||||
|
mblOperationProperty.setOperationId(mblOperationId);
|
||||||
|
mblOperationProperty.setProperty(TEST_MBL_OPR_PROPERTY_PWD);
|
||||||
|
mblOperationProperty.setValue(TEST_MBL_OPR_PROPERTY_PWD_UPDATED_VALUE);
|
||||||
|
|
||||||
|
boolean status =
|
||||||
|
mobileOperationPropertyDAO.updateMobileOperationProperty(mblOperationProperty);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE" +
|
||||||
|
" OPERATION_ID = ? AND PROPERTY = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setInt(1, mblOperationId);
|
||||||
|
preparedStatement.setString(2, TEST_MBL_OPR_PROPERTY_PWD);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
testMblOperationProperty.setOperationId(resultSet.getInt(1));
|
||||||
|
testMblOperationProperty.setProperty(resultSet.getString(2));
|
||||||
|
testMblOperationProperty.setValue(resultSet.getString(3));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving MobileOperationProperty data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status, "MobileOperationProperty has updated ");
|
||||||
|
Assert.assertEquals(TEST_MBL_OPR_PROPERTY_PWD_UPDATED_VALUE,
|
||||||
|
testMblOperationProperty.getValue(),
|
||||||
|
"MobileOperationProperty value has updated ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = { "addMobileOperationPropertyTest", "getMobileOperationPropertyTest",
|
||||||
|
"getAllMobileOperationPropertiesOfOperationTest",
|
||||||
|
"updateMobileOperationPropertyTest" })
|
||||||
|
public void deleteMobileOperationPropertiesOfOperationTest()
|
||||||
|
throws MobileDeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
boolean status =
|
||||||
|
mobileOperationPropertyDAO.deleteMobileOperationProperties(mblOperationId);
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(testDBConfiguration.getConnectionURL());
|
||||||
|
String selectDBQuery =
|
||||||
|
"SELECT OPERATION_ID, PROPERTY, VALUE FROM MBL_OPERATION_PROPERTY WHERE" +
|
||||||
|
" OPERATION_ID = ?";
|
||||||
|
preparedStatement = conn.prepareStatement(selectDBQuery);
|
||||||
|
preparedStatement.setInt(1, mblOperationId);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
if (resultSet.next()) {
|
||||||
|
status = false;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error in retrieving MobileOperationProperty data ";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new MobileDeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
MobileDatabaseUtils.cleanupResources(conn, preparedStatement, null);
|
||||||
|
}
|
||||||
|
Assert.assertTrue(status, "MobileOperationProperty has deleted ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.mobile.impl.dao.util;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.DBTypes;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.common.TestDBConfigurations;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
import java.io.File;
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides the utility methods needed for DAO related test executions.
|
||||||
|
*/
|
||||||
|
public class MobileDatabaseUtils {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(MobileDatabaseUtils.class);
|
||||||
|
public static final String TEST_RESOURCES_DB_CONFIG_FILE =
|
||||||
|
"src/test/resources/testdbconfig.xml";
|
||||||
|
|
||||||
|
public static void cleanupResources(Connection conn, Statement stmt, ResultSet rs) {
|
||||||
|
if (rs != null) {
|
||||||
|
try {
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.warn("Error occurred while closing result set", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stmt != null) {
|
||||||
|
try {
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.warn("Error occurred while closing prepared statement", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (conn != null) {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.warn("Error occurred while closing database connection", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws
|
||||||
|
MobileDeviceManagementDAOException,
|
||||||
|
DeviceManagementException {
|
||||||
|
File deviceMgtConfig = new File(TEST_RESOURCES_DB_CONFIG_FILE);
|
||||||
|
Document doc;
|
||||||
|
TestDBConfiguration testDBConfiguration = null;
|
||||||
|
TestDBConfigurations testDBConfigurations;
|
||||||
|
|
||||||
|
doc = MobileDeviceManagementUtil.convertToDocument(deviceMgtConfig);
|
||||||
|
JAXBContext testDBContext;
|
||||||
|
|
||||||
|
try {
|
||||||
|
testDBContext = JAXBContext.newInstance(TestDBConfigurations.class);
|
||||||
|
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();
|
||||||
|
testDBConfigurations = (TestDBConfigurations) unmarshaller.unmarshal(doc);
|
||||||
|
} catch (JAXBException e) {
|
||||||
|
throw new MobileDeviceManagementDAOException("Error parsing test db configurations", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TestDBConfiguration testDBConfiguration1 : testDBConfigurations.getDbTypesList()) {
|
||||||
|
testDBConfiguration = testDBConfiguration1;
|
||||||
|
if (testDBConfiguration.getType().equals(dbType.toString())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return testDBConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createH2DB(TestDBConfiguration testDBConf) throws Exception {
|
||||||
|
Connection conn = null;
|
||||||
|
Statement stmt = null;
|
||||||
|
try {
|
||||||
|
Class.forName(testDBConf.getDriverClassName());
|
||||||
|
conn = DriverManager.getConnection(testDBConf.getConnectionURL());
|
||||||
|
stmt = conn.createStatement();
|
||||||
|
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'");
|
||||||
|
} finally {
|
||||||
|
cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,6 +23,7 @@ CREATE TABLE IF NOT EXISTS `MBL_FEATURE` (
|
|||||||
`CODE` VARCHAR(45) NOT NULL,
|
`CODE` VARCHAR(45) NOT NULL,
|
||||||
`NAME` VARCHAR(100) NULL ,
|
`NAME` VARCHAR(100) NULL ,
|
||||||
`DESCRIPTION` VARCHAR(200) NULL ,
|
`DESCRIPTION` VARCHAR(200) NULL ,
|
||||||
|
`DEVICE_TYPE` VARCHAR(50) NULL ,
|
||||||
PRIMARY KEY (`FEATURE_ID`) );
|
PRIMARY KEY (`FEATURE_ID`) );
|
||||||
|
|
||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
@ -74,7 +75,7 @@ CREATE TABLE IF NOT EXISTS `MBL_OPERATION_PROPERTY` (
|
|||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` (
|
CREATE TABLE IF NOT EXISTS `MBL_FEATURE_PROPERTY` (
|
||||||
`PROPERTY` VARCHAR(45) NOT NULL ,
|
`PROPERTY` VARCHAR(45) NOT NULL ,
|
||||||
`FEATURE_ID` VARCHAR(45) NOT NULL ,
|
`FEATURE_ID` INT NOT NULL ,
|
||||||
PRIMARY KEY (`PROPERTY`) ,
|
PRIMARY KEY (`PROPERTY`) ,
|
||||||
CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1`
|
CONSTRAINT `fk_MBL_FEATURE_PROPERTY_MBL_FEATURE1`
|
||||||
FOREIGN KEY (`FEATURE_ID` )
|
FOREIGN KEY (`FEATURE_ID` )
|
||||||
|
|||||||
@ -25,11 +25,16 @@
|
|||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
|
|
||||||
<!--test name="DAO Unit Tests" preserve-order="true">
|
<test name="DAO Unit Tests" preserve-order="true">
|
||||||
<parameter name="dbType" value="H2"/>
|
<parameter name="dbType" value="H2"/>
|
||||||
<classes>
|
<classes>
|
||||||
<class name="org.wso2.carbon.device.mgt.mobile.impl.dao.MobileFeatureDAOTestSuite"/>
|
<class name="org.wso2.carbon.device.mgt.mobile.impl.dao.MobileFeatureDAOTestSuite"/>
|
||||||
|
<class name="org.wso2.carbon.device.mgt.mobile.impl.dao.MobileDeviceDAOTestSuite"/>
|
||||||
|
<class name="org.wso2.carbon.device.mgt.mobile.impl.dao.MobileOperationDAOTestSuite"/>
|
||||||
|
<class name="org.wso2.carbon.device.mgt.mobile.impl.dao.MobileOperationPropertyDAOTestSuite"/>
|
||||||
|
<class name="org.wso2.carbon.device.mgt.mobile.impl.dao.MobileFeaturePropertyDAOTestSuite"/>
|
||||||
|
<class name="org.wso2.carbon.device.mgt.mobile.impl.dao.MobileDeviceOperationMappingDAOTestSuite"/>
|
||||||
</classes>
|
</classes>
|
||||||
</test-->
|
</test>
|
||||||
|
|
||||||
</suite>
|
</suite>
|
||||||
@ -17,7 +17,9 @@
|
|||||||
~ under the License.
|
~ under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
|
|||||||
7
pom.xml
7
pom.xml
@ -17,7 +17,9 @@
|
|||||||
~ under the License.
|
~ under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
||||||
@ -488,7 +490,8 @@
|
|||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<url>https://github.com/wso2/carbon-device-mgt-plugins.git</url>
|
<url>https://github.com/wso2/carbon-device-mgt-plugins.git</url>
|
||||||
<developerConnection>scm:git:https://github.com/wso2/carbon-device-mgt-plugins.git</developerConnection>
|
<developerConnection>scm:git:https://github.com/wso2/carbon-device-mgt-plugins.git
|
||||||
|
</developerConnection>
|
||||||
<connection>scm:git:https://github.com/wso2/carbon-device-mgt-plugins.git</connection>
|
<connection>scm:git:https://github.com/wso2/carbon-device-mgt-plugins.git</connection>
|
||||||
<tag>HEAD</tag>
|
<tag>HEAD</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user