Remove sonar issue in simple provider 79/87679/1
authorliamfallon <liam.fallon@est.tech>
Tue, 14 May 2019 13:20:01 +0000 (13:20 +0000)
committerliamfallon <liam.fallon@est.tech>
Tue, 14 May 2019 13:20:01 +0000 (13:20 +0000)
Issue-ID: POLICY-1738
Change-Id: Id85d710154727c7c535db7cc50af88f52114a358
Signed-off-by: liamfallon <liam.fallon@est.tech>
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java

index 761a47c..47e0b67 100644 (file)
@@ -288,7 +288,10 @@ public class SimpleToscaProvider {
 
         if (PfKey.NULL_KEY_VERSION.equals(policyTypeKey.getVersion())) {
             policyType = getLatestPolicyTypeVersion(dao, policyTypeKey.getName());
-            policy.getType().setVersion(policyType.getKey().getVersion());
+
+            if (policyType != null) {
+                policy.getType().setVersion(policyType.getKey().getVersion());
+            }
         } else {
             policyType = dao.get(JpaToscaPolicyType.class, policyTypeKey);
         }
@@ -310,8 +313,7 @@ public class SimpleToscaProvider {
      */
     private JpaToscaPolicyType getLatestPolicyTypeVersion(final PfDao dao, final String policyTypeName) {
         // Policy type version is not specified, get the latest version from the database
-        List<JpaToscaPolicyType> jpaPolicyTypeList =
-                dao.getFiltered(JpaToscaPolicyType.class, policyTypeName, null);
+        List<JpaToscaPolicyType> jpaPolicyTypeList = dao.getFiltered(JpaToscaPolicyType.class, policyTypeName, null);
 
         if (jpaPolicyTypeList.isEmpty()) {
             return null;
@@ -325,9 +327,8 @@ public class SimpleToscaProvider {
         List<PfConcept> filterdPolicyTypeList = pfConceptFilter.filter(policyTypeKeyList);
 
         // We should have one and only one returned entry
-        if (filterdPolicyTypeList.size() != 1 ) {
-            String errorMessage =
-                    "search for lates policy type " + policyTypeName + " returned more than one entry";
+        if (filterdPolicyTypeList.size() != 1) {
+            String errorMessage = "search for lates policy type " + policyTypeName + " returned more than one entry";
             LOGGER.warn(errorMessage);
             throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
         }