768f531938e3310db3118a355698504f4077fd02
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation;
18
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;
24
25 public class FunctionTranslator {
26
27     private static final String UNSUPPORTED_RESOURCE_PREFIX = "UNSUPPORTED_RESOURCE_";
28     private static final String UNSUPPORTED_ATTRIBUTE_PREFIX = "UNSUPPORTED_ATTRIBUTE_";
29
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;
38
39     public FunctionTranslator() {
40         //default constructor
41     }
42
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();
53     }
54
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,
59                 context);
60     }
61
62     public ServiceTemplate getServiceTemplate() {
63         return serviceTemplate;
64     }
65
66     public String getResourceId() {
67         return resourceId;
68     }
69
70     public String getPropertyName() {
71         return propertyName;
72     }
73
74     Object getFunctionValue() {
75         return functionValue;
76     }
77
78     void setFunctionValue(Object functionValue) {
79         this.functionValue = functionValue;
80     }
81
82     public String getHeatFileName() {
83         return heatFileName;
84     }
85
86     public HeatOrchestrationTemplate getHeatOrchestrationTemplate() {
87         return heatOrchestrationTemplate;
88     }
89
90     Template getToscaTemplate() {
91         return toscaTemplate;
92     }
93
94     public TranslationContext getContext() {
95         return context;
96     }
97
98     String getUnsupportedResourcePrefix() {
99         return UNSUPPORTED_RESOURCE_PREFIX;
100     }
101
102     String getUnsupportedAttributePrefix() {
103         return UNSUPPORTED_ATTRIBUTE_PREFIX;
104     }
105
106     public boolean isResourceSupported(String translatedResourceId) {
107         return !translatedResourceId.startsWith(UNSUPPORTED_RESOURCE_PREFIX);
108     }
109
110     boolean isAttributeSupported(String translatedAttName) {
111         return !translatedAttName.startsWith(UNSUPPORTED_ATTRIBUTE_PREFIX);
112     }
113 }