Adapting LicenseManager changes introduced in org.wso2.carbon.device.mgt.core and org.wso2.carbon.device.mgt.extensions

revert-dabc3590
prabathabey 9 years ago
parent d07c226dd5
commit 29a6f0706a

@ -76,6 +76,7 @@
org.wso2.carbon.registry.core.service, org.wso2.carbon.registry.core.service,
org.wso2.carbon.registry.core.session, org.wso2.carbon.registry.core.session,
org.wso2.carbon.registry.api, org.wso2.carbon.registry.api,
org.wso2.carbon.device.mgt.extensions.license.mgt
</Import-Package> </Import-Package>
<Export-Package> <Export-Package>
!org.wso2.carbon.device.mgt.mobile.internal, !org.wso2.carbon.device.mgt.mobile.internal,
@ -127,6 +128,10 @@
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId> <artifactId>org.wso2.carbon.device.mgt.common</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.extensions</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.wso2.carbon</groupId> <groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ndatasource.core</artifactId> <artifactId>org.wso2.carbon.ndatasource.core</artifactId>

@ -43,10 +43,11 @@ import java.util.List;
public class AndroidDeviceManagementService implements DeviceManagementService { public class AndroidDeviceManagementService implements DeviceManagementService {
private DeviceManager deviceManager; private DeviceManager deviceManager;
public static final String DEVICE_TYPE_ANDROID = "android";
@Override @Override
public String getType() { public String getType() {
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID; return AndroidDeviceManagementService.DEVICE_TYPE_ANDROID;
} }
@Override @Override

@ -24,13 +24,18 @@ import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.extensions.license.mgt.RegistryBasedLicenseManager;
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory; import org.wso2.carbon.device.mgt.mobile.impl.android.dao.AndroidDAOFactory;
import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
import org.wso2.carbon.registry.api.Collection; import org.wso2.carbon.registry.api.Collection;
import org.wso2.carbon.registry.api.Registry;
import org.wso2.carbon.registry.api.Resource; import org.wso2.carbon.registry.api.Resource;
import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.registry.api.RegistryException;
@ -39,295 +44,314 @@ import java.util.List;
public class AndroidDeviceManager implements DeviceManager { public class AndroidDeviceManager implements DeviceManager {
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory;
private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class); private static final Log log = LogFactory.getLog(AndroidDeviceManagementService.class);
private FeatureManager featureManager = new AndroidFeatureManager(); private FeatureManager featureManager = new AndroidFeatureManager();
private License license; private LicenseManager licenseManager;
public AndroidDeviceManager() { public AndroidDeviceManager() {
mobileDeviceManagementDAOFactory = new AndroidDAOFactory(); this.mobileDeviceManagementDAOFactory = new AndroidDAOFactory();
} try {
Registry registry =
MobileDeviceManagementDataHolder.getInstance().getRegistryService().getConfigSystemRegistry();
this.licenseManager = new RegistryBasedLicenseManager(registry);
} catch (org.wso2.carbon.registry.core.exceptions.RegistryException e) {
throw new IllegalStateException("Error occurred while retrieving config system registry of the tenant, " +
"which in turns fails the initialization of Android Device Manager", e);
}
}
@Override @Override
public FeatureManager getFeatureManager() { public FeatureManager getFeatureManager() {
return featureManager; return featureManager;
} }
@Override @Override
public boolean saveConfiguration(TenantConfiguration tenantConfiguration) public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
throws DeviceManagementException { throws DeviceManagementException {
boolean status = false; boolean status = false;
Resource resource; Resource resource;
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Persisting android configurations in Registry"); log.debug("Persisting android configurations in Registry");
} }
String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath( String resourcePath = MobileDeviceManagementUtil.getPlatformConfigPath(
DeviceManagementConstants. DeviceManagementConstants.
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
MobileDeviceManagementUtil.createRegistryCollection(resourcePath); MobileDeviceManagementUtil.createRegistryCollection(resourcePath);
for (ConfigurationEntry configEntry : tenantConfiguration.getConfiguration()) { for (ConfigurationEntry configEntry : tenantConfiguration.getConfiguration()) {
resource = MobileDeviceManagementUtil.getRegistry().newResource(); resource = MobileDeviceManagementUtil.getRegistry().newResource();
resource.setContent(configEntry.getValue()); resource.setContent(configEntry.getValue());
MobileDeviceManagementUtil.putRegistryResource(resourcePath + "/" + configEntry.getName(), resource); MobileDeviceManagementUtil.putRegistryResource(resourcePath + "/" + configEntry.getName(), resource);
} }
status = true; status = true;
} catch (MobileDeviceMgtPluginException e) { } catch (MobileDeviceMgtPluginException e) {
throw new DeviceManagementException( throw new DeviceManagementException(
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e); "Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
} catch (RegistryException e) { } catch (RegistryException e) {
throw new DeviceManagementException( throw new DeviceManagementException(
"Error occurred while persisting the Registry resource : " + e.getMessage(), e); "Error occurred while persisting the Registry resource : " + e.getMessage(), e);
} }
return status; return status;
} }
@Override @Override
public TenantConfiguration getConfiguration() throws DeviceManagementException { public TenantConfiguration getConfiguration() throws DeviceManagementException {
Collection dsCollection = null; Collection dsCollection = null;
TenantConfiguration tenantConfiguration; TenantConfiguration tenantConfiguration;
List<ConfigurationEntry> configs = new ArrayList<ConfigurationEntry>(); List<ConfigurationEntry> configs = new ArrayList<ConfigurationEntry>();
ConfigurationEntry entry; ConfigurationEntry entry;
Resource resource; Resource resource;
try { try {
String androidRegPath = MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants. String androidRegPath =
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants.
dsCollection = (Collection) MobileDeviceManagementUtil.getRegistryResource(androidRegPath); MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
String[] dsmPaths = dsCollection.getChildren(); dsCollection =
for (String dsmPath : dsmPaths) { (Collection) MobileDeviceManagementUtil.getRegistryResource(androidRegPath);
entry = new ConfigurationEntry(); String[] dsmPaths = dsCollection.getChildren();
resource = MobileDeviceManagementUtil.getRegistryResource(dsmPath); for (String dsmPath : dsmPaths) {
entry.setValue(resource.getContent()); entry = new ConfigurationEntry();
entry.setName(resource.getId()); resource = MobileDeviceManagementUtil.getRegistryResource(dsmPath);
configs.add(entry); entry.setValue(resource.getContent());
} entry.setName(resource.getId());
tenantConfiguration = new TenantConfiguration(); configs.add(entry);
tenantConfiguration.setConfiguration(configs); }
tenantConfiguration.setType(DeviceManagementConstants. tenantConfiguration = new TenantConfiguration();
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); tenantConfiguration.setConfiguration(configs);
} catch (MobileDeviceMgtPluginException e) { tenantConfiguration.setType(DeviceManagementConstants.
throw new DeviceManagementException( MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e); } catch (MobileDeviceMgtPluginException e) {
} catch (RegistryException e) { throw new DeviceManagementException(
throw new DeviceManagementException( "Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
"Error occurred while retrieving the Registry data : " + e.getMessage(), e); } catch (RegistryException e) {
} throw new DeviceManagementException(
return tenantConfiguration; "Error occurred while retrieving the Registry data : " + e.getMessage(), e);
} }
return tenantConfiguration;
}
@Override @Override
public boolean enrollDevice(Device device) throws DeviceManagementException { public boolean enrollDevice(Device device) throws DeviceManagementException {
boolean status; boolean status;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
} }
AndroidDAOFactory.beginTransaction(); AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice(
mobileDevice); mobileDevice);
AndroidDAOFactory.commitTransaction(); AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
try { try {
AndroidDAOFactory.rollbackTransaction(); AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) { } catch (MobileDeviceManagementDAOException mobileDAOEx) {
String msg = "Error occurred while roll back the device enrol transaction :" + String msg = "Error occurred while roll back the device enrol transaction :" +
device.toString(); device.toString();
log.warn(msg, mobileDAOEx); log.warn(msg, mobileDAOEx);
} }
String msg = String msg =
"Error while enrolling the Android device : " + device.getDeviceIdentifier(); "Error while enrolling the Android device : " + device.getDeviceIdentifier();
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return status; return status;
} }
@Override @Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException { public boolean modifyEnrollment(Device device) throws DeviceManagementException {
boolean status; boolean status;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Modifying the Android device enrollment data"); log.debug("Modifying the Android device enrollment data");
} }
AndroidDAOFactory.beginTransaction(); AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice);
.updateMobileDevice(mobileDevice); AndroidDAOFactory.commitTransaction();
AndroidDAOFactory.commitTransaction(); } catch (MobileDeviceManagementDAOException e) {
} catch (MobileDeviceManagementDAOException e) { try {
try { AndroidDAOFactory.rollbackTransaction();
AndroidDAOFactory.rollbackTransaction(); } catch (MobileDeviceManagementDAOException mobileDAOEx) {
} catch (MobileDeviceManagementDAOException mobileDAOEx) { String msg = "Error occurred while roll back the update device transaction :" +
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
device.toString(); log.warn(msg, mobileDAOEx);
log.warn(msg, mobileDAOEx); }
} String msg = "Error while updating the enrollment of the Android device : " +
String msg = "Error while updating the enrollment of the Android device : " + device.getDeviceIdentifier();
device.getDeviceIdentifier(); log.error(msg, e);
log.error(msg, e); throw new DeviceManagementException(msg, e);
throw new DeviceManagementException(msg, e); }
} return status;
return status; }
}
@Override @Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
boolean status; boolean status;
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Dis-enrolling Android device : " + deviceId); log.debug("Dis-enrolling Android device : " + deviceId);
} }
AndroidDAOFactory.beginTransaction(); AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO() status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.deleteMobileDevice(deviceId.getId()); .deleteMobileDevice(deviceId.getId());
AndroidDAOFactory.commitTransaction(); AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
try { try {
AndroidDAOFactory.rollbackTransaction(); AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) { } catch (MobileDeviceManagementDAOException mobileDAOEx) {
String msg = "Error occurred while roll back the device dis enrol transaction :" + String msg = "Error occurred while roll back the device dis enrol transaction :" +
deviceId.toString(); deviceId.toString();
log.warn(msg, mobileDAOEx); log.warn(msg, mobileDAOEx);
} }
String msg = "Error while removing the Android device : " + deviceId.getId(); String msg = "Error while removing the Android device : " + deviceId.getId();
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return status; return status;
} }
@Override @Override
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()) { if (log.isDebugEnabled()) {
log.debug("Checking the enrollment of Android device : " + deviceId.getId()); log.debug("Checking the enrollment of Android device : " + deviceId.getId());
} }
MobileDevice mobileDevice = MobileDevice mobileDevice =
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice( mobileDeviceManagementDAOFactory.getMobileDeviceDAO().getMobileDevice(
deviceId.getId()); deviceId.getId());
if (mobileDevice != null) { if (mobileDevice != null) {
isEnrolled = true; isEnrolled = true;
} }
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while checking the enrollment status of Android device : " + String msg = "Error while checking the enrollment status of Android device : " +
deviceId.getId(); deviceId.getId();
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return isEnrolled; return isEnrolled;
} }
@Override @Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
return true; return true;
} }
@Override @Override
public boolean setActive(DeviceIdentifier deviceId, boolean status) public boolean setActive(DeviceIdentifier deviceId, boolean status)
throws DeviceManagementException { throws DeviceManagementException {
return true; return true;
} }
@Override @Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
Device device; Device device;
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting the details of Android device : " + deviceId.getId()); 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);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while fetching the Android device : " + deviceId.getId(); String msg = "Error while fetching the Android device : " + deviceId.getId();
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
return device; return device;
} }
@Override @Override
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
throws DeviceManagementException { throws DeviceManagementException {
return true; return true;
} }
@Override @Override
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
return false; return false;
} }
@Override @Override
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser, public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
EnrolmentInfo.Status status) throws DeviceManagementException { EnrolmentInfo.Status status) throws DeviceManagementException {
return false; return false;
} }
@Override @Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) public License getLicense(String languageCode) throws LicenseManagementException {
throws DeviceManagementException { return licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode);
boolean status; }
Device deviceDB = this.getDevice(deviceIdentifier);
// This object holds the current persisted device object
MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB);
// This object holds the newly received device object from response @Override
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); public void addLicense(License license) throws LicenseManagementException {
licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, license);
}
// Updating current object features using newer ones @Override
mobileDeviceDB.setLatitude(mobileDevice.getLatitude()); public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
mobileDeviceDB.setLongitude(mobileDevice.getLongitude()); throws DeviceManagementException {
mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties()); boolean status;
Device deviceDB = this.getDevice(deviceIdentifier);
// This object holds the current persisted device object
MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB);
try { // This object holds the newly received device object from response
if (log.isDebugEnabled()) { MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
log.debug(
"updating the details of Android device : " + device.getDeviceIdentifier());
}
AndroidDAOFactory.beginTransaction();
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
.updateMobileDevice(mobileDeviceDB);
AndroidDAOFactory.commitTransaction();
} catch (MobileDeviceManagementDAOException e) {
try {
AndroidDAOFactory.rollbackTransaction();
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
String msg = "Error occurred while roll back the update device info transaction :" +
device.toString();
log.warn(msg, mobileDAOEx);
}
String msg =
"Error while updating the Android device : " + device.getDeviceIdentifier();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
@Override // Updating current object features using newer ones
public List<Device> getAllDevices() throws DeviceManagementException { mobileDeviceDB.setLatitude(mobileDevice.getLatitude());
List<Device> devices = null; mobileDeviceDB.setLongitude(mobileDevice.getLongitude());
try { mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties());
if (log.isDebugEnabled()) {
log.debug("Fetching the details of all Android devices"); try {
} if (log.isDebugEnabled()) {
List<MobileDevice> mobileDevices = log.debug(
mobileDeviceManagementDAOFactory.getMobileDeviceDAO(). "updating the details of Android device : " + device.getDeviceIdentifier());
getAllMobileDevices(); }
if (mobileDevices != null) { AndroidDAOFactory.beginTransaction();
devices = new ArrayList<Device>(); status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO()
for (MobileDevice mobileDevice : mobileDevices) { .updateMobileDevice(mobileDeviceDB);
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice)); AndroidDAOFactory.commitTransaction();
} } catch (MobileDeviceManagementDAOException e) {
} try {
} catch (MobileDeviceManagementDAOException e) { AndroidDAOFactory.rollbackTransaction();
String msg = "Error while fetching all Android devices."; } catch (MobileDeviceManagementDAOException mobileDAOEx) {
log.error(msg, e); String msg = "Error occurred while roll back the update device info transaction :" +
throw new DeviceManagementException(msg, e); device.toString();
} log.warn(msg, mobileDAOEx);
return devices; }
} String msg =
"Error while updating the Android device : " + device.getDeviceIdentifier();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
@Override
public List<Device> getAllDevices() throws DeviceManagementException {
List<Device> devices = null;
try {
if (log.isDebugEnabled()) {
log.debug("Fetching the details of all Android devices");
}
List<MobileDevice> mobileDevices =
mobileDeviceManagementDAOFactory.getMobileDeviceDAO().
getAllMobileDevices();
if (mobileDevices != null) {
devices = new ArrayList<Device>();
for (MobileDevice mobileDevice : mobileDevices) {
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
}
}
} catch (MobileDeviceManagementDAOException e) {
String msg = "Error while fetching all Android devices.";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return devices;
}
} }

