diff options
author | emartin <ephraim.martin@est.tech> | 2019-04-02 11:40:04 +0000 |
---|---|---|
committer | emartin <ephraim.martin@est.tech> | 2019-04-02 11:40:04 +0000 |
commit | 39bec8163a57b4c026fc78feb12797a0d3bbdc15 (patch) | |
tree | ca1e7c08369ea3dfd5d09aed4a1a0675d919cbb6 | |
parent | 36605ed860a6eb7fca09156c6e8ae6ebf5259ea3 (diff) |
Handle non-xml PM files
*Non-xml files will not be mapped to VES
Change-Id: Ice1b901576be4da0593f38eb2c0b4e4676b6019e
Issue-ID: DCAEGEN2-1327
Signed-off-by: emartin <ephraim.martin@est.tech>
3 files changed, 27 insertions, 2 deletions
@@ -47,6 +47,7 @@ <undertow.version>2.0.16.Final</undertow.version> <gson.version>2.8.5</gson.version> <freemarker.version>2.3.28</freemarker.version> + <commons.io.version>2.6</commons.io.version> <!-- Testing.Test Dependencies --> <junit.version>5.3.2</junit.version> <mockito.version>2.23.4</mockito.version> @@ -128,6 +129,11 @@ <version>${freemarker.version}</version> </dependency> <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>${commons.io.version}</version> + </dependency> + <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>${junit.version}</version> 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) { 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 436984e..694b4e9 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 @@ -194,7 +194,7 @@ class MeasFilterHandlerTest { @Test void invalid_fileType() { Event event = mock(Event.class); - List<String> invalidFiletypes = Arrays.asList("Bpm.xml","Dpm.xml","asdf","bsdf"); + List<String> invalidFiletypes = Arrays.asList("Bpm.xml","Dpm.xml","Apm.xml.gz","Apm.xm1","asdf","bsdf"); when(event.getHttpServerExchange()).thenReturn(exchange); when(exchange.getRequestPath()) .thenReturn(invalidFiletypes.toString()); |