@Test public void calculateFixityTest() throws Exception { String origSrc = ""; if (sampleFilePath.contains(":/")) { origSrc = "file://" + sampleFilePath; } else { origSrc = "file:///" + sampleFilePath; } Dcp sip = new Dcp(); DcsFile file = new DcsFile(); file.setId("example:/file"); file.setSource(origSrc); file.setExtant(true); sip.addFile(file); String id = ingest.getSipStager().addSIP(sip); ExternalContentStager ecs = new ExternalContentStager(); ecs.setAlwaysCalculateFixityFor("SHA-1"); ecs.setIngestFramework(ingest); ecs.execute(id); sip = ingest.getSipStager().getSIP(id); DcsFile retrieved = sip.getFiles().iterator().next(); String stagedSipRef = ingest.getFileContentStager().get(retrieved.getSource()).getSipRef(); DcsFile stagedFile = ingest.getSipStager().getSIP(stagedSipRef).getFiles().iterator().next(); Assert.assertEquals(1, stagedFile.getFixity().size()); DcsEvent digestEvent = ingest.getEventManager().getEventByType(stagedSipRef, Events.FIXITY_DIGEST); Assert.assertNotNull(digestEvent); for (DcsEntityReference er : digestEvent.getTargets()) { Assert.assertEquals(stagedFile.getId(), er.getRef()); } }
@Test public void downloadEventTest() throws Exception { String origSrc = ""; if (sampleFilePath.contains(":/")) { origSrc = "file://" + sampleFilePath; } else { origSrc = "file:///" + sampleFilePath; } Dcp sip = new Dcp(); DcsFile file = new DcsFile(); file.setId("example:/file"); file.setSource(origSrc); file.setExtant(true); sip.addFile(file); String id = ingest.getSipStager().addSIP(sip); ExternalContentStager ecs = new ExternalContentStager(); ecs.setIngestFramework(ingest); ecs.execute(id); sip = ingest.getSipStager().getSIP(id); DcsFile retrieved = sip.getFiles().iterator().next(); String stagedSipRef = ingest.getFileContentStager().get(retrieved.getSource()).getSipRef(); DcsFile stagedFile = ingest.getSipStager().getSIP(stagedSipRef).getFiles().iterator().next(); DcsEvent upload = ingest.getEventManager().getEventByType(stagedSipRef, Events.FILE_DOWNLOAD); Assert.assertNotNull(upload); for (DcsEntityReference er : upload.getTargets()) { Assert.assertEquals(stagedFile.getId(), er.getRef()); } }
@Override protected boolean checkMetadataReferenceExists( String depositId, IngestWorkflowState state, String reference) { try { if (!checkProjectExists(reference)) { if (!checkCollectionExists(reference)) { if (!checkDataItemExists(reference)) { DcsEvent event = state.getEventManager().newEvent(Package.Events.INGEST_FAIL); String stackTrace = ""; for (StackTraceElement st : Thread.currentThread().getStackTrace()) { stackTrace += st + "\n"; } event.setDetail(stackTrace); event.setOutcome("Package Missing external reference: " + reference); List<DcsEntityReference> refs = new ArrayList<DcsEntityReference>(); DcsEntityReference ref = new DcsEntityReference(reference); refs.add(ref); event.setTargets(refs); state.getEventManager().addEvent(depositId, event); return false; } } } } catch (Exception e) { DcsEvent event = state.getEventManager().newEvent(Package.Events.INGEST_FAIL); event.setDetail(e.getStackTrace().toString()); event.setOutcome( "Failed to validate external reference: " + reference + " " + e.getMessage()); List<DcsEntityReference> refs = new ArrayList<DcsEntityReference>(); DcsEntityReference ref = new DcsEntityReference(reference); refs.add(ref); event.setTargets(refs); state.getEventManager().addEvent(depositId, event); return false; } return true; }
@Override protected boolean checkReferenceExists( String depositId, IngestWorkflowState state, String reference, String expectedReferenceType) { boolean found = false; /*This service only handles references to external objects. * So any references that don't start with http should be passed through. These will be checked by the internal * reference checker.*/ if (!reference.startsWith("http:")) { return true; } try { if (expectedReferenceType.equalsIgnoreCase("project")) { found = checkProjectExists(reference); } else if (expectedReferenceType.equalsIgnoreCase("collection")) { found = checkCollectionExists(reference); } else if (expectedReferenceType.equalsIgnoreCase("dataItem")) { found = checkDataItemExists(reference); } else if (expectedReferenceType.equalsIgnoreCase("file")) { found = checkFileExists(reference); } else if (expectedReferenceType.equalsIgnoreCase("collection|project")) { if (idService.fromUrl(new URL(reference)).getType() == Types.COLLECTION.getTypeName()) { found = checkCollectionExists(reference); } else { found = checkProjectExists(reference); } } if (!found) { DcsEvent event = state.getEventManager().newEvent(Package.Events.INGEST_FAIL); String stackTrace = ""; for (StackTraceElement st : Thread.currentThread().getStackTrace()) { stackTrace += st + "\n"; } event.setDetail(stackTrace); event.setOutcome("Package Missing external reference: " + reference); List<DcsEntityReference> refs = new ArrayList<DcsEntityReference>(); DcsEntityReference ref = new DcsEntityReference(reference); refs.add(ref); event.setTargets(refs); state.getEventManager().addEvent(depositId, event); return false; } } catch (Exception e) { DcsEvent event = state.getEventManager().newEvent(Package.Events.INGEST_FAIL); event.setDetail(e.getStackTrace().toString()); event.setOutcome( "Failed to validate external reference: " + reference + " " + e.getMessage()); List<DcsEntityReference> refs = new ArrayList<DcsEntityReference>(); DcsEntityReference ref = new DcsEntityReference(reference); refs.add(ref); event.setTargets(refs); state.getEventManager().addEvent(depositId, event); return false; } return found; }