From 2eff2870374b37be96b29e5a3d8f9c021f038a10 Mon Sep 17 00:00:00 2001 From: Alexey Sandler Date: Thu, 19 Dec 2019 11:05:40 +0200 Subject: Add resources summarizing function in service instance. Issue-ID: VID-724 Signed-off-by: Alexey Sandler Change-Id: I9f4d6201cadd31e84ef90f25a619d95bf74eb9ae Signed-off-by: Alexey Sandler --- .../AsyncInstantiationBusinessLogicImpl.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'vid-app-common/src/main/java/org/onap') 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 c77eb8230..d1b475cb4 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,6 +20,9 @@ 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.groupingBy; 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; @@ -30,11 +33,16 @@ 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.UUID; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.stream.Collectors; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.hibernate.SessionFactory; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; @@ -178,6 +186,28 @@ public class AsyncInstantiationBusinessLogicImpl implements return uuids; } + public Map getSummarizedChildrenMap(ServiceInstantiation serviceInstantiation){ + List existingTypesList = new ArrayList<>(); + Map existingTypesCounters; + + existingTypesList = getChildrenList(serviceInstantiation, existingTypesList); + existingTypesCounters = existingTypesList.stream().collect(groupingBy(identity(), counting())); + + return existingTypesCounters; + } + + private List getChildrenList(BaseResource resource, List list){ + Collection children = resource.getChildren(); + if (CollectionUtils.isNotEmpty(children)){ + children.forEach( child -> { + String childType = child.getModelInfo().getModelType(); + getChildrenList(child, list); + list.add(childType); + }); + } + return list; + } + private ServiceInfo.ServiceAction getAction(ServiceInstantiation request) { if (request.getAction() == null) { //throw new GenericUncheckedException("Required 'action' field not provided at service level"); -- cgit 1.2.3-korg