refactored WindowsFeatureManager

revert-dabc3590
hasuniea 9 years ago
parent 7f66885f61
commit 9adfb05b37

@ -57,11 +57,16 @@ public class WindowsDeviceManager implements DeviceManager {
public WindowsDeviceManager() { public WindowsDeviceManager() {
this.daoFactory = new WindowsDAOFactory(); this.daoFactory = new WindowsDAOFactory();
this.licenseManager = new RegistryBasedLicenseManager(); this.licenseManager = new RegistryBasedLicenseManager();
License defaultLicense = WindowsPluginUtils.getDefaultLicense(); License defaultLicense = WindowsPluginUtils.getDefaultLicense();
try { try {
licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, defaultLicense); licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, defaultLicense);
featureManager.addSupportedFeaturesToDB();
} catch (LicenseManagementException e) { } catch (LicenseManagementException e) {
log.error("Error occurred while adding default license for Windows devices", e); log.error("Error occurred while adding default license for Windows devices", e);
} catch (DeviceManagementException e) {
log.error("Error occurred while adding supported device features for Windows platform", e);
} }
} }

@ -18,12 +18,9 @@
*/ */
package org.wso2.carbon.device.mgt.mobile.impl.windows; package org.wso2.carbon.device.mgt.mobile.impl.windows;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.mobile.dao.AbstractMobileDeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
@ -37,7 +34,6 @@ import java.util.List;
public class WindowsFeatureManager implements FeatureManager { public class WindowsFeatureManager implements FeatureManager {
private MobileFeatureDAO featureDAO; private MobileFeatureDAO featureDAO;
private static final Log log = LogFactory.getLog(WindowsFeatureManager.class);
public WindowsFeatureManager() { public WindowsFeatureManager() {
MobileDeviceManagementDAOFactory daoFactory = new WindowsDAOFactory(); MobileDeviceManagementDAOFactory daoFactory = new WindowsDAOFactory();
@ -59,8 +55,20 @@ public class WindowsFeatureManager implements FeatureManager {
} }
@Override @Override
public boolean addFeatures(List<Feature> list) throws DeviceManagementException { public boolean addFeatures(List<Feature> features) throws DeviceManagementException {
return false; List<MobileFeature> mobileFeatures = new ArrayList<MobileFeature>();
for (Feature feature : features) {
mobileFeatures.add(MobileDeviceManagementUtil.convertToMobileFeature(feature));
}
try {
WindowsDAOFactory.beginTransaction();
featureDAO.addFeatures(mobileFeatures);
WindowsDAOFactory.commitTransaction();
return true;
} catch (MobileDeviceManagementDAOException e) {
WindowsDAOFactory.rollbackTransaction();
throw new DeviceManagementException("Error occurred while adding the features", e);
}
} }
@Override @Override
@ -86,7 +94,7 @@ public class WindowsFeatureManager 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); "Windows platform", e);
} }
} }
@ -107,7 +115,64 @@ public class WindowsFeatureManager implements FeatureManager {
@Override @Override
public boolean addSupportedFeaturesToDB() throws DeviceManagementException { public boolean addSupportedFeaturesToDB() throws DeviceManagementException {
return false; synchronized (this) {
List<Feature> supportedFeatures = getSupportedFeatures();
List<Feature> existingFeatures = this.getFeatures();
List<Feature> missingFeatures = MobileDeviceManagementUtil.
getMissingFeatures(supportedFeatures, existingFeatures);
if (missingFeatures.size() > 0) {
return this.addFeatures(missingFeatures);
}
return true;
}
} }
public 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("CAMERA");
feature.setName("camera");
feature.setDescription("Enable or disable camera");
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("WIPE_DATA");
feature.setName("Wipe Data");
feature.setDescription("Factory reset the device");
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("DISENROLL");
feature.setName("DisEnroll");
feature.setDescription("DisEnroll the device");
supportedFeatures.add(feature);
feature = new Feature();
feature.setCode("LOCK_RESET");
feature.setName("LockReset");
feature.setDescription("Lock Reset device");
return supportedFeatures;
}
} }

