diff --git a/libs/api/metadata-converter/src/lib/iso19115-3/write-parts.spec.ts b/libs/api/metadata-converter/src/lib/iso19115-3/write-parts.spec.ts index 0a92d0800c..e85eb58cf5 100644 --- a/libs/api/metadata-converter/src/lib/iso19115-3/write-parts.spec.ts +++ b/libs/api/metadata-converter/src/lib/iso19115-3/write-parts.spec.ts @@ -7,6 +7,7 @@ import { writeResourceCreated, writeResourcePublished, writeResourceUpdated, + writeSpatialRepresentation, } from './write-parts' import { createElement, @@ -605,6 +606,34 @@ describe('write parts', () => { +`) + }) + }) + + describe('writeSpatialRepresentation', () => { + it('writes the corresponding element', () => { + writeSpatialRepresentation(datasetRecord, rootEl) + expect(rootAsString()).toEqual(` + + + + grid + + + +`) + }) + it('clears the corresponding element if the record has no spatial representation', () => { + writeSpatialRepresentation(datasetRecord, rootEl) + const modified: DatasetRecord = { + ...datasetRecord, + spatialRepresentation: null, + } + writeSpatialRepresentation(modified, rootEl) + expect(rootAsString()).toEqual(` + + + `) }) }) diff --git a/libs/api/metadata-converter/src/lib/iso19115-3/write-parts.ts b/libs/api/metadata-converter/src/lib/iso19115-3/write-parts.ts index feb3443acd..c0e9a34032 100644 --- a/libs/api/metadata-converter/src/lib/iso19115-3/write-parts.ts +++ b/libs/api/metadata-converter/src/lib/iso19115-3/write-parts.ts @@ -409,6 +409,13 @@ export function writeSpatialRepresentation( record: DatasetRecord, rootEl: XmlElement ) { + if (!record.spatialRepresentation) { + pipe( + findOrCreateIdentification(), + removeChildrenByName('mri:spatialRepresentationType') + )(rootEl) + return + } pipe( findOrCreateIdentification(), findNestedChildOrCreate( diff --git a/libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts b/libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts index 820c0edb5a..5138819570 100644 --- a/libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts +++ b/libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts @@ -17,6 +17,7 @@ import { writeResourcePublished, writeResourceUpdated, writeSpatialExtents, + writeSpatialRepresentation, writeTemporalExtents, } from './write-parts' @@ -926,4 +927,32 @@ describe('write parts', () => { ).toEqual('P0Y0M3D') }) }) + + describe('writeSpatialRepresentation', () => { + it('writes the corresponding element', () => { + writeSpatialRepresentation(datasetRecord, rootEl) + expect(rootAsString()).toEqual(` + + + + + + + +`) + }) + it('clears the corresponding element if the record has no spatial representation', () => { + writeSpatialRepresentation(datasetRecord, rootEl) + const modified: DatasetRecord = { + ...datasetRecord, + spatialRepresentation: null, + } + writeSpatialRepresentation(modified, rootEl) + expect(rootAsString()).toEqual(` + + + +`) + }) + }) }) diff --git a/libs/api/metadata-converter/src/lib/iso19139/write-parts.ts b/libs/api/metadata-converter/src/lib/iso19139/write-parts.ts index 34a80e1b80..0cbe91ee43 100644 --- a/libs/api/metadata-converter/src/lib/iso19139/write-parts.ts +++ b/libs/api/metadata-converter/src/lib/iso19139/write-parts.ts @@ -953,6 +953,13 @@ export function writeSpatialRepresentation( record: DatasetRecord, rootEl: XmlElement ) { + if (!record.spatialRepresentation) { + pipe( + findOrCreateIdentification(), + removeChildrenByName('gmd:spatialRepresentationType') + )(rootEl) + return + } pipe( findOrCreateIdentification(), findNestedChildOrCreate(