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.AttachedPropertyVal;
24 import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId;
25 import org.openecomp.sdc.translator.datatypes.heattotosca.PropertyRegexMatcher;
27 import java.util.List;
29 import java.util.Objects;
30 import java.util.Optional;
31 import java.util.regex.Pattern;
33 public class NameExtractorUtil {
36 * Extract Node Type Name By Properties Priority.
37 * @param properties properties list
38 * @param propertiesRegexMatchers Regex expression list
39 * @return node type name
41 public static Optional<String> extractNodeTypeNameByPropertiesPriority(
42 Map<String, Object> properties,
43 List<PropertyRegexMatcher> propertiesRegexMatchers) {
45 for (PropertyRegexMatcher propertyRegexMatcher : propertiesRegexMatchers) {
46 Optional<String> parameterNameValue =
47 HeatToToscaUtil.getPropertyParameterNameValue(
48 properties.get(propertyRegexMatcher.getPropertyName()));
49 if (parameterNameValue.isPresent()) {
50 if (isPropertyValueMatchNamingConvention(propertyRegexMatcher, parameterNameValue.get())) {
51 return Optional.of(parameterNameValue.get().substring(0, parameterNameValue.get()
52 .lastIndexOf(propertyRegexMatcher.getStringToSearchForPropertyValue())));
56 return Optional.empty();
60 * Check if property value match the naming convention using Regex expression.
61 * @param propertyRegexMatcher naming convention using Regex expression
62 * @param propertyValue property value
63 * @return true is there is a match, false otherwise
65 public static boolean isPropertyValueMatchNamingConvention(PropertyRegexMatcher
67 String propertyValue) {
68 for (Pattern pattern : propertyRegexMatcher.getRegexPatterns()) {
69 if (pattern.matcher(propertyValue).matches()) {