TOSCA Compliant Guard Policies
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / legacy / mapping / LegacyOperationalPolicyMapper.java
index 4ddcd60..de1bc12 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.
@@ -44,6 +44,10 @@ import org.slf4j.LoggerFactory;
  */
 public class LegacyOperationalPolicyMapper
         implements JpaToscaServiceTemplateMapper<LegacyOperationalPolicy, LegacyOperationalPolicy> {
+
+    // Property name for the operational policy content
+    private static final String CONTENT_PROPERTY = "content";
+
     private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicyMapper.class);
 
     private static final PfConceptKey LEGACY_OPERATIONAL_TYPE =
@@ -64,10 +68,10 @@ public class LegacyOperationalPolicyMapper
 
         final Map<String, String> propertyMap = new HashMap<>();
         toscaPolicy.setProperties(propertyMap);
-        toscaPolicy.getProperties().put("Content", legacyOperationalPolicy.getContent());
+        toscaPolicy.getProperties().put(CONTENT_PROPERTY, legacyOperationalPolicy.getContent());
 
         final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
-        serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0");
+        serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_1_0");
 
         serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
 
@@ -101,9 +105,10 @@ public class LegacyOperationalPolicyMapper
             throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
         }
 
-        final String content = toscaPolicy.getProperties().get("Content");
-        if (toscaPolicy.getProperties() == null) {
-            String errorMessage = "property \"Content\" not defined on TOSCA policy";
+        String content = toscaPolicy.getProperties().get(CONTENT_PROPERTY);
+
+        if (content == null) {
+            String errorMessage = "property \"content\" not defined on TOSCA policy";
             LOGGER.warn(errorMessage);
             throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
         }