diff options
author | Henrik Andersson <henrik.b.andersson@est.tech> | 2019-04-02 12:21:47 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-02 12:21:47 +0000 |
commit | 7be6327ec6df91622c0a5feaa07e39fae8efb018 (patch) | |
tree | f50957ca335b250b13fe11e8302658547a5ff7bc /src/main | |
parent | 03e519407ccc47e51efbbfb26cca339f90cbff1b (diff) | |
parent | 39bec8163a57b4c026fc78feb12797a0d3bbdc15 (diff) |
Merge "Handle non-xml PM files"
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/onap/dcaegen2/services/pmmapper/filtering/MeasFilterHandler.java | 21 |
1 files changed, 20 insertions, 1 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 7aec457..6896d3c 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 @@ -28,6 +28,7 @@ import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; +import org.apache.commons.io.FilenameUtils; import org.onap.dcaegen2.services.pmmapper.model.Event; import org.onap.dcaegen2.services.pmmapper.model.MeasCollecFile; import org.onap.dcaegen2.services.pmmapper.model.MeasCollecFile.MeasData; @@ -45,6 +46,7 @@ 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; public MeasFilterHandler(MeasConverter converter) { @@ -129,7 +131,24 @@ public class MeasFilterHandler { logger.unwrap().debug("Filtering the measurement by file type."); String requestPath = event.getHttpServerExchange().getRequestPath(); String fileName = requestPath.substring(requestPath.lastIndexOf('/')+1); - return (fileName.startsWith("C") || fileName.startsWith("A")); + boolean isXML = isXMLFile(fileName); + boolean isValidPMType = isValidPMType(fileName); + if(!isXML) { + logger.unwrap().info("PM measurement file must have an extension of .{}", XML_EXTENSION); + } + if(!isValidPMType) { + logger.unwrap().info("PM measurement file type not supported"); + } + + return isXML && isValidPMType; + } + + private boolean isValidPMType(String fileName) { + return fileName.startsWith("C") || fileName.startsWith("A"); + } + + private boolean isXMLFile(String fileName) { + return FilenameUtils.getExtension(fileName).equals(XML_EXTENSION); } private void setMeasInfoFromMeasType(MeasInfo currentMeasInfo, List<MeasInfo> filteredMeasInfos, Filter filter) { |