From 5d97afcc0137b2679f67793f05c462913c0b25ee Mon Sep 17 00:00:00 2001
From: Jan Loewe <jan.loewe@ptb.de>
Date: Mon, 14 Feb 2022 09:08:04 +0100
Subject: [PATCH] feat(dcc): update mapping to v3.1.0

---
 README.md                                            |  2 +-
 src/DCC.ts                                           |  7 ++++---
 src/DCCDocument.ts                                   | 12 +++++++++++-
 tests/DCCDocument.test.ts                            |  2 +-
 .../{siliziumkugel.xml.ts => example.xml.ts}         |  2 +-
 5 files changed, 18 insertions(+), 7 deletions(-)
 rename tests/Resources/{siliziumkugel.xml.ts => example.xml.ts} (99%)

diff --git a/README.md b/README.md
index c3272ce..0e94781 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,7 @@ const doc = DCCDocument.fromXml(xml);
 
 // access the properties of the DCC
 // _attr contains all the attributes of a given element
-doc.digitalCalibrationCertificate._attr.schemaVersion // => 3.1.0
+doc.digitalCalibrationCertificate._attr.schemaVersion // => 3.1.1
 // _text is used to access the value of the given element
 doc.digitalCalibrationCertificate.administrativeData.coreData.uniqueIdentifier._text
 
diff --git a/src/DCC.ts b/src/DCC.ts
index 1a0e9f4..a186379 100644
--- a/src/DCC.ts
+++ b/src/DCC.ts
@@ -2,7 +2,7 @@ import * as si from "./DSI";
 import { XMLDate, XMLElement, XMLNumber, XMLBoolean, XMLList, INamespaced, ISchemaInformation } from "./BaseTypes";
 import { ensureArray } from "./Util";
 
-const schemaVersion = "3.1.0";
+const schemaVersion = "3.1.1";
 const namespace = "dcc";
 const namespaceUrl = `https://ptb.de/${namespace}`;
 const schemaLocation = `${namespaceUrl}/v${schemaVersion}/dcc.xsd`;
@@ -1041,6 +1041,7 @@ export class ListType extends DCCXMLElement {
 
   constructor(el: Partial<ListType> = {}) {
     super(el);
+
     if (el.name) this.name = new TextType(el.name);
     if (el.description) this.description = new RichContentType(el.description);
     if (el.usedMethods) this.usedMethods = new UsedMethodListType(el.usedMethods);
@@ -1062,7 +1063,7 @@ export class ListType extends DCCXMLElement {
 export class RelativeUncertaintyType extends DCCXMLElement {
   // region choice
   relativeUncertaintyXmlList?: si.RealListXMLListType;
-  relativeUncertainty?: si.RealQuantityType;
+  relativeUncertaintySingle?: si.RealQuantityType;
 
   // endregion choice
 
@@ -1071,7 +1072,7 @@ export class RelativeUncertaintyType extends DCCXMLElement {
 
     // choice
     if (el.relativeUncertaintyXmlList) this.relativeUncertaintyXmlList = new si.RealListXMLListType(el.relativeUncertaintyXmlList);
-    else if (el.relativeUncertainty) this.relativeUncertainty = new si.RealQuantityType(el.relativeUncertainty);
+    else if (el.relativeUncertaintySingle) this.relativeUncertaintySingle = new si.RealQuantityType(el.relativeUncertaintySingle);
   }
 }
 
diff --git a/src/DCCDocument.ts b/src/DCCDocument.ts
index 065f7ae..74d8aa8 100644
--- a/src/DCCDocument.ts
+++ b/src/DCCDocument.ts
@@ -1,6 +1,6 @@
 import { Element, js2xml, xml2js } from "xml-js";
 
-import { DigitalCalibrationCertificateType } from "./DCC";
+import { DigitalCalibrationCertificateType, DCC } from "./DCC";
 
 export class DCCDocument {
   _declaration: unknown;
@@ -11,6 +11,16 @@ export class DCCDocument {
     this.digitalCalibrationCertificate = new DigitalCalibrationCertificateType(el?.digitalCalibrationCertificate);
   }
 
+  static createEmpty() {
+    return new DCCDocument({
+      digitalCalibrationCertificate: new DigitalCalibrationCertificateType({
+        _attr: {
+          schemaVersion: DCC.schemaVersion,
+        },
+      }),
+    });
+  }
+
   static fromXml(xml) {
     const parsed = <Partial<DCCDocument>>xml2js(xml, {
       compact: true,
diff --git a/tests/DCCDocument.test.ts b/tests/DCCDocument.test.ts
index 0bf6753..3e1d889 100644
--- a/tests/DCCDocument.test.ts
+++ b/tests/DCCDocument.test.ts
@@ -1,5 +1,5 @@
 import { DCCDocument } from "../src";
-import { xml } from "./Resources/siliziumkugel.xml";
+import { xml } from "./Resources/example.xml";
 import { expect } from "chai";
 import { describe, it } from "mocha";
 
diff --git a/tests/Resources/siliziumkugel.xml.ts b/tests/Resources/example.xml.ts
similarity index 99%
rename from tests/Resources/siliziumkugel.xml.ts
rename to tests/Resources/example.xml.ts
index 12c534b..ecb64cf 100644
--- a/tests/Resources/siliziumkugel.xml.ts
+++ b/tests/Resources/example.xml.ts
@@ -1,4 +1,4 @@
-const dcc = `<dcc:digitalCalibrationCertificate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dcc="https://ptb.de/dcc" xmlns:si="https://ptb.de/si" xsi:schemaLocation="https://ptb.de/dcc https://ptb.de/dcc/v3.1.0/dcc.xsd" schemaVersion="3.1.0">
+const dcc = `<dcc:digitalCalibrationCertificate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dcc="https://ptb.de/dcc" xmlns:si="https://ptb.de/si" xsi:schemaLocation="https://ptb.de/dcc https://ptb.de/dcc/v3.1.1/dcc.xsd" schemaVersion="3.1.1">
   <dcc:administrativeData>
     <dcc:dccSoftware>
       <dcc:software>
-- 
GitLab