Fix the Tosca Converter to Json Schema 68/117968/2
authorsebdet <sebastien.determe@intl.att.com>
Mon, 15 Feb 2021 10:02:18 +0000 (11:02 +0100)
committerLiam Fallon <liam.fallon@est.tech>
Mon, 22 Feb 2021 14:14:02 +0000 (14:14 +0000)
The backend had to be slightly fixed so that the json generation without being in a loop is not an issue. This is required for the policies listing feature

Issue-ID: POLICY-2926
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Change-Id: Ia6a9e034f888384999a8ea557ce550c87c65c4be
(cherry picked from commit 08ed2240b2389fbf83e9ed67cc65cc6fc628ea72)

src/main/java/org/onap/policy/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java
src/main/java/org/onap/policy/clamp/clds/tosca/update/execution/target/ToscaMetadataTargetProcess.java
src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java
src/test/resources/http-cache/example/policy/api/v1/policytypes/onap.policies.Naming/versions/1.0.0/.file

index bd3a1cb..4ad4742 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP CLAMP
  * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights
  *                             reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +23,8 @@
 
 package org.onap.policy.clamp.clds.tosca.update.execution.cds;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
@@ -31,6 +33,7 @@ import java.util.Set;
 import org.onap.policy.clamp.clds.tosca.ToscaSchemaConstants;
 import org.onap.policy.clamp.clds.tosca.ToscaSchemaConstants;
 import org.onap.policy.clamp.clds.tosca.update.execution.ToscaMetadataProcess;
+import org.onap.policy.clamp.clds.tosca.update.execution.target.ToscaMetadataTargetProcess;
 import org.onap.policy.clamp.loop.service.Service;
 
 
@@ -39,8 +42,15 @@ import org.onap.policy.clamp.loop.service.Service;
  */
 public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
 
+    private static final EELFLogger logger =
+            EELFManager.getInstance().getLogger(ToscaMetadataCdsProcess.class);
+
     @Override
     public void executeProcess(String parameters, JsonObject childObject, Service serviceModel) {
+        if (serviceModel == null) {
+            logger.info("serviceModel is null, therefore the ToscaMetadataCdsProcess is skipped");
+            return;
+        }
         switch (parameters) {
             case "actor":
                 JsonArray jsonArray = new JsonArray();
index f4ca990..dcfd059 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP CLAMP
  * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights
  *                             reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
 
 package org.onap.policy.clamp.clds.tosca.update.execution.target;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
 import com.google.gson.JsonObject;
+import org.onap.policy.clamp.clds.tosca.update.execution.ToscaMetadataExecutor;
 import org.onap.policy.clamp.clds.tosca.update.execution.ToscaMetadataProcess;
 import org.onap.policy.clamp.loop.service.Service;
 import org.onap.policy.clamp.policy.operational.OperationalPolicyRepresentationBuilder;
@@ -33,8 +36,15 @@ import org.onap.policy.clamp.policy.operational.OperationalPolicyRepresentationB
  */
 public class ToscaMetadataTargetProcess extends ToscaMetadataProcess {
 
+    private static final EELFLogger logger =
+            EELFManager.getInstance().getLogger(ToscaMetadataTargetProcess.class);
+
     @Override
     public void executeProcess(String parameters, JsonObject childObject, Service serviceModel) {
+        if (serviceModel == null) {
+            logger.info("serviceModel is null, therefore the ToscaMetadataTargetProcess is skipped");
+            return;
+        }
         childObject.add("anyOf", OperationalPolicyRepresentationBuilder.createAnyOfArray(serviceModel, false));
     }
 }
index 5a9720a..74fd8e5 100644 (file)
@@ -118,8 +118,8 @@ public class ToscaConverterToJsonSchema {
         JsonArray requirements = new JsonArray();
         ToscaElement toParse = components.get(nameComponent);
         //Check for a father component, and launch the same process
-        if (!toParse.getDerivedFrom().equals("tosca.datatypes.Root")
-                && !toParse.getDerivedFrom().equals("tosca.policies.Root")) {
+        if (!"tosca.datatypes.Root".equals(toParse.getDerivedFrom())
+                && !"tosca.policies.Root".equals(toParse.getDerivedFrom())) {
             requirements.addAll(getRequirements(toParse.getDerivedFrom()));
         }
         //Each property is checked, and add to the requirement array if it's required
index a444351..a006929 100644 (file)
@@ -61,7 +61,7 @@ data_types:
                 type: policy.data.increment-sequence
                 required: false
     policy.data.increment-sequence:
-        derived_from: tosca.nodes.Root
+        derived_from: tosca.datatypes.Root
         properties:
             scope:
                 type: list