Search in sources :

Example 1 with YamlConfiguration

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

the class YamlSipIngester method run.

private void run(String rootPath) throws IOException {
    System.out.printf("%nSample 3: Assemble SIP from %s and ingest into InfoArchive%n", rootPath);
    // Load the configuration
    YamlConfiguration configuration = new YamlConfiguration(new File(rootPath, "configuration.yml"));
    // Tell InfoArchive where and how to archive the data
    URI entityUri = URI.create(configuration.getPdiSchemaName());
    String entityName = "animal";
    PackagingInformation prototype = PackagingInformation.builder().dss().application(configuration.getApplicationName()).holding(configuration.getHoldingName()).producer("SIP-SDK").entity(entityName).schema(entityUri.toString()).end().build();
    // Define a mapping from our domain object to the PDI XML
    XmlPdiAssembler<File> pdiAssembler;
    try (InputStream schema = new StringStream(configuration.getPdiSchema())) {
        pdiAssembler = new XmlPdiAssembler<File>(entityUri, entityName, schema) {

            @Override
            protected void doAdd(File value, Map<String, ContentInfo> ignored) {
                String name = value.getName();
                getBuilder().element("animal_name", name.substring(0, name.lastIndexOf('.'))).element("file_path", relativePath(value, rootPath));
            }
        };
    }
    DigitalObjectsExtraction<File> contentAssembler = file -> Collections.singleton(DigitalObject.fromFile(relativePath(file, rootPath), file)).iterator();
    // Assemble the SIP
    SipAssembler<File> sipAssembler = SipAssembler.forPdiAndContent(prototype, pdiAssembler, contentAssembler);
    FileGenerator<File> generator = new FileGenerator<>(sipAssembler, FileSupplier.fromTemporaryDirectory());
    File f1 = new File(rootPath, "ape.dat");
    File f2 = new File(rootPath, "bear.dat");
    File f3 = new File(rootPath, "cobra.dat");
    FileGenerationMetrics metrics = generator.generate(Arrays.asList(f1, f2, f3));
    File assembledSip = metrics.getFile();
    // Get an ArchiveClient instance to interact with InfoArchive.
    // In this case, we start with a blank installation, and create a sample holding from scratch that will contain
    // the SIP we've just assembled.
    // Use ArchiveClients.usingAlreadyConfiguredServer() instead if you already configured the server with application,
    // holding, etc.
    ArchiveClient archiveClient = ArchiveClients.configuringApplicationUsing(new YamlBasedApplicationConfigurer(configuration), newArchiveConnection(rootPath));
    // Ingest the SIP into InfoArchive
    try (InputStream sip = Files.newInputStream(assembledSip.toPath(), StandardOpenOption.READ)) {
        String aipId = archiveClient.ingestDirect(sip);
        System.out.println("  SIP ingested as AIP " + aipId);
    }
}
Also used : YamlBasedApplicationConfigurer(com.opentext.ia.sdk.server.configuration.yaml.YamlBasedApplicationConfigurer) XmlPdiAssembler(com.opentext.ia.sdk.sip.XmlPdiAssembler) Arrays(java.util.Arrays) ArchiveClients(com.opentext.ia.sdk.client.factory.ArchiveClients) PackagingInformation(com.opentext.ia.sdk.sip.PackagingInformation) FileGenerationMetrics(com.opentext.ia.sdk.sip.FileGenerationMetrics) FileSupplier(com.opentext.ia.sdk.support.io.FileSupplier) StringUtils(org.apache.commons.lang3.StringUtils) YamlConfiguration(com.opentext.ia.yaml.configuration.YamlConfiguration) InfoArchiveConnectionProperties(com.opentext.ia.sdk.server.configuration.InfoArchiveConnectionProperties) Map(java.util.Map) DigitalObjectsExtraction(com.opentext.ia.sdk.sip.DigitalObjectsExtraction) URI(java.net.URI) PropertiesBasedArchiveConnection(com.opentext.ia.sdk.server.configuration.PropertiesBasedArchiveConnection) Properties(java.util.Properties) DigitalObject(com.opentext.ia.sdk.sip.DigitalObject) Files(java.nio.file.Files) StandardOpenOption(java.nio.file.StandardOpenOption) ArchiveClient(com.opentext.ia.sdk.client.api.ArchiveClient) IOException(java.io.IOException) File(java.io.File) ArchiveConnection(com.opentext.ia.sdk.client.api.ArchiveConnection) ContentInfo(com.opentext.ia.sdk.sip.ContentInfo) SipAssembler(com.opentext.ia.sdk.sip.SipAssembler) StringStream(com.opentext.ia.sdk.support.io.StringStream) FileGenerator(com.opentext.ia.sdk.sip.FileGenerator) Paths(java.nio.file.Paths) Collections(java.util.Collections) InputStream(java.io.InputStream) FileGenerator(com.opentext.ia.sdk.sip.FileGenerator) InputStream(java.io.InputStream) YamlConfiguration(com.opentext.ia.yaml.configuration.YamlConfiguration) URI(java.net.URI) StringStream(com.opentext.ia.sdk.support.io.StringStream) YamlBasedApplicationConfigurer(com.opentext.ia.sdk.server.configuration.yaml.YamlBasedApplicationConfigurer) FileGenerationMetrics(com.opentext.ia.sdk.sip.FileGenerationMetrics) ContentInfo(com.opentext.ia.sdk.sip.ContentInfo) File(java.io.File) ArchiveClient(com.opentext.ia.sdk.client.api.ArchiveClient) PackagingInformation(com.opentext.ia.sdk.sip.PackagingInformation)

Aggregations

ArchiveClient (com.opentext.ia.sdk.client.api.ArchiveClient)1 ArchiveConnection (com.opentext.ia.sdk.client.api.ArchiveConnection)1 ArchiveClients (com.opentext.ia.sdk.client.factory.ArchiveClients)1 InfoArchiveConnectionProperties (com.opentext.ia.sdk.server.configuration.InfoArchiveConnectionProperties)1 PropertiesBasedArchiveConnection (com.opentext.ia.sdk.server.configuration.PropertiesBasedArchiveConnection)1 YamlBasedApplicationConfigurer (com.opentext.ia.sdk.server.configuration.yaml.YamlBasedApplicationConfigurer)1 ContentInfo (com.opentext.ia.sdk.sip.ContentInfo)1 DigitalObject (com.opentext.ia.sdk.sip.DigitalObject)1 DigitalObjectsExtraction (com.opentext.ia.sdk.sip.DigitalObjectsExtraction)1 FileGenerationMetrics (com.opentext.ia.sdk.sip.FileGenerationMetrics)1 FileGenerator (com.opentext.ia.sdk.sip.FileGenerator)1 PackagingInformation (com.opentext.ia.sdk.sip.PackagingInformation)1 SipAssembler (com.opentext.ia.sdk.sip.SipAssembler)1 XmlPdiAssembler (com.opentext.ia.sdk.sip.XmlPdiAssembler)1 FileSupplier (com.opentext.ia.sdk.support.io.FileSupplier)1 StringStream (com.opentext.ia.sdk.support.io.StringStream)1 YamlConfiguration (com.opentext.ia.yaml.configuration.YamlConfiguration)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1