Java 17 Upgrade
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / utils / ToscaUtils.java
index 5ec8247..f4c22fc 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2021 Nordix Foundation.
+ *  Copyright (C) 2019-2023 Nordix Foundation.
  *  Modifications 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.models.tosca.utils;
 
+import jakarta.ws.rs.core.Response;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.function.Function;
-import javax.ws.rs.core.Response;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
@@ -106,6 +106,15 @@ public final class ToscaUtils {
         assertExist(serviceTemplate, ToscaUtils::checkPoliciesExist);
     }
 
+    /**
+     * Assert that node templates have been specified correctly.
+     *
+     * @param serviceTemplate the service template containing node templates to be checked
+     */
+    public static void assertNodeTemplatesExist(final JpaToscaServiceTemplate serviceTemplate) {
+        assertExist(serviceTemplate, ToscaUtils::checkNodeTemplateExist);
+    }
+
     /**
      * Check that data types have been specified correctly.
      *
@@ -134,6 +143,16 @@ public final class ToscaUtils {
         return doExist(serviceTemplate, ToscaUtils::checkPoliciesExist);
     }
 
+    /**
+     * Check that tosca node templates have been specified correctly.
+     *
+     * @param serviceTemplate the service template containing node templates to be checked
+     */
+    public static boolean doNodeTemplatesExist(final JpaToscaServiceTemplate serviceTemplate) {
+
+        return doExist(serviceTemplate, ToscaUtils::checkNodeTemplateExist);
+    }
+
     /**
      * Assert that something have been specified correctly.
      *
@@ -206,6 +225,20 @@ public final class ToscaUtils {
         return null;
     }
 
+    /**
+     * Check if node templates have been specified correctly.
+     */
+    public static String checkNodeTemplateExist(final JpaToscaServiceTemplate serviceTemplate) {
+        if (serviceTemplate.getTopologyTemplate().getNodeTemplates() == null) {
+            return "node templates not present on the service template";
+        }
+
+        if (serviceTemplate.getTopologyTemplate().getNodeTemplates().getConceptMap().isEmpty()) {
+            return "no parameters present on the node templates";
+        }
+        return null;
+    }
+
     /**
      * getLatestPolicyTypeVersion Find all the ancestors of an entity type.
      *