use of com.opentext.ia.sdk.sip.SipMetrics in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class FileArchiver method run.
private void run(String rootPath, String sip) throws IOException {
File sipFile = new File(sip).getCanonicalFile();
if (!sipFile.getParentFile().mkdirs() && !sipFile.getParentFile().isDirectory()) {
throw new IllegalStateException("Could not create all required directories in path " + sipFile.getParentFile().getAbsolutePath());
}
System.out.printf("%nSample 2: Archiving files from %s into %s%n", rootPath, sipFile.getPath());
// Tell InfoArchive where and how to archive the data
URI entityUri = URI.create("urn:com.opentext.ia.sdk.sample.file:1.0");
String entityName = "file";
PackagingInformation prototype = PackagingInformation.builder().dss().application("fileApplication").holding("fileHolding").producer("SIP SDK").entity(entityName).schema(entityUri.toString()).end().build();
// Define a mapping from our domain object to the PDI XML
PdiAssembler<File> pdiAssembler = new XmlPdiAssembler<File>(entityUri, entityName) {
@Override
protected void doAdd(File file, Map<String, ContentInfo> contentInfo) {
try {
String path = relativePath(file, rootPath);
getBuilder().element("path", path).element("size", Long.toString(file.length())).element("permissions", permissionsOf(file)).element("contentType", Files.probeContentType(file.toPath())).elements("hashes", "hash", contentInfo.get(path).getContentHashes(), (hash, builder) -> {
builder.attribute("algorithm", hash.getHashFunction()).attribute("encoding", hash.getEncoding()).attribute("value", hash.getValue());
});
} catch (IOException e) {
throw new RuntimeIoException(e);
}
}
};
DigitalObjectsExtraction<File> contentAssembler = file -> Collections.singleton(DigitalObject.fromFile(relativePath(file, rootPath), file)).iterator();
HashAssembler contentHashAssembler = new SingleHashAssembler(HashFunction.SHA256, Encoding.BASE64);
// Assemble the SIP
SipAssembler<File> assembler = SipAssembler.forPdiAndContentWithContentHashing(prototype, pdiAssembler, contentAssembler, contentHashAssembler);
assembler.start(new FileBuffer(sipFile));
try {
addFilesIn(new File(rootPath), rootPath, relativePath(sipFile, rootPath), assembler);
} finally {
assembler.end();
}
// Show metrics about the assembly process
SipMetrics metrics = assembler.getMetrics();
System.out.printf(" Added %d files to SIP of %d bytes in %d ms%n", metrics.numDigitalObjects(), metrics.sipFileSize(), metrics.assemblyTime());
}
use of com.opentext.ia.sdk.sip.SipMetrics 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());
}
Aggregations