re base code
[sdc.git] / openecomp-be / lib / openecomp-sdc-translator-lib / openecomp-sdc-translator-core / src / main / java / org / openecomp / sdc / translator / services / heattotosca / impl / nameextractor / NameExtractorContrailComputeImpl.java
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.nameextractor;
18
19 import org.openecomp.sdc.heat.datatypes.model.Resource;
20 import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
21 import org.openecomp.sdc.translator.datatypes.heattotosca.PropertyRegexMatcher;
22 import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
23 import org.openecomp.sdc.translator.services.heattotosca.NameExtractorUtil;
24 import org.openecomp.sdc.translator.services.heattotosca.helper.ContrailTranslationHelper;
25
26 import java.util.List;
27 import java.util.Optional;
28
29 import static org.openecomp.sdc.tosca.services.ToscaConstants.HEAT_NODE_TYPE_SUFFIX;
30
31 public class NameExtractorContrailComputeImpl implements NameExtractor {
32
33     @Override
34     public String extractNodeTypeName(Resource resource, String resourceId, String translatedId) {
35         ContrailTranslationHelper contrailTranslationHelper = new ContrailTranslationHelper();
36         List<PropertyRegexMatcher> propertyRegexMatchers =
37                 contrailTranslationHelper.getPropertyRegexMatchersForComputeNodeType();
38         Optional<String> extractedNodeTypeName = NameExtractorUtil.extractNodeTypeNameByPropertiesPriority(resource
39                         .getProperties(), propertyRegexMatchers);
40
41         return ToscaNodeType.VFC_NODE_TYPE_PREFIX + HEAT_NODE_TYPE_SUFFIX
42                 + (extractedNodeTypeName.orElseGet(() -> "compute_" + translatedId));
43     }
44
45 }