diff --git a/static/src/js/util/accessMethods/__tests__/buildAccessMethods.test.js b/static/src/js/util/accessMethods/__tests__/buildAccessMethods.test.js index c3c5dcff0a..5025a65be6 100644 --- a/static/src/js/util/accessMethods/__tests__/buildAccessMethods.test.js +++ b/static/src/js/util/accessMethods/__tests__/buildAccessMethods.test.js @@ -1,15 +1,30 @@ import { buildAccessMethods } from '../buildAccessMethods' +import * as buildDownload from '../buildAccessMethods/buildDownload' +import * as buildSwodlr from '../buildAccessMethods/buildSwodlr' +import * as buildHarmony from '../buildAccessMethods/buildHarmony' +import * as buildOpendap from '../buildAccessMethods/buildOpendap' +import * as buildEsiEcho from '../buildAccessMethods/buildEsiEcho' + import * as getApplicationConfig from '../../../../../../sharedUtils/config' beforeEach(() => { jest.spyOn(getApplicationConfig, 'getApplicationConfig').mockImplementation(() => ({ - disableOrdering: 'false' + disableOrdering: 'false', + disableSwodlr: 'false' })) }) -describe('buildAccessMethods', () => { - test('returns a download access method', () => { +afterEach(() => { + jest.clearAllMocks() +}) + +describe('when buildAccessMethods is called', () => { + test('calls buildDownload access method', () => { + const buildDownloadMock = jest.spyOn(buildDownload, 'buildDownload') + + buildDownloadMock.mockImplementationOnce(() => jest.fn()) + const collectionMetadata = { granules: { items: [{ @@ -19,297 +34,275 @@ describe('buildAccessMethods', () => { } const isOpenSearch = false - const methods = buildAccessMethods(collectionMetadata, isOpenSearch) - - expect(methods).toEqual({ - download: { - isValid: true, - type: 'download' - } - }) - }) - - test('returns a download access method for open search', () => { - const collectionMetadata = {} - const isOpenSearch = true + buildAccessMethods(collectionMetadata, isOpenSearch) - const methods = buildAccessMethods(collectionMetadata, isOpenSearch) + expect(buildDownloadMock).toBeCalledTimes(1) - expect(methods).toEqual({ - download: { - isValid: true, - type: 'download' - } - }) + expect(buildDownloadMock).toBeCalledWith({ items: [{ online_access_flag: true }] }, false) }) - test('returns an esi access method', () => { + test('calls buildEsiEcho access method with type ECHO ORDERS', () => { + const buildEsiEchoMock = jest.spyOn(buildEsiEcho, 'buildEsiEcho') + const collectionMetadata = { services: { - items: [{ - type: 'ESI', - url: { - urlValue: 'https://example.com' + items: [ + { + type: 'ECHO ORDERS', + url: { + urlValue: 'https://example.com' + }, + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { + conceptId: 'OO10000-EDSC', + name: 'mock form', + form: 'mock form' + } + ] + } }, - orderOptions: { - items: [{ - conceptId: 'OO10000-EDSC', - name: 'mock form', - form: 'mock form' - }] + { + type: 'ECHO ORDERS', + url: { + urlValue: 'https://example.com' + }, + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { + conceptId: 'OO10001-EDSC', + name: 'mock form', + form: 'mock form' + } + ] + } } - }] + ] } } const isOpenSearch = false - const methods = buildAccessMethods(collectionMetadata, isOpenSearch) + buildAccessMethods(collectionMetadata, isOpenSearch) - expect(methods).toEqual({ - esi0: { - form: 'mock form', - formDigest: '75f9480053e9ba083665951820d17ae5c2139d92', - optionDefinition: { - conceptId: 'OO10000-EDSC', - name: 'mock form' - }, - type: 'ESI', - url: 'https://example.com' - } - }) - }) + expect(buildEsiEchoMock).toBeCalledTimes(2) - test('returns an echo orders access method', () => { - const collectionMetadata = { - services: { - items: [{ - type: 'ECHO ORDERS', - url: { - urlValue: 'https://example.com' - }, - maxItemsPerOrder: 2000, - orderOptions: { - items: [{ + expect(buildEsiEchoMock).toHaveBeenNthCalledWith( + 1, + { + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { conceptId: 'OO10000-EDSC', - name: 'mock form', - form: 'mock form' - }] - } - }] + form: 'mock form', + name: 'mock form' + } + ] + }, + type: 'ECHO ORDERS', + url: { + urlValue: 'https://example.com' + } + }, + { + associatedVariables: {}, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 0 } - } - const isOpenSearch = false + ) - const methods = buildAccessMethods(collectionMetadata, isOpenSearch) - - expect(methods).toEqual({ - echoOrder0: { - form: 'mock form', - formDigest: '75f9480053e9ba083665951820d17ae5c2139d92', - optionDefinition: { - conceptId: 'OO10000-EDSC', - name: 'mock form' + expect(buildEsiEchoMock).toHaveBeenNthCalledWith( + 2, + { + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { + conceptId: 'OO10001-EDSC', + form: 'mock form', + name: 'mock form' + } + ] }, type: 'ECHO ORDERS', - maxItemsPerOrder: 2000, - url: 'https://example.com' + url: { + urlValue: 'https://example.com' + } + }, + { + associatedVariables: {}, + echoIndex: 1, + esiIndex: 0, + harmonyIndex: 0 } - }) + ) }) - describe('when ordering is disabled', () => { - test('no echo-order access method is returned', () => { - jest.spyOn(getApplicationConfig, 'getApplicationConfig').mockImplementation(() => ({ - disableOrdering: 'true' - })) + test('calls buildEsiEcho access method with type ESI', () => { + const buildEsiEchoMock = jest.spyOn(buildEsiEcho, 'buildEsiEcho') - const collectionMetadata = { - services: { - items: [{ - type: 'ECHO ORDERS', + buildEsiEchoMock.mockImplementationOnce(() => jest.fn()) + + const collectionMetadata = { + services: { + items: [ + { + type: 'ESI', url: { urlValue: 'https://example.com' }, maxItemsPerOrder: 2000, orderOptions: { - items: [{ - conceptId: 'OO10000-EDSC', - name: 'mock form', - form: 'mock form' - }] + items: [ + { + conceptId: 'OO10000-EDSC', + name: 'mock form', + form: 'mock form' + } + ] } - }] - } + } + ] } - const isOpenSearch = false + } + const isOpenSearch = false - const methods = buildAccessMethods(collectionMetadata, isOpenSearch) + buildAccessMethods(collectionMetadata, isOpenSearch) - expect(methods).toEqual({}) - }) + expect(buildEsiEchoMock).toBeCalledTimes(1) + + expect(buildEsiEchoMock).toHaveBeenCalledWith( + { + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { + conceptId: 'OO10000-EDSC', + form: 'mock form', + name: 'mock form' + } + ] + }, + type: 'ESI', + url: { + urlValue: 'https://example.com' + } + }, + { + associatedVariables: {}, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 0 + } + ) }) - test('returns a harmony access method', () => { + test('calls buildHarmony access method', () => { + const buildHarmonyMock = jest.spyOn(buildHarmony, 'buildHarmony') + + buildHarmonyMock.mockImplementationOnce(() => jest.fn()) + const collectionMetadata = { services: { - items: [{ - conceptId: 'S100000-EDSC', - longName: 'Mock Service Name', - name: 'mock-name', - type: 'Harmony', - url: { - description: 'Mock URL', - urlValue: 'https://example.com' - }, - serviceOptions: { - subset: { - spatialSubset: { - boundingBox: { - allowMultipleValues: false + items: [ + { + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true } }, - variableSubset: { - allowMultipleValues: true - } + aggregation: { + concatenate: { + concatenateDefault: true + } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }] }, - aggregation: { - concatenate: { - concatenateDefault: true + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' } - }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { - projectionName: 'Geographic' - }], - interpolationTypes: [ - 'Bilinear Interpolation', - 'Nearest Neighbor' ], - supportedReformattings: [{ - supportedInputFormat: 'NETCDF-4', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ] - }, { - supportedInputFormat: 'GEOTIFF', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ] - }] - }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { - projectionName: 'Geographic' - }], - supportedReformattings: [{ - supportedInputFormat: 'NETCDF-4', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ] - }, { - supportedInputFormat: 'GEOTIFF', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ] - }], - variables: { - count: 0, - items: null + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }], + variables: { + count: 0, + items: null + } } - }] + ] }, variables: { count: 4, - items: [{ - conceptId: 'V100000-EDSC', - definition: 'Alpha channel value', - longName: 'Alpha channel ', - name: 'alpha_var', - nativeId: 'mmt_variable_3972', - scienceKeywords: null - }, { - conceptId: 'V100001-EDSC', - definition: 'Blue channel value', - longName: 'Blue channel', - name: 'blue_var', - nativeId: 'mmt_variable_3971', - scienceKeywords: null - }, { - conceptId: 'V100002-EDSC', - definition: 'Green channel value', - longName: 'Green channel', - name: 'green_var', - nativeId: 'mmt_variable_3970', - scienceKeywords: null - }, { - conceptId: 'V100003-EDSC', - definition: 'Red channel value', - longName: 'Red Channel', - name: 'red_var', - nativeId: 'mmt_variable_3969', - scienceKeywords: null - }] - } - } - const isOpenSearch = false - - const methods = buildAccessMethods(collectionMetadata, isOpenSearch) - - expect(methods).toEqual({ - harmony0: { - enableTemporalSubsetting: true, - enableSpatialSubsetting: true, - hierarchyMappings: [ - { - id: 'V100000-EDSC' - }, - { - id: 'V100001-EDSC' - }, + items: [ { - id: 'V100002-EDSC' - }, - { - id: 'V100003-EDSC' - } - ], - id: 'S100000-EDSC', - isValid: true, - keywordMappings: [], - longName: 'Mock Service Name', - name: 'mock-name', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ], - supportedOutputProjections: [], - supportsBoundingBoxSubsetting: true, - supportsShapefileSubsetting: false, - supportsTemporalSubsetting: false, - supportsVariableSubsetting: true, - supportsConcatenation: true, - defaultConcatenation: true, - enableConcatenateDownload: true, - type: 'Harmony', - url: 'https://example.com', - variables: { - 'V100000-EDSC': { conceptId: 'V100000-EDSC', definition: 'Alpha channel value', longName: 'Alpha channel ', @@ -317,7 +310,7 @@ describe('buildAccessMethods', () => { nativeId: 'mmt_variable_3972', scienceKeywords: null }, - 'V100001-EDSC': { + { conceptId: 'V100001-EDSC', definition: 'Blue channel value', longName: 'Blue channel', @@ -325,7 +318,7 @@ describe('buildAccessMethods', () => { nativeId: 'mmt_variable_3971', scienceKeywords: null }, - 'V100002-EDSC': { + { conceptId: 'V100002-EDSC', definition: 'Green channel value', longName: 'Green channel', @@ -333,7 +326,7 @@ describe('buildAccessMethods', () => { nativeId: 'mmt_variable_3970', scienceKeywords: null }, - 'V100003-EDSC': { + { conceptId: 'V100003-EDSC', definition: 'Red channel value', longName: 'Red Channel', @@ -341,107 +334,434 @@ describe('buildAccessMethods', () => { nativeId: 'mmt_variable_3969', scienceKeywords: null } + ] + } + } + const isOpenSearch = false + + buildAccessMethods(collectionMetadata, isOpenSearch) + + expect(buildHarmonyMock).toBeCalledTimes(1) + + expect(buildHarmonyMock).toHaveBeenNthCalledWith( + 1, + { + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + serviceOptions: { + aggregation: { + concatenate: { + concatenateDefault: true + } + }, + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + subset: { + spatialSubset: { boundingBox: { allowMultipleValues: false } }, + variableSubset: { allowMultipleValues: true } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ], + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + variables: { + count: 0, + items: null } + }, + { + associatedVariables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null + }, + { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + }, + { + conceptId: 'V100003-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3969', + scienceKeywords: null + } + ] + }, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 0 } - }) + ) }) - test('returns an opendap access method', () => { + test('calls buildOpendap access method', () => { + const buildOpendapMock = jest.spyOn(buildOpendap, 'buildOpendap') + + buildOpendapMock.mockImplementationOnce(() => jest.fn()) + const collectionMetadata = { services: { - items: [{ - conceptId: 'S100000-EDSC', - longName: 'Mock Service Name', - name: 'mock-name', - type: 'OPeNDAP', - url: { - description: 'Mock URL', - urlValue: 'https://example.com' + items: [ + { + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + type: 'OPeNDAP', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + serviceOptions: { + supportedInputProjections: [ + { + projectionName: 'Geographic' + } + ], + supportedOutputProjections: [ + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'ASCII', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'BINARY', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + } + ], + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + } + }, + supportedOutputProjections: [ + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'ASCII', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'BINARY', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + } + ], + orderOptions: { + count: 0, + items: null + }, + variables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'analysed_sst in units of kelvin', + longName: 'analysed_sst', + name: 'analysed_sst', + nativeId: 'e2eTestVarHiRes1', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100001-EDSC', + definition: 'analysis_error in units of kelvin', + longName: 'analysis_error', + name: 'analysis_error', + nativeId: 'e2eTestVarHiRes2', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100002-EDSC', + definition: 'mask in units of seconds since 1981-0', + longName: 'mask', + name: 'mask', + nativeId: 'e2eTestVarHiRes4', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100003-EDSC', + definition: 'sea_ice_fraction in units of fraction (between 0 ', + longName: 'sea_ice_fraction', + name: 'sea_ice_fraction', + nativeId: 'e2eTestVarHiRes3', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + } + ] + } + } + ] + } + } + const isOpenSearch = false + + buildAccessMethods(collectionMetadata, isOpenSearch) + + expect(buildOpendapMock).toBeCalledTimes(1) + + expect(buildOpendapMock).toBeCalledWith( + { + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + orderOptions: { + count: 0, + items: null + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } }, - serviceOptions: { - supportedInputProjections: [{ + supportedInputProjections: [ + { projectionName: 'Geographic' - }], - supportedOutputProjections: [{ + } + ], + supportedOutputProjections: [ + { projectionName: 'Geographic' - }], - supportedReformattings: [{ + } + ], + supportedReformattings: [ + { supportedInputFormat: 'ASCII', supportedOutputFormats: [ 'ASCII', 'BINARY', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'BINARY', supportedOutputFormats: [ 'ASCII', 'BINARY', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'ASCII', 'BINARY', 'NETCDF-4' ] - }], - subset: { - spatialSubset: { - boundingBox: { - allowMultipleValues: false - } - }, - variableSubset: { - allowMultipleValues: true - } } - }, - supportedOutputProjections: [{ + ] + }, + supportedOutputProjections: [ + { projectionName: 'Geographic' - }], - supportedReformattings: [{ + } + ], + supportedReformattings: [ + { supportedInputFormat: 'ASCII', supportedOutputFormats: [ 'ASCII', 'BINARY', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'BINARY', supportedOutputFormats: [ 'ASCII', 'BINARY', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'ASCII', 'BINARY', 'NETCDF-4' ] - }], - orderOptions: { - count: 0, - items: null - }, - variables: { - count: 4, - items: [{ + } + ], + type: 'OPeNDAP', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + variables: { + count: 4, + items: [ + { conceptId: 'V100000-EDSC', definition: 'analysed_sst in units of kelvin', longName: 'analysed_sst', name: 'analysed_sst', nativeId: 'e2eTestVarHiRes1', - scienceKeywords: [{ - category: 'Earth Science', - topic: 'Oceans', - term: 'Ocean Temperature', - variableLevel1: 'Sea Surface Temperature' - }] - }, { + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { conceptId: 'V100001-EDSC', definition: 'analysis_error in units of kelvin', longName: 'analysis_error', @@ -450,133 +770,123 @@ describe('buildAccessMethods', () => { scienceKeywords: [ { category: 'Earth Science', - topic: 'Oceans', term: 'Ocean Temperature', + topic: 'Oceans', variableLevel1: 'Sea Surface Temperature' } ] - }, { + }, + { conceptId: 'V100002-EDSC', definition: 'mask in units of seconds since 1981-0', longName: 'mask', name: 'mask', nativeId: 'e2eTestVarHiRes4', - scienceKeywords: [{ - category: 'Earth Science', - topic: 'Oceans', - term: 'Ocean Temperature', - variableLevel1: 'Sea Surface Temperature' - }] - }, { + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { conceptId: 'V100003-EDSC', definition: 'sea_ice_fraction in units of fraction (between 0 ', longName: 'sea_ice_fraction', name: 'sea_ice_fraction', nativeId: 'e2eTestVarHiRes3', - scienceKeywords: [{ - category: 'Earth Science', - topic: 'Oceans', - term: 'Ocean Temperature', - variableLevel1: 'Sea Surface Temperature' - }] - }] - } - }] - } - } - const isOpenSearch = false - - const methods = buildAccessMethods(collectionMetadata, isOpenSearch) - - expect(methods).toEqual({ - opendap: { - hierarchyMappings: [{ - id: 'V100000-EDSC' - }, { - id: 'V100001-EDSC' - }, { - id: 'V100002-EDSC' - }, { - id: 'V100003-EDSC' - }], - id: 'S100000-EDSC', - isValid: true, - keywordMappings: [{ - children: [{ - id: 'V100000-EDSC' - }, { - id: 'V100001-EDSC' - }, { - id: 'V100002-EDSC' - }, { - id: 'V100003-EDSC' - }], - label: 'Sea Surface Temperature' - }], - longName: 'Mock Service Name', - name: 'mock-name', - supportedOutputFormats: ['ASCII', 'BINARY', 'NETCDF-4'], - supportsVariableSubsetting: true, - type: 'OPeNDAP', - variables: { - 'V100000-EDSC': { - conceptId: 'V100000-EDSC', - definition: 'analysed_sst in units of kelvin', - longName: 'analysed_sst', - name: 'analysed_sst', - nativeId: 'e2eTestVarHiRes1', - scienceKeywords: [{ - category: 'Earth Science', - topic: 'Oceans', - term: 'Ocean Temperature', - variableLevel1: 'Sea Surface Temperature' - }] - }, - 'V100001-EDSC': { - conceptId: 'V100001-EDSC', - definition: 'analysis_error in units of kelvin', - longName: 'analysis_error', - name: 'analysis_error', - nativeId: 'e2eTestVarHiRes2', - scienceKeywords: [{ - category: 'Earth Science', - topic: 'Oceans', - term: 'Ocean Temperature', - variableLevel1: 'Sea Surface Temperature' - }] - }, - 'V100002-EDSC': { - conceptId: 'V100002-EDSC', - definition: 'mask in units of seconds since 1981-0', - longName: 'mask', - name: 'mask', - nativeId: 'e2eTestVarHiRes4', - scienceKeywords: [{ - category: 'Earth Science', - topic: 'Oceans', - term: 'Ocean Temperature', - variableLevel1: 'Sea Surface Temperature' - }] - }, - 'V100003-EDSC': { - conceptId: 'V100003-EDSC', - definition: 'sea_ice_fraction in units of fraction (between 0 ', - longName: 'sea_ice_fraction', - name: 'sea_ice_fraction', - nativeId: 'e2eTestVarHiRes3', - scienceKeywords: [{ - category: 'Earth Science', - topic: 'Oceans', - term: 'Ocean Temperature', - variableLevel1: 'Sea Surface Temperature' - }] - } + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + } + ] } + }, + { + associatedVariables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'analysed_sst in units of kelvin', + longName: 'analysed_sst', + name: 'analysed_sst', + nativeId: 'e2eTestVarHiRes1', + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100001-EDSC', + definition: 'analysis_error in units of kelvin', + longName: 'analysis_error', + name: 'analysis_error', + nativeId: 'e2eTestVarHiRes2', + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100002-EDSC', + definition: 'mask in units of seconds since 1981-0', + longName: 'mask', + name: 'mask', + nativeId: 'e2eTestVarHiRes4', + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100003-EDSC', + definition: 'sea_ice_fraction in units of fraction (between 0 ', + longName: 'sea_ice_fraction', + name: 'sea_ice_fraction', + nativeId: 'e2eTestVarHiRes3', + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + } + ] + }, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 0 } - }) + ) }) - test('returns a swodlr access method', () => { + test('calls buildSwodlr access method', () => { + const buildSwodlrMock = jest.spyOn(buildSwodlr, 'buildSwodlr') + + buildSwodlrMock.mockImplementationOnce(() => jest.fn()) + const collectionMetadata = { services: { items: [ @@ -621,79 +931,55 @@ describe('buildAccessMethods', () => { } const isOpenSearch = false - const methods = buildAccessMethods(collectionMetadata, isOpenSearch) + buildAccessMethods(collectionMetadata, isOpenSearch) + + expect(buildSwodlrMock).toBeCalledTimes(1) - expect(methods).toEqual({ - swodlr: { - id: 'S100000-EDSC', - isValid: true, + expect(buildSwodlrMock).toHaveBeenCalledWith( + { + conceptId: 'S100000-EDSC', longName: 'Mock PODAAC SWOT On-Demand Level 2 Raster Generation (SWODLR)', name: 'Mock PODAAC_SWODLR', - supportsSwodlr: true, - type: 'SWODLR', - url: 'https://swodlr.podaac.earthdatacloud.nasa.gov' - } - }) - }) - - describe('when swodlr is disabled', () => { - test('no swodlr access method is returned', () => { - jest.spyOn(getApplicationConfig, 'getApplicationConfig').mockImplementation(() => ({ - disableSwodlr: 'true' - })) - - const collectionMetadata = { - services: { - items: [ + orderOptions: { + items: [] + }, + serviceOptions: { + supportedOutputProjections: [ { - conceptId: 'S100000-EDSC', - longName: 'Mock PODAAC SWOT On-Demand Level 2 Raster Generation (SWODLR)', - name: 'Mock PODAAC_SWODLR', - type: 'SWODLR', - url: { - description: 'Service top-level URL', - urlValue: 'https://swodlr.podaac.earthdatacloud.nasa.gov' - }, - serviceOptions: { - supportedOutputProjections: [ - { - projectionName: 'Universal Transverse Mercator' - }, - { - projectionName: 'WGS84 - World Geodetic System 1984' - } - ] - }, - supportedOutputProjections: [ - { - projectionName: 'Universal Transverse Mercator' - }, - { - projectionName: 'WGS84 - World Geodetic System 1984' - } - ], - supportedReformattings: null, - supportedInputProjections: null, - orderOptions: { - items: [] - }, - variables: { - items: [] - } + projectionName: 'Universal Transverse Mercator' + }, + { + projectionName: 'WGS84 - World Geodetic System 1984' } ] + }, + supportedInputProjections: null, + supportedOutputProjections: [ + { + projectionName: 'Universal Transverse Mercator' + }, + { + projectionName: 'WGS84 - World Geodetic System 1984' + } + ], + supportedReformattings: null, + type: 'SWODLR', + url: { + description: 'Service top-level URL', + urlValue: 'https://swodlr.podaac.earthdatacloud.nasa.gov' + }, + variables: { + items: [] } } - const isOpenSearch = false - - const methods = buildAccessMethods(collectionMetadata, isOpenSearch) - - expect(methods).toEqual({}) - }) + ) }) - describe('when the collection contains both variables associated to its services and variables directly associated to the collection', () => { - test('variables on the service are returned instead of variables directly associated to the collection', () => { + describe('when the collection contains both variables associated to its services and variables directly associated to the collection and 3 service records', () => { + test('variables on the service are returned instead of variables directly associated to the collection and buildHarmony is called 3 times', () => { + const buildHarmonyMock = jest.spyOn(buildHarmony, 'buildHarmony') + buildHarmonyMock.mockImplementationOnce(() => jest.fn()) + const collectionMetadata = { services: { items: [{ @@ -716,16 +1002,49 @@ describe('buildAccessMethods', () => { allowMultipleValues: true } }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { - projectionName: 'Geographic' - }], + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], interpolationTypes: [ 'Bilinear Interpolation', 'Nearest Neighbor' ], - supportedReformattings: [{ + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'GEOTIFF', @@ -733,7 +1052,8 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'GEOTIFF', supportedOutputFormats: [ 'GEOTIFF', @@ -741,63 +1061,46 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }] - }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { - projectionName: 'Geographic' - }], - supportedReformattings: [{ - supportedInputFormat: 'NETCDF-4', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ] - }, { - supportedInputFormat: 'GEOTIFF', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ] - }], + }], variables: { count: 4, - items: [{ - conceptId: 'V100000-EDSC', - definition: 'Alpha channel value', - longName: 'Alpha channel ', - name: 'alpha_var', - nativeId: 'mmt_variable_3972', - scienceKeywords: null - }, { - conceptId: 'V100001-EDSC', - definition: 'Blue channel value', - longName: 'Blue channel', - name: 'blue_var', - nativeId: 'mmt_variable_3971', - scienceKeywords: null - }, { - conceptId: 'V100002-EDSC', - definition: 'Green channel value', - longName: 'Green channel', - name: 'green_var', - nativeId: 'mmt_variable_3970', - scienceKeywords: null - }, { - conceptId: 'V100003-EDSC', - definition: 'Red channel value', - longName: 'Red Channel', - name: 'red_var', - nativeId: 'mmt_variable_3969', - scienceKeywords: null - }] + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null + }, + { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + }, + { + conceptId: 'V100003-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3969', + scienceKeywords: null + } + ] } - }, { + }, + { conceptId: 'S100001-EDSC', longName: 'Mock Service Name 2', name: 'mock-name 2', @@ -817,16 +1120,49 @@ describe('buildAccessMethods', () => { allowMultipleValues: true } }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { - projectionName: 'Geographic' - }], + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], interpolationTypes: [ 'Bilinear Interpolation', 'Nearest Neighbor' ], - supportedReformattings: [{ + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'GEOTIFF', @@ -834,7 +1170,8 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'GEOTIFF', supportedOutputFormats: [ 'GEOTIFF', @@ -842,61 +1179,43 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }] - }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { - projectionName: 'Geographic' - }], - supportedReformattings: [{ - supportedInputFormat: 'NETCDF-4', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ] - }, { - supportedInputFormat: 'GEOTIFF', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ] - }], + }], variables: { count: 4, - items: [{ - conceptId: 'V100006-EDSC', - definition: 'Alpha channel value', - longName: 'Alpha channel ', - name: 'alpha_var', - nativeId: 'mmt_variable_3973', - scienceKeywords: null - }, { - conceptId: 'V100007-EDSC', - definition: 'Blue channel value', - longName: 'Blue channel', - name: 'blue_var', - nativeId: 'mmt_variable_3974', - scienceKeywords: null - }, { - conceptId: 'V100008-EDSC', - definition: 'Green channel value', - longName: 'Green channel', - name: 'green_var', - nativeId: 'mmt_variable_3975', - scienceKeywords: null - }, { - conceptId: 'V100009-EDSC', - definition: 'Red channel value', - longName: 'Red Channel', - name: 'red_var', - nativeId: 'mmt_variable_3966', - scienceKeywords: null - }] + items: [ + { + conceptId: 'V100006-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3973', + scienceKeywords: null + }, + { + conceptId: 'V100007-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3974', + scienceKeywords: null + }, + { + conceptId: 'V100008-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3975', + scienceKeywords: null + }, + { + conceptId: 'V100009-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3966', + scienceKeywords: null + } + ] } }, { @@ -919,16 +1238,49 @@ describe('buildAccessMethods', () => { allowMultipleValues: true } }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { - projectionName: 'Geographic' - }], + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], interpolationTypes: [ 'Bilinear Interpolation', 'Nearest Neighbor' ], - supportedReformattings: [{ + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'GEOTIFF', @@ -936,7 +1288,8 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'GEOTIFF', supportedOutputFormats: [ 'GEOTIFF', @@ -944,247 +1297,14 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }] - }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { - projectionName: 'Geographic' - }], - supportedReformattings: [{ - supportedInputFormat: 'NETCDF-4', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ] - }, { - supportedInputFormat: 'GEOTIFF', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ] - }] + } + ] }] }, variables: { count: 3, - items: [{ - conceptId: 'V100003-EDSC', - definition: 'Beta channel value', - longName: 'Beta channel ', - name: 'beta_var', - nativeId: 'mmt_variable_4972', - scienceKeywords: null - }, { - conceptId: 'V100004-EDSC', - definition: 'Orange channel value', - longName: 'Orange channel', - name: 'orange_var', - nativeId: 'mmt_variable_4971', - scienceKeywords: null - }, { - conceptId: 'V100005-EDSC', - definition: 'Purple channel value', - longName: 'Purple channel', - name: 'purple_var', - nativeId: 'mmt_variable_4970', - scienceKeywords: null - }] - } - } - const isOpenSearch = false - - const methods = buildAccessMethods(collectionMetadata, isOpenSearch) - - expect(methods).toEqual({ - harmony0: { - defaultConcatenation: false, - enableConcatenateDownload: false, - enableTemporalSubsetting: true, - enableSpatialSubsetting: true, - hierarchyMappings: [ - { - id: 'V100000-EDSC' - }, - { - id: 'V100001-EDSC' - }, - { - id: 'V100002-EDSC' - }, - { - id: 'V100003-EDSC' - } - ], - id: 'S100000-EDSC', - isValid: true, - keywordMappings: [], - longName: 'Mock Service Name', - name: 'mock-name', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ], - supportedOutputProjections: [], - supportsBoundingBoxSubsetting: true, - supportsConcatenation: false, - supportsShapefileSubsetting: false, - supportsTemporalSubsetting: false, - supportsVariableSubsetting: true, - type: 'Harmony', - url: 'https://example.com', - variables: { - 'V100000-EDSC': { - conceptId: 'V100000-EDSC', - definition: 'Alpha channel value', - longName: 'Alpha channel ', - name: 'alpha_var', - nativeId: 'mmt_variable_3972', - scienceKeywords: null - }, - 'V100001-EDSC': { - conceptId: 'V100001-EDSC', - definition: 'Blue channel value', - longName: 'Blue channel', - name: 'blue_var', - nativeId: 'mmt_variable_3971', - scienceKeywords: null - }, - 'V100002-EDSC': { - conceptId: 'V100002-EDSC', - definition: 'Green channel value', - longName: 'Green channel', - name: 'green_var', - nativeId: 'mmt_variable_3970', - scienceKeywords: null - }, - 'V100003-EDSC': { - conceptId: 'V100003-EDSC', - definition: 'Red channel value', - longName: 'Red Channel', - name: 'red_var', - nativeId: 'mmt_variable_3969', - scienceKeywords: null - } - } - }, - harmony1: { - defaultConcatenation: false, - enableConcatenateDownload: false, - enableTemporalSubsetting: true, - enableSpatialSubsetting: true, - hierarchyMappings: [ - { - id: 'V100006-EDSC' - }, - { - id: 'V100007-EDSC' - }, - { - id: 'V100008-EDSC' - }, - { - id: 'V100009-EDSC' - } - ], - id: 'S100001-EDSC', - isValid: true, - keywordMappings: [], - longName: 'Mock Service Name 2', - name: 'mock-name 2', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ], - supportedOutputProjections: [], - supportsBoundingBoxSubsetting: true, - supportsConcatenation: false, - supportsShapefileSubsetting: false, - supportsTemporalSubsetting: false, - supportsVariableSubsetting: true, - type: 'Harmony', - url: 'https://example2.com', - variables: { - 'V100006-EDSC': { - conceptId: 'V100006-EDSC', - definition: 'Alpha channel value', - longName: 'Alpha channel ', - name: 'alpha_var', - nativeId: 'mmt_variable_3973', - scienceKeywords: null - }, - 'V100007-EDSC': { - conceptId: 'V100007-EDSC', - definition: 'Blue channel value', - longName: 'Blue channel', - name: 'blue_var', - nativeId: 'mmt_variable_3974', - scienceKeywords: null - }, - 'V100008-EDSC': { - conceptId: 'V100008-EDSC', - definition: 'Green channel value', - longName: 'Green channel', - name: 'green_var', - nativeId: 'mmt_variable_3975', - scienceKeywords: null - }, - 'V100009-EDSC': { - conceptId: 'V100009-EDSC', - definition: 'Red channel value', - longName: 'Red Channel', - name: 'red_var', - nativeId: 'mmt_variable_3966', - scienceKeywords: null - } - } - }, - // Harmony2 contains the default variables in the coll -> var association - harmony2: { - defaultConcatenation: false, - enableConcatenateDownload: false, - enableTemporalSubsetting: true, - enableSpatialSubsetting: true, - hierarchyMappings: [ - { - id: 'V100003-EDSC' - }, - { - id: 'V100004-EDSC' - }, + items: [ { - id: 'V100005-EDSC' - } - ], - id: 'S100002-EDSC', - isValid: true, - keywordMappings: [], - longName: 'Mock Service Name 3', - name: 'mock-name 3', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ], - supportedOutputProjections: [], - supportsBoundingBoxSubsetting: true, - supportsConcatenation: false, - supportsShapefileSubsetting: false, - supportsTemporalSubsetting: false, - supportsVariableSubsetting: true, - type: 'Harmony', - url: 'https://example3.com', - variables: { - 'V100003-EDSC': { conceptId: 'V100003-EDSC', definition: 'Beta channel value', longName: 'Beta channel ', @@ -1192,7 +1312,7 @@ describe('buildAccessMethods', () => { nativeId: 'mmt_variable_4972', scienceKeywords: null }, - 'V100004-EDSC': { + { conceptId: 'V100004-EDSC', definition: 'Orange channel value', longName: 'Orange channel', @@ -1200,7 +1320,7 @@ describe('buildAccessMethods', () => { nativeId: 'mmt_variable_4971', scienceKeywords: null }, - 'V100005-EDSC': { + { conceptId: 'V100005-EDSC', definition: 'Purple channel value', longName: 'Purple channel', @@ -1208,46 +1328,41 @@ describe('buildAccessMethods', () => { nativeId: 'mmt_variable_4970', scienceKeywords: null } - } + ] } - }) - }) - }) + } + const isOpenSearch = false - describe('when the collection contains variables directly associated to the collection and no variables associated to it services (empty)', () => { - test('variables on the collection are returned instead of variables associated to the service', () => { - const collectionMetadata = { - services: { - items: [{ - conceptId: 'S100000-EDSC', - longName: 'Mock Service Name', - name: 'mock-name', - type: 'Harmony', - url: { - description: 'Mock URL', - urlValue: 'https://example.com' + buildAccessMethods(collectionMetadata, isOpenSearch) + + expect(buildHarmonyMock).toBeCalledTimes(3) + + expect(buildHarmonyMock).toHaveBeenNthCalledWith( + 1, + { + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + serviceOptions: { + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + subset: { + spatialSubset: { boundingBox: { allowMultipleValues: false } }, + variableSubset: { allowMultipleValues: true } }, - serviceOptions: { - subset: { - spatialSubset: { - boundingBox: { - allowMultipleValues: false - } - }, - variableSubset: { - allowMultipleValues: true - } - }, - supportedOutputProjections: [{ + supportedOutputProjections: [ + { projectionName: 'Polar Stereographic' - }, { + }, + { projectionName: 'Geographic' - }], - interpolationTypes: [ - 'Bilinear Interpolation', - 'Nearest Neighbor' - ], - supportedReformattings: [{ + + } + ], + supportedReformattings: [ + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'GEOTIFF', @@ -1255,7 +1370,8 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'GEOTIFF', supportedOutputFormats: [ 'GEOTIFF', @@ -1264,13 +1380,17 @@ describe('buildAccessMethods', () => { 'NETCDF-4' ] }] - }, - supportedOutputProjections: [{ + }, + supportedOutputProjections: [ + { projectionName: 'Polar Stereographic' - }, { + }, + { projectionName: 'Geographic' - }], - supportedReformattings: [{ + } + ], + supportedReformattings: [ + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'GEOTIFF', @@ -1278,7 +1398,8 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'GEOTIFF', supportedOutputFormats: [ 'GEOTIFF', @@ -1286,41 +1407,121 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }], - variables: { - count: 0, - items: [] } - }, { - conceptId: 'S100001-EDSC', - longName: 'Mock Service Name 2', - name: 'mock-name 2', - type: 'Harmony', - url: { - description: 'Mock URL', - urlValue: 'https://example2.com' - }, - serviceOptions: { - subset: { - spatialSubset: { - boundingBox: { - allowMultipleValues: false - } - }, - variableSubset: { - allowMultipleValues: true - } + ], + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + variables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null + }, + { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + }, + { + conceptId: 'V100003-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3969', + scienceKeywords: null + } + ] + } + }, + { + associatedVariables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null }, - supportedOutputProjections: [{ + { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + }, + { + conceptId: 'V100003-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3969', + scienceKeywords: null + } + ] + }, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 0 + } + ) + + // Checks also that harmony increments it's index correctly + expect(buildHarmonyMock).toHaveBeenNthCalledWith( + 2, + { + conceptId: 'S100001-EDSC', + longName: 'Mock Service Name 2', + name: 'mock-name 2', + serviceOptions: { + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + subset: { + spatialSubset: { boundingBox: { allowMultipleValues: false } }, + variableSubset: { allowMultipleValues: true } + }, + supportedOutputProjections: [ + { projectionName: 'Polar Stereographic' - }, { + }, + { projectionName: 'Geographic' - }], - interpolationTypes: [ - 'Bilinear Interpolation', - 'Nearest Neighbor' - ], - supportedReformattings: [{ + } + ], + supportedReformattings: [ + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'GEOTIFF', @@ -1328,7 +1529,8 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'GEOTIFF', supportedOutputFormats: [ 'GEOTIFF', @@ -1336,14 +1538,19 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }] - }, - supportedOutputProjections: [{ + } + ] + }, + supportedOutputProjections: [ + { projectionName: 'Polar Stereographic' - }, { + }, + { projectionName: 'Geographic' - }], - supportedReformattings: [{ + } + ], + supportedReformattings: [ + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'GEOTIFF', @@ -1351,7 +1558,8 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'GEOTIFF', supportedOutputFormats: [ 'GEOTIFF', @@ -1359,73 +1567,159 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }], - variables: { - count: 4, - items: [] } + ], + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example2.com' }, - { - conceptId: 'S100002-EDSC', - longName: 'Mock Service Name 3', - name: 'mock-name 3', - type: 'Harmony', - url: { - description: 'Mock URL', - urlValue: 'https://example3.com' - }, - serviceOptions: { - subset: { - spatialSubset: { - boundingBox: { - allowMultipleValues: false - } - }, - variableSubset: { - allowMultipleValues: true - } + variables: { + count: 4, + items: [ + { + conceptId: 'V100006-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3973', + scienceKeywords: null }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { - projectionName: 'Geographic' - }], - interpolationTypes: [ - 'Bilinear Interpolation', - 'Nearest Neighbor' - ], - supportedReformattings: [{ - supportedInputFormat: 'NETCDF-4', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ] - }, { - supportedInputFormat: 'GEOTIFF', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ] - }] - }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { - projectionName: 'Geographic' - }], - supportedReformattings: [{ - supportedInputFormat: 'NETCDF-4', + { + conceptId: 'V100007-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3974', + scienceKeywords: null + }, + { + conceptId: 'V100008-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3975', + scienceKeywords: null + }, + { + conceptId: 'V100009-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3966', + scienceKeywords: null + } + ] + } + }, + { + associatedVariables: { + count: 4, + items: [ + { + conceptId: 'V100006-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3973', + scienceKeywords: null + }, + { + conceptId: 'V100007-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3974', + scienceKeywords: null + }, + { + conceptId: 'V100008-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3975', + scienceKeywords: null + }, + { + conceptId: 'V100009-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3966', + scienceKeywords: null + } + ] + }, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 1 + } + ) + + // Checks also that harmony increments it's index correctly + expect(buildHarmonyMock).toHaveBeenNthCalledWith( + 3, + { + conceptId: 'S100002-EDSC', + longName: 'Mock Service Name 3', + name: 'mock-name 3', + serviceOptions: { + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + subset: { + spatialSubset: { boundingBox: { allowMultipleValues: false } }, + variableSubset: { allowMultipleValues: true } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'GEOTIFF', 'PNG', 'TIFF', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'GEOTIFF', supportedOutputFormats: [ 'GEOTIFF', @@ -1433,77 +1727,324 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }] - }] + }], + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example3.com' + } }, - variables: { - count: 3, - items: [{ - conceptId: 'V100003-EDSC', - definition: 'Beta channel value', - longName: 'Beta channel ', - name: 'beta_var', - nativeId: 'mmt_variable_4972', - scienceKeywords: null - }, { - conceptId: 'V100004-EDSC', - definition: 'Orange channel value', - longName: 'Orange channel', - name: 'orange_var', - nativeId: 'mmt_variable_4971', - scienceKeywords: null - }, { - conceptId: 'V100005-EDSC', - definition: 'Purple channel value', - longName: 'Purple channel', - name: 'purple_var', - nativeId: 'mmt_variable_4970', - scienceKeywords: null - }] + { + associatedVariables: { + count: 3, + items: [ + { + conceptId: 'V100003-EDSC', + definition: 'Beta channel value', + longName: 'Beta channel ', + name: 'beta_var', + nativeId: 'mmt_variable_4972', + scienceKeywords: null + }, + { + conceptId: 'V100004-EDSC', + definition: 'Orange channel value', + longName: 'Orange channel', + name: 'orange_var', + nativeId: 'mmt_variable_4971', + scienceKeywords: null + }, + { + conceptId: 'V100005-EDSC', + definition: 'Purple channel value', + longName: 'Purple channel', + name: 'purple_var', + nativeId: 'mmt_variable_4970', + scienceKeywords: null + } + ] + }, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 2 } - } - const isOpenSearch = false + ) + }) + }) - const methods = buildAccessMethods(collectionMetadata, isOpenSearch) + describe('when the collection contains variables directly associated to the collection and no variables associated to it services (empty) and 3 service records', () => { + test('variables on the collection are returned instead of variables associated to the service and buildHarmony is called 3 times', () => { + const buildHarmonyMock = jest.spyOn(buildHarmony, 'buildHarmony') + buildHarmonyMock.mockImplementationOnce(() => jest.fn()) - expect(methods).toEqual({ - harmony0: { - defaultConcatenation: false, - enableConcatenateDownload: false, - enableTemporalSubsetting: true, - enableSpatialSubsetting: true, - hierarchyMappings: [ + const collectionMetadata = { + services: { + items: [ { - id: 'V100003-EDSC' + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ], + variables: { + count: 0, + items: [] + } }, { - id: 'V100004-EDSC' + conceptId: 'S100001-EDSC', + longName: 'Mock Service Name 2', + name: 'mock-name 2', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example2.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + }, + supportedOutputProjections: [ + { + projectionName: + 'Polar Stereographic' + }, + { + projectionName: + 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }] + }, + supportedOutputProjections: [ + { + projectionName: + 'Polar Stereographic' + }, + { + projectionName: + 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ], + variables: { + count: 4, + items: [] + } }, { - id: 'V100005-EDSC' + conceptId: 'S100002-EDSC', + longName: 'Mock Service Name 3', + name: 'mock-name 3', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example3.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + }, + supportedOutputProjections: [ + { + projectionName: + 'Polar Stereographic' + }, + { + projectionName: + 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] } - ], - id: 'S100000-EDSC', - isValid: true, - keywordMappings: [], - longName: 'Mock Service Name', - name: 'mock-name', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ], - supportedOutputProjections: [], - supportsBoundingBoxSubsetting: true, - supportsConcatenation: false, - supportsShapefileSubsetting: false, - supportsTemporalSubsetting: false, - supportsVariableSubsetting: true, - type: 'Harmony', - url: 'https://example.com', - variables: { - 'V100003-EDSC': { + ] + }, + variables: { + count: 3, + items: [ + { conceptId: 'V100003-EDSC', definition: 'Beta channel value', longName: 'Beta channel ', @@ -1511,7 +2052,7 @@ describe('buildAccessMethods', () => { nativeId: 'mmt_variable_4972', scienceKeywords: null }, - 'V100004-EDSC': { + { conceptId: 'V100004-EDSC', definition: 'Orange channel value', longName: 'Orange channel', @@ -1519,7 +2060,7 @@ describe('buildAccessMethods', () => { nativeId: 'mmt_variable_4971', scienceKeywords: null }, - 'V100005-EDSC': { + { conceptId: 'V100005-EDSC', definition: 'Purple channel value', longName: 'Purple channel', @@ -1527,171 +2068,1717 @@ describe('buildAccessMethods', () => { nativeId: 'mmt_variable_4970', scienceKeywords: null } - } - }, - harmony1: { - defaultConcatenation: false, - enableConcatenateDownload: false, - enableTemporalSubsetting: true, - enableSpatialSubsetting: true, - hierarchyMappings: [ - { - id: 'V100003-EDSC' - }, - { - id: 'V100004-EDSC' - }, - { - id: 'V100005-EDSC' + ] + } + } + const isOpenSearch = false + + buildAccessMethods(collectionMetadata, isOpenSearch) + + expect(buildHarmonyMock).toBeCalledTimes(3) + + expect(buildHarmonyMock).toHaveBeenNthCalledWith( + 1, + { + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + serviceOptions: { + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + subset: { + spatialSubset: { boundingBox: { allowMultipleValues: false } }, + variableSubset: { allowMultipleValues: true } + }, + supportedOutputProjections: [ + { + projectionName: + 'Polar Stereographic' + }, + { + projectionName: + 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: + 'Polar Stereographic' + }, + { + projectionName: + 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] } ], - id: 'S100001-EDSC', - isValid: true, - keywordMappings: [], + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + variables: { + count: 0, + items: [] + } + }, + { + associatedVariables: { + count: 3, + items: [ + { + conceptId: 'V100003-EDSC', + definition: 'Beta channel value', + longName: 'Beta channel ', + name: 'beta_var', + nativeId: 'mmt_variable_4972', + scienceKeywords: null + }, + { + conceptId: 'V100004-EDSC', + definition: 'Orange channel value', + longName: 'Orange channel', + name: 'orange_var', + nativeId: 'mmt_variable_4971', + scienceKeywords: null + }, + { + conceptId: 'V100005-EDSC', + definition: 'Purple channel value', + longName: 'Purple channel', + name: 'purple_var', + nativeId: 'mmt_variable_4970', + scienceKeywords: null + } + ] + }, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 0 + } + ) + + expect(buildHarmonyMock).toHaveBeenNthCalledWith( + 2, + { + conceptId: 'S100001-EDSC', longName: 'Mock Service Name 2', name: 'mock-name 2', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' + serviceOptions: { + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + subset: { + spatialSubset: { boundingBox: { allowMultipleValues: false } }, + variableSubset: { allowMultipleValues: true } + }, + supportedOutputProjections: [ + { + projectionName: + 'Polar Stereographic' + }, + { + projectionName: + 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: + 'Polar Stereographic' + }, + { + projectionName: + 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } ], - supportedOutputProjections: [], - supportsBoundingBoxSubsetting: true, - supportsConcatenation: false, - supportsShapefileSubsetting: false, - supportsTemporalSubsetting: false, - supportsVariableSubsetting: true, type: 'Harmony', - url: 'https://example2.com', + url: { + description: 'Mock URL', + urlValue: 'https://example2.com' + }, variables: { - 'V100003-EDSC': { - conceptId: 'V100003-EDSC', - definition: 'Beta channel value', - longName: 'Beta channel ', - name: 'beta_var', - nativeId: 'mmt_variable_4972', - scienceKeywords: null + count: 4, + items: [] + } + }, + { + associatedVariables: { + count: 3, + items: [ + { + conceptId: 'V100003-EDSC', + definition: 'Beta channel value', + longName: 'Beta channel ', + name: 'beta_var', + nativeId: 'mmt_variable_4972', + scienceKeywords: null + }, + { + conceptId: 'V100004-EDSC', + definition: 'Orange channel value', + longName: 'Orange channel', + name: 'orange_var', + nativeId: 'mmt_variable_4971', + scienceKeywords: null + }, + { + conceptId: 'V100005-EDSC', + definition: 'Purple channel value', + longName: 'Purple channel', + name: 'purple_var', + nativeId: 'mmt_variable_4970', + scienceKeywords: null + } + ] + }, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 1 + } + ) + + expect(buildHarmonyMock).toHaveBeenNthCalledWith( + 3, + { + conceptId: 'S100002-EDSC', + longName: 'Mock Service Name 3', + name: 'mock-name 3', + serviceOptions: { + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + subset: { + spatialSubset: { boundingBox: { allowMultipleValues: false } }, + variableSubset: { allowMultipleValues: true } }, - 'V100004-EDSC': { - conceptId: 'V100004-EDSC', - definition: 'Orange channel value', - longName: 'Orange channel', - name: 'orange_var', - nativeId: 'mmt_variable_4971', - scienceKeywords: null + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' }, - 'V100005-EDSC': { - conceptId: 'V100005-EDSC', - definition: 'Purple channel value', - longName: 'Purple channel', - name: 'purple_var', - nativeId: 'mmt_variable_4970', - scienceKeywords: null + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ], + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example3.com' + } + }, + { + associatedVariables: { + count: 3, + items: [ + { + conceptId: 'V100003-EDSC', + definition: 'Beta channel value', + longName: 'Beta channel ', + name: 'beta_var', + nativeId: 'mmt_variable_4972', + scienceKeywords: null + }, + { + conceptId: 'V100004-EDSC', + definition: 'Orange channel value', + longName: 'Orange channel', + name: 'orange_var', + nativeId: 'mmt_variable_4971', + scienceKeywords: null + }, + { + conceptId: 'V100005-EDSC', + definition: 'Purple channel value', + longName: 'Purple channel', + name: 'purple_var', + nativeId: 'mmt_variable_4970', + scienceKeywords: null + } + ] + }, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 2 + } + ) + }) + }) + + describe('when the collection contains variables directly associated to the collection and some variables associated to some services and 3 service records', () => { + test('variables on the collection are returned for services without variables but, variables associated to the service are returned for services that have them and buildHarmony is called 3 times', () => { + const buildHarmonyMock = jest.spyOn(buildHarmony, 'buildHarmony') + buildHarmonyMock.mockImplementationOnce(() => jest.fn()) + + const collectionMetadata = { + services: { + items: [ + { + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ], + variables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null + }, + { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + }, + { + conceptId: 'V100003-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3969', + scienceKeywords: null + } + ] + } + }, + { + conceptId: 'S100001-EDSC', + longName: 'Mock Service Name 2', + name: 'mock-name 2', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example2.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + { + conceptId: 'S100002-EDSC', + longName: 'Mock Service Name 3', + name: 'mock-name 3', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example3.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + } + ] + }, + variables: { + count: 3, + items: [ + { + conceptId: 'V100003-EDSC', + definition: 'Beta channel value', + longName: 'Beta channel ', + name: 'beta_var', + nativeId: 'mmt_variable_4972', + scienceKeywords: null + }, + { + conceptId: 'V100004-EDSC', + definition: 'Orange channel value', + longName: 'Orange channel', + name: 'orange_var', + nativeId: 'mmt_variable_4971', + scienceKeywords: null + }, + { + conceptId: 'V100005-EDSC', + definition: 'Purple channel value', + longName: 'Purple channel', + name: 'purple_var', + nativeId: 'mmt_variable_4970', + scienceKeywords: null + } + ] + } + } + + const isOpenSearch = false + + buildAccessMethods(collectionMetadata, isOpenSearch) + + expect(buildHarmonyMock).toBeCalledTimes(3) + + expect(buildHarmonyMock).toHaveBeenNthCalledWith( + 1, + { + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + serviceOptions: { + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + subset: { + spatialSubset: { boundingBox: { allowMultipleValues: false } }, + variableSubset: { allowMultipleValues: true } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ], + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + variables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null + }, + { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + }, + { + conceptId: 'V100003-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3969', + scienceKeywords: null + } + ] + } + }, + { + associatedVariables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null + }, + { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + }, + { + conceptId: 'V100003-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3969', + scienceKeywords: null + } + ] + }, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 0 + } + ) + + expect(buildHarmonyMock).toHaveBeenNthCalledWith( + 2, + { + conceptId: 'S100001-EDSC', + longName: 'Mock Service Name 2', + name: 'mock-name 2', + serviceOptions: { + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + subset: { + spatialSubset: { boundingBox: { allowMultipleValues: false } }, + variableSubset: { allowMultipleValues: true } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ], + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example2.com' + } + }, + { + associatedVariables: { + count: 3, + items: [ + { + conceptId: 'V100003-EDSC', + definition: 'Beta channel value', + longName: 'Beta channel ', + name: 'beta_var', + nativeId: 'mmt_variable_4972', + scienceKeywords: null + }, + { + conceptId: 'V100004-EDSC', + definition: 'Orange channel value', + longName: 'Orange channel', + name: 'orange_var', + nativeId: 'mmt_variable_4971', + scienceKeywords: null + }, + { + conceptId: 'V100005-EDSC', + definition: 'Purple channel value', + longName: 'Purple channel', + name: 'purple_var', + nativeId: 'mmt_variable_4970', + scienceKeywords: null + } + ] + }, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 1 + } + ) + + expect(buildHarmonyMock).toHaveBeenNthCalledWith( + 3, + { + conceptId: 'S100002-EDSC', + longName: 'Mock Service Name 3', + name: 'mock-name 3', + serviceOptions: { + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + subset: { + spatialSubset: { boundingBox: { allowMultipleValues: false } }, + variableSubset: { allowMultipleValues: true } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ], + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example3.com' + } + }, + { + associatedVariables: { + count: 3, + items: [ + { + conceptId: 'V100003-EDSC', + definition: 'Beta channel value', + longName: 'Beta channel ', + name: 'beta_var', + nativeId: 'mmt_variable_4972', + scienceKeywords: null + }, + { + conceptId: 'V100004-EDSC', + definition: 'Orange channel value', + longName: 'Orange channel', + name: 'orange_var', + nativeId: 'mmt_variable_4971', + scienceKeywords: null + }, + { + conceptId: 'V100005-EDSC', + definition: 'Purple channel value', + longName: 'Purple channel', + name: 'purple_var', + nativeId: 'mmt_variable_4970', + scienceKeywords: null + } + ] + }, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 2 + } + ) + }) + }) + + describe('calls complex compilation of mutliple different access methods', () => { + test('calls all access methods correctly', () => { + const buildEsiEchoMock = jest.spyOn(buildEsiEcho, 'buildEsiEcho') + const buildHarmonyMock = jest.spyOn(buildHarmony, 'buildHarmony') + const buildOpendapMock = jest.spyOn(buildOpendap, 'buildOpendap') + const buildSwodlrMock = jest.spyOn(buildSwodlr, 'buildSwodlr') + + const echoOrderItem1 = { + type: 'ECHO ORDERS', + url: { + urlValue: 'https://example.com' + }, + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { + conceptId: 'OO10000-EDSC', + name: 'mock form', + form: 'mock form' + } + ] + } + } + + const esiItem = { + type: 'ESI', + url: { + urlValue: 'https://example.com' + }, + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { + conceptId: 'OO10001-EDSC', + name: 'mock form', + form: 'mock form' + } + ] + } + } + + const harmonyItem1 = { + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }], + variables: { + count: 0, + items: null + } + } + + const echoOrderItem2 = { + type: 'ECHO ORDERS', + url: { + urlValue: 'https://example.com' + }, + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { + conceptId: 'OO10002-EDSC', + name: 'mock form', + form: 'mock form' + } + ] + } + } + + const opendapItem = { + conceptId: 'S100003-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + type: 'OPeNDAP', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + serviceOptions: { + supportedInputProjections: [ + { + projectionName: 'Geographic' + } + ], + supportedOutputProjections: [ + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'ASCII', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'BINARY', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + } + ], + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + } + }, + supportedOutputProjections: [ + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'ASCII', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'BINARY', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + } + ], + orderOptions: { + count: 0, + items: null + }, + variables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'analysed_sst in units of kelvin', + longName: 'analysed_sst', + name: 'analysed_sst', + nativeId: 'e2eTestVarHiRes1', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100001-EDSC', + definition: 'analysis_error in units of kelvin', + longName: 'analysis_error', + name: 'analysis_error', + nativeId: 'e2eTestVarHiRes2', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100002-EDSC', + definition: 'mask in units of seconds since 1981-0', + longName: 'mask', + name: 'mask', + nativeId: 'e2eTestVarHiRes4', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100003-EDSC', + definition: 'sea_ice_fraction in units of fraction (between 0 ', + longName: 'sea_ice_fraction', + name: 'sea_ice_fraction', + nativeId: 'e2eTestVarHiRes3', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + } + ] + } + } + + const swodlrItem = { + conceptId: 'S100004-EDSC', + longName: 'Mock PODAAC SWOT On-Demand Level 2 Raster Generation (SWODLR)', + name: 'Mock PODAAC_SWODLR', + type: 'SWODLR', + url: { + description: 'Service top-level URL', + urlValue: 'https://swodlr.podaac.earthdatacloud.nasa.gov' + }, + serviceOptions: { + supportedOutputProjections: [ + { + projectionName: 'Universal Transverse Mercator' + }, + { + projectionName: 'WGS84 - World Geodetic System 1984' + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Universal Transverse Mercator' + }, + { + projectionName: 'WGS84 - World Geodetic System 1984' + } + ], + supportedReformattings: null, + supportedInputProjections: null, + orderOptions: { + items: [] + }, + variables: { + items: [] + } + } + + const harmonyItem2 = { + conceptId: 'S100001-EDSC', + longName: 'Mock Service Name 2', + name: 'mock-name 2', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example2.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + }, + supportedOutputProjections: [ + { + projectionName: + 'Polar Stereographic' + }, + { + projectionName: + 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }] + }, + supportedOutputProjections: [ + { + projectionName: + 'Polar Stereographic' + }, + { + projectionName: + 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ], + variables: { + count: 0, + items: [] + } + } + + const collectionMetadata = { + services: { + items: [ + echoOrderItem1, + esiItem, + echoOrderItem2, + harmonyItem1, + opendapItem, + swodlrItem, + harmonyItem2 + ] + }, + variables: { + count: 3, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null + }, + { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + } + ] + } + } + + const isOpenSearch = false + + buildAccessMethods(collectionMetadata, isOpenSearch) + + expect(buildEsiEchoMock).toHaveBeenCalledTimes(3) // Apparently the buildEsiEchoMock gets called 3 times but the first call isn't actually going through the code + expect(buildHarmonyMock).toHaveBeenCalledTimes(2) + expect(buildOpendapMock).toHaveBeenCalledTimes(1) + expect(buildSwodlrMock).toHaveBeenCalledTimes(1) + + const defaultAssociatedVariables = { + count: 3, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null + }, + { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + } + ] + } + + // ESI & Echo Order expected Calls + const echoCall1 = { + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { + conceptId: 'OO10000-EDSC', + form: 'mock form', + name: 'mock form' } - } + ] }, - // Harmony2 contains the default variables in the coll -> var association - harmony2: { - defaultConcatenation: false, - enableConcatenateDownload: false, - enableTemporalSubsetting: true, - enableSpatialSubsetting: true, - hierarchyMappings: [ - { - id: 'V100003-EDSC' - }, - { - id: 'V100004-EDSC' - }, + type: 'ECHO ORDERS', + url: { + urlValue: 'https://example.com' + } + } + + const esiCall = { + maxItemsPerOrder: 2000, + orderOptions: { + items: [ { - id: 'V100005-EDSC' + conceptId: 'OO10001-EDSC', + form: 'mock form', + name: 'mock form' } - ], - id: 'S100002-EDSC', - isValid: true, - keywordMappings: [], - longName: 'Mock Service Name 3', - name: 'mock-name 3', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ], - supportedOutputProjections: [], - supportsBoundingBoxSubsetting: true, - supportsConcatenation: false, - supportsShapefileSubsetting: false, - supportsTemporalSubsetting: false, - supportsVariableSubsetting: true, - type: 'Harmony', - url: 'https://example3.com', - variables: { - 'V100003-EDSC': { - conceptId: 'V100003-EDSC', - definition: 'Beta channel value', - longName: 'Beta channel ', - name: 'beta_var', - nativeId: 'mmt_variable_4972', - scienceKeywords: null - }, - 'V100004-EDSC': { - conceptId: 'V100004-EDSC', - definition: 'Orange channel value', - longName: 'Orange channel', - name: 'orange_var', - nativeId: 'mmt_variable_4971', - scienceKeywords: null - }, - 'V100005-EDSC': { - conceptId: 'V100005-EDSC', - definition: 'Purple channel value', - longName: 'Purple channel', - name: 'purple_var', - nativeId: 'mmt_variable_4970', - scienceKeywords: null + ] + }, + type: 'ESI', + url: { + urlValue: 'https://example.com' + } + } + + const echoCall2 = { + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { + conceptId: 'OO10002-EDSC', + form: 'mock form', + name: 'mock form' } - } + ] + }, + type: 'ECHO ORDERS', + url: { + urlValue: 'https://example.com' } - }) - }) - }) + } - describe('when the collection contains variables directly associated to the collection and some variables associated to some services', () => { - test('variables on the collection are returned for services without variables but, variables associated to the service are returned for services that have them', () => { - const collectionMetadata = { - services: { - items: [{ - conceptId: 'S100000-EDSC', - longName: 'Mock Service Name', - name: 'mock-name', - type: 'Harmony', - url: { - description: 'Mock URL', - urlValue: 'https://example.com' + expect(buildEsiEchoMock).toHaveBeenNthCalledWith( + 1, + echoCall1, + { + associatedVariables: defaultAssociatedVariables, + echoIndex: 0, + esiIndex: 0, + harmonyIndex: 0 + } + ) + + // Increment echoIndex after expecting the esiEchoMethod to have been called for echo orders + expect(buildEsiEchoMock).toHaveBeenNthCalledWith( + 2, + esiCall, + { + associatedVariables: defaultAssociatedVariables, + echoIndex: 1, + esiIndex: 0, + harmonyIndex: 0 + } + ) + + // Increment esiIndex after expecting the esiEchoMethod to have been called for an ESI Order + expect(buildEsiEchoMock).toHaveBeenNthCalledWith( + 3, + echoCall2, + { + associatedVariables: defaultAssociatedVariables, + echoIndex: 1, + esiIndex: 1, + harmonyIndex: 0 + } + ) + + // Increment echoIndex after expecting the esiEchoMethod to have been called for echo orders + expect(buildHarmonyMock).toHaveBeenNthCalledWith( + 1, + { + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + serviceOptions: { + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + subset: { + spatialSubset: { boundingBox: { allowMultipleValues: false } }, + variableSubset: { allowMultipleValues: true } }, - serviceOptions: { - subset: { - spatialSubset: { - boundingBox: { - allowMultipleValues: false - } - }, - variableSubset: { - allowMultipleValues: true - } - }, - supportedOutputProjections: [{ + supportedOutputProjections: [ + { projectionName: 'Polar Stereographic' - }, { + }, + { projectionName: 'Geographic' - }], - interpolationTypes: [ - 'Bilinear Interpolation', - 'Nearest Neighbor' - ], - supportedReformattings: [{ + } + ], + supportedReformattings: [ + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'GEOTIFF', @@ -1699,7 +3786,8 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'GEOTIFF', supportedOutputFormats: [ 'GEOTIFF', @@ -1707,14 +3795,19 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }] - }, - supportedOutputProjections: [{ + } + ] + }, + supportedOutputProjections: [ + { projectionName: 'Polar Stereographic' - }, { + }, + { projectionName: 'Geographic' - }], - supportedReformattings: [{ + } + ], + supportedReformattings: [ + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'GEOTIFF', @@ -1722,7 +3815,8 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'GEOTIFF', supportedOutputFormats: [ 'GEOTIFF', @@ -1730,143 +3824,283 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }], - variables: { - count: 4, - items: [{ - conceptId: 'V100000-EDSC', - definition: 'Alpha channel value', - longName: 'Alpha channel ', - name: 'alpha_var', - nativeId: 'mmt_variable_3972', - scienceKeywords: null - }, { - conceptId: 'V100001-EDSC', - definition: 'Blue channel value', - longName: 'Blue channel', - name: 'blue_var', - nativeId: 'mmt_variable_3971', - scienceKeywords: null - }, { - conceptId: 'V100002-EDSC', - definition: 'Green channel value', - longName: 'Green channel', - name: 'green_var', - nativeId: 'mmt_variable_3970', - scienceKeywords: null - }, { - conceptId: 'V100003-EDSC', - definition: 'Red channel value', - longName: 'Red Channel', - name: 'red_var', - nativeId: 'mmt_variable_3969', - scienceKeywords: null - }] } - }, { - conceptId: 'S100001-EDSC', - longName: 'Mock Service Name 2', - name: 'mock-name 2', - type: 'Harmony', - url: { - description: 'Mock URL', - urlValue: 'https://example2.com' - }, - serviceOptions: { - subset: { - spatialSubset: { - boundingBox: { - allowMultipleValues: false - } - }, - variableSubset: { - allowMultipleValues: true + ], + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + variables: { + count: 0, + items: null + } + }, + { + associatedVariables: defaultAssociatedVariables, + echoIndex: 2, + esiIndex: 1, + harmonyIndex: 0 + } + ) + + expect(buildOpendapMock).toHaveBeenNthCalledWith( + 1, + { + conceptId: 'S100003-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + orderOptions: { + count: 0, + items: null + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false } }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { + variableSubset: { + allowMultipleValues: true + } + }, + supportedInputProjections: [ + { projectionName: 'Geographic' - }], - interpolationTypes: [ - 'Bilinear Interpolation', - 'Nearest Neighbor' - ], - supportedReformattings: [{ - supportedInputFormat: 'NETCDF-4', + } + ], + supportedOutputProjections: [ + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'ASCII', supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', + 'ASCII', + 'BINARY', 'NETCDF-4' ] - }, { - supportedInputFormat: 'GEOTIFF', + }, + { + supportedInputFormat: 'BINARY', supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', + 'ASCII', + 'BINARY', 'NETCDF-4' ] - }] - }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { + }, + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { projectionName: 'Geographic' - }], - supportedReformattings: [{ - supportedInputFormat: 'NETCDF-4', + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'ASCII', supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', + 'ASCII', + 'BINARY', 'NETCDF-4' ] - }, { - supportedInputFormat: 'GEOTIFF', + }, + { + supportedInputFormat: 'BINARY', supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', 'NETCDF-4' ] - }], - variables: { - count: 4, - items: [] } + ], + type: 'OPeNDAP', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' }, - { - conceptId: 'S100002-EDSC', - longName: 'Mock Service Name 3', - name: 'mock-name 3', - type: 'Harmony', - url: { - description: 'Mock URL', - urlValue: 'https://example3.com' - }, - serviceOptions: { - subset: { - spatialSubset: { - boundingBox: { - allowMultipleValues: false + variables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'analysed_sst in units of kelvin', + longName: 'analysed_sst', + name: 'analysed_sst', + nativeId: 'e2eTestVarHiRes1', + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' } - }, - variableSubset: { - allowMultipleValues: true - } + ] + }, + { + conceptId: 'V100001-EDSC', + definition: 'analysis_error in units of kelvin', + longName: 'analysis_error', + name: 'analysis_error', + nativeId: 'e2eTestVarHiRes2', + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100002-EDSC', + definition: 'mask in units of seconds since 1981-0', + longName: 'mask', + name: 'mask', + nativeId: 'e2eTestVarHiRes4', + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100003-EDSC', + definition: 'sea_ice_fraction in units of fraction (between 0 ', + longName: 'sea_ice_fraction', + name: 'sea_ice_fraction', + nativeId: 'e2eTestVarHiRes3', + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + } + ] + } + }, + { + associatedVariables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'analysed_sst in units of kelvin', + longName: 'analysed_sst', + name: 'analysed_sst', + nativeId: 'e2eTestVarHiRes1', + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100001-EDSC', + definition: 'analysis_error in units of kelvin', + longName: 'analysis_error', + name: 'analysis_error', + nativeId: 'e2eTestVarHiRes2', + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100002-EDSC', + definition: 'mask in units of seconds since 1981-0', + longName: 'mask', + name: 'mask', + nativeId: 'e2eTestVarHiRes4', + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] }, - supportedOutputProjections: [{ + { + conceptId: 'V100003-EDSC', + definition: 'sea_ice_fraction in units of fraction (between 0 ', + longName: 'sea_ice_fraction', + name: 'sea_ice_fraction', + nativeId: 'e2eTestVarHiRes3', + scienceKeywords: [ + { + category: 'Earth Science', + term: 'Ocean Temperature', + topic: 'Oceans', + variableLevel1: 'Sea Surface Temperature' + } + ] + } + ] + }, + echoIndex: 2, + esiIndex: 1, + harmonyIndex: 1 + } + ) + + expect(buildHarmonyMock).toHaveBeenNthCalledWith( + 2, + { + conceptId: 'S100001-EDSC', + longName: 'Mock Service Name 2', + name: 'mock-name 2', + serviceOptions: { + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + subset: { + spatialSubset: { boundingBox: { allowMultipleValues: false } }, + variableSubset: { allowMultipleValues: true } + }, + supportedOutputProjections: [ + { projectionName: 'Polar Stereographic' - }, { + }, + { projectionName: 'Geographic' - }], - interpolationTypes: [ - 'Bilinear Interpolation', - 'Nearest Neighbor' - ], - supportedReformattings: [{ + } + ], + supportedReformattings: [ + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'GEOTIFF', @@ -1874,7 +4108,8 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'GEOTIFF', supportedOutputFormats: [ 'GEOTIFF', @@ -1882,14 +4117,20 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: + 'Polar Stereographic' }, - supportedOutputProjections: [{ - projectionName: 'Polar Stereographic' - }, { + { projectionName: 'Geographic' - }], - supportedReformattings: [{ + } + ], + supportedReformattings: [ + { supportedInputFormat: 'NETCDF-4', supportedOutputFormats: [ 'GEOTIFF', @@ -1897,7 +4138,8 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }, { + }, + { supportedInputFormat: 'GEOTIFF', supportedOutputFormats: [ 'GEOTIFF', @@ -1905,239 +4147,65 @@ describe('buildAccessMethods', () => { 'TIFF', 'NETCDF-4' ] - }] - }] - }, - variables: { - count: 3, - items: [{ - conceptId: 'V100003-EDSC', - definition: 'Beta channel value', - longName: 'Beta channel ', - name: 'beta_var', - nativeId: 'mmt_variable_4972', - scienceKeywords: null - }, { - conceptId: 'V100004-EDSC', - definition: 'Orange channel value', - longName: 'Orange channel', - name: 'orange_var', - nativeId: 'mmt_variable_4971', - scienceKeywords: null - }, { - conceptId: 'V100005-EDSC', - definition: 'Purple channel value', - longName: 'Purple channel', - name: 'purple_var', - nativeId: 'mmt_variable_4970', - scienceKeywords: null - }] - } - } - const isOpenSearch = false - - const methods = buildAccessMethods(collectionMetadata, isOpenSearch) - - expect(methods).toEqual({ - harmony0: { - defaultConcatenation: false, - enableConcatenateDownload: false, - enableTemporalSubsetting: true, - enableSpatialSubsetting: true, - hierarchyMappings: [ - { - id: 'V100000-EDSC' - }, - { - id: 'V100001-EDSC' - }, - { - id: 'V100002-EDSC' - }, - { - id: 'V100003-EDSC' - } - ], - id: 'S100000-EDSC', - isValid: true, - keywordMappings: [], - longName: 'Mock Service Name', - name: 'mock-name', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ], - supportedOutputProjections: [], - supportsBoundingBoxSubsetting: true, - supportsConcatenation: false, - supportsShapefileSubsetting: false, - supportsTemporalSubsetting: false, - supportsVariableSubsetting: true, - type: 'Harmony', - url: 'https://example.com', - variables: { - 'V100000-EDSC': { - conceptId: 'V100000-EDSC', - definition: 'Alpha channel value', - longName: 'Alpha channel ', - name: 'alpha_var', - nativeId: 'mmt_variable_3972', - scienceKeywords: null - }, - 'V100001-EDSC': { - conceptId: 'V100001-EDSC', - definition: 'Blue channel value', - longName: 'Blue channel', - name: 'blue_var', - nativeId: 'mmt_variable_3971', - scienceKeywords: null - }, - 'V100002-EDSC': { - conceptId: 'V100002-EDSC', - definition: 'Green channel value', - longName: 'Green channel', - name: 'green_var', - nativeId: 'mmt_variable_3970', - scienceKeywords: null - }, - 'V100003-EDSC': { - conceptId: 'V100003-EDSC', - definition: 'Red channel value', - longName: 'Red Channel', - name: 'red_var', - nativeId: 'mmt_variable_3969', - scienceKeywords: null - } - } - }, - harmony1: { - defaultConcatenation: false, - enableConcatenateDownload: false, - enableTemporalSubsetting: true, - enableSpatialSubsetting: true, - hierarchyMappings: [ - { - id: 'V100003-EDSC' - }, - { - id: 'V100004-EDSC' - }, - { - id: 'V100005-EDSC' } ], - id: 'S100001-EDSC', - isValid: true, - keywordMappings: [], - longName: 'Mock Service Name 2', - name: 'mock-name 2', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ], - supportedOutputProjections: [], - supportsBoundingBoxSubsetting: true, - supportsConcatenation: false, - supportsShapefileSubsetting: false, - supportsTemporalSubsetting: false, - supportsVariableSubsetting: true, type: 'Harmony', - url: 'https://example2.com', + url: { + description: 'Mock URL', + urlValue: 'https://example2.com' + }, variables: { - 'V100003-EDSC': { - conceptId: 'V100003-EDSC', - definition: 'Beta channel value', - longName: 'Beta channel ', - name: 'beta_var', - nativeId: 'mmt_variable_4972', - scienceKeywords: null - }, - 'V100004-EDSC': { - conceptId: 'V100004-EDSC', - definition: 'Orange channel value', - longName: 'Orange channel', - name: 'orange_var', - nativeId: 'mmt_variable_4971', - scienceKeywords: null - }, - 'V100005-EDSC': { - conceptId: 'V100005-EDSC', - definition: 'Purple channel value', - longName: 'Purple channel', - name: 'purple_var', - nativeId: 'mmt_variable_4970', - scienceKeywords: null - } + count: 0, + items: [] } }, - // Harmony2 contains the default variables in the coll -> var association - harmony2: { - defaultConcatenation: false, - enableConcatenateDownload: false, - enableTemporalSubsetting: true, - enableSpatialSubsetting: true, - hierarchyMappings: [ - { - id: 'V100003-EDSC' - }, + { + associatedVariables: defaultAssociatedVariables, + echoIndex: 2, + esiIndex: 1, + harmonyIndex: 1 + } + ) + + expect(buildSwodlrMock).toHaveBeenNthCalledWith( + 1, + { + conceptId: 'S100004-EDSC', + longName: 'Mock PODAAC SWOT On-Demand Level 2 Raster Generation (SWODLR)', + name: 'Mock PODAAC_SWODLR', + orderOptions: { + items: [] + }, + serviceOptions: { + supportedOutputProjections: [ + { + projectionName: 'Universal Transverse Mercator' + }, + { + projectionName: 'WGS84 - World Geodetic System 1984' + } + ] + }, + supportedInputProjections: null, + supportedOutputProjections: [ { - id: 'V100004-EDSC' + projectionName: 'Universal Transverse Mercator' }, { - id: 'V100005-EDSC' + projectionName: 'WGS84 - World Geodetic System 1984' } ], - id: 'S100002-EDSC', - isValid: true, - keywordMappings: [], - longName: 'Mock Service Name 3', - name: 'mock-name 3', - supportedOutputFormats: [ - 'GEOTIFF', - 'PNG', - 'TIFF', - 'NETCDF-4' - ], - supportedOutputProjections: [], - supportsBoundingBoxSubsetting: true, - supportsConcatenation: false, - supportsShapefileSubsetting: false, - supportsTemporalSubsetting: false, - supportsVariableSubsetting: true, - type: 'Harmony', - url: 'https://example3.com', + supportedReformattings: null, + type: 'SWODLR', + url: { + description: 'Service top-level URL', + urlValue: 'https://swodlr.podaac.earthdatacloud.nasa.gov' + }, variables: { - 'V100003-EDSC': { - conceptId: 'V100003-EDSC', - definition: 'Beta channel value', - longName: 'Beta channel ', - name: 'beta_var', - nativeId: 'mmt_variable_4972', - scienceKeywords: null - }, - 'V100004-EDSC': { - conceptId: 'V100004-EDSC', - definition: 'Orange channel value', - longName: 'Orange channel', - name: 'orange_var', - nativeId: 'mmt_variable_4971', - scienceKeywords: null - }, - 'V100005-EDSC': { - conceptId: 'V100005-EDSC', - definition: 'Purple channel value', - longName: 'Purple channel', - name: 'purple_var', - nativeId: 'mmt_variable_4970', - scienceKeywords: null - } + items: [] } } - }) + ) }) }) }) diff --git a/static/src/js/util/accessMethods/buildAccessMethods.js b/static/src/js/util/accessMethods/buildAccessMethods.js index 3d0d2a8100..df97e266a5 100644 --- a/static/src/js/util/accessMethods/buildAccessMethods.js +++ b/static/src/js/util/accessMethods/buildAccessMethods.js @@ -1,16 +1,8 @@ -import { camelCase, uniq } from 'lodash-es' - -import { getApplicationConfig } from '../../../../../sharedUtils/config' - -import { isDownloadable } from '../../../../../sharedUtils/isDownloadable' -import { generateFormDigest } from './generateFormDigest' -import { getVariables } from './getVariables' -import { supportsBoundingBoxSubsetting } from './supportsBoundingBoxSubsetting' -import { supportsConcatenation } from './supportsConcatenation' -import { defaultConcatenation } from './defaultConcatenation' -import { supportsShapefileSubsetting } from './supportsShapefileSubsetting' -import { supportsTemporalSubsetting } from './supportsTemporalSubsetting' -import { supportsVariableSubsetting } from './supportsVariableSubsetting' +import { buildEsiEcho } from './buildAccessMethods/buildEsiEcho' +import { buildOpendap } from './buildAccessMethods/buildOpendap' +import { buildHarmony } from './buildAccessMethods/buildHarmony' +import { buildSwodlr } from './buildAccessMethods/buildSwodlr' +import { buildDownload } from './buildAccessMethods/buildDownload' /** * Builds the different access methods available for the provided collection @@ -25,25 +17,27 @@ export const buildAccessMethods = (collectionMetadata, isOpenSearch) => { variables: collectionAssociatedVariables = {} } = collectionMetadata - const accessMethods = {} let harmonyIndex = 0 + let echoIndex = 0 + let esiIndex = 0 + const { items: serviceItems = null } = services - const { disableOrdering, disableSwodlr } = getApplicationConfig() + const buildMethods = { + esi: (serviceItem, params) => buildEsiEcho(serviceItem, params), + 'echo orders': (serviceItem, params) => buildEsiEcho(serviceItem, params), + opendap: (serviceItem, params) => buildOpendap(serviceItem, params), + harmony: (serviceItem, params) => buildHarmony(serviceItem, params), + swodlr: (serviceItem) => buildSwodlr(serviceItem), + downloads: () => buildDownload(granules, isOpenSearch) + } - if (serviceItems !== null) { - serviceItems.forEach((serviceItem) => { + const nonDownloadMethods = serviceItems === null + ? {} + : serviceItems.reduce((methods, serviceItem) => { let associatedVariables = collectionAssociatedVariables const { - conceptId: serviceConceptId, - description, - orderOptions, type: serviceType, - url, - longName, - maxItemsPerOrder, - name, - supportedReformattings, variables: serviceAssociatedVariables = {} } = serviceItem @@ -52,175 +46,45 @@ export const buildAccessMethods = (collectionMetadata, isOpenSearch) => { associatedVariables = serviceAssociatedVariables } + const lowerServiceType = serviceType.toLowerCase() + // Only process service types that EDSC supports const supportedServiceTypes = ['esi', 'echo orders', 'opendap', 'harmony', 'swodlr'] - if (!supportedServiceTypes.includes(serviceType.toLowerCase())) return - - const { urlValue } = url - - const supportsOrderOptions = ['esi', 'echo orders'] - - // Only process orderOptions if the service type uses orderOptions - // Do not include access if orders are disabled - if (supportsOrderOptions.includes(serviceType.toLowerCase()) && (disableOrdering !== 'true')) { - const { items: orderOptionsItems } = orderOptions - if (orderOptionsItems === null) return - - orderOptionsItems.forEach((orderOptionItem, orderOptionIndex) => { - const { - conceptId: orderOptionConceptId, - form, - name: orderOptionName - } = orderOptionItem - - const method = { - type: serviceType, - maxItemsPerOrder, - url: urlValue, - optionDefinition: { - conceptId: orderOptionConceptId, - name: orderOptionName - }, - form, - formDigest: generateFormDigest(form) - } - - let methodKey = camelCase(serviceType) - - // `echoOrders` needs to be singular to match existing savedAccessConfigurations - if (methodKey === 'echoOrders') { - methodKey = 'echoOrder' - } - - accessMethods[`${methodKey}${orderOptionIndex}`] = method - }) - } + if (!supportedServiceTypes.includes(lowerServiceType)) return {} - if (serviceType.toLowerCase() === 'opendap') { - const { - hierarchyMappings, - keywordMappings, - variables - } = getVariables(associatedVariables) - - const outputFormats = [] - - if (supportedReformattings) { - supportedReformattings.forEach((reformatting) => { - const { supportedOutputFormats } = reformatting - - // Collect all supported output formats from each mapping - outputFormats.push(...supportedOutputFormats) - }) - } - - accessMethods.opendap = { - hierarchyMappings, - id: serviceConceptId, - isValid: true, - keywordMappings, - longName, - name, - supportedOutputFormats: uniq(outputFormats), - supportsVariableSubsetting: supportsVariableSubsetting(serviceItem), - type: serviceType, - variables - } + const params = { + harmonyIndex, + echoIndex, + esiIndex, + associatedVariables } - if (serviceType.toLowerCase() === 'harmony') { - const { - hierarchyMappings, - keywordMappings, - variables - } = getVariables(associatedVariables) - const { - supportedOutputProjections - } = serviceItem - - const outputFormats = [] - - if (supportedReformattings) { - supportedReformattings.forEach((reformatting) => { - const { supportedOutputFormats } = reformatting - - // Collect all supported output formats from each mapping - outputFormats.push(...supportedOutputFormats) - }) - } - - let outputProjections = [] - if (supportedOutputProjections) { - outputProjections = supportedOutputProjections.filter((projection) => { - const { projectionAuthority } = projection - - return projectionAuthority != null - }).map((projection) => { - const { projectionAuthority } = projection - - return projectionAuthority - }) - } - - accessMethods[`harmony${harmonyIndex}`] = { - description, - enableTemporalSubsetting: true, - enableSpatialSubsetting: true, - hierarchyMappings, - id: serviceConceptId, - isValid: true, - keywordMappings, - longName, - name, - supportedOutputFormats: uniq(outputFormats), - supportedOutputProjections: outputProjections, - supportsBoundingBoxSubsetting: supportsBoundingBoxSubsetting(serviceItem), - supportsShapefileSubsetting: supportsShapefileSubsetting(serviceItem), - supportsTemporalSubsetting: supportsTemporalSubsetting(serviceItem), - supportsVariableSubsetting: supportsVariableSubsetting(serviceItem), - supportsConcatenation: supportsConcatenation(serviceItem), - defaultConcatenation: defaultConcatenation(serviceItem), - enableConcatenateDownload: defaultConcatenation(serviceItem), - type: serviceType, - url: urlValue, - variables - } + const builtMethod = buildMethods[lowerServiceType](serviceItem, params) - harmonyIndex += 1 - } + const { + accessMethods: newAccessMethods, + esiIndex: newEsiIndex, + echoIndex: newEchoIndex + } = builtMethod - if (serviceType.toLowerCase() === 'swodlr' && (disableSwodlr !== 'true')) { - accessMethods.swodlr = { - id: serviceConceptId, - isValid: true, - longName, - name, - type: serviceType, - supportsSwodlr: true, - url: urlValue - } - } - }) - } + esiIndex = newEsiIndex || esiIndex + echoIndex = newEchoIndex || echoIndex - // Determine if the collection should have the downloadable accessMethod - let onlineAccessFlag = false + const updatedMethods = { + ...methods, + ...newAccessMethods + } - if (granules) { - // If the collection has granules, check their online access flags to - // determine if this collection is downloadable - const { items: granuleItems } = granules + if (lowerServiceType === 'harmony') { + harmonyIndex += 1 + } - if (granuleItems) { - onlineAccessFlag = isDownloadable(granuleItems) - } + return updatedMethods + }, {}) - if (onlineAccessFlag || isOpenSearch) { - accessMethods.download = { - isValid: true, - type: 'download' - } - } + const accessMethods = { + ...nonDownloadMethods, + ...buildMethods.downloads() } return accessMethods diff --git a/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildDownload.test.js b/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildDownload.test.js new file mode 100644 index 0000000000..936dda0011 --- /dev/null +++ b/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildDownload.test.js @@ -0,0 +1,49 @@ +import { buildDownload } from '../buildDownload' + +describe('buildDownload', () => { + test('returns a download access method', () => { + const collectionMetadata = { + granules: { + items: [{ + online_access_flag: true + }] + } + } + const isOpenSearch = false + + const { + granules + } = collectionMetadata + + const method = buildDownload(granules, isOpenSearch) + + expect(method).toEqual( + { + download: { + isValid: true, + type: 'download' + } + } + ) + }) + + test('returns a download access method for open search', () => { + const collectionMetadata = {} + const isOpenSearch = true + + const { + granules = {} + } = collectionMetadata + + const method = buildDownload(granules, isOpenSearch) + + expect(method).toEqual( + { + download: { + isValid: true, + type: 'download' + } + } + ) + }) +}) diff --git a/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildEsiEcho.test.js b/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildEsiEcho.test.js new file mode 100644 index 0000000000..d4d282f79f --- /dev/null +++ b/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildEsiEcho.test.js @@ -0,0 +1,225 @@ +import { buildEsiEcho } from '../buildEsiEcho' + +import * as getApplicationConfig from '../../../../../../../sharedUtils/config' + +beforeEach(() => { + jest.spyOn(getApplicationConfig, 'getApplicationConfig').mockImplementation(() => ({ + disableOrdering: 'false' + })) +}) + +afterEach(() => { + jest.clearAllMocks() +}) + +describe('buildEsiEcho', () => { + test('returns an esi access method', () => { + const collectionMetadata = { + services: { + items: [{ + type: 'ESI', + url: { + urlValue: 'https://example.com' + }, + orderOptions: { + items: [{ + conceptId: 'OO10000-EDSC', + name: 'mock form', + form: 'mock form' + }] + } + }] + } + } + + const { services } = collectionMetadata + const serviceItem = services.items[0] + + const params = { + esiIndex: 0, + echoIndex: 0 + } + + const { + accessMethods: methods, + esiIndex: newEsiIndex, + echoIndex: newEchoIndex + } = buildEsiEcho(serviceItem, params) + + expect(newEsiIndex).toEqual(1) + expect(newEchoIndex).toEqual(0) + + expect(methods).toEqual({ + esi0: { + form: 'mock form', + formDigest: '75f9480053e9ba083665951820d17ae5c2139d92', + optionDefinition: { + conceptId: 'OO10000-EDSC', + name: 'mock form' + }, + type: 'ESI', + url: 'https://example.com' + } + }) + }) + + test('returns an echo orders access method and indexes are incremented correctly', () => { + const collectionMetadata = { + services: { + items: [ + { + type: 'ECHO ORDERS', + url: { + urlValue: 'https://example.com' + }, + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { + conceptId: 'OO10000-EDSC', + name: 'mock form', + form: 'mock form' + }, + { + conceptId: 'OO30000-EDSC', + name: 'mock form', + form: 'mock form' + } + ] + } + }, + { + type: 'ESI', + url: { + urlValue: 'https://example.com' + }, + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { + conceptId: 'OO20000-EDSC', + name: 'mock form', + form: 'mock form' + } + ] + } + } + ] + } + } + + const { services } = collectionMetadata + const serviceItem0 = services.items[0] + const serviceItem1 = services.items[1] + + const params = { + esiIndex: 0, + echoIndex: 0 + } + + const { + accessMethods: echoMethods, + esiIndex: newEsiIndex, + echoIndex: newEchoIndex + } = buildEsiEcho(serviceItem0, params) + + params.esiIndex = newEsiIndex + params.echoIndex = newEchoIndex + + const { + accessMethods: esiMethods, + esiIndex: finalEsiIndex, + echoIndex: finalEchoIndex + } = buildEsiEcho(serviceItem1, params) + + expect(finalEchoIndex).toEqual(2) + expect(finalEsiIndex).toEqual(1) + + expect(echoMethods).toEqual({ + echoOrder0: { + form: 'mock form', + formDigest: '75f9480053e9ba083665951820d17ae5c2139d92', + optionDefinition: { + conceptId: 'OO10000-EDSC', + name: 'mock form' + }, + type: 'ECHO ORDERS', + maxItemsPerOrder: 2000, + url: 'https://example.com' + }, + echoOrder1: { + form: 'mock form', + formDigest: '75f9480053e9ba083665951820d17ae5c2139d92', + optionDefinition: { + conceptId: 'OO30000-EDSC', + name: 'mock form' + }, + type: 'ECHO ORDERS', + maxItemsPerOrder: 2000, + url: 'https://example.com' + } + }) + + expect(esiMethods).toEqual({ + esi0: { + form: 'mock form', + formDigest: '75f9480053e9ba083665951820d17ae5c2139d92', + optionDefinition: { + conceptId: 'OO20000-EDSC', + name: 'mock form' + }, + type: 'ESI', + maxItemsPerOrder: 2000, + url: 'https://example.com' + } + }) + }) + + describe('when ordering is disabled', () => { + test('returns an empty object', () => { + jest.spyOn(getApplicationConfig, 'getApplicationConfig').mockImplementation(() => ({ + disableOrdering: 'true' + })) + + const collectionMetadata = { + services: { + items: [{ + type: 'ECHO ORDERS', + url: { + urlValue: 'https://example.com' + }, + maxItemsPerOrder: 2000, + orderOptions: { + items: [ + { + conceptId: 'OO10000-EDSC', + name: 'mock form', + form: 'mock form' + } + ] + } + }] + } + } + + const { services } = collectionMetadata + const serviceItem = services.items[0] + + const params = { + esiIndex: 0, + echoIndex: 0 + } + + const { + accessMethods: methods, + esiIndex: newEsiIndex, + echoIndex: newEchoIndex + } = buildEsiEcho(serviceItem, params) + + expect(newEsiIndex).toEqual(0) + expect(newEchoIndex).toEqual(0) + + expect(methods).toEqual({}) + }) + }) +}) diff --git a/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildHarmony.test.js b/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildHarmony.test.js new file mode 100644 index 0000000000..0cd9ab541c --- /dev/null +++ b/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildHarmony.test.js @@ -0,0 +1,844 @@ +import { buildHarmony } from '../buildHarmony' + +describe('buildHarmony', () => { + test('returns a harmony access method', () => { + const collectionMetadata = { + services: { + items: [ + { + description: 'abc123', + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + }, + aggregation: { + concatenate: { + concatenateDefault: true + } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ], + variables: { + count: 0, + items: null + } + } + ] + }, + variables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null + }, + { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + }, + { + conceptId: 'V100003-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3969', + scienceKeywords: null + } + ] + } + } + + const { services, variables: associatedVariables } = collectionMetadata + const serviceItem = services.items[0] + + const harmonyIndex = 0 + + const params = { + associatedVariables, + harmonyIndex + } + + const { accessMethods } = buildHarmony(serviceItem, params) + + expect(accessMethods).toEqual({ + harmony0: { + description: 'abc123', + enableTemporalSubsetting: true, + enableSpatialSubsetting: true, + hierarchyMappings: [ + { + id: 'V100000-EDSC' + }, + { + id: 'V100001-EDSC' + }, + { + id: 'V100002-EDSC' + }, + { + id: 'V100003-EDSC' + } + ], + id: 'S100000-EDSC', + isValid: true, + keywordMappings: [], + longName: 'Mock Service Name', + name: 'mock-name', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ], + supportedOutputProjections: [], + supportsBoundingBoxSubsetting: true, + supportsShapefileSubsetting: false, + supportsTemporalSubsetting: false, + supportsVariableSubsetting: true, + supportsConcatenation: true, + defaultConcatenation: true, + enableConcatenateDownload: true, + type: 'Harmony', + url: 'https://example.com', + variables: { + 'V100000-EDSC': { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null + }, + 'V100001-EDSC': { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + 'V100002-EDSC': { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + }, + 'V100003-EDSC': { + conceptId: 'V100003-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3969', + scienceKeywords: null + } + } + } + }) + }) + + test('correctly builds multiple harmony items', () => { + const collectionMetadata = { + services: { + items: [ + { + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + description: 'Mock Name', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic', + projectionAuthority: 'Polar Stereographic' + }, + { + projectionName: 'Geographic', + projectionAuthority: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ], + variables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null + }, + { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + }, + { + conceptId: 'V100003-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3969', + scienceKeywords: null + } + ] + } + }, + { + conceptId: 'S100001-EDSC', + longName: 'Mock Service Name 2', + name: 'mock-name 2', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example2.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ], + variables: { + count: 4, + items: [ + { + conceptId: 'V100006-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3973', + scienceKeywords: null + }, + { + conceptId: 'V100007-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3974', + scienceKeywords: null + }, + { + conceptId: 'V100008-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3975', + scienceKeywords: null + }, + { + conceptId: 'V100009-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3966', + scienceKeywords: null + } + ] + } + }, + { + conceptId: 'S100002-EDSC', + longName: 'Mock Service Name 3', + name: 'mock-name 3', + type: 'Harmony', + url: { + description: 'Mock URL', + urlValue: 'https://example3.com' + }, + serviceOptions: { + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + interpolationTypes: [ + 'Bilinear Interpolation', + 'Nearest Neighbor' + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Polar Stereographic' + }, + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'GEOTIFF', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ] + } + ] + }] + }, + variables: { + count: 3, + items: [ + { + conceptId: 'V100003-EDSC', + definition: 'Beta channel value', + longName: 'Beta channel ', + name: 'beta_var', + nativeId: 'mmt_variable_4972', + scienceKeywords: null + }, + { + conceptId: 'V100004-EDSC', + definition: 'Orange channel value', + longName: 'Orange channel', + name: 'orange_var', + nativeId: 'mmt_variable_4971', + scienceKeywords: null + }, + { + conceptId: 'V100005-EDSC', + definition: 'Purple channel value', + longName: 'Purple channel', + name: 'purple_var', + nativeId: 'mmt_variable_4970', + scienceKeywords: null + } + ] + } + } + + const { services, variables: collectionAssociatedVariables = {} } = collectionMetadata + const { items: serviceItems = null } = services + + let harmonyIndex = 0 + let methods = {} + + serviceItems.forEach((serviceItem) => { + let associatedVariables = collectionAssociatedVariables + + const { + variables: serviceAssociatedVariables = {} + } = serviceItem + + if (serviceAssociatedVariables.items && serviceAssociatedVariables.items.length > 0) { + associatedVariables = serviceAssociatedVariables + } + + const params = { + associatedVariables, + harmonyIndex + } + + const harmonyResult = buildHarmony(serviceItem, params) + + const { + accessMethods + } = harmonyResult + + methods = { + ...accessMethods, + ...methods + } + + harmonyIndex += 1 + }) + + expect(methods).toEqual( + { + harmony0: { + defaultConcatenation: false, + enableConcatenateDownload: false, + enableTemporalSubsetting: true, + enableSpatialSubsetting: true, + description: 'Mock Name', + hierarchyMappings: [ + { + id: 'V100000-EDSC' + }, + { + id: 'V100001-EDSC' + }, + { + id: 'V100002-EDSC' + }, + { + id: 'V100003-EDSC' + } + ], + id: 'S100000-EDSC', + isValid: true, + keywordMappings: [], + longName: 'Mock Service Name', + name: 'mock-name', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ], + supportedOutputProjections: [ + 'Polar Stereographic', + 'Geographic' + ], + supportsBoundingBoxSubsetting: true, + supportsConcatenation: false, + supportsShapefileSubsetting: false, + supportsTemporalSubsetting: false, + supportsVariableSubsetting: true, + type: 'Harmony', + url: 'https://example.com', + variables: { + 'V100000-EDSC': { + conceptId: 'V100000-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3972', + scienceKeywords: null + }, + 'V100001-EDSC': { + conceptId: 'V100001-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3971', + scienceKeywords: null + }, + 'V100002-EDSC': { + conceptId: 'V100002-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3970', + scienceKeywords: null + }, + 'V100003-EDSC': { + conceptId: 'V100003-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3969', + scienceKeywords: null + } + } + }, + harmony1: { + defaultConcatenation: false, + enableConcatenateDownload: false, + enableTemporalSubsetting: true, + enableSpatialSubsetting: true, + hierarchyMappings: [ + { + id: 'V100006-EDSC' + }, + { + id: 'V100007-EDSC' + }, + { + id: 'V100008-EDSC' + }, + { + id: 'V100009-EDSC' + } + ], + id: 'S100001-EDSC', + isValid: true, + keywordMappings: [], + longName: 'Mock Service Name 2', + name: 'mock-name 2', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ], + supportedOutputProjections: [], + supportsBoundingBoxSubsetting: true, + supportsConcatenation: false, + supportsShapefileSubsetting: false, + supportsTemporalSubsetting: false, + supportsVariableSubsetting: true, + type: 'Harmony', + url: 'https://example2.com', + variables: { + 'V100006-EDSC': { + conceptId: 'V100006-EDSC', + definition: 'Alpha channel value', + longName: 'Alpha channel ', + name: 'alpha_var', + nativeId: 'mmt_variable_3973', + scienceKeywords: null + }, + 'V100007-EDSC': { + conceptId: 'V100007-EDSC', + definition: 'Blue channel value', + longName: 'Blue channel', + name: 'blue_var', + nativeId: 'mmt_variable_3974', + scienceKeywords: null + }, + 'V100008-EDSC': { + conceptId: 'V100008-EDSC', + definition: 'Green channel value', + longName: 'Green channel', + name: 'green_var', + nativeId: 'mmt_variable_3975', + scienceKeywords: null + }, + 'V100009-EDSC': { + conceptId: 'V100009-EDSC', + definition: 'Red channel value', + longName: 'Red Channel', + name: 'red_var', + nativeId: 'mmt_variable_3966', + scienceKeywords: null + } + } + }, + // Harmony2 contains the default variables in the coll -> var association + harmony2: { + defaultConcatenation: false, + enableConcatenateDownload: false, + enableTemporalSubsetting: true, + enableSpatialSubsetting: true, + hierarchyMappings: [ + { + id: 'V100003-EDSC' + }, + { + id: 'V100004-EDSC' + }, + { + id: 'V100005-EDSC' + } + ], + id: 'S100002-EDSC', + isValid: true, + keywordMappings: [], + longName: 'Mock Service Name 3', + name: 'mock-name 3', + supportedOutputFormats: [ + 'GEOTIFF', + 'PNG', + 'TIFF', + 'NETCDF-4' + ], + supportedOutputProjections: [], + supportsBoundingBoxSubsetting: true, + supportsConcatenation: false, + supportsShapefileSubsetting: false, + supportsTemporalSubsetting: false, + supportsVariableSubsetting: true, + type: 'Harmony', + url: 'https://example3.com', + variables: { + 'V100003-EDSC': { + conceptId: 'V100003-EDSC', + definition: 'Beta channel value', + longName: 'Beta channel ', + name: 'beta_var', + nativeId: 'mmt_variable_4972', + scienceKeywords: null + }, + 'V100004-EDSC': { + conceptId: 'V100004-EDSC', + definition: 'Orange channel value', + longName: 'Orange channel', + name: 'orange_var', + nativeId: 'mmt_variable_4971', + scienceKeywords: null + }, + 'V100005-EDSC': { + conceptId: 'V100005-EDSC', + definition: 'Purple channel value', + longName: 'Purple channel', + name: 'purple_var', + nativeId: 'mmt_variable_4970', + scienceKeywords: null + } + } + } + } + ) + }) +}) diff --git a/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildOpendap.test.js b/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildOpendap.test.js new file mode 100644 index 0000000000..7a057939cb --- /dev/null +++ b/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildOpendap.test.js @@ -0,0 +1,296 @@ +import { buildOpendap } from '../buildOpendap' + +describe('buildOpendap', () => { + test('returns an opendap access method', () => { + const collectionMetadata = { + services: { + items: [ + { + conceptId: 'S100000-EDSC', + longName: 'Mock Service Name', + name: 'mock-name', + type: 'OPeNDAP', + url: { + description: 'Mock URL', + urlValue: 'https://example.com' + }, + serviceOptions: { + supportedInputProjections: [ + { + projectionName: 'Geographic' + } + ], + supportedOutputProjections: [ + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'ASCII', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'BINARY', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + } + ], + subset: { + spatialSubset: { + boundingBox: { + allowMultipleValues: false + } + }, + variableSubset: { + allowMultipleValues: true + } + } + }, + supportedOutputProjections: [ + { + projectionName: 'Geographic' + } + ], + supportedReformattings: [ + { + supportedInputFormat: 'ASCII', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'BINARY', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + }, + { + supportedInputFormat: 'NETCDF-4', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ] + } + ], + orderOptions: { + count: 0, + items: null + }, + variables: { + count: 4, + items: [ + { + conceptId: 'V100000-EDSC', + definition: 'analysed_sst in units of kelvin', + longName: 'analysed_sst', + name: 'analysed_sst', + nativeId: 'e2eTestVarHiRes1', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100001-EDSC', + definition: 'analysis_error in units of kelvin', + longName: 'analysis_error', + name: 'analysis_error', + nativeId: 'e2eTestVarHiRes2', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100002-EDSC', + definition: 'mask in units of seconds since 1981-0', + longName: 'mask', + name: 'mask', + nativeId: 'e2eTestVarHiRes4', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + { + conceptId: 'V100003-EDSC', + definition: 'sea_ice_fraction in units of fraction (between 0 ', + longName: 'sea_ice_fraction', + name: 'sea_ice_fraction', + nativeId: 'e2eTestVarHiRes3', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + } + ] + } + } + ] + } + } + + const { services, variables: collectionAssociatedVariables = {} } = collectionMetadata + const serviceItem = services.items[0] + + let associatedVariables = collectionAssociatedVariables + + const { + variables: serviceAssociatedVariables = {} + } = serviceItem + + if (serviceAssociatedVariables.items && serviceAssociatedVariables.items.length > 0) { + associatedVariables = serviceAssociatedVariables + } + + const { accessMethods } = buildOpendap(serviceItem, associatedVariables) + + expect(accessMethods).toEqual({ + opendap: { + hierarchyMappings: [ + { + id: 'V100000-EDSC' + }, + { + id: 'V100001-EDSC' + }, + { + id: 'V100002-EDSC' + }, + { + id: 'V100003-EDSC' + } + ], + id: 'S100000-EDSC', + isValid: true, + keywordMappings: [ + { + children: [ + { + id: 'V100000-EDSC' + }, + { + id: 'V100001-EDSC' + }, + { + id: 'V100002-EDSC' + }, + { + id: 'V100003-EDSC' + } + ], + label: 'Sea Surface Temperature' + } + ], + longName: 'Mock Service Name', + name: 'mock-name', + supportedOutputFormats: [ + 'ASCII', + 'BINARY', + 'NETCDF-4' + ], + supportsVariableSubsetting: true, + type: 'OPeNDAP', + variables: { + 'V100000-EDSC': { + conceptId: 'V100000-EDSC', + definition: 'analysed_sst in units of kelvin', + longName: 'analysed_sst', + name: 'analysed_sst', + nativeId: 'e2eTestVarHiRes1', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + 'V100001-EDSC': { + conceptId: 'V100001-EDSC', + definition: 'analysis_error in units of kelvin', + longName: 'analysis_error', + name: 'analysis_error', + nativeId: 'e2eTestVarHiRes2', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + 'V100002-EDSC': { + conceptId: 'V100002-EDSC', + definition: 'mask in units of seconds since 1981-0', + longName: 'mask', + name: 'mask', + nativeId: 'e2eTestVarHiRes4', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + }, + 'V100003-EDSC': { + conceptId: 'V100003-EDSC', + definition: 'sea_ice_fraction in units of fraction (between 0 ', + longName: 'sea_ice_fraction', + name: 'sea_ice_fraction', + nativeId: 'e2eTestVarHiRes3', + scienceKeywords: [ + { + category: 'Earth Science', + topic: 'Oceans', + term: 'Ocean Temperature', + variableLevel1: 'Sea Surface Temperature' + } + ] + } + } + } + }) + }) +}) diff --git a/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildSwodlr.test.js b/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildSwodlr.test.js new file mode 100644 index 0000000000..3f08f96229 --- /dev/null +++ b/static/src/js/util/accessMethods/buildAccessMethods/__tests__/buildSwodlr.test.js @@ -0,0 +1,133 @@ +import { buildSwodlr } from '../buildSwodlr' + +import * as getApplicationConfig from '../../../../../../../sharedUtils/config' + +beforeEach(() => { + jest.spyOn(getApplicationConfig, 'getApplicationConfig').mockImplementation(() => ({ + disableSwodlr: 'false' + })) +}) + +describe('buildSwodlr', () => { + test('returns an swodlr access method', () => { + const collectionMetadata = { + services: { + items: [ + { + conceptId: 'S100000-EDSC', + longName: 'Mock PODAAC SWOT On-Demand Level 2 Raster Generation (SWODLR)', + name: 'Mock PODAAC_SWODLR', + type: 'SWODLR', + url: { + description: 'Service top-level URL', + urlValue: 'https://swodlr.podaac.earthdatacloud.nasa.gov' + }, + serviceOptions: { + supportedOutputProjections: [ + { + projectionName: 'Universal Transverse Mercator' + }, + { + projectionName: 'WGS84 - World Geodetic System 1984' + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Universal Transverse Mercator' + }, + { + projectionName: 'WGS84 - World Geodetic System 1984' + } + ], + supportedReformattings: null, + supportedInputProjections: null, + orderOptions: { + items: [] + }, + variables: { + items: [] + } + } + ] + } + } + + const { services } = collectionMetadata + const serviceItem = services.items[0] + + const { accessMethods } = buildSwodlr(serviceItem) + + expect(accessMethods).toEqual({ + swodlr: { + id: 'S100000-EDSC', + isValid: true, + longName: 'Mock PODAAC SWOT On-Demand Level 2 Raster Generation (SWODLR)', + name: 'Mock PODAAC_SWODLR', + supportsSwodlr: true, + type: 'SWODLR', + url: 'https://swodlr.podaac.earthdatacloud.nasa.gov' + } + }) + }) + + describe('when swodlr is disabled', () => { + beforeEach(() => { + jest.spyOn(getApplicationConfig, 'getApplicationConfig').mockImplementation(() => ({ + disableSwodlr: 'true' + })) + }) + + test('no swodlr access method is returned', () => { + const collectionMetadata = { + services: { + items: [ + { + conceptId: 'S100000-EDSC', + longName: 'Mock PODAAC SWOT On-Demand Level 2 Raster Generation (SWODLR)', + name: 'Mock PODAAC_SWODLR', + type: 'SWODLR', + url: { + description: 'Service top-level URL', + urlValue: 'https://swodlr.podaac.earthdatacloud.nasa.gov' + }, + serviceOptions: { + supportedOutputProjections: [ + { + projectionName: 'Universal Transverse Mercator' + }, + { + projectionName: 'WGS84 - World Geodetic System 1984' + } + ] + }, + supportedOutputProjections: [ + { + projectionName: 'Universal Transverse Mercator' + }, + { + projectionName: 'WGS84 - World Geodetic System 1984' + } + ], + supportedReformattings: null, + supportedInputProjections: null, + orderOptions: { + items: [] + }, + variables: { + items: [] + } + } + ] + } + } + + const { services } = collectionMetadata + const serviceItem = services.items[0] + + const { accessMethods } = buildSwodlr(serviceItem) + + expect(accessMethods).toEqual({}) + }) + }) +}) diff --git a/static/src/js/util/accessMethods/buildAccessMethods/buildDownload.js b/static/src/js/util/accessMethods/buildAccessMethods/buildDownload.js new file mode 100644 index 0000000000..d8f9ef918a --- /dev/null +++ b/static/src/js/util/accessMethods/buildAccessMethods/buildDownload.js @@ -0,0 +1,33 @@ +import { isDownloadable } from '../../../../../../sharedUtils/isDownloadable' + +/** + * Builds the Downloads access method + * @param {object} granules granules object pulled from the collectionMetdata + * @param {boolean} isOpenSearch Is the collection an open search collection + * @returns {object} Access method for Downloads + */ +export const buildDownload = (granules, isOpenSearch) => { + const accessMethods = {} + + // Determine if the collection should have the downloadable accessMethod + let onlineAccessFlag = false + + if (granules) { + // If the collection has granules, check their online access flags to + // determine if this collection is downloadable + const { items: granuleItems } = granules + + if (granuleItems) { + onlineAccessFlag = isDownloadable(granuleItems) + } + + if (onlineAccessFlag || isOpenSearch) { + accessMethods.download = { + isValid: true, + type: 'download' + } + } + } + + return accessMethods +} diff --git a/static/src/js/util/accessMethods/buildAccessMethods/buildEsiEcho.js b/static/src/js/util/accessMethods/buildAccessMethods/buildEsiEcho.js new file mode 100644 index 0000000000..ecf12130ac --- /dev/null +++ b/static/src/js/util/accessMethods/buildAccessMethods/buildEsiEcho.js @@ -0,0 +1,80 @@ +import { camelCase } from 'lodash-es' + +import { getApplicationConfig } from '../../../../../../sharedUtils/config' + +import { generateFormDigest } from '../generateFormDigest' + +/** + * Builds the ESI or Echo Ordering access method + * @param {object} serviceItem serviceItem in the Collection Metadata + * @param {boolean} disabledOrdering true if ordering is disabled + * @returns {object} Access method for ESI or Echo Orders + */ +export const buildEsiEcho = (serviceItem, params) => { + const accessMethods = {} + // Only process orderOptions if the service type uses orderOptions + // Do not include access if orders are disabled + const { disableOrdering } = getApplicationConfig() + + const { + esiIndex: initEsiIndex, + echoIndex: initEchoIndex + } = params + + let esiIndex = initEsiIndex + let echoIndex = initEchoIndex + + if (disableOrdering !== 'true') { + // Pull out the esi and echo indices and increment them to have an accurate count + const { + orderOptions, + type: serviceType, + url, + maxItemsPerOrder + } = serviceItem + + const { urlValue } = url + + const { items: orderOptionsItems } = orderOptions + + if (orderOptionsItems === null) return {} + + orderOptionsItems.forEach((orderOptionItem) => { + const { + conceptId: orderOptionConceptId, + form, + name: orderOptionName + } = orderOptionItem + + const method = { + type: serviceType, + maxItemsPerOrder, + url: urlValue, + optionDefinition: { + conceptId: orderOptionConceptId, + name: orderOptionName + }, + form, + formDigest: generateFormDigest(form) + } + + let methodKey = camelCase(serviceType) + + // `echoOrders` needs to be singular to match existing savedAccessConfigurations + if (methodKey === 'echoOrders') { + methodKey = 'echoOrder' + accessMethods[`${methodKey}${echoIndex}`] = method + echoIndex += 1 + } else { + accessMethods[`${methodKey}${esiIndex}`] = method + esiIndex += 1 + } + }) + } + + return { + accessMethods, + echoIndex, + esiIndex + } +} diff --git a/static/src/js/util/accessMethods/buildAccessMethods/buildHarmony.js b/static/src/js/util/accessMethods/buildAccessMethods/buildHarmony.js new file mode 100644 index 0000000000..1a56fdb187 --- /dev/null +++ b/static/src/js/util/accessMethods/buildAccessMethods/buildHarmony.js @@ -0,0 +1,97 @@ +import { uniq } from 'lodash-es' + +import { getVariables } from '../getVariables' + +import { supportsBoundingBoxSubsetting } from '../supportsBoundingBoxSubsetting' +import { supportsConcatenation } from '../supportsConcatenation' +import { defaultConcatenation } from '../defaultConcatenation' +import { supportsShapefileSubsetting } from '../supportsShapefileSubsetting' +import { supportsTemporalSubsetting } from '../supportsTemporalSubsetting' +import { supportsVariableSubsetting } from '../supportsVariableSubsetting' + +/** + * Builds the Harmony access method + * @param {object} serviceItem serviceItem in the Collection Metadata + * @param {object} associatedVariables variables that are either in the serviceItem or collectionMetadata (prioritizes the serviceItem variables) + * @param {integer} index the harmony index for this harmony service item + * @returns {object} Access method for Harmony + */ +export const buildHarmony = (serviceItem, params) => { + const accessMethods = {} + + const { associatedVariables, harmonyIndex: index } = params + + const { + description, + conceptId: serviceConceptId, + type: serviceType, + longName, + name, + url, + supportedReformattings + } = serviceItem + + const { urlValue } = url + + const { + hierarchyMappings, + keywordMappings, + variables + } = getVariables(associatedVariables) + + const { + supportedOutputProjections + } = serviceItem + + const outputFormats = [] + + if (supportedReformattings) { + supportedReformattings.forEach((reformatting) => { + const { supportedOutputFormats } = reformatting + + // Collect all supported output formats from each mapping + outputFormats.push(...supportedOutputFormats) + }) + } + + let outputProjections = [] + if (supportedOutputProjections) { + outputProjections = supportedOutputProjections.filter((projection) => { + const { projectionAuthority } = projection + + return projectionAuthority != null + }).map((projection) => { + const { projectionAuthority } = projection + + return projectionAuthority + }) + } + + accessMethods[`harmony${index}`] = { + description, + enableTemporalSubsetting: true, + enableSpatialSubsetting: true, + hierarchyMappings, + id: serviceConceptId, + isValid: true, + keywordMappings, + longName, + name, + supportedOutputFormats: uniq(outputFormats), + supportedOutputProjections: outputProjections, + supportsBoundingBoxSubsetting: supportsBoundingBoxSubsetting(serviceItem), + supportsShapefileSubsetting: supportsShapefileSubsetting(serviceItem), + supportsTemporalSubsetting: supportsTemporalSubsetting(serviceItem), + supportsVariableSubsetting: supportsVariableSubsetting(serviceItem), + supportsConcatenation: supportsConcatenation(serviceItem), + defaultConcatenation: defaultConcatenation(serviceItem), + enableConcatenateDownload: defaultConcatenation(serviceItem), + type: serviceType, + url: urlValue, + variables + } + + return { + accessMethods + } +} diff --git a/static/src/js/util/accessMethods/buildAccessMethods/buildOpendap.js b/static/src/js/util/accessMethods/buildAccessMethods/buildOpendap.js new file mode 100644 index 0000000000..9a3b67f95e --- /dev/null +++ b/static/src/js/util/accessMethods/buildAccessMethods/buildOpendap.js @@ -0,0 +1,56 @@ +import { uniq } from 'lodash-es' + +import { getVariables } from '../getVariables' +import { supportsVariableSubsetting } from '../supportsVariableSubsetting' + +/** + * Builds the oPeNDAP access method + * @param {object} serviceItem serviceItem in the Collection Metadata + * @param {object} associatedVariables variables that are either in the serviceItem or collectionMetadata (prioritizes the serviceItem variables) + * @returns {object} Access method for oPeNDAP + */ +export const buildOpendap = (serviceItem, associatedVariables) => { + const accessMethods = {} + + const { + conceptId: serviceConceptId, + type: serviceType, + longName, + name, + supportedReformattings + } = serviceItem + + const { + hierarchyMappings, + keywordMappings, + variables + } = getVariables(associatedVariables) + + const outputFormats = [] + + if (supportedReformattings) { + supportedReformattings.forEach((reformatting) => { + const { supportedOutputFormats } = reformatting + + // Collect all supported output formats from each mapping + outputFormats.push(...supportedOutputFormats) + }) + } + + accessMethods.opendap = { + hierarchyMappings, + id: serviceConceptId, + isValid: true, + keywordMappings, + longName, + name, + supportedOutputFormats: uniq(outputFormats), + supportsVariableSubsetting: supportsVariableSubsetting(serviceItem), + type: serviceType, + variables + } + + return { + accessMethods + } +} diff --git a/static/src/js/util/accessMethods/buildAccessMethods/buildSwodlr.js b/static/src/js/util/accessMethods/buildAccessMethods/buildSwodlr.js new file mode 100644 index 0000000000..8c901171aa --- /dev/null +++ b/static/src/js/util/accessMethods/buildAccessMethods/buildSwodlr.js @@ -0,0 +1,39 @@ +import { getApplicationConfig } from '../../../../../../sharedUtils/config' + +/** + * Builds the swodlr access method + * @param {object} serviceItem serviceItem in the Collection Metadata + * @param {boolean} disabledSwodlr true if the swodlr acceessMethod disabled + * @returns {object} Access method for SWODLR + */ +export const buildSwodlr = (serviceItem) => { + const accessMethods = {} + + const { disableSwodlr } = getApplicationConfig() + + if (disableSwodlr !== 'true') { + const { + conceptId: serviceConceptId, + longName, + name, + type: serviceType, + url + } = serviceItem + + const { urlValue } = url + + accessMethods.swodlr = { + id: serviceConceptId, + isValid: true, + longName, + name, + type: serviceType, + supportsSwodlr: true, + url: urlValue + } + } + + return { + accessMethods + } +}