Added feature addition to the plugin initialization.

revert-dabc3590
harshanl 9 years ago
parent c47ace254c
commit 78f0ba2cdf

@ -30,7 +30,7 @@ public interface MobileDeviceManagementDAOFactoryInterface {
public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO(); public MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO();
public MobileFeatureDAO getMobileFeatureDao(); public MobileFeatureDAO getMobileFeatureDAO();
public MobileFeaturePropertyDAO getFeaturePropertyDAO(); public MobileFeaturePropertyDAO getFeaturePropertyDAO();

@ -32,11 +32,20 @@ public interface MobileFeatureDAO {
* Adds a new MobileFeature to Mobile-Feature table. * Adds a new MobileFeature to Mobile-Feature table.
* *
* @param mobileFeature MobileFeature 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 id of inserted MobileFeature. * @return boolean status of the operation.
* @throws MobileDeviceManagementDAOException * @throws MobileDeviceManagementDAOException
*/ */
boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException; boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException;
/**
* Adda a list of MobileFeatures to Mobile-Feature table.
*
* @param mobileFeatures List of MobileFeature objects.
* @return boolean status of the operation.
* @throws MobileDeviceManagementDAOException
*/
boolean addFeatures(List<MobileFeature> mobileFeatures) throws MobileDeviceManagementDAOException;
/** /**
* Updates a MobileFeature in Mobile-Feature table. * Updates a MobileFeature in Mobile-Feature table.
* *

@ -81,6 +81,11 @@ public class MobileFeatureDAOImpl implements MobileFeatureDAO {
return status; return status;
} }
@Override
public boolean addFeatures(List<MobileFeature> mobileFeatures) throws MobileDeviceManagementDAOException {
return false;
}
@Override @Override
public boolean updateFeature(MobileFeature mobileFeature) public boolean updateFeature(MobileFeature mobileFeature)
throws MobileDeviceManagementDAOException { throws MobileDeviceManagementDAOException {

@ -62,10 +62,13 @@ public class AndroidDeviceManager implements DeviceManager {
try { try {
licenseManager licenseManager
.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense); .addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense);
featureManager.addSupportedFeaturesToDB();
} catch (LicenseManagementException e) { } catch (LicenseManagementException e) {
log.error("Error occurred while adding default license for Android devices", e); log.error("Error occurred while adding default license for Android devices", e);
} } catch (DeviceManagementException e) {
} log.error("Error occurred while adding supported device features for Android platform", e);
}
}
@Override @Override
public FeatureManager getFeatureManager() { public FeatureManager getFeatureManager() {

@ -41,12 +41,11 @@ public class AndroidFeatureManager implements FeatureManager {
public AndroidFeatureManager() { public AndroidFeatureManager() {
mobileDeviceManagementDAOFactory = new AndroidDAOFactory(); mobileDeviceManagementDAOFactory = new AndroidDAOFactory();
this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDao(); this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDAO();
} }
@Override @Override
public boolean addFeature(Feature feature) throws DeviceManagementException { public boolean addFeature(Feature feature) throws DeviceManagementException {
try { try {
AndroidDAOFactory.beginTransaction(); AndroidDAOFactory.beginTransaction();
MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature); MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature);
@ -63,11 +62,32 @@ public class AndroidFeatureManager implements FeatureManager {
} }
} }
@Override
public boolean addFeatures(List<Feature> features) throws DeviceManagementException {
List<MobileFeature> mobileFeatures = new ArrayList<MobileFeature>();
for (Feature feature:features) {
mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature));
}
try {
AndroidDAOFactory.beginTransaction();
featureDAO.addFeatures(mobileFeatures);
AndroidDAOFactory.commitTransaction();
return true;
} catch (MobileDeviceManagementDAOException e) {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException e1) {
log.warn("Error occurred while roll-backing the transaction", e);
}
throw new DeviceManagementException("Error occurred while adding the features", e);
}
}
@Override @Override
public Feature getFeature(String name) throws DeviceManagementException { public Feature getFeature(String name) throws DeviceManagementException {
try { try {
MobileFeature mobileFeature = featureDAO.getFeatureByCode(name); MobileFeature mobileFeature = featureDAO.getFeatureByCode(name);
Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature); Feature feature = MobileDeviceManagementUtil.convertToFeature(mobileFeature);
return feature; return feature;
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while retrieving the feature", e); throw new DeviceManagementException("Error occurred while retrieving the feature", e);
@ -76,7 +96,6 @@ public class AndroidFeatureManager implements FeatureManager {
@Override @Override
public List<Feature> getFeatures() throws DeviceManagementException { public List<Feature> getFeatures() throws DeviceManagementException {
List<Feature> featureList = new ArrayList<Feature>(); List<Feature> featureList = new ArrayList<Feature>();
try { try {
List<MobileFeature> mobileFeatures = featureDAO.getAllFeatures(); List<MobileFeature> mobileFeatures = featureDAO.getAllFeatures();
@ -86,13 +105,13 @@ public class AndroidFeatureManager implements FeatureManager {
return featureList; return featureList;
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " + throw new DeviceManagementException("Error occurred while retrieving the list of features registered for " +
"Android platform", e); "Android platform", e);
} }
} }
@Override @Override
public boolean removeFeature(String code) throws DeviceManagementException { public boolean removeFeature(String code) throws DeviceManagementException {
boolean status = false; boolean status;
try { try {
AndroidDAOFactory.beginTransaction(); AndroidDAOFactory.beginTransaction();
featureDAO.deleteFeatureByCode(code); featureDAO.deleteFeatureByCode(code);
@ -109,4 +128,115 @@ public class AndroidFeatureManager implements FeatureManager {
return status; return status;
} }
@Override
public boolean addSupportedFeaturesToDB() throws DeviceManagementException {
synchronized (this) {
List<Feature> supportedFeatures = getSupportedFeatures();
List<Feature> existingFeatures = this.getFeatures();
List<Feature> missingFeatures = MobileDeviceManagementUtil.
getMissingFeatures(supportedFeatures, existingFeatures);
return this.addFeatures(missingFeatures);
}
}
//Get the supported feature list.
private static List<Feature> getSupportedFeatures() {
List<Feature> supportedFeatures = new ArrayList<Feature>();
Feature feature = new Feature();
feature.setCode("DEVICE_LOCK");
feature.setName("Device Lock");
feature.setDescription("Lock the device");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("DEVICE_LOCATION");
feature.setName("Location");
feature.setDescription("Request coordinates of device location");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("WIFI");
feature.setName("wifi");
feature.setDescription("Setting up wifi configuration");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("CAMERA");
feature.setName("camera");
feature.setDescription("Enable or disable camera");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("EMAIL");
feature.setName("Email");
feature.setDescription("Configure email settings");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("DEVICE_MUTE");
feature.setName("mute");
feature.setDescription("Enable mute in the device");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("DEVICE_INFO");
feature.setName("Device info");
feature.setDescription("Request device information");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("ENTERPRISE_WIPE");
feature.setName("Enterprise Wipe");
feature.setDescription("Remove enterprise applications");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("CLEAR_PASSWORD");
feature.setName("Clear Password");
feature.setDescription("Clear current password");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("WIPE_DATA");
feature.setName("Wipe Data");
feature.setDescription("Factory reset the device");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("APPLICATION_LIST");
feature.setName("Application List");
feature.setDescription("Request list of current installed applications");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("CHANGE_LOCK_CODE");
feature.setName("Change Lock-code");
feature.setDescription("Change current lock code");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("INSTALL_APPLICATION");
feature.setName("Install App");
feature.setDescription("Install Enterprise or Market application");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("UNINSTALL_APPLICATION");
feature.setName("Uninstall App");
feature.setDescription("Uninstall application");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("BLACKLIST_APPLICATIONS");
feature.setName("Blacklist app");
feature.setDescription("Blacklist applications");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("ENCRYPT_STORAGE");
feature.setName("Encrypt storage");
feature.setDescription("Encrypt storage");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("DEVICE_RING");
feature.setName("Ring");
feature.setDescription("Ring the device");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("PASSCODE_POLICY");
feature.setName("Password Policy");
feature.setDescription("Set passcode policy");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("NOTIFICATION");
feature.setName("Message");
feature.setDescription("Send message");
supportedFeatures.add(feature);
return supportedFeatures;
}
} }

@ -60,7 +60,8 @@ public class AndroidDAOFactory extends MobileDeviceManagementDAOFactory
return null; return null;
} }
@Override public MobileFeatureDAO getMobileFeatureDao() { @Override
public MobileFeatureDAO getMobileFeatureDAO() {
return new AndroidFeatureDAOImpl(); return new AndroidFeatureDAOImpl();
} }

@ -48,10 +48,9 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
@Override @Override
public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
boolean status = false; boolean status = false;
Connection conn = null; Connection conn;
try { try {
conn = AndroidDAOFactory.getConnection(); conn = AndroidDAOFactory.getConnection();
String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
@ -61,11 +60,37 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
stmt.setString(3, mobileFeature.getDescription()); stmt.setString(3, mobileFeature.getDescription());
stmt.executeUpdate(); stmt.executeUpdate();
status = true; status = true;
status = true;
} catch (SQLException e) { } catch (SQLException e) {
throw new AndroidFeatureManagementDAOException( throw new AndroidFeatureManagementDAOException(
"Error occurred while adding android feature '" + "Error occurred while adding android feature '" +
mobileFeature.getName() + "' into the metadata repository", e); mobileFeature.getName() + "' into the metadata repository", e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
}
return status;
}
@Override
public boolean addFeatures(List<MobileFeature> mobileFeatures) throws MobileDeviceManagementDAOException {
PreparedStatement stmt = null;
MobileFeature mobileFeature;
boolean status = false;
Connection conn;
try {
conn = AndroidDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)");
for (int i = 0; i < mobileFeatures.size(); i++) {
mobileFeature = mobileFeatures.get(i);
stmt.setString(1, mobileFeature.getCode());
stmt.setString(2, mobileFeature.getName());
stmt.setString(3, mobileFeature.getDescription());
stmt.addBatch();
}
stmt.executeBatch();
status = true;
} catch (SQLException e) {
throw new AndroidFeatureManagementDAOException(
"Error occurred while adding android features into the metadata repository", e);
} finally { } finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
} }
@ -75,7 +100,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
@Override @Override
public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
Connection conn = null; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = AndroidDAOFactory.getConnection(); conn = AndroidDAOFactory.getConnection();
@ -112,7 +137,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
boolean status = false; boolean status = false;
Connection conn = null; Connection conn;
try { try {
conn = AndroidDAOFactory.getConnection(); conn = AndroidDAOFactory.getConnection();
String sql = "DELETE FROM AD_FEATURE WHERE ID = ?"; String sql = "DELETE FROM AD_FEATURE WHERE ID = ?";
@ -135,7 +160,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
MobileDeviceManagementDAOException { MobileDeviceManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
boolean status = false; boolean status = false;
Connection conn = null; Connection conn;
try { try {
conn = AndroidDAOFactory.getConnection(); conn = AndroidDAOFactory.getConnection();
String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?"; String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?";
@ -146,7 +171,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
} catch (SQLException e) { } catch (SQLException e) {
throw new AndroidFeatureManagementDAOException( throw new AndroidFeatureManagementDAOException(
"Error occurred while deleting android feature '" + "Error occurred while deleting android feature '" +
mblFeatureCode + "' from Android database.", e); mblFeatureCode + "' from Android database.", e);
} finally { } finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null); MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
} }
@ -158,7 +183,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
MobileDeviceManagementDAOException { MobileDeviceManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Connection conn = null; Connection conn;
try { try {
conn = AndroidDAOFactory.getConnection(); conn = AndroidDAOFactory.getConnection();
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE ID = ?"; String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE ID = ?";
@ -193,7 +218,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
MobileDeviceManagementDAOException { MobileDeviceManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Connection conn = null; Connection conn;
try { try {
conn = AndroidDAOFactory.getConnection(); conn = AndroidDAOFactory.getConnection();
@ -217,7 +242,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
} catch (SQLException e) { } catch (SQLException e) {
throw new AndroidFeatureManagementDAOException( throw new AndroidFeatureManagementDAOException(
"Error occurred while retrieving android feature '" + "Error occurred while retrieving android feature '" +
mblFeatureCode + "' from the Android database.", e); mblFeatureCode + "' from the Android database.", e);
} finally { } finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
AndroidDAOFactory.closeConnection(); AndroidDAOFactory.closeConnection();
@ -235,7 +260,7 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Connection conn = null; Connection conn;
List<MobileFeature> features = new ArrayList<MobileFeature>(); List<MobileFeature> features = new ArrayList<MobileFeature>();
try { try {
@ -259,10 +284,10 @@ public class AndroidFeatureDAOImpl implements MobileFeatureDAO {
return features; return features;
} catch (SQLException e) { } catch (SQLException e) {
throw new AndroidFeatureManagementDAOException("Error occurred while retrieving all " + throw new AndroidFeatureManagementDAOException("Error occurred while retrieving all " +
"android features from the android database.", e); "android features from the android database.", e);
} finally { } finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs); MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
AndroidDAOFactory.closeConnection(); AndroidDAOFactory.closeConnection();
} }
} }
} }

@ -41,7 +41,7 @@ public class WindowsFeatureManager implements FeatureManager {
public WindowsFeatureManager() { public WindowsFeatureManager() {
mobileDeviceManagementDAOFactory = new WindowsDAOFactory(); mobileDeviceManagementDAOFactory = new WindowsDAOFactory();
this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDao(); this.featureDAO = mobileDeviceManagementDAOFactory.getMobileFeatureDAO();
} }
@Override @Override
@ -59,6 +59,11 @@ public class WindowsFeatureManager implements FeatureManager {
} }
} }
@Override
public boolean addFeatures(List<Feature> list) throws DeviceManagementException {
return false;
}
@Override @Override
public Feature getFeature(String name) throws DeviceManagementException { public Feature getFeature(String name) throws DeviceManagementException {
try { try {
@ -88,7 +93,7 @@ public class WindowsFeatureManager implements FeatureManager {
@Override @Override
public boolean removeFeature(String code) throws DeviceManagementException { public boolean removeFeature(String code) throws DeviceManagementException {
boolean status = false; boolean status;
try { try {
WindowsDAOFactory.beginTransaction(); WindowsDAOFactory.beginTransaction();
featureDAO.deleteFeatureByCode(code); featureDAO.deleteFeatureByCode(code);
@ -101,4 +106,9 @@ public class WindowsFeatureManager implements FeatureManager {
return status; return status;
} }
@Override
public boolean addSupportedFeaturesToDB() throws DeviceManagementException {
return false;
}
} }

@ -60,7 +60,7 @@ public class WindowsDAOFactory extends MobileDeviceManagementDAOFactory
} }
@Override @Override
public MobileFeatureDAO getMobileFeatureDao() { public MobileFeatureDAO getMobileFeatureDAO() {
return null; return null;
} }

@ -298,4 +298,19 @@ public class MobileDeviceManagementUtil {
e.getMessage(), e); e.getMessage(), e);
} }
} }
public static List<Feature> getMissingFeatures(List<Feature> supportedFeatures, List<Feature> existingFeatures) {
HashMap<String,Feature> featureHashMap = new HashMap();
for (Feature feature: existingFeatures) {
featureHashMap.put(feature.getCode(),feature);
}
List<Feature> missingFeatures = new ArrayList<Feature>();
for (Feature supportedFeature : supportedFeatures) {
if (featureHashMap.get(supportedFeature.getCode()) != null) {
continue;
}
missingFeatures.add(supportedFeature);
}
return missingFeatures;
}
} }

@ -19,53 +19,17 @@
<MobileDeviceMgtConfiguration> <MobileDeviceMgtConfiguration>
<ManagementRepository> <ManagementRepository>
<DataSourceConfigurations> <DataSourceConfigurations>
<DataSourceConfiguration type="android"> <DataSourceConfiguration type="android">
<JndiLookupDefinition> <JndiLookupDefinition>
<Name>jdbc/MobileAndroidDM_DS</Name> <Name>jdbc/MobileAndroidDM_DS</Name>
</JndiLookupDefinition> </JndiLookupDefinition>
</DataSourceConfiguration> </DataSourceConfiguration>
<DataSourceConfiguration type="windows"> <DataSourceConfiguration type="windows">
<JndiLookupDefinition> <JndiLookupDefinition>
<Name>jdbc/MobileWindowsDM_DS</Name> <Name>jdbc/MobileWindowsDM_DS</Name>
</JndiLookupDefinition> </JndiLookupDefinition>
</DataSourceConfiguration> </DataSourceConfiguration>
</DataSourceConfigurations> </DataSourceConfigurations>
</ManagementRepository> </ManagementRepository>
<APIPublisher>
<APIs>
<API>
<Name>appmanager</Name>
<Owner>admin</Owner>
<Context>/devices</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/test/app</Endpoint>
<Transports>http,https</Transports>
</API>
<API>
<Name>enrol</Name>
<Owner>admin</Owner>
<Context>/enroll</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/mdm-android-agent/enrollment</Endpoint>
<Transports>http,https</Transports>
</API>
<API>
<Name>license</Name>
<Owner>admin</Owner>
<Context>/license</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/mdm-android-agent/devices/license</Endpoint>
<Transports>http,https</Transports>
</API>
<API>
<Name>operation</Name>
<Owner>admin</Owner>
<Context>/operation</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/mdm-android-agent/operations</Endpoint>
<Transports>http,https</Transports>
</API>
</APIs>
</APIPublisher>
</MobileDeviceMgtConfiguration> </MobileDeviceMgtConfiguration>

Loading…
Cancel
Save