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

CMR-10128: Adding metadata xml file back to assets #354

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions src/domains/__tests__/collections.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ describe("collectionsToStac", () => {
roles: ["metadata"],
title: "S3 credentials API endpoint documentation",
},
metadata: {
href: "undefined/search/concepts/C00000000-TEST_PROV.xml",
roles: ["metadata"],
title: "CMR XML metadata for C00000000-TEST_PROV",
type: "application/xml",
},
});
});
});
Expand Down Expand Up @@ -107,25 +113,45 @@ describe("collectionsToStac", () => {
roles: ["metadata"],
title: "S3 credentials API endpoint documentation",
},
metadata: {
href: "undefined/search/concepts/C00000000-TEST_PROV.xml",
roles: ["metadata"],
title: "CMR XML metadata for C00000000-TEST_PROV",
type: "application/xml",
},
});
});
});
});

describe("given a collection without direct distribution information", () => {
it("should return a STAC collection with empty assets", () => {
it("should return a STAC collection with only the xml metadata asset", () => {
const [base] = generateCollections(1);
const malformed: any = { ...base, directDistributionInformation: {} };

expect(collectionToStac(malformed as any)).to.have.deep.property("assets", {});
expect(collectionToStac(malformed as any)).to.have.deep.property("assets", {
metadata: {
href: "undefined/search/concepts/C00000000-TEST_PROV.xml",
roles: ["metadata"],
title: "CMR XML metadata for C00000000-TEST_PROV",
type: "application/xml",
},
});
});
});

describe("given a collection with null direct distribution information", () => {
it("should return a STAC collection with empty assets", () => {
it("should return a STAC collection with only the xml metadata asset", () => {
const [base] = generateCollections(1);
base.directDistributionInformation = null;
expect(collectionToStac(base)).to.have.deep.property("assets", {});
expect(collectionToStac(base)).to.have.deep.property("assets", {
metadata: {
href: "undefined/search/concepts/C00000000-TEST_PROV.xml",
roles: ["metadata"],
title: "CMR XML metadata for C00000000-TEST_PROV",
type: "application/xml",
},
});
});
});

Expand Down
18 changes: 18 additions & 0 deletions src/domains/__tests__/items.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ describe("granuleToStac", () => {
description: "Browse image for Earthdata Search",
roles: ["thumbnail"],
},
metadata: {
href: "undefined/search/concepts/G000000000-TEST_PROV.xml",
roles: ["metadata"],
title: "CMR XML metadata for G000000000-TEST_PROV",
type: "application/xml",
},
},
});
});
Expand Down Expand Up @@ -169,6 +175,12 @@ describe("granuleToStac", () => {
description: "Browse image for Earthdata Search",
roles: ["thumbnail"],
},
metadata: {
href: "undefined/search/concepts/G000000000-TEST_PROV.xml",
roles: ["metadata"],
title: "CMR XML metadata for G000000000-TEST_PROV",
type: "application/xml",
},
},
});
});
Expand Down Expand Up @@ -246,6 +258,12 @@ describe("granuleToStac", () => {
description: "Browse image for Earthdata Search",
roles: ["thumbnail"],
},
metadata: {
href: "undefined/search/concepts/G000000000-TEST_PROV.xml",
roles: ["metadata"],
title: "CMR XML metadata for G000000000-TEST_PROV",
type: "application/xml",
},
},
});
});
Expand Down
25 changes: 24 additions & 1 deletion src/domains/stac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { dateTimeToRange } from "../utils/datetime";
import { AssetLinks } from "../@types/StacCollection";
import { Collection, Granule, RelatedUrlType } from "../models/GraphQLModels";

const CMR_ROOT = process.env.CMR_URL;

/**
* Return download assets if present.
*/
Expand Down Expand Up @@ -75,6 +77,20 @@ const metadataAssets = (concept: Collection | Granule) => {
}, {} as AssetLinks);
};

/**
* Return the xml metadata asset.
*/
const xmlMetadataAssets = (concept: Collection | Granule) => {
const xmlMetadataAsset: AssetLinks = {};
xmlMetadataAsset[`metadata`] = {
href: `${CMR_ROOT}/search/concepts/${concept.conceptId}.xml`,
title: `CMR XML metadata for ${concept.conceptId}`,
type: "application/xml",
roles: ["metadata"],
};
return { ...metadataAssets, ...xmlMetadataAsset } as AssetLinks;
};

/**
* Return thumbnail assets if present.
*/
Expand Down Expand Up @@ -167,7 +183,14 @@ const s3Assets = (concept: Collection | Granule) => {
return s3Assets;
};

const defaultExtractors = [browseAssets, thumbnailAssets, downloadAssets, metadataAssets, s3Assets];
const defaultExtractors = [
browseAssets,
thumbnailAssets,
downloadAssets,
metadataAssets,
s3Assets,
xmlMetadataAssets,
];

/**
* Given a concept and a list of asset extractors return available assets.
Expand Down
Loading