@ -40,10 +40,11 @@ import java.util.List;
public class WindowsDeviceManagementService implements DeviceManagementService { public class WindowsDeviceManagementService implements DeviceManagementService {
private DeviceManager deviceManager; private DeviceManager deviceManager;
public static final String DEVICE_TYPE_WINDOWS = "windows";
@Override @Override
public String getType() { public String getType() {
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS; return WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS;
} }
@Override @Override

@ -21,24 +21,38 @@ package org.wso2.carbon.device.mgt.mobile.impl.windows;
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.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.extensions.license.mgt.RegistryBasedLicenseManager;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice; import org.wso2.carbon.device.mgt.mobile.dto.MobileDevice;
import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory; import org.wso2.carbon.device.mgt.mobile.impl.windows.dao.WindowsDAOFactory;
import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil; import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
import org.wso2.carbon.registry.api.Registry;
import java.util.List; import java.util.List;
import java.util.Map;
public class WindowsDeviceManager implements DeviceManager { public class WindowsDeviceManager implements DeviceManager {
private MobileDeviceManagementDAOFactory mobileDeviceManagementDAOFactory; private MobileDeviceManagementDAOFactory daoFactory;
private LicenseManager licenseManager;
private static final Log log = LogFactory.getLog(WindowsDeviceManagementService.class); private static final Log log = LogFactory.getLog(WindowsDeviceManagementService.class);
public WindowsDeviceManager() { public WindowsDeviceManager() {
mobileDeviceManagementDAOFactory = new WindowsDAOFactory(); daoFactory = new WindowsDAOFactory();
try {
Registry registry =
MobileDeviceManagementDataHolder.getInstance().getRegistryService().getConfigSystemRegistry();
this.licenseManager = new RegistryBasedLicenseManager(registry);
} catch (org.wso2.carbon.registry.core.exceptions.RegistryException e) {
throw new IllegalStateException("Error occurred while retrieving config system registry of the tenant, " +
"which in turns fails the initialization of Android Device Manager", e);
}
} }
@Override @Override
@ -110,7 +124,18 @@ public class WindowsDeviceManager implements DeviceManager {
} }
@Override @Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { public License getLicense(String languageCode) throws LicenseManagementException {
return licenseManager.getLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, languageCode);
}
@Override
public void addLicense(License license) throws LicenseManagementException {
licenseManager.addLicense(WindowsDeviceManagementService.DEVICE_TYPE_WINDOWS, license);
}
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier,
Device device) throws DeviceManagementException {
return true; return true;
} }
@ -119,13 +144,10 @@ public class WindowsDeviceManager implements DeviceManager {
boolean status; boolean status;
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device); MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
try { try {
status = mobileDeviceManagementDAOFactory.getMobileDeviceDAO().addMobileDevice( status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice);
mobileDevice);
} catch (MobileDeviceManagementDAOException e) { } catch (MobileDeviceManagementDAOException e) {
String msg = "Error while enrolling the Windows device : " + throw new DeviceManagementException("Error while enrolling the Windows device '" +
device.getDeviceIdentifier(); device.getDeviceIdentifier() + "'", e);
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} }
return status; return status;
} }

