mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Merge pull request #7 from milanperera/master
Refactored device enrolment in plugin
This commit is contained in:
commit
d0d98ceff8
@ -21,6 +21,7 @@ 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.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;
|
||||||
@ -131,26 +132,30 @@ public class AndroidDeviceManager implements DeviceManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||||
boolean status;
|
boolean status = false;
|
||||||
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();
|
boolean isEnrolled = this.isEnrolled(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
||||||
status = daoFactory.getMobileDeviceDAO().addMobileDevice(
|
if (isEnrolled) {
|
||||||
mobileDevice);
|
this.modifyEnrollment(device);
|
||||||
AndroidDAOFactory.commitTransaction();
|
} else {
|
||||||
|
AndroidDAOFactory.beginTransaction();
|
||||||
|
status = daoFactory.getMobileDeviceDAO().addMobileDevice(mobileDevice);
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
throw new DeviceManagementException("Error while enrolling the Android device: '" +
|
String msg = "Error while enrolling the Android device : " + device.getDeviceIdentifier();
|
||||||
device.getDeviceIdentifier() + "'", e);
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -174,8 +179,10 @@ public class AndroidDeviceManager implements DeviceManager {
|
|||||||
device.toString();
|
device.toString();
|
||||||
log.warn(msg, mobileDAOEx);
|
log.warn(msg, mobileDAOEx);
|
||||||
}
|
}
|
||||||
throw new DeviceManagementException("Error while updating the enrollment of the Android device: '" +
|
String msg = "Error while updating the enrollment of the Android device : " +
|
||||||
device.getDeviceIdentifier() + "'", e);
|
device.getDeviceIdentifier();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -185,22 +192,22 @@ public class AndroidDeviceManager implements DeviceManager {
|
|||||||
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 = daoFactory.getMobileDeviceDAO()
|
status = daoFactory.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 e1) {
|
} 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, e1);
|
log.warn(msg, mobileDAOEx);
|
||||||
}
|
}
|
||||||
throw new DeviceManagementException("Error occurred while removing the Android device: '" +
|
String msg = "Error while removing the Android device : " + deviceId.getId();
|
||||||
deviceId.getId() + "'", e);
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -213,14 +220,15 @@ public class AndroidDeviceManager implements DeviceManager {
|
|||||||
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
||||||
}
|
}
|
||||||
MobileDevice mobileDevice =
|
MobileDevice mobileDevice =
|
||||||
daoFactory.getMobileDeviceDAO().getMobileDevice(
|
daoFactory.getMobileDeviceDAO().getMobileDevice(deviceId.getId());
|
||||||
deviceId.getId());
|
|
||||||
if (mobileDevice != null) {
|
if (mobileDevice != null) {
|
||||||
isEnrolled = true;
|
isEnrolled = true;
|
||||||
}
|
}
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
throw new DeviceManagementException("Error occurred while checking the enrollment status of Android " +
|
String msg = "Error while checking the enrollment status of Android device : " +
|
||||||
"device: '" + deviceId.getId() + "'", e);
|
deviceId.getId();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementException(msg, e);
|
||||||
}
|
}
|
||||||
return isEnrolled;
|
return isEnrolled;
|
||||||
}
|
}
|
||||||
@ -270,6 +278,7 @@ public class AndroidDeviceManager implements DeviceManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public License getLicense(String languageCode) throws LicenseManagementException {
|
public License getLicense(String languageCode) throws LicenseManagementException {
|
||||||
return licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode);
|
return licenseManager.getLicense(AndroidDeviceManagementService.DEVICE_TYPE_ANDROID, languageCode);
|
||||||
@ -284,17 +293,17 @@ public class AndroidDeviceManager implements DeviceManager {
|
|||||||
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
boolean status;
|
boolean status;
|
||||||
Device deviceDB = this.getDevice(deviceIdentifier);
|
Device existingDevice = this.getDevice(deviceIdentifier);
|
||||||
// This object holds the current persisted device object
|
// This object holds the current persisted device object
|
||||||
MobileDevice mobileDeviceDB = MobileDeviceManagementUtil.convertToMobileDevice(deviceDB);
|
MobileDevice existingMobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(existingDevice);
|
||||||
|
|
||||||
// This object holds the newly received device object from response
|
// This object holds the newly received device object from response
|
||||||
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
MobileDevice mobileDevice = MobileDeviceManagementUtil.convertToMobileDevice(device);
|
||||||
|
|
||||||
// Updating current object features using newer ones
|
// Updating current object features using newer ones
|
||||||
mobileDeviceDB.setLatitude(mobileDevice.getLatitude());
|
existingMobileDevice.setLatitude(mobileDevice.getLatitude());
|
||||||
mobileDeviceDB.setLongitude(mobileDevice.getLongitude());
|
existingMobileDevice.setLongitude(mobileDevice.getLongitude());
|
||||||
mobileDeviceDB.setDeviceProperties(mobileDevice.getDeviceProperties());
|
existingMobileDevice.setDeviceProperties(mobileDevice.getDeviceProperties());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -302,7 +311,7 @@ public class AndroidDeviceManager implements DeviceManager {
|
|||||||
}
|
}
|
||||||
AndroidDAOFactory.beginTransaction();
|
AndroidDAOFactory.beginTransaction();
|
||||||
status = daoFactory.getMobileDeviceDAO()
|
status = daoFactory.getMobileDeviceDAO()
|
||||||
.updateMobileDevice(mobileDeviceDB);
|
.updateMobileDevice(existingMobileDevice);
|
||||||
AndroidDAOFactory.commitTransaction();
|
AndroidDAOFactory.commitTransaction();
|
||||||
} catch (MobileDeviceManagementDAOException e) {
|
} catch (MobileDeviceManagementDAOException e) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -19,29 +19,52 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl.android;
|
package org.wso2.carbon.device.mgt.mobile.impl.android;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
|
||||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||||
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
|
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AndroidPolicyMonitoringService implements PolicyMonitoringService {
|
public class AndroidPolicyMonitoringService implements PolicyMonitoringService {
|
||||||
@Override
|
|
||||||
public void notifyDevices(List<Device> list) throws PolicyComplianceException {
|
|
||||||
|
|
||||||
}
|
private static Log log = LogFactory.getLog(AndroidPolicyMonitoringService.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object o) throws PolicyComplianceException {
|
public void notifyDevices(List<Device> list) throws PolicyComplianceException {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public String getType() {
|
|
||||||
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
|
@Override
|
||||||
}
|
public ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object o) throws PolicyComplianceException {
|
||||||
}
|
ComplianceData complianceData = new ComplianceData();
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Checking policy compliance status of device '" + deviceIdentifier.getId() + "'");
|
||||||
|
}
|
||||||
|
if (o == null || policy == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<ComplianceFeature> complianceFeatures = (List<ComplianceFeature>) o;
|
||||||
|
complianceData.setComplianceFeatures(complianceFeatures);
|
||||||
|
|
||||||
|
for (ComplianceFeature cf : complianceFeatures) {
|
||||||
|
if(!cf.isCompliance()){
|
||||||
|
complianceData.setStatus(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return complianceData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.mobile.impl.android.util;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains utility methods used by Android plugin.
|
||||||
|
*/
|
||||||
|
public class AndroidUtils {
|
||||||
|
|
||||||
|
public static String getDeviceProperty(Map<String, String> deviceProperties, String property) {
|
||||||
|
|
||||||
|
String deviceProperty = deviceProperties.get(property);
|
||||||
|
return deviceProperty;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user