diff options
author | Mateusz Gołuchowski <mateusz.goluchowski@nokia.com> | 2020-07-16 11:00:00 +0200 |
---|---|---|
committer | Mateusz Gołuchowski <mateusz.goluchowski@nokia.com> | 2020-07-20 10:57:45 +0200 |
commit | c62f765c1ed65829e126807e1e7a91388bb1c322 (patch) | |
tree | 0bba7d7bd35e8ecdcb00047a0bae1a82e64f35ef /src/main | |
parent | 977a518c680032572f6c5c59879ead71221e460a (diff) |
Adjust pm-mapper to accept new schema.
- Replaced 28.550 schema and template with 28.532 standard
- Adjusted class for new schema
- Adjusted xml files for tests
- validate method will now throw exception when given fileFormatType is not supported
Issue-ID: DCAEGEN2-2308
Change-Id: I375db2004887f1f634adac31d4d1af3675f5911c
Signed-off-by: Mateusz Goluchowski <mateusz.goluchowski@nokia.com>
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/NotSupportedFormatTypeException.java | 29 | ||||
-rw-r--r-- | src/main/java/org/onap/dcaegen2/services/pmmapper/model/measurement/nr/MeasDataFile.java | 31 | ||||
-rw-r--r-- | src/main/java/org/onap/dcaegen2/services/pmmapper/utils/MeasConverter.java | 4 | ||||
-rw-r--r-- | src/main/java/org/onap/dcaegen2/services/pmmapper/utils/XMLValidator.java | 20 | ||||
-rw-r--r-- | src/main/resources/schemas/org.3GPP.28.532#measData (renamed from src/main/resources/schemas/org.3GPP.28.550#measData) | 58 | ||||
-rw-r--r-- | src/main/resources/templates/org.3GPP.28.532#measData (renamed from src/main/resources/templates/org.3GPP.28.550#measData) | 18 |
6 files changed, 102 insertions, 58 deletions
diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/NotSupportedFormatTypeException.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/NotSupportedFormatTypeException.java new file mode 100644 index 0000000..3e3214d --- /dev/null +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/exceptions/NotSupportedFormatTypeException.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.pmmapper.exceptions; + +public class NotSupportedFormatTypeException extends Exception { + + public NotSupportedFormatTypeException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/measurement/nr/MeasDataFile.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/measurement/nr/MeasDataFile.java index 1ef1a8b..0f87465 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/measurement/nr/MeasDataFile.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/measurement/nr/MeasDataFile.java @@ -20,10 +20,11 @@ package org.onap.dcaegen2.services.pmmapper.model.measurement.nr; -import java.util.ArrayList; -import java.util.List; +import lombok.Data; +import org.onap.dcaegen2.services.pmmapper.model.measurement.common.MeasurementData; +import org.onap.dcaegen2.services.pmmapper.model.measurement.common.MeasurementFile; +import org.onap.dcaegen2.services.pmmapper.model.measurement.common.MeasurementInfo; -import java.util.Optional; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -32,10 +33,9 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSchemaType; import javax.xml.bind.annotation.XmlType; import javax.xml.datatype.XMLGregorianCalendar; -import lombok.Data; -import org.onap.dcaegen2.services.pmmapper.model.measurement.common.MeasurementData; -import org.onap.dcaegen2.services.pmmapper.model.measurement.common.MeasurementFile; -import org.onap.dcaegen2.services.pmmapper.model.measurement.common.MeasurementInfo; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { @@ -43,7 +43,7 @@ import org.onap.dcaegen2.services.pmmapper.model.measurement.common.MeasurementI "measData", "fileFooter" }) -@XmlRootElement(name = "MeasDataFile") +@XmlRootElement(name = "measDataFile") @Data public class MeasDataFile implements MeasurementFile { @@ -68,7 +68,7 @@ public class MeasDataFile implements MeasurementFile { measData.clear(); measurementData.forEach(measurementDatum -> { MeasData measDatum = new MeasData(); - measDatum.setMeasuredEntity((MeasData.MeasuredEntity) measurementDatum.getManagedEntity()); + measDatum.setMeasEntity((MeasData.MeasEntity) measurementDatum.getManagedEntity()); measDatum.setMeasInfo(measurementDatum.getMeasurementInfo()); this.measData.add(measDatum); }); @@ -81,7 +81,7 @@ public class MeasDataFile implements MeasurementFile { @Data public static class FileFooter { - @XmlElement(name = "MeasData", required = true) + @XmlElement(name = "measData", required = true) protected MeasDataFile.FileFooter.MeasData measData; @XmlAccessorType(XmlAccessType.FIELD) @@ -104,7 +104,7 @@ public class MeasDataFile implements MeasurementFile { public static class FileHeader { @XmlElement(required = true) protected MeasDataFile.FileHeader.FileSender fileSender; - @XmlElement(name = "MeasData", required = true) + @XmlElement(name = "measData", required = true) protected MeasDataFile.FileHeader.MeasData measData; @XmlAttribute(name = "fileFormatVersion", required = true) protected String fileFormatVersion; @@ -137,14 +137,13 @@ public class MeasDataFile implements MeasurementFile { @XmlAccessorType(XmlAccessType.FIELD) - @XmlType(name = "", propOrder = { - "measuredEntity", + @XmlType(name = "", propOrder = {"measEntity", "measInfo" }) @Data public static class MeasData implements MeasurementData { @XmlElement(required = true) - protected MeasDataFile.MeasData.MeasuredEntity measuredEntity; + protected MeasEntity measEntity; @XmlElement() protected List<MeasurementInfo> measInfo; @@ -160,13 +159,13 @@ public class MeasDataFile implements MeasurementFile { @Override public Object getManagedEntity() { - return this.measuredEntity; + return this.measEntity; } @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "") @Data - public static class MeasuredEntity { + public static class MeasEntity { @XmlAttribute(name = "localDn") protected String localDn; @XmlAttribute(name = "userLabel") diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/MeasConverter.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/MeasConverter.java index 70ad8ab..dbe58ab 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/MeasConverter.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/MeasConverter.java @@ -49,8 +49,8 @@ public class MeasConverter { private static final ONAPLogAdapter logger = new ONAPLogAdapter(LoggerFactory.getLogger(MeasConverter.class));
public static final String LTE_FILE_TYPE = "org.3GPP.32.435#measCollec";
- public static final String NR_FILE_TYPE = "org.3GPP.28.550#measData";
-
+ public static final String NR_FILE_TYPE = "org.3GPP.28.532#measData";
+ public static final String NOT_SUPPORTED_TYPE = "notSupportedType";
/**
* Converts 3GPP Measurement xml string to MeasCollecFile.
diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/XMLValidator.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/XMLValidator.java index c6fa3fa..0d14e1c 100644 --- a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/XMLValidator.java +++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/XMLValidator.java @@ -23,11 +23,14 @@ package org.onap.dcaegen2.services.pmmapper.utils; import java.nio.file.Files; import java.util.HashMap; import java.util.stream.Stream; + import lombok.NonNull; +import org.onap.dcaegen2.services.pmmapper.exceptions.NotSupportedFormatTypeException; import org.onap.dcaegen2.services.pmmapper.model.Event; import org.onap.logging.ref.slf4j.ONAPLogAdapter; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; + import javax.xml.XMLConstants; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; @@ -41,6 +44,7 @@ public class XMLValidator { private static final ONAPLogAdapter logger = new ONAPLogAdapter(LoggerFactory.getLogger(XMLValidator.class)); private HashMap<String, Schema> schemas; private SchemaFactory schemaFactory; + public XMLValidator(Path schemaDirectory) { logger.unwrap().trace("Constructing schema from {}", schemaDirectory); schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); @@ -57,14 +61,15 @@ public class XMLValidator { logger.unwrap().debug("Loading schema from {}", schema.toString()); try { schemas.put(schema.getFileName().toString(), schemaFactory.newSchema(schema.toFile())); - } catch(SAXException exception) { + } catch (SAXException exception) { logger.unwrap().error("Failed to discover a valid schema at {}", schema, exception); throw new IllegalArgumentException("Failed to discover a valid schema from given path", exception); } } + public boolean validate(@NonNull Event event) { try { - Validator validator = schemas.get(event.getMetadata().getFileFormatType()).newValidator(); + Validator validator = getValidatorForAccordingFileFormat(event.getMetadata().getFileFormatType()); validator.validate(new StreamSource(new StringReader(event.getBody()))); logger.unwrap().info("XML validation successful"); logger.unwrap().debug(String.valueOf(event)); @@ -72,6 +77,17 @@ public class XMLValidator { } catch (SAXException | IOException exception) { logger.unwrap().error("XML validation failed {}", event, exception); return false; + } catch (NotSupportedFormatTypeException exception) { + logger.unwrap().error("XML validation failed - given file format type is not supported. {}", event, exception); + return false; + } + } + + private Validator getValidatorForAccordingFileFormat(String fileFormatType) throws NotSupportedFormatTypeException { + Schema schema = schemas.get(fileFormatType); + if (schema == null) { + throw new NotSupportedFormatTypeException(fileFormatType); } + return schema.newValidator(); } }
\ No newline at end of file diff --git a/src/main/resources/schemas/org.3GPP.28.550#measData b/src/main/resources/schemas/org.3GPP.28.532#measData index d3a9fef..0b4a8aa 100644 --- a/src/main/resources/schemas/org.3GPP.28.550#measData +++ b/src/main/resources/schemas/org.3GPP.28.532#measData @@ -1,12 +1,12 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="UTF-8" ?> <!-- - 3GPP TS 28.550 Measurements data XML file format definition + 3GPP TS 28.532 Measurements data XML file format definition data file XML schema measData.xsd --> -<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:md="http://www.3gpp.org/ftp/specs/archive/28_series/28.550#measData" targetNamespace="http://www.3gpp.org/ftp/specs/archive/28_series/28.550#measData" elementFormDefault="qualified"> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:md="http://www.3gpp.org/ftp/specs/archive/28_series/28.532#measData" targetNamespace="http://www.3gpp.org/ftp/specs/archive/28_series/28.532#measData" elementFormDefault="qualified"> <!-- Measurement collection data file root XML element --> - <element name="MeasDataFile"> + <element name="measDataFile"> <complexType> <sequence> <element name="fileHeader"> @@ -14,29 +14,29 @@ <sequence> <element name="fileSender"> <complexType> - <attribute name="senderName" type="string" use="optional"/> - <attribute name="senderType" type="string" use="optional"/> + <attribute name="senderName" type="string" use="optional" /> + <attribute name="senderType" type="string" use="optional" /> </complexType> </element> - <element name="MeasData"> + <element name="measData"> <complexType> - <attribute name="beginTime" type="dateTime" use="required"/> + <attribute name="beginTime" type="dateTime" use="required" /> </complexType> </element> </sequence> - <attribute name="fileFormatVersion" type="string" use="required"/> - <attribute name="vendorName" type="string" use="optional"/> - <attribute name="dnPrefix" type="string" use="optional"/> + <attribute name="fileFormatVersion" type="string" use="required" /> + <attribute name="vendorName" type="string" use="optional" /> + <attribute name="dnPrefix" type="string" use="optional" /> </complexType> </element> <element name="measData" minOccurs="0" maxOccurs="unbounded"> <complexType> <sequence> - <element name="measuredEntity"> + <element name="measEntity"> <complexType> - <attribute name="userLabel" type="string" use="optional"/> - <attribute name="localDn" type="string" use="optional"/> - <attribute name="swVersion" type="string" use="optional"/> + <attribute name="userLabel" type="string" use="optional" /> + <attribute name="localDn" type="string" use="optional" /> + <attribute name="swVersion" type="string" use="optional" /> </complexType> </element> <element name="measInfo" minOccurs="0" maxOccurs="unbounded"> @@ -44,31 +44,31 @@ <sequence> <element name="job" minOccurs="0"> <complexType> - <attribute name="jobId" type="string" use="required"/> + <attribute name="jobId" type="string" use="required" /> </complexType> </element> <element name="granPeriod"> <complexType> - <attribute name="duration" type="duration" use="required"/> - <attribute name="endTime" type="dateTime" use="required"/> + <attribute name="duration" type="duration" use="required" /> + <attribute name="endTime" type="dateTime" use="required" /> </complexType> </element> <element name="repPeriod" minOccurs="0"> <complexType> - <attribute name="duration" type="duration" use="required"/> + <attribute name="duration" type="duration" use="required" /> </complexType> </element> <choice> <element name="measTypes"> <simpleType> - <list itemType="Name"/> + <list itemType="Name" /> </simpleType> </element> <element name="measType" minOccurs="0" maxOccurs="unbounded"> <complexType> <simpleContent> <extension base="Name"> - <attribute name="p" type="positiveInteger" use="required"/> + <attribute name="p" type="positiveInteger" use="required" /> </extension> </simpleContent> </complexType> @@ -80,26 +80,26 @@ <choice> <element name="measResults"> <simpleType> - <list itemType="md:measResultType"/> + <list itemType="md:measResultType" /> </simpleType> </element> <element name="r" minOccurs="0" maxOccurs="unbounded"> <complexType> <simpleContent> <extension base="md:measResultType"> - <attribute name="p" type="positiveInteger" use="required"/> + <attribute name="p" type="positiveInteger" use="required" /> </extension> </simpleContent> </complexType> </element> </choice> - <element name="suspect" type="boolean" minOccurs="0"/> + <element name="suspect" type="boolean" minOccurs="0" /> </sequence> - <attribute name="measObjLdn" type="string" use="required"/> + <attribute name="measObjLdn" type="string" use="required" /> </complexType> </element> </sequence> - <attribute name="measInfoId" type="string" use="optional"/> + <attribute name="measInfoId" type="string" use="optional" /> </complexType> </element> </sequence> @@ -108,9 +108,9 @@ <element name="fileFooter"> <complexType> <sequence> - <element name="MeasData"> + <element name="measData"> <complexType> - <attribute name="endTime" type="dateTime" use="required"/> + <attribute name="endTime" type="dateTime" use="required" /> </complexType> </element> </sequence> @@ -123,7 +123,7 @@ <union memberTypes="integer float string"> <simpleType> <restriction base="string"> - <enumeration value="NULL"/> + <enumeration value="NULL" /> </restriction> </simpleType> </union> diff --git a/src/main/resources/templates/org.3GPP.28.550#measData b/src/main/resources/templates/org.3GPP.28.532#measData index 653077e..a845cc8 100644 --- a/src/main/resources/templates/org.3GPP.28.550#measData +++ b/src/main/resources/templates/org.3GPP.28.532#measData @@ -19,9 +19,9 @@ ============LICENSE_END========================================================= --> <#compress> -<#assign fileHeader = xml.MeasDataFile.fileHeader> -<#assign fileFooter = xml.MeasDataFile.fileFooter> -<#assign measData = xml.MeasDataFile.measData> +<#assign fileHeader = xml.measDataFile.fileHeader> +<#assign fileFooter = xml.measDataFile.fileFooter> +<#assign measData = xml.measDataFile.measData> <#setting datetime_format="iso"> { "event": { @@ -42,8 +42,8 @@ "sourceName": "${metadata.sourceName}", "reportingEntityName": "", "priority": "Normal", - "startEpochMicrosec": ${fileHeader.MeasData.@beginTime?datetime?long?c}, - "lastEpochMicrosec": ${fileFooter.MeasData.@endTime?datetime?long?c}, + "startEpochMicrosec": ${fileHeader.measData.@beginTime?datetime?long?c}, + "lastEpochMicrosec": ${fileFooter.measData.@endTime?datetime?long?c}, "version": "4.0", "vesEventListenerVersion": "7.1", "timeZoneOffset": "${metadata.timeZoneOffset}" @@ -116,9 +116,9 @@ <#macro measDataCollection> { "granularityPeriod": ${measData.measInfo.granPeriod.@endTime[0]!?datetime?long?c}, - "measuredEntityUserName": "${measData.measuredEntity.@userLabel[0]!}", - "measuredEntityDn": "${measData.measuredEntity.@localDn[0]!}", - "measuredEntitySoftwareVersion": "${measData.measuredEntity.@swVersion[0]!}", + "measuredEntityUserName": "${measData.measEntity.@userLabel[0]!}", + "measuredEntityDn": "${measData.measEntity.@localDn[0]!}", + "measuredEntitySoftwareVersion": "${measData.measEntity.@swVersion[0]!}", "measInfoList": <@measInfoList/> } </#macro> @@ -129,4 +129,4 @@ "measDataCollection": <@measDataCollection/> } </#macro> -</#compress>
\ No newline at end of file +</#compress> |