Search in sources :

Example 6 with XmlPdiAssembler

use of com.opentext.ia.sdk.sip.XmlPdiAssembler in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class MultipleDomainObjects method run.

private void run() throws IOException {
    System.out.println("\nSample 6: Assembling multiple domain object types into a single PDI");
    // Assembler for PDI, where the domain object is flexible
    PdiAssembler<Aiu> pdiAssembler = new XmlPdiAssembler<Aiu>(NAMESPACE, "aiu") {

        @Override
        protected void doAdd(Aiu aiu, Map<String, ContentInfo> ignored) {
            aiu.addTo(getBuilder());
        }
    };
    // Collect the PDI XML in an in-memory buffer. For large PDIs, use a FileBuffer instead.
    DataBuffer dataBuffer = new MemoryBuffer();
    pdiAssembler.start(dataBuffer);
    try {
        // Assemble the PDI by adding domain objects to it.
        // In this sample, the domain objects are flexible objects
        pdiAssembler.add(wrapDomainObject(new Animal("Gnu")));
        pdiAssembler.add(wrapDomainObject(new Person("Remon", "Sinnema")));
    } finally {
        pdiAssembler.end();
    }
    try (InputStream pdi = dataBuffer.openForReading()) {
        System.out.println(IOUtils.toString(pdi, StandardCharsets.UTF_8));
    }
}
Also used : MemoryBuffer(com.opentext.ia.sdk.support.io.MemoryBuffer) XmlPdiAssembler(com.opentext.ia.sdk.sip.XmlPdiAssembler) InputStream(java.io.InputStream) Map(java.util.Map) DataBuffer(com.opentext.ia.sdk.support.io.DataBuffer)

Example 7 with XmlPdiAssembler

use of com.opentext.ia.sdk.sip.XmlPdiAssembler in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class HelloSip method run.

private void run() throws IOException {
    System.out.println("\nSample 1: Creating our first SIP");
    // Tell InfoArchive where and how to archive the data
    URI entityUri = URI.create("urn:com.opentext.ia.sdk.sample.greeting:1.0");
    String entityName = "greeting";
    PackagingInformation prototype = PackagingInformation.builder().dss().application("greetingApplication").holding("greetingHolding").producer("world").entity(entityName).schema(entityUri.toString()).end().build();
    // Define a mapping from our domain object to the PDI XML
    PdiAssembler<Greeting> pdiAssembler = new XmlPdiAssembler<Greeting>(entityUri, entityName) {

        @Override
        protected void doAdd(Greeting greeting, Map<String, ContentInfo> ignored) {
            getBuilder().element("message", greeting.getMessage());
        }
    };
    // Assemble the SIP
    SipAssembler<Greeting> sipAssembler = SipAssembler.forPdi(prototype, pdiAssembler);
    FileGenerator<Greeting> generator = new FileGenerator<>(sipAssembler, () -> new File("hello-sip.zip"));
    Greeting greeting = new Greeting("Hello, SIP");
    SipMetrics metrics = (SipMetrics) generator.generate(greeting).getMetrics();
    long numAius = metrics.numAius();
    System.out.printf("  Added %d %s to SIP of %d bytes in %d ms%n", numAius, English.plural("AIU", (int) numAius), metrics.sipFileSize(), metrics.assemblyTime());
}
Also used : FileGenerator(com.opentext.ia.sdk.sip.FileGenerator) URI(java.net.URI) XmlPdiAssembler(com.opentext.ia.sdk.sip.XmlPdiAssembler) Map(java.util.Map) File(java.io.File) PackagingInformation(com.opentext.ia.sdk.sip.PackagingInformation) SipMetrics(com.opentext.ia.sdk.sip.SipMetrics)

Aggregations

XmlPdiAssembler (com.opentext.ia.sdk.sip.XmlPdiAssembler)7 Map (java.util.Map)7 InputStream (java.io.InputStream)5 DataBuffer (com.opentext.ia.sdk.support.io.DataBuffer)4 MemoryBuffer (com.opentext.ia.sdk.support.io.MemoryBuffer)4 PackagingInformation (com.opentext.ia.sdk.sip.PackagingInformation)3 File (java.io.File)3 URI (java.net.URI)3 ContentInfo (com.opentext.ia.sdk.sip.ContentInfo)2 DigitalObject (com.opentext.ia.sdk.sip.DigitalObject)2 DigitalObjectsExtraction (com.opentext.ia.sdk.sip.DigitalObjectsExtraction)2 FileGenerator (com.opentext.ia.sdk.sip.FileGenerator)2 SipAssembler (com.opentext.ia.sdk.sip.SipAssembler)2 SipMetrics (com.opentext.ia.sdk.sip.SipMetrics)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Collections (java.util.Collections)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1