2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.translator.services.heattotosca;
23 import org.openecomp.sdc.translator.datatypes.heattotosca.PropertyRegexMatcher;
25 import java.util.List;
27 import java.util.Optional;
28 import java.util.regex.Pattern;
30 public class NameExtractorUtil {
33 * Extract Node Type Name By Properties Priority.
34 * @param properties properties list
35 * @param propertiesRegexMatchers Regex expression list
36 * @return node type name
38 public static Optional<String> extractNodeTypeNameByPropertiesPriority(
39 Map<String, Object> properties,
40 List<PropertyRegexMatcher> propertiesRegexMatchers) {
42 for (PropertyRegexMatcher propertyRegexMatcher : propertiesRegexMatchers) {
43 Optional<String> parameterNameValue =
44 HeatToToscaUtil.getPropertyParameterNameValue(
45 properties.get(propertyRegexMatcher.getPropertyName()));
46 if (parameterNameValue.isPresent()) {
47 if (isPropertyValueMatchNamingConvention(propertyRegexMatcher, parameterNameValue.get())) {
48 return Optional.of(parameterNameValue.get().substring(0, parameterNameValue.get()
49 .lastIndexOf(propertyRegexMatcher.getStringToSearchForPropertyValue())));
53 return Optional.empty();
57 * Check if property value match the naming convention using Regex expression.
58 * @param propertyRegexMatcher naming convention using Regex expression
59 * @param propertyValue property value
60 * @return true is there is a match, false otherwise
62 public static boolean isPropertyValueMatchNamingConvention(PropertyRegexMatcher
64 String propertyValue) {
65 for (Pattern pattern : propertyRegexMatcher.getRegexPatterns()) {
66 if (pattern.matcher(propertyValue).matches()) {