From 70dbf7a387b0e5d00f50a954751c4d4b4e54d7e2 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 3 Feb 2020 14:37:33 +0000 Subject: Add merge utility for service templates This utility function allows a TOSCA service template fragment to be merged with an exsiting service template and will be tbe backbone of "create" methods on the API from now on. Issue-ID: POLICY-1402 Change-Id: I3381cb2a1bd30621a639dedc213c546eeb2bf9aa Signed-off-by: liamfallon --- .../simple/concepts/JpaToscaServiceTemplate.java | 44 +++--- .../simple/concepts/JpaToscaTopologyTemplate.java | 30 ++-- .../tosca/utils/ToscaServiceTemplateUtils.java | 152 +++++++++++++++++++++ 3 files changed, 201 insertions(+), 25 deletions(-) create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtils.java (limited to 'models-tosca/src/main/java/org/onap') diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java index 31c7df047..f6139ab2d 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java @@ -277,26 +277,13 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType The type of container + * + * @param compositeContainer the original container + * @param fragmentContainer the fragment being added to the original container + * @return the composite container with the result + */ + @SuppressWarnings("unchecked") + // @formatter:off + private static + , ? extends ToscaEntity>> + S addFragmentEntitites(final S compositeContainer, final S fragmentContainer, + final PfValidationResult result) { + + if (compositeContainer == null) { + return fragmentContainer; + } + + if (fragmentContainer == null) { + return compositeContainer; + } + + for (Entry> fragmentEntry : fragmentContainer + .getConceptMap().entrySet()) { + JpaToscaEntityType containerEntry = + compositeContainer.getConceptMap().get(fragmentEntry.getKey()); + if (containerEntry != null && !containerEntry.equals(fragmentEntry.getValue())) { + result.addValidationMessage(new PfValidationMessage(fragmentEntry.getKey(), + ToscaServiceTemplateUtils.class, + ValidationResult.INVALID, "entity in incoming fragment does not equal existing entity")); + } + } + + // This use of a generic map is required to get around typing errors in directly adding the fragment map to the + // original map + @SuppressWarnings("rawtypes") + Map originalContainerMap = compositeContainer.getConceptMap(); + originalContainerMap.putAll(fragmentContainer.getConceptMap()); + + return compositeContainer; + } + // @formatter:on +} -- cgit 1.2.3-korg