Skip to content

Commit

Permalink
Feature/hitide UI 29 - change collection cmr calls to graphql (#66)
Browse files Browse the repository at this point in the history
* feature/hitide-ui-29: update changelog

* feature/hitide-ui-29: update hitideConfig profile to uat

---------

Co-authored-by: jbyrne <[email protected]>
  • Loading branch information
jbyrne6 and jbyrne authored Apr 29, 2024
1 parent 560365d commit 275324a
Showing 1 changed file with 55 additions and 43 deletions.
98 changes: 55 additions & 43 deletions src/jpl/utils/SearchDatasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,59 +123,71 @@ define([
return datasets;
}

function getCmrSpatialExtent(datasetObject){
var conceptId = datasetObject["Dataset-PersistentId"]
var secondURL = config.hitide.externalConfigurables.cmrCollectionSearchService + "/" + conceptId + ".umm_json"
return request(secondURL, {
function getAdditionalCmrMetadata(collectionObjectArray) {
var graphqlURL = config.hitide.externalConfigurables.cmrVariableService
var collectionIds = collectionObjectArray.map(function(collectionObject) {
return '"' + collectionObject["Dataset-PersistentId"] + '"'
})
var templateQuery = "{\n collections (conceptId: [{COLLECTION_ID}]) {\n items {\n conceptId\n spatialExtent\n relatedUrls\n }\n }\n}"
var query = templateQuery.replace("{COLLECTION_ID}", collectionIds);
var updatedCollectionObjects = request.post(graphqlURL, {
handleAs: 'json',
withCredentials: config.hitide.externalConfigurables.crossOriginCmrCookies,
headers: {
"X-Requested-With": null
"X-Requested-With": null,
"Content-Type": "application/json"
},
withCredentials: config.hitide.externalConfigurables.crossOriginCmrCookies
data: JSON.stringify({ query: query })
}).then(function(response) {
datasetObject["Dataset-Resolution"] = []
var resolutionAndCoordinateSystemObject = response.SpatialExtent.HorizontalSpatialDomain.ResolutionAndCoordinateSystem
var relatedUrlsArray = response.RelatedUrls
if (resolutionAndCoordinateSystemObject) {
var resolutionObjects = resolutionAndCoordinateSystemObject.HorizontalDataResolution.GenericResolutions
if (resolutionObjects) {
resolutionObjects.forEach(function(resolutionObject) {
var acrossTrack = resolutionObject.XDimension
var alongTrack = resolutionObject.YDimension
var unit = resolutionObject.Unit
datasetObject["Dataset-Resolution"].push({"Dataset-AcrossTrackResolution": acrossTrack, "Dataset-AlongTrackResolution": alongTrack, "Unit": unit})
});
} else {
// Resolution not available by error
datasetObject["Dataset-Resolution"].push({"error": "Not Available"})
}
} else {
// Key [Collection]/SpatialExtent/HorizontalSpatialDomain/ResolutionAndCoordinateSystem does not exist. This likely was intentional to indicate resolution is not applicable to this collection.
datasetObject["Dataset-Resolution"].push({"error": "Not Applicable"})
}
if (relatedUrlsArray) {
var urlDatasetImageUrl = 'https://podaac.jpl.nasa.gov/Podaac/thumbnails/image_not_available.jpg'
for(var i=0; i < relatedUrlsArray.length; i++) {
var currentRelatedUrlObject = relatedUrlsArray[i]
if (currentRelatedUrlObject['Description'] === 'Thumbnail') {
urlDatasetImageUrl = currentRelatedUrlObject['URL']
}
return collectionObjectArray.map(function(collectionObject) {
collectionObject["Dataset-ImageUrl"] = 'https://podaac.jpl.nasa.gov/Podaac/thumbnails/image_not_available.jpg'
var objectWithMetadata = response.data.collections.items.find(function (metadataItem) { return metadataItem.conceptId === collectionObject["Dataset-PersistentId"] })
var databaseCollectionObjectToReturn = collectionObject
if(objectWithMetadata) {
databaseCollectionObjectToReturn = getCmrSpatialExtent(collectionObject, objectWithMetadata)
}
datasetObject["Dataset-ImageUrl"] = urlDatasetImageUrl
}
return datasetObject
})
}

function getAdditionalCmrMetadata(collectionObjectArray) {
var promises = collectionObjectArray.map(function(collectionObject) {
return getCmrSpatialExtent(collectionObject)
return databaseCollectionObjectToReturn
})
})
return all(promises).then(function(resolvedPromises) {
return all(updatedCollectionObjects).then(function(resolvedPromises) {
return resolvedPromises
})
}

function getCmrSpatialExtent(datasetObject, additionalMetadataObject){
datasetObject["Dataset-Resolution"] = []
var resolutionAndCoordinateSystemObject = additionalMetadataObject.spatialExtent.horizontalSpatialDomain.resolutionAndCoordinateSystem
var relatedUrlsArray = additionalMetadataObject.relatedUrls
if (resolutionAndCoordinateSystemObject) {
var resolutionObjects = resolutionAndCoordinateSystemObject.horizontalDataResolution.genericResolutions
if (resolutionObjects) {
resolutionObjects.forEach(function(resolutionObject) {
var acrossTrack = resolutionObject.xdimension
var alongTrack = resolutionObject.ydimension
var unit = resolutionObject.unit
datasetObject["Dataset-Resolution"].push({"Dataset-AcrossTrackResolution": acrossTrack, "Dataset-AlongTrackResolution": alongTrack, "Unit": unit})
});
} else {
// Resolution not available by error
datasetObject["Dataset-Resolution"].push({"error": "Not Available"})
}
} else {
// Key [Collection]/SpatialExtent/HorizontalSpatialDomain/ResolutionAndCoordinateSystem does not exist. This likely was intentional to indicate resolution is not applicable to this collection.
datasetObject["Dataset-Resolution"].push({"error": "Not Applicable"})
}
if (relatedUrlsArray) {
var urlDatasetImageUrl = 'https://podaac.jpl.nasa.gov/Podaac/thumbnails/image_not_available.jpg'
for(var i=0; i < relatedUrlsArray.length; i++) {
var currentRelatedUrlObject = relatedUrlsArray[i]
if (currentRelatedUrlObject.description === 'Thumbnail') {
urlDatasetImageUrl = currentRelatedUrlObject.url
}
}
datasetObject["Dataset-ImageUrl"] = urlDatasetImageUrl
}
return datasetObject
}

function extractCmrFacets(response) {
var preFacets = response.feed.facets;

Expand Down

0 comments on commit 275324a

Please sign in to comment.