From 0a321e279a1172dfe9bfa73d341335434cc8c096 Mon Sep 17 00:00:00 2001 From: mharindu Date: Thu, 24 Sep 2015 14:37:52 +0530 Subject: [PATCH 1/2] Added null check to getLicense --- .../service/DeviceManagementProviderServiceImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 919a901fa5..494b03da1d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -603,6 +603,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public License getLicense(String deviceType, String languageCode) throws DeviceManagementException { DeviceManager deviceManager = this.getDeviceManager(deviceType); + License license; if (deviceManager == null) { if (log.isDebugEnabled()) { log.debug("Device Manager associated with the device type '" + deviceType + "' is null. " + @@ -611,7 +612,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return null; } try { - return deviceManager.getLicense(languageCode); + license = deviceManager.getLicense(languageCode); + if (license == null) { + if (log.isDebugEnabled()) { + log.debug("Cannot find a license for '" + deviceType + "' device type"); + } + } + return license; } catch (LicenseManagementException e) { throw new DeviceManagementException("Error occurred while retrieving license configured for " + "device type '" + deviceType + "' and language code '" + languageCode + "'", e); @@ -851,7 +858,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } - public List getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException { List devices = new ArrayList<>(); List allDevices; From 9813816fab97c48fb3b73c3fd47acce4b4fd561f Mon Sep 17 00:00:00 2001 From: mharindu Date: Tue, 29 Sep 2015 16:24:35 +0530 Subject: [PATCH 2/2] Fixed bug of adding operations --- .../mgt/core/PolicyManagerServiceImpl.java | 34 ++----------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java index e96e4ff6a0..1ad71fa0f9 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java @@ -119,43 +119,13 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException { try { - - List effectiveFeatures = PolicyManagementDataHolder.getInstance() - .getPolicyEvaluationPoint(). - getEffectiveFeatures(deviceIdentifier); - - List deviceIdentifiers = new ArrayList(); - deviceIdentifiers.add(deviceIdentifier); - List profileOperationList = new ArrayList(); - - if (!effectiveFeatures.isEmpty()) { - for (ProfileFeature feature : effectiveFeatures) { - ProfileOperation operation = new ProfileOperation(); - - operation.setCode(feature.getFeatureCode()); - operation.setPayLoad(feature.getContent()); - operation.setStatus(Operation.Status.PENDING); - operation.setType(Operation.Type.PROFILE); - operation.setEnabled(true); - profileOperationList.add(operation); - PolicyManagementDataHolder.getInstance().getDeviceManagementService(). - addOperation(operation, deviceIdentifiers); - } - } else { - return null; - } - - return effectiveFeatures; + return PolicyManagementDataHolder.getInstance(). + getPolicyEvaluationPoint().getEffectiveFeatures(deviceIdentifier); } catch (PolicyEvaluationException e) { String msg = "Error occurred while getting the effective features from the PEP service " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); throw new FeatureManagementException(msg, e); - } catch (OperationManagementException e) { - String msg = "Error occurred while adding the effective feature to database." + - deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); - log.error(msg, e); - throw new FeatureManagementException(msg, e); } }