summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
authormarcinrzepeckiwroc <marcin.rzepecki@nokia.com>2020-07-24 16:46:06 +0200
committermarcinrzepeckiwroc <marcin.rzepecki@nokia.com>2020-07-30 09:54:32 +0200
commit0e12fb1d1d96d3711ec45d8bcc176a49ecf20921 (patch)
treeccbbdf238a93da0d8bf1822ca03966e817a78b24 /src/main/java/org/onap
parentf6e7430b34f65b72e57685d370f1938e45bcbc11 (diff)
Support 28.532 file naming convention
Issue-ID: DCAEGEN2-2351 Signed-off-by: marcinrzepeckiwroc <marcin.rzepecki@nokia.com> Change-Id: I5a281b352832ed05f656b5da39ec4df25fdb67c5
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r--src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandler.java79
1 files changed, 56 insertions, 23 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);