Support persistence of data types
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / utils / ToscaUtils.java
index 1b509e2..23a428b 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019-2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -43,7 +43,28 @@ public final class ToscaUtils {
     }
 
     /**
-     * Check if policy types have been specified is initialized.
+     * Check if data types have been specified correctly.
+     *
+     * @param serviceTemplate the service template containing data types to be checked
+     */
+    public static void assertDataTypesExist(final JpaToscaServiceTemplate serviceTemplate) {
+        if (serviceTemplate.getDataTypes() == null) {
+            String errorMessage = "no data types specified on service template";
+            LOGGER.warn(errorMessage);
+            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+        }
+
+        if (serviceTemplate.getDataTypes().getConceptMap().isEmpty()) {
+            String errorMessage = "list of data types specified on service template is empty";
+            LOGGER.warn(errorMessage);
+            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+        }
+    }
+
+    /**
+     * Check if policy types have been specified correctly.
+     *
+     * @param serviceTemplate the service template containing policy types to be checked
      */
     public static void assertPolicyTypesExist(final JpaToscaServiceTemplate serviceTemplate) {
         if (serviceTemplate.getPolicyTypes() == null) {
@@ -60,7 +81,9 @@ public final class ToscaUtils {
     }
 
     /**
-     * Check if policy types have been specified is initialized.
+     * Check if policies have been specified correctly.
+     *
+     * @param serviceTemplate the service template containing policy types to be checked
      */
     public static void assertPoliciesExist(final JpaToscaServiceTemplate serviceTemplate) {
         if (serviceTemplate.getTopologyTemplate() == null) {