From 036b56698cf85459ecafce97f14a771fd5b5c0c5 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Fri, 14 Feb 2020 15:53:50 +0000 Subject: Fix return codes and policy get Change the return codes for validation to return more helpful and correct codes. Fix the policy "get" request to get policy types and data types for a policy get. Issue-ID: POLICY-1402 Change-Id: I89d67f830e9a75bdeef39c4142523c718879f19c Signed-off-by: liamfallon --- .../tosca/simple/provider/SimpleToscaProvider.java | 17 ++++++++--------- .../models/tosca/utils/ToscaServiceTemplateUtils.java | 2 +- .../org/onap/policy/models/tosca/utils/ToscaUtils.java | 4 ++-- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'models-tosca/src/main/java/org') 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 17eae006d..d19dbf9aa 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 @@ -106,7 +106,7 @@ public class SimpleToscaProvider { PfValidationResult result = serviceTemplateToWrite.validate(new PfValidationResult()); if (!result.isValid()) { - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, result.toString()); + throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.toString()); } new SimpleToscaServiceTemplateProvider().write(dao, serviceTemplateToWrite); @@ -378,6 +378,8 @@ public class SimpleToscaProvider { LOGGER.debug("->getPolicies: name={}, version={}", name, version); JpaToscaServiceTemplate serviceTemplate = getServiceTemplate(dao); + serviceTemplate.setDataTypes(new JpaToscaDataTypes()); + serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); if (!ToscaUtils.doPoliciesExist(serviceTemplate)) { throw new PfModelRuntimeException(Response.Status.NOT_FOUND, @@ -392,13 +394,10 @@ public class SimpleToscaProvider { } for (JpaToscaPolicy policy : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().values()) { - if (policy.getDerivedFrom() != null) { - JpaToscaServiceTemplate referencedEntitiesServiceTemplate = - getPolicyTypes(dao, policy.getDerivedFrom().getName(), policy.getDerivedFrom().getVersion()); + JpaToscaServiceTemplate referencedEntitiesServiceTemplate = + getPolicyTypes(dao, policy.getType().getName(), policy.getType().getVersion()); - serviceTemplate = - ToscaServiceTemplateUtils.addFragment(serviceTemplate, referencedEntitiesServiceTemplate); - } + serviceTemplate = ToscaServiceTemplateUtils.addFragment(serviceTemplate, referencedEntitiesServiceTemplate); } LOGGER.debug("<-getPolicies: name={}, version={}, serviceTemplate={}", name, version, serviceTemplate); @@ -502,7 +501,7 @@ public class SimpleToscaProvider { if (policyType == null) { String errorMessage = "policy type " + policyTypeKey.getId() + " for policy " + policy.getId() + " does not exist"; - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); + throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, errorMessage); } } @@ -531,7 +530,7 @@ public class SimpleToscaProvider { // We should have one and only one returned entry if (filterdPolicyTypeList.size() != 1) { String errorMessage = "search for latest policy type " + policyTypeName + " returned more than one entry"; - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); + throw new PfModelRuntimeException(Response.Status.CONFLICT, errorMessage); } return (JpaToscaPolicyType) filterdPolicyTypeList.get(0); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java index aae45e5ce..6f21c1942 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java @@ -95,7 +95,7 @@ public class ToscaServiceTemplateUtils { if (!result.isValid()) { String message = result.toString(); - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, message); + throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, message); } return compositeTemplate; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java index cc0431946..b75273e5e 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java @@ -147,7 +147,7 @@ public final class ToscaUtils { final Function checkerFunction) { String message = checkerFunction.apply(serviceTemplate); if (message != null) { - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, message); + throw new PfModelRuntimeException(Response.Status.NOT_FOUND, message); } } @@ -263,7 +263,7 @@ public final class ToscaUtils { } if (!result.isValid()) { - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, result.toString()); + throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, result.toString()); } entityTypes.getConceptMap().entrySet() -- cgit 1.2.3-korg