Improve code

corrective-policy
Pahansith 4 years ago
parent d06fc0e5f3
commit 0a9fbe3654

@ -181,23 +181,23 @@ public class PolicyManagerUtil {
private static void transformGeoFencePolicy(List<ProfileFeature> effectiveFeatures, private static void transformGeoFencePolicy(List<ProfileFeature> effectiveFeatures,
PolicyOperation policyOperation, Policy policy) throws PolicyTransformException { PolicyOperation policyOperation, Policy policy) throws PolicyTransformException {
String payload = null; String payload = null;
int fenceId = -1;
for (ProfileFeature effectiveFeature : effectiveFeatures) { for (ProfileFeature effectiveFeature : effectiveFeatures) {
if (effectiveFeature.getFeatureCode().equals(PolicyManagementConstants.GEOFENCE_POLICY)) { if (effectiveFeature.getFeatureCode().equals(PolicyManagementConstants.GEOFENCE_POLICY)) {
payload = effectiveFeature.getContent().toString(); payload = effectiveFeature.getContent().toString();
break; break;
} }
} }
for (ProfileOperation profileOperation : policyOperation.getProfileOperations()) { if (payload != null) {
int fenceId = -1; for (ProfileOperation profileOperation : policyOperation.getProfileOperations()) {
try { try {
if (profileOperation.getCode().equals(PolicyManagementConstants.GEOFENCE_POLICY)) { if (profileOperation.getCode().equals(PolicyManagementConstants.GEOFENCE_POLICY)) {
JsonParser jsonParser = new JsonParser(); JsonParser jsonParser = new JsonParser();
if (payload != null) {
JsonElement parsedPayload = jsonParser.parse(payload); JsonElement parsedPayload = jsonParser.parse(payload);
JsonObject jsonPayload = parsedPayload.getAsJsonObject(); JsonObject jsonPayload = parsedPayload.getAsJsonObject();
GeoLocationProviderServiceImpl geoLocationProviderService = new GeoLocationProviderServiceImpl(); GeoLocationProviderServiceImpl geoLocationProviderService = new GeoLocationProviderServiceImpl();
if (jsonPayload.get("fenceId") == null) { 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); log.error(msg);
throw new PolicyTransformException(msg); throw new PolicyTransformException(msg);
} }
@ -216,12 +216,17 @@ public class PolicyManagerUtil {
profileOperation.setPayLoad(operationPayload.toString()); 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 } else {
+ " for the policy with Id "+policy.getId(); if (log.isDebugEnabled()) {
log.error(msg); String msg = "No Geofence feature attached with the policy " + policy.getId();
throw new PolicyTransformException(msg); log.debug(msg);
} }
} }
} }

Loading…
Cancel
Save