diff --git a/src/main/java/edu/unc/lib/boxc/migration/cdm/SipsCommand.java b/src/main/java/edu/unc/lib/boxc/migration/cdm/SipsCommand.java index a7e30191..d3ed1127 100644 --- a/src/main/java/edu/unc/lib/boxc/migration/cdm/SipsCommand.java +++ b/src/main/java/edu/unc/lib/boxc/migration/cdm/SipsCommand.java @@ -8,6 +8,8 @@ import java.util.List; import edu.unc.lib.boxc.migration.cdm.services.AggregateFileMappingService; +import edu.unc.lib.boxc.migration.cdm.services.CdmFieldService; +import edu.unc.lib.boxc.migration.cdm.services.StreamingMetadataService; import org.slf4j.Logger; import edu.unc.lib.boxc.migration.cdm.exceptions.MigrationException; @@ -46,6 +48,8 @@ public class SipsCommand { private CdmIndexService indexService; private AggregateFileMappingService aggregateTopMappingService; private AggregateFileMappingService aggregateBottomMappingService; + private CdmFieldService fieldService; + private StreamingMetadataService streamingMetadataService; private PIDMinter pidMinter; private PremisLoggerFactoryImpl premisLoggerFactory; private SipService sipService; @@ -135,6 +139,11 @@ private void initialize() throws IOException { aggregateBottomMappingService = new AggregateFileMappingService(true); aggregateBottomMappingService.setIndexService(indexService); aggregateBottomMappingService.setProject(project); + fieldService = new CdmFieldService(); + streamingMetadataService = new StreamingMetadataService(); + streamingMetadataService.setProject(project); + streamingMetadataService.setFieldService(fieldService); + streamingMetadataService.setIndexService(indexService); sipService = new SipService(); sipService.setIndexService(indexService); @@ -147,5 +156,6 @@ private void initialize() throws IOException { sipService.setChompbConfig(parentCommand.getChompbConfig()); sipService.setAggregateTopMappingService(aggregateTopMappingService); sipService.setAggregateBottomMappingService(aggregateBottomMappingService); + sipService.setStreamingMetadataService(streamingMetadataService); } } diff --git a/src/main/java/edu/unc/lib/boxc/migration/cdm/services/SipService.java b/src/main/java/edu/unc/lib/boxc/migration/cdm/services/SipService.java index 365eb2c4..c2e32583 100644 --- a/src/main/java/edu/unc/lib/boxc/migration/cdm/services/SipService.java +++ b/src/main/java/edu/unc/lib/boxc/migration/cdm/services/SipService.java @@ -72,6 +72,7 @@ public class SipService { private MigrationProject project; private ChompbConfigService.ChompbConfig chompbConfig; private PermissionsService permissionsService; + private StreamingMetadataService streamingMetadataService; private PIDMinter pidMinter; private CdmToDestMapper cdmToDestMapper = new CdmToDestMapper(); private WorkGeneratorFactory workGeneratorFactory; @@ -104,6 +105,7 @@ private void initDependencies(SipGenerationOptions options, Connection conn) thr workGeneratorFactory.setPostMigrationReportService(postMigrationReportService); workGeneratorFactory.setAggregateTopMappingService(aggregateTopMappingService); workGeneratorFactory.setAggregateBottomMappingService(aggregateBottomMappingService); + workGeneratorFactory.setStreamingMetadataService(streamingMetadataService); try { workGeneratorFactory.setPermissionsInfo(permissionsService.loadMappings(project)); } catch (NoSuchFileException e) { @@ -378,6 +380,10 @@ public void setPermissionsService(PermissionsService permissionsService) { this.permissionsService = permissionsService; } + public void setStreamingMetadataService(StreamingMetadataService streamingMetadataService) { + this.streamingMetadataService = streamingMetadataService; + } + public void setPidMinter(PIDMinter pidMinter) { this.pidMinter = pidMinter; } diff --git a/src/main/java/edu/unc/lib/boxc/migration/cdm/services/sips/WorkGenerator.java b/src/main/java/edu/unc/lib/boxc/migration/cdm/services/sips/WorkGenerator.java index a85b357c..e015bd26 100644 --- a/src/main/java/edu/unc/lib/boxc/migration/cdm/services/sips/WorkGenerator.java +++ b/src/main/java/edu/unc/lib/boxc/migration/cdm/services/sips/WorkGenerator.java @@ -4,6 +4,7 @@ import edu.unc.lib.boxc.deposit.impl.model.DepositModelHelpers; import edu.unc.lib.boxc.migration.cdm.exceptions.InvalidProjectStateException; import edu.unc.lib.boxc.migration.cdm.model.DestinationSipEntry; +import edu.unc.lib.boxc.migration.cdm.model.GroupMappingInfo; import edu.unc.lib.boxc.migration.cdm.model.PermissionsInfo; import edu.unc.lib.boxc.migration.cdm.model.SourceFilesInfo; import edu.unc.lib.boxc.migration.cdm.options.SipGenerationOptions; @@ -12,6 +13,7 @@ import edu.unc.lib.boxc.migration.cdm.services.PostMigrationReportService; import edu.unc.lib.boxc.migration.cdm.services.RedirectMappingService; import edu.unc.lib.boxc.migration.cdm.services.SipService; +import edu.unc.lib.boxc.migration.cdm.services.StreamingMetadataService; import edu.unc.lib.boxc.model.api.DatastreamType; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.model.api.ids.PIDMinter; @@ -36,6 +38,7 @@ import static edu.unc.lib.boxc.auth.api.AccessPrincipalConstants.PUBLIC_PRINC; import static edu.unc.lib.boxc.migration.cdm.util.CLIConstants.outputLogger; import static edu.unc.lib.boxc.model.api.DatastreamType.ORIGINAL_FILE; +import static org.apache.jena.rdf.model.ResourceFactory.createProperty; import static org.slf4j.LoggerFactory.getLogger; /** @@ -45,6 +48,9 @@ */ public class WorkGenerator { private static final Logger log = getLogger(WorkGenerator.class); + // use local streamingUrl property for now because Cdr.streamingUrl only exists in a feature branch + public static final Property streamingUrl = createProperty( + "http://cdr.unc.edu/definitions/model#streamingUrl"); protected PIDMinter pidMinter; protected RedirectMappingService redirectMappingService; protected SourceFilesInfo sourceFilesInfo; @@ -58,6 +64,7 @@ public class WorkGenerator { protected AccessFileService accessFileService; protected PostMigrationReportService postMigrationReportService; protected PermissionsInfo permissionsInfo; + protected StreamingMetadataService streamingMetadataService; protected String cdmId; protected String cdmCreated; @@ -175,6 +182,9 @@ protected PID addFileObject(String cdmId, String cdmFileCreated, SourceFilesInfo // Add permission to source file addFilePermission(cdmId, fileObjResc); + // Add streamingUrl + addStreamingMetadata(cdmId, fileObjResc); + // Link access file if (accessFilesInfo != null) { SourceFilesInfo.SourceFileMapping accessMapping = accessFilesInfo.getMappingByCdmId(cdmId); @@ -229,4 +239,15 @@ protected void addPermission(String cdmId, Resource resource) { } } } + + protected void addStreamingMetadata(String cdmId, Resource resource) { + if (streamingMetadataService.verifyRecordHasStreamingMetadata(cdmId)) { + String[] streamingMetadata = streamingMetadataService.getStreamingMetadata(cdmId); + String duracloudSpace = streamingMetadata[1]; + String streamingFile = streamingMetadata[0]; + String streamingUrlValue = "https://durastream.lib.unc.edu/player?spaceId=" + duracloudSpace + + "&filename=" + streamingFile; + resource.addProperty(streamingUrl, streamingUrlValue); + } + } } diff --git a/src/main/java/edu/unc/lib/boxc/migration/cdm/services/sips/WorkGeneratorFactory.java b/src/main/java/edu/unc/lib/boxc/migration/cdm/services/sips/WorkGeneratorFactory.java index bb9516c5..fc0e1fb0 100644 --- a/src/main/java/edu/unc/lib/boxc/migration/cdm/services/sips/WorkGeneratorFactory.java +++ b/src/main/java/edu/unc/lib/boxc/migration/cdm/services/sips/WorkGeneratorFactory.java @@ -9,6 +9,7 @@ import edu.unc.lib.boxc.migration.cdm.services.DescriptionsService; import edu.unc.lib.boxc.migration.cdm.services.PostMigrationReportService; import edu.unc.lib.boxc.migration.cdm.services.RedirectMappingService; +import edu.unc.lib.boxc.migration.cdm.services.StreamingMetadataService; import edu.unc.lib.boxc.model.api.ids.PIDMinter; import java.io.IOException; @@ -34,6 +35,7 @@ public class WorkGeneratorFactory { private AggregateFileMappingService aggregateBottomMappingService; private PIDMinter pidMinter; private PermissionsInfo permissionsInfo; + private StreamingMetadataService streamingMetadataService; public WorkGenerator create(String cdmId, String cdmCreated, String entryType) throws IOException { WorkGenerator gen; @@ -58,6 +60,7 @@ public WorkGenerator create(String cdmId, String cdmCreated, String entryType) t gen.redirectMappingService = redirectMappingService; gen.postMigrationReportService = postMigrationReportService; gen.permissionsInfo = permissionsInfo; + gen.streamingMetadataService = streamingMetadataService; return gen; } @@ -116,4 +119,8 @@ public void setAggregateBottomMappingService(AggregateFileMappingService aggrega public void setPermissionsInfo(PermissionsInfo permissionsInfo) { this.permissionsInfo = permissionsInfo; } + + public void setStreamingMetadataService(StreamingMetadataService streamingMetadataService) { + this.streamingMetadataService = streamingMetadataService; + } } diff --git a/src/test/java/edu/unc/lib/boxc/migration/cdm/services/SipServiceTest.java b/src/test/java/edu/unc/lib/boxc/migration/cdm/services/SipServiceTest.java index 0b4bdcd7..999f1b4d 100644 --- a/src/test/java/edu/unc/lib/boxc/migration/cdm/services/SipServiceTest.java +++ b/src/test/java/edu/unc/lib/boxc/migration/cdm/services/SipServiceTest.java @@ -60,6 +60,7 @@ import static edu.unc.lib.boxc.auth.api.AccessPrincipalConstants.AUTHENTICATED_PRINC; import static edu.unc.lib.boxc.auth.api.AccessPrincipalConstants.PUBLIC_PRINC; +import static edu.unc.lib.boxc.migration.cdm.services.sips.WorkGenerator.streamingUrl; import static edu.unc.lib.boxc.migration.cdm.test.PostMigrationReportTestHelper.assertContainsRow; import static java.nio.file.StandardOpenOption.APPEND; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -1374,6 +1375,55 @@ public void generateSipsGroupedWorkWorkPermissions() throws Exception { assertPersistedSipInfoMatches(sip); } + @Test + public void generateSipsWithStreamingUrl() throws Exception { + testHelper.indexExportData("mini_gilmer"); + testHelper.generateDefaultDestinationsMapping(DEST_UUID, null); + testHelper.populateDescriptions("gilmer_mods1.xml"); + List stagingLocs = testHelper.populateSourceFiles("276_182_E.tif", "276_183_E.tif", "276_203_E.tif"); + + List sips = service.generateSips(makeOptions()); + assertEquals(1, sips.size()); + MigrationSip sip = sips.get(0); + + assertTrue(Files.exists(sip.getSipPath())); + + DepositDirectoryManager dirManager = testHelper.createDepositDirectoryManager(sip); + + Model model = testHelper.getSipModel(sip); + + Bag depBag = model.getBag(sip.getDepositPid().getRepositoryPath()); + List depBagChildren = depBag.iterator().toList(); + assertEquals(3, depBagChildren.size()); + + Resource workResc1 = testHelper.getResourceByCreateTime(depBagChildren, "2005-11-23"); + testHelper.assertObjectPopulatedInSip(workResc1, dirManager, model, stagingLocs.get(0), null, "25"); + Bag workResc1Bag = model.getBag(workResc1); + List workResc1Children = workResc1Bag.iterator().toList(); + assertEquals(1, workResc1Children.size()); + Resource workResc1FileObj = workResc1Children.get(0).asResource(); + assertFalse(workResc1FileObj.hasProperty(streamingUrl, "https://durastream.lib.unc.edu/player?" + + "spaceId=open-hls&filename=gilmer_recording-playlist.m3u8")); + Resource workResc2 = testHelper.getResourceByCreateTime(depBagChildren, "2005-11-24"); + testHelper.assertObjectPopulatedInSip(workResc2, dirManager, model, stagingLocs.get(1), null, "26"); + Bag workResc2Bag = model.getBag(workResc2); + List workResc2Children = workResc2Bag.iterator().toList(); + assertEquals(1, workResc2Children.size()); + Resource workResc2FileObj = workResc2Children.get(0).asResource(); + assertFalse(workResc2FileObj.hasProperty(streamingUrl, "https://durastream.lib.unc.edu/player?" + + "spaceId=open-hls&filename=gilmer_recording-playlist.m3u8")); + Resource workResc3 = testHelper.getResourceByCreateTime(depBagChildren, "2005-12-08"); + testHelper.assertObjectPopulatedInSip(workResc3, dirManager, model, stagingLocs.get(2), null, "27"); + Bag workResc3Bag = model.getBag(workResc3); + List workResc3Children = workResc3Bag.iterator().toList(); + assertEquals(1, workResc3Children.size()); + Resource workResc3FileObj = workResc3Children.get(0).asResource(); + assertTrue(workResc3FileObj.hasProperty(streamingUrl, "https://durastream.lib.unc.edu/player?" + + "spaceId=open-hls&filename=gilmer_recording-playlist.m3u8")); + + assertPersistedSipInfoMatches(sip); + } + private void solrResponseWithPid() throws Exception { QueryResponse testResponse1 = new QueryResponse(); SolrDocument testDocument1 = new SolrDocument(); diff --git a/src/test/java/edu/unc/lib/boxc/migration/cdm/test/SipServiceHelper.java b/src/test/java/edu/unc/lib/boxc/migration/cdm/test/SipServiceHelper.java index 87aa663e..ec38a03a 100644 --- a/src/test/java/edu/unc/lib/boxc/migration/cdm/test/SipServiceHelper.java +++ b/src/test/java/edu/unc/lib/boxc/migration/cdm/test/SipServiceHelper.java @@ -28,6 +28,7 @@ import edu.unc.lib.boxc.migration.cdm.services.ChompbConfigService; import edu.unc.lib.boxc.migration.cdm.services.GroupMappingService; import edu.unc.lib.boxc.migration.cdm.services.PermissionsService; +import edu.unc.lib.boxc.migration.cdm.services.StreamingMetadataService; import org.apache.commons.io.FileUtils; import org.apache.jena.rdf.model.Bag; import org.apache.jena.rdf.model.Model; @@ -91,6 +92,7 @@ public class SipServiceHelper { private CdmIndexService indexService; private GroupMappingService groupMappingService; private PermissionsService permissionsService; + private StreamingMetadataService streamingMetadataService; private PIDMinter pidMinter; private PremisLoggerFactoryImpl premisLoggerFactory; private ChompbConfigService.ChompbConfig chompbConfig; @@ -125,6 +127,10 @@ public SipServiceHelper(MigrationProject project, Path filesBasePath) throws IOE archivalDestinationsService.setDestinationsService(destinationsService); permissionsService = new PermissionsService(); permissionsService.setProject(project); + streamingMetadataService = new StreamingMetadataService(); + streamingMetadataService.setProject(project); + streamingMetadataService.setFieldService(fieldService); + streamingMetadataService.setIndexService(indexService); Files.createDirectories(project.getExportPath()); } @@ -142,6 +148,7 @@ public SipService createSipsService() { service.setAggregateTopMappingService(getAggregateFileMappingService()); service.setAggregateBottomMappingService(getAggregateBottomMappingService()); service.setPermissionsService(permissionsService); + service.setStreamingMetadataService(streamingMetadataService); return service; }