@Test public void fileUriTest() 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(); Assert.assertTrue(origSrc != retrieved.getSource()); Assert.assertTrue(ingest.getFileContentStager().contains(retrieved.getSource())); }
@Test public void untouchedNonExtantFileUriTest() throws Exception { String origSrc = "file://" + sampleFilePath; Dcp sip = new Dcp(); DcsFile file = new DcsFile(); file.setId("example:/file"); file.setSource(origSrc); file.setExtant(false); 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(); Assert.assertEquals(origSrc, retrieved.getSource()); Assert.assertFalse(ingest.getFileContentStager().contains(retrieved.getSource())); }
@Test public void untouchedStagedFileTest() throws Exception { StagedFile staged = ingest.getFileContentStager().add(IOUtils.toInputStream("stagedContent"), null); Dcp sip = new Dcp(); DcsFile file = new DcsFile(); file.setId("example:/file"); file.setSource(staged.getReferenceURI()); 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(); Assert.assertEquals(staged.getReferenceURI(), retrieved.getSource()); }
@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()); } }
public static SolrInputDocument indexMetadataFile( SolrInputDocument doc, Collection<DcsMetadataRef> set, List<SolrInputDocument> docs) { int foundFgdc = 0; // Assuming the DCS file is available in the Sip for (DcsMetadataRef ref : set) { DcsFile file = null; for (SolrInputDocument document : docs) { String refStr = ref.getRef(); String id = (String) document.getFieldValue(EntityField.ID.solrName()); if (refStr.equals(id)) try { file = (DcsFile) fromSolr(toSolrDocument(document)); } catch (IOException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } } if (file == null) continue; // get the file from SIP or from index // DcsFile file = new DcsFile(); for (DcsFormat format : file.getFormats()) { if (format.getFormat().contains("fgdc")) { MetadataDocument fgdcDoc = null; try { String fileSource = file.getSource().replace("file://", ""); fgdcDoc = MetadataDocument.Factory.parse(new File(fileSource)); ThemeType[] keywords = fgdcDoc.getMetadata().getIdinfo().getKeywords().getThemeArray(); PlaceType[] places = fgdcDoc.getMetadata().getIdinfo().getKeywords().getPlaceArray(); Set<String> themes = new HashSet<String>(); for (ThemeType theme : keywords) { for (String themeStr : theme.getThemekeyArray()) themes.add(themeStr); } addStrings(doc, themes, CoreMetadataField.SUBJECT); Set<String> placeKeys = new HashSet<String>(); for (PlaceType place : places) { for (String placeStr : place.getPlacekeyArray()) placeKeys.add(placeStr); } addStrings(doc, placeKeys, SeadSolrField.DeliverableUnitField.LOCATION); } catch (XmlException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (IOException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } foundFgdc = 1; } if (foundFgdc == 1) break; } if (foundFgdc == 1) break; } return doc; }