@ -23,16 +23,16 @@ import org.wso2.carbon.registry.core.service.RegistryService;
/** /**
* DataHolder class of Mobile plugins component. * DataHolder class of Mobile plugins component.
*/ */
public class MobileDeviceManagementServiceDataHolder { public class MobileDeviceManagementDataHolder {
private RegistryService registryService; private RegistryService registryService;
private static MobileDeviceManagementServiceDataHolder thisInstance = new MobileDeviceManagementServiceDataHolder(); private static MobileDeviceManagementDataHolder thisInstance = new MobileDeviceManagementDataHolder();
private MobileDeviceManagementServiceDataHolder() { private MobileDeviceManagementDataHolder() {
} }
public static MobileDeviceManagementServiceDataHolder getInstance() { public static MobileDeviceManagementDataHolder getInstance() {
return thisInstance; return thisInstance;
} }

@ -157,11 +157,11 @@ public class MobileDeviceManagementServiceComponent {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("RegistryService acquired"); log.debug("RegistryService acquired");
} }
MobileDeviceManagementServiceDataHolder.getInstance().setRegistryService(registryService); MobileDeviceManagementDataHolder.getInstance().setRegistryService(registryService);
} }
protected void unsetRegistryService(RegistryService registryService) { protected void unsetRegistryService(RegistryService registryService) {
MobileDeviceManagementServiceDataHolder.getInstance().setRegistryService(null); MobileDeviceManagementDataHolder.getInstance().setRegistryService(null);
} }
} }

