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;
} }
} }
if (payload != null) {
for (ProfileOperation profileOperation : policyOperation.getProfileOperations()) { for (ProfileOperation profileOperation : policyOperation.getProfileOperations()) {
int fenceId = -1;
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,7 +216,6 @@ public class PolicyManagerUtil {
profileOperation.setPayLoad(operationPayload.toString()); profileOperation.setPayLoad(operationPayload.toString());
} }
} }
}
} catch (GeoLocationBasedServiceException e) { } catch (GeoLocationBasedServiceException e) {
String msg = "Error occurred while retrieving geofence with fence Id " + fenceId String msg = "Error occurred while retrieving geofence with fence Id " + fenceId
+ " for the policy with Id "+policy.getId(); + " for the policy with Id "+policy.getId();
@ -224,6 +223,12 @@ public class PolicyManagerUtil {
throw new PolicyTransformException(msg); throw new PolicyTransformException(msg);
} }
} }
} else {
if (log.isDebugEnabled()) {
String msg = "No Geofence feature attached with the policy " + policy.getId();
log.debug(msg);
}
}
} }
/** /**

Loading…
Cancel
Save