diff --git a/src/main/java/edu/unc/lib/boxc/migration/cdm/services/PostMigrationReportService.java b/src/main/java/edu/unc/lib/boxc/migration/cdm/services/PostMigrationReportService.java index 4f3e14d2..c0b31cd7 100644 --- a/src/main/java/edu/unc/lib/boxc/migration/cdm/services/PostMigrationReportService.java +++ b/src/main/java/edu/unc/lib/boxc/migration/cdm/services/PostMigrationReportService.java @@ -109,7 +109,7 @@ public void closeCsv() { * @param isSingleItem whether this work is a CDM single item type * @throws IOException */ - public void addWorkRow(String cdmObjectId, String boxcWorkId, int childCount, boolean isSingleItem) + public void addWorkRow(String cdmObjectId, String boxcWorkId, int childCount, boolean isSingleItem, String sipId) throws IOException { if (!enabled) { return; @@ -129,7 +129,7 @@ public void addWorkRow(String cdmObjectId, String boxcWorkId, int childCount, bo } addRow(cdmObjectId, cdmUrl, objType, boxcUrl, boxcTitle, matchingValue, sourceFile, - null, parentUrl, parentTitle, childCount, null, null); + null, parentUrl, parentTitle, childCount, sipId, null, null); } /** @@ -142,7 +142,7 @@ public void addWorkRow(String cdmObjectId, String boxcWorkId, int childCount, bo * @throws IOException */ public void addFileRow(String fileCdmId, String parentCdmId, String boxcWorkId, String boxcFileId, - boolean isSingleItem) + boolean isSingleItem, String sipId) throws IOException { if (!enabled) { return; @@ -165,14 +165,14 @@ public void addFileRow(String fileCdmId, String parentCdmId, String boxcWorkId, } addRow(fileCdmId, cdmUrl, objType, boxcUrl, boxcTitle, matchingValue, sourceFile, - null, parentUrl, parentTitle, null, null, null); + null, parentUrl, parentTitle, null, sipId, null, null); } protected void addRow(String cdmId, String cdmUrl, String objType, String boxcUrl, String boxcTitle, String matchingValue, String sourceFile, String verified, String parentUrl, - String parentTitle, Integer childCount, String parentCollUrl, String parentCollTitle) throws IOException { + String parentTitle, Integer childCount, String sipId, String parentCollUrl, String parentCollTitle) throws IOException { csvPrinter.printRecord(cdmId, cdmUrl, objType, boxcUrl, boxcTitle, matchingValue, sourceFile, - verified, parentUrl, parentTitle, childCount, parentCollUrl, parentCollTitle); + verified, parentUrl, parentTitle, childCount, sipId, parentCollUrl, parentCollTitle); } private String buildCdmUrl(String cdmObjectId, boolean isWorkObject, boolean isSingleItem) { diff --git a/src/main/java/edu/unc/lib/boxc/migration/cdm/services/sips/MultiFileWorkGenerator.java b/src/main/java/edu/unc/lib/boxc/migration/cdm/services/sips/MultiFileWorkGenerator.java index 11d976b9..4ab3b4e9 100644 --- a/src/main/java/edu/unc/lib/boxc/migration/cdm/services/sips/MultiFileWorkGenerator.java +++ b/src/main/java/edu/unc/lib/boxc/migration/cdm/services/sips/MultiFileWorkGenerator.java @@ -51,7 +51,7 @@ protected List addChildObjects() throws IOException { PID filePid = addFileObject(fileCdmId, cdmCreated, sourceMapping); addChildDescription(fileCdmId, filePid); postMigrationReportService.addFileRow(fileCdmId, cdmId, workPid.getId(), - filePid.getId(), isSingleItem()); + filePid.getId(), isSingleItem(), sipId); childPids.add(filePid); } 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 b3b6d160..bf083a4e 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 @@ -82,7 +82,7 @@ public class WorkGenerator { protected String cdmId; protected String cdmCreated; - + protected String sipId; protected PID workPid; protected Bag workBag; protected List fileObjPids; @@ -119,9 +119,10 @@ protected void generateWork() throws IOException { // Copy description to SIP copyDescriptionToSip(workPid, expDescPath); + sipId = destEntry.getDepositPid().getId(); fileObjPids = addChildObjects(); - postMigrationReportService.addWorkRow(cdmId, workPid.getId(), fileObjPids.size(), isSingleItem()); + postMigrationReportService.addWorkRow(cdmId, workPid.getId(), fileObjPids.size(), isSingleItem(), sipId); } protected List addChildObjects() throws IOException { @@ -130,7 +131,7 @@ protected List addChildObjects() throws IOException { // in a single file object, the cdm id refers to the new work, so add suffix to reference the child file addChildDescription(cdmId + "/original_file", fileObjectPid); postMigrationReportService.addFileRow(cdmId + "/original_file", cdmId, workPid.getId(), - fileObjectPid.getId(), isSingleItem()); + fileObjectPid.getId(), isSingleItem(), sipId); return Collections.singletonList(fileObjectPid); } diff --git a/src/main/java/edu/unc/lib/boxc/migration/cdm/util/PostMigrationReportConstants.java b/src/main/java/edu/unc/lib/boxc/migration/cdm/util/PostMigrationReportConstants.java index 29a4ee89..161b7011 100644 --- a/src/main/java/edu/unc/lib/boxc/migration/cdm/util/PostMigrationReportConstants.java +++ b/src/main/java/edu/unc/lib/boxc/migration/cdm/util/PostMigrationReportConstants.java @@ -12,13 +12,14 @@ public class PostMigrationReportConstants { public static final String VERIFIED_HEADER = "verified"; public static final String PARENT_COLL_URL_HEADER = "parent_collection_url"; public static final String PARENT_COLL_TITLE_HEADER = "parent_collection_title"; + public static final String SIP_ID = "sip_id"; public static final String RECORD_PATH = "record/"; public static final String API_PATH = "api/" + RECORD_PATH; public static final String[] CSV_HEADERS = new String[] { "cdm_id", "cdm_url", "boxc_obj_type", "boxc_url", "boxc_title", "matching_value", "source_file", - VERIFIED_HEADER, "boxc_parent_work_url", "boxc_parent_work_title", "children_count", PARENT_COLL_URL_HEADER, - PARENT_COLL_TITLE_HEADER }; + VERIFIED_HEADER, "boxc_parent_work_url", "boxc_parent_work_title", "children_count", + SIP_ID, PARENT_COLL_URL_HEADER, PARENT_COLL_TITLE_HEADER }; public static final CSVFormat CSV_OUTPUT_FORMAT = CSVFormat.Builder.create() .setHeader(CSV_HEADERS) .get(); diff --git a/src/test/java/edu/unc/lib/boxc/migration/cdm/services/MigrationTypeReportServiceTest.java b/src/test/java/edu/unc/lib/boxc/migration/cdm/services/MigrationTypeReportServiceTest.java index 33696577..5c7eec95 100644 --- a/src/test/java/edu/unc/lib/boxc/migration/cdm/services/MigrationTypeReportServiceTest.java +++ b/src/test/java/edu/unc/lib/boxc/migration/cdm/services/MigrationTypeReportServiceTest.java @@ -51,9 +51,9 @@ public void setup() throws Exception { public void reportCountWorksTest() throws Exception { reportGenerator.init(); reportGenerator.addRow("25", CDM_URL_1, "Work", BOXC_URL_1, "Redoubt C", - null, null, null, "", "", 1, null, null); + null, null, null, "", "", 1, null, null, null); reportGenerator.addRow("26", CDM_URL_2, "File", BOXC_URL_2, "A file", - null, null, null, BOXC_URL_1, "Redoubt C", null, null, null); + null, null, null, BOXC_URL_1, "Redoubt C", null, null, null, null); reportGenerator.closeCsv(); long numWorks = service.countWorks(); @@ -64,11 +64,11 @@ public void reportCountWorksTest() throws Exception { public void reportCountFilesTest() throws Exception { reportGenerator.init(); reportGenerator.addRow("25", CDM_URL_1, "Work", BOXC_URL_1, "Redoubt C", - null, null, null, "", "", 1, null, null); + null, null, null, "", "", 1, null, null, null); reportGenerator.addRow("26", CDM_URL_2, "File", BOXC_URL_2, "A file", - null, null, null, BOXC_URL_1, "Redoubt C", null, null, null); + null, null, null, BOXC_URL_1, "Redoubt C", null, null,null, null); reportGenerator.addRow("27", CDM_URL_3, "File", BOXC_URL_3, "A file", - null, null, null, BOXC_URL_1, "Redoubt C", null, null, null); + null, null, null, BOXC_URL_1, "Redoubt C", null, null,null, null); reportGenerator.closeCsv(); long numFiles = service.countFiles(); diff --git a/src/test/java/edu/unc/lib/boxc/migration/cdm/services/PostMigrationReportServiceTest.java b/src/test/java/edu/unc/lib/boxc/migration/cdm/services/PostMigrationReportServiceTest.java index 3e4bc6c0..0eb13241 100644 --- a/src/test/java/edu/unc/lib/boxc/migration/cdm/services/PostMigrationReportServiceTest.java +++ b/src/test/java/edu/unc/lib/boxc/migration/cdm/services/PostMigrationReportServiceTest.java @@ -20,6 +20,7 @@ import static edu.unc.lib.boxc.migration.cdm.test.PostMigrationReportTestHelper.assertContainsRow; import static edu.unc.lib.boxc.migration.cdm.test.PostMigrationReportTestHelper.parseReport; +import static edu.unc.lib.boxc.migration.cdm.util.PostMigrationReportConstants.SIP_ID; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.MockitoAnnotations.openMocks; @@ -72,8 +73,8 @@ public void addSingleItemTest() throws Exception { writeSourceFileCsv(mappingBody("25,," + srcPath1 +",")); testHelper.populateDescriptions("gilmer_mods1.xml"); - service.addWorkRow("25", BOXC_ID_1, 1, true); - service.addFileRow("25/original_file", "25", BOXC_ID_1, BOXC_ID_2, true); + service.addWorkRow("25", BOXC_ID_1, 1, true, SIP_ID); + service.addFileRow("25/original_file", "25", BOXC_ID_1, BOXC_ID_2, true, SIP_ID); service.closeCsv(); var rows = parseReport(project); @@ -88,6 +89,7 @@ public void addSingleItemTest() throws Exception { "", "", "1", + SIP_ID, "", ""); assertContainsRow(rows, "25/original_file", @@ -101,6 +103,7 @@ public void addSingleItemTest() throws Exception { BOXC_URL_1, "Redoubt C", "", + SIP_ID, "", ""); } @@ -113,8 +116,8 @@ public void addSingleItemWithFileDescTest() throws Exception { writeSourceFileCsv(mappingBody("25,," + srcPath1 +",")); testHelper.populateDescriptions("gilmer_mods1.xml", "gilmer_mods_children.xml"); - service.addWorkRow("25", BOXC_ID_1, 1, true); - service.addFileRow("25/original_file", "25", BOXC_ID_1, BOXC_ID_2, true); + service.addWorkRow("25", BOXC_ID_1, 1, true, SIP_ID); + service.addFileRow("25/original_file", "25", BOXC_ID_1, BOXC_ID_2, true, SIP_ID); service.closeCsv(); var rows = parseReport(project); @@ -129,6 +132,7 @@ public void addSingleItemWithFileDescTest() throws Exception { "", "", "1", + SIP_ID, "", ""); assertContainsRow(rows, "25/original_file", @@ -142,6 +146,7 @@ public void addSingleItemWithFileDescTest() throws Exception { BOXC_URL_1, "Redoubt C", "", + SIP_ID, "", ""); } @@ -155,9 +160,9 @@ public void addGroupedTest() throws Exception { writeSourceFileCsv(mappingBody("26,," + srcPath1 +",", "27,," + srcPath2 +",")); testHelper.populateDescriptions("grouped_mods.xml"); - service.addWorkRow("grp:groupa:group1", BOXC_ID_1, 2, false); - service.addFileRow("26", "grp:groupa:group1", BOXC_ID_1, BOXC_ID_2, false); - service.addFileRow("27", "grp:groupa:group1", BOXC_ID_1, BOXC_ID_3, false); + service.addWorkRow("grp:groupa:group1", BOXC_ID_1, 2, false, SIP_ID); + service.addFileRow("26", "grp:groupa:group1", BOXC_ID_1, BOXC_ID_2, false, SIP_ID); + service.addFileRow("27", "grp:groupa:group1", BOXC_ID_1, BOXC_ID_3, false, SIP_ID); service.closeCsv(); var rows = parseReport(project); @@ -172,6 +177,7 @@ public void addGroupedTest() throws Exception { "", "", "2", + SIP_ID, "", ""); assertContainsRow(rows, "26", @@ -185,6 +191,7 @@ public void addGroupedTest() throws Exception { BOXC_URL_1, "Folder Group 1", "", + SIP_ID, "", ""); assertContainsRow(rows, "27", @@ -198,6 +205,7 @@ public void addGroupedTest() throws Exception { BOXC_URL_1, "Folder Group 1", "", + SIP_ID, "", ""); } @@ -212,9 +220,9 @@ public void addCompoundTest() throws Exception { descriptionsService.generateDocuments(true); descriptionsService.expandDescriptions(); - service.addWorkRow("605", BOXC_ID_1, 2, false); - service.addFileRow("602", "605", BOXC_ID_1, BOXC_ID_2, false); - service.addFileRow("603", "605", BOXC_ID_1, BOXC_ID_3, false); + service.addWorkRow("605", BOXC_ID_1, 2, false, SIP_ID); + service.addFileRow("602", "605", BOXC_ID_1, BOXC_ID_2, false, SIP_ID); + service.addFileRow("603", "605", BOXC_ID_1, BOXC_ID_3, false, SIP_ID); service.closeCsv(); var rows = parseReport(project); @@ -229,6 +237,7 @@ public void addCompoundTest() throws Exception { "", "", "2", + SIP_ID, "", ""); assertContainsRow(rows, "602", @@ -242,6 +251,7 @@ public void addCompoundTest() throws Exception { BOXC_URL_1, "Tiffany's pillbox commemorating UNC's bicentennial (closed, in box)", "", + SIP_ID, "", ""); assertContainsRow(rows, "603", @@ -255,6 +265,7 @@ public void addCompoundTest() throws Exception { BOXC_URL_1, "Tiffany's pillbox commemorating UNC's bicentennial (closed, in box)", "", + SIP_ID, "", ""); } @@ -272,8 +283,8 @@ public void addSingleItemNonCdmProjectTest() throws Exception { writeSourceFileCsv(mappingBody("25,," + srcPath1 +",")); testHelper.populateDescriptions("gilmer_mods1.xml"); - service.addWorkRow("25", BOXC_ID_1, 1, true); - service.addFileRow("25/original_file", "25", BOXC_ID_1, BOXC_ID_2, true); + service.addWorkRow("25", BOXC_ID_1, 1, true, SIP_ID); + service.addFileRow("25/original_file", "25", BOXC_ID_1, BOXC_ID_2, true, SIP_ID); service.closeCsv(); assertFalse(Files.exists(project.getPostMigrationReportPath())); diff --git a/src/test/java/edu/unc/lib/boxc/migration/cdm/services/PostMigrationReportVerifierTest.java b/src/test/java/edu/unc/lib/boxc/migration/cdm/services/PostMigrationReportVerifierTest.java index c31618dc..35b99ce0 100644 --- a/src/test/java/edu/unc/lib/boxc/migration/cdm/services/PostMigrationReportVerifierTest.java +++ b/src/test/java/edu/unc/lib/boxc/migration/cdm/services/PostMigrationReportVerifierTest.java @@ -33,6 +33,7 @@ import static edu.unc.lib.boxc.migration.cdm.test.PostMigrationReportTestHelper.PARENT_COLL_URL; import static edu.unc.lib.boxc.migration.cdm.test.PostMigrationReportTestHelper.parseReport; import static edu.unc.lib.boxc.migration.cdm.util.PostMigrationReportConstants.API_PATH; +import static edu.unc.lib.boxc.migration.cdm.util.PostMigrationReportConstants.SIP_ID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; @@ -95,9 +96,9 @@ public void reportVerifySuccessTest() throws Exception { reportGenerator.init(); reportGenerator.addRow("25", CDM_URL_1, "Work", BOXC_URL_1, "Redoubt C", - null, null, null, "", "", 1, null, null); + null, null, null, "", "", 1, SIP_ID, null,null); reportGenerator.addRow("26", CDM_URL_2, "File", BOXC_URL_2, "A file", - null, null, null, BOXC_URL_1, "Redoubt C", null, null, null); + null, null, null, BOXC_URL_1, "Redoubt C", null, SIP_ID, null,null); reportGenerator.closeCsv(); var outcome = verifier.verify(); @@ -118,6 +119,7 @@ public void reportVerifySuccessTest() throws Exception { "", "", "1", + SIP_ID, PARENT_COLL_URL, PARENT_COLL_TITLE); assertRowContainsAllInfo(rows, "26", @@ -131,6 +133,7 @@ public void reportVerifySuccessTest() throws Exception { BOXC_URL_1, "Redoubt C", "", + SIP_ID, PARENT_COLL_URL, PARENT_COLL_TITLE); } @@ -142,9 +145,9 @@ public void reportVerifyErrorsTest() throws Exception { reportGenerator.init(); reportGenerator.addRow("25", CDM_URL_1, "Work", BOXC_URL_1, "Redoubt C", - null, null, null, "", "", 1, null, null); + null, null, null, "", "", 1, SIP_ID, null,null); reportGenerator.addRow("26", CDM_URL_2, "File", BOXC_URL_2, "A file", - null, null, null, BOXC_URL_1, "Redoubt C", null, null, null); + null, null, null, BOXC_URL_1, "Redoubt C", null, SIP_ID, null,null); reportGenerator.closeCsv(); var outcome = verifier.verify(); @@ -165,6 +168,7 @@ public void reportVerifyErrorsTest() throws Exception { "", "", "1", + SIP_ID, PARENT_COLL_URL, PARENT_COLL_TITLE); assertRowContainsAllInfo(rows, "26", @@ -178,6 +182,7 @@ public void reportVerifyErrorsTest() throws Exception { BOXC_URL_1, "Redoubt C", "", + SIP_ID, PARENT_COLL_URL, PARENT_COLL_TITLE); } @@ -188,9 +193,9 @@ public void reportVerifyPartialTest() throws Exception { reportGenerator.init(); reportGenerator.addRow("25", CDM_URL_1, "Work", BOXC_URL_1, "Redoubt C", - null, null, HttpStatus.OK.name(), "", "", 1, null, null); + null, null, HttpStatus.OK.name(), "", "", 1, SIP_ID, null,null); reportGenerator.addRow("26", CDM_URL_2, "File", BOXC_URL_2, "A file", - null, null, null, BOXC_URL_1, "Redoubt C", null, null, null); + null, null, null, BOXC_URL_1, "Redoubt C", null, SIP_ID, null,null); reportGenerator.closeCsv(); var outcome = verifier.verify(); @@ -211,6 +216,7 @@ public void reportVerifyPartialTest() throws Exception { "", "", "1", + SIP_ID, PARENT_COLL_URL, PARENT_COLL_TITLE); assertRowContainsAllInfo(rows, "26", @@ -224,6 +230,7 @@ public void reportVerifyPartialTest() throws Exception { BOXC_URL_1, "Redoubt C", "", + SIP_ID, PARENT_COLL_URL, PARENT_COLL_TITLE); } @@ -234,9 +241,9 @@ public void reportVerifyWithParentCollectionError() throws Exception { reportGenerator.init(); reportGenerator.addRow("25", CDM_URL_1, "Work", BOXC_URL_1, "Redoubt C", - null, null, null, "", "", 1, null, null); + null, null, null, "", "", 1, SIP_ID, null,null); reportGenerator.addRow("26", CDM_URL_2, "File", BOXC_URL_2, "A file", - null, null, null, BOXC_URL_1, "Redoubt C", null, null, null); + null, null, null, BOXC_URL_1, "Redoubt C", null, SIP_ID, null,null); reportGenerator.closeCsv(); var outcome = verifier.verify(); @@ -257,6 +264,7 @@ public void reportVerifyWithParentCollectionError() throws Exception { "", "", "1", + SIP_ID, "", ""); assertRowContainsAllInfo(rows, "26", @@ -270,6 +278,7 @@ public void reportVerifyWithParentCollectionError() throws Exception { BOXC_URL_1, "Redoubt C", "", + SIP_ID, "", ""); } @@ -300,10 +309,10 @@ private void mockBxcResponses(Map urlToStatus, boolean apiFa public static void assertRowContainsAllInfo(List> rows, String cdmId, String cdmUrl, String objType, String bxcUrl, String bxcTitle, String matchingValue, String sourceFile, String verified, String parentUrl, String parentTitle, String childCount, - String parentCollUrl, String parentCollTitle) { + String sipId, String parentCollUrl, String parentCollTitle) { var found = rows.stream().filter(r -> r.getFirst().equals(cdmId)).findFirst().orElse(null); assertNotNull(found, "Did not find row for CDM id " + cdmId + ", rows were:\n" + rows); assertEquals(Arrays.asList(cdmId, cdmUrl, objType, bxcUrl, bxcTitle, matchingValue, sourceFile, verified, - parentUrl, parentTitle, childCount, parentCollUrl, parentCollTitle), found); + parentUrl, parentTitle, childCount, sipId, parentCollUrl, parentCollTitle), found); } } diff --git a/src/test/java/edu/unc/lib/boxc/migration/cdm/test/PostMigrationReportTestHelper.java b/src/test/java/edu/unc/lib/boxc/migration/cdm/test/PostMigrationReportTestHelper.java index 6638dac8..d88abdd1 100644 --- a/src/test/java/edu/unc/lib/boxc/migration/cdm/test/PostMigrationReportTestHelper.java +++ b/src/test/java/edu/unc/lib/boxc/migration/cdm/test/PostMigrationReportTestHelper.java @@ -25,6 +25,7 @@ private PostMigrationReportTestHelper() { public static final String PARENT_COLL_ID = "4fe5080f-41cd-4b1e-9cdd-71203c824cd0"; public static final String PARENT_COLL_URL = TEST_BASE_URL + RECORD_PATH + PARENT_COLL_ID; public static final String PARENT_COLL_TITLE = "Latin Studies Program"; + private static final String SIP_ID = "6f4b5e38-754f-49ca-a4a0-6441fea95d76"; public static final String JSON = "{\"findingAidUrl\":\"https://finding-aids.lib.unc.edu/catalog/40489\"," + "\"viewerType\":\"clover\",\"canBulkDownload\":false,\"dataFileUrl\":\"content/6f4b5e38-754f-49ca-a4a0-6441fea95d76\"," + "\"markedForDeletion\":false,\"pageSubtitle\":\"TEST.jpg\",\"briefObject\":{\"added\":\"2018-05-24T20:39:18.165Z\"," + @@ -67,10 +68,10 @@ public static void assertContainsRow(List> rows, String cdmId, Stri public static void assertContainsRow(List> rows, String cdmId, String cdmUrl, String objType, String bxcUrl, String bxcTitle, String matchingValue, String sourceFile, String verified, String parentUrl, String parentTitle, String childCount, - String parentCollUrl, String parentCollTitle) { + String sipId, String parentCollUrl, String parentCollTitle ) { var found = rows.stream().filter(r -> r.get(0).equals(cdmId)).findFirst().orElse(null); assertNotNull(found, "Did not find row for CDM id " + cdmId + ", rows were:\n" + rows); assertEquals(Arrays.asList(cdmId, cdmUrl, objType, bxcUrl, bxcTitle, matchingValue, sourceFile, verified, - parentUrl, parentTitle, childCount, parentCollUrl, parentCollTitle), found); + parentUrl, parentTitle, childCount, sipId, parentCollUrl, parentCollTitle), found); } }