Search in sources :

Example 1 with PropertiesBasedConfigurer

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

the class WhenUsingInfoArchive method shouldRetryWhenTemporarilyUnavailable.

@Test
public void shouldRetryWhenTemporarilyUnavailable() throws IOException {
    configuration.put(InfoArchiveConfiguration.FEDERATION_NAME, randomString());
    when(restClient.createCollectionItem(eq(federations), any(XdbFederation.class), eq(LINK_ADD), eq(LINK_SELF))).then(invocation -> {
        throw new HttpException(503, "");
    });
    ArchiveClients.configuringServerUsing(new PropertiesBasedConfigurer(configuration, restClient, mock(Clock.class)), restClient);
    verify(restClient, times(5)).createCollectionItem(eq(federations), any(XdbFederation.class), eq(LINK_ADD), eq(LINK_SELF));
}
Also used : PropertiesBasedConfigurer(com.opentext.ia.sdk.server.configuration.PropertiesBasedConfigurer) Test(org.junit.Test)

Example 2 with PropertiesBasedConfigurer

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

the class SipIngester method run.

@SuppressWarnings("PMD.SystemPrintln")
private void run(String rootPath) throws IOException {
    // Tell InfoArchive where and how to archive the data
    URI entityUri = URI.create(SAMPLE_NAMESPACE);
    String entityName = "animal";
    PackagingInformation prototype = PackagingInformation.builder().dss().application(SAMPLE_HOLDING).holding(SAMPLE_HOLDING).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 = getClass().getResourceAsStream('/' + SAMPLE_SCHEMA)) {
        pdiAssembler = new XmlPdiAssembler<File>(entityUri, entityName, schema) {

            @Override
            protected void doAdd(File value, Map<String, ContentInfo> ignored) {
                getBuilder().element("animal_name", value.getName().substring(0, value.getName().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(SAMPLE_FILES_PATH, "ape.dat");
    File f2 = new File(SAMPLE_FILES_PATH, "bear.dat");
    File f3 = new File(SAMPLE_FILES_PATH, "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.configuringServerUsing(new PropertiesBasedConfigurer(sampleHoldingConfiguration()));
    // Ingest the SIP into InfoArchive
    try (InputStream sip = new FileInputStream(assembledSip)) {
        String aipId = archiveClient.ingestDirect(sip);
        System.out.println("SIP ingested as AIP " + aipId);
    }
}
Also used : PropertiesBasedConfigurer(com.opentext.ia.sdk.server.configuration.PropertiesBasedConfigurer) InfoArchiveConfiguration(com.opentext.ia.sdk.server.configuration.InfoArchiveConfiguration) java.util(java.util) ArchiveClients(com.opentext.ia.sdk.client.factory.ArchiveClients) ArchiveClient(com.opentext.ia.sdk.client.api.ArchiveClient) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FileSupplier(com.opentext.ia.sdk.support.io.FileSupplier) File(java.io.File) IOUtils(org.apache.commons.io.IOUtils) com.opentext.ia.sdk.sip(com.opentext.ia.sdk.sip) URI(java.net.URI) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PropertiesBasedConfigurer(com.opentext.ia.sdk.server.configuration.PropertiesBasedConfigurer) URI(java.net.URI) FileInputStream(java.io.FileInputStream) File(java.io.File) ArchiveClient(com.opentext.ia.sdk.client.api.ArchiveClient)

Aggregations

PropertiesBasedConfigurer (com.opentext.ia.sdk.server.configuration.PropertiesBasedConfigurer)2 ArchiveClient (com.opentext.ia.sdk.client.api.ArchiveClient)1 ArchiveClients (com.opentext.ia.sdk.client.factory.ArchiveClients)1 InfoArchiveConfiguration (com.opentext.ia.sdk.server.configuration.InfoArchiveConfiguration)1 com.opentext.ia.sdk.sip (com.opentext.ia.sdk.sip)1 FileSupplier (com.opentext.ia.sdk.support.io.FileSupplier)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 java.util (java.util)1 IOUtils (org.apache.commons.io.IOUtils)1 Test (org.junit.Test)1