From ccdc2ae3ddbaf63164ddd9ae4af2274944cb2c4c Mon Sep 17 00:00:00 2001 From: emartin Date: Fri, 5 Apr 2019 16:43:46 +0000 Subject: Fix issue with filtering multiple measValue Change-Id: I8f81510445edf276561645bdd4549a8c18207b57 Issue-ID: DCAEGEN2-1327 Signed-off-by: emartin --- .../pmmapper/filtering/MeasFilterHandler.java | 47 +++++++++++++--------- .../services/pmmapper/model/MeasCollecFile.java | 4 ++ 2 files changed, 32 insertions(+), 19 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandler.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandler.java index 6896d3c..2dc4ae9 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandler.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandler.java @@ -22,6 +22,8 @@ package org.onap.dcaegen2.services.pmmapper.filtering; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -151,29 +153,36 @@ public class MeasFilterHandler { return FilenameUtils.getExtension(fileName).equals(XML_EXTENSION); } - private void setMeasInfoFromMeasType(MeasInfo currentMeasInfo, List filteredMeasInfos, Filter filter) { - MeasValue currentMeasValue = currentMeasInfo.getMeasValue() - .get(0); - List measResultsRNodes = currentMeasValue.getR(); - Map mappedR = measResultsRNodes.stream() - .collect(Collectors.toMap(R::getP, Function.identity())); - List filteredRs = new ArrayList<>(); - List filteredMeasTypes = currentMeasInfo.getMeasType() - .stream().filter(mt -> { - List measTypeFilters = filter.getMeasTypes(); - if (measTypeFilters.contains(mt.getValue())) { - filteredRs.add(mappedR.get(mt.getP())); - return true; - } - return false; - }) + private boolean hasMatchingResults(List filteredMeasTypes, MeasValue measValue ) { + List filteredResults = new ArrayList<>(); + + filteredMeasTypes.forEach( mst -> + measValue.getR().stream() + .filter(r -> mst.getP().equals(r.getP())) + .findFirst() + .ifPresent(filteredResults::add) + ); + + boolean hasResults = !filteredResults.isEmpty(); + if(hasResults) { + measValue.replaceR(filteredResults); + } + return hasResults; + } + + private void setMeasInfoFromMeasType(MeasInfo currentMeasInfo, List filteredMeasInfos, Filter filter) { + List filteredMeasTypes = currentMeasInfo.getMeasType().stream() + .filter(mt -> filter.getMeasTypes().contains(mt.getValue())) .collect(Collectors.toList()); - if (!filteredMeasTypes.isEmpty()) { + + if(!filteredMeasTypes.isEmpty()) { + List filteredMeasValues = currentMeasInfo.getMeasValue().stream() + .filter( mv -> hasMatchingResults(filteredMeasTypes, mv)) + .collect(Collectors.toList()); currentMeasInfo.replaceMeasType(filteredMeasTypes); - currentMeasValue.replaceR(filteredRs); + currentMeasInfo.replaceMeasValue(filteredMeasValues); filteredMeasInfos.add(currentMeasInfo); } - } private void setMeasInfosFromMeasTypes(MeasInfo currentMeasInfo, List filteredMeasInfos, Filter filter) { diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MeasCollecFile.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MeasCollecFile.java index 613fe63..6e9e254 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MeasCollecFile.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MeasCollecFile.java @@ -1832,6 +1832,10 @@ public class MeasCollecFile { this.measType = filteredMeasTypes; } + public void replaceMeasValue(List filteredMeasValues) { + this.measValue = filteredMeasValues; + } + } -- cgit 1.2.3-korg