Skip to content

Commit

Permalink
fix(converter): do not write spatial representation if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jahow committed Sep 30, 2024
1 parent a318b4a commit bd40e8b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
29 changes: 29 additions & 0 deletions libs/api/metadata-converter/src/lib/iso19115-3/write-parts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
writeResourceCreated,
writeResourcePublished,
writeResourceUpdated,
writeSpatialRepresentation,
} from './write-parts'
import {
createElement,
Expand Down Expand Up @@ -605,6 +606,34 @@ describe('write parts', () => {
</mri:pointOfContact>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
</root>`)
})
})

describe('writeSpatialRepresentation', () => {
it('writes the corresponding element', () => {
writeSpatialRepresentation(datasetRecord, rootEl)
expect(rootAsString()).toEqual(`<root>
<gmd:identificationInfo>
<gmd:MD_DataIdentification>
<mri:spatialRepresentationType>
<mcc:MD_SpatialRepresentationTypeCode codeList="https://standards.iso.org/iso/19115/resources/Codelists/cat/codelists.xml#MD_SpatialRepresentationTypeCode" codeListValue="grid">grid</mcc:MD_SpatialRepresentationTypeCode>
</mri:spatialRepresentationType>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
</root>`)
})
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(`<root>
<gmd:identificationInfo>
<gmd:MD_DataIdentification/>
</gmd:identificationInfo>
</root>`)
})
})
Expand Down
7 changes: 7 additions & 0 deletions libs/api/metadata-converter/src/lib/iso19115-3/write-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,13 @@ export function writeSpatialRepresentation(
record: DatasetRecord,
rootEl: XmlElement
) {
if (!record.spatialRepresentation) {
pipe(
findOrCreateIdentification(),
removeChildrenByName('mri:spatialRepresentationType')
)(rootEl)
return
}
pipe(
findOrCreateIdentification(),
findNestedChildOrCreate(
Expand Down
29 changes: 29 additions & 0 deletions libs/api/metadata-converter/src/lib/iso19139/write-parts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
writeResourcePublished,
writeResourceUpdated,
writeSpatialExtents,
writeSpatialRepresentation,
writeTemporalExtents,
} from './write-parts'

Expand Down Expand Up @@ -926,4 +927,32 @@ describe('write parts', () => {
).toEqual('P0Y0M3D')
})
})

describe('writeSpatialRepresentation', () => {
it('writes the corresponding element', () => {
writeSpatialRepresentation(datasetRecord, rootEl)
expect(rootAsString()).toEqual(`<root>
<gmd:identificationInfo>
<gmd:MD_DataIdentification>
<gmd:spatialRepresentationType>
<gmd:MD_SpatialRepresentationTypeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_SpatialRepresentationTypeCode" codeListValue="grid"/>
</gmd:spatialRepresentationType>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
</root>`)
})
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(`<root>
<gmd:identificationInfo>
<gmd:MD_DataIdentification/>
</gmd:identificationInfo>
</root>`)
})
})
})
7 changes: 7 additions & 0 deletions libs/api/metadata-converter/src/lib/iso19139/write-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,13 @@ export function writeSpatialRepresentation(
record: DatasetRecord,
rootEl: XmlElement
) {
if (!record.spatialRepresentation) {
pipe(
findOrCreateIdentification(),
removeChildrenByName('gmd:spatialRepresentationType')
)(rootEl)
return
}
pipe(
findOrCreateIdentification(),
findNestedChildOrCreate(
Expand Down

0 comments on commit bd40e8b

Please sign in to comment.