aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/aai
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/aai')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java44
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java29
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/KeyValueModel.java42
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelatedToProperty.java59
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Relationship.java8
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipData.java32
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVersions.kt3
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java95
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeNodeUtils.java49
9 files changed, 261 insertions, 100 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
index 4ef6fbd24..015ede893 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
@@ -21,11 +21,13 @@
package org.onap.vid.aai;
import static java.util.Collections.emptyList;
+import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toMap;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
import static org.apache.commons.lang3.StringUtils.isEmpty;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
@@ -37,6 +39,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Function;
+import java.util.stream.Stream;
import javax.inject.Inject;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
@@ -49,6 +52,7 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.aai.exceptions.InvalidAAIResponseException;
+import org.onap.vid.aai.model.*;
import org.onap.vid.aai.model.AaiGetAicZone.AicZones;
import org.onap.vid.aai.model.AaiGetInstanceGroupsByCloudRegion;
import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.AaiGetNetworkCollectionDetails;
@@ -117,6 +121,7 @@ public class AaiClient implements AaiClientInterface {
private static final String GET_SERVICE_MODELS_RESPONSE_BODY = "{\"start\" : \"service-design-and-creation/models/\", \"query\" : \"query/serviceModels-byDistributionStatus?distributionStatus=DISTRIBUTION_COMPLETE_OK\"}";
+
@Inject
public AaiClient(AAIRestInterface restController, PortDetailsTranslator portDetailsTranslator, CacheProvider cacheProvider) {
this.restController = restController;
@@ -425,8 +430,8 @@ public class AaiClient implements AaiClientInterface {
}
@Override
- public AaiResponse getSubscriberData(String subscriberId) {
- String depth = "2";
+ public AaiResponse getSubscriberData(String subscriberId, boolean omitServiceInstances) {
+ String depth = omitServiceInstances ? "1" : "2";
AaiResponse subscriberDataResponse;
Response resp = doAaiGet(BUSINESS_CUSTOMERS_CUSTOMER + subscriberId + "?depth=" + depth, false);
subscriberDataResponse = processAaiResponse(resp, Services.class, null);
@@ -434,6 +439,41 @@ public class AaiClient implements AaiClientInterface {
}
@Override
+ public ModelVer getLatestVersionByInvariantId(String modelInvariantId) {
+ if (modelInvariantId.isEmpty()) {
+ throw new GenericUncheckedException("no invariant-id provided to getLatestVersionByInvariantId; request is rejected");
+ }
+
+ // add the modelInvariantId to the payload
+ StringBuilder payload = new StringBuilder(GET_SERVICE_MODELS_RESPONSE_BODY);
+ payload.insert(50, modelInvariantId);
+
+ Response response = doAaiPut("service-design-and-creation/models/model/", payload.toString(),false);
+ AaiResponse<ModelVersions> aaiResponse = processAaiResponse(response, ModelVersions.class, null, VidObjectMapperType.FASTERXML);
+ Stream<ModelVer> modelVerStream = toModelVerStream(aaiResponse.getT());
+ return maxModelVer(modelVerStream);
+
+ }
+
+ protected Stream<ModelVer> toModelVerStream(ModelVersions modelVersions) {
+
+ return Stream.of(modelVersions)
+ .map(ModelVersions::getResults)
+ .flatMap(java.util.Collection::stream)
+ .flatMap(map -> map.entrySet().stream())
+ .filter(kv -> StringUtils.equals(kv.getKey(), "model-ver"))
+ .map(Map.Entry::getValue);
+
+ }
+
+ protected ModelVer maxModelVer(Stream<ModelVer> modelVerStream) {
+ return modelVerStream
+ .filter(modelVer -> StringUtils.isNotEmpty(modelVer.getModelVersion()))
+ .max(comparing(ModelVer::getModelVersion, comparing(DefaultArtifactVersion::new)))
+ .orElseThrow(() -> new GenericUncheckedException("Could not find any version"));
+ }
+
+ @Override
public AaiResponse getServices() {
Response resp = doAaiGet("service-design-and-creation/services", false);
return processAaiResponse(resp, GetServicesAAIRespone.class, null);
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java
index 5f69b8769..1061ae5f5 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,30 +21,37 @@
package org.onap.vid.aai;
import com.fasterxml.jackson.databind.JsonNode;
-import java.net.URI;
-import java.util.List;
-import java.util.Map;
-import javax.ws.rs.core.Response;
import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList;
import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
+import org.onap.vid.aai.model.ModelVer;
import org.onap.vid.aai.model.PortDetailsTranslator;
import org.onap.vid.aai.model.Properties;
import org.onap.vid.aai.model.ResourceType;
-import org.onap.vid.services.ProbeInterface;
import org.onap.vid.model.SubscriberList;
+import org.onap.vid.model.probes.ExternalComponentStatus;
+import org.onap.vid.services.ProbeInterface;
+import org.springframework.http.HttpMethod;
+
+import javax.ws.rs.core.Response;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
/**
* Created by Oren on 7/4/17.
*/
-public interface AaiClientInterface extends ProbeInterface {
+public interface AaiClientInterface extends ProbeInterface {
boolean isNodeTypeExistsByName(String name, ResourceType type);
<T> T typedAaiGet(URI path, Class<T> clz);
+ <T> T typedAaiRest(URI path, Class<T> clz, String payload, HttpMethod method, boolean propagateExceptions);
+
AaiResponse<SubscriberList> getAllSubscribers();
- AaiResponse getSubscriberData(String subscriberId);
+ AaiResponse getSubscriberData(String subscriberId, boolean omitServiceInstances);
AaiResponse getServices();
@@ -68,10 +75,12 @@ public interface AaiClientInterface extends ProbeInterface {
Response getVersionByInvariantId(List<String> modelInvariantId);
+ ModelVer getLatestVersionByInvariantId(String modelInvariantId);
+
AaiResponse getServicesByProjectNames(List<String> projectNames);
AaiResponse getServiceModelsByDistributionStatus();
-
+
AaiResponse getPNFData(String globalCustomerId, String serviceType, String modelVersionId, String modelInvariantId, String cloudRegion, String equipVendor, String equipModel);
AaiResponse<Pnf> getSpecificPnf(String pnfId);
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/KeyValueModel.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/KeyValueModel.java
new file mode 100644
index 000000000..6e0e1c06a
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/KeyValueModel.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+public abstract class KeyValueModel {
+ private String key;
+ private String value;
+
+ public String getKey() {
+ return key;
+ }
+ public String getValue() {
+ return value;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelatedToProperty.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelatedToProperty.java
index d53d90fd4..7c5287770 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelatedToProperty.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelatedToProperty.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,33 +25,30 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
-public class RelatedToProperty {
-
- public String getPropertyKey() {
- return propertyKey;
- }
-
-
- public void setPropertyKey(String propertyKey) {
- this.propertyKey = propertyKey;
- }
-
-
- public String getPropertyValue() {
- return propertyValue;
- }
-
-
- public void setPropertyValue(String propertyValue) {
- this.propertyValue = propertyValue;
- }
-
-
- @JsonProperty("property-key")
- public String propertyKey;
-
-
- @JsonProperty("property-value")
- public String propertyValue;
-
+public class RelatedToProperty extends KeyValueModel {
+
+ @Override
+ @JsonProperty("property-key")
+ public String getKey() {
+ return super.getKey();
+ }
+
+ @Override
+ @JsonProperty("property-key")
+ public void setKey(String propertyKey) {
+ super.setKey(propertyKey);
+ }
+
+ @Override
+ @JsonProperty("property-value")
+ public String getValue() {
+ return super.getValue();
+ }
+
+ @Override
+ @JsonProperty("property-value")
+ public void setValue(String propertyValue) {
+ super.setValue(propertyValue);
+ }
}
+
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Relationship.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Relationship.java
index 4de11500e..110e922c1 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Relationship.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Relationship.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -31,13 +31,13 @@ public class Relationship {
@JsonProperty("related-to")
public String relatedTo;
-
+
@JsonProperty("related-link")
public String relatedLink;
@JsonProperty("relationship-label")
public String relationshipLabel;
-
+
@JsonProperty("relationship-data")
public List<RelationshipData> relationshipData;
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipData.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipData.java
index cba7f43cb..f480ef8d0 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipData.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipData.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,26 +24,26 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
-public class RelationshipData {
+public class RelationshipData extends KeyValueModel {
+
+ @Override
@JsonProperty("relationship-key")
- public String getRelationshipKey() {
- return relationshipKey;
+ public String getKey() {
+ return super.getKey();
}
+ @Override
@JsonProperty("relationship-key")
- public void setRelationshipKey(String relationshipKey) {
- this.relationshipKey = relationshipKey;
+ public void setKey(String relationshipKey) {
+ super.setKey(relationshipKey);
}
+ @Override
@JsonProperty("relationship-value")
- public String getRelationshipValue() {
- return relationshipValue;
+ public String getValue() {
+ return super.getValue();
}
+ @Override
@JsonProperty("relationship-value")
- public void setRelationshipValue(String relationshipValue) {
- this.relationshipValue = relationshipValue;
+ public void setValue(String relationshipValue) {
+ super.setValue(relationshipValue);
}
-
- public String relationshipKey;
-
- public String relationshipValue;
-
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVersions.kt b/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVersions.kt
new file mode 100644
index 000000000..c4aa45d55
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVersions.kt
@@ -0,0 +1,3 @@
+package org.onap.vid.aai.model
+
+data class ModelVersions(val results: List<Map<String, ModelVer>>)
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java
index 5be26a0ec..48736bc01 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,36 +20,43 @@
package org.onap.vid.aai.util;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.vid.model.aaiTree.*;
-import org.onap.vid.mso.model.ModelInfo;
-import org.onap.vid.services.AAITreeNodeBuilder;
-import org.springframework.stereotype.Component;
-
-import java.util.Objects;
-
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;
import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.A_LA_CARTE;
+import java.util.Map;
+import java.util.Objects;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.vid.model.aaiTree.AAITreeNode;
+import org.onap.vid.model.aaiTree.CollectionResource;
+import org.onap.vid.model.aaiTree.Network;
+import org.onap.vid.model.aaiTree.Node;
+import org.onap.vid.model.aaiTree.NodeType;
+import org.onap.vid.model.aaiTree.ServiceInstance;
+import org.onap.vid.model.aaiTree.Vnf;
+import org.onap.vid.model.aaiTree.VnfGroup;
+import org.onap.vid.model.aaiTree.Vrf;
+import org.onap.vid.mso.model.ModelInfo;
+import org.springframework.stereotype.Component;
+
@Component
public class AAITreeConverter {
public static final String VNF_TYPE = "vnf-type";
public static final String NETWORK_TYPE = "network-type";
+ public static final String NETWORK_ROLE = "network-role";
+ public static final String PHYSICAL_NETWORK_NAME = "physical-network-name";
+ public static final String SERVICE_INSTANCE = "service-instance";
+ public static final String TENANT = "tenant";
+ public static final String VPN_BINDING = "vpn-binding";
public static final String IS_BASE_VF_MODULE = "is-base-vf-module";
+ public static final String SERVICE_INSTANCE_SERVICE_INSTANCE_NAME = "service-instance.service-instance-name";
+ public static final String SERVICE_INSTANCE_SERVICE_INSTANCE_ID = "service-instance.service-instance-id";
+ public static final String TENANT_TENANT_NAME = "tenant.tenant-name";
- public enum ModelType {
- service,
- vnf,
- network,
- instanceGroup,
- vfModule
- }
-
- public ServiceInstance convertTreeToUIModel(AAITreeNode rootNode, String globalCustomerId, String serviceType, String instantiationType) {
+ public ServiceInstance convertTreeToUIModel(AAITreeNode rootNode, String globalCustomerId, String serviceType, String instantiationType, String instanceRole, String instanceType) {
ServiceInstance serviceInstance = new ServiceInstance();
serviceInstance.setInstanceId(rootNode.getId());
serviceInstance.setInstanceName(rootNode.getName());
@@ -58,46 +65,60 @@ public class AAITreeConverter {
serviceInstance.setSubscriptionServiceType(serviceType);
serviceInstance.setIsALaCarte(StringUtils.equals(instantiationType, A_LA_CARTE));
- serviceInstance.setModelInfo(createModelInfo(rootNode, ModelType.service));
+ serviceInstance.setModelInfo(createModelInfo(rootNode));
//set children: vnf, network,group
rootNode.getChildren().forEach(child -> {
- if (child.getType().equals(AAITreeNodeBuilder.GENERIC_VNF)) {
+ if (child.getType() == NodeType.GENERIC_VNF) {
serviceInstance.getVnfs().put(child.getUniqueNodeKey(), Vnf.from(child));
- } else if (child.getType().equals(AAITreeNodeBuilder.NETWORK)) {
+ } else if (child.getType() == NodeType.NETWORK) {
serviceInstance.getNetworks().put(child.getUniqueNodeKey(), Network.from(child));
- } else if (child.getType().equals(AAITreeNodeBuilder.INSTANCE_GROUP)) {
- serviceInstance.getVnfGroups().put(child.getUniqueNodeKey(), VnfGroup.from(child));
+ } else if (child.getType() == NodeType.INSTANCE_GROUP) {
+ serviceInstance.getVnfGroups().put(child.getUniqueNodeKey(), new VnfGroup(child));
+ } else if (child.getType() == NodeType.COLLECTION_RESOURCE) {
+ serviceInstance.getCollectionResources().put(child.getUniqueNodeKey(), new CollectionResource(child));
+ } else if (isChildVrf(instanceType, instanceRole, child)){
+ serviceInstance.getVrfs().put(child.getUniqueNodeKey(), Vrf.from(child));
}
});
serviceInstance.setExistingVNFCounterMap(
- serviceInstance.getVnfs().entrySet().stream()
- .map(k -> k.getValue().getModelInfo().getModelVersionId())
- .collect(groupingBy(identity(), counting()))
+ getExistingCounterMap(serviceInstance.getVnfs())
);
serviceInstance.setExistingNetworksCounterMap(
- serviceInstance.getNetworks().entrySet().stream()
- .map(k -> k.getValue().getModelInfo().getModelVersionId())
- .filter(Objects::nonNull)
- .collect(groupingBy(identity(), counting()))
+ getExistingCounterMap(serviceInstance.getNetworks())
);
serviceInstance.setExistingVnfGroupCounterMap(
- serviceInstance.getVnfGroups().entrySet().stream()
- .map(k -> k.getValue().getModelInfo().getModelVersionId())
- .filter(Objects::nonNull)
- .collect(groupingBy(identity(), counting()))
+ getExistingCounterMap(serviceInstance.getVnfGroups())
+ );
+
+ serviceInstance.setExistingVRFCounterMap(
+ getExistingCounterMap(serviceInstance.getVrfs())
);
return serviceInstance;
}
- private static ModelInfo createModelInfo(AAITreeNode aaiNode, ModelType modelType) {
+ protected boolean isChildVrf(String instanceType, String serviceRole, AAITreeNode child) {
+ return child.getType() == NodeType.CONFIGURATION && StringUtils.equalsIgnoreCase(instanceType, "BONDING") && StringUtils.equalsIgnoreCase(serviceRole, "INFRASTRUCTURE-VPN");
+ }
+
+ private <T extends Node> Map<String, Long> getExistingCounterMap(Map<String, T> nodeList) {
+ return nodeList.entrySet().stream()
+ .map(k -> {
+ ModelInfo modelInfo = k.getValue().getModelInfo();
+ return StringUtils.defaultIfEmpty(modelInfo.getModelCustomizationId(), modelInfo.getModelVersionId());
+ })
+ .filter(Objects::nonNull)
+ .collect(groupingBy(identity(), counting()));
+ }
+
+ private static ModelInfo createModelInfo(AAITreeNode aaiNode) {
ModelInfo modelInfo = new ModelInfo();
- modelInfo.setModelType(modelType.name());
+ modelInfo.setModelType(aaiNode.getType().getModelType());
modelInfo.setModelName(aaiNode.getModelName());
modelInfo.setModelVersion(aaiNode.getModelVersion());
modelInfo.setModelVersionId(aaiNode.getModelVersionId());
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeNodeUtils.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeNodeUtils.java
new file mode 100644
index 000000000..7ff6f280f
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeNodeUtils.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.vid.aai.util;
+
+import java.util.List;
+import java.util.Optional;
+import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.KeyValueModel;
+import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship;
+import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelationshipList;
+
+public class AAITreeNodeUtils {
+
+ private AAITreeNodeUtils() {
+ }
+
+ public static Optional<Relationship> findFirstRelationshipByRelatedTo(RelationshipList relationshipList, String relatedTo) {
+ if (relationshipList==null || relationshipList.getRelationship()==null) {
+ return Optional.empty();
+ }
+ return relationshipList.getRelationship().stream().filter(x->relatedTo.equals(x.getRelatedTo())).findFirst();
+ }
+
+ public static <T extends KeyValueModel> Optional<String> findFirstValue(List<T> data, String key) {
+ if (data==null || data.isEmpty()) {
+ return Optional.empty();
+ }
+ Optional<T> optValue = data.stream().filter(x->key.equals(x.getKey())).findFirst();
+ return optValue.map(KeyValueModel::getValue);
+ }
+
+}