diff --git a/schemas/Metals/v0.1.1/stylesheet.xsl b/schemas/Metals/v0.1.1/stylesheet.xsl index c443bcd..378db02 100644 --- a/schemas/Metals/v0.1.1/stylesheet.xsl +++ b/schemas/Metals/v0.1.1/stylesheet.xsl @@ -21,11 +21,29 @@ xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" xmlns:mi="urn:material-identity:metals-stylesheet"> + + + + + + + + + + - - + + @@ -49,21 +67,21 @@ - Digital Material Passport + - ID + - - Version + - Issue Date + - - Certificate Type + @@ -99,13 +117,13 @@ - Manufacturer + - Customer + - Business Transaction + @@ -128,9 +146,9 @@ - Subcustomer - Goods Receiver - Certificate Receiver + + + @@ -158,7 +176,7 @@ - + @@ -173,14 +191,14 @@ - + - + @@ -188,7 +206,7 @@ - + @@ -197,7 +215,7 @@ - + @@ -206,7 +224,7 @@ - + @@ -215,7 +233,7 @@ - + @@ -224,7 +242,7 @@ - + @@ -233,7 +251,7 @@ - + @@ -242,7 +260,7 @@ - + @@ -251,7 +269,7 @@ - + @@ -260,7 +278,7 @@ - + @@ -269,7 +287,7 @@ - + - + - + @@ -321,7 +339,7 @@ - + @@ -331,7 +349,7 @@ - + - + @@ -357,7 +375,7 @@ - + @@ -366,7 +384,7 @@ - + @@ -375,7 +393,7 @@ - + @@ -384,7 +402,7 @@ - + @@ -393,7 +411,7 @@ - + @@ -419,24 +437,24 @@ - + - Process: + : - - Lot: + : - - Furnace: + : - - Date: + : @@ -449,11 +467,11 @@ - Stage - Temperature - Duration - Cooling - Atmosphere + + + + + @@ -491,39 +509,39 @@ - + - Heat Number + - - Cast Number + - - Melting Process + - - Casting Method + - - Casting Date + - - Sample Location + @@ -622,7 +640,7 @@ select="distinct-values(for $t in distinct-values($allTC) return if (count($allTC[. eq $t]) ge 2) then $t else ())" /> - + - + @@ -1276,7 +1294,7 @@ - Validated by + , @@ -1326,19 +1344,19 @@ - Symbol + - Unit + - Min + @@ -1353,7 +1371,7 @@ - Max + @@ -1368,7 +1386,7 @@ - Actual + @@ -1457,7 +1475,7 @@ on some fixtures. The comma preserves this explicit priority regardless of input order. --> - + @@ -1476,12 +1494,26 @@ - Pos. + · + + + + : + + + + + : + + @@ -1651,13 +1683,13 @@ - No. + - Symbol + @@ -1669,42 +1701,42 @@ - Average + - Min + - Max + - Std Dev + - Spec Min + - Spec Max + - Method + - Status + @@ -1714,9 +1746,9 @@ - + - Value + @@ -1836,7 +1868,7 @@ ) - Parameter + @@ -1852,7 +1884,7 @@ - Min + @@ -1871,7 +1903,7 @@ - Max + @@ -1893,9 +1925,9 @@ - + - Value + @@ -1913,7 +1945,7 @@ - Status + @@ -2380,7 +2412,7 @@ - Specimen: + : @@ -2399,7 +2431,7 @@ - - ID: + : diff --git a/schemas/Metals/v0.1.1/translation.json b/schemas/Metals/v0.1.1/translation.json index 70940e3..80f016d 100644 --- a/schemas/Metals/v0.1.1/translation.json +++ b/schemas/Metals/v0.1.1/translation.json @@ -403,7 +403,43 @@ "OtherMechanicalTests": "Other Mechanical Tests", "NonDestructiveTests": "Non-Destructive Tests", "OtherProductTests": "Other Product Tests", - "Attachments": "Attachments" + "Attachments": "Attachments", + + "ProductName": "Product Name", + "ToleranceStandard": "Tolerance Standard", + "Specification": "Specification", + "DiameterTolerance": "Diameter Tolerance", + "FlangeThicknessTolerance": "Flange Thickness Tolerance", + "FlangeWidthTolerance": "Flange Width Tolerance", + "HeightTolerance": "Height Tolerance", + "InnerDiameterTolerance": "Inner Diameter Tolerance", + "LengthTolerance": "Length Tolerance", + "OuterDiameterTolerance": "Outer Diameter Tolerance", + "ThicknessTolerance": "Thickness Tolerance", + "WallThicknessTolerance": "Wall Thickness Tolerance", + "WebThicknessTolerance": "Web Thickness Tolerance", + "WidthTolerance": "Width Tolerance", + "Lot": "Lot", + "Stage": "Stage", + "Atmosphere": "Atmosphere", + "Property": "Property", + "Symbol": "Symbol", + "Min": "Min", + "Max": "Max", + "Status": "Status", + "TargetOrMinimum": "Target/Min", + "Test": "Test", + "ResultAndLimits": "Result / limits", + "SequenceNumber": "No.", + "Average": "Average", + "StdDev": "Std Dev", + "SpecMin": "Spec Min", + "SpecMax": "Spec Max", + "Parameter": "Parameter", + "MicroPurityIso4967": "Micro-purity acc. ISO 4967 - actual (max) per type", + "Specimen": "Specimen", + "PositionShort": "Pos.", + "ValidatedBy": "Validated by" } }, "DE": { @@ -811,7 +847,43 @@ "OtherMechanicalTests": "Andere mechanische Prüfungen", "NonDestructiveTests": "Zerstörungsfreie Prüfungen", "OtherProductTests": "Andere Produktprüfungen", - "Attachments": "Anlagen" + "Attachments": "Anlagen", + + "ProductName": "Produktname", + "ToleranceStandard": "Toleranznorm", + "Specification": "Spezifikation", + "DiameterTolerance": "Durchmessertoleranz", + "FlangeThicknessTolerance": "Flanschdickentoleranz", + "FlangeWidthTolerance": "Flanschbreitentoleranz", + "HeightTolerance": "Höhentoleranz", + "InnerDiameterTolerance": "Innendurchmessertoleranz", + "LengthTolerance": "Längentoleranz", + "OuterDiameterTolerance": "Außendurchmessertoleranz", + "ThicknessTolerance": "Dickentoleranz", + "WallThicknessTolerance": "Wanddickentoleranz", + "WebThicknessTolerance": "Stegdickentoleranz", + "WidthTolerance": "Breitentoleranz", + "Lot": "Los", + "Stage": "Stufe", + "Atmosphere": "Atmosphäre", + "Property": "Eigenschaft", + "Symbol": "Symbol", + "Min": "Min", + "Max": "Max", + "Status": "Status", + "TargetOrMinimum": "Soll/Min", + "Test": "Prüfung", + "ResultAndLimits": "Ergebnis mit Grenzwerten", + "SequenceNumber": "Nr.", + "Average": "Durchschnitt", + "StdDev": "Std.-Abw.", + "SpecMin": "Spez. Min", + "SpecMax": "Spez. Max", + "Parameter": "Parameter", + "MicroPurityIso4967": "Mikroreinheit nach ISO 4967 - Ist (max) je Typ", + "Specimen": "Probekörper", + "PositionShort": "Pos.", + "ValidatedBy": "Validiert von" } } } diff --git a/src/main/java/com/materialidentity/schemaservice/TranslationLoader.java b/src/main/java/com/materialidentity/schemaservice/TranslationLoader.java index 0305111..2c10e2d 100644 --- a/src/main/java/com/materialidentity/schemaservice/TranslationLoader.java +++ b/src/main/java/com/materialidentity/schemaservice/TranslationLoader.java @@ -29,7 +29,9 @@ public JsonNode load() throws IOException { ObjectNode resourceTranslations = loadTranslationsFromResource(resource); JsonMerger.deepMerge(resourceTranslations, translations, null); } - return translations; + // Translation keys become XML element names under Root/Translations; Metals' keys include + // enum values such as "1/4T" that are not legal names (material-identity/schemas#331). + return XmlKeySanitizer.sanitize(translations); } private ObjectNode loadTranslationsFromResource(Resource resource) throws IOException { diff --git a/src/main/java/com/materialidentity/schemaservice/WatermarkManager.java b/src/main/java/com/materialidentity/schemaservice/WatermarkManager.java index 3ff82d9..1cca02c 100644 --- a/src/main/java/com/materialidentity/schemaservice/WatermarkManager.java +++ b/src/main/java/com/materialidentity/schemaservice/WatermarkManager.java @@ -51,12 +51,9 @@ public WatermarkManager(String text) { */ public static String resolveText(String translationFilePattern, String primaryLanguage) { String lang = primaryLanguage.toUpperCase(Locale.ROOT); - // Broaden "translations*.json" to "translation*.json" so Metals' singular - // translation.json (unmatched by the render pipeline's pattern) is found too. - String pattern = translationFilePattern.replace("translations*", "translation*"); try { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); - for (Resource resource : resolver.getResources("classpath*:" + pattern)) { + for (Resource resource : resolver.getResources("classpath*:" + translationFilePattern)) { JsonNode tree; try (InputStream is = resource.getInputStream()) { tree = objectMapper.readTree(is); diff --git a/src/main/java/com/materialidentity/schemaservice/XmlKeySanitizer.java b/src/main/java/com/materialidentity/schemaservice/XmlKeySanitizer.java new file mode 100644 index 0000000..a4c9b8c --- /dev/null +++ b/src/main/java/com/materialidentity/schemaservice/XmlKeySanitizer.java @@ -0,0 +1,75 @@ +package com.materialidentity.schemaservice; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; +import java.util.HashSet; +import java.util.Set; + +/** + * Rewrites JSON object keys so the document survives the XmlMapper JSON → XML conversion in + * {@link XsltTransformer}, which writes keys verbatim as element names. Metals' translation.json + * carries enum values such as {@code 1/4T} or {@code Quenching and Tempering} as keys; loading it + * as {@code Root/Translations} unsanitized produces XML that does not parse + * (material-identity/schemas#331). Any character that is illegal in an XML name becomes + * {@code _}, and a key that cannot start an XML name gets a {@code _} prefix. Legal keys pass + * through unchanged. Ported from material-identity/schema's {@code :legacy} module. + */ +public final class XmlKeySanitizer { + + private XmlKeySanitizer() { + } + + /** A deep copy of {@code node} with every object key rewritten to a legal XML element name. */ + public static JsonNode sanitize(JsonNode node) { + if (node.isObject()) { + // A key that is already legal owns its name; a rewritten key that lands on a taken + // name moves aside with a "_" prefix. Otherwise "a b" before "a_b" would take "a_b" + // and a lookup of a_b would read the wrong value. Key order is preserved. + Set taken = new HashSet<>(); + node.fieldNames().forEachRemaining(key -> { + if (sanitizeKey(key).equals(key)) { + taken.add(key); + } + }); + ObjectNode out = JsonNodeFactory.instance.objectNode(); + var fields = node.fields(); + while (fields.hasNext()) { + var entry = fields.next(); + String key = sanitizeKey(entry.getKey()); + if (!key.equals(entry.getKey())) { + while (taken.contains(key)) { + key = "_" + key; + } + taken.add(key); + } + out.set(key, sanitize(entry.getValue())); + } + return out; + } + if (node.isArray()) { + ArrayNode out = JsonNodeFactory.instance.arrayNode(node.size()); + node.forEach(element -> out.add(sanitize(element))); + return out; + } + return node; + } + + /** + * Rewrite one key: illegal characters → {@code _}, and a leading character that is only legal + * mid-name (a digit, {@code -}, {@code .}) keeps its value behind a {@code _} prefix. + */ + static String sanitizeKey(String key) { + StringBuilder sb = new StringBuilder(key.length() + 1); + for (int i = 0; i < key.length(); i++) { + char c = key.charAt(i); + boolean legal = Character.isLetterOrDigit(c) || c == '-' || c == '.' || c == '_'; + sb.append(legal ? c : '_'); + } + if (sb.isEmpty() || !(Character.isLetter(sb.charAt(0)) || sb.charAt(0) == '_')) { + sb.insert(0, '_'); + } + return sb.toString(); + } +} diff --git a/src/main/java/com/materialidentity/schemaservice/config/SchemaControllerConstants.java b/src/main/java/com/materialidentity/schemaservice/config/SchemaControllerConstants.java index fc33ab5..f000ca9 100644 --- a/src/main/java/com/materialidentity/schemaservice/config/SchemaControllerConstants.java +++ b/src/main/java/com/materialidentity/schemaservice/config/SchemaControllerConstants.java @@ -3,7 +3,9 @@ public final class SchemaControllerConstants { // render endpoint constants public static final String SCHEMAS_FOLDER_NAME = "schemas"; - public static final String JSON_TRANSLATIONS_FILE_NAME_PATTERN = "translations*.json"; + // Singular prefix so Metals' translation.json matches alongside every other family's + // translations.json (material-identity/schemas#331). + public static final String JSON_TRANSLATIONS_FILE_NAME_PATTERN = "translation*.json"; public static final String XSLT_FILE_NAME = "stylesheet.xsl"; public static final String DEFAULT_PDF_ATTACHMENT_CERT_FILE_NAME = "dmp.json"; public static final String DEFAULT_PDF_ATTACHMENT_CERT_FILE_EXTENSION = ".json"; diff --git a/src/test/java/com/materialidentity/schemaservice/TranslationLoaderTest.java b/src/test/java/com/materialidentity/schemaservice/TranslationLoaderTest.java new file mode 100644 index 0000000..0ba3a3e --- /dev/null +++ b/src/test/java/com/materialidentity/schemaservice/TranslationLoaderTest.java @@ -0,0 +1,98 @@ +package com.materialidentity.schemaservice; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.nio.file.Paths; + +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.materialidentity.schemaservice.config.SchemaControllerConstants; + +/** + * The render pipeline loads Metals' singular translation.json as Root/Translations + * (material-identity/schemas#331), with keys made legal XML names, and the test-mode watermark + * still resolves the same text from it. + */ +class TranslationLoaderTest { + + private static final ObjectMapper MAPPER = new ObjectMapper(); + + private static String pattern(String family, String version) { + return Paths.get("schemas", family, version, + SchemaControllerConstants.JSON_TRANSLATIONS_FILE_NAME_PATTERN).toString(); + } + + @Test + void loadsMetalsSingularTranslationFile() throws Exception { + JsonNode labels = new TranslationLoader(pattern("Metals", "v0.1.1"), new String[] { "EN" }) + .load().get("DigitalMaterialPassport"); + assertEquals("Cast Number", labels.get("CastNumber").asText()); + } + + @Test + void englishOnlyCertificateGetsEnglishLabelsOnly() throws Exception { + JsonNode labels = new TranslationLoader(pattern("Metals", "v0.1.1"), new String[] { "EN" }) + .load().get("DigitalMaterialPassport"); + assertEquals("Heat Number", labels.get("HeatNumber").asText()); + assertFalse(labels.get("HeatNumber").asText().contains(" / ")); + } + + @Test + void bilingualCertificateJoinsLabelsInLanguageOrder() throws Exception { + JsonNode labels = new TranslationLoader(pattern("Metals", "v0.1.1"), new String[] { "EN", "DE" }) + .load().get("DigitalMaterialPassport"); + assertEquals("Cast Number / Gussnummer", labels.get("CastNumber").asText()); + } + + @Test + void enumValueKeysBecomeLegalXmlNames() throws Exception { + JsonNode labels = new TranslationLoader(pattern("Metals", "v0.1.1"), new String[] { "EN" }) + .load().get("DigitalMaterialPassport"); + assertEquals("1/4 Thickness", labels.get("_1_4T").asText()); + assertEquals("Quenching and Tempering", labels.get("Quenching_and_Tempering").asText()); + assertFalse(labels.has("1/4T")); + } + + @Test + void sanitizingLeavesOtherFamiliesUnchanged() throws Exception { + for (String[] familyVersion : new String[][] { + { "CoA", "v1.1.0" }, { "EN10168", "v0.5.0" }, { "ForestrySource", "v1.1.0" } }) { + JsonNode loaded = new TranslationLoader(pattern(familyVersion[0], familyVersion[1]), + new String[] { "EN", "DE" }).load(); + assertTrue(loaded.size() > 0, familyVersion[0] + " translations should load"); + assertEquals(loaded, XmlKeySanitizer.sanitize(loaded), + familyVersion[0] + " keys must already be legal XML names"); + } + } + + @Test + void metalsWatermarkTextIsUnchanged() { + String metals = pattern("Metals", "v0.1.1"); + assertEquals("PREVIEW — NOT A VALID CERTIFICATE", WatermarkManager.resolveText(metals, "EN")); + assertEquals("VORSCHAU — KEIN GÜLTIGES ZERTIFIKAT", WatermarkManager.resolveText(metals, "DE")); + } + + @Test + void sanitizerRewritesOnlyIllegalKeys() throws Exception { + assertEquals("CastNumber", XmlKeySanitizer.sanitizeKey("CastNumber")); + assertEquals("_1_4T", XmlKeySanitizer.sanitizeKey("1/4T")); + assertEquals("L-T", XmlKeySanitizer.sanitizeKey("L-T")); + assertEquals("a_b", XmlKeySanitizer.sanitizeKey("a b")); + assertEquals("ns_name", XmlKeySanitizer.sanitizeKey("ns:name")); + assertEquals("_", XmlKeySanitizer.sanitizeKey("")); + + JsonNode out = XmlKeySanitizer.sanitize(MAPPER.readTree(""" + { "a b": "x", "a_b": "y", "list": [ { "1st": 1 } ], "keep": "v a l / u e" } + """)); + assertEquals(4, out.size()); + // "a_b" is already legal and keeps its name and value; the rewritten "a b" moves aside. + assertEquals("y", out.get("a_b").asText()); + assertEquals("x", out.get("_a_b").asText()); + assertEquals(1, out.at("/list/0/_1st").asInt()); + assertEquals("v a l / u e", out.get("keep").asText()); + } +} diff --git a/test/fixtures/Metals/v0.1.1/valid_address_fields.pdf b/test/fixtures/Metals/v0.1.1/valid_address_fields.pdf index f052dab..7eba7b4 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_address_fields.pdf and b/test/fixtures/Metals/v0.1.1/valid_address_fields.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_backward_compatibility.pdf b/test/fixtures/Metals/v0.1.1/valid_backward_compatibility.pdf index 0b71301..2b16f09 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_backward_compatibility.pdf and b/test/fixtures/Metals/v0.1.1/valid_backward_compatibility.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_basic_certificate.pdf b/test/fixtures/Metals/v0.1.1/valid_basic_certificate.pdf index a717294..c8ddc7a 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_basic_certificate.pdf and b/test/fixtures/Metals/v0.1.1/valid_basic_certificate.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_bilingual_labels.json b/test/fixtures/Metals/v0.1.1/valid_bilingual_labels.json new file mode 100644 index 0000000..350f327 --- /dev/null +++ b/test/fixtures/Metals/v0.1.1/valid_bilingual_labels.json @@ -0,0 +1,265 @@ +{ + "RefSchemaUrl": "https://schemas.materialidentity.org/metals-schemas/v0.1.1/schema.json", + "DigitalMaterialPassport": { + "Languages": [ + "EN", + "DE" + ], + "Id": "DMP-AL-2025-00733", + "Version": "1.0.0", + "IssueDate": "2025-06-02", + "TransactionData": { + "Parties": { + "Manufacturer": { + "Name": "ACME Aluminium Extrusions S.A.", + "Street": [ + "Industrial Zone B, Plot 17" + ], + "ZipCode": "57022", + "City": "Thessaloniki", + "Country": "GR", + "Email": "quality@acme-aluminium.example.com", + "Identifiers": { + "VAT": "EL123456789" + } + }, + "Customer": { + "Name": "Window Systems GmbH", + "Street": [ + "Fensterstraße 12" + ], + "ZipCode": "70173", + "City": "Stuttgart", + "Country": "DE", + "Email": "purchasing@windowsystems.example.com", + "Identifiers": { + "VAT": "DE987654321" + } + } + }, + "BusinessTransaction": { + "Contract": { + "Id": "CT-2025-0042", + "Date": "2025-01-10", + "Description": "Frame agreement for extruded aluminium profiles 2025" + }, + "Order": { + "Id": "PO-2025-1187", + "Position": "30", + "Date": "2025-04-14", + "Quantity": 2400, + "QuantityUnit": "m", + "CustomerProductId": "WS-Z-6060-T66" + }, + "Delivery": { + "Id": "DN-2025-0466", + "Position": "2", + "Date": "2025-05-28", + "Quantity": 2400, + "QuantityUnit": "m", + "InternalOrderId": "SO-88123" + } + } + }, + "Product": { + "Name": "Extruded aluminium Z-profile EN AW-6060 T66", + "ProductNorms": [ + { + "Standard": "EN 755-2", + "Year": "2016" + } + ], + "MaterialNorms": [ + { + "Standard": "EN 573-3", + "Year": "2019" + } + ], + "MaterialDesignations": [ + { + "Name": { + "System": "EN 573-2", + "Value": "EN AW-AlMgSi" + }, + "Number": { + "System": "EN 573-1", + "Value": "EN AW-6060" + } + } + ], + "Shape": { + "Form": "ZProfile", + "Length": 6000, + "Height": 40, + "Width": 25, + "Thickness": 2.5, + "Unit": "mm", + "MassPerLength": 1.85, + "MassPerLengthUnit": "kg/m" + }, + "BatchId": "EXT-2025-05-0174", + "ToolingId": "NM520-3", + "SurfaceCondition": "Mill finish", + "CountryOfOrigin": "GR", + "ManufacturingLocation": "Thessaloniki Plant", + "ProductionDate": "2025-05-21", + "Quantity": 400, + "Weight": 4440, + "WeightUnit": "kg", + "DeliveryCondition": { + "Code": "T66", + "Description": "Solution heat-treated and artificially aged - improved mechanical properties", + "Standard": "EN 515" + }, + "ProductionIdentifiers": [ + { + "Type": "CastNumber", + "Value": "DC-2025-0417" + }, + { + "Type": "BilletNumber", + "Value": "B-0417-03" + } + ] + }, + "Validation": { + "ValidationStatement": { + "Statement": "We hereby certify that the material described above has been manufactured and tested in accordance with the requirements of EN 10204:2004 type 3.1 and the specified standards. The results comply with the requirements.", + "Standards": [ + "EN 755-2:2016", + "EN 10204:2004" + ], + "ComplianceType": "Declaration of Conformity" + }, + "ValidationDate": "2025-06-02", + "Validators": [ + { + "Name": "Eleni Papadopoulou", + "Title": "Quality Inspector", + "Department": "Quality Assurance" + } + ], + "ValidationPlace": "Thessaloniki, Greece", + "CertificateType": { + "Standard": "EN 10204", + "Type": "3.1" + } + }, + "ChemicalAnalysis": { + "CastNumber": "DC-2025-0417", + "CastingMethod": "DirectChillCasting", + "CastingDate": "2025-04-28", + "AnalysisStandard": "EN 573-3", + "Elements": [ + { + "PropertySymbol": "Si", + "Unit": "%", + "Actual": { + "ResultType": "numeric", + "Value": 0.44 + }, + "Maximum": { + "ResultType": "numeric", + "Value": 0.60 + }, + "Minimum": { + "ResultType": "numeric", + "Value": 0.30 + } + }, + { + "PropertySymbol": "Fe", + "Unit": "%", + "Actual": { + "ResultType": "numeric", + "Value": 0.16 + }, + "Maximum": { + "ResultType": "numeric", + "Value": 0.30 + }, + "Minimum": { + "ResultType": "numeric", + "Value": 0.10 + } + }, + { + "PropertySymbol": "Cu", + "Unit": "%", + "Actual": { + "ResultType": "numeric", + "Value": 0.01 + }, + "Maximum": { + "ResultType": "numeric", + "Value": 0.10 + } + }, + { + "PropertySymbol": "Mn", + "Unit": "%", + "Actual": { + "ResultType": "numeric", + "Value": 0.02 + }, + "Maximum": { + "ResultType": "numeric", + "Value": 0.10 + } + }, + { + "PropertySymbol": "Mg", + "Unit": "%", + "Actual": { + "ResultType": "numeric", + "Value": 0.44 + }, + "Maximum": { + "ResultType": "numeric", + "Value": 0.60 + }, + "Minimum": { + "ResultType": "numeric", + "Value": 0.35 + } + }, + { + "PropertySymbol": "Cr", + "Unit": "%", + "Actual": { + "ResultType": "numeric", + "Value": 0.001 + }, + "Maximum": { + "ResultType": "numeric", + "Value": 0.05 + } + }, + { + "PropertySymbol": "Zn", + "Unit": "%", + "Actual": { + "ResultType": "numeric", + "Value": 0.004 + }, + "Maximum": { + "ResultType": "numeric", + "Value": 0.15 + } + }, + { + "PropertySymbol": "Ti", + "Unit": "%", + "Actual": { + "ResultType": "numeric", + "Value": 0.011 + }, + "Maximum": { + "ResultType": "numeric", + "Value": 0.10 + } + } + ] + } + } +} diff --git a/test/fixtures/Metals/v0.1.1/valid_bilingual_labels.pdf b/test/fixtures/Metals/v0.1.1/valid_bilingual_labels.pdf new file mode 100644 index 0000000..6a8e07e Binary files /dev/null and b/test/fixtures/Metals/v0.1.1/valid_bilingual_labels.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_cast_number.pdf b/test/fixtures/Metals/v0.1.1/valid_cast_number.pdf index 6ad5333..a10bfc8 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_cast_number.pdf and b/test/fixtures/Metals/v0.1.1/valid_cast_number.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_country_of_melt_and_pour.json b/test/fixtures/Metals/v0.1.1/valid_country_of_melt_and_pour.json index 8db972c..ec16a1a 100644 --- a/test/fixtures/Metals/v0.1.1/valid_country_of_melt_and_pour.json +++ b/test/fixtures/Metals/v0.1.1/valid_country_of_melt_and_pour.json @@ -1,7 +1,7 @@ { "RefSchemaUrl": "https://schemas.materialidentity.org/metals-schemas/v0.1.1/schema.json", "DigitalMaterialPassport": { - "Languages": ["EN", "DE"], + "Languages": ["EN"], "Id": "DMP-METAL-013", "Version": "1.0.0", "IssueDate": "2025-05-14", diff --git a/test/fixtures/Metals/v0.1.1/valid_country_of_melt_and_pour.pdf b/test/fixtures/Metals/v0.1.1/valid_country_of_melt_and_pour.pdf index 39bfb9a..46eae06 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_country_of_melt_and_pour.pdf and b/test/fixtures/Metals/v0.1.1/valid_country_of_melt_and_pour.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_dimensional_tolerances.pdf b/test/fixtures/Metals/v0.1.1/valid_dimensional_tolerances.pdf index d20b29d..b8dc61d 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_dimensional_tolerances.pdf and b/test/fixtures/Metals/v0.1.1/valid_dimensional_tolerances.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_extruded_aluminium_profile.json b/test/fixtures/Metals/v0.1.1/valid_extruded_aluminium_profile.json index 3cbd033..51f9b3c 100644 --- a/test/fixtures/Metals/v0.1.1/valid_extruded_aluminium_profile.json +++ b/test/fixtures/Metals/v0.1.1/valid_extruded_aluminium_profile.json @@ -42,7 +42,8 @@ "Date": "2025-04-14", "Quantity": 2400, "QuantityUnit": "m", - "CustomerProductId": "WS-Z-6060-T66" + "CustomerProductId": "WS-Z-6060-T66", + "CustomerProductName": "Z-profile 40 x 30 x 2, window sash, drawing WS-114 rev C" }, "Delivery": { "Id": "DN-2025-0466", diff --git a/test/fixtures/Metals/v0.1.1/valid_extruded_aluminium_profile.pdf b/test/fixtures/Metals/v0.1.1/valid_extruded_aluminium_profile.pdf index c619873..6495efc 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_extruded_aluminium_profile.pdf and b/test/fixtures/Metals/v0.1.1/valid_extruded_aluminium_profile.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_individual_statements.json b/test/fixtures/Metals/v0.1.1/valid_individual_statements.json index 6152737..dcdb9f8 100644 --- a/test/fixtures/Metals/v0.1.1/valid_individual_statements.json +++ b/test/fixtures/Metals/v0.1.1/valid_individual_statements.json @@ -1,10 +1,7 @@ { "RefSchemaUrl": "https://schemas.materialidentity.org/metals-schemas/v0.1.1/schema.json", "DigitalMaterialPassport": { - "Languages": [ - "EN", - "DE" - ], + "Languages": ["EN"], "Id": "DMP-METAL-001", "Version": "1.0.0", "IssueDate": "2025-05-14", diff --git a/test/fixtures/Metals/v0.1.1/valid_individual_statements.pdf b/test/fixtures/Metals/v0.1.1/valid_individual_statements.pdf index 7e7d7fa..2ed53a2 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_individual_statements.pdf and b/test/fixtures/Metals/v0.1.1/valid_individual_statements.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_international_addresses.pdf b/test/fixtures/Metals/v0.1.1/valid_international_addresses.pdf index 34a71b2..4a0a642 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_international_addresses.pdf and b/test/fixtures/Metals/v0.1.1/valid_international_addresses.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_mechanical_properties.json b/test/fixtures/Metals/v0.1.1/valid_mechanical_properties.json index bb25e7b..01c2af9 100644 --- a/test/fixtures/Metals/v0.1.1/valid_mechanical_properties.json +++ b/test/fixtures/Metals/v0.1.1/valid_mechanical_properties.json @@ -1,7 +1,7 @@ { "RefSchemaUrl": "https://schemas.materialidentity.org/metals-schemas/v0.1.1/schema.json", "DigitalMaterialPassport": { - "Languages": ["EN", "DE"], + "Languages": ["EN"], "Id": "DMP-METAL-002", "Version": "1.0.0", "IssueDate": "2025-05-14", diff --git a/test/fixtures/Metals/v0.1.1/valid_mechanical_properties.pdf b/test/fixtures/Metals/v0.1.1/valid_mechanical_properties.pdf index 9dcc274..ffd046b 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_mechanical_properties.pdf and b/test/fixtures/Metals/v0.1.1/valid_mechanical_properties.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_physical_properties.pdf b/test/fixtures/Metals/v0.1.1/valid_physical_properties.pdf index b727130..b9fa56b 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_physical_properties.pdf and b/test/fixtures/Metals/v0.1.1/valid_physical_properties.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_product_analysis.pdf b/test/fixtures/Metals/v0.1.1/valid_product_analysis.pdf index 9b27407..c373578 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_product_analysis.pdf and b/test/fixtures/Metals/v0.1.1/valid_product_analysis.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_product_shapes.pdf b/test/fixtures/Metals/v0.1.1/valid_product_shapes.pdf index 5c7b5ef..b8ea294 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_product_shapes.pdf and b/test/fixtures/Metals/v0.1.1/valid_product_shapes.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_production_identifiers.pdf b/test/fixtures/Metals/v0.1.1/valid_production_identifiers.pdf index 1a12d3a..082ca27 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_production_identifiers.pdf and b/test/fixtures/Metals/v0.1.1/valid_production_identifiers.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_regulatory_markings.json b/test/fixtures/Metals/v0.1.1/valid_regulatory_markings.json index 40ffe7b..6423f41 100644 --- a/test/fixtures/Metals/v0.1.1/valid_regulatory_markings.json +++ b/test/fixtures/Metals/v0.1.1/valid_regulatory_markings.json @@ -1,10 +1,7 @@ { "RefSchemaUrl": "https://schemas.materialidentity.org/metals-schemas/v0.1.1/schema.json", "DigitalMaterialPassport": { - "Languages": [ - "EN", - "DE" - ], + "Languages": ["EN"], "Id": "DMP-METAL-007", "Version": "1.0.0", "IssueDate": "2025-05-20", diff --git a/test/fixtures/Metals/v0.1.1/valid_regulatory_markings.pdf b/test/fixtures/Metals/v0.1.1/valid_regulatory_markings.pdf index 7c42e46..5b47b4b 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_regulatory_markings.pdf and b/test/fixtures/Metals/v0.1.1/valid_regulatory_markings.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_result_types.json b/test/fixtures/Metals/v0.1.1/valid_result_types.json index 41e6768..2a359b2 100644 --- a/test/fixtures/Metals/v0.1.1/valid_result_types.json +++ b/test/fixtures/Metals/v0.1.1/valid_result_types.json @@ -1,10 +1,7 @@ { "RefSchemaUrl": "https://schemas.materialidentity.org/metals-schemas/v0.1.1/schema.json", "DigitalMaterialPassport": { - "Languages": [ - "EN", - "DE" - ], + "Languages": ["EN"], "Id": "DMP-METAL-005", "Version": "1.0.0", "IssueDate": "2025-05-17", diff --git a/test/fixtures/Metals/v0.1.1/valid_result_types.pdf b/test/fixtures/Metals/v0.1.1/valid_result_types.pdf index 98599c2..ee0757a 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_result_types.pdf and b/test/fixtures/Metals/v0.1.1/valid_result_types.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_statement_links.json b/test/fixtures/Metals/v0.1.1/valid_statement_links.json index 5d66358..68c29b5 100644 --- a/test/fixtures/Metals/v0.1.1/valid_statement_links.json +++ b/test/fixtures/Metals/v0.1.1/valid_statement_links.json @@ -1,10 +1,7 @@ { "RefSchemaUrl": "https://schemas.materialidentity.org/metals-schemas/v0.1.1/schema.json", "DigitalMaterialPassport": { - "Languages": [ - "EN", - "DE" - ], + "Languages": ["EN"], "Id": "DMP-METAL-LINKS-001", "Version": "1.0.0", "IssueDate": "2025-05-14", diff --git a/test/fixtures/Metals/v0.1.1/valid_statement_links.pdf b/test/fixtures/Metals/v0.1.1/valid_statement_links.pdf index a235a46..bdbdfe7 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_statement_links.pdf and b/test/fixtures/Metals/v0.1.1/valid_statement_links.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_supplementary_tests.json b/test/fixtures/Metals/v0.1.1/valid_supplementary_tests.json index 727b037..2986e97 100644 --- a/test/fixtures/Metals/v0.1.1/valid_supplementary_tests.json +++ b/test/fixtures/Metals/v0.1.1/valid_supplementary_tests.json @@ -1,10 +1,7 @@ { "RefSchemaUrl": "https://schemas.materialidentity.org/metals-schemas/v0.1.1/schema.json", "DigitalMaterialPassport": { - "Languages": [ - "EN", - "DE" - ], + "Languages": ["EN"], "Id": "DMP-METAL-004", "Version": "1.0.0", "IssueDate": "2025-05-16", diff --git a/test/fixtures/Metals/v0.1.1/valid_supplementary_tests.pdf b/test/fixtures/Metals/v0.1.1/valid_supplementary_tests.pdf index c95ec6d..9d98bc7 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_supplementary_tests.pdf and b/test/fixtures/Metals/v0.1.1/valid_supplementary_tests.pdf differ diff --git a/test/fixtures/Metals/v0.1.1/valid_word_wrap_breaks.pdf b/test/fixtures/Metals/v0.1.1/valid_word_wrap_breaks.pdf index 3a02325..8f5d4ac 100644 Binary files a/test/fixtures/Metals/v0.1.1/valid_word_wrap_breaks.pdf and b/test/fixtures/Metals/v0.1.1/valid_word_wrap_breaks.pdf differ diff --git a/test/metals-labels.spec.js b/test/metals-labels.spec.js new file mode 100644 index 0000000..29e7408 --- /dev/null +++ b/test/metals-labels.spec.js @@ -0,0 +1,93 @@ +// Metals v0.1.1 renders its labels from translation.json (material-identity/schemas#331). An +// English-only certificate (Interfer's production certificates) must render exactly as it did +// before the lookups existed, so every key the stylesheet reads must carry an EN value that is +// character-identical to the stylesheet's fallback literal. Any English drift fails here. +const fs = require('fs'); +const path = require('path'); + +const versionDir = path.resolve(__dirname, '../schemas/Metals/v0.1.1'); +const stylesheet = fs.readFileSync(path.join(versionDir, 'stylesheet.xsl'), 'utf8'); +const translations = JSON.parse( + fs.readFileSync(path.join(versionDir, 'translation.json'), 'utf8') +); +const schema = JSON.parse(fs.readFileSync(path.join(versionDir, 'schema.json'), 'utf8')); +const EN = translations.EN.DigitalMaterialPassport; +const DE = translations.DE.DigitalMaterialPassport; + +// mi:label('Key', 'Fallback') with two string literals +const staticCall = /mi:label\('([^']*)', '([^']*)'\)/g; +const staticLookups = [...stylesheet.matchAll(staticCall)].map(([, key, fallback]) => ({ + key, + fallback, +})); + +// Lookups whose key comes from the data; each is checked against the schema below. +const dynamicCalls = [ + // production identifier types + "mi:label(Type, replace(replace(Type, '([a-z])([A-Z])', '$1 $2'), ' Id$', ' ID'))", + // dimensional tolerance rows + "mi:label(concat(name(), 'Tolerance'), concat(replace(name(), '([a-z])([A-Z])', '$1 $2'), ' Tolerance'))", + // business transaction rows (Order / Delivery / Contract) + 'mi:label(name(), name())', +]; + +// The same fallback computations the stylesheet runs, in JavaScript +const splitCamel = (name) => name.replace(/([a-z])([A-Z])/g, '$1 $2'); +const identifierLabel = (type) => splitCamel(type).replace(/ Id$/, ' ID'); +const toleranceLabel = (name) => `${splitCamel(name)} Tolerance`; + +const identifierTypes = schema.$defs.ProductionIdentifier.properties.Type.enum; +const toleranceNames = Object.keys( + schema.$defs.DimensionalTolerances.properties.Tolerances.properties +); +const transactionRows = ['Order', 'Delivery', 'Contract']; + +const allLookups = [ + ...staticLookups, + ...identifierTypes.map((type) => ({ key: type, fallback: identifierLabel(type) })), + ...toleranceNames.map((name) => ({ key: `${name}Tolerance`, fallback: toleranceLabel(name) })), + ...transactionRows.map((row) => ({ key: row, fallback: row })), +]; + +describe('Metals v0.1.1 label lookups', () => { + test('every mi:label call is either a static literal pair or a known dynamic lookup', () => { + const total = stylesheet.split('mi:label(').length - 1; + dynamicCalls.forEach((call) => expect(stylesheet).toContain(call)); + expect(total).toBe(staticLookups.length + dynamicCalls.length); + }); + + test('covers the labels the stylesheet prints', () => { + // a floor, so a refactor that silently drops the lookups fails + expect(staticLookups.length).toBeGreaterThanOrEqual(90); + }); + + test.each(allLookups.map(({ key, fallback }) => [key, fallback]))( + 'EN %s equals the fallback literal "%s"', + (key, fallback) => { + expect(EN[key]).toBe(fallback); + } + ); + + test.each([...new Set(allLookups.map(({ key }) => key))])('DE defines %s', (key) => { + expect(DE[key]).toEqual(expect.any(String)); + expect(DE[key].length).toBeGreaterThan(0); + }); + + test.each([...new Set(allLookups.map(({ key }) => key))])( + '%s is a legal XML element name, so Root/Translations carries it unchanged', + (key) => { + expect(key).toMatch(/^[A-Za-z_][A-Za-z0-9._-]*$/); + } + ); + + test('the bilingual fixture lists both languages', () => { + const fixture = JSON.parse( + fs.readFileSync( + path.resolve(__dirname, 'fixtures/Metals/v0.1.1/valid_bilingual_labels.json'), + 'utf8' + ) + ); + expect(fixture.DigitalMaterialPassport.Languages).toEqual(['EN', 'DE']); + expect(fixture.DigitalMaterialPassport.ChemicalAnalysis.CastNumber).toBeDefined(); + }); +});