From cee63084a9ebe9f91dc7afa490d18572448e6668 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 14 May 2019 13:20:01 +0000 Subject: Remove sonar issue in simple provider Issue-ID: POLICY-1738 Change-Id: Id85d710154727c7c535db7cc50af88f52114a358 Signed-off-by: liamfallon --- .../models/tosca/simple/provider/SimpleToscaProvider.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'models-tosca/src/main') diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java index 761a47c9a..47e0b67a3 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java @@ -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 jpaPolicyTypeList = - dao.getFiltered(JpaToscaPolicyType.class, policyTypeName, null); + List jpaPolicyTypeList = dao.getFiltered(JpaToscaPolicyType.class, policyTypeName, null); if (jpaPolicyTypeList.isEmpty()) { return null; @@ -325,9 +327,8 @@ public class SimpleToscaProvider { List 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); } -- cgit 1.2.3-korg