2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation;
19 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
20 import org.onap.sdc.tosca.datatypes.model.Template;
21 import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
22 import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
23 import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
25 public class FunctionTranslator {
27 private static final String UNSUPPORTED_RESOURCE_PREFIX = "UNSUPPORTED_RESOURCE_";
28 private static final String UNSUPPORTED_ATTRIBUTE_PREFIX = "UNSUPPORTED_ATTRIBUTE_";
30 private ServiceTemplate serviceTemplate;
31 private String resourceId;
32 private String propertyName;
33 private Object functionValue;
34 private String heatFileName;
35 private HeatOrchestrationTemplate heatOrchestrationTemplate;
36 private Template toscaTemplate;
37 private TranslationContext context;
39 public FunctionTranslator() {
43 public FunctionTranslator(TranslateTo functionTranslateTo, String propertyName, Object functionValue,
44 Template toscaTemplate) {
45 this.serviceTemplate = functionTranslateTo.getServiceTemplate();
46 this.resourceId = functionTranslateTo.getResourceId();
47 this.propertyName = propertyName;
48 this.functionValue = functionValue;
49 this.heatFileName = functionTranslateTo.getHeatFileName();
50 this.heatOrchestrationTemplate = functionTranslateTo.getHeatOrchestrationTemplate();
51 this.toscaTemplate = toscaTemplate;
52 this.context = functionTranslateTo.getContext();
55 public static TranslateTo getFunctionTranslateTo(ServiceTemplate serviceTemplate, String resourceId,
56 String heatFileName, HeatOrchestrationTemplate heatOrchestrationTemplate,
57 TranslationContext context) {
58 return new TranslateTo(heatFileName, serviceTemplate, heatOrchestrationTemplate, null, resourceId, null,
62 public ServiceTemplate getServiceTemplate() {
63 return serviceTemplate;
66 public String getResourceId() {
70 public String getPropertyName() {
74 Object getFunctionValue() {
78 void setFunctionValue(Object functionValue) {
79 this.functionValue = functionValue;
82 public String getHeatFileName() {
86 public HeatOrchestrationTemplate getHeatOrchestrationTemplate() {
87 return heatOrchestrationTemplate;
90 Template getToscaTemplate() {
94 public TranslationContext getContext() {
98 String getUnsupportedResourcePrefix() {
99 return UNSUPPORTED_RESOURCE_PREFIX;
102 String getUnsupportedAttributePrefix() {
103 return UNSUPPORTED_ATTRIBUTE_PREFIX;
106 public boolean isResourceSupported(String translatedResourceId) {
107 return !translatedResourceId.startsWith(UNSUPPORTED_RESOURCE_PREFIX);
110 boolean isAttributeSupported(String translatedAttName) {
111 return !translatedAttName.startsWith(UNSUPPORTED_ATTRIBUTE_PREFIX);