aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-translator-lib
diff options
context:
space:
mode:
authorojasdubey <ojas.dubey@amdocs.com>2018-05-29 17:58:56 +0530
committerOren Kleks <orenkle@amdocs.com>2018-05-31 14:01:02 +0000
commita8d58165f25ff2cde93ed623f0ebbf78fcd82057 (patch)
tree4cbefda35217f2c75dbe16e1041ee8b815bdd4ad /openecomp-be/lib/openecomp-sdc-translator-lib
parentba61c887dbcb1b81e31e15b18a44f68ff344b2fb (diff)
Refactor Onboarding Function Translation code
1. Fixed sonar violations and static analysis issues for function translation 2. Refactored methods for code smells Note: The below files are modified to keep successful compilation and will be handled separately in a different commit (i) HeatToToscaUtil (ii) TranslatorHeatToToscaParameterConverter (iii) TranslatorHeatToToscaPropertyConverter Change-Id: I75472c2848d1eb812468e7d6457c8da96d6c0e4e Issue-ID: SDC-1331 Signed-off-by: ojasdubey <ojas.dubey@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib')
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/FunctionTranslation.java27
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/FunctionTranslationFactory.java72
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java71
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/FunctionTranslationHelper.java47
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java742
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetFileImpl.java98
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetParamImpl.java167
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetResourceImpl.java51
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslator.java113
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaParameterConverter.java10
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaPropertyConverter.java10
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImplTest.java20
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetFileImplTest.java42
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetParamImplTest.java225
14 files changed, 783 insertions, 912 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/FunctionTranslation.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/FunctionTranslation.java
index 0c2ea4b80d..54805bed2c 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/FunctionTranslation.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/FunctionTranslation.java
@@ -1,38 +1,25 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca;
-
-import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.onap.sdc.tosca.datatypes.model.Template;
-import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
+import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator;
public interface FunctionTranslation {
- //return the value of the translated function ("get_param", "get_attr" and etc)
- Object translateFunction(ServiceTemplate serviceTemplate,
- String resourceId, String propertyName, String functionKey,
- Object functionValue, String heatFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- Template toscaTemplate, TranslationContext context);
+ Object translateFunction(FunctionTranslator functionTranslator);
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/FunctionTranslationFactory.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/FunctionTranslationFactory.java
index 90abc1b5c4..aafcdbe898 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/FunctionTranslationFactory.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/FunctionTranslationFactory.java
@@ -1,70 +1,60 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca;
+import java.util.Map;
+import java.util.Optional;
import org.onap.config.api.Configuration;
import org.onap.config.api.ConfigurationManager;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
-import java.util.Map;
-import java.util.Optional;
-
-
public class FunctionTranslationFactory {
- private static Map<String, ImplementationConfiguration> functionTranslationImplMap;
+ private static final Map<String, ImplementationConfiguration> functionTranslationImplMap;
- static {
- Configuration config = ConfigurationManager.lookup();
- functionTranslationImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
- ConfigConstants.FUNCTION_TRANSLATION_IMPL_KEY, ImplementationConfiguration.class);
- functionTranslationImplMap.putAll(config.populateMap(ConfigConstants.MANDATORY_TRANSLATOR_NAMESPACE,
- ConfigConstants.FUNCTION_TRANSLATION_IMPL_KEY, ImplementationConfiguration.class));
+ static {
+ Configuration config = ConfigurationManager.lookup();
+ functionTranslationImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
+ ConfigConstants.FUNCTION_TRANSLATION_IMPL_KEY, ImplementationConfiguration.class);
+ functionTranslationImplMap.putAll(config.populateMap(ConfigConstants.MANDATORY_TRANSLATOR_NAMESPACE,
+ ConfigConstants.FUNCTION_TRANSLATION_IMPL_KEY, ImplementationConfiguration.class));
- }
-
- /**
- * Gets function translation instance.
- *
- * @param heatFunctionKey heat function key
- * @return the instance
- */
- public static Optional<FunctionTranslation> getInstance(String heatFunctionKey) {
- if (isSupportedFunction(heatFunctionKey)) {
- String functionTranslationImplClassName =
- functionTranslationImplMap.get(heatFunctionKey).getImplementationClass();
- return Optional.of(CommonMethods
- .newInstance(functionTranslationImplClassName, FunctionTranslation.class));
}
- return Optional.empty();
- }
+ /**
+ * Gets function translation instance.
+ *
+ * @param heatFunctionKey heat function key
+ * @return the instance
+ */
+ public static Optional<FunctionTranslation> getInstance(String heatFunctionKey) {
+ if (isSupportedFunction(heatFunctionKey)) {
+ String functionTranslationImplClassName =
+ functionTranslationImplMap.get(heatFunctionKey).getImplementationClass();
+ return Optional.of(CommonMethods
+ .newInstance(functionTranslationImplClassName, FunctionTranslation.class));
+ }
+ return Optional.empty();
+ }
- private static boolean isSupportedFunction(String heatFunctionKey) {
- if (functionTranslationImplMap.containsKey(heatFunctionKey)) {
- return true;
+ private static boolean isSupportedFunction(String heatFunctionKey) {
+ return functionTranslationImplMap.containsKey(heatFunctionKey);
}
- return false;
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java
index 600aa52742..33afabc3a5 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java
@@ -16,9 +16,41 @@
package org.openecomp.sdc.translator.services.heattotosca;
+import static org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator.getFunctionTranslateTo;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.io.FilenameUtils;
+import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.onap.sdc.tosca.datatypes.model.Import;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.onap.sdc.tosca.datatypes.model.PropertyType;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.datatypes.model.Template;
+import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
+import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
+import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.core.translator.api.HeatToToscaTranslator;
import org.openecomp.core.translator.datatypes.TranslatorOutput;
import org.openecomp.core.translator.factory.HeatToToscaTranslatorFactory;
@@ -50,25 +82,10 @@ import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
-import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
-import org.onap.sdc.tosca.datatypes.model.Import;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.NodeType;
-import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
-import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
-import org.onap.sdc.tosca.datatypes.model.PropertyType;
-import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.onap.sdc.tosca.datatypes.model.Template;
-import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
import org.openecomp.sdc.tosca.services.ToscaConstants;
-import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.openecomp.sdc.tosca.services.ToscaUtil;
-import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedPropertyVal;
import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
@@ -79,25 +96,10 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.services.heattotosca.errors.ResourceNotFoundInHeatFileErrorBuilder;
import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
import org.openecomp.sdc.translator.services.heattotosca.helper.ContrailV2VirtualMachineInterfaceHelper;
-import org.openecomp.sdc.translator.services.heattotosca.helper.FunctionTranslationHelper;
+import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator;
import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.ResourceTranslationBase;
import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
/**
* The type Heat to tosca util.
*/
@@ -382,12 +384,13 @@ public class HeatToToscaUtil {
if (!FunctionTranslationFactory.getInstance(entry.getKey()).isPresent()) {
translatedId = null;
} else {
+ FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(null, null,
+ heatFileName, heatOrchestrationTemplate, context), null, entry.getValue(), null);
translatedId = FunctionTranslationFactory.getInstance(entry.getKey()).get()
- .translateFunction(null, null, null, entry.getKey(), entry.getValue(), heatFileName,
- heatOrchestrationTemplate, null, context);
+ .translateFunction(functionTranslator);
}
if (translatedId instanceof String
- && !FunctionTranslationHelper.isResourceSupported((String) translatedId)) {
+ && !new FunctionTranslator().isResourceSupported((String) translatedId)) {
translatedId = null;
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/FunctionTranslationHelper.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/FunctionTranslationHelper.java
deleted file mode 100644
index c06892046f..0000000000
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/FunctionTranslationHelper.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.translator.services.heattotosca.helper;
-
-/**
- * @author SHIRIA
- * @since December 15, 2016.
- */
-public class FunctionTranslationHelper {
-
- private static final String UNSUPPORTED_RESOURCE = "UNSUPPORTED_RESOURCE_";
- private static final String UNSUPPORTED_ATTRIBUTE = "UNSUPPORTED_ATTRIBUTE_";
-
- public static boolean isResourceSupported(String translatedResourceId) {
- return !translatedResourceId.startsWith(UNSUPPORTED_RESOURCE);
- }
-
- public static boolean isAttributeSupported(String translatedAttName) {
- return !translatedAttName.startsWith(UNSUPPORTED_ATTRIBUTE);
- }
-
- public static String getUnsupportedResourcePrefix() {
- return UNSUPPORTED_RESOURCE;
- }
-
- public static String getUnsupportedAttributePrefix() {
- return UNSUPPORTED_ATTRIBUTE;
- }
-}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java
index 38dcc54f73..f533353d18 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java
@@ -18,15 +18,22 @@ package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslati
import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants.TRANS_MAPPING_DELIMITER_CHAR;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
import org.apache.commons.lang3.StringUtils;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.heat.services.HeatConstants;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.onap.sdc.tosca.datatypes.model.Template;
-import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.EntityConsolidationData;
@@ -37,461 +44,352 @@ import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslation;
import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslationFactory;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
-import org.openecomp.sdc.translator.services.heattotosca.helper.FunctionTranslationHelper;
import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.ResourceTranslationBase;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
-
public class FunctionTranslationGetAttrImpl implements FunctionTranslation {
+ private static List<Object> translateGetAttributeFunctionExpression(FunctionTranslator functionTranslator) {
- @Override
- public Object translateFunction(ServiceTemplate serviceTemplate,
- String resourceId, String propertyName, String functionKey,
- Object functionValue, String heatFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- Template toscaTemplate, TranslationContext context) {
- Object returnValue = new HashMap<>();
- List<Object> attributeFunctionExpression =
- translateGetAttributeFunctionExpression(serviceTemplate, resourceId, functionValue,
- propertyName, heatFileName, heatOrchestrationTemplate, (NodeTemplate) toscaTemplate,
- context);
- if (FunctionTranslationHelper.isResourceSupported(attributeFunctionExpression.get(0).toString())
- && FunctionTranslationHelper.isAttributeSupported(attributeFunctionExpression.get(0)
- .toString())) {
- ((Map) returnValue)
- .put(ToscaFunctions.GET_ATTRIBUTE.getDisplayName(), attributeFunctionExpression);
- } else {
- returnValue = attributeFunctionExpression;
- }
+ List<Object> attributeParamList = (List) functionTranslator.getFunctionValue();
+ List<Object> toscaAttributeParamList = new ArrayList<>();
- return returnValue;
- }
-
- private static List<Object> translateGetAttributeFunctionExpression(
- ServiceTemplate serviceTemplate,
- String resourceId,
- Object functionValue,
- String propertyName,
- String heatFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- NodeTemplate nodeTemplate,
- TranslationContext context) {
-
- List<Object> attributeParamList = (List) functionValue;
- List<Object> toscaAttributeParamList = new ArrayList<>();
-
- Optional<String> targetResourceTranslatedId = Optional.empty();
- String targetResourceId = null;
- if( attributeParamList.get(0) instanceof String) {
- targetResourceId = (String) attributeParamList.get(0);
- targetResourceTranslatedId =
- handleResourceName(targetResourceId, heatFileName, heatOrchestrationTemplate,
- context);
- }
- if (!targetResourceTranslatedId.isPresent()) {
- //unsupported resource
- toscaAttributeParamList
- .add(
- FunctionTranslationHelper.getUnsupportedResourcePrefix() + attributeParamList.get(0));
- return toscaAttributeParamList;
- } else {
- toscaAttributeParamList.add(targetResourceTranslatedId.get());
+ Optional<String> targetResourceTranslatedId = Optional.empty();
+ String targetResourceId = null;
+ if (attributeParamList.get(0) instanceof String) {
+ targetResourceId = (String) attributeParamList.get(0);
+ targetResourceTranslatedId = handleResourceName(targetResourceId, functionTranslator.getHeatFileName(),
+ functionTranslator.getHeatOrchestrationTemplate(), functionTranslator.getContext());
+ }
+ if (!targetResourceTranslatedId.isPresent()) {
+ //unsupported resource
+ toscaAttributeParamList.add(functionTranslator.getUnsupportedResourcePrefix() + attributeParamList.get(0));
+ return toscaAttributeParamList;
+ }
+ toscaAttributeParamList.add(targetResourceTranslatedId.get());
+ Optional<List<Object>> toscaAttList = handleAttributeName(attributeParamList, functionTranslator);
+ if (!toscaAttList.isPresent()) {
+ //Unsupported attribute
+ toscaAttributeParamList.clear();
+ toscaAttributeParamList.add(functionTranslator.getUnsupportedAttributePrefix()
+ + attributeParamList.get(0) + "." + attributeParamList.get(1));
+ return toscaAttributeParamList;
+ }
+ toscaAttributeParamList.addAll(toscaAttList.get());
+ handleGetAttrConsolidationData(functionTranslator, targetResourceId, targetResourceTranslatedId.get(),
+ toscaAttList.get());
+
+ String resourceType = HeatToToscaUtil.getResourceType((String) attributeParamList.get(0), functionTranslator
+ .getHeatOrchestrationTemplate(), functionTranslator.getHeatFileName());
+ Optional<List<Object>> toscaIndexOrKey = handleAttributeIndexOrKey(functionTranslator, resourceType,
+ attributeParamList);
+ toscaIndexOrKey.ifPresent(toscaAttributeParamList::addAll);
+ return toscaAttributeParamList;
}
- Optional<List<Object>> toscaAttList =
- handleAttributeName(attributeParamList, heatOrchestrationTemplate, propertyName,
- heatFileName, serviceTemplate,
- context);
- if (!toscaAttList.isPresent()) {
- //Unsupported attribute
- toscaAttributeParamList.clear();
- toscaAttributeParamList
- .add(FunctionTranslationHelper.getUnsupportedAttributePrefix() + attributeParamList.get(0)
- + "." + attributeParamList.get(1));
- return toscaAttributeParamList;
- } else {
- toscaAttributeParamList.addAll(toscaAttList.get());
-
- handleGetAttrConsolidationData(serviceTemplate, resourceId, propertyName, heatFileName,
- heatOrchestrationTemplate, context, targetResourceId,
- targetResourceTranslatedId,
- toscaAttList.get());
+ private static void handleGetAttrConsolidationData(FunctionTranslator functionTranslator,
+ String targetResourceId,
+ String targetResourceTranslatedId,
+ List<Object> toscaAttList) {
+
+ Optional<String> resourceTranslatedId;
+ String resourceId = functionTranslator.getResourceId();
+ String resourceTranslatedIdValue = null;
+ if (resourceId != null) {
+ resourceTranslatedId = handleResourceName(resourceId, functionTranslator.getHeatFileName(),
+ functionTranslator.getHeatOrchestrationTemplate(), functionTranslator.getContext());
+ if (resourceTranslatedId.isPresent()) {
+ resourceTranslatedIdValue = resourceTranslatedId.get();
+ handleGetAttrOutConsolidationData(functionTranslator, targetResourceTranslatedId,
+ resourceTranslatedIdValue, toscaAttList);
+ }
+ }
+ handleGetAttrInConsolidationData(functionTranslator, resourceTranslatedIdValue, targetResourceId,
+ targetResourceTranslatedId, toscaAttList);
}
- Optional<List<Object>> toscaIndexOrKey = handleAttributeIndexOrKey(serviceTemplate,
- resourceId, propertyName, HeatToToscaUtil
- .getResourceType((String) attributeParamList.get(0), heatOrchestrationTemplate,
- heatFileName), attributeParamList, context, heatFileName,
- heatOrchestrationTemplate);
- toscaIndexOrKey.ifPresent(toscaAttributeParamList::addAll);
-
- return toscaAttributeParamList;
- }
-
- private static void handleGetAttrConsolidationData(
- ServiceTemplate serviceTemplate,
- String resourceId, String propertyName,
- String heatFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- TranslationContext context,
- String targetResourceId,
- Optional<String> targetResourceTranslatedId,
- List<Object> toscaAttList) {
-
- Optional<String> resourceTranslatedId = Optional.empty();
- if (resourceId != null) {
- resourceTranslatedId =
- handleResourceName(resourceId, heatFileName, heatOrchestrationTemplate,
- context);
- resourceTranslatedId
- .ifPresent(resourceTranslatedIdValue -> handleGetAttrOutConsolidationData(serviceTemplate,
- propertyName,
- heatOrchestrationTemplate, context, resourceId, targetResourceTranslatedId.get(),
- resourceTranslatedIdValue, toscaAttList, heatFileName));
+ private static void handleGetAttrOutConsolidationData(FunctionTranslator functionTranslator,
+ String targetTranslatedResourceId,
+ String resourceTranslatedId,
+ List<Object> toscaAttList) {
+ if (functionTranslator.getServiceTemplate() == null) {
+ return;
+ }
+ Optional<EntityConsolidationData> entityConsolidationData = getEntityConsolidationData(functionTranslator,
+ functionTranslator.getResourceId(), resourceTranslatedId);
+ if (entityConsolidationData.isPresent()) {
+ String attName = (String) toscaAttList.get(0);
+ handleNodeGetAttrOut(targetTranslatedResourceId, functionTranslator, entityConsolidationData.get(),
+ attName);
+ }
}
- if (targetResourceTranslatedId.isPresent()) {
- handleGetAttrInConsolidationData(serviceTemplate, resourceId, resourceTranslatedId,
- propertyName, heatOrchestrationTemplate, context, targetResourceId,
- targetResourceTranslatedId.get(), toscaAttList, heatFileName);
- }
- }
-
- private static void handleGetAttrOutConsolidationData(
- ServiceTemplate serviceTemplate,
- String propertyName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- TranslationContext context,
- String resourceId,
- String targetTranslatedResourceId,
- String resourceTranslatedId,
- List<Object> toscaAttList,
- String heatFileName) {
- if (serviceTemplate != null) {
- Optional<EntityConsolidationData> entityConsolidationData =
- getEntityConsolidationData(serviceTemplate, heatOrchestrationTemplate, context,
- resourceId, resourceTranslatedId, heatFileName);
- if (entityConsolidationData.isPresent()) {
- String attName = (String) toscaAttList.get(0);
- handleNodeGetAttrOut(targetTranslatedResourceId, propertyName, heatOrchestrationTemplate,
- context, resourceId, entityConsolidationData.get(), attName);
- }
- }
- }
-
- private static void handleGetAttrInConsolidationData(
- ServiceTemplate serviceTemplate,
- String resourceId,
- Optional<String> resourceTranslatedId,
- String propertyName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- TranslationContext context,
- String targetResourceId,
- String targetResourceTranslatedId,
- List<Object> toscaAttList,
- String heatFileName) {
-
- if (serviceTemplate != null) {
- Optional<EntityConsolidationData> entityConsolidationData =
- getEntityConsolidationData(serviceTemplate, heatOrchestrationTemplate, context,
- targetResourceId, targetResourceTranslatedId, heatFileName);
- if (entityConsolidationData.isPresent()) {
+ private static void handleGetAttrInConsolidationData(FunctionTranslator functionTranslator,
+ String resourceTranslatedId,
+ String targetResourceId,
+ String targetResourceTranslatedId,
+ List<Object> toscaAttList) {
+ if (functionTranslator.getServiceTemplate() == null) {
+ return;
+ }
+ Optional<EntityConsolidationData> entityConsolidationData = getEntityConsolidationData(functionTranslator,
+ targetResourceId, targetResourceTranslatedId);
+ if (!entityConsolidationData.isPresent()) {
+ return;
+ }
String attName = (String) toscaAttList.get(0);
- if (resourceTranslatedId.isPresent()) {
- handleNodeGetAttrIn(resourceTranslatedId.get(), propertyName, heatOrchestrationTemplate,
- context,
- resourceId, entityConsolidationData.get(), attName);
+ if (Objects.nonNull(resourceTranslatedId)) {
+ handleNodeGetAttrIn(resourceTranslatedId, functionTranslator, entityConsolidationData.get(), attName);
} else {
- ConsolidationDataUtil
- .updateOutputGetAttributeInConsolidationData(entityConsolidationData.get(),
- propertyName, attName);
+ ConsolidationDataUtil.updateOutputGetAttributeInConsolidationData(entityConsolidationData.get(),
+ functionTranslator.getPropertyName(), attName);
}
- }
- }
- }
-
- private static void handleNodeGetAttrOut(String nodeTemplateId, String propertyName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- TranslationContext context, String resourceId,
- EntityConsolidationData entityConsolidationData,
- String attName) {
- Resource resource = heatOrchestrationTemplate.getResources().get(resourceId);
- boolean isNestedResource = HeatToToscaUtil.isNestedResource(resource);
- String toscaPropertyName = propertyName;
- if (!isNestedResource) {
- toscaPropertyName = HeatToToscaUtil.getToscaPropertyName(context, resource
- .getType(), propertyName);
- }
- ConsolidationDataUtil
- .updateNodeGetAttributeOut(entityConsolidationData,
- nodeTemplateId, toscaPropertyName, attName);
- }
-
- private static void handleNodeGetAttrIn(String nodeTemplateId, String propertyName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- TranslationContext context, String resourceId,
- EntityConsolidationData entityConsolidationData,
- String attName) {
- Resource resource = heatOrchestrationTemplate.getResources().get(resourceId);
- boolean isNestedResource = HeatToToscaUtil.isNestedResource(resource);
- String heatPropertyName = propertyName;
- String toscaPropertyName = propertyName;
- //For handling get_attr in inner levels for complex properties
- if (propertyName.contains(TRANS_MAPPING_DELIMITER_CHAR)) {
- heatPropertyName = propertyName.substring(0,
- propertyName.indexOf(TRANS_MAPPING_DELIMITER_CHAR));
- }
- if (!isNestedResource) {
- toscaPropertyName = HeatToToscaUtil.getToscaPropertyName(context, resource
- .getType(), heatPropertyName);
}
- ConsolidationDataUtil
- .updateNodeGetAttributeIn(entityConsolidationData,
- nodeTemplateId, toscaPropertyName, attName);
- }
-
- private static Optional<EntityConsolidationData> getEntityConsolidationData(
- ServiceTemplate serviceTemplate,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- TranslationContext context,
- String resourceId,
- String resourceTranslatedId,
- String heatFileName) {
- Resource resource = heatOrchestrationTemplate.getResources().get(resourceId);
- if (ConsolidationDataUtil.isComputeResource(heatOrchestrationTemplate, resourceId)) {
- String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType();
- NameExtractor nodeTypeNameExtractor =
- context.getNameExtractorImpl(resourceType);
- String computeType =
- nodeTypeNameExtractor.extractNodeTypeName(
- resource, resourceId, context.getTranslatedIds().get(heatFileName).get(resourceId));
-
- return Optional.of(
- ConsolidationDataUtil.getComputeTemplateConsolidationData(context, serviceTemplate,
- computeType, resourceTranslatedId));
- } else if (ConsolidationDataUtil.isPortResource(heatOrchestrationTemplate, resourceId)) {
- return Optional.of(ConsolidationDataUtil
- .getPortTemplateConsolidationData(context, serviceTemplate, resourceId, resource.getType(),
- resourceTranslatedId));
- } else if (HeatToToscaUtil.isSubInterfaceResource(resource, context)) {
- TranslateTo subInterfaceTo = new TranslateTo(heatFileName, serviceTemplate, heatOrchestrationTemplate,
- resource, resourceId, resourceTranslatedId, context);
- Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
- ConsolidationDataUtil.getSubInterfaceTemplateConsolidationData(subInterfaceTo, resourceTranslatedId);
- if (subInterfaceTemplateConsolidationData.isPresent()) {
- return Optional.of(subInterfaceTemplateConsolidationData.get());
- }
- } else if (HeatToToscaUtil.isNestedResource(resource)) {
- return Optional.ofNullable(ConsolidationDataUtil
- .getNestedTemplateConsolidationData(context, serviceTemplate, heatFileName, resourceTranslatedId));
+
+ private static void handleNodeGetAttrOut(String nodeTemplateId, FunctionTranslator functionTranslator,
+ EntityConsolidationData entityConsolidationData,
+ String attName) {
+ Resource resource = functionTranslator.getHeatOrchestrationTemplate().getResources().get(functionTranslator
+ .getResourceId());
+ boolean isNestedResource = HeatToToscaUtil.isNestedResource(resource);
+ String toscaPropertyName = functionTranslator.getPropertyName();
+ if (!isNestedResource) {
+ toscaPropertyName = HeatToToscaUtil.getToscaPropertyName(functionTranslator.getContext(), resource
+ .getType(), functionTranslator.getPropertyName());
+ }
+ ConsolidationDataUtil.updateNodeGetAttributeOut(entityConsolidationData, nodeTemplateId, toscaPropertyName,
+ attName);
}
- return Optional.empty();
- }
-
- private static Optional<List<Object>> handleAttributeIndexOrKey(
- ServiceTemplate serviceTemplate,
- String resourceId, String propertyName,
- String resourceType,
- List<Object> attributeParamList,
- TranslationContext context,
- String heatFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate) {
-
- List<Object> attributeIndexOrKey = new ArrayList<>();
- if (attributeParamList.size() < 3) {
- return Optional.empty();
+
+ private static void handleNodeGetAttrIn(String nodeTemplateId, FunctionTranslator functionTranslator,
+ EntityConsolidationData entityConsolidationData,
+ String attName) {
+ Resource resource = functionTranslator.getHeatOrchestrationTemplate().getResources().get(functionTranslator
+ .getResourceId());
+ boolean isNestedResource = HeatToToscaUtil.isNestedResource(resource);
+ String propertyName = functionTranslator.getPropertyName();
+ String heatPropertyName = propertyName;
+ String toscaPropertyName = propertyName;
+ //For handling get_attr in inner levels for complex properties
+ if (propertyName.contains(TRANS_MAPPING_DELIMITER_CHAR)) {
+ heatPropertyName = propertyName.substring(0, propertyName.indexOf(TRANS_MAPPING_DELIMITER_CHAR));
+ }
+ if (!isNestedResource) {
+ toscaPropertyName = HeatToToscaUtil.getToscaPropertyName(functionTranslator.getContext(), resource
+ .getType(), heatPropertyName);
+ }
+ ConsolidationDataUtil.updateNodeGetAttributeIn(entityConsolidationData, nodeTemplateId, toscaPropertyName,
+ attName);
}
- Object attributeName = attributeParamList.get(1);
- for (int i = 2; i < attributeParamList.size(); i++) {
-
- if (isInteger(attributeParamList.get(i))) {
- attributeIndexOrKey.add(attributeParamList.get(i));
- } else if (attributeParamList.get(i) instanceof Map) {
- attributeIndexOrKey.add(getToscaAttributeValue(serviceTemplate, resourceId,
- propertyName, attributeParamList.get(i), resourceType, heatFileName,
- heatOrchestrationTemplate, null, context));
-
- } else {
- Object toscaAttributeName = resourceType == null ? null : context
- .getElementMapping(resourceType, Constants.ATTR,
- getAttributeFullPath(attributeParamList, i));
- if (toscaAttributeName == null) {
- toscaAttributeName = attributeParamList.get(i);
+ private static Optional<EntityConsolidationData> getEntityConsolidationData(FunctionTranslator functionTranslator,
+ String resourceId,
+ String resourceTranslatedId) {
+ HeatOrchestrationTemplate heatOrchestrationTemplate = functionTranslator.getHeatOrchestrationTemplate();
+ TranslationContext context = functionTranslator.getContext();
+ ServiceTemplate serviceTemplate = functionTranslator.getServiceTemplate();
+ String heatFileName = functionTranslator.getHeatFileName();
+
+ Resource resource = heatOrchestrationTemplate.getResources().get(resourceId);
+ if (ConsolidationDataUtil.isComputeResource(heatOrchestrationTemplate, resourceId)) {
+ String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType();
+ NameExtractor nodeTypeNameExtractor = TranslationContext.getNameExtractorImpl(resourceType);
+ String computeType = nodeTypeNameExtractor.extractNodeTypeName(resource, resourceId, context
+ .getTranslatedIds().get(heatFileName).get(resourceId));
+
+ return Optional.of(ConsolidationDataUtil.getComputeTemplateConsolidationData(context, serviceTemplate,
+ computeType, resourceTranslatedId));
+ } else if (ConsolidationDataUtil.isPortResource(heatOrchestrationTemplate, resourceId)) {
+ return Optional.of(ConsolidationDataUtil
+ .getPortTemplateConsolidationData(context, serviceTemplate, resourceId, resource.getType(),
+ resourceTranslatedId));
+ } else if (HeatToToscaUtil.isSubInterfaceResource(resource, context)) {
+ TranslateTo subInterfaceTo = new TranslateTo(heatFileName, serviceTemplate, heatOrchestrationTemplate,
+ resource, resourceId, resourceTranslatedId, context);
+ Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
+ ConsolidationDataUtil.getSubInterfaceTemplateConsolidationData(subInterfaceTo,
+ resourceTranslatedId);
+ if (subInterfaceTemplateConsolidationData.isPresent()) {
+ return Optional.of(subInterfaceTemplateConsolidationData.get());
+ }
+ } else if (HeatToToscaUtil.isNestedResource(resource)) {
+ return Optional.ofNullable(ConsolidationDataUtil
+ .getNestedTemplateConsolidationData(context, serviceTemplate, heatFileName, resourceTranslatedId));
}
- attributeIndexOrKey.add(toscaAttributeName);
- }
+ return Optional.empty();
}
- return Optional.of(attributeIndexOrKey);
- }
+ private static Optional<List<Object>> handleAttributeIndexOrKey(FunctionTranslator functionTranslator,
+ String resourceType,
+ List<Object> attributeParamList) {
- private static String getAttributeFullPath(List<Object> attributeParamList, int attributeIndex) {
- if (attributeParamList.size() < 3) {
- return null;
- }
- StringBuilder attributeFullPath = new StringBuilder();
- attributeFullPath.append(attributeParamList.get(1));
- for (int j = 2; j <= attributeIndex; j++) {
- if (isInteger(attributeParamList.get(j))) {
- continue;
- }
- attributeFullPath.append(TRANS_MAPPING_DELIMITER_CHAR);
- attributeFullPath.append(attributeParamList.get(j));
+ List<Object> attributeIndexOrKey = new ArrayList<>();
+ if (attributeParamList.size() < 3) {
+ return Optional.empty();
+ }
+
+ for (int i = 2; i < attributeParamList.size(); i++) {
+ if (isInteger(attributeParamList.get(i))) {
+ attributeIndexOrKey.add(attributeParamList.get(i));
+ } else if (attributeParamList.get(i) instanceof Map) {
+ attributeIndexOrKey.add(getToscaAttributeValue(functionTranslator, attributeParamList.get(i)));
+ } else {
+ Object toscaAttributeName = resourceType == null ? null : functionTranslator.getContext()
+ .getElementMapping(resourceType, Constants.ATTR, getAttributeFullPath(attributeParamList, i));
+ if (toscaAttributeName == null) {
+ toscaAttributeName = attributeParamList.get(i);
+ }
+ attributeIndexOrKey.add(toscaAttributeName);
+ }
+ }
+
+ return Optional.of(attributeIndexOrKey);
}
- return attributeFullPath.toString();
- }
- private static boolean isInteger(Object inputNumber) {
- if (inputNumber == null) {
- return false;
+ private static String getAttributeFullPath(List<Object> attributeParamList, int attributeIndex) {
+ if (attributeParamList.size() < 3) {
+ return null;
+ }
+ StringBuilder attributeFullPath = new StringBuilder();
+ attributeFullPath.append(attributeParamList.get(1));
+ for (int j = 2; j <= attributeIndex; j++) {
+ if (isInteger(attributeParamList.get(j))) {
+ continue;
+ }
+ attributeFullPath.append(TRANS_MAPPING_DELIMITER_CHAR);
+ attributeFullPath.append(attributeParamList.get(j));
+ }
+ return attributeFullPath.toString();
}
- if (StringUtils.isNumeric(String.valueOf(inputNumber))){
- return true;
- } else {
- return false;
+ private static boolean isInteger(Object inputNumber) {
+ if (inputNumber == null) {
+ return false;
+ }
+ return StringUtils.isNumeric(String.valueOf(inputNumber));
}
- }
-
- private static Optional<String> handleResourceName(String resourceId, String heatFileName,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- TranslationContext context) {
- return ResourceTranslationBase
- .getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, resourceId, context);
- }
-
- private static Optional<List<Object>> handleAttributeName(List<Object> attributeParamList,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- String propertyName,
- String heatFileName,
- ServiceTemplate serviceTemplate,
- TranslationContext context) {
- String resourceId = (String) attributeParamList.get(0);
- Resource resource =
- HeatToToscaUtil.getResource(heatOrchestrationTemplate, resourceId, heatFileName);
-
- if (attributeParamList.size() == 1) {
- return getResourceTranslatedAttributesList(resource, context);
+
+ private static Optional<String> handleResourceName(String resourceId, String heatFileName,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context) {
+ return ResourceTranslationBase
+ .getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, resourceId, context);
}
- if (!(attributeParamList.get(1) instanceof String)) {
- return Optional.empty();
+ private static Optional<List<Object>> handleAttributeName(List<Object> attributeParamList,
+ FunctionTranslator functionTranslator) {
+ String resourceId = (String) attributeParamList.get(0);
+ Resource resource = HeatToToscaUtil.getResource(functionTranslator.getHeatOrchestrationTemplate(),
+ resourceId, functionTranslator.getHeatFileName());
+ if (attributeParamList.size() == 1) {
+ return getResourceTranslatedAttributesList(resource, functionTranslator.getContext());
+ }
+ if (!(attributeParamList.get(1) instanceof String)) {
+ return Optional.empty();
+ }
+ if (HeatToToscaUtil.isNestedResource(resource)) {
+ return getNestedResourceTranslatedAttribute((String) attributeParamList.get(1));
+ } else {
+ return getResourceTranslatedAttribute(resource, (String) attributeParamList.get(1), functionTranslator
+ .getContext());
+ }
}
- if (HeatToToscaUtil.isNestedResource(resource)) {
- return getNestedResourceTranslatedAttribute((String) attributeParamList.get(1));
- } else {
- return getResourceTranslatedAttribute(resource, (String) attributeParamList.get(1), context);
+ private static Optional<List<Object>> getNestedResourceTranslatedAttribute(String attributeName) {
+ List<Object> translatedAttributesList = new ArrayList<>();
+ if (attributeName.startsWith(HeatConstants.GET_ATTR_FROM_RESOURCE_GROUP_PREFIX)) {
+ String[] attributeSplit = attributeName.split("\\.");
+ if (attributeSplit.length == 2) {
+ translatedAttributesList.add(attributeSplit[1]);
+ } else if (attributeSplit.length == 3) {
+ translatedAttributesList.add(attributeSplit[2]);
+ translatedAttributesList.add(Integer.valueOf(attributeSplit[1]));
+ } else {
+ return Optional.empty();
+ }
+ } else {
+ translatedAttributesList.add(attributeName);
+ }
+ return Optional.of(translatedAttributesList);
}
- }
-
- private static Optional<List<Object>> getNestedResourceTranslatedAttribute(String attributeName) {
- List<Object> translatedAttributesList = new ArrayList<>();
-
- if (attributeName.startsWith(HeatConstants.GET_ATTR_FROM_RESOURCE_GROUP_PREFIX)) {
- String[] attributeSplit = attributeName.split("\\.");
- if (attributeSplit.length == 2) {
- translatedAttributesList.add(attributeSplit[1]);
- } else if (attributeSplit.length == 3) {
- translatedAttributesList.add(attributeSplit[2]);
- translatedAttributesList.add(Integer.valueOf(attributeSplit[1]));
- } else {
- return Optional.empty();
- }
- } else {
- translatedAttributesList.add(attributeName);
+
+ private static Optional<List<Object>> getResourceTranslatedAttributesList(Resource resource,
+ TranslationContext context) {
+ List<Object> translatedAttributes = new ArrayList<>();
+ if (HeatToToscaUtil.isNestedResource(resource)) {
+ Optional<String> nestedFile = HeatToToscaUtil.getNestedFile(resource);
+ if (!nestedFile.isPresent()) {
+ return Optional.empty();
+ }
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil()
+ .yamlToObject(context.getFiles().getFileContent(nestedFile.get()), HeatOrchestrationTemplate.class);
+ translatedAttributes.addAll(nestedHeatOrchestrationTemplate.getOutputs().keySet());
+ return Optional.of(translatedAttributes);
+
+ } else {
+ Map<String, String> resourceMappingAttributes =
+ context.getElementMapping(resource.getType(), Constants.ATTR);
+ if (resourceMappingAttributes == null) {
+ return Optional.empty();
+ }
+ Set<String> mappingAttributes = new HashSet<>(new ArrayList<>(resourceMappingAttributes.values()));
+ translatedAttributes.addAll(mappingAttributes);
+ return Optional.of(translatedAttributes);
+ }
}
- return Optional.of(translatedAttributesList);
- }
-
- private static Optional<List<Object>> getResourceTranslatedAttributesList(Resource resource,
- TranslationContext
- context) {
- List<Object> translatedAttributes = new ArrayList<>();
- if (HeatToToscaUtil.isNestedResource(resource)) {
- Optional<String> nestedFile = HeatToToscaUtil.getNestedFile(resource);
- if (!nestedFile.isPresent()) {
- return Optional.empty();
- }
- HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil()
- .yamlToObject(context.getFiles().getFileContent(nestedFile.get()),
- HeatOrchestrationTemplate.class);
- translatedAttributes.addAll(nestedHeatOrchestrationTemplate.getOutputs().keySet());
- return Optional.of(translatedAttributes);
-
- } else {
- Map<String, String> resourceMappingAttributes =
- context.getElementMapping(resource.getType(), Constants.ATTR);
- if (resourceMappingAttributes == null) {
- return Optional.empty();
- }
- Set<String> mappingAttributes = new HashSet<>();
- mappingAttributes
- .addAll(resourceMappingAttributes.values().stream().collect(Collectors.toList()));
- translatedAttributes.addAll(mappingAttributes);
- return Optional.of(translatedAttributes);
+
+ private static Optional<List<Object>> getResourceTranslatedAttribute(Resource resource,
+ String attributeName,
+ TranslationContext context) {
+ List<Object> translatedAttributesList = new ArrayList<>();
+ String translatedAttribute = context.getElementMapping(resource.getType(), Constants.ATTR, attributeName);
+ if (translatedAttribute != null) {
+ translatedAttributesList.add(translatedAttribute);
+ return Optional.of(translatedAttributesList);
+ } else { //unsupported attribute
+ return Optional.empty();
+ }
}
- }
-
- private static Optional<List<Object>> getResourceTranslatedAttribute(Resource resource,
- String attributeName,
- TranslationContext context) {
- List<Object> translatedAttributesList = new ArrayList<>();
- String translatedAttribute =
- context.getElementMapping(resource.getType(), Constants.ATTR, attributeName);
- if (translatedAttribute != null) {
- translatedAttributesList.add(translatedAttribute);
- return Optional.of(translatedAttributesList);
- } else { //unsupported attribute
- return Optional.empty();
+
+ private static Object getToscaAttributeValue(FunctionTranslator functionTranslator,
+ Object attributeVal) {
+ if (attributeVal instanceof Map && !((Map) attributeVal).isEmpty()) {
+ Map.Entry<String, Object> functionMapEntry =
+ (Map.Entry<String, Object>) ((Map) attributeVal).entrySet().iterator().next();
+ Optional<FunctionTranslation> functionTranslationInstance =
+ FunctionTranslationFactory.getInstance(functionMapEntry.getKey());
+ if (functionTranslationInstance.isPresent()) {
+ functionTranslator.setFunctionValue(functionMapEntry.getValue());
+ return functionTranslationInstance.get().translateFunction(functionTranslator);
+ }
+ Map<String, Object> attrValueMap = new HashMap<>();
+ for (Map.Entry<String, Object> entry : ((Map<String, Object>) attributeVal).entrySet()) {
+ attrValueMap.put(entry.getKey(), getToscaAttributeValue(functionTranslator, entry.getValue()));
+ }
+ return attrValueMap;
+ } else if (attributeVal instanceof List && !((List) attributeVal).isEmpty()) {
+ List<Object> propertyValueArray = new ArrayList<>();
+ for (int i = 0; i < ((List) attributeVal).size(); i++) {
+ propertyValueArray.add(getToscaAttributeValue(functionTranslator, ((List) attributeVal).get(i)));
+ }
+ return propertyValueArray;
+ }
+ return attributeVal;
}
- }
-
- private static Object getToscaAttributeValue(ServiceTemplate serviceTemplate,
- String resourceId, String propertyName,
- Object attributeVal, String resourceType,
- String heatFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- Template template, TranslationContext context) {
- if (attributeVal instanceof Map && !((Map) attributeVal).isEmpty()) {
- Map.Entry<String, Object> functionMapEntry =
- (Map.Entry<String, Object>) ((Map) attributeVal).entrySet().iterator().next();
- if (FunctionTranslationFactory.getInstance(functionMapEntry.getKey()).isPresent()) {
- return FunctionTranslationFactory.getInstance(functionMapEntry.getKey()).get()
- .translateFunction(serviceTemplate, resourceId, propertyName,
- functionMapEntry.getKey(), functionMapEntry
- .getValue(), heatFileName, heatOrchestrationTemplate, template, context);
- }
- Map<String, Object> attrValueMap = new HashMap<>();
- for (Map.Entry<String, Object> entry : ((Map<String, Object>) attributeVal).entrySet()) {
- attrValueMap.put(entry.getKey(),
- getToscaAttributeValue(serviceTemplate, resourceId, propertyName, entry.getValue(),
- resourceType, heatFileName, heatOrchestrationTemplate, template, context));
- }
- return attrValueMap;
- } else if (attributeVal instanceof List && !((List) attributeVal).isEmpty()) {
- List propertyValueArray = new ArrayList<>();
- for (int i = 0; i < ((List) attributeVal).size(); i++) {
- propertyValueArray.add(
- getToscaAttributeValue(serviceTemplate, resourceId, propertyName,
- ((List) attributeVal).get(i), resourceType, heatFileName,
- heatOrchestrationTemplate, template, context));
- }
- return propertyValueArray;
+
+ @Override
+ public Object translateFunction(FunctionTranslator functionTranslator) {
+ Object returnValue;
+ List<Object> attributeFunctionExpression = translateGetAttributeFunctionExpression(functionTranslator);
+ if (functionTranslator.isResourceSupported(attributeFunctionExpression.get(0).toString())
+ && functionTranslator.isAttributeSupported(attributeFunctionExpression.get(0).toString())) {
+ Map<String, Object> getAttrValue = new HashMap<>();
+ getAttrValue.put(ToscaFunctions.GET_ATTRIBUTE.getDisplayName(), attributeFunctionExpression);
+ returnValue = getAttrValue;
+ } else {
+ returnValue = attributeFunctionExpression;
+ }
+ return returnValue;
}
- return attributeVal;
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetFileImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetFileImpl.java
index 73ca52051a..a56350c143 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetFileImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetFileImpl.java
@@ -1,87 +1,65 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation;
-import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
-import org.openecomp.sdc.tosca.datatypes.ToscaArtifactType;
-import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.onap.sdc.tosca.datatypes.model.ArtifactDefinition;
import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.onap.sdc.tosca.datatypes.model.Template;
+import org.openecomp.sdc.tosca.datatypes.ToscaArtifactType;
+import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.tosca.services.ToscaFileOutputService;
import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
-import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslation;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author SHIRIA
- * @since December 15, 2016.
- */
public class FunctionTranslationGetFileImpl implements FunctionTranslation {
- @Override
- public Object translateFunction(ServiceTemplate serviceTemplate,
- String resourceId, String propertyName, String functionKey,
- Object functionValue, String heatFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- Template toscaTemplate, TranslationContext context) {
- String file = ((String) functionValue).replace("file:///", "");
- Object returnValue;
- final String artifactId = file.split("\\.")[0];
+ private static ArtifactDefinition createArtifactDefinition(Object function,
+ ToscaFileOutputService toscaFileOutputService) {
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setType(ToscaArtifactType.NATIVE_DEPLOYMENT);
+ artifactDefinition.setFile("../" + toscaFileOutputService.getArtifactsFolderName() + "/" + function);
+ return artifactDefinition;
+ }
- returnValue = new HashMap<>();
- List artifactParameters = new ArrayList();
- artifactParameters.add(0, ToscaConstants.MODELABLE_ENTITY_NAME_SELF);
- ((Map) returnValue).put(ToscaFunctions.GET_ARTIFACT.getDisplayName(), artifactParameters);
- artifactParameters.add(1, artifactId);
+ @Override
+ public Object translateFunction(FunctionTranslator functionTranslator) {
- ToscaFileOutputService toscaFileOutputService = new ToscaFileOutputServiceCsarImpl();
- if (toscaTemplate != null) {
- if (toscaTemplate instanceof NodeTemplate) {
- NodeTemplate nodeTemplate = (NodeTemplate) toscaTemplate;
- ArtifactDefinition artifactDefinition =
- createArtifactDefinition(file, toscaFileOutputService);
- if (nodeTemplate.getArtifacts() == null) {
- nodeTemplate.setArtifacts(new HashMap<>());
+ String file = ((String) functionTranslator.getFunctionValue()).replace("file:///", "");
+ final String artifactId = file.split("\\.")[0];
+ Map<String, Object> returnValue = new HashMap<>();
+ List<String> artifactParameters = new ArrayList<>();
+ artifactParameters.add(ToscaConstants.MODELABLE_ENTITY_NAME_SELF);
+ returnValue.put(ToscaFunctions.GET_ARTIFACT.getDisplayName(), artifactParameters);
+ artifactParameters.add(artifactId);
+
+ ToscaFileOutputService toscaFileOutputService = new ToscaFileOutputServiceCsarImpl();
+ if (functionTranslator.getToscaTemplate() instanceof NodeTemplate) {
+ NodeTemplate nodeTemplate = (NodeTemplate) functionTranslator.getToscaTemplate();
+ ArtifactDefinition artifactDefinition = createArtifactDefinition(file, toscaFileOutputService);
+ if (nodeTemplate.getArtifacts() == null) {
+ nodeTemplate.setArtifacts(new HashMap<>());
+ }
+ nodeTemplate.getArtifacts().put(artifactId, artifactDefinition);
}
- nodeTemplate.getArtifacts().put(artifactId, artifactDefinition);
- }
+ return returnValue;
}
- return returnValue;
- }
-
- private static ArtifactDefinition createArtifactDefinition(Object function,
- ToscaFileOutputService
- toscaFileOutputService) {
- ArtifactDefinition artifactDefinition = new ArtifactDefinition();
- artifactDefinition.setType(ToscaArtifactType.NATIVE_DEPLOYMENT);
- artifactDefinition
- .setFile("../" + toscaFileOutputService.getArtifactsFolderName() + "/" + function);
- return artifactDefinition;
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetParamImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetParamImpl.java
index a9f8e5975e..b25d33618f 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetParamImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetParamImpl.java
@@ -1,128 +1,95 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation;
-import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
-import org.openecomp.sdc.heat.datatypes.model.HeatPseudoParameters;
-import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.onap.sdc.tosca.datatypes.model.Template;
-import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
-import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslation;
-import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslationFactory;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
-/**
- * @author SHIRIA
- * @since December 15, 2016.
- */
-public class FunctionTranslationGetParamImpl implements FunctionTranslation {
- @Override
- public Object translateFunction(ServiceTemplate serviceTemplate, String resourceId,
- String propertyName, String functionKey,
- Object functionValue, String heatFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- Template toscaTemplate, TranslationContext context) {
- Map returnValue = new HashMap<>();
- returnValue.put(ToscaFunctions.GET_INPUT.getDisplayName(),
- translateGetParamFunctionExpression(serviceTemplate, resourceId, propertyName,
- functionValue, heatFileName, heatOrchestrationTemplate, context));
- return returnValue;
- }
+import org.openecomp.sdc.heat.datatypes.model.HeatPseudoParameters;
+import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
+import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslation;
+import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslationFactory;
- private static Object translateGetParamFunctionExpression(ServiceTemplate serviceTemplate,
- String resourceId,
- String propertyName,Object functionValue,
- String heatFileName,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- TranslationContext context) {
- Object returnValue = null;
- if (functionValue instanceof String) {
- returnValue = functionValue;
- if (HeatPseudoParameters.getPseudoParameterNames().contains(functionValue)) {
- context
- .addUsedHeatPseudoParams(heatFileName, (String) functionValue, (String) functionValue);
- }
- } else if (functionValue instanceof List) {
- returnValue = new ArrayList<>();
- for (int i = 0; i < ((List) functionValue).size(); i++) {
- Object paramValue = ((List) functionValue).get(i);
- if ((paramValue instanceof Map && !((Map) paramValue).isEmpty())) {
- Map<String, Object> paramMap = (Map) paramValue;
- ((List) returnValue).add(translatedInnerMap(serviceTemplate, resourceId,
- propertyName, paramMap, heatFileName, heatOrchestrationTemplate, context));
- } else {
- ((List) returnValue).add(paramValue);
+public class FunctionTranslationGetParamImpl implements FunctionTranslation {
+ private static Object translateGetParamFunctionExpression(FunctionTranslator functionTranslator) {
+ Object functionValue = functionTranslator.getFunctionValue();
+ Object returnValue = null;
+ if (functionValue instanceof String) {
+ returnValue = functionValue;
+ if (HeatPseudoParameters.getPseudoParameterNames().contains(functionValue)) {
+ functionTranslator.getContext().addUsedHeatPseudoParams(functionTranslator.getHeatFileName(),
+ (String) functionValue, (String) functionValue);
+ }
+ } else if (functionValue instanceof List) {
+ returnValue = new ArrayList<>();
+ for (int i = 0; i < ((List) functionValue).size(); i++) {
+ Object paramValue = ((List) functionValue).get(i);
+ if ((paramValue instanceof Map && !((Map) paramValue).isEmpty())) {
+ Map<String, Object> paramMap = (Map) paramValue;
+ ((List) returnValue).add(translatedInnerMap(functionTranslator, paramMap));
+ } else {
+ ((List) returnValue).add(paramValue);
+ }
+ }
}
- }
- }
- return returnValue;
- }
+ return returnValue;
+ }
- private static Object translatedInnerMap(ServiceTemplate serviceTemplate, String resourceId,
- String propertyName, Map<String, Object> paramMap,
- String heatFileName,HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- TranslationContext context) {
+ private static Object translatedInnerMap(FunctionTranslator functionTranslator, Map<String, Object> paramMap) {
+ Map<String, Object> translatedInnerMapValue = new HashMap<>();
+ for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
+ Optional<FunctionTranslation> functionTranslationInstance =
+ FunctionTranslationFactory.getInstance(entry.getKey());
+ if (functionTranslationInstance.isPresent()) {
+ functionTranslator.setFunctionValue(entry.getValue());
+ return functionTranslationInstance.get().translateFunction(functionTranslator);
+ } else {
+ translatedInnerMapValue.put(entry.getKey(), translatedInnerValue(functionTranslator, entry.getValue()));
+ }
+ }
+ return translatedInnerMapValue;
+ }
- Map<String, Object> translatedInnerMapValue = new HashMap<>();
- for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
- if (FunctionTranslationFactory.getInstance(entry.getKey()).isPresent()) {
- return FunctionTranslationFactory.getInstance(entry.getKey()).get()
- .translateFunction(serviceTemplate, resourceId, propertyName, entry.getKey(),
- entry.getValue(), heatFileName, heatOrchestrationTemplate, null, context);
- } else {
- translatedInnerMapValue.put(entry.getKey(),
- translatedInnerValue(serviceTemplate, resourceId, propertyName,entry.getValue(),
- heatFileName, heatOrchestrationTemplate, context));
+ private static Object translatedInnerValue(FunctionTranslator functionTranslator,
+ Object value) {
+ if (value instanceof String) {
+ return value;
+ } else if (value instanceof Map) {
+ return translatedInnerMap(functionTranslator, (Map<String, Object>) value);
+ } else if (value instanceof List) {
+ List<Object> returnedList = new ArrayList<>();
+ for (int i = 0; i < ((List) value).size(); i++) {
+ returnedList.add(translatedInnerValue(functionTranslator, ((List) value).get(i)));
+ }
+ return returnedList;
+ }
- }
+ return value;
}
- return translatedInnerMapValue;
- }
- private static Object translatedInnerValue(ServiceTemplate serviceTemplate, String resourceId,
- String propertyName,Object value, String heatFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- TranslationContext context) {
- if (value instanceof String) {
- return value;
- } else if (value instanceof Map) {
- return translatedInnerMap(serviceTemplate, resourceId, propertyName,(Map<String, Object>)
- value, heatFileName, heatOrchestrationTemplate, context);
- } else if (value instanceof List) {
- List returnedList = new ArrayList();
- for (int i = 0; i < ((List) value).size(); i++) {
- returnedList.add(translatedInnerValue(serviceTemplate, resourceId, propertyName,
- ((List) value).get(i), heatFileName, heatOrchestrationTemplate, context));
- }
- return returnedList;
+ @Override
+ public Object translateFunction(FunctionTranslator functionTranslator) {
+ Map<String, Object> returnValue = new HashMap<>();
+ returnValue.put(ToscaFunctions.GET_INPUT.getDisplayName(),
+ translateGetParamFunctionExpression(functionTranslator));
+ return returnValue;
}
-
- return value;
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetResourceImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetResourceImpl.java
index ffb0b7212c..6bd6bf3aa7 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetResourceImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetResourceImpl.java
@@ -1,52 +1,35 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation;
-import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.onap.sdc.tosca.datatypes.model.Template;
-import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
+import java.util.Optional;
+
import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslation;
-import org.openecomp.sdc.translator.services.heattotosca.helper.FunctionTranslationHelper;
import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.ResourceTranslationBase;
-import java.util.Optional;
-
-/**
- * @author SHIRIA
- * @since December 15, 2016.
- */
public class FunctionTranslationGetResourceImpl implements FunctionTranslation {
- @Override
- public Object translateFunction(ServiceTemplate serviceTemplate, String resourceId,
- String propertyName, String functionKey,
- Object functionValue, String heatFileName,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- Template toscaTemplate, TranslationContext context) {
- Object returnValue;
- Optional<String> resourceTranslatedId = ResourceTranslationBase
- .getResourceTranslatedId(heatFileName, heatOrchestrationTemplate, (String) functionValue,
- context);
- returnValue = resourceTranslatedId
- .orElseGet(() -> FunctionTranslationHelper.getUnsupportedResourcePrefix() + functionValue);
- return returnValue;
- }
+ @Override
+ public Object translateFunction(FunctionTranslator functionTranslator) {
+ Object returnValue;
+ Optional<String> resourceTranslatedId = ResourceTranslationBase.getResourceTranslatedId(functionTranslator
+ .getHeatFileName(), functionTranslator.getHeatOrchestrationTemplate(),
+ (String) functionTranslator.getFunctionValue(), functionTranslator.getContext());
+ returnValue = resourceTranslatedId.orElseGet(() -> functionTranslator.getUnsupportedResourcePrefix()
+ + functionTranslator.getFunctionValue());
+ return returnValue;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslator.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslator.java
new file mode 100644
index 0000000000..768f531938
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslator.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation;
+
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.datatypes.model.Template;
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+
+public class FunctionTranslator {
+
+ private static final String UNSUPPORTED_RESOURCE_PREFIX = "UNSUPPORTED_RESOURCE_";
+ private static final String UNSUPPORTED_ATTRIBUTE_PREFIX = "UNSUPPORTED_ATTRIBUTE_";
+
+ private ServiceTemplate serviceTemplate;
+ private String resourceId;
+ private String propertyName;
+ private Object functionValue;
+ private String heatFileName;
+ private HeatOrchestrationTemplate heatOrchestrationTemplate;
+ private Template toscaTemplate;
+ private TranslationContext context;
+
+ public FunctionTranslator() {
+ //default constructor
+ }
+
+ public FunctionTranslator(TranslateTo functionTranslateTo, String propertyName, Object functionValue,
+ Template toscaTemplate) {
+ this.serviceTemplate = functionTranslateTo.getServiceTemplate();
+ this.resourceId = functionTranslateTo.getResourceId();
+ this.propertyName = propertyName;
+ this.functionValue = functionValue;
+ this.heatFileName = functionTranslateTo.getHeatFileName();
+ this.heatOrchestrationTemplate = functionTranslateTo.getHeatOrchestrationTemplate();
+ this.toscaTemplate = toscaTemplate;
+ this.context = functionTranslateTo.getContext();
+ }
+
+ public static TranslateTo getFunctionTranslateTo(ServiceTemplate serviceTemplate, String resourceId,
+ String heatFileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context) {
+ return new TranslateTo(heatFileName, serviceTemplate, heatOrchestrationTemplate, null, resourceId, null,
+ context);
+ }
+
+ public ServiceTemplate getServiceTemplate() {
+ return serviceTemplate;
+ }
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ Object getFunctionValue() {
+ return functionValue;
+ }
+
+ void setFunctionValue(Object functionValue) {
+ this.functionValue = functionValue;
+ }
+
+ public String getHeatFileName() {
+ return heatFileName;
+ }
+
+ public HeatOrchestrationTemplate getHeatOrchestrationTemplate() {
+ return heatOrchestrationTemplate;
+ }
+
+ Template getToscaTemplate() {
+ return toscaTemplate;
+ }
+
+ public TranslationContext getContext() {
+ return context;
+ }
+
+ String getUnsupportedResourcePrefix() {
+ return UNSUPPORTED_RESOURCE_PREFIX;
+ }
+
+ String getUnsupportedAttributePrefix() {
+ return UNSUPPORTED_ATTRIBUTE_PREFIX;
+ }
+
+ public boolean isResourceSupported(String translatedResourceId) {
+ return !translatedResourceId.startsWith(UNSUPPORTED_RESOURCE_PREFIX);
+ }
+
+ boolean isAttributeSupported(String translatedAttName) {
+ return !translatedAttName.startsWith(UNSUPPORTED_ATTRIBUTE_PREFIX);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaParameterConverter.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaParameterConverter.java
index da6677ac16..eb95ea9c0b 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaParameterConverter.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaParameterConverter.java
@@ -16,6 +16,8 @@
package org.openecomp.sdc.translator.services.heattotosca.mapping;
+import static org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator.getFunctionTranslateTo;
+
import org.apache.commons.collections4.MapUtils;
import org.onap.sdc.tosca.datatypes.model.Constraint;
import org.onap.sdc.tosca.datatypes.model.EntrySchema;
@@ -33,6 +35,7 @@ import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslationFactory;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator;
import java.util.*;
@@ -252,10 +255,11 @@ public class TranslatorHeatToToscaParameterConverter {
Map.Entry<String, Object> functionMapEntry =
(Map.Entry<String, Object>) ((Map) paramValue).entrySet().iterator().next();
if (FunctionTranslationFactory.getInstance(functionMapEntry.getKey()).isPresent()) {
+
+ FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(serviceTemplate, null,
+ heatFileName, heatOrchestrationTemplate, context), parameterName, functionMapEntry.getValue(), null);
return FunctionTranslationFactory.getInstance(functionMapEntry.getKey()).get()
- .translateFunction(serviceTemplate, null, parameterName, functionMapEntry.getKey(),
- functionMapEntry.getValue(),heatFileName,
- heatOrchestrationTemplate, null, context);
+ .translateFunction(functionTranslator);
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaPropertyConverter.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaPropertyConverter.java
index 654e630957..3643a26977 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaPropertyConverter.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaPropertyConverter.java
@@ -20,6 +20,8 @@
package org.openecomp.sdc.translator.services.heattotosca.mapping;
+import static org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator.getFunctionTranslateTo;
+
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.onap.sdc.tosca.datatypes.model.Template;
@@ -27,6 +29,7 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants;
import org.openecomp.sdc.translator.services.heattotosca.Constants;
import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslationFactory;
+import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator;
import java.util.ArrayList;
import java.util.HashMap;
@@ -129,10 +132,11 @@ public class TranslatorHeatToToscaPropertyConverter {
Map.Entry<String, Object> functionMapEntry =
(Map.Entry<String, Object>) ((Map) propertyValue).entrySet().iterator().next();
if (FunctionTranslationFactory.getInstance(functionMapEntry.getKey()).isPresent()) {
+ FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(serviceTemplate,
+ resourceId, heatFileName, heatOrchestrationTemplate, context), propertyName,
+ functionMapEntry.getValue(), template);
return FunctionTranslationFactory.getInstance(functionMapEntry.getKey()).get()
- .translateFunction(serviceTemplate, resourceId, propertyName ,functionMapEntry
- .getKey(), functionMapEntry
- .getValue(), heatFileName, heatOrchestrationTemplate, template, context);
+ .translateFunction(functionTranslator);
}
Map<String, Object> propertyValueMap = new HashMap<>();
for (Map.Entry<String, Object> entry : ((Map<String, Object>) propertyValue).entrySet()) {
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImplTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImplTest.java
index 878183b239..a7bcf04e4b 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImplTest.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImplTest.java
@@ -1,12 +1,28 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation;
+import java.io.IOException;
+
import org.junit.Before;
import org.junit.Test;
import org.openecomp.sdc.translator.services.heattotosca.buildconsolidationdata.TestConstants;
import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.BaseResourceTranslationTest;
-import java.io.IOException;
-
public class FunctionTranslationGetAttrImplTest extends BaseResourceTranslationTest {
@Override
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetFileImplTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetFileImplTest.java
index 023c0f5937..76f0c61eb0 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetFileImplTest.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetFileImplTest.java
@@ -1,43 +1,37 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation;
+import static org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator.getFunctionTranslateTo;
+
+import java.util.HashMap;
+import java.util.List;
+
import org.junit.Assert;
import org.junit.Test;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.tosca.services.ToscaFileOutputService;
import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslationFactory;
-import java.util.HashMap;
-import java.util.List;
-
-/**
- * @author SHIRIA
- * @since December 18, 2016.
- */
public class FunctionTranslationGetFileImplTest {
@Test
public void testGetFileWithExtensionFunction() {
@@ -71,18 +65,18 @@ public class FunctionTranslationGetFileImplTest {
HeatOrchestrationTemplate heatOrchestrationTemplate,
NodeTemplate nodeTemplate,
TranslationContext context) {
- Assert.assertEquals(true, FunctionTranslationFactory.getInstance(functionName).isPresent());
+ Assert.assertTrue(FunctionTranslationFactory.getInstance(functionName).isPresent());
if(FunctionTranslationFactory.getInstance(functionName).isPresent()) {
+ FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(null, null, heatFileName,
+ heatOrchestrationTemplate, context), null, function, nodeTemplate);
Object result = FunctionTranslationFactory.getInstance(functionName).get()
- .translateFunction(null, null, null, functionName, function, heatFileName,
- heatOrchestrationTemplate,
- nodeTemplate, context);
+ .translateFunction(functionTranslator);
Assert.assertNotNull(((HashMap) result).get("get_artifact"));
List artifactParameters = (List) ((HashMap) result).get("get_artifact");
Assert.assertNotNull(artifactParameters);
- Assert.assertEquals(artifactParameters.size(), 2);
- Assert.assertEquals(artifactParameters.get(0), ToscaConstants.MODELABLE_ENTITY_NAME_SELF);
- Assert.assertEquals(artifactParameters.get(1), ((String) function).split("\\.")[0]);
+ Assert.assertEquals(2, artifactParameters.size());
+ Assert.assertEquals(ToscaConstants.MODELABLE_ENTITY_NAME_SELF, artifactParameters.get(0));
+ Assert.assertEquals(((String) function).split("\\.")[0], artifactParameters.get(1));
Assert.assertNotNull(nodeTemplate.getArtifacts());
Assert.assertNotNull(
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetParamImplTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetParamImplTest.java
index 860074ba70..d29e4af4e8 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetParamImplTest.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetParamImplTest.java
@@ -1,28 +1,25 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation;
-import org.junit.Before;
-import org.junit.Test;
-import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.BaseResourceTranslationTest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator.getFunctionTranslateTo;
import java.io.IOException;
import java.util.ArrayList;
@@ -30,8 +27,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.BaseResourceTranslationTest;
public class FunctionTranslationGetParamImplTest extends BaseResourceTranslationTest {
@@ -42,150 +40,136 @@ public class FunctionTranslationGetParamImplTest extends BaseResourceTranslation
}
@Test
- public void testStringGetParamFuncValue() throws Exception {
+ public void testStringGetParamFuncValue() {
FunctionTranslationGetParamImpl translationImpl = new FunctionTranslationGetParamImpl();
String functionValue = "parameter1";
- Object translatedFunc = translationImpl.translateFunction(null, null, null, "get_param",
- functionValue, "dummy", null, null, null);
+ FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(null, null, "dummy", null,
+ null), null, functionValue, null);
+ Object translatedFunc = translationImpl.translateFunction(functionTranslator);
- assertEquals(true, translatedFunc instanceof Map);
- if (translatedFunc instanceof Map) {
- assertNotNull(((Map) translatedFunc).get("get_input"));
- assertEquals(functionValue, ((Map) translatedFunc).get("get_input"));
- }
+ assertTrue(translatedFunc instanceof Map);
+ assertNotNull(((Map) translatedFunc).get("get_input"));
+ assertEquals(functionValue, ((Map) translatedFunc).get("get_input"));
}
@Test
- public void testListGetParamFuncValue() throws Exception {
+ public void testListGetParamFuncValue() {
FunctionTranslationGetParamImpl translationImpl = new FunctionTranslationGetParamImpl();
- List functionValue = new ArrayList();
+ List<Object> functionValue = new ArrayList<>();
functionValue.add("parameter1");
functionValue.add(0);
functionValue.add("key1");
- Object translatedFunc = translationImpl.translateFunction(null, null, null,"get_param",
- functionValue, "dummy", null, null, null);
+ FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(null, null, "dummy", null,
+ null), null, functionValue, null);
+ Object translatedFunc = translationImpl.translateFunction(functionTranslator);
- assertEquals(true, translatedFunc instanceof Map);
- if (translatedFunc instanceof Map) {
- assertNotNull(((Map) translatedFunc).get("get_input"));
- Object translatedFunValue = ((Map) translatedFunc).get("get_input");
- assertEquals(true, translatedFunValue instanceof List);
- if (translatedFunValue instanceof List) {
+ assertTrue(translatedFunc instanceof Map);
+ assertNotNull(((Map) translatedFunc).get("get_input"));
+ Object translatedFunValue = ((Map) translatedFunc).get("get_input");
+ assertTrue(translatedFunValue instanceof List);
- assertEquals(functionValue.get(0), ((List) translatedFunValue).get(0));
- assertEquals(functionValue.get(1), ((List) translatedFunValue).get(1));
- assertEquals(functionValue.get(2), ((List) translatedFunValue).get(2));
- }
- }
+ assertEquals(functionValue.get(0), ((List) translatedFunValue).get(0));
+ assertEquals(functionValue.get(1), ((List) translatedFunValue).get(1));
+ assertEquals(functionValue.get(2), ((List) translatedFunValue).get(2));
}
@Test
- public void testMapGetParamFuncValue() throws Exception {
+ public void testMapGetParamFuncValue() {
// input heat function expression
//{get_param: [parameter1, {get_param:indexParam}, key1]}
// output translated function expression
//{get_input: [parameter1, {get_input:indexParam}, key1]}
FunctionTranslationGetParamImpl translationImpl = new FunctionTranslationGetParamImpl();
- List functionValue = new ArrayList();
+ List<Object> functionValue = new ArrayList<>();
functionValue.add("parameter1");
- Map innerParamMap = new HashMap();
+ Map<String, String> innerParamMap = new HashMap<>();
innerParamMap.put("get_param", "indexParam");
functionValue.add(innerParamMap);
functionValue.add("key1");
- Object translatedFunc = translationImpl.translateFunction(null, null, null, "get_param",
- functionValue, "dummy", null, null, null);
-
- assertEquals(true, translatedFunc instanceof Map);
- if (translatedFunc instanceof Map) {
- assertNotNull(((Map) translatedFunc).get("get_input"));
- Object translatedFunValue = ((Map) translatedFunc).get("get_input");
- assertEquals(true, translatedFunValue instanceof List);
- if (translatedFunValue instanceof List) {
- assertEquals(functionValue.get(0), ((List) translatedFunValue).get(0));
- assertEquals(functionValue.get(2), ((List) translatedFunValue).get(2));
- assertEquals(true, ((List) translatedFunValue).get(1) instanceof Map);
- if (((List) translatedFunValue).get(1) instanceof Map) {
- assertEquals(innerParamMap.get("get_param"), ((Map) ((List) translatedFunValue).get(1))
+ FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(null, null, "dummy", null,
+ null), null, functionValue, null);
+ Object translatedFunc = translationImpl.translateFunction(functionTranslator);
+
+ assertTrue(translatedFunc instanceof Map);
+ assertNotNull(((Map) translatedFunc).get("get_input"));
+ Object translatedFunValue = ((Map) translatedFunc).get("get_input");
+ assertTrue(translatedFunValue instanceof List);
+ assertEquals(functionValue.get(0), ((List) translatedFunValue).get(0));
+ assertEquals(functionValue.get(2), ((List) translatedFunValue).get(2));
+ assertTrue(((List) translatedFunValue).get(1) instanceof Map);
+ if (((List) translatedFunValue).get(1) instanceof Map) {
+ assertEquals(innerParamMap.get("get_param"), ((Map) ((List) translatedFunValue).get(1))
.get("get_input"));
- }
- }
-
}
+
}
@Test
- public void testMapWithMapGetParamFuncValue() throws Exception {
+ public void testMapWithMapGetParamFuncValue() {
// input heat function expression
//{get_param: [parameter1, {get_param:[parameter2, {get_param:indexParam}]}, key1]}
// output translated function expression
//{get_input: [parameter1, {get_input:[parameter2, {get_input:indexParam}]}, key1]}
FunctionTranslationGetParamImpl translationImpl = new FunctionTranslationGetParamImpl();
- List functionValue = new ArrayList();
+ List<Object> functionValue = new ArrayList<>();
functionValue.add("parameter1");
- Map firstInnerParamMap = new HashMap();
- Map secondInnerParamMap = new HashMap();
+ Map<String, Object> firstInnerParamMap = new HashMap<>();
+ Map<String, String> secondInnerParamMap = new HashMap<>();
secondInnerParamMap.put("get_param", "indexParam");
- List innerfunction = new ArrayList();
+ List<Object> innerfunction = new ArrayList<>();
innerfunction.add("parameter2");
innerfunction.add(secondInnerParamMap);
firstInnerParamMap.put("get_param", innerfunction);
functionValue.add(firstInnerParamMap);
functionValue.add("key1");
- Object translatedFunc = translationImpl.translateFunction(null, null, null, "get_param",
- functionValue, "dummy", null, null, null);
-
- assertEquals(true, translatedFunc instanceof Map);
- if (translatedFunc instanceof Map) {
- assertNotNull(((Map) translatedFunc).get("get_input"));
- Object translatedFunValue = ((Map) translatedFunc).get("get_input");
- assertEquals(true, translatedFunValue instanceof List);
- if (translatedFunValue instanceof List) {
- assertEquals(functionValue.get(0), ((List) translatedFunValue).get(0));
- assertEquals(functionValue.get(2), ((List) translatedFunValue).get(2));
- assertEquals(true, ((List) translatedFunValue).get(1) instanceof Map);
- if (((List) translatedFunValue).get(1) instanceof Map) {
- assertEquals(true, ((Map) ((List) translatedFunValue).get(1)).get("get_input")
- instanceof List);
- List innerTranslatedFunction =
- (List) ((Map) ((List) translatedFunValue).get(1)).get("get_input");
- assertEquals(innerfunction.get(0), innerTranslatedFunction.get(0));
- assertEquals(true, innerTranslatedFunction.get(1) instanceof Map);
- assertEquals(secondInnerParamMap.get("get_param"),
- ((Map) innerTranslatedFunction.get(1)).get("get_input"));
- }
- }
-
+ FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(null, null, "dummy", null,
+ null), null, functionValue, null);
+ Object translatedFunc = translationImpl.translateFunction(functionTranslator);
+
+ assertTrue(translatedFunc instanceof Map);
+ assertNotNull(((Map) translatedFunc).get("get_input"));
+ Object translatedFunValue = ((Map) translatedFunc).get("get_input");
+ assertTrue(translatedFunValue instanceof List);
+ assertEquals(functionValue.get(0), ((List) translatedFunValue).get(0));
+ assertEquals(functionValue.get(2), ((List) translatedFunValue).get(2));
+ assertTrue(((List) translatedFunValue).get(1) instanceof Map);
+ if (((List) translatedFunValue).get(1) instanceof Map) {
+ assertTrue(((Map) ((List) translatedFunValue).get(1)).get("get_input") instanceof List);
+ List innerTranslatedFunction = (List) ((Map) ((List) translatedFunValue).get(1)).get("get_input");
+ assertEquals(innerfunction.get(0), innerTranslatedFunction.get(0));
+ assertTrue(innerTranslatedFunction.get(1) instanceof Map);
+ assertEquals(secondInnerParamMap.get("get_param"), ((Map) innerTranslatedFunction.get(1)).get("get_input"));
}
}
@Test
- public void testInnerNotSupportedFuncGetParamFuncValue() throws Exception {
+ public void testInnerNotSupportedFuncGetParamFuncValue() {
// input heat function expression
//{get_param: [parameter1, {str_replace: {template:$AAkgiru, AA:{get_param:prameter2}}}, key1]}
// output translated function expression
//{get_input: [parameter1, {str_replace: {template:$AAkgiru, AA:{get_input:parameter2}}}, key1]}
FunctionTranslationGetParamImpl translationImpl = new FunctionTranslationGetParamImpl();
- List functionValue = new ArrayList();
+ List<Object> functionValue = new ArrayList<>();
functionValue.add("parameter1");
- Map templateMap = new HashMap();
+ Map<String, Object> templateMap = new HashMap<>();
templateMap.put("template", "$AAkgiru");
- Map strReplaceFuncMap = new HashMap();
- Map getParamMapInner = new HashMap();
+ Map<String, Object> strReplaceFuncMap = new HashMap<>();
+ Map<String, Object> getParamMapInner = new HashMap<>();
getParamMapInner.put("get_param", "parameter2");
templateMap.put("AA", getParamMapInner);
- Map innerParamValue = new HashMap();
+ Map<String, Object> innerParamValue = new HashMap<>();
innerParamValue.putAll(templateMap);
innerParamValue.putAll(strReplaceFuncMap);
@@ -194,34 +178,31 @@ public class FunctionTranslationGetParamImplTest extends BaseResourceTranslation
functionValue.add("key1");
- Object translatedFunc = translationImpl.translateFunction(null, null, null, "get_param",
- functionValue, "dummy", null, null, null);
-
- assertEquals(true, translatedFunc instanceof Map);
- if (translatedFunc instanceof Map) {
- assertNotNull(((Map) translatedFunc).get("get_input"));
- Object translatedFunValue = ((Map) translatedFunc).get("get_input");
- assertEquals(true, translatedFunValue instanceof List);
- if (translatedFunValue instanceof List) {
- assertEquals(functionValue.get(0), ((List) translatedFunValue).get(0));
- assertEquals(functionValue.get(2), ((List) translatedFunValue).get(2));
- assertEquals(true, ((List) translatedFunValue).get(1) instanceof Map);
- if (((List) translatedFunValue).get(1) instanceof Map) {
- assertEquals(strReplaceFuncMap.get("get_param"),
+ FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(null, null, "dummy", null,
+ null), null, functionValue, null);
+ Object translatedFunc = translationImpl.translateFunction(functionTranslator);
+
+ assertTrue(translatedFunc instanceof Map);
+ assertNotNull(((Map) translatedFunc).get("get_input"));
+ Object translatedFunValue = ((Map) translatedFunc).get("get_input");
+ assertTrue(translatedFunValue instanceof List);
+ assertEquals(functionValue.get(0), ((List) translatedFunValue).get(0));
+ assertEquals(functionValue.get(2), ((List) translatedFunValue).get(2));
+ assertTrue(((List) translatedFunValue).get(1) instanceof Map);
+ if (((List) translatedFunValue).get(1) instanceof Map) {
+ assertEquals(strReplaceFuncMap.get("get_param"),
((Map) ((List) translatedFunValue).get(1))
- .get("get_input"));
- }
- assertEquals(true, ((List) translatedFunValue).get(1) instanceof Map);
- if (((List) translatedFunValue).get(1) instanceof Map) {
- assertEquals(true, ((Map) ((List) translatedFunValue).get(1)).get("str_replace") instanceof Map);
- Map strReplacefunctionValue = (Map) ((Map) ((List) translatedFunValue).get(1)).get("str_replace");
- assertEquals(templateMap.get("template"), strReplacefunctionValue.get("template"));
- assertEquals(true, strReplacefunctionValue.get("AA") instanceof Map);
- if (strReplacefunctionValue.get("AA") instanceof Map) {
- assertEquals(getParamMapInner.get("get_param"), ((Map) strReplacefunctionValue.get
+ .get("get_input"));
+ }
+ assertTrue(((List) translatedFunValue).get(1) instanceof Map);
+ if (((List) translatedFunValue).get(1) instanceof Map) {
+ assertTrue(((Map) ((List) translatedFunValue).get(1)).get("str_replace") instanceof Map);
+ Map strReplacefunctionValue = (Map) ((Map) ((List) translatedFunValue).get(1)).get("str_replace");
+ assertEquals(templateMap.get("template"), strReplacefunctionValue.get("template"));
+ assertTrue(strReplacefunctionValue.get("AA") instanceof Map);
+ if (strReplacefunctionValue.get("AA") instanceof Map) {
+ assertEquals(getParamMapInner.get("get_param"), ((Map) strReplacefunctionValue.get
("AA")).get("get_input"));
- }
- }
}
}
}
@@ -229,9 +210,9 @@ public class FunctionTranslationGetParamImplTest extends BaseResourceTranslation
@Test
public void testTranslateHeatPseudoParamUsedFromMainHeat() throws Exception {
inputFilesPath =
- "/mock/services/heattotosca/heatPseudoParameters/usedFromMainHeat/inputfiles";
+ "/mock/services/heattotosca/heatPseudoParameters/usedFromMainHeat/inputfiles";
outputFilesPath =
- "/mock/services/heattotosca/heatPseudoParameters/usedFromMainHeat/expectedoutputfiles";
+ "/mock/services/heattotosca/heatPseudoParameters/usedFromMainHeat/expectedoutputfiles";
initTranslatorAndTranslate();
testTranslation();
}
@@ -239,9 +220,9 @@ public class FunctionTranslationGetParamImplTest extends BaseResourceTranslation
@Test
public void testTranslateHeatPseudoParamUsedFromNestedHeat() throws Exception {
inputFilesPath =
- "/mock/services/heattotosca/heatPseudoParameters/usedFromNestedHeat/inputfiles";
+ "/mock/services/heattotosca/heatPseudoParameters/usedFromNestedHeat/inputfiles";
outputFilesPath =
- "/mock/services/heattotosca/heatPseudoParameters/usedFromNestedHeat/expectedoutputfiles";
+ "/mock/services/heattotosca/heatPseudoParameters/usedFromNestedHeat/expectedoutputfiles";
initTranslatorAndTranslate();
testTranslation();
}