summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandler.java79
-rw-r--r--src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandlerTest.java13
2 files changed, 64 insertions, 28 deletions
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 7f2a5d6..7dbe913 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
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2020 Nokia.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +25,7 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;
@@ -45,7 +47,9 @@ import org.slf4j.LoggerFactory;
public class MeasFilterHandler {
private static final ONAPLogAdapter logger = new ONAPLogAdapter(LoggerFactory.getLogger(MeasFilterHandler.class));
public static final String XML_EXTENSION = "xml";
- private MeasConverter converter;
+ private static final String GENERIC_PM_TYPE_WITH_SPECIFIC_DATA_EXTENSION_REGEX = "PM\\d{12}[+-]\\d{4,}([A-D]).*\\.xml";
+ private static final String LEGACY_PM_TYPE_REGEX = "([A-D]).*\\.xml";
+ private final MeasConverter converter;
public MeasFilterHandler(MeasConverter converter) {
this.converter = converter;
@@ -96,7 +100,7 @@ public class MeasFilterHandler {
getFilteredMeasInfoFromMeasType(currentMeasInfo, filterPatternList).ifPresent(filteredMeasInfos::add);
}
}
- return filteredMeasInfos;
+ return filteredMeasInfos;
}
private List<Pattern> getPatternsFromFilters(Optional<Filter> filters) {
@@ -106,6 +110,7 @@ public class MeasFilterHandler {
}
return patternList;
}
+
private Optional<Pattern> tryToCompileFilter(String measType) {
try {
return Optional.of(Pattern.compile("^" + measType + "$"));
@@ -135,43 +140,71 @@ public class MeasFilterHandler {
**/
public boolean filterByFileType(Event event) {
logger.unwrap().debug("Filtering the measurement by file type.");
- String requestPath = event.getHttpServerExchange().getRequestPath();
- String fileName = requestPath.substring(requestPath.lastIndexOf('/')+1);
+ String requestPath = event.getHttpServerExchange().getRequestPath();
+ String fileName = requestPath.substring(requestPath.lastIndexOf('/') + 1);
boolean isXML = isXMLFile(fileName);
boolean isValidPMType = isValidPMType(fileName);
- if(!isXML) {
- logger.unwrap().info("PM measurement file must have an extension of .{}", XML_EXTENSION);
+ if (!isXML) {
+ logger.unwrap().warn("PM measurement file must have an extension of .{}", XML_EXTENSION);
}
- if(!isValidPMType) {
- logger.unwrap().info("PM measurement file type not supported");
+ if (!isValidPMType) {
+ logger.unwrap().warn("PM measurement file type not supported");
}
-
- return isXML && isValidPMType;
+ return isXML && isValidPMType;
}
private boolean isValidPMType(String fileName) {
- return fileName.startsWith("C") || fileName.startsWith("A");
+ String pmType;
+ if(fileName.startsWith("PM")){
+ pmType = getPMTypeConventionWithSpec28532(fileName);
+ }else {
+ pmType = getPMTypeConventionWithSpec32434(fileName);
+ }
+ return isSupportedPMType(pmType);
+ }
+
+ private String getPMTypeConventionWithSpec28532(String fileName) {
+ Pattern convention28532 = Pattern.compile(GENERIC_PM_TYPE_WITH_SPECIFIC_DATA_EXTENSION_REGEX);
+ return getPMType(fileName, convention28532);
+ }
+
+ private String getPMTypeConventionWithSpec32434(String fileName) {
+ Pattern convention32434 = Pattern.compile(LEGACY_PM_TYPE_REGEX);
+ return getPMType(fileName, convention32434);
+ }
+
+ private String getPMType(String fileName, Pattern pattern) {
+ String pmType = "";
+ Matcher matcher = pattern.matcher(fileName);
+ if(matcher.find()){
+ pmType = matcher.group(1);
+ }
+ return pmType;
+ }
+
+ private boolean isSupportedPMType(String pmType) {
+ return pmType.equals("A") || pmType.equals("C");
}
private boolean isXMLFile(String fileName) {
return FilenameUtils.getExtension(fileName).equals(XML_EXTENSION);
}
- private boolean hasMatchingResults(List<MeasurementInfo.MeasType> filteredMeasTypes, MeasValue measValue ) {
+ private boolean hasMatchingResults(List<MeasurementInfo.MeasType> filteredMeasTypes, MeasValue measValue) {
List<MeasValue.R> filteredResults = new ArrayList<>();
- filteredMeasTypes.forEach( mst ->
- measValue.getR().stream()
- .filter(r -> mst.getP().equals(r.getP()))
- .findFirst()
- .ifPresent(filteredResults::add)
+ 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);
+ boolean hasResults = !filteredResults.isEmpty();
+ if (hasResults) {
+ measValue.replaceR(filteredResults);
}
- return hasResults;
+ return hasResults;
}
private Optional<MeasurementInfo> getFilteredMeasInfoFromMeasType(MeasurementInfo currentMeasInfo, List<Pattern> filters) {
@@ -179,9 +212,9 @@ public class MeasFilterHandler {
.filter(mt -> matchFilters(filters, mt.getValue()))
.collect(Collectors.toList());
- if(!filteredMeasTypes.isEmpty()) {
+ if (!filteredMeasTypes.isEmpty()) {
List<MeasValue> filteredMeasValues = currentMeasInfo.getMeasValue().stream()
- .filter( mv -> hasMatchingResults(filteredMeasTypes, mv))
+ .filter(mv -> hasMatchingResults(filteredMeasTypes, mv))
.collect(Collectors.toList());
currentMeasInfo.replaceMeasType(filteredMeasTypes);
currentMeasInfo.replaceMeasValue(filteredMeasValues);
diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandlerTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandlerTest.java
index b4fce87..5283cda 100644
--- a/src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandlerTest.java
+++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandlerTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2020 Nokia.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -143,17 +144,20 @@ class MeasFilterHandlerTest {
@Test
void valid_fileType() {
+ List<String> validFileTypes = Arrays.asList("Apm.xml", "Cpm.xml", "PM202007171301+020024C202007171207+0200-1215+0200_45678.xml", "PM202007171301-0100999A202007171207+0200-1215+0200_45678.xml");
Event event = mock(Event.class);
when(event.getHttpServerExchange()).thenReturn(exchange);
- when(exchange.getRequestPath()).thenReturn("Apm.xml","Cpm.xml");
- assertTrue(objUnderTest.filterByFileType(event));
- assertTrue(objUnderTest.filterByFileType(event));
+ validFileTypes.forEach(fileName -> {
+ when(exchange.getRequestPath())
+ .thenReturn(fileName);
+ assertTrue(objUnderTest.filterByFileType(event));
+ } );
}
@Test
void invalid_fileType() {
+ List<String> invalidFileTypes = Arrays.asList("Bpm.xml","Dpm.xml","Apm.xml.gz","Apm.xm1","asdf","bsdf", "B202007171207+0200-1215+0200_45678.xml", "PM202007171301+020024B202007171207+0200-1215+0200_45678.xml", "PMC202007171301+020024C202007171207+0200-1215+0200_45678.xml" , "PM202007171301-020024.xml");
Event event = mock(Event.class);
- List<String> invalidFileTypes = Arrays.asList("Bpm.xml","Dpm.xml","Apm.xml.gz","Apm.xm1","asdf","bsdf");
when(event.getHttpServerExchange()).thenReturn(exchange);
invalidFileTypes.forEach(fileName -> {
when(exchange.getRequestPath())
@@ -212,5 +216,4 @@ class MeasFilterHandlerTest {
return EventUtils.generateEventArguments(FILTER_DIRECTORY, creator);
}
-
}