From d378c37fbd1ecec7b43394926f1ca32a695e07de Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 22 Mar 2021 15:33:06 +0000 Subject: Reformat openecomp-be Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1 --- .../impl/GlobalSubstitutionServiceTemplate.java | 53 ++++++++-------------- 1 file changed, 18 insertions(+), 35 deletions(-) (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java') diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java index 98d8d23751..4907451a06 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.core.impl; import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX; @@ -35,15 +34,14 @@ import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypes public class GlobalSubstitutionServiceTemplate extends ServiceTemplate { - public static final String GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME = - "GlobalSubstitutionTypesServiceTemplate.yaml"; + public static final String GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME = "GlobalSubstitutionTypesServiceTemplate.yaml"; public static final String TEMPLATE_NAME_PROPERTY = "template_name"; public static final String DEFINITION_VERSION = "tosca_simple_yaml_1_0_0"; public static final String HEAT_INDEX = "openecomp_heat_index"; public static final String HEAT_INDEX_IMPORT_FILE = "openecomp-heat/_index.yml"; public static final String ONAP_INDEX_IMPORT_FILE = "onap/_index.yml"; - // transient needed to avoid being parsed as a YAML String. Used parser is reading fields instead of getters, + // although it ignores static or transient fields. private final transient Map globalServiceTemplates; private final transient Map globalDataTypeMap; @@ -51,12 +49,11 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate { public GlobalSubstitutionServiceTemplate() { super(); init(); - globalServiceTemplates = - GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.CSAR); + globalServiceTemplates = GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.CSAR); globalDataTypeMap = loadGlobalDataTypes(); } - public void init() { + public void init() { writeDefinitionSection(); writeMetadataSection(); writeImportsSection(); @@ -73,12 +70,10 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate { if (MapUtils.isEmpty(dataTypeMap)) { return; } - dataTypeMap.entrySet().stream() - .filter(dataTypeEntry -> !isGlobalDataType(dataTypeEntry.getKey())) - .forEach(dataTypeEntry -> { - final Optional dataType = parseDataTypeToYamlObject(dataTypeEntry); - dataType.ifPresent(dataType1 -> getData_types().put(dataTypeEntry.getKey(), dataType1)); - }); + dataTypeMap.entrySet().stream().filter(dataTypeEntry -> !isGlobalDataType(dataTypeEntry.getKey())).forEach(dataTypeEntry -> { + final Optional dataType = parseDataTypeToYamlObject(dataTypeEntry); + dataType.ifPresent(dataType1 -> getData_types().put(dataTypeEntry.getKey(), dataType1)); + }); } private void writeImportsSection() { @@ -94,7 +89,6 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate { stringImportMap.put(ONAP_INDEX, onapDefinitionsImport); } - private void writeMetadataSection() { Map metadata = new HashMap<>(); metadata.put(TEMPLATE_NAME_PROPERTY, "GlobalSubstitutionTypes"); @@ -105,22 +99,18 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate { setTosca_definitions_version(DEFINITION_VERSION); } - private Optional> findNonGlobalTypesNodes(final Map nodes){ + private Optional> findNonGlobalTypesNodes(final Map nodes) { final Map globalNodeTypes = getAllGlobalNodeTypes(); if (MapUtils.isEmpty(globalNodeTypes)) { return Optional.of(nodes); } - final Map nodeTypesToAdd = new HashMap<>(); - - for(Map.Entry nodeTypeEntry : nodes.entrySet()){ - if(!globalNodeTypes.containsKey(nodeTypeEntry.getKey())){ + for (Map.Entry nodeTypeEntry : nodes.entrySet()) { + if (!globalNodeTypes.containsKey(nodeTypeEntry.getKey())) { Optional nodeType = parseNodeTypeToYamlObject(nodeTypeEntry); - nodeType - .ifPresent(nodeTypeValue -> nodeTypesToAdd.put(nodeTypeEntry.getKey(), nodeTypeValue)); + nodeType.ifPresent(nodeTypeValue -> nodeTypesToAdd.put(nodeTypeEntry.getKey(), nodeTypeValue)); } } - return Optional.of(nodeTypesToAdd); } @@ -128,37 +118,30 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate { if (MapUtils.isEmpty(globalDataTypeMap)) { return false; } - return globalDataTypeMap.containsKey(dataType); } private Optional parseNodeTypeToYamlObject(final Entry nodeTypeEntry) { - return ToscaConverterUtil - .createObjectFromClass(nodeTypeEntry.getKey(), nodeTypeEntry.getValue(), NodeType.class); + return ToscaConverterUtil.createObjectFromClass(nodeTypeEntry.getKey(), nodeTypeEntry.getValue(), NodeType.class); } private Optional parseDataTypeToYamlObject(final Entry dataTypeEntry) { - return ToscaConverterUtil - .createObjectFromClass(dataTypeEntry.getKey(), dataTypeEntry.getValue(), DataType.class); + return ToscaConverterUtil.createObjectFromClass(dataTypeEntry.getKey(), dataTypeEntry.getValue(), DataType.class); } private Map loadGlobalDataTypes() { - return globalServiceTemplates.values().stream() - .map(ServiceTemplate::getData_types) - .filter(MapUtils::isNotEmpty) + return globalServiceTemplates.values().stream().map(ServiceTemplate::getData_types).filter(MapUtils::isNotEmpty) .flatMap(stringDataTypeMap -> stringDataTypeMap.entrySet().stream()) .collect(Collectors.toMap(Entry::getKey, Entry::getValue, (dataType, dataType2) -> dataType)); } - private Map getAllGlobalNodeTypes(){ + private Map getAllGlobalNodeTypes() { Map globalNodeTypes = new HashMap<>(); - - for(Map.Entry serviceTemplateEntry : globalServiceTemplates.entrySet()){ - if(isNodesServiceTemplate(serviceTemplateEntry.getKey())){ + for (Map.Entry serviceTemplateEntry : globalServiceTemplates.entrySet()) { + if (isNodesServiceTemplate(serviceTemplateEntry.getKey())) { globalNodeTypes.putAll(serviceTemplateEntry.getValue().getNode_types()); } } - return globalNodeTypes; } -- cgit 1.2.3-korg