Skip to content

Commit afb7fef

Browse files
authored
GQL-118: Add support for retrieving a collection revision (#182)
* GQL-118a: Add support for retrieving a collection revision * GQL-118: Update json key list, fix issue with non empty jsonKeys when revisionId * GQL-118: Remove debug logs * GQL-118: Fix issue with 'provider' * GQL-118: Add test for revisionId * GQL-118: Remove String conversion, remove error for not matching revision * GQL-118: Refactoring * GQL-118: Remove throwing errors for list of json fields * GQL-118: Remove error messages for list of fields * GQL-118: Rorder revvisionId in list of CollectionInput * GQL-118: Add comment * GQL-118: Add test for case of retrieving collection by revisionId * GQL-118: Add tests * GQL-118: Get revisionId from requestInfo, empty out jsonKeys * GQL-118: Update test for revisionId * GQL-118: Add test for json only field * GQL-118: Add allRvisions to parameter list before calling cmrQuery * GQL-118: Add Notes to json only fields * GQL-118: Add comment * GQL-118: Remove 'providerId' as requested * GQL-118: Fix vulnerabilities
1 parent aa8f5f7 commit afb7fef

8 files changed

Lines changed: 414 additions & 90 deletions

File tree

package-lock.json

Lines changed: 85 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"graphql-type-json": "^0.3.2",
8787
"jsonwebtoken": "^9.0.2",
8888
"jwks-rsa": "^3.1.0",
89-
"lodash": "^4.17.21",
89+
"lodash": "^4.18.1",
9090
"qs": "^6.12.0",
9191
"snakecase-keys": "^6.0.0",
9292
"stellate": "^2.11.1",

src/cmr/concepts/concept.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,19 @@ export default class Concept {
643643
fetchUmm(searchParams, requestedKeys, providedHeaders) {
644644
this.logKeyRequest(requestedKeys, 'umm')
645645

646+
const { revisionId } = this.requestInfo
647+
648+
const params = pick(snakeCaseKeys(searchParams), this.getPermittedUmmSearchParams())
649+
650+
// Add all_revisions to params if revisionId is present and all_revisions is not set
651+
if (revisionId && !params.all_revisions) {
652+
params.all_revisions = true
653+
}
654+
646655
// Construct the promise that will request data from the umm endpoint
647656
return cmrQuery({
648657
conceptType: this.getConceptType(),
649-
params: pick(snakeCaseKeys(searchParams), this.getPermittedUmmSearchParams()),
658+
params,
650659
nonIndexedKeys: this.getNonIndexedKeys(),
651660
headers: providedHeaders,
652661
options: {
@@ -943,6 +952,7 @@ export default class Concept {
943952
* @param {Array} ummKeys Array of the keys requested in the query
944953
*/
945954
async parseUmm(ummResponse, ummKeys) {
955+
const { revisionId } = this.requestInfo
946956
// Pull out the key mappings so we can retrieve the values below
947957
const { ummKeyMappings } = this.requestInfo
948958

@@ -961,14 +971,26 @@ export default class Concept {
961971
items.forEach((item, itemIndex) => {
962972
const normalizedItem = this.normalizeUmmItem(item)
963973

974+
// Filter out items that don't match the requested revisionId
975+
// This is necessary because the umm endpoint returns multiple revisions
976+
if (revisionId && normalizedItem.meta['revision-id'].toString() !== revisionId.toString()) {
977+
return
978+
}
979+
964980
// Creates unique item keys regardless of whether or not
965981
// a user calls for data with similar conceptIds (as is the case with revisions)
966982
const itemKey = this.generateUmmItemKey(itemIndex, normalizedItem)
967983

968984
this.setEssentialUmmValues(itemKey, normalizedItem)
969985

970-
this.setUmmItems(item, itemKey, ummKeys, ummKeyMappings,)
986+
this.setUmmItems(item, itemKey, ummKeys, ummKeyMappings)
971987
})
988+
989+
// Update the item count if we filtered out items
990+
if (revisionId) {
991+
const filteredItemCount = Object.keys(this.items).length
992+
this.setUmmItemCount(filteredItemCount)
993+
}
972994
}
973995

974996
/**

0 commit comments

Comments
 (0)