From 9131e3944d1cf571b6a6d57f402a30d8468237a3 Mon Sep 17 00:00:00 2001 From: Einat Vinouze Date: Wed, 25 Sep 2019 16:06:48 +0300 Subject: sort base resource according it's position field Issue-ID: VID-646 Signed-off-by: Einat Vinouze Change-Id: I35705cd4a239e30bc6d86da7cde05495648d2a04 Signed-off-by: Einat Vinouze --- .../src/main/java/org/onap/vid/job/command/ResourceCommand.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt') diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt index ac5c2751c..df97f89f8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt @@ -427,14 +427,17 @@ abstract class ResourceCommand( protected fun pushChildrenJobsToBroker(children:Collection, dataForChild: Map, jobType: JobType?=null): List { - var counter = 0; - return children - .map {Pair(it, counter++)} + return setPositionWhereIsMissing(children) .map { jobAdapter.createChildJob(jobType ?: it.first.jobType, it.first, sharedData, dataForChild, it.second) } .map { jobsBrokerService.add(it) } .map { it.toString() } } + protected fun setPositionWhereIsMissing(children: Collection): List> { + var orderingPosition = children.map{ defaultIfNull(it.position, 0) }.max() ?: 0 + return children + .map {Pair(it, it.position ?: ++orderingPosition)} + } } -- cgit 1.2.3-korg