diff --git a/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/DBNAlliancePayload.java b/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/DBNAlliancePayload.java index c7f96a5f..e27a7328 100644 --- a/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/DBNAlliancePayload.java +++ b/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/DBNAlliancePayload.java @@ -26,7 +26,10 @@ import com.helger.commons.annotation.Nonempty; import com.helger.commons.annotation.ReturnsMutableCopy; import com.helger.commons.annotation.ReturnsMutableObject; +import com.helger.commons.mime.CMimeType; +import com.helger.commons.mime.IMimeType; import com.helger.commons.string.StringHelper; +import com.helger.commons.string.ToStringGenerator; import com.helger.peppolid.IDocumentTypeIdentifier; import com.helger.peppolid.IProcessIdentifier; import com.helger.peppolid.factory.IIdentifierFactory; @@ -37,24 +40,25 @@ * of the Exchange Header Envelope (XHE) Version 1.0 specification. * * @author Robinson Garcia + * @author Philip Helger */ @NotThreadSafe public class DBNAlliancePayload { + public static final String DEFAULT_CONTENT_TYPE_CODE_LIST_ID = "MIME"; public static final boolean DEFAULT_INSTANCE_ENCRYPTION_INDICATOR = false; private final IIdentifierFactory m_aIdentifierFactory; private String m_sDescription; private String m_sContentTypeCodeListID; - private String m_sContentTypeCodeValue; - private String m_sCustomizationIDScheme; - private String m_sCustomizationIDValue; - private String m_sProfileIDScheme; - private String m_sProfileIDValue; + private String m_sContentTypeCode; + private String m_sCustomizationIDSchemeID; + private String m_sCustomizationID; + private String m_sProfileIDSchemeID; + private String m_sProfileID; private boolean m_bInstanceEncryptionIndicator = DEFAULT_INSTANCE_ENCRYPTION_INDICATOR; private String m_sInstanceEncryptionMethod; - // PayloadContent private Element m_aPayloadContent; /** @@ -93,18 +97,16 @@ public boolean hasDescription () * Set the content of the fields that are mapped to * XHE/Payloads/Payload/Description. * - * @param sDescription + * @param s * Description - An OPTIONAL human readable description of the payload. * This field is mapped to * XHE/Payloads/Payload/Description . - * @return this + * @return this for chaining */ @Nonnull - public DBNAlliancePayload setDescription (@Nonnull @Nonempty final String sDescription) + public DBNAlliancePayload setDescription (@Nullable final String s) { - ValueEnforcer.notEmpty (sDescription, "Description"); - - m_sDescription = sDescription; + m_sDescription = s; return this; } @@ -119,180 +121,308 @@ public String getContentTypeCodeListID () return m_sContentTypeCodeListID; } + /** + * @return true if a Content-Type Code list ID is present, + * false if not. + */ + public boolean hasContentTypeCodeListID () + { + return StringHelper.hasText (m_sContentTypeCodeListID); + } + + /** + * Set the content type code list ID. + * + * @param s + * An OPTIONAL aIribute specifying that the ContentTypeCode value is a + * MIME Type. When set, this aIribute MUST be set to: + * MIME. + * @return this for chaining + */ + @Nonnull + public DBNAlliancePayload setContentTypeCodeListID (@Nullable final String s) + { + m_sContentTypeCodeListID = s; + return this; + } + /** * @return The content type code value. May be null if not * initialized. This field is mapped to * XHE/Payloads/Payload/ContentTypeCode/. */ @Nullable - public String getContentTypeCodeValue () + public String getContentTypeCode () { - return m_sContentTypeCodeValue; + return m_sContentTypeCode; } /** - * Set the content type code. + * @return true if a Content-Type Code value is present, + * false if not. + */ + public boolean hasContentTypeCode () + { + return StringHelper.hasText (m_sContentTypeCode); + } + + /** + * Set the content type code. The MIME Type of the payload content. For XML + * payload content the ContentTypeCode MUST be set to: + * application/xml * - * @param slistID - * The DBNAlliance identifier scheme. May neither be null - * nor empty. This field is mapped to - * XHE/Payloads/Payload/ContentTypeCode/@listID . - * @param sValue - * The from party identifier value. May neither be null - * nor empty. This field is mapped to + * @param s + * The Content-Type code to use. This field is mapped to * XHE/Payloads/Payload/ContentTypeCode/. - * @return this + * @return this for chaining */ @Nonnull - public DBNAlliancePayload setContentTypeCode (@Nullable final String slistID, @Nonnull @Nonempty final String sValue) + public DBNAlliancePayload setContentTypeCode (@Nonnull @Nonempty final String s) { - ValueEnforcer.notEmpty (sValue, "Value"); + ValueEnforcer.notEmpty (s, "Value"); - m_sContentTypeCodeListID = slistID; - m_sContentTypeCodeValue = sValue; + m_sContentTypeCode = s; return this; } + @Nonnull + public DBNAlliancePayload setContentTypeCode (@Nullable final String sCodeListID, + @Nonnull @Nonempty final String sValue) + { + return setContentTypeCodeListID (sCodeListID).setContentTypeCode (sValue); + } + /** - * @return The customization id scheme that applies to the payload instance. - * May be null if not initialized. This field is mapped - * to XHE/Payloads/Payload/CustomizationID/@schemeID. + * Set the content type code. The MIME Type of the payload content. For XML + * payload content the ContentTypeCode MUST be set to: + * application/xml + * + * @param a + * The Content-Type code to use. May neither be null nor + * empty. This field is mapped to + * XHE/Payloads/Payload/ContentTypeCode/. + * @return this for chaining */ - @Nullable - public String getCustomizationIDScheme () + @Nonnull + public DBNAlliancePayload setContentTypeCode (@Nonnull final IMimeType a) + { + ValueEnforcer.notNull (a, "Value"); + return setContentTypeCode (a.getAsString ()); + } + + /** + * Set the content type code to application/xml + * + * @return this for chaining + */ + @Nonnull + public DBNAlliancePayload setContentTypeCodeXML () { - return m_sCustomizationIDScheme; + return setContentTypeCode (CMimeType.APPLICATION_XML); } /** - * @return The customization id value that applies to the payload instance. - * May be null if not initialized. This field is mapped - * to XHE/Payloads/Payload/CustomizationID/. + * @return The identifier of the scheme used for the CustomizationID if one is + * defined. May be null if not initialized. This field is + * mapped to + * XHE/Payloads/Payload/CustomizationID/@schemeID. */ @Nullable - public String getCustomizationIDValue () + public String getCustomizationIDSchemeID () + { + return m_sCustomizationIDSchemeID; + } + + public boolean hasCustomizationIDSchemeID () { - return m_sCustomizationIDValue; + return StringHelper.hasText (m_sCustomizationIDSchemeID); } /** - * @return The from party participant identifier as a participant identifier - * or null if certain information are missing or are - * invalid. + * Set the customization identifier scheme ID. + * + * @param s + * The identifier of the scheme used for the CustomizationID if one is + * defined. May be null if not initialized. This field is + * mapped to + * XHE/Payloads/Payload/CustomizationID/@schemeID. + * @return this for chaining + */ + @Nonnull + public DBNAlliancePayload setCustomizationIDSchemeID (@Nullable final String s) + { + m_sCustomizationIDSchemeID = s; + return this; + } + + /** + * @return If defined in the business document profile or specification of the + * payload, this MUST be set to the Customization ID as specified + * therein. May be null if not initialized. This field is + * mapped to XHE/Payloads/Payload/CustomizationID/. */ @Nullable - public IDocumentTypeIdentifier getCustomizationIDAsIdentifier () + public String getCustomizationID () + { + return m_sCustomizationID; + } + + public boolean hasCustomizationID () { - return m_aIdentifierFactory.createDocumentTypeIdentifier (m_sCustomizationIDScheme, m_sCustomizationIDValue); + return StringHelper.hasText (m_sCustomizationID); } /** * Set the customization identifier. * - * @param sScheme - * The customization id scheme that applies to the payload instance. - * May be null if not initialized. This field is mapped to - * XHE/Payloads/Payload/CustomizationID/@schemeID. - * @param sValue - * The customization id value that applies to the payload instance. May - * be null if not initialized. This field is mapped to + * @param s + * If defined in the business document profile or specification of the + * payload, this MUST be set to the Customization ID as specified + * therein. Otherwise, MUST NOT be used. May be null if + * not initialized. This field is mapped to * XHE/Payloads/Payload/CustomizationID/. - * @return this + * @return this for chaining */ @Nonnull - public DBNAlliancePayload setCustomizationID (@Nullable final String sScheme, @Nonnull @Nonempty final String sValue) + public DBNAlliancePayload setCustomizationID (@Nullable final String s) { - ValueEnforcer.notEmpty (sValue, "Value"); - - m_sCustomizationIDScheme = sScheme; - m_sCustomizationIDValue = sValue; + m_sCustomizationID = s; return this; } + /** + * @return The customization identifier as a document type identifier or + * null if certain information are missing or are + * invalid. + */ + @Nullable + public IDocumentTypeIdentifier getCustomizationIDAsIdentifier () + { + return m_aIdentifierFactory.createDocumentTypeIdentifier (m_sCustomizationIDSchemeID, m_sCustomizationID); + } + /** * Set the customization identifier. * - * @param aCustomizationID - * The document type identifier to use. May not be null. - * @return this + * @param a + * The document type identifier to use. May be null. + * @return this for chaining + * @see #setCustomizationIDSchemeID(String) + * @see #setCustomizationID(String) */ @Nonnull - public DBNAlliancePayload setCustomizationID (@Nonnull final IDocumentTypeIdentifier aCustomizationID) + public DBNAlliancePayload setCustomizationID (@Nullable final IDocumentTypeIdentifier a) { - ValueEnforcer.notNull (aCustomizationID, "CustomizationID"); + if (a != null) + return setCustomizationIDSchemeID (a.getScheme ()).setCustomizationID (a.getValue ()); + return this; + } - return setCustomizationID (aCustomizationID.getScheme (), aCustomizationID.getValue ()); + @Nonnull + public DBNAlliancePayload setCustomizationID (@Nullable final String sSchemeID, @Nullable final String sValue) + { + return setCustomizationIDSchemeID (sSchemeID).setCustomizationID (sValue); } /** - * @return The profile id scheme that the payload instance is part of. May be - * null if not initialized. This field is mapped to - * XHE/Payloads/Payload/ProfileID/@schemeID. + * @return The identifier of the scheme used for the ProfileID if one is + * defined. May be null if not initialized. This field is + * mapped to XHE/Payloads/Payload/ProfileID/@schemeID. */ @Nullable - public String getProfileIDScheme () + public String getProfileIDSchemeID () { - return m_sProfileIDScheme; + return m_sProfileIDSchemeID; + } + + public boolean hasProfileIDSchemeID () + { + return StringHelper.hasText (m_sProfileIDSchemeID); } /** - * @return The profile id value that the payload instance is part of. May be - * null if not initialized. This field is mapped to - * XHE/Payloads/Payload/ProfileID/. + * Set the profile identifier scheme ID. + * + * @param s + * The identifier of the scheme used for the ProfileID if one is + * defined. May be null if not initialized. This field is + * mapped to XHE/Payloads/Payload/ProfileID/@schemeID. + * @return this for chaining */ - @Nullable - public String getProfileIDValue () + @Nonnull + public DBNAlliancePayload setProfileIDSchemeID (@Nullable final String s) { - return m_sProfileIDValue; + m_sCustomizationIDSchemeID = s; + return this; } /** - * @return The from party participant identifier as a participant identifier - * or null if certain information are missing or are - * invalid. + * @return If defined in the business document profile or specification of the + * payload, this MUST be set to the Profile ID as specified therein. + * Otherwise, MUST NOT be used. May be null if not + * initialized. This field is mapped to + * XHE/Payloads/Payload/ProfileID/. */ @Nullable - public IProcessIdentifier getProfileIDAsIdentifier () + public String getProfileID () { - return m_aIdentifierFactory.createProcessIdentifier (m_sProfileIDScheme, m_sProfileIDValue); + return m_sProfileID; + } + + public boolean hasProfileID () + { + return StringHelper.hasText (m_sProfileID); } /** * Set the profile identifier. * - * @param sScheme - * The profile id scheme that the payload instance is part of. May be - * null if not initialized. This field is mapped to - * XHE/Payloads/Payload/ProfileID/@schemeID. - * @param sValue - * The profile id value that the payload instance is part of. May be - * null if not initialized. This field is mapped to + * @param s + * If defined in the business document profile or specification of the + * payload, this MUST be set to the Profile ID as specified therein. + * Otherwise, MUST NOT be used. May be null if not + * initialized. This field is mapped to * XHE/Payloads/Payload/ProfileID/. * @return this */ @Nonnull - public DBNAlliancePayload setProfileID (@Nullable final String sScheme, @Nonnull @Nonempty final String sValue) + public DBNAlliancePayload setProfileID (@Nullable final String s) { - ValueEnforcer.notEmpty (sValue, "Value"); - - m_sCustomizationIDScheme = sScheme; - m_sCustomizationIDValue = sValue; + m_sCustomizationID = s; return this; } + /** + * @return The profile identifier or null if certain information + * are missing or are invalid. + */ + @Nullable + public IProcessIdentifier getProfileIDAsIdentifier () + { + return m_aIdentifierFactory.createProcessIdentifier (m_sProfileIDSchemeID, m_sProfileID); + } + /** * Set the profile identifier. * * @param aProfileID - * The process identifier to use. May not be null. + * The process identifier to use. May be null. * @return this + * @see #setProfileID(String) + * @see #setProfileIDSchemeID(String) */ @Nonnull - public DBNAlliancePayload setProfileID (@Nonnull final IProcessIdentifier aProfileID) + public DBNAlliancePayload setProfileID (@Nullable final IProcessIdentifier aProfileID) { - ValueEnforcer.notNull (aProfileID, "CustomizationID"); + if (aProfileID != null) + return setProfileIDSchemeID (aProfileID.getScheme ()).setProfileID (aProfileID.getValue ()); + return this; + } - return setCustomizationID (aProfileID.getScheme (), aProfileID.getValue ()); + @Nonnull + public DBNAlliancePayload setProfileID (@Nullable final String sSchemeID, @Nullable final String sValue) + { + return setProfileIDSchemeID (sSchemeID).setProfileID (sValue); } /** @@ -311,25 +441,28 @@ public boolean isInstanceEncryptionIndicator () * Set the content of the fields that are mapped to * XHE/Payloads/Payload/InstanceEncryptionIndicator. * - * @param bInstanceEncryptionIndicator + * @param b * Indicator to state whether the payload instance is encrypted or not. * This field is mapped to * XHE/Payloads/Payload/InstanceEncryptionIndicator . * @return this */ @Nonnull - public DBNAlliancePayload setInstanceEncryptionIndicator (final boolean bInstanceEncryptionIndicator) + public DBNAlliancePayload setInstanceEncryptionIndicator (final boolean b) { - m_bInstanceEncryptionIndicator = bInstanceEncryptionIndicator; + m_bInstanceEncryptionIndicator = b; return this; } /** - * InstanceEncryptionMethod - Method used to encrypt the payload instance. - * This field is mapped to - * XHE/Payloads/Payload/InstanceEncryptionMethod. + * The method or algorithm used for encrypting payload content. When + * encryption is used, payloads MUST be encrypted using one of the supported + * encryption methods and algorithms as specified in section 7.3 and the value + * of this element MUST be set to the corresponding identifier. This field is + * mapped to XHE/Payloads/Payload/InstanceEncryptionMethod. * - * @return InstanceEncryptionMethod value. Default value is false. + * @return InstanceEncryptionMethod value. Default value is + * false. */ @Nullable public String getInstanceEncryptionMethod () @@ -347,20 +480,22 @@ public boolean hasInstanceEncryptionMethod () } /** - * Set the content of the fields that are mapped to + * Set the method or algorithm used for encrypting payload content. When + * encryption is used, payloads MUST be encrypted using one of the supported + * encryption methods and algorithms as specified in section 7.3 and the value + * of this element MUST be set to the corresponding identifier. The content of + * the fields that are mapped to * XHE/Payloads/Payload/InstanceEncryptionMethod. * - * @param sInstanceEncryptionMethod + * @param s * Method used to encrypt the payload instance. This field is mapped to * XHE/Payloads/Payload/InstanceEncryptionMethod . - * @return this + * @return this for chaining */ @Nonnull - public DBNAlliancePayload setInstanceEncryptionMethod (@Nonnull @Nonempty final String sInstanceEncryptionMethod) + public DBNAlliancePayload setInstanceEncryptionMethod (@Nullable final String s) { - ValueEnforcer.notEmpty (sInstanceEncryptionMethod, "InstanceEncryptionMethod"); - - m_sInstanceEncryptionMethod = sInstanceEncryptionMethod; + m_sInstanceEncryptionMethod = s; return this; } @@ -446,4 +581,25 @@ public DBNAlliancePayload setPayloadContentNoClone (@Nonnull final Element aPayl m_aPayloadContent = aPayloadContent; return this; } + + public boolean areAllMandatoryFieldsSet () + { + return hasContentTypeCode () && hasPayloadContent (); + } + + @Override + public String toString () + { + return new ToStringGenerator (null).append ("Description", m_sDescription) + .append ("ContentTypeCodeListID", m_sContentTypeCodeListID) + .append ("ContentTypeCode", m_sContentTypeCode) + .append ("CustomizationIDSchemeID", m_sCustomizationIDSchemeID) + .append ("CustomizationID", m_sCustomizationID) + .append ("ProfileIDSchemeID", m_sProfileIDSchemeID) + .append ("ProfileID", m_sProfileID) + .append ("InstanceEncryptionIndicator", m_bInstanceEncryptionIndicator) + .append ("InstanceEncryptionMethod", m_sInstanceEncryptionMethod) + .append ("PayloadContent", m_aPayloadContent) + .getToString (); + } } diff --git a/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/DBNAllianceXHEData.java b/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/DBNAllianceXHEData.java index 8d6ad989..b9a81bf0 100644 --- a/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/DBNAllianceXHEData.java +++ b/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/DBNAllianceXHEData.java @@ -43,11 +43,11 @@ * Envelope (XHE) Version 1.0 specification. * * @author Robinson Garcia + * @author Philip Helger */ @NotThreadSafe public class DBNAllianceXHEData { - private static final Logger LOGGER = LoggerFactory.getLogger (DBNAllianceXHEData.class); private final IIdentifierFactory m_aIdentifierFactory; @@ -78,7 +78,7 @@ public DBNAllianceXHEData (@Nonnull final IIdentifierFactory aIdentifierFactory) * be unique for each Exchange Header Envelope being created. This ID is not * the same as the ID of the business message (such as the Invoice Number). It * is not the same as a transmission Message ID generated by the application - * sending the message (as defined in AS2 or START).
+ * sending the message (as defined in e.g. AS4).
* The InstanceIdentifier MUST be globally unique and it is RECOMMENDED to use * UUID (such as 118e3040-51d2-11e3-8f96-0800200c9a66). This field is mapped * to XHE/Header/ID . @@ -118,10 +118,9 @@ public boolean hasID () * @return this */ @Nonnull - public DBNAllianceXHEData setInstanceIdentifier (@Nonnull @Nonempty final String sID) + public DBNAllianceXHEData setID (@Nonnull @Nonempty final String sID) { ValueEnforcer.notEmpty (sID, "ID"); - m_sID = sID; return this; } @@ -175,6 +174,18 @@ public DBNAllianceXHEData setCreationDateAndTime (@Nonnull final XMLOffsetDateTi return this; } + /** + * Set the content of the fields that are mapped to + * XHE/Header/CreationDateTime to the current date and time. + * + * @return this + */ + @Nonnull + public DBNAllianceXHEData setCreationDateAndTimeNow () + { + return setCreationDateAndTime (PDTFactory.getCurrentXMLOffsetDateTime ()); + } + /** * @return The from party participant identifier scheme. May be * null if not initialized. This field is mapped to @@ -413,7 +424,7 @@ public boolean areAllFieldsSet (final boolean bLogMissing) if (m_aPayloads.isEmpty ()) { - aCondLog.info ("DBNAlliance XHE data - An envelope MUST contain at least one business document."); + aCondLog.info ("DBNAlliance XHE data - An envelope MUST contain at least one payload."); return false; } @@ -435,8 +446,8 @@ public boolean areAllFieldsSet () * @see DBNAllianceXHEDocumentWriter for the main logic */ @Nonnull - public XHE10XHEType getAsStandardBusinessDocument () + public XHE10XHEType getAsXHEDocument () { - return new DBNAllianceXHEDocumentWriter ().createExchangeHeaderEnvelope (this); + return DBNAllianceXHEDocumentWriter.createExchangeHeaderEnvelope (this); } } diff --git a/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/read/DBNAllianceXHEDocumentReader.java b/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/read/DBNAllianceXHEDocumentReader.java index 3c28c817..87fcedb5 100644 --- a/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/read/DBNAllianceXHEDocumentReader.java +++ b/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/read/DBNAllianceXHEDocumentReader.java @@ -63,6 +63,7 @@ * required data out of it. * * @author Robinson Garcia + * @author Philip Helger */ public class DBNAllianceXHEDocumentReader { @@ -843,7 +844,7 @@ public DBNAllianceXHEData extractDataUnchecked (@Nonnull final XHE10XHEType aXHE final XHE10HeaderType aHeader = aXHE.getHeader (); if (aHeader != null) { - ret.setInstanceIdentifier (aHeader.getIDValue ()); + ret.setID (aHeader.getIDValue ()); ret.setCreationDateAndTime (aHeader.getCreationDateTimeValue ()); // From Party diff --git a/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/write/DBNAllianceXHEDocumentWriter.java b/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/write/DBNAllianceXHEDocumentWriter.java index 5b682f78..6407969a 100644 --- a/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/write/DBNAllianceXHEDocumentWriter.java +++ b/dbnalliance-xhe/src/main/java/com/helger/peppol/xhe/write/DBNAllianceXHEDocumentWriter.java @@ -16,9 +16,8 @@ */ package com.helger.peppol.xhe.write; -import java.util.List; - import javax.annotation.Nonnull; +import javax.annotation.concurrent.ThreadSafe; import com.helger.commons.ValueEnforcer; import com.helger.peppol.xhe.CDBNAllianceXHE; @@ -41,9 +40,13 @@ * Convert a DBNAlliance XHE document to a regular XHE document * * @author Robinson Garcia + * @author Philip Helger */ -public class DBNAllianceXHEDocumentWriter +@ThreadSafe +public final class DBNAllianceXHEDocumentWriter { + private DBNAllianceXHEDocumentWriter () + {} /** * Create a new {@link XHE10XHEType} from the specified document data. @@ -56,7 +59,7 @@ public class DBNAllianceXHEDocumentWriter * if not all document data fields are set! */ @Nonnull - public XHE10XHEType createExchangeHeaderEnvelope (@Nonnull final DBNAllianceXHEData aData) + public static XHE10XHEType createExchangeHeaderEnvelope (@Nonnull final DBNAllianceXHEData aData) { ValueEnforcer.notNull (aData, "Data"); if (!aData.areAllFieldsSet ()) @@ -111,51 +114,55 @@ public XHE10XHEType createExchangeHeaderEnvelope (@Nonnull final DBNAllianceXHED { final XHE10PayloadsType aPayloads = new XHE10PayloadsType (); - final List aDataPayloads = aData.getPayloads (); - int nID = 1; - for (final DBNAlliancePayload aDataPayload : aDataPayloads) + int nPayloadID = 1; + for (final DBNAlliancePayload aDataPayload : aData.getPayloads ()) { final XHE10PayloadType aPayload = new XHE10PayloadType (); // payload IDs MUST be numbered sequentially starting with the number 1. - aPayload.setID (Integer.toString (nID++)); + aPayload.setID (Integer.toString (nPayloadID++)); aPayload.setInstanceEncryptionIndicator (aDataPayload.isInstanceEncryptionIndicator ()); - aPayload.setInstanceEncryptionMethod (aDataPayload.getInstanceEncryptionMethod ()); + if (aDataPayload.hasInstanceEncryptionMethod ()) + aPayload.setInstanceEncryptionMethod (aDataPayload.getInstanceEncryptionMethod ()); // Description data + if (aDataPayload.hasDescription ()) { final XHE10DescriptionType aDescription = new XHE10DescriptionType (); aDescription.setValue (aDataPayload.getDescription ()); aPayload.addDescription (aDescription); } - // Content Type data + // Content Type (mandatory) { final XHE10ContentTypeCodeType aContentTypeCode = new XHE10ContentTypeCodeType (); aContentTypeCode.setListID (aDataPayload.getContentTypeCodeListID ()); - aContentTypeCode.setValue (aDataPayload.getContentTypeCodeValue ()); + aContentTypeCode.setValue (aDataPayload.getContentTypeCode ()); aPayload.setContentTypeCode (aContentTypeCode); } // Customization ID data + if (aDataPayload.hasCustomizationID ()) { final XHE10CustomizationIDType aCustomization = new XHE10CustomizationIDType (); - aCustomization.setSchemeID (aDataPayload.getCustomizationIDScheme ()); - aCustomization.setValue (aDataPayload.getCustomizationIDValue ()); + aCustomization.setSchemeID (aDataPayload.getCustomizationIDSchemeID ()); + aCustomization.setValue (aDataPayload.getCustomizationID ()); aPayload.setCustomizationID (aCustomization); } // Profile ID data + if (aDataPayload.hasProfileID ()) { final XHE10ProfileIDType aProfile = new XHE10ProfileIDType (); - aProfile.setSchemeID (aDataPayload.getProfileIDScheme ()); - aProfile.setValue (aDataPayload.getProfileIDValue ()); + aProfile.setSchemeID (aDataPayload.getProfileIDSchemeID ()); + aProfile.setValue (aDataPayload.getProfileID ()); aPayload.setProfileID (aProfile); } // Payload content data { final XHE10PayloadContentType aContent = new XHE10PayloadContentType (); - aContent.addContent (aDataPayload.getPayloadContentNoClone ()); + aContent.addContent (aDataPayload.getPayloadContent ()); + aPayload.setPayloadContent (aContent); } aPayloads.addPayload (aPayload); diff --git a/dbnalliance-xhe/src/test/java/com/helger/peppol/xhe/DBNAllianceXHEDataTest.java b/dbnalliance-xhe/src/test/java/com/helger/peppol/xhe/DBNAllianceXHEDataTest.java new file mode 100644 index 00000000..d6a24bbe --- /dev/null +++ b/dbnalliance-xhe/src/test/java/com/helger/peppol/xhe/DBNAllianceXHEDataTest.java @@ -0,0 +1,71 @@ +package com.helger.peppol.xhe; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; + +import com.helger.peppolid.factory.IIdentifierFactory; +import com.helger.peppolid.factory.SimpleIdentifierFactory; +import com.helger.xhe.v10.XHE10Marshaller; +import com.helger.xhe.v10.XHE10XHEType; +import com.helger.xml.serialize.read.DOMReader; + +/** + * Test class for class {@link DBNAllianceXHEData}. + * + * @author Philip Helger + */ +public final class DBNAllianceXHEDataTest +{ + private static final Logger LOGGER = LoggerFactory.getLogger (DBNAllianceXHEDataTest.class); + + @Test + public void testBasic () + { + final IIdentifierFactory aIF = SimpleIdentifierFactory.INSTANCE; + final DBNAllianceXHEData a = new DBNAllianceXHEData (aIF); + assertNull (a.getID ()); + assertFalse (a.hasID ()); + assertFalse (a.areAllFieldsSet (false)); + + final Document aPayload = DOMReader.readXMLDOM (""); + assertNotNull (aPayload); + + final DBNAlliancePayload aPayload1 = new DBNAlliancePayload (aIF).setContentTypeCodeXML () + .setPayloadContent (aPayload.getDocumentElement ()); + assertTrue (aPayload1.areAllMandatoryFieldsSet ()); + assertNotNull (aPayload1.getPayloadContent ()); + assertNotNull (aPayload1.getPayloadContentNoClone ()); + + a.setID ("abc") + .setCreationDateAndTimeNow () + .setFromParty ("fs", "fv") + .setToParty ("ts", "tv") + .addPayload (aPayload1); + + assertTrue (a.areAllFieldsSet (false)); + final XHE10XHEType aXHEDoc = a.getAsXHEDocument (); + assertNotNull (aXHEDoc); + + // Write unformatted + final String sXHE = new XHE10Marshaller ().setFormattedOutput (false).getAsString (aXHEDoc); + assertNotNull (sXHE); + if (false) + LOGGER.info (sXHE); + + // Read again + final XHE10XHEType aXHE2Doc = new XHE10Marshaller ().read (sXHE); + assertNotNull (aXHE2Doc); + + // Fails because of different payload element + if (false) + assertEquals (aXHEDoc, aXHE2Doc); + } +} diff --git a/dbnalliance-xhe/src/test/java/com/helger/peppol/xhe/SPITest.java b/dbnalliance-xhe/src/test/java/com/helger/peppol/xhe/SPITest.java new file mode 100644 index 00000000..3e66f205 --- /dev/null +++ b/dbnalliance-xhe/src/test/java/com/helger/peppol/xhe/SPITest.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2015-2024 Philip Helger + * philip[at]helger[dot]com + * + * 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. + */ +package com.helger.peppol.xhe; + +import org.junit.Test; + +import com.helger.commons.mock.SPITestHelper; + +public final class SPITest +{ + @Test + public void testBasic () throws Exception + { + SPITestHelper.testIfAllSPIImplementationsAreValid (); + } +}