Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BXC-4511 add streaming metadata to SIPS #91

Merged
merged 7 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/edu/unc/lib/boxc/migration/cdm/SipsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -147,5 +156,6 @@ private void initialize() throws IOException {
sipService.setChompbConfig(parentCommand.getChompbConfig());
sipService.setAggregateTopMappingService(aggregateTopMappingService);
sipService.setAggregateBottomMappingService(aggregateBottomMappingService);
sipService.setStreamingMetadataService(streamingMetadataService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

/**
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Path> stagingLocs = testHelper.populateSourceFiles("276_182_E.tif", "276_183_E.tif", "276_203_E.tif");

List<MigrationSip> 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<RDFNode> 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<RDFNode> 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<RDFNode> 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<RDFNode> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand All @@ -142,6 +148,7 @@ public SipService createSipsService() {
service.setAggregateTopMappingService(getAggregateFileMappingService());
service.setAggregateBottomMappingService(getAggregateBottomMappingService());
service.setPermissionsService(permissionsService);
service.setStreamingMetadataService(streamingMetadataService);
return service;
}

Expand Down
Loading