use of com.helger.peppol.sbdh.write.PeppolSBDHDocumentWriter in project phase4 by phax.
the class Phase4PeppolSender method createSBDH.
/**
* @param aSenderID
* Sender participant ID. May not be <code>null</code>.
* @param aReceiverID
* Receiver participant ID. May not be <code>null</code>.
* @param aDocTypeID
* Document type ID. May not be <code>null</code>.
* @param aProcID
* Process ID. May not be <code>null</code>.
* @param sInstanceIdentifier
* SBDH instance identifier. May be <code>null</code> to create a
* random ID.
* @param sTypeVersion
* SBDH syntax version ID (e.g. "2.1" for OASIS UBL 2.1). May be
* <code>null</code> to use the default.
* @param aPayloadElement
* Payload element to be wrapped. May not be <code>null</code>.
* @return The domain object representation of the created SBDH or
* <code>null</code> if not all parameters are present.
*/
@Nullable
public static StandardBusinessDocument createSBDH(@Nonnull final IParticipantIdentifier aSenderID, @Nonnull final IParticipantIdentifier aReceiverID, @Nonnull final IDocumentTypeIdentifier aDocTypeID, @Nonnull final IProcessIdentifier aProcID, @Nullable final String sInstanceIdentifier, @Nullable final String sTypeVersion, @Nonnull final Element aPayloadElement) {
final PeppolSBDHDocument aData = new PeppolSBDHDocument(IF);
aData.setSender(aSenderID.getScheme(), aSenderID.getValue());
aData.setReceiver(aReceiverID.getScheme(), aReceiverID.getValue());
aData.setDocumentType(aDocTypeID.getScheme(), aDocTypeID.getValue());
aData.setProcess(aProcID.getScheme(), aProcID.getValue());
String sRealTypeVersion = sTypeVersion;
if (StringHelper.hasNoText(sRealTypeVersion)) {
// Determine from document type
try {
final IPeppolDocumentTypeIdentifierParts aParts = PeppolDocumentTypeIdentifierParts.extractFromIdentifier(aDocTypeID);
sRealTypeVersion = aParts.getVersion();
} catch (final IllegalArgumentException ex) {
// failure
}
}
if (StringHelper.hasNoText(sRealTypeVersion)) {
LOGGER.warn("No TypeVersion was provided and none could be deduced from the document type identifier '" + aDocTypeID.getURIEncoded() + "'");
return null;
}
String sRealInstanceIdentifier = sInstanceIdentifier;
if (StringHelper.hasNoText(sRealInstanceIdentifier)) {
sRealInstanceIdentifier = UUID.randomUUID().toString();
if (LOGGER.isDebugEnabled())
LOGGER.debug("As no SBDH InstanceIdentifier was provided, a random one was created: '" + sRealInstanceIdentifier + "'");
}
aData.setDocumentIdentification(aPayloadElement.getNamespaceURI(), sRealTypeVersion, aPayloadElement.getLocalName(), sRealInstanceIdentifier, XMLOffsetDateTime.of(MetaAS4Manager.getTimestampMgr().getCurrentDateTime()));
aData.setBusinessMessage(aPayloadElement);
return new PeppolSBDHDocumentWriter().createStandardBusinessDocument(aData);
}
Aggregations