diff options
author | sebdet <sebastien.determe@intl.att.com> | 2021-04-15 19:43:27 +0200 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2021-04-16 18:40:43 +0200 |
commit | 4b6371f7ed8e35fd157ea640d05b5898989f32ca (patch) | |
tree | 64ce4f0fd56b2c227d093f589fb5bfa76dbc5387 /src/main | |
parent | 1f2d62dd48694fa78041572a200b3e5d04bd268e (diff) |
Fix Sonar bugs & sec issues
Fix all bugs & sec issues reported by Sonar
Issue-ID: POLICY-3200
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Change-Id: Ifb3d0d3602586b8defb0826e799ef0e24742235c
Diffstat (limited to 'src/main')
6 files changed, 133 insertions, 110 deletions
diff --git a/src/main/java/org/onap/policy/clamp/clds/Application.java b/src/main/java/org/onap/policy/clamp/clds/Application.java index 17f08c973..a242086da 100644 --- a/src/main/java/org/onap/policy/clamp/clds/Application.java +++ b/src/main/java/org/onap/policy/clamp/clds/Application.java @@ -28,7 +28,6 @@ package org.onap.policy.clamp.clds; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import java.io.IOException; -import java.io.InputStream; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -78,7 +77,7 @@ public class Application extends SpringBootServletInitializer { // This settings is an additional one to Spring config, // only if we want to have an additional port automatically redirected to // HTTPS - @Value("${server.http-to-https-redirection.port:none}") + @Value("${server.http-to-https-redirection.port:#{null}}") private String httpRedirectedPort; /** * This 8080 is the default port used by spring if this parameter is not @@ -86,8 +85,19 @@ public class Application extends SpringBootServletInitializer { */ @Value("${server.port:8080}") private String springServerPort; - @Value("${server.ssl.key-store:none}") - private String sslKeystoreFile; + + @Value("${server.ssl.key-store:#{null}}") + private String keystoreFile; + + @Value("${server.ssl.key-store-password:#{null}}") + private String keyStorePass; + + @Value("${server.ssl.key-store-type:JKS}") + private String keyStoreType; + + + @Value("${clamp.config.keyFile:#{null}}") + private String keyFile; @Autowired private Environment env; @@ -99,6 +109,7 @@ public class Application extends SpringBootServletInitializer { /** * Main method that starts the Clamp backend. + * * @param args app params */ public static void main(String[] args) { @@ -130,7 +141,7 @@ public class Application extends SpringBootServletInitializer { @Bean public ServletWebServerFactory getEmbeddedServletContainerFactory() { TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); - if (!"none".equals(httpRedirectedPort) && !"none".equals(sslKeystoreFile)) { + if (httpRedirectedPort != null && keystoreFile != null) { // Automatically redirect to HTTPS tomcat = new TomcatEmbeddedServletContainerFactoryRedirection(); Connector newConnector = createRedirectConnector(Integer.parseInt(springServerPort)); @@ -158,14 +169,10 @@ public class Application extends SpringBootServletInitializer { private String getSslExpirationDate() throws IOException { StringBuilder result = new StringBuilder(" :: SSL Certificates :: "); try { - if (env.getProperty("server.ssl.key-store") != null) { - - KeyStore keystore = KeyStore.getInstance(env.getProperty("server.ssl.key-store-type")); - String password = PassDecoder.decode(env.getProperty("server.ssl.key-store-password"), - env.getProperty("clamp.config.keyFile")); - String keyStore = env.getProperty("server.ssl.key-store"); - InputStream is = ResourceFileUtils.getResourceAsStream(keyStore.replaceAll("classpath:", "")); - keystore.load(is, password.toCharArray()); + if (keystoreFile != null) { + KeyStore keystore = KeyStore.getInstance(keyStoreType); + keystore.load(ResourceFileUtils.getResourceAsStream(keystoreFile.replace("classpath:", "")), + PassDecoder.decode(keyStorePass, keyFile).toCharArray()); Enumeration<String> aliases = keystore.aliases(); while (aliases.hasMoreElements()) { diff --git a/src/main/java/org/onap/policy/clamp/clds/ClampServlet.java b/src/main/java/org/onap/policy/clamp/clds/ClampServlet.java index 5149dd3b7..dcaa2acf3 100644 --- a/src/main/java/org/onap/policy/clamp/clds/ClampServlet.java +++ b/src/main/java/org/onap/policy/clamp/clds/ClampServlet.java @@ -71,7 +71,7 @@ public class ClampServlet extends CamelHttpTransportServlet { private synchronized List<String> loadDynamicAuthenticationClasses() { return Arrays.stream(WebApplicationContextUtils.getWebApplicationContext(getServletContext()) - .getEnvironment().getProperty(AUTHENTICATION_CLASS).split(",")).map(className -> className.trim()) + .getEnvironment().getProperty(AUTHENTICATION_CLASS).split(",")).map(String::trim) .collect(Collectors.toList()); } diff --git a/src/main/java/org/onap/policy/clamp/clds/client/CdsServices.java b/src/main/java/org/onap/policy/clamp/clds/client/CdsServices.java index 085e905e9..80ff9f774 100644 --- a/src/main/java/org/onap/policy/clamp/clds/client/CdsServices.java +++ b/src/main/java/org/onap/policy/clamp/clds/client/CdsServices.java @@ -1,9 +1,11 @@ /*-
* ============LICENSE_START=======================================================
- * ONAP CLAMP
+ * ONAP POLICY-CLAMP
* ================================================================================
* Copyright (C) 2020 Huawei Technologies Co., Ltd.
* ================================================================================
+ * Modifications Copyright (C) 2021 AT&T.
+ * ================================================================================
* Licensed 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
@@ -29,16 +31,19 @@ import com.att.eelf.configuration.EELFManager; import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import java.io.IOException;
import java.util.Date;
import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.ExchangeBuilder;
import org.onap.policy.clamp.clds.exception.cds.CdsParametersException;
import org.onap.policy.clamp.clds.model.cds.CdsBpWorkFlowListResponse;
import org.onap.policy.clamp.clds.util.JsonUtils;
import org.onap.policy.clamp.clds.util.LoggingUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -57,14 +62,6 @@ public class CdsServices { private static final String LIST = "list";
/**
- * Constructor.
- */
- @Autowired
- public CdsServices() {
- }
-
-
- /**
* Query CDS to get blueprint's workflow list.
*
* @param blueprintName CDS blueprint name
@@ -74,23 +71,28 @@ public class CdsServices { public CdsBpWorkFlowListResponse getBlueprintWorkflowList(String blueprintName, String blueprintVersion) {
LoggingUtils.setTargetContext("CDS", "getBlueprintWorkflowList");
- Exchange exchangeResponse = camelContext.createProducerTemplate()
- .send("direct:get-blueprint-workflow-list", ExchangeBuilder.anExchange(camelContext)
- .withProperty("blueprintName", blueprintName).withProperty("blueprintVersion", blueprintVersion)
- .withProperty("raiseHttpExceptionFlag", true).build());
-
- if (Integer.valueOf(200).equals(exchangeResponse.getIn().getHeader("CamelHttpResponseCode"))) {
- String cdsResponse = (String) exchangeResponse.getIn().getBody();
- logger.info("getBlueprintWorkflowList, response from CDS:" + cdsResponse);
- LoggingUtils.setResponseContext("0", "Get Blueprint workflow list", this.getClass().getName());
- Date startTime = new Date();
- LoggingUtils.setTimeContext(startTime, new Date());
- return JsonUtils.GSON_JPA_MODEL.fromJson(cdsResponse, CdsBpWorkFlowListResponse.class);
- } else {
- logger.error("CDS getBlueprintWorkflowList FAILED");
- return null;
+ try (ProducerTemplate producerTemplate = camelContext.createProducerTemplate()) {
+ Exchange exchangeResponse =
+ producerTemplate.send("direct:get-blueprint-workflow-list", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("blueprintName", blueprintName)
+ .withProperty("blueprintVersion", blueprintVersion)
+ .withProperty("raiseHttpExceptionFlag", false).build());
+
+ if (HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()) {
+ String cdsResponse = (String) exchangeResponse.getIn().getBody();
+ logger.info("getBlueprintWorkflowList, response from CDS:" + cdsResponse);
+ LoggingUtils.setResponseContext("0", "Get Blueprint workflow list", this.getClass().getName());
+ Date startTime = new Date();
+ LoggingUtils.setTimeContext(startTime, new Date());
+ return JsonUtils.GSON_JPA_MODEL.fromJson(cdsResponse, CdsBpWorkFlowListResponse.class);
+ } else {
+ logger.error("CDS getBlueprintWorkflowList FAILED");
+ }
+ } catch (IOException e) {
+ logger.error("IOException caught when trying to execute get-blueprint-workflow-list flow", e);
}
-
+ return null;
}
/**
@@ -105,22 +107,27 @@ public class CdsServices { String workflow) {
LoggingUtils.setTargetContext("CDS", "getWorkflowInputProperties");
- Exchange exchangeResponse = camelContext.createProducerTemplate()
- .send("direct:get-blueprint-workflow-input-properties", ExchangeBuilder.anExchange(camelContext)
- .withBody(getCdsPayloadForWorkFlow(blueprintName, blueprintVersion, workflow))
- .withProperty("raiseHttpExceptionFlag", true).build());
-
- if (Integer.valueOf(200).equals(exchangeResponse.getIn().getHeader("CamelHttpResponseCode"))) {
- String cdsResponse = (String) exchangeResponse.getIn().getBody();
- logger.info("getWorkflowInputProperties, response from CDS:" + cdsResponse);
- LoggingUtils.setResponseContext("0", "Get Blueprint workflow input properties", this.getClass().getName());
- Date startTime = new Date();
- LoggingUtils.setTimeContext(startTime, new Date());
- return parseCdsResponse(cdsResponse);
- } else {
- logger.error("CDS getWorkflowInputProperties FAILED");
- return null;
+ try (ProducerTemplate producerTemplate = camelContext.createProducerTemplate()) {
+ Exchange exchangeResponse = producerTemplate
+ .send("direct:get-blueprint-workflow-input-properties", ExchangeBuilder.anExchange(camelContext)
+ .withBody(getCdsPayloadForWorkFlow(blueprintName, blueprintVersion, workflow))
+ .withProperty("raiseHttpExceptionFlag", false).build());
+ if (HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()) {
+ String cdsResponse = (String) exchangeResponse.getIn().getBody();
+ logger.info("getWorkflowInputProperties, response from CDS:" + cdsResponse);
+ LoggingUtils
+ .setResponseContext("0", "Get Blueprint workflow input properties", this.getClass().getName());
+ Date startTime = new Date();
+ LoggingUtils.setTimeContext(startTime, new Date());
+ return parseCdsResponse(cdsResponse);
+ } else {
+ logger.error("CDS getWorkflowInputProperties FAILED");
+ }
+ } catch (IOException e) {
+ logger.error("IOException caught when trying to execute get-blueprint-workflow-input-properties flow", e);
}
+ return null;
}
protected JsonObject parseCdsResponse(String response) {
@@ -133,8 +140,7 @@ public class CdsServices { return workFlowProperties;
}
- private JsonObject getInputProperties(JsonObject inputs, JsonObject dataTypes,
- JsonObject inputObject) {
+ private JsonObject getInputProperties(JsonObject inputs, JsonObject dataTypes, JsonObject inputObject) {
if (inputs == null) {
return inputObject;
}
@@ -164,7 +170,7 @@ public class CdsServices { String type = inputProperty.get("entry_schema").getAsJsonObject().get(
TYPE).getAsString();
- if (dataTypes.get(type) != null) {
+ if (dataTypes != null && dataTypes.get(type) != null) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty(TYPE, LIST);
jsonObject.add(PROPERTIES, getPropertiesObject(type, dataTypes));
diff --git a/src/main/java/org/onap/policy/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/policy/clamp/clds/client/DcaeInventoryServices.java index 1956a962f..98eeae220 100644 --- a/src/main/java/org/onap/policy/clamp/clds/client/DcaeInventoryServices.java +++ b/src/main/java/org/onap/policy/clamp/clds/client/DcaeInventoryServices.java @@ -1,8 +1,8 @@ /*-
* ============LICENSE_START=======================================================
- * ONAP CLAMP
+ * ONAP POLICY-CLAMP
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018, 2021 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,7 @@ import java.io.IOException; import java.util.Date;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.ExchangeBuilder;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
@@ -40,6 +41,7 @@ import org.onap.policy.clamp.clds.model.dcae.DcaeInventoryResponse; import org.onap.policy.clamp.clds.util.JsonUtils;
import org.onap.policy.clamp.clds.util.LoggingUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
@@ -107,29 +109,32 @@ public class DcaeInventoryServices { retryInterval = Integer.valueOf(refProp.getStringValue(DCAE_INVENTORY_RETRY_INTERVAL));
}
for (int i = 0; i < retryLimit; i++) {
- Exchange myCamelExchange = ExchangeBuilder.anExchange(camelContext)
- .withProperty("blueprintResourceId", resourceUuid).withProperty("blueprintServiceId", serviceUuid)
- .withProperty("blueprintName", artifactName).withProperty("raiseHttpExceptionFlag", true).build();
metricsLogger.info("Attempt n°" + i + " to contact DCAE inventory");
+ try (ProducerTemplate producerTemplate = camelContext.createProducerTemplate()) {
+ Exchange exchangeResponse = producerTemplate
+ .send("direct:get-dcae-blueprint-inventory", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("blueprintResourceId", resourceUuid)
+ .withProperty("blueprintServiceId", serviceUuid)
+ .withProperty("blueprintName", artifactName)
+ .withProperty("raiseHttpExceptionFlag", false).build());
- Exchange exchangeResponse = camelContext.createProducerTemplate()
- .send("direct:get-dcae-blueprint-inventory", myCamelExchange);
-
- if (Integer.valueOf(200).equals(exchangeResponse.getIn().getHeader("CamelHttpResponseCode"))) {
- String dcaeResponse = (String) exchangeResponse.getIn().getBody();
- int totalCount = getTotalCountFromDcaeInventoryResponse(dcaeResponse);
- metricsLogger.info("getDcaeInformation complete: totalCount returned=" + totalCount);
- if (totalCount > 0) {
- logger.info("getDcaeInformation, answer from DCAE inventory:" + dcaeResponse);
- LoggingUtils.setResponseContext("0", "Get Dcae Information success", this.getClass().getName());
- Date startTime = new Date();
- LoggingUtils.setTimeContext(startTime, new Date());
- return getItemsFromDcaeInventoryResponse(dcaeResponse);
- } else {
- logger.info("Dcae inventory totalCount returned is 0, so waiting " + retryInterval
- + "ms before retrying ...");
- // wait for a while and try to connect to DCAE again
- Thread.sleep(retryInterval);
+ if (HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()) {
+ String dcaeResponse = (String) exchangeResponse.getIn().getBody();
+ int totalCount = getTotalCountFromDcaeInventoryResponse(dcaeResponse);
+ metricsLogger.info("getDcaeInformation complete: totalCount returned=" + totalCount);
+ if (totalCount > 0) {
+ logger.info("getDcaeInformation, answer from DCAE inventory:" + dcaeResponse);
+ LoggingUtils.setResponseContext("0", "Get Dcae Information success", this.getClass().getName());
+ Date startTime = new Date();
+ LoggingUtils.setTimeContext(startTime, new Date());
+ return getItemsFromDcaeInventoryResponse(dcaeResponse);
+ } else {
+ logger.info("Dcae inventory totalCount returned is 0, so waiting " + retryInterval
+ + "ms before retrying ...");
+ // wait for a while and try to connect to DCAE again
+ Thread.sleep(retryInterval);
+ }
}
}
}
diff --git a/src/main/java/org/onap/policy/clamp/policy/PolicyEngineServices.java b/src/main/java/org/onap/policy/clamp/policy/PolicyEngineServices.java index 1a936bbca..4142841e2 100644 --- a/src/main/java/org/onap/policy/clamp/policy/PolicyEngineServices.java +++ b/src/main/java/org/onap/policy/clamp/policy/PolicyEngineServices.java @@ -25,10 +25,11 @@ package org.onap.policy.clamp.policy; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import java.io.IOException; import java.util.LinkedHashMap; -import java.util.Map; import org.apache.camel.CamelContext; import org.apache.camel.Exchange; +import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.ExchangeBuilder; import org.onap.policy.clamp.clds.config.ClampProperties; import org.onap.policy.clamp.clds.sdc.controller.installer.BlueprintMicroService; @@ -37,6 +38,7 @@ import org.onap.policy.clamp.loop.template.PolicyModel; import org.onap.policy.clamp.loop.template.PolicyModelsService; import org.onap.policy.models.pdp.concepts.PdpGroups; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; @@ -55,9 +57,11 @@ public class PolicyEngineServices { private final PolicyModelsService policyModelsService; + private static final String RAISE_EXCEPTION_FLAG = "raiseHttpExceptionFlag"; + private static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyEngineServices.class); - private static int retryInterval = 0; - private static int retryLimit = 1; + private int retryInterval = 0; + private int retryLimit = 1; public static final String POLICY_RETRY_INTERVAL = "policy.retry.interval"; public static final String POLICY_RETRY_LIMIT = "policy.retry.limit"; @@ -131,8 +135,7 @@ public class PolicyEngineServices { return; } - LinkedHashMap<String, Object> policyTypesMap = (LinkedHashMap<String, Object>) loadedYaml - .get("policy_types"); + LinkedHashMap<String, Object> policyTypesMap = (LinkedHashMap<String, Object>) loadedYaml.get("policy_types"); policyTypesMap.forEach((key, value) -> this.createPolicyModelFromPolicyEngine(key, ((String) ((LinkedHashMap<String, Object>) value).get("version")))); @@ -146,7 +149,7 @@ public class PolicyEngineServices { */ public String downloadAllPolicyModels() { return callCamelRoute( - ExchangeBuilder.anExchange(camelContext).withProperty("raiseHttpExceptionFlag", true).build(), + ExchangeBuilder.anExchange(camelContext).withProperty(RAISE_EXCEPTION_FLAG, true).build(), "direct:get-all-policy-models", "Get all policies models"); } @@ -167,7 +170,7 @@ public class PolicyEngineServices { Yaml yamlParser = new Yaml(options); String responseBody = callCamelRoute( ExchangeBuilder.anExchange(camelContext).withProperty("policyModelType", policyType) - .withProperty("policyModelVersion", policyVersion).withProperty("raiseHttpExceptionFlag", true) + .withProperty("policyModelVersion", policyVersion).withProperty(RAISE_EXCEPTION_FLAG, false) .build(), "direct:get-policy-tosca-model", "Get one policy"); @@ -176,7 +179,7 @@ public class PolicyEngineServices { return null; } - return yamlParser.dump((Map<String, Object>) yamlParser.load(responseBody)); + return yamlParser.dump(yamlParser.load(responseBody)); } /** @@ -185,7 +188,7 @@ public class PolicyEngineServices { public void downloadPdpGroups() { String responseBody = callCamelRoute( - ExchangeBuilder.anExchange(camelContext).withProperty("raiseHttpExceptionFlag", true).build(), + ExchangeBuilder.anExchange(camelContext).withProperty(RAISE_EXCEPTION_FLAG, false).build(), "direct:get-all-pdp-groups", "Get Pdp Groups"); if (responseBody == null || responseBody.isEmpty()) { @@ -198,17 +201,21 @@ public class PolicyEngineServices { private String callCamelRoute(Exchange exchange, String camelFlow, String logMsg) { for (int i = 0; i < retryLimit; i++) { - Exchange exchangeResponse = camelContext.createProducerTemplate().send(camelFlow, exchange); - if (Integer.valueOf(200).equals(exchangeResponse.getIn().getHeader("CamelHttpResponseCode"))) { - return (String) exchangeResponse.getIn().getBody(); - } else { - logger.info(logMsg + " query " + retryInterval + "ms before retrying ..."); - // wait for a while and try to connect to DCAE again - try { + try (ProducerTemplate producerTemplate = camelContext.createProducerTemplate()) { + Exchange exchangeResponse = producerTemplate.send(camelFlow, exchange); + if (HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE)) + .is2xxSuccessful()) { + return (String) exchangeResponse.getIn().getBody(); + } else { + logger.info(logMsg + " query " + retryInterval + "ms before retrying ..."); + // wait for a while and try to connect to DCAE again Thread.sleep(retryInterval); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); + } + } catch (IOException e) { + logger.error("IOException caught when trying to call Camel flow:" + camelFlow, e); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } } return ""; diff --git a/src/main/java/org/onap/policy/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java b/src/main/java/org/onap/policy/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java index 8a1bb1abf..6718475ca 100644 --- a/src/main/java/org/onap/policy/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java +++ b/src/main/java/org/onap/policy/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java @@ -1,8 +1,8 @@ /*- * ============LICENSE_START======================================================= - * ONAP CLAMP + * ONAP POLICY-CLAMP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights * reserved. * Modifications Copyright (C) 2020 Huawei Technologies Co., Ltd. * ================================================================================ @@ -81,12 +81,10 @@ public class OperationalPolicyRepresentationBuilder { .getAsJsonObject().get(ANY_OF).getAsJsonArray().addAll(createAnyOfArray(modelJson, true)); // update CDS recipe and payload information to schema - JsonArray actors = jsonSchema.get(PROPERTIES).getAsJsonObject() + for (JsonElement actor : jsonSchema.get(PROPERTIES).getAsJsonObject() .get("operational_policy").getAsJsonObject().get(PROPERTIES).getAsJsonObject().get("policies") .getAsJsonObject().get(ITEMS).getAsJsonObject().get(PROPERTIES).getAsJsonObject().get("actor") - .getAsJsonObject().get(ANY_OF).getAsJsonArray(); - - for (JsonElement actor : actors) { + .getAsJsonObject().get(ANY_OF).getAsJsonArray()) { if ("CDS".equalsIgnoreCase(actor.getAsJsonObject().get(TITLE).getAsString())) { actor.getAsJsonObject().get(PROPERTIES).getAsJsonObject().get(RECIPE).getAsJsonObject() .get(ANY_OF).getAsJsonArray() @@ -141,8 +139,8 @@ public class OperationalPolicyRepresentationBuilder { private static JsonArray createBlankEntry() { JsonArray result = new JsonArray(); JsonObject blankObject = new JsonObject(); - blankObject.addProperty("title", "User defined"); - blankObject.add("properties", new JsonObject()); + blankObject.addProperty(TITLE, "User defined"); + blankObject.add(PROPERTIES, new JsonObject()); result.add(blankObject); return result; } @@ -224,7 +222,7 @@ public class OperationalPolicyRepresentationBuilder { for (Entry<String, JsonElement> workflowsEntry : workflows.entrySet()) { JsonObject obj = new JsonObject(); obj.addProperty(TITLE, workflowsEntry.getKey()); - obj.addProperty(TYPE, "object"); + obj.addProperty(TYPE, TYPE_OBJECT); obj.add(PROPERTIES, createPayloadProperty(workflowsEntry.getValue().getAsJsonObject(), controllerProperties, workflowsEntry.getKey())); schemaArray.add(obj); @@ -239,7 +237,7 @@ public class OperationalPolicyRepresentationBuilder { JsonObject controllerProperties, String workFlowName) { JsonObject payload = new JsonObject(); payload.addProperty(TITLE, "Payload"); - payload.addProperty(TYPE, "object"); + payload.addProperty(TYPE, TYPE_OBJECT); payload.add(PROPERTIES, createInputPropertiesForPayload(workFlow, controllerProperties, workFlowName)); JsonObject properties = new JsonObject(); @@ -302,7 +300,7 @@ public class OperationalPolicyRepresentationBuilder { String key = entry.getKey(); JsonObject inputProperty = inputs.getAsJsonObject(key); if (key.equalsIgnoreCase(workFlowName + "-properties")) { - addDataFields(entry.getValue().getAsJsonObject().get("properties").getAsJsonObject(), + addDataFields(entry.getValue().getAsJsonObject().get(PROPERTIES).getAsJsonObject(), dataObj, workFlowName); } else { dataObj.add(entry.getKey(), @@ -326,7 +324,7 @@ public class OperationalPolicyRepresentationBuilder { listProperties.add(PROPERTIES, getProperties(cdsProperty.get(PROPERTIES).getAsJsonObject())); property.add(ITEMS, listProperties); } - } else if (TYPE_OBJECT.equalsIgnoreCase(type)) { + } else if (cdsProperty != null && TYPE_OBJECT.equalsIgnoreCase(type)) { property.addProperty(TYPE, TYPE_OBJECT); property.add(PROPERTIES, getProperties(cdsProperty.get(PROPERTIES).getAsJsonObject())); } else { |