private Datastream addInlineDatastreamVersion(Feed feed, Entry entry, DigitalObject obj, String encoding, File tempDir) throws ObjectIntegrityException, StreamIOException { DatastreamXMLMetadata ds = new DatastreamXMLMetadata(); setDSCommonProperties(ds, obj, entry, feed); String dsId = ds.DatastreamID; String dsvId = ds.DSVersionID; addAuditDatastream(obj, entry, encoding, tempDir); } else { try { if (m_format.equals(ATOM_ZIP1_1)) { File entryContent = getContentSrcAsFile(entry.getContentSrc(), tempDir); ByteBuffer byteBuffer = ByteBuffer.allocate((int)entryContent.length()); FileUtils.copy(new FileInputStream(entryContent), ds.DSMIME = mimeType.toString(); setDatastreamVersionChecksumProperties(ds, obj, entry); return ds;
private void addDatastreams(Feed feed, DigitalObject obj, String encoding, int transContext, File tempDir) throws UnsupportedEncodingException, StreamIOException, ObjectIntegrityException { feed.sortEntries(new UpdatedIdComparator(true)); List<Entry> entries = feed.getEntries(); for (Entry entry : entries) { if (ThreadHelper.getInReplyTo(entry) != null) { addDatastreamVersion(feed, entry, obj, encoding, transContext, tempDir); } } }
Feed feed = feedDoc.getRoot(); addObjectProperties(feed, obj); addDatastreams(feed, obj, encoding, transContext, tempDir);
private void addDatastreamVersion(Feed feed, Entry entry, DigitalObject obj, String encoding, int transContext, File tempDir) throws UnsupportedEncodingException, StreamIOException, ObjectIntegrityException { IRI ref = ThreadHelper.getInReplyTo(entry).getRef(); Entry parent = feed.getEntry(ref.toString()); Datastream ds; String controlGroup = getDSControlGroup(obj, parent); if (controlGroup.equals("X")) { ds = addInlineDatastreamVersion(feed, entry, obj, encoding, tempDir); } else if (controlGroup.equals("M")) { ds = addManagedDatastreamVersion(obj, entry, feed, encoding, transContext, tempDir); } else { try { ds = addExternalReferencedDatastreamVersion(obj, entry, feed, transContext); } catch (IOException e) { throw new StreamIOException(e.getMessage(), e); } } obj.addDatastreamVersion(ds, true); }
throws StreamIOException, ObjectIntegrityException { Datastream ds = new DatastreamManagedContent(); setDSCommonProperties(ds, obj, entry, feed); ds.DSLocationType = Datastream.DS_LOCATION_TYPE_INTERNAL; ds.DSMIME = getDSMimeType(entry); if (!contentLocation.isAbsolute() && !contentLocation.isPathAbsolute()) { try { File f = getContentSrcAsFile(contentLocation, tempDir); contentLocation = new IRI(DatastreamManagedContent.TEMP_SCHEME + f.getAbsolutePath()); (m_translator.normalizeDSLocationURLs(obj .getPid(), ds, transContext)).DSLocation; setDatastreamVersionChecksumProperties(ds, obj, entry); return ds;
public TestAtomDODeserializer(DODeserializer deserializer, DOSerializer serializer) { super(deserializer, serializer); m_zip_serializer = new AtomDOSerializer(AtomDODeserializer.ATOM_ZIP1_1, translationUtility()); m_zip_deserializer = new AtomDODeserializer(AtomDODeserializer.ATOM_ZIP1_1, translationUtility()); }
private void addAuditDatastream(DigitalObject obj, Entry entry, String encoding, File tempDir) throws ObjectIntegrityException, StreamIOException { try { Reader auditTrail; if (m_format.equals(ATOM_ZIP1_1)) { File f = getContentSrcAsFile(entry.getContentSrc(), tempDir); auditTrail = new InputStreamReader(new FileInputStream(f), encoding); } else { auditTrail = new StringReader(entry.getContent()); } obj.getAuditRecords().addAll(DOTranslationUtility .getAuditRecords(auditTrail)); auditTrail.close(); } catch (XMLStreamException e) { throw new ObjectIntegrityException(e.getMessage(), e); } catch (IOException e) { throw new StreamIOException(e.getMessage(), e); } }
@Test public void testDeserializeWithAutoChecksum() throws Exception { Datastream.defaultChecksumType = "MD5"; Datastream.autoChecksum = true; byte[] demo1001ATOMZip = get_demo1001_zip(); InputStream in = new ByteArrayInputStream(demo1001ATOMZip); DigitalObject obj = new BasicDigitalObject(); m_zip_deserializer.deserialize(in, obj, "UTF-8", DOTranslationUtility.DESERIALIZE_INSTANCE); assertEquals("demo:1001", obj.getPid()); assertEquals(true, Datastream.autoChecksum); // RELS-EXT is not marked, so should default String id = "RELS-EXT"; for (Datastream version : obj.datastreams(id)) { System.out.println("Test object was: " + obj.getPid()); assertEquals(obj.getPid() + "/" + id + " did not have expected CS type", Datastream.getDefaultChecksumType(), version.DSChecksumType); assertEquals(32, version.getChecksum().length()); } }
private void addDatastreamVersion(Feed feed, Entry entry, DigitalObject obj, String encoding, int transContext, File tempDir) throws UnsupportedEncodingException, StreamIOException, ObjectIntegrityException { IRI ref = ThreadHelper.getInReplyTo(entry).getRef(); Entry parent = feed.getEntry(ref.toString()); Datastream ds; String controlGroup = getDSControlGroup(obj, parent); if (controlGroup.equals("X")) { ds = addInlineDatastreamVersion(feed, entry, obj, encoding, tempDir); } else if (controlGroup.equals("M")) { ds = addManagedDatastreamVersion(obj, entry, feed, encoding, transContext, tempDir); } else { try { ds = addExternalReferencedDatastreamVersion(obj, entry, feed, transContext); } catch (IOException e) { throw new StreamIOException(e.getMessage(), e); } } obj.addDatastreamVersion(ds, true); }
throws StreamIOException, ObjectIntegrityException { Datastream ds = new DatastreamManagedContent(); setDSCommonProperties(ds, obj, entry, feed); ds.DSLocationType = Datastream.DS_LOCATION_TYPE_INTERNAL; ds.DSMIME = getDSMimeType(entry); if (!contentLocation.isAbsolute() && !contentLocation.isPathAbsolute()) { try { File f = getContentSrcAsFile(contentLocation, tempDir); contentLocation = new IRI(DatastreamManagedContent.TEMP_SCHEME + f.getAbsolutePath()); (m_translator.normalizeDSLocationURLs(obj .getPid(), ds, transContext)).DSLocation; setDatastreamVersionChecksumProperties(ds, obj, entry); return ds;
public TestAtomDODeserializer() { this(new AtomDODeserializer(AtomDODeserializer.DEFAULT_FORMAT, translationUtility()), new AtomDOSerializer(AtomDODeserializer.DEFAULT_FORMAT, translationUtility())); }
private void addAuditDatastream(DigitalObject obj, Entry entry, String encoding, File tempDir) throws ObjectIntegrityException, StreamIOException { try { Reader auditTrail; if (m_format.equals(ATOM_ZIP1_1)) { File f = getContentSrcAsFile(entry.getContentSrc(), tempDir); auditTrail = new InputStreamReader(new FileInputStream(f), encoding); } else { auditTrail = new StringReader(entry.getContent()); } obj.getAuditRecords().addAll(DOTranslationUtility .getAuditRecords(auditTrail)); auditTrail.close(); } catch (XMLStreamException e) { throw new ObjectIntegrityException(e.getMessage(), e); } catch (IOException e) { throw new StreamIOException(e.getMessage(), e); } }
@Test public void testDeserializeWithoutAutoChecksum() throws Exception { Datastream.defaultChecksumType = "DISABLED"; Datastream.autoChecksum = false; byte[] demo1001ATOMZip = get_demo1001_zip(); InputStream in = new ByteArrayInputStream(demo1001ATOMZip); DigitalObject obj = new BasicDigitalObject(); m_zip_deserializer.deserialize(in, obj, "UTF-8", DOTranslationUtility.DESERIALIZE_INSTANCE); assertEquals("demo:1001", obj.getPid()); assertEquals(false, Datastream.autoChecksum); String id = "RELS-EXT"; for (Datastream version : obj.datastreams(id)) { System.out.println("Test object was: " + obj.getPid()); assertEquals(obj.getPid() + "/" + id + " did not have expected CS type", Datastream.CHECKSUMTYPE_DISABLED, version.DSChecksumType); assertEquals(Datastream.CHECKSUM_NONE, version.getChecksum()); } }
private Datastream addInlineDatastreamVersion(Feed feed, Entry entry, DigitalObject obj, String encoding, File tempDir) throws ObjectIntegrityException, StreamIOException { DatastreamXMLMetadata ds = new DatastreamXMLMetadata(); setDSCommonProperties(ds, obj, entry, feed); String dsId = ds.DatastreamID; String dsvId = ds.DSVersionID; addAuditDatastream(obj, entry, encoding, tempDir); } else { try { if (m_format.equals(ATOM_ZIP1_1)) { File entryContent = getContentSrcAsFile(entry.getContentSrc(), tempDir); ByteBuffer byteBuffer = ByteBuffer.allocate((int)entryContent.length()); FileUtils.copy(new FileInputStream(entryContent), ds.DSMIME = mimeType.toString(); setDatastreamVersionChecksumProperties(ds, obj, entry); return ds;
Feed feed = feedDoc.getRoot(); addObjectProperties(feed, obj); addDatastreams(feed, obj, encoding, transContext, tempDir);
private void addDatastreams(Feed feed, DigitalObject obj, String encoding, int transContext, File tempDir) throws UnsupportedEncodingException, StreamIOException, ObjectIntegrityException { feed.sortEntries(new UpdatedIdComparator(true)); List<Entry> entries = feed.getEntries(); for (Entry entry : entries) { if (ThreadHelper.getInReplyTo(entry) != null) { addDatastreamVersion(feed, entry, obj, encoding, transContext, tempDir); } } }