Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't allow duplicate URLs in Hyrax metadata updates #3592

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions tasks/hyrax-metadata-updates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,20 @@ function addHyraxUrlToUmmG(metadata, hyraxUrl) {
if (metadataCopy.RelatedUrls === undefined) {
metadataCopy.RelatedUrls = [];
}

const url = {
URL: hyraxUrl,
Type: 'USE SERVICE API',
Subtype: 'OPENDAP DATA',
Description: 'OPeNDAP request URL',
};

for (const relatedUrl of metadataCopy.RelatedUrls) {
if (isEqual(relatedUrl, url)) {
return JSON.stringify(metadataCopy, undefined, 2);
}
}

metadataCopy.RelatedUrls.push(url);

return JSON.stringify(metadataCopy, undefined, 2);
Expand Down Expand Up @@ -245,6 +253,13 @@ function addHyraxUrlToEcho10(metadata, hyraxUrl) {
Description: 'OPeNDAP request URL',
Type: 'GET DATA : OPENDAP DATA',
};

for (const resourceUrl of resourceUrls) {
if (isEqual(resourceUrl, url)) {
return generateEcho10XMLString(metadata.Granule);
}
}

resourceUrls.push(url);

metadataCopy.Granule.OnlineResources = {
Expand Down
19 changes: 19 additions & 0 deletions tasks/hyrax-metadata-updates/tests/test-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ test('Test adding OPeNDAP URL to UMM-G file with no related urls', (t) => {
t.is(actual, JSON.stringify(expectedObject, undefined, 2));
});

test('Test adding duplicate OPeNDAP URL to UMM-G file', (t) => {
const data = fs.readFileSync('tests/data/umm-gin.json', 'utf8');
const metadata = JSON.parse(data);
const expected = fs.readFileSync('tests/data/umm-gout.json', 'utf8');
const expectedObject = JSON.parse(expected);
const newMetadata = JSON.parse(addHyraxUrl(metadata, true, 'https://opendap.earthdata.nasa.gov/collections/C1453188197-GES_DISC/granules/GLDAS_CLSM025_D.2.0%3AGLDAS_CLSM025_D.A20141230.020.nc4'));
const actual = addHyraxUrl(newMetadata, true, 'https://opendap.earthdata.nasa.gov/collections/C1453188197-GES_DISC/granules/GLDAS_CLSM025_D.2.0%3AGLDAS_CLSM025_D.A20141230.020.nc4');
t.is(actual, JSON.stringify(expectedObject, undefined, 2));
});

test('Test adding OPeNDAP URL to ECHO10 file', async (t) => {
const data = fs.readFileSync('tests/data/echo10in.xml', 'utf8');
const metadata = await (promisify(xml2js.parseString))(data, xmlParseOptions);
Expand Down Expand Up @@ -130,6 +140,15 @@ test('Test adding OPeNDAP URL to ECHO10 file with two OnlineResources', async (t
t.is(actual, expected.trim('\n'));
});

test('Test adding duplicate OPeNDAP URL to ECHO10 file', async (t) => {
const data = fs.readFileSync('tests/data/echo10in.xml', 'utf8');
const metadata = await (promisify(xml2js.parseString))(data, xmlParseOptions);
const expected = fs.readFileSync('tests/data/echo10out.xml', 'utf8');
const newMetadata = await (promisify(xml2js.parseString))(addHyraxUrl(metadata, false, 'https://opendap.earthdata.nasa.gov/collections/C1453188197-GES_DISC/granules/GLDAS_CLSM025_D.2.0%3AGLDAS_CLSM025_D.A20141230.020.nc4'), xmlParseOptions);
const actual = addHyraxUrl(newMetadata, false, 'https://opendap.earthdata.nasa.gov/collections/C1453188197-GES_DISC/granules/GLDAS_CLSM025_D.2.0%3AGLDAS_CLSM025_D.A20141230.020.nc4');
t.is(actual, expected.trim('\n'));
});

test('Test building CMR Search Params with short name and version', (t) => {
const inputSearchParams = {
shortName: 'GLDAS_CLSM025_D',
Expand Down