Skip to content

Commit

Permalink
import without exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcrane committed Sep 11, 2024
1 parent 250a6c4 commit 0f9499f
Show file tree
Hide file tree
Showing 2 changed files with 310 additions and 0 deletions.
183 changes: 183 additions & 0 deletions LeedsPrototypeTests/samples/10315s-tweaked-METS/10315.METS.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?xml version="1.0" encoding="utf-8"?>
<mets-objects>
<mets:mets
xmlns:mets="http://www.loc.gov/METS/"
xmlns:mods="http://www.loc.gov/mods/v3"
xmlns:premis="http://www.loc.gov/premis/v3"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

OBJID="eprint_10315" LABEL="Eprints Item"

xsi:schemaLocation="
http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd
http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-3.xsd">
<mets:metsHdr CREATEDATE="2023-12-22T04:53:58Z">
<mets:agent ROLE="CREATOR" TYPE="OTHER" OTHERTYPE="SOFTWARE">
<mets:name>EPrints 3.3.15</mets:name>
</mets:agent>
</mets:metsHdr>
<mets:dmdSec ID="DMD_eprint_10315">
<mets:mdWrap MDTYPE="MODS">
<mets:xmlData>
<mods:titleInfo>
<mods:title>[Example title]</mods:title>
</mods:titleInfo>
<mets:abstract>The description of this object has been modified.</mets:abstract>
<mets:recordInfo>
<mets:recordIdentifier source="EPrints">10315</mets:recordIdentifier>
<mets:recordIdentifier source="EMu">372705</mets:recordIdentifier>
<mets:recordInfoNote type="IngestionID">20151118190008_372705</mets:recordInfoNote>
</mets:recordInfo>
<mets:originInfo>
<mets:publisher>University of Leeds</mets:publisher>
</mets:originInfo>
</mets:xmlData>
</mets:mdWrap>
</mets:dmdSec>
<mets:amdSec ID="AMD_eprint_10315">
<mets:techMD ID="AMD_eprint_10315_370441">
<mets:mdWrap MDTYPE="OTHER" MIMETYPE="text/xml">
<premis:object xsi:type="premis:file" xsi:schemaLocation="http://www.loc.gov/premis/v3 http://www.loc.gov/standards/premis/v3/premis.xsd">
<premis:objectIdentifier>
<premis:objectIdentifierType>local</premis:objectIdentifierType>
<premis:objectIdentifierValue>372705s_001.jpg</premis:objectIdentifierValue>
</premis:objectIdentifier>
<premis:objectCharacteristics>
<premis:fixity>
<premis:messageDigestAlgorithm>sha256</premis:messageDigestAlgorithm>
<premis:messageDigest>4675c73e6fd66d2ea9a684ec79e4e6559bb4d44a35e8234794b0691472b0385d</premis:messageDigest>
</premis:fixity>
<premis:size>876464</premis:size>
<premis:format>
<premis:formatDesignation>
<premis:formatName>JPEG File Interchange Format</premis:formatName>
</premis:formatDesignation>
<premis:formatRegistry>
<premis:formatRegistryName>PRONOM</premis:formatRegistryName>
<premis:formatRegistryKey>fmt/43</premis:formatRegistryKey>
</premis:formatRegistry>
</premis:format>
</premis:objectCharacteristics>
</premis:object>
</mets:mdWrap>
</mets:techMD>
<mets:techMD ID="AMD_eprint_10315_370442">
<mets:mdWrap MDTYPE="OTHER" MIMETYPE="text/xml">
<premis:object xsi:type="premis:file" xsi:schemaLocation="http://www.loc.gov/premis/v3 http://www.loc.gov/standards/premis/v3/premis.xsd">
<premis:objectIdentifier>
<premis:objectIdentifierType>local</premis:objectIdentifierType>
<premis:objectIdentifierValue>817982 372705s_002</premis:objectIdentifierValue>
</premis:objectIdentifier>
<premis:objectCharacteristics>
<premis:fixity>
<premis:messageDigestAlgorithm>sha256</premis:messageDigestAlgorithm>
<premis:messageDigest>a321d0fc85bd0a760ca767a883e742632ca7c560d09bdf55200571ab44c43850</premis:messageDigest>
</premis:fixity>
<premis:size>817982</premis:size>
<premis:format>
<premis:formatDesignation>
<premis:formatName>JPEG File Interchange Format</premis:formatName>
</premis:formatDesignation>
<premis:formatRegistry>
<premis:formatRegistryName>PRONOM</premis:formatRegistryName>
<premis:formatRegistryKey>fmt/43</premis:formatRegistryKey>
</premis:formatRegistry>
</premis:format>
</premis:objectCharacteristics>
</premis:object>
</mets:mdWrap>
</mets:techMD>
<mets:techMD ID="AMD_eprint_10315_370443">
<mets:mdWrap MDTYPE="OTHER" MIMETYPE="text/xml">
<premis:object xsi:type="premis:file" xsi:schemaLocation="http://www.loc.gov/premis/v3 http://www.loc.gov/standards/premis/v3/premis.xsd">
<premis:objectIdentifier>
<premis:objectIdentifierType>local</premis:objectIdentifierType>
<premis:objectIdentifierValue>372705s_003.jpg</premis:objectIdentifierValue>
</premis:objectIdentifier>
<premis:objectCharacteristics>
<premis:fixity>
<premis:messageDigestAlgorithm>sha256</premis:messageDigestAlgorithm>
<premis:messageDigest>0a753e84444d398436f09a3b8bda8232e4bb206aa016381a0e9cf5ef6af869c6</premis:messageDigest>
</premis:fixity>
<premis:size>754672</premis:size>
<premis:format>
<premis:formatDesignation>
<premis:formatName>JPEG File Interchange Format</premis:formatName>
</premis:formatDesignation>
<premis:formatRegistry>
<premis:formatRegistryName>PRONOM</premis:formatRegistryName>
<premis:formatRegistryKey>fmt/43</premis:formatRegistryKey>
</premis:formatRegistry>
</premis:format>
</premis:objectCharacteristics>
</premis:object>
</mets:mdWrap>
</mets:techMD>
<mets:techMD ID="AMD_eprint_10315_370444">
<mets:mdWrap MDTYPE="OTHER" MIMETYPE="text/xml">
<premis:object xsi:type="premis:file" xsi:schemaLocation="http://www.loc.gov/premis/v3 http://www.loc.gov/standards/premis/v3/premis.xsd">
<premis:objectIdentifier>
<premis:objectIdentifierType>local</premis:objectIdentifierType>
<premis:objectIdentifierValue>372705s_004.jpg</premis:objectIdentifierValue>
</premis:objectIdentifier>
<premis:objectCharacteristics>
<premis:fixity>
<premis:messageDigestAlgorithm>sha256</premis:messageDigestAlgorithm>
<premis:messageDigest>315bb3bd2eb2da5ce8b848bb7f09803d8a48e64021c4b6fe074aed9cc591c154</premis:messageDigest>
</premis:fixity>
<premis:size>743515</premis:size>
<premis:format>
<premis:formatDesignation>
<premis:formatName>JPEG File Interchange Format</premis:formatName>
</premis:formatDesignation>
<premis:formatRegistry>
<premis:formatRegistryName>PRONOM</premis:formatRegistryName>
<premis:formatRegistryKey>fmt/43</premis:formatRegistryKey>
</premis:formatRegistry>
</premis:format>
</premis:objectCharacteristics>
</premis:object>
</mets:mdWrap>
</mets:techMD>
</mets:amdSec>
<mets:fileSec>
<mets:fileGrp USE="reference">
<mets:file ID="eprint_10315_370441" SIZE="266036836" MIMETYPE="image/jpeg" ADMID="AMD_eprint_10315_370441">
<mets:FLocat LOCTYPE="URL" xlink:type="simple" xlink:href="objects/372705s_001.jpg"/>
</mets:file>
</mets:fileGrp>
<mets:fileGrp USE="reference">
<mets:file ID="eprint_10315_370442" SIZE="266035584" MIMETYPE="image/jpeg" ADMID="AMD_eprint_10315_370442">
<mets:FLocat LOCTYPE="URL" xlink:type="simple" xlink:href="objects/372705s_002.jpg"/>
</mets:file>
</mets:fileGrp>
<mets:fileGrp USE="reference">
<mets:file ID="eprint_10315_370443" SIZE="266036112" MIMETYPE="image/jpeg" ADMID="AMD_eprint_10315_370443">
<mets:FLocat LOCTYPE="URL" xlink:type="simple" xlink:href="objects/372705s_003.jpg"/>
</mets:file>
</mets:fileGrp>
<mets:fileGrp USE="reference">
<mets:file ID="eprint_10315_370444" SIZE="266036344" MIMETYPE="image/jpeg" ADMID="AMD_eprint_10315_370444">
<mets:FLocat LOCTYPE="URL" xlink:type="simple" xlink:href="objects/372705s_004.jpg"/>
</mets:file>
</mets:fileGrp>
</mets:fileSec>
<mets:structMap>
<mets:div DMDID="DMD_eprint_10315" ADMID="AMD_eprint_10315">
<mets:div>
<mets:fptr FILEID="eprint_10315_370441"/>
</mets:div>
<mets:div>
<mets:fptr FILEID="eprint_10315_370442"/>
</mets:div>
<mets:div>
<mets:fptr FILEID="eprint_10315_370443"/>
</mets:div>
<mets:div>
<mets:fptr FILEID="eprint_10315_370444"/>
</mets:div>
</mets:div>
</mets:structMap>
</mets:mets>
</mets-objects>
127 changes: 127 additions & 0 deletions LeedsPrototypeTests/tests/new-version-without-exporting.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,130 @@
import {expect, test} from '@playwright/test';
import { createDigitalObject } from './quick-prep.spec'
import {getS3Client, getShortTimestamp, listKeys, uploadFile} from "./common-utils";
import {ListObjectsV2Command} from "@aws-sdk/client-s3";

