From f35587328e1bd99882ed8a4df85d01660d54c007 Mon Sep 17 00:00:00 2001 From: brunomilitzer Date: Thu, 5 May 2022 15:20:30 +0100 Subject: Added Edit Instance Properties Functionality Issue-ID: POLICY-4094 Change-Id: Id52dba3c0912486fa551697be170c05542a0ee22 Signed-off-by: brunomilitzer --- .../provider/ServiceTemplateProvider.java | 53 +++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'models') diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java index 0de5f480a..942fe8d46 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -133,7 +133,6 @@ public class ServiceTemplateProvider { * @param fullNodeTypes map of all the node types in the specified template * @param common boolean to indicate whether common or instance properties are required * @return node types map that only has common properties - * @throws PfModelException on errors getting node type with common properties */ private Map getInitialNodeTypesMap(Map fullNodeTypes, boolean common) { @@ -214,6 +213,56 @@ public class ServiceTemplateProvider { return filteredNodeTypes; } + /** + * Get the node types derived from those that have been saved by instantiation. + * + * @param initialNodeTypes map of all the node types in the specified template + * @param filteredNodeTypes map of all the node types that have common or instance properties + * @param instanceName automation composition name + * @return all node types that have common properties including their children + */ + private Map getFinalSavedInstanceNodeTypesMap( + Map initialNodeTypes, + Map filteredNodeTypes, String instanceName) { + + for (var i = 0; i < initialNodeTypes.size(); i++) { + initialNodeTypes.forEach((key, nodeType) -> { + var tempToscaNodeType = new ToscaNodeType(); + tempToscaNodeType.setName(key); + + if (filteredNodeTypes.get(nodeType.getDerivedFrom()) != null) { + tempToscaNodeType.setName(key); + + var finalProps = new HashMap( + filteredNodeTypes.get(nodeType.getDerivedFrom()).getProperties()); + + tempToscaNodeType.setProperties(finalProps); + } else { + return; + } + filteredNodeTypes.putIfAbsent(key, tempToscaNodeType); + + }); + } + return filteredNodeTypes; + } + + /** + * Get the requested node types by automation composition. + * + * @param instanceName automation composition name + * @param serviceTemplate the ToscaServiceTemplate + * @return the node types with common or instance properties + */ + public Map getSavedInstanceInstancePropertiesFromNodeTypes( + String instanceName, ToscaServiceTemplate serviceTemplate) { + var tempNodeTypesMap = + this.getInitialNodeTypesMap(serviceTemplate.getNodeTypes(), false); + + return this.getFinalSavedInstanceNodeTypesMap(serviceTemplate.getNodeTypes(), tempNodeTypesMap, instanceName); + + } + /** * Get the requested node types with common or instance properties. * -- cgit 1.2.3-korg