From 0a9fbe36547050ed2654f35f79f17ef66ef36b4f Mon Sep 17 00:00:00 2001 From: Pahansith Date: Wed, 30 Sep 2020 00:23:30 +0530 Subject: [PATCH] Improve code --- .../mgt/core/util/PolicyManagerUtil.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java index c2daceb2aac..a71e247ff88 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java @@ -181,23 +181,23 @@ public class PolicyManagerUtil { private static void transformGeoFencePolicy(List effectiveFeatures, PolicyOperation policyOperation, Policy policy) throws PolicyTransformException { String payload = null; + int fenceId = -1; for (ProfileFeature effectiveFeature : effectiveFeatures) { if (effectiveFeature.getFeatureCode().equals(PolicyManagementConstants.GEOFENCE_POLICY)) { payload = effectiveFeature.getContent().toString(); break; } } - for (ProfileOperation profileOperation : policyOperation.getProfileOperations()) { - int fenceId = -1; - try { - if (profileOperation.getCode().equals(PolicyManagementConstants.GEOFENCE_POLICY)) { - JsonParser jsonParser = new JsonParser(); - if (payload != null) { + if (payload != null) { + for (ProfileOperation profileOperation : policyOperation.getProfileOperations()) { + try { + if (profileOperation.getCode().equals(PolicyManagementConstants.GEOFENCE_POLICY)) { + JsonParser jsonParser = new JsonParser(); JsonElement parsedPayload = jsonParser.parse(payload); JsonObject jsonPayload = parsedPayload.getAsJsonObject(); GeoLocationProviderServiceImpl geoLocationProviderService = new GeoLocationProviderServiceImpl(); if (jsonPayload.get("fenceId") == null) { - String msg = "No valid fence Id found in operation payload"; + String msg = "No valid fence Id found in saved policy payload"; log.error(msg); throw new PolicyTransformException(msg); } @@ -216,12 +216,17 @@ public class PolicyManagerUtil { profileOperation.setPayLoad(operationPayload.toString()); } } + } catch (GeoLocationBasedServiceException e) { + String msg = "Error occurred while retrieving geofence with fence Id " + fenceId + + " for the policy with Id "+policy.getId(); + log.error(msg); + throw new PolicyTransformException(msg); } - } catch (GeoLocationBasedServiceException e) { - String msg = "Error occurred while retrieving geofence with fence Id " + fenceId - + " for the policy with Id "+policy.getId(); - log.error(msg); - throw new PolicyTransformException(msg); + } + } else { + if (log.isDebugEnabled()) { + String msg = "No Geofence feature attached with the policy " + policy.getId(); + log.debug(msg); } } }