2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright (c) 2017-2019 European Software Marketing Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.aai.babel.parser;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Optional;
27 import java.util.function.Predicate;
28 import java.util.stream.Stream;
29 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
30 import org.onap.sdc.tosca.parser.enums.SdcTypes;
31 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
32 import org.onap.sdc.toscaparser.api.Group;
33 import org.onap.sdc.toscaparser.api.NodeTemplate;
36 * Helper class to isolate the deprecated tosca parser API methods.
39 public class ToscaParser {
41 private ToscaParser() {
42 // Not to be instantiated in this version
45 @SuppressWarnings("deprecation")
46 public static Stream<NodeTemplate> getServiceNodeTemplates(ISdcCsarHelper csarHelper) {
47 return csarHelper.getServiceNodeTemplates().stream(); // NOSONAR
50 @SuppressWarnings("deprecation")
51 public static List<Group> getServiceLevelGroups(ISdcCsarHelper csarHelper) {
52 return Optional.ofNullable(csarHelper.getGroupsOfTopologyTemplate()).orElse(new ArrayList<>()); // NOSONAR
56 * Create a Predicate that will return true if and only if the supplied NodeTemplate's metadata contains a
57 * <code>type</code> value matching the specified SDC Type.
60 * the type metadata value to match against
61 * @return a Predicate for matching the NodeTemplate to the SDC Type
63 public static Predicate<NodeTemplate> filterOnType(SdcTypes sdcType) {
64 return nodeTemplate -> (nodeTemplate.getMetaData() != null
65 && sdcType.getValue().equals(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)));