aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-12-19 15:17:36 +0200
committerIttay Stern <ittay.stern@att.com>2019-12-19 15:44:38 +0200
commitfecb7b8df6d8f589fd879b41731e7495cf657c92 (patch)
tree80c495ef9241b7e0d24a2f5563e2cccd9bb35b84
parentfee16feed4b65692e44153c5e4453721785a285b (diff)
Tweak add resources summarizing function in service instance
Issue-ID: VID-724 Change-Id: I7e705aef5e94698c60bd4ea17991b5beb6f0dc54 Signed-off-by: Alexey Sandler <alexey.sandler@intl.att.com> Signed-off-by: Ittay Stern <ittay.stern@att.com>
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java40
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java7
2 files changed, 23 insertions, 24 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
index d1b475cb4..c0ee7ea4f 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
@@ -20,9 +20,10 @@
package org.onap.vid.services;
-import static java.util.stream.Collectors.counting;
import static java.util.function.Function.identity;
+import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;
+import static java.util.stream.Stream.concat;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
@@ -33,16 +34,13 @@ import java.io.IOException;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Calendar;
-import java.util.Collection;
import java.util.Date;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.UUID;
import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import org.apache.commons.collections.CollectionUtils;
+import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.SessionFactory;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
@@ -69,6 +67,7 @@ import org.onap.vid.mso.MsoBusinessLogicImpl;
import org.onap.vid.mso.MsoProperties;
import org.onap.vid.mso.MsoUtil;
import org.onap.vid.mso.RestObject;
+import org.onap.vid.mso.model.ModelInfo;
import org.onap.vid.mso.rest.AsyncRequestStatus;
import org.onap.vid.mso.rest.RequestStatus;
import org.onap.vid.properties.Features;
@@ -186,26 +185,25 @@ public class AsyncInstantiationBusinessLogicImpl implements
return uuids;
}
- public Map<String, Long> getSummarizedChildrenMap(ServiceInstantiation serviceInstantiation){
- List<String> existingTypesList = new ArrayList<>();
- Map<String, Long> existingTypesCounters;
+ public Map<String, Long> getSummarizedChildrenMap(ServiceInstantiation serviceInstantiation){
+ Stream<String> existingTypesStream =
+ allDeepChildResources(serviceInstantiation)
+ .map(BaseResource::getModelInfo)
+ .filter(Objects::nonNull)
+ .map(ModelInfo::getModelType);
- existingTypesList = getChildrenList(serviceInstantiation, existingTypesList);
- existingTypesCounters = existingTypesList.stream().collect(groupingBy(identity(), counting()));
+ Map<String, Long> existingTypesCounters =
+ existingTypesStream.collect(groupingBy(identity(), counting()));
return existingTypesCounters;
}
- private List<String> getChildrenList(BaseResource resource, List<String> list){
- Collection<? extends BaseResource> children = resource.getChildren();
- if (CollectionUtils.isNotEmpty(children)){
- children.forEach( child -> {
- String childType = child.getModelInfo().getModelType();
- getChildrenList(child, list);
- list.add(childType);
- });
- }
- return list;
+ private Stream<BaseResource> allDeepChildResources(BaseResource resource) {
+ return resource
+ .getChildren()
+ .stream()
+ .map(it -> concat(Stream.of(it), allDeepChildResources(it)))
+ .flatMap(identity());
}
private ServiceInfo.ServiceAction getAction(ServiceInstantiation request) {
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
index 4b4aa4deb..29d614cb2 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
@@ -496,9 +496,10 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
ServiceInstantiation serviceInstantiation = TestUtils.readJsonResourceFileAsObject(
"/payload_jsons/templateSummarize4vnfs6vfmodules.json", ServiceInstantiation.class);
Map<String, Long> childrenMap = asyncInstantiationBL.getSummarizedChildrenMap(serviceInstantiation);
- HashMap<String, Long> expectedMap = new HashMap<>();
- expectedMap.put("vnf", Long.valueOf(4));
- expectedMap.put("vfModule", Long.valueOf(6));
+ Map<String, Long> expectedMap = ImmutableMap.of(
+ "vnf", 4L,
+ "vfModule", 6L
+ );
assertEquals(childrenMap,expectedMap);
}