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=========================================================
20 package org.openecomp.sdc.translator.services.heattotosca;
22 import java.util.List;
24 import java.util.Optional;
25 import java.util.regex.Pattern;
26 import org.openecomp.sdc.translator.datatypes.heattotosca.PropertyRegexMatcher;
28 public class NameExtractorUtil {
31 * Extract Node Type Name By Properties Priority.
33 * @param properties properties list
34 * @param propertiesRegexMatchers Regex expression list
35 * @return node type name
37 public static Optional<String> extractNodeTypeNameByPropertiesPriority(Map<String, Object> properties,
38 List<PropertyRegexMatcher> propertiesRegexMatchers) {
39 for (PropertyRegexMatcher propertyRegexMatcher : propertiesRegexMatchers) {
40 Optional<String> parameterNameValue = HeatToToscaUtil
41 .getPropertyParameterNameValue(properties.get(propertyRegexMatcher.getPropertyName()));
42 if (parameterNameValue.isPresent()) {
43 if (isPropertyValueMatchNamingConvention(propertyRegexMatcher, parameterNameValue.get())) {
44 return Optional.of(parameterNameValue.get()
45 .substring(0, parameterNameValue.get().lastIndexOf(propertyRegexMatcher.getStringToSearchForPropertyValue())));
49 return Optional.empty();
53 * Check if property value match the naming convention using Regex expression.
55 * @param propertyRegexMatcher naming convention using Regex expression
56 * @param propertyValue property value
57 * @return true is there is a match, false otherwise
59 public static boolean isPropertyValueMatchNamingConvention(PropertyRegexMatcher propertyRegexMatcher, String propertyValue) {
60 for (Pattern pattern : propertyRegexMatcher.getRegexPatterns()) {
61 if (pattern.matcher(propertyValue).matches()) {