// Create a new deposit by exporting a version


test.describe('Update a Digital Object without exporting anything first', () => {


test('editing-mets', async ({request, baseURL}) => {

// Set a very long timeout so you can debug on breakpoints or whatnot.
test.setTimeout(1000000);

// Background prep
console.log("Starting condition is a Preserved Digital Object in the repository - we'll make one for this test");
const digitalObjectUri = await createDigitalObject(request, baseURL);
console.log("Created " + digitalObjectUri);

console.log("Create a new Deposit - NOT an export:");
console.log("POST /deposits");
const newDepositResp = await request.post('/deposits', {
data: {
digitalObject: digitalObjectUri,
submissionText: "Creating a new deposit to demonstrate updates without exporting"
}
})
const newDeposit = await newDepositResp.json();
console.log("New Deposit created:");
console.log(newDeposit);
console.log("----");

console.log("Now upload the changed file - just the METS and not 5GB of tiffs!")
const s3Client = getS3Client();
await uploadFile(s3Client, newDeposit.files, 'samples/10315s-tweaked-METS/10315.METS.xml', '10315.METS.xml');

console.log("----");
console.log("Now build our own import job from scratch");
const importJobId = "https://digirati.com/importJobs/job-" + getShortTimestamp();
console.log("We can also mint whatever id we like for this job:")
console.log(`"@id": "${importJobId}"`);
console.log("This time we have to add the sha256 ourselves because we are not asking the server to build the import job")
const importJob = {
'@id': importJobId,
type: 'ImportJob',
deposit: newDeposit['@id'],
digitalObject: digitalObjectUri,
containersToAdd: [],
binariesToAdd: [],
containersToDelete: [],
binariesToDelete: [],
binariesToPatch: [
{
'@id': digitalObjectUri + '/10315.METS.xml',
name: '10315.METS.xml',
contentType: 'application/xml',
partOf: digitalObjectUri,
digest: 'c033d56b1c756f718233893ca735a2eb1add86fb4200a99f30c93deb5ffe6adf'
}
]
};
console.log(importJob);

const executeJobUri = newDeposit['@id'] + '/importJobs';
console.log("Now execute the import job...");
console.log("POST " + executeJobUri);
const executeImportJobReq = await request.post(executeJobUri, {
data: importJob
});
let importJobResult = await executeImportJobReq.json();
console.log(importJobResult);
expect(importJobResult).toEqual(expect.objectContaining({
type: 'ImportJobResult',
status: 'waiting',
digitalObject: digitalObjectUri
}));
console.log("----");

console.log("... and poll it until it is either complete or completeWithErrors...");
await expect.poll(async () => {

// ### API INTERACTION ###
console.log("GET " + importJobResult['@id']);
const ijrReq = await request.get(importJobResult['@id']);

const ijr = await ijrReq.json();
console.log("status: " + ijr.status);
return ijr.status;
}, {
intervals: [2000], // every 2 seconds
timeout: 60000 // allow 1 minute to complete
}).toMatch(/completed.*/);
console.log("----");

// ### API INTERACTION ###
console.log("Now request the digital object URI we made earlier:");
console.log("GET " + digitalObjectUri);
const digitalObjectReq = await request.get(digitalObjectUri);

expect(digitalObjectReq.ok()).toBeTruthy();
const digitalObject = await digitalObjectReq.json();
console.log("We expect to see two versions available in this object")
console.log(digitalObject);

expect(digitalObject).toEqual(expect.objectContaining({
'@id': digitalObjectUri,
type: 'DigitalObject',
name: '[Example title]', // This will have been read from the METS file <mods:title>
version: expect.objectContaining({name: 'v2'}), // and we expect it to be at version 2
versions: expect.arrayContaining(
[
expect.objectContaining({name:'v1'}),
expect.objectContaining({name:'v2'})
]
),
binaries: expect.arrayContaining(
[
// and it has a METS file in the root
expect.objectContaining({'@id': expect.stringContaining('10315.METS.xml')})
])
}));
})
});


// maybe you have these files handy already
// replace jpeg 2 with another binary, same name
// sha256 changes in METS but that's all
Expand Down

0 comments on commit 0f9499f

Please sign in to comment.