Skip to content

Commit

Permalink
CMR-10128: Adding metadata xml file back to assets (#354)
Browse files Browse the repository at this point in the history
* CMR-10128: Adding metadata xml file back to assets

* CMR-10128: Fixing prettier warnings
  • Loading branch information
william-valencia authored Oct 2, 2024
1 parent 55915b0 commit 7482b0e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
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

0 comments on commit 7482b0e

Please sign in to comment.