2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 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.onap.vid.aai.util;
23 import org.apache.commons.lang3.StringUtils;
24 import org.onap.vid.model.aaiTree.*;
25 import org.onap.vid.mso.model.ModelInfo;
26 import org.onap.vid.services.AAITreeNodeBuilder;
27 import org.springframework.stereotype.Component;
29 import java.util.Objects;
31 import static java.util.function.Function.identity;
32 import static java.util.stream.Collectors.counting;
33 import static java.util.stream.Collectors.groupingBy;
34 import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.A_LA_CARTE;
37 public class AAITreeConverter {
39 public static final String VNF_TYPE = "vnf-type";
40 public static final String NETWORK_TYPE = "network-type";
42 public static final String IS_BASE_VF_MODULE = "is-base-vf-module";
44 public enum ModelType {
52 public ServiceInstance convertTreeToUIModel(AAITreeNode rootNode, String globalCustomerId, String serviceType, String instantiationType) {
53 ServiceInstance serviceInstance = new ServiceInstance();
54 serviceInstance.setInstanceId(rootNode.getId());
55 serviceInstance.setInstanceName(rootNode.getName());
56 serviceInstance.setOrchStatus(rootNode.getOrchestrationStatus());
57 serviceInstance.setGlobalSubscriberId(globalCustomerId);
58 serviceInstance.setSubscriptionServiceType(serviceType);
59 serviceInstance.setIsALaCarte(StringUtils.equals(instantiationType, A_LA_CARTE));
61 serviceInstance.setModelInfo(createModelInfo(rootNode, ModelType.service));
63 //set children: vnf, network,group
64 rootNode.getChildren().forEach(child -> {
65 if (child.getType().equals(AAITreeNodeBuilder.GENERIC_VNF)) {
66 serviceInstance.getVnfs().put(child.getUniqueNodeKey(), Vnf.from(child));
67 } else if (child.getType().equals(AAITreeNodeBuilder.NETWORK)) {
68 serviceInstance.getNetworks().put(child.getUniqueNodeKey(), Network.from(child));
69 } else if (child.getType().equals(AAITreeNodeBuilder.INSTANCE_GROUP)) {
70 serviceInstance.getVnfGroups().put(child.getUniqueNodeKey(), VnfGroup.from(child));
74 serviceInstance.setExistingVNFCounterMap(
75 serviceInstance.getVnfs().entrySet().stream()
76 .map(k -> k.getValue().getModelInfo().getModelVersionId())
77 .collect(groupingBy(identity(), counting()))
80 serviceInstance.setExistingNetworksCounterMap(
81 serviceInstance.getNetworks().entrySet().stream()
82 .map(k -> k.getValue().getModelInfo().getModelVersionId())
83 .filter(Objects::nonNull)
84 .collect(groupingBy(identity(), counting()))
88 serviceInstance.setExistingVnfGroupCounterMap(
89 serviceInstance.getVnfGroups().entrySet().stream()
90 .map(k -> k.getValue().getModelInfo().getModelVersionId())
91 .filter(Objects::nonNull)
92 .collect(groupingBy(identity(), counting()))
95 return serviceInstance;
98 private static ModelInfo createModelInfo(AAITreeNode aaiNode, ModelType modelType) {
99 ModelInfo modelInfo = new ModelInfo();
100 modelInfo.setModelType(modelType.name());
101 modelInfo.setModelName(aaiNode.getModelName());
102 modelInfo.setModelVersion(aaiNode.getModelVersion());
103 modelInfo.setModelVersionId(aaiNode.getModelVersionId());
104 modelInfo.setModelInvariantId(aaiNode.getModelInvariantId());
105 modelInfo.setModelCustomizationId(aaiNode.getModelCustomizationId());