phax / peppol-commons

Java library with shared Peppol components - identifier handling, codelists, SBDH handler, SMP Client, SML Client
Apache License 2.0
29 stars 8 forks source link

SBDH Creation - How to read document type and process schema from document body #41

Closed francescodiperna closed 1 year ago

francescodiperna commented 1 year ago

Ciao, I'm writing a function for create the SBDH header with the following parameters:

Can I abstract from the document type and process schema calculating those data from the body of the document? This is my code, thanks.


Resource fileResource = new ClassPathResource("esempi/EsempioOrdineInizialiBuono.xml");     
String contenuto_file = CharStreams.toString(new InputStreamReader(fileResource.getInputStream(), Charsets.UTF_8));
final Document aDoc = DOMReader.readXMLDOM (contenuto_file);

// Create the document data
 final PeppolSBDHDocument aData = PeppolSBDHDocument.createUBL21 (
                aDoc.getDocumentElement (),
PeppolIdentifierFactory.INSTANCE)
                   .setSenderWithDefaultScheme ("0088:sender")
                   .setReceiverWithDefaultScheme ("0099:receiver")
                   .setDocumentTypeWithBusdoxDocidQns ("urn:foobar::root#doctypeid:2.1")
                   .setProcessWithDefaultScheme ("procid");
        // Create the SBDH document
        final StandardBusinessDocument aSBD = new PeppolSBDHDocumentWriter().createStandardBusinessDocument (aData);
        final String sXML = new SBDMarshaller().getAsString (aSBD);
phax commented 1 year ago

Hi @francescodiperna, yes theoretically you should be able to deduce the document type identifier from the document you want to send. The exactly rules for this is defined in the Peppol Policy for use of identifiers from https://docs.peppol.eu/edelivery/ - depending on the syntax you use (UBL or CII) you need to find the correct "Customization ID".

The process ID may also be deduced to my understanding - using the "Profile ID" in the document to be send.

If you however have a document type that doesn't have a Customization ID you may need a fallback.

I suggest to pass the document type ID and process ID explicitly to the method.

francescodiperna commented 1 year ago

Good morning Philip, thanks. Your answer confirm my implementation idea. Bye