-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support local IDs for overlay of MARC records.
refs #3555
- Loading branch information
1 parent
e38de3d
commit 0e9debc
Showing
18 changed files
with
384 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
[ | ||
{ | ||
"@id": "http://localhost:3000/resource/ae93cff4-d272-43b2-a4ee-fb8651907e51", | ||
"@type": [ | ||
"http://sinopia.io/vocabulary/LocalAdminMetadata" | ||
], | ||
"http://id.loc.gov/ontologies/bibframe/identifier": [ | ||
{ | ||
"@id": "_:Nfe4b29df32004cc1b097a218f69df09f" | ||
} | ||
], | ||
"http://sinopia.io/vocabulary/exportDate": [ | ||
{ | ||
"@value": "2022-08-01T15:49:44.558203" | ||
} | ||
], | ||
"http://sinopia.io/vocabulary/hasResourceTemplate": [ | ||
{ | ||
"@value": "pcc:sinopia:localAdminMetadata" | ||
} | ||
], | ||
"http://sinopia.io/vocabulary/localAdminMetadataFor": [ | ||
{ | ||
"@id": "http://localhost:3000/resource/a5c5f4c0-e7cd-4ca5-a20f-2a37fe1080d5" | ||
} | ||
] | ||
}, | ||
{ | ||
"@id": "_:Nfe4b29df32004cc1b097a218f69df09f", | ||
"@type": [ | ||
"http://id.loc.gov/ontologies/bibframe/Local" | ||
], | ||
"http://id.loc.gov/ontologies/bibframe/source": [ | ||
{ | ||
"@id": "_:Nf65f353d6fb64adeb6aa6040d21fb88c" | ||
} | ||
], | ||
"http://www.w3.org/1999/02/22-rdf-syntax-ns#value": [ | ||
{ | ||
"@value": "13714202" | ||
} | ||
] | ||
}, | ||
{ | ||
"@id": "_:Nf65f353d6fb64adeb6aa6040d21fb88c", | ||
"@type": [ | ||
"http://id.loc.gov/ontologies/bibframe/Source" | ||
], | ||
"http://www.w3.org/2000/01/rdf-schema#label": [ | ||
{ | ||
"@value": "SIRSI" | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,75 @@ | ||
import { postTransfer } from "../sinopiaApi" | ||
import { postTransfer, fetchResource } from "../sinopiaApi" | ||
import { addError } from "actions/errors" | ||
import { clearLocalIds, setLocalId } from "actions/transfer" | ||
import rdf from "rdf-ext" | ||
|
||
export const transfer = | ||
(resourceUri, group, target, errorKey) => (dispatch) => { | ||
postTransfer(resourceUri, group, target).catch((err) => { | ||
(resourceUri, group, target, localId, errorKey) => (dispatch) => | ||
postTransfer(resourceUri, group, target, localId).catch((err) => { | ||
dispatch( | ||
addError(errorKey, `Error requesting transfer: ${err.message || err}`) | ||
) | ||
}) | ||
|
||
export const loadLocalIds = | ||
(resourceKey, sinopiaLocalAdminMetadataRefs, errorKey) => (dispatch) => { | ||
dispatch(clearLocalIds(resourceKey)) | ||
sinopiaLocalAdminMetadataRefs.forEach((resourceUri) => { | ||
dispatch(fetchLocalId(resourceUri, errorKey)).then( | ||
([target, group, localId]) => { | ||
if (!target) { | ||
return | ||
} | ||
dispatch(setLocalId(resourceKey, target, group, localId)) | ||
} | ||
) | ||
}) | ||
} | ||
|
||
export const noop = () => {} | ||
const fetchLocalId = (uri, errorKey) => (dispatch) => | ||
fetchResource(uri) | ||
.then(([dataset, response]) => { | ||
if (!dataset) return [false, false, false] | ||
const identifierNode = identifierNodeFromDataset(uri, dataset) | ||
if (!identifierNode) return [false, false, false] | ||
const localId = localIdFromIdentifierNode(identifierNode, dataset) | ||
const target = targetFromIdentifierNode(identifierNode, dataset) | ||
return [target, response.group, localId] | ||
}) | ||
.catch((err) => { | ||
dispatch( | ||
addError(errorKey, `Error retrieving ${uri}: ${err.message || err}`) | ||
) | ||
return [false, false, false] | ||
}) | ||
|
||
const localIdFromIdentifierNode = (identifierNode, dataset) => | ||
dataset | ||
.match( | ||
identifierNode, | ||
rdf.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#value") | ||
) | ||
.toArray()[0].object.value | ||
|
||
const targetFromIdentifierNode = (identifierNode, dataset) => { | ||
const sourceNode = dataset | ||
.match( | ||
identifierNode, | ||
rdf.namedNode("http://id.loc.gov/ontologies/bibframe/source") | ||
) | ||
.toArray()[0].object | ||
return dataset | ||
.match( | ||
sourceNode, | ||
rdf.namedNode("http://www.w3.org/2000/01/rdf-schema#label") | ||
) | ||
.toArray()[0].object.value | ||
} | ||
|
||
const identifierNodeFromDataset = (uri, dataset) => | ||
dataset | ||
.match( | ||
rdf.namedNode(uri), | ||
rdf.namedNode("http://id.loc.gov/ontologies/bibframe/identifier") | ||
) | ||
.toArray()[0].object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const clearLocalIds = (resourceKey) => ({ | ||
type: "CLEAR_LOCAL_IDS", | ||
payload: resourceKey, | ||
}) | ||
|
||
export const setLocalId = (resourceKey, target, group, localId) => ({ | ||
type: "SET_LOCAL_ID", | ||
payload: { resourceKey, target, group, localId }, | ||
}) |
Oops, something went wrong.