From 3b2709a860a42554365922f18df81c196182bb14 Mon Sep 17 00:00:00 2001 From: Maxim Date: Tue, 2 Jul 2024 23:33:02 +0300 Subject: [PATCH] Fixing metadata. Support fixing non-integer parts --- .../fixer/gf/impl/model/MetadataImpl.java | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/metadata-fixer/src/main/java/org/verapdf/metadata/fixer/gf/impl/model/MetadataImpl.java b/metadata-fixer/src/main/java/org/verapdf/metadata/fixer/gf/impl/model/MetadataImpl.java index 225128147..3fffd8c15 100644 --- a/metadata-fixer/src/main/java/org/verapdf/metadata/fixer/gf/impl/model/MetadataImpl.java +++ b/metadata-fixer/src/main/java/org/verapdf/metadata/fixer/gf/impl/model/MetadataImpl.java @@ -204,10 +204,25 @@ public void addPDFUAIdentificationSchema(MetadataFixerResultImpl.Builder resultB if (!XMPMetaFactory.getSchemaRegistry().getNamespaces().containsKey(XMPConst.NS_PDFUA_ID)) { XMPMetaFactory.getSchemaRegistry().registerNamespace(XMPConst.NS_PDFUA_ID, VeraPDFMeta.PDFUAID_PREFIX, false); } - int part = flavour.getPart().getPartNumber(); - if (!Objects.equals(this.metadata.getPDFUAIdentificationPart(), part)) { - resultBuilder.addFix(String.format(this.metadata.getPDFUAIdentificationPart() == null ? - ADD_PROPERTY_MESSAGE : SET_PROPERTY_MESSAGE, VeraPDFMeta.PART, part)); + } catch (XMPException e) { + LOGGER.log(Level.FINE, "Can not register " + XMPConst.NS_PDFUA_ID + " namespace.", e); + } + boolean isBadPart = true; + boolean isMissingPart = false; + int part = flavour.getPart().getPartNumber(); + try { + if (Objects.equals(this.metadata.getPDFUAIdentificationPart(), part)) { + isBadPart = false; + } else { + isMissingPart = this.metadata.getPDFUAIdentificationPart() == null; + } + } catch (XMPException e) { + LOGGER.log(Level.FINE, "Can not obtain identification fields.", e); + } + try { + if (isBadPart) { + resultBuilder.addFix(String.format(isMissingPart ? ADD_PROPERTY_MESSAGE : SET_PROPERTY_MESSAGE, + VeraPDFMeta.PART, part)); this.metadata.setPDFUAIdentificationPart(part); this.setNeedToBeUpdated(true); } @@ -264,10 +279,21 @@ private boolean addPropertyDefinition(MetadataFixerResultImpl.Builder resultBuil public void addPDFAIdentificationSchema(MetadataFixerResultImpl.Builder resultBuilder, PDFAFlavour flavour) { int part = flavour.getPart().getPartNumber(); String conformance = !PDFFlavours.isFlavour(flavour, PDFAFlavour.PDFA_4) ? flavour.getLevel().getCode().toUpperCase() : null; + boolean isBadPart = true; + boolean isMissingPart = false; + try { + if (Objects.equals(this.metadata.getPDFAIdentificationPart(), part)) { + isBadPart = false; + } else { + isMissingPart = this.metadata.getPDFAIdentificationPart() == null; + } + } catch (XMPException e) { + LOGGER.log(Level.FINE, "Can not obtain identification fields.", e); + } try { - if (!Objects.equals(this.metadata.getPDFAIdentificationPart(), part)) { - resultBuilder.addFix(String.format(this.metadata.getPDFAIdentificationPart() == null ? - ADD_PROPERTY_MESSAGE : SET_PROPERTY_MESSAGE, VeraPDFMeta.PART, part)); + if (isBadPart) { + resultBuilder.addFix(String.format(isMissingPart ? ADD_PROPERTY_MESSAGE : SET_PROPERTY_MESSAGE, + VeraPDFMeta.PART, part)); this.metadata.setPDFAIdentificationPart(part); this.setNeedToBeUpdated(true); }