Giter Club home page Giter Club logo

vefa-sbdh's Introduction

Build Status

vefa-sbdh - manipulates StandardBusinessDocument and StandardBusinessDocumentHeader

Use this component to:

  • wrap an ASiC archive as base64 encoded payload within a StandardBusinessDocument (SBD) for use with PEPPOL, eSENS etc.
  • parse (extract) base64 encoded ASiC archive from SBD payload
  • parse (extract) SBDH from really large XML documents very fast.

See UN/CEFACT SBDH Technical Specification for the details of the SBD and SBDH.

Note: The term "SBDH" is often used as a synonym for "SBD", which is kind of confusing.

ASiC as base64 encoded payload within StandardBusinessDocument

<?xml version="1.0"?>
<StandardBusinessDocument>
<StandardBusinessDocumentHeader xmlns="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">
    <HeaderVersion>1.0</HeaderVersion>
    <Sender>
        <Identifier Authority="iso6523-actorid-upis">9908:810018902</Identifier>
    </Sender>
    <Receiver>
        <Identifier Authority="iso6523-actorid-upis">9908:810418052</Identifier>
    </Receiver>
    <DocumentIdentification>
        <Standard>urn:oasis:names:specification:ubl:schema:xsd:Tender-2</Standard>
        <TypeVersion>2.1</TypeVersion>
        <InstanceIdentifier>FA4A6819-6149-4134-95C3-C53A65338EB6</InstanceIdentifier>
        <Type>Tender</Type>
        <CreationDateAndTime>2015-07-26T20:08:00+01:00</CreationDateAndTime>
    </DocumentIdentification>
    <Manifest>
        <NumberOfItems>1</NumberOfItems>
        <ManifestItem>
            <MimeTypeQualifierCode>application/vnd.etsi.asic-e+zip</MimeTypeQualifierCode>
            <UniformResourceIdentifier>#asic</UniformResourceIdentifier>
            <Description>ASiC archive containing the business documents.</Description>
        </ManifestItem>
    </Manifest>
    <BusinessScope>
        <Scope>
            <Type>PROCESSID</Type>
            <InstanceIdentifier>urn:www.cenbii.eu:profile:bii46:ver3.0</InstanceIdentifier>
        </Scope>
        <Scope>
            <Type>DOCUMENTID</Type>
            <InstanceIdentifier>
                urn:oasis:names:specification:ubl:schema:xsd:Tender-2::Tender##urn:www.cenbii.eu:transaction:biitrdm090:ver3.0::2.1
            </InstanceIdentifier>
        </Scope>
    </BusinessScope>
</StandardBusinessDocumentHeader>
<asic:asic xmlns:asic="urn:etsi.org:specification:02918:v1.2.1" id="asic">
UEsDBAoAAAgAAI1ZMEeKIflFHwAAAB8AAAAIAAAAbWltZXR5cGVhcHBsaWNhdGlvbi92bmQuZXRz
aS5hc2ljLWUremlwUEsDBBQACAgIAI1ZMEcAAAAAAAAAAAAAAAAIAAAAc2JkaC54bWytVk1z2kgQ
   .... loads of data removed for readability ......
bWxQSwUGAAAAAAcABwAUAgAAbBYAACgAbWltZXR5cGU9YXBwbGljYXRpb24vdm5kLmV0c2kuYXNp
Yy1lK3pp
</asic:asic>
</StandardBusinessDocument>
   

Wrapping ASiC archive as base64 encoded payload within StandardBusinessDocument

In order to transport an ASiC archive as payload within a StandardBusinessDocument (SBD), the payload must be base64 encoded.

/** Wraps the ASiC archive supplied in the "inputStream" into a SBD, with the supplied SBDH */
public void wrapSampleData(InputStream inputStream, StandardBusinessDocumentHeader standardBusinessDocumentHeader) throws Exception {
    SbdWrapper sbdWrapper = new SbdWrapper();

    File outputFile = File.createTempFile("vefa-sbdh", ".xml");
    FileOutputStream fileOutputStream = new FileOutputStream(outputFile);

    sbdWrapper.wrapInputStream(standardBusinessDocumentHeader, inputStream, fileOutputStream);
    log.debug("Wrote sample StandardBusinessDocument into " + outputFile.toString());
}

Please review the unit tests for further details and examples.

Extracting base64 encoded ASiC archive from SBD payload

Retrieving and decoding the base64 encoded ASiC archive from an SBD is easy:

/** Illustrates how to extract base64 encoded ASiC archive */
@Test(dataProvider = "sampleSbd", dataProviderClass = SampleDataProvider.class)
public void extractAsicArchiveFromPayload(InputStream inputStream) throws Exception {

    // Creates the extractor
    AsicExtractor asicExtractor = AsicExtractorFactory.defaultAsicExtractor();

    // Creates a temporary file to hold the results
    File asiceFile = File.createTempFile("vefa-sample-asic", ".asice");
    FileOutputStream fileOutputStream = new FileOutputStream(asiceFile);
    BufferedOutputStream outputStream = new BufferedOutputStream(fileOutputStream);

    // Performs the actual extraction
    asicExtractor.extractAsic(inputStream, outputStream);

    inputStream.close();
    outputStream.close();
}

Please review the unit tests for further details and examples.

Extracting the SBDH only from SBD with large payload

Extracting the SBDH (the SBD Header) from a really large StandardBusinessDocument (due to base64 encoded payload), is shown below. Note that the parser will not parse the entire document, i.e. read all the bytes. Only the SBDH will be extracted and parse.

public void parseSampleSbdhFromLargeStandardBusinessDocument(InputStream sbdInputStream) throws Exception {

    // Creates a parser, which will extract the SBDH from a really large xml file
    SbdhParser sbdhParser = SbdhParserFactory.sbdhParserAndExtractor();

    // Performs the actual parsing
    StandardBusinessDocumentHeader standardBusinessDocumentHeader = sbdhParser.parse(sbdInputStream);

    // Ensures that we got something
    assertNotNull(standardBusinessDocumentHeader);
}

Please review the unit tests for further details and examples.

vefa-sbdh's People

Contributors

klakegg avatar steinarcook avatar glennbech avatar

Watchers

Jerry Dimitriou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.