aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java21
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/model/ModelUtil.java53
2 files changed, 30 insertions, 44 deletions
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 48736bc01..111a260e1 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
@@ -20,14 +20,12 @@
package org.onap.vid.aai.util;
-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 javax.inject.Inject;
import org.apache.commons.lang3.StringUtils;
+import org.onap.vid.model.ModelUtil;
import org.onap.vid.model.aaiTree.AAITreeNode;
import org.onap.vid.model.aaiTree.CollectionResource;
import org.onap.vid.model.aaiTree.Network;
@@ -56,6 +54,13 @@ public class AAITreeConverter {
public static final String SERVICE_INSTANCE_SERVICE_INSTANCE_ID = "service-instance.service-instance-id";
public static final String TENANT_TENANT_NAME = "tenant.tenant-name";
+ private final ModelUtil modelUtil;
+
+ @Inject
+ public AAITreeConverter(ModelUtil modelUtil) {
+ this.modelUtil = modelUtil;
+ }
+
public ServiceInstance convertTreeToUIModel(AAITreeNode rootNode, String globalCustomerId, String serviceType, String instantiationType, String instanceRole, String instanceType) {
ServiceInstance serviceInstance = new ServiceInstance();
serviceInstance.setInstanceId(rootNode.getId());
@@ -107,13 +112,7 @@ public class AAITreeConverter {
}
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()));
+ return modelUtil.getExistingCounterMap(nodeList, Node::getModelInfo);
}
private static ModelInfo createModelInfo(AAITreeNode aaiNode) {
diff --git a/vid-app-common/src/main/java/org/onap/vid/model/ModelUtil.java b/vid-app-common/src/main/java/org/onap/vid/model/ModelUtil.java
index 45e100fb1..6c56a464b 100644
--- a/vid-app-common/src/main/java/org/onap/vid/model/ModelUtil.java
+++ b/vid-app-common/src/main/java/org/onap/vid/model/ModelUtil.java
@@ -20,39 +20,26 @@
package org.onap.vid.model;
+import static java.util.function.Function.identity;
+import static java.util.stream.Collectors.counting;
+import static java.util.stream.Collectors.groupingBy;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.vid.mso.model.ModelInfo;
+import org.springframework.stereotype.Component;
+
+@Component
public class ModelUtil {
- /**
- * Gets the tags for the given element according to the configured namespace
- * @param namespaces the namespace list from the configuration
- * @param constantValue the constant portion of the tag name, i.e. resource.vf...
- * @return the tags
- */
- public static String[] getTags ( String[] namespaces, String constantValue ) {
- String[] tags;
- if ( namespaces == null || namespaces.length == 0 ) {
- return null;
- }
- int le = namespaces.length;
- tags = new String[le];
- for ( int i = 0; i < le; i++ ) {
- tags[i] = namespaces[i] + constantValue;
- }
- return (tags);
- }
- /**
- * Determine if a note template type matches a set of configurable tags
- * @param type the node template type
- * @param tags the model configurable namespaces
- * @return true if type starts with a tag in the array, false otherwise
- */
- public static boolean isType ( String type, String[] tags ) {
- if ( (tags != null) && (tags.length > 0) ) {
- for ( int i = 0; i < tags.length; i++ ) {
- if ( type.startsWith (tags[i]) ) {
- return (true);
- }
- }
- }
- return (false);
+ public <T> Map<String, Long> getExistingCounterMap(Map<String, T> nodeList, Function<T, ModelInfo> modelInfoExtractor) {
+ return nodeList.values().stream()
+ .map(it -> {
+ ModelInfo modelInfo = modelInfoExtractor.apply(it);
+ return StringUtils.defaultIfEmpty(modelInfo.getModelCustomizationId(), modelInfo.getModelVersionId());
+ })
+ .filter(Objects::nonNull)
+ .collect(groupingBy(identity(), counting()));
}
}