@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceDAO;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO; import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsDeviceDAOImpl; import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsDeviceDAOImpl;
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.impl.WindowsFeatureDAOImpl;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.sql.Connection; import java.sql.Connection;
@ -48,7 +49,7 @@ public class WindowsDAOFactory extends AbstractMobileDeviceManagementDAOFactory
@Override @Override
public MobileFeatureDAO getMobileFeatureDAO() { public MobileFeatureDAO getMobileFeatureDAO() {
return null; return new WindowsFeatureDAOImpl();
} }
public static void beginTransaction() throws MobileDeviceManagementDAOException { public static void beginTransaction() throws MobileDeviceManagementDAOException {

@ -46,6 +46,7 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO {
public WindowsFeatureDAOImpl() { public WindowsFeatureDAOImpl() {
} }
@Override @Override
public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -53,7 +54,7 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO {
Connection conn; Connection conn;
try { try {
conn = WindowsDAOFactory.getConnection(); conn = WindowsDAOFactory.getConnection();
String sql = "INSERT INTO WINDOWS_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)"; String sql = "INSERT INTO WIN_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, mobileFeature.getCode()); stmt.setString(1, mobileFeature.getCode());
stmt.setString(2, mobileFeature.getName()); stmt.setString(2, mobileFeature.getName());
@ -71,6 +72,31 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO {
return status; return status;
} }
@Override
public boolean addFeatures(List<MobileFeature> mobileFeatures) throws MobileDeviceManagementDAOException {
PreparedStatement stmt = null;
boolean status = false;
Connection conn;
try {
conn = WindowsDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO WIN_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)");
for (MobileFeature mobileFeature : mobileFeatures) {
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 WindowsFeatureManagementDAOException(
"Error occurred while adding windows features into the metadata repository", e);
} finally {
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
}
return status;
}
@Override @Override
public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException { public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
boolean status = false; boolean status = false;
@ -79,7 +105,7 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO {
try { try {
conn = WindowsDAOFactory.getConnection(); conn = WindowsDAOFactory.getConnection();
String updateDBQuery = String updateDBQuery =
"UPDATE WINDOWS_FEATURE SET NAME = ?, DESCRIPTION = ?" + "UPDATE WIN_FEATURE SET NAME = ?, DESCRIPTION = ?" +
"WHERE CODE = ?"; "WHERE CODE = ?";
stmt = conn.prepareStatement(updateDBQuery); stmt = conn.prepareStatement(updateDBQuery);
@ -110,10 +136,10 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO {
public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
boolean status = false; boolean status = false;
Connection conn = null; Connection conn;
try { try {
conn = WindowsDAOFactory.getConnection(); conn = WindowsDAOFactory.getConnection();
String sql = "DELETE FROM WINDOWS_FEATURE WHERE FEATURE_ID = ?"; String sql = "DELETE FROM WIN_FEATURE WHERE FEATURE_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, mblFeatureId); stmt.setInt(1, mblFeatureId);
stmt.execute(); stmt.execute();
@ -132,10 +158,10 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO {
public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException { public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
boolean status = false; boolean status = false;
Connection conn = null; Connection conn;
try { try {
conn = WindowsDAOFactory.getConnection(); conn = WindowsDAOFactory.getConnection();
String sql = "DELETE FROM WINDOWS_FEATURE WHERE CODE = ?"; String sql = "DELETE FROM WIN_FEATURE WHERE CODE = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, mblFeatureCode); stmt.setString(1, mblFeatureCode);
stmt.execute(); stmt.execute();
@ -154,10 +180,10 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO {
public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException { public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Connection conn = null; Connection conn;
try { try {
conn = WindowsDAOFactory.getConnection(); conn = WindowsDAOFactory.getConnection();
String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WINDOWS_FEATURE WHERE ID = ?"; String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE WHERE ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, mblFeatureId); stmt.setInt(1, mblFeatureId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -191,7 +217,7 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO {
try { try {
conn = WindowsDAOFactory.getConnection(); conn = WindowsDAOFactory.getConnection();
String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WINDOWS_FEATURE WHERE CODE = ?"; String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE WHERE CODE = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, mblFeatureCode); stmt.setString(1, mblFeatureCode);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -231,7 +257,7 @@ public class WindowsFeatureDAOImpl implements MobileFeatureDAO {
try { try {
conn = WindowsDAOFactory.getConnection(); conn = WindowsDAOFactory.getConnection();
String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WINDOWS_FEATURE"; String sql = "SELECT FEATURE_ID, CODE, NAME, DESCRIPTION FROM WIN_FEATURE";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
MobileFeature mobileFeature; MobileFeature mobileFeature;

@ -1,7 +1,7 @@
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WINDOWS_FEATURE` -- Table `WINDOWS_FEATURE`
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE WINDOWS_FEATURE ( CREATE TABLE WIN_FEATURE (
ID INT NOT NULL IDENTITY, ID INT NOT NULL IDENTITY,
CODE VARCHAR(45) NOT NULL, CODE VARCHAR(45) NOT NULL,
NAME VARCHAR(100) NULL, NAME VARCHAR(100) NULL,
@ -12,7 +12,7 @@ CREATE TABLE WINDOWS_FEATURE (
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `WINDOWS_DEVICE` -- Table `WINDOWS_DEVICE`
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE WINDOWS_DEVICE ( CREATE TABLE WIN_DEVICE (
DEVICE_ID VARCHAR(45) NOT NULL, DEVICE_ID VARCHAR(45) NOT NULL,
CHANNEL_URI VARCHAR(100) NULL DEFAULT NULL, CHANNEL_URI VARCHAR(100) NULL DEFAULT NULL,
DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL, DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL,

@ -31,18 +31,5 @@ CREATE TABLE IF NOT EXISTS `WIN_FEATURE` (
PRIMARY KEY (`FEATURE_ID`)) PRIMARY KEY (`FEATURE_ID`))
ENGINE = InnoDB; ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `WIN_FEATURE_PROPERTY`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `WIN_FEATURE_PROPERTY` (
`PROPERTY` VARCHAR(45) NOT NULL ,
`FEATURE_ID` INT NOT NULL ,
PRIMARY KEY (`PROPERTY`),
CONSTRAINT `fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1`
FOREIGN KEY (`FEATURE_ID`)
REFERENCES `WIN_FEATURE` (`FEATURE_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

@ -32,20 +32,6 @@ CREATE TABLE WIN_FEATURE (
); );
/ /
-- -----------------------------------------------------
-- Table `WIN_FEATURE_PROPERTY`
-- -----------------------------------------------------
CREATE TABLE WIN_FEATURE_PROPERTY (
PROPERTY VARCHAR(45) NOT NULL,
FEATURE_ID INT NOT NULL,
PRIMARY KEY (PROPERTY),
CONSTRAINT fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1
FOREIGN KEY (FEATURE_ID)
REFERENCES WIN_FEATURE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
/
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Sequence `WIN_FEATURE_ID_INC_SEQ` -- Sequence `WIN_FEATURE_ID_INC_SEQ`
-- ----------------------------------------------------- -- -----------------------------------------------------

@ -30,16 +30,3 @@ CREATE TABLE IF NOT EXISTS WIN_FEATURE (
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
-- -----------------------------------------------------
-- Table `WIN_FEATURE_PROPERTY`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS WIN_FEATURE_PROPERTY (
PROPERTY VARCHAR(45) NOT NULL ,
FEATURE_ID INT NOT NULL ,
PRIMARY KEY (PROPERTY),
CONSTRAINT fk_WIN_FEATURE_PROPERTY_WIN_FEATURE1
FOREIGN KEY (FEATURE_ID)
REFERENCES WIN_FEATURE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);

Loading…
Cancel
Save