@ -30,7 +30,8 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.common.MobileDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants; import org.wso2.carbon.device.mgt.mobile.common.MobilePluginConstants;
import org.wso2.carbon.device.mgt.mobile.dto.*; import org.wso2.carbon.device.mgt.mobile.dto.*;
import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementServiceDataHolder; import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementDataHolder;
import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.registry.api.RegistryException;
import org.wso2.carbon.registry.api.Resource; import org.wso2.carbon.registry.api.Resource;
import org.wso2.carbon.registry.core.Registry; import org.wso2.carbon.registry.core.Registry;
@ -201,7 +202,7 @@ public class MobileDeviceManagementUtil {
public static Registry getRegistry() throws MobileDeviceMgtPluginException { public static Registry getRegistry() throws MobileDeviceMgtPluginException {
try { try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
return MobileDeviceManagementServiceDataHolder.getInstance().getRegistryService() return MobileDeviceManagementDataHolder.getInstance().getRegistryService()
.getConfigSystemRegistry( .getConfigSystemRegistry(
tenantId); tenantId);
} catch (RegistryException e) { } catch (RegistryException e) {

@ -214,6 +214,11 @@
<artifactId>org.wso2.carbon.device.mgt.common</artifactId> <artifactId>org.wso2.carbon.device.mgt.common</artifactId>
<version>${carbon.device.mgt.version}</version> <version>${carbon.device.mgt.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.extensions</artifactId>
<version>${carbon.device.mgt.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId> <artifactId>org.wso2.carbon.policy.mgt.common</artifactId>

Loading…
Cancel
Save