mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Fixed tenant configuration persisting issue
This commit is contained in:
parent
d0d98ceff8
commit
a89b67aa25
@ -21,8 +21,6 @@ package org.wso2.carbon.device.mgt.mobile.impl.android;
|
|||||||
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.License;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||||
@ -33,318 +31,331 @@ 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.impl.android.util.AndroidPluginConstants;
|
||||||
import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginUtils;
|
import org.wso2.carbon.device.mgt.mobile.impl.android.util.AndroidPluginUtils;
|
||||||
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.RegistryException;
|
import org.wso2.carbon.registry.api.RegistryException;
|
||||||
import org.wso2.carbon.registry.api.Resource;
|
import org.wso2.carbon.registry.api.Resource;
|
||||||
|
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
import javax.xml.bind.Marshaller;
|
||||||
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AndroidDeviceManager implements DeviceManager {
|
public class AndroidDeviceManager implements DeviceManager {
|
||||||
|
|
||||||
private MobileDeviceManagementDAOFactory daoFactory;
|
private MobileDeviceManagementDAOFactory daoFactory;
|
||||||
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 LicenseManager licenseManager;
|
private LicenseManager licenseManager;
|
||||||
|
|
||||||
public AndroidDeviceManager() {
|
public AndroidDeviceManager() {
|
||||||
this.daoFactory = new AndroidDAOFactory();
|
this.daoFactory = new AndroidDAOFactory();
|
||||||
this.licenseManager = new RegistryBasedLicenseManager();
|
this.licenseManager = new RegistryBasedLicenseManager();
|
||||||
|
|
||||||
License defaultLicense = AndroidPluginUtils.getDefaultLicense();
|
License defaultLicense = AndroidPluginUtils.getDefaultLicense();
|
||||||
try {
|
try {
|
||||||
licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense);
|
licenseManager
|
||||||
} catch (LicenseManagementException e) {
|
.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, defaultLicense);
|
||||||
log.error("Error occurred while adding default license for Android devices", e);
|
} catch (LicenseManagementException e) {
|
||||||
}
|
log.error("Error occurred while adding default license for Android devices", 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;
|
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);
|
StringWriter writer = new StringWriter();
|
||||||
for (ConfigurationEntry configEntry : tenantConfiguration.getConfiguration()) {
|
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
||||||
resource = MobileDeviceManagementUtil.getRegistry().newResource();
|
Marshaller marshaller = context.createMarshaller();
|
||||||
resource.setContent(configEntry.getValue());
|
marshaller.marshal(tenantConfiguration, writer);
|
||||||
MobileDeviceManagementUtil.putRegistryResource(resourcePath + "/" + configEntry.getName(), resource);
|
|
||||||
}
|
|
||||||
status = true;
|
|
||||||
} catch (MobileDeviceMgtPluginException e) {
|
|
||||||
throw new DeviceManagementException(
|
|
||||||
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
|
|
||||||
} catch (RegistryException e) {
|
|
||||||
throw new DeviceManagementException(
|
|
||||||
"Error occurred while persisting the Registry resource : " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
resource = MobileDeviceManagementUtil.getRegistry().newResource();
|
||||||
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
resource.setContent(writer.toString());
|
||||||
Collection dsCollection;
|
resource.setMediaType(AndroidPluginConstants.MEDIA_TYPE_XML);
|
||||||
TenantConfiguration tenantConfiguration;
|
MobileDeviceManagementUtil.putRegistryResource(resourcePath, resource);
|
||||||
List<ConfigurationEntry> configs = new ArrayList<>();
|
status = true;
|
||||||
ConfigurationEntry entry;
|
} catch (MobileDeviceMgtPluginException e) {
|
||||||
Resource resource;
|
throw new DeviceManagementException(
|
||||||
try {
|
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
|
||||||
String androidRegPath =
|
} catch (RegistryException e) {
|
||||||
MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants.
|
throw new DeviceManagementException(
|
||||||
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
"Error occurred while persisting the Registry resource : " + e.getMessage(), e);
|
||||||
dsCollection =
|
} catch (JAXBException e) {
|
||||||
(Collection) MobileDeviceManagementUtil.getRegistryResource(androidRegPath);
|
throw new DeviceManagementException(
|
||||||
String[] dsmPaths = dsCollection.getChildren();
|
"Error occurred while parsing the configuration : " + e.getMessage(), e);
|
||||||
for (String dsmPath : dsmPaths) {
|
}
|
||||||
entry = new ConfigurationEntry();
|
return status;
|
||||||
resource = MobileDeviceManagementUtil.getRegistryResource(dsmPath);
|
}
|
||||||
entry.setValue(resource.getContent());
|
|
||||||
entry.setName(resource.getId());
|
|
||||||
configs.add(entry);
|
|
||||||
}
|
|
||||||
tenantConfiguration = new TenantConfiguration();
|
|
||||||
tenantConfiguration.setConfiguration(configs);
|
|
||||||
tenantConfiguration.setType(DeviceManagementConstants.
|
|
||||||
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
||||||
} catch (MobileDeviceMgtPluginException e) {
|
|
||||||
throw new DeviceManagementException(
|
|
||||||
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
|
|
||||||
} catch (RegistryException e) {
|
|
||||||
throw new DeviceManagementException(
|
|
||||||
"Error occurred while retrieving the Registry data : " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
return tenantConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
public TenantConfiguration getConfiguration() throws DeviceManagementException {
|
||||||
boolean status = false;
|
Resource resource;
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
try {
|
||||||
try {
|
String androidRegPath =
|
||||||
if (log.isDebugEnabled()) {
|
MobileDeviceManagementUtil.getPlatformConfigPath(DeviceManagementConstants.
|
||||||
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||||
}
|
resource = MobileDeviceManagementUtil.getRegistryResource(androidRegPath);
|
||||||
boolean isEnrolled = this.isEnrolled(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
JAXBContext context = JAXBContext.newInstance(TenantConfiguration.class);
|
||||||
if (isEnrolled) {
|
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||||
this.modifyEnrollment(device);
|
return (TenantConfiguration) unmarshaller.unmarshal(
|
||||||
} else {
|
new StringReader(new String((byte[]) resource.getContent(), Charset
|
||||||
AndroidDAOFactory.beginTransaction();
|
.forName("UTF8"))));
|
||||||
status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice);
|
|
||||||
AndroidDAOFactory.commitTransaction();
|
|
||||||
}
|
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
|
||||||
try {
|
|
||||||
AndroidDAOFactory.rollbackTransaction();
|
|
||||||
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
||||||
String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
|
|
||||||
log.warn(msg, mobileDAOEx);
|
|
||||||
}
|
|
||||||
String msg = "Error while enrolling the Android device : " + device.getDeviceIdentifier();
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementException(msg, e);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
} catch (MobileDeviceMgtPluginException e) {
|
||||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
throw new DeviceManagementException(
|
||||||
boolean status;
|
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
} catch (JAXBException e) {
|
||||||
try {
|
throw new DeviceManagementException(
|
||||||
if (log.isDebugEnabled()) {
|
"Error occurred while parsing the configuration : " + e.getMessage(), e);
|
||||||
log.debug("Modifying the Android device enrollment data");
|
} catch (RegistryException e) {
|
||||||
}
|
throw new DeviceManagementException(
|
||||||
AndroidDAOFactory.beginTransaction();
|
"Error occurred while retrieving the Registry resource : " + e.getMessage(), e);
|
||||||
status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice);
|
}
|
||||||
AndroidDAOFactory.commitTransaction();
|
}
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
|
||||||
try {
|
|
||||||
AndroidDAOFactory.rollbackTransaction();
|
|
||||||
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
|
||||||
String msg = "Error occurred while roll back the update device transaction :" +
|
|
||||||
device.toString();
|
|
||||||
log.warn(msg, mobileDAOEx);
|
|
||||||
}
|
|
||||||
String msg = "Error while updating the enrollment of the Android device : " +
|
|
||||||
device.getDeviceIdentifier();
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementException(msg, e);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||||
boolean status;
|
boolean status = false;
|
||||||
try {
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||||
if (log.isDebugEnabled()) {
|
try {
|
||||||
log.debug("Dis-enrolling Android device : " + deviceId);
|
if (log.isDebugEnabled()) {
|
||||||
}
|
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
||||||
AndroidDAOFactory.beginTransaction();
|
}
|
||||||
status = daoFactory.getMobileDeviceDAO().deleteMobileDevice(deviceId.getId());
|
boolean isEnrolled = this.isEnrolled(
|
||||||
AndroidDAOFactory.commitTransaction();
|
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
if (isEnrolled) {
|
||||||
try {
|
this.modifyEnrollment(device);
|
||||||
AndroidDAOFactory.rollbackTransaction();
|
} else {
|
||||||
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
AndroidDAOFactory.beginTransaction();
|
||||||
String msg = "Error occurred while roll back the device dis enrol transaction :" +
|
status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice);
|
||||||
deviceId.toString();
|
AndroidDAOFactory.commitTransaction();
|
||||||
log.warn(msg, mobileDAOEx);
|
}
|
||||||
}
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
String msg = "Error while removing the Android device : " + deviceId.getId();
|
try {
|
||||||
log.error(msg, e);
|
AndroidDAOFactory.rollbackTransaction();
|
||||||
throw new DeviceManagementException(msg, e);
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
||||||
}
|
String msg = "Error occurred while roll back the device enrol transaction :" +
|
||||||
return status;
|
device.toString();
|
||||||
}
|
log.warn(msg, mobileDAOEx);
|
||||||
|
}
|
||||||
|
String msg =
|
||||||
|
"Error while enrolling the Android device : " + device.getDeviceIdentifier();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||||
boolean isEnrolled = false;
|
boolean status;
|
||||||
try {
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||||
if (log.isDebugEnabled()) {
|
try {
|
||||||
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
if (log.isDebugEnabled()) {
|
||||||
}
|
log.debug("Modifying the Android device enrollment data");
|
||||||
MobileDevice mobileDevice =
|
}
|
||||||
daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
|
AndroidDAOFactory.beginTransaction();
|
||||||
if (mobileDevice != null) {
|
status = daoFactory.getMobileDeviceDAO().updateMobileDevice(mobileDevice);
|
||||||
isEnrolled = true;
|
AndroidDAOFactory.commitTransaction();
|
||||||
}
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
try {
|
||||||
String msg = "Error while checking the enrollment status of Android device : " +
|
AndroidDAOFactory.rollbackTransaction();
|
||||||
deviceId.getId();
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
||||||
log.error(msg, e);
|
String msg = "Error occurred while roll back the update device transaction :" +
|
||||||
throw new DeviceManagementException(msg, e);
|
device.toString();
|
||||||
}
|
log.warn(msg, mobileDAOEx);
|
||||||
return isEnrolled;
|
}
|
||||||
}
|
String msg = "Error while updating the enrollment of the Android device : " +
|
||||||
|
device.getDeviceIdentifier();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
return true;
|
boolean status;
|
||||||
}
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Dis-enrolling Android device : " + deviceId);
|
||||||
|
}
|
||||||
|
AndroidDAOFactory.beginTransaction();
|
||||||
|
status = daoFactory.getMobileDeviceDAO().deleteMobileDevice(deviceId.getId());
|
||||||
|
AndroidDAOFactory.commitTransaction();
|
||||||
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
|
try {
|
||||||
|
AndroidDAOFactory.rollbackTransaction();
|
||||||
|
} catch (MobileDeviceManagementDAOException mobileDAOEx) {
|
||||||
|
String msg = "Error occurred while roll back the device dis enrol transaction :" +
|
||||||
|
deviceId.toString();
|
||||||
|
log.warn(msg, mobileDAOEx);
|
||||||
|
}
|
||||||
|
String msg = "Error while removing the Android device : " + deviceId.getId();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
throws DeviceManagementException {
|
boolean isEnrolled = false;
|
||||||
return true;
|
try {
|
||||||
}
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
||||||
|
}
|
||||||
|
MobileDevice mobileDevice =
|
||||||
|
daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
|
||||||
|
if (mobileDevice != null) {
|
||||||
|
isEnrolled = true;
|
||||||
|
}
|
||||||
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
|
String msg = "Error while checking the enrollment status of Android device : " +
|
||||||
|
deviceId.getId();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return isEnrolled;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
Device device;
|
return true;
|
||||||
try {
|
}
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Getting the details of Android device : '" + deviceId.getId() + "'");
|
|
||||||
}
|
|
||||||
MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO().
|
|
||||||
getMobileDevice(deviceId.getId());
|
|
||||||
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
|
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
|
||||||
throw new DeviceManagementException("Error occurred while fetching the Android device: '" +
|
|
||||||
deviceId.getId() + "'", e);
|
|
||||||
}
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||||
return false;
|
Device device;
|
||||||
}
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting the details of Android device : '" + deviceId.getId() + "'");
|
||||||
|
}
|
||||||
|
MobileDevice mobileDevice = daoFactory.getMobileDeviceDAO().
|
||||||
|
getMobileDevice(deviceId.getId());
|
||||||
|
device = MobileDeviceManagementUtil.convertToDevice(mobileDevice);
|
||||||
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
|
throw new DeviceManagementException(
|
||||||
|
"Error occurred while fetching the Android device: '" +
|
||||||
|
deviceId.getId() + "'", e);
|
||||||
|
}
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||||
EnrolmentInfo.Status status) throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public License getLicense(String languageCode) throws LicenseManagementException {
|
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
||||||
return licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode);
|
EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addLicense(License license) throws LicenseManagementException {
|
public License getLicense(String languageCode) throws LicenseManagementException {
|
||||||
licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, license);
|
return licenseManager
|
||||||
}
|
.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
public void addLicense(License license) throws LicenseManagementException {
|
||||||
throws DeviceManagementException {
|
licenseManager.addLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, license);
|
||||||
boolean status;
|
}
|
||||||
Device existingDevice = this.getDevice(deviceIdentifier);
|
|
||||||
// This object holds the current persisted device object
|
|
||||||
MobileDevice existingMobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(existingDevice);
|
|
||||||
|
|
||||||
// This object holds the newly received device object from response
|
@Override
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
boolean status;
|
||||||
|
Device existingDevice = this.getDevice(deviceIdentifier);
|
||||||
|
// This object holds the current persisted device object
|
||||||
|
MobileDevice existingMobileDevice =
|
||||||
|
MobileDeviceManagementUtil.convertToMobileDevice(existingDevice);
|
||||||
|
|
||||||
// Updating current object features using newer ones
|
// This object holds the newly received device object from response
|
||||||
existingMobileDevice.setLatitude(mobileDevice.getLatitude());
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||||
existingMobileDevice.setLongitude(mobileDevice.getLongitude());
|
|
||||||
existingMobileDevice.setDeviceProperties(mobileDevice.getDeviceProperties());
|
|
||||||
|
|
||||||
try {
|
// Updating current object features using newer ones
|
||||||
if (log.isDebugEnabled()) {
|
existingMobileDevice.setLatitude(mobileDevice.getLatitude());
|
||||||
log.debug("updating the details of Android device : " + device.getDeviceIdentifier());
|
existingMobileDevice.setLongitude(mobileDevice.getLongitude());
|
||||||
}
|
existingMobileDevice.setDeviceProperties(mobileDevice.getDeviceProperties());
|
||||||
AndroidDAOFactory.beginTransaction();
|
|
||||||
status = daoFactory.getMobileDeviceDAO()
|
|
||||||
.updateMobileDevice(existingMobileDevice);
|
|
||||||
AndroidDAOFactory.commitTransaction();
|
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
|
||||||
try {
|
|
||||||
AndroidDAOFactory.rollbackTransaction();
|
|
||||||
} catch (MobileDeviceManagementDAOException e1) {
|
|
||||||
log.warn("Error occurred while roll back the update device info transaction : '" +
|
|
||||||
device.toString() + "'", e1);
|
|
||||||
}
|
|
||||||
throw new DeviceManagementException("Error occurred while updating the Android device: '" +
|
|
||||||
device.getDeviceIdentifier() + "'", e);
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public List<Device> getAllDevices() throws DeviceManagementException {
|
if (log.isDebugEnabled()) {
|
||||||
List<Device> devices = null;
|
log.debug(
|
||||||
try {
|
"updating the details of Android device : " + device.getDeviceIdentifier());
|
||||||
if (log.isDebugEnabled()) {
|
}
|
||||||
log.debug("Fetching the details of all Android devices");
|
AndroidDAOFactory.beginTransaction();
|
||||||
}
|
status = daoFactory.getMobileDeviceDAO()
|
||||||
List<MobileDevice> mobileDevices =
|
.updateMobileDevice(existingMobileDevice);
|
||||||
daoFactory.getMobileDeviceDAO().getAllMobileDevices();
|
AndroidDAOFactory.commitTransaction();
|
||||||
if (mobileDevices != null) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
devices = new ArrayList<>();
|
try {
|
||||||
for (MobileDevice mobileDevice : mobileDevices) {
|
AndroidDAOFactory.rollbackTransaction();
|
||||||
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
|
} catch (MobileDeviceManagementDAOException e1) {
|
||||||
}
|
log.warn("Error occurred while roll back the update device info transaction : '" +
|
||||||
}
|
device.toString() + "'", e1);
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
}
|
||||||
throw new DeviceManagementException("Error occurred while fetching all Android devices", e);
|
throw new DeviceManagementException(
|
||||||
}
|
"Error occurred while updating the Android device: '" +
|
||||||
return devices;
|
device.getDeviceIdentifier() + "'", 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 =
|
||||||
|
daoFactory.getMobileDeviceDAO().getAllMobileDevices();
|
||||||
|
if (mobileDevices != null) {
|
||||||
|
devices = new ArrayList<>();
|
||||||
|
for (MobileDevice mobileDevice : mobileDevices) {
|
||||||
|
devices.add(MobileDeviceManagementUtil.convertToDevice(mobileDevice));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
|
throw new DeviceManagementException("Error occurred while fetching all Android devices",
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,4 +44,6 @@ public class AndroidPluginConstants {
|
|||||||
public static final String ANDROID_FEATURE_NAME = "NAME";
|
public static final String ANDROID_FEATURE_NAME = "NAME";
|
||||||
public static final String ANDROID_FEATURE_DESCRIPTION = "DESCRIPTION";
|
public static final String ANDROID_FEATURE_DESCRIPTION = "DESCRIPTION";
|
||||||
|
|
||||||
|
public static final String MEDIA_TYPE_XML = "application/xml";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,6 @@ 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.MobileDeviceManagementDataHolder;
|
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;
|
||||||
@ -260,12 +259,10 @@ public class MobileDeviceManagementUtil {
|
|||||||
String regPath = "";
|
String regPath = "";
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
case DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID:
|
case DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID:
|
||||||
regPath = MobilePluginConstants.MOBILE_CONFIG_REGISTRY_ROOT + "/" +
|
regPath = DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
|
||||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
|
|
||||||
break;
|
break;
|
||||||
case DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS:
|
case DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS:
|
||||||
regPath = MobilePluginConstants.MOBILE_CONFIG_REGISTRY_ROOT + "/" +
|
regPath = DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS;
|
||||||
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return regPath;
|
return regPath;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user