Skip to content

Commit

Permalink
feat(md-converter): improve keywords grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
jahow committed Apr 11, 2024
1 parent 4321a00 commit 73be4e4
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
87 changes: 87 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 @@ -422,6 +422,93 @@ describe('write parts', () => {
</gmd:descriptiveKeywords>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
</root>`)
})

it('correctly adds a thesaurus to an existing keyword', () => {
// add some distributions first
const sample = parseXmlString(`
<root>
<gmd:identificationInfo >
<gmd:MD_DataIdentification>
<gmd:descriptiveKeywords>
<gmd:MD_Keywords>
<gmd:keyword>
<gco:CharacterString>Usage des sols</gco:CharacterString>
</gmd:keyword>
<gmd:keyword>
<gco:CharacterString>Agriculture</gco:CharacterString>
</gmd:keyword>
<gmd:type>
<gmd:MD_KeywordTypeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_KeywordTypeCode"
codeListValue="theme"/>
</gmd:type>
</gmd:MD_Keywords>
</gmd:descriptiveKeywords>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
</root>`)
rootEl = getRootElement(sample)
writeKeywords(
{
...datasetRecord,
keywords: [
{
label: 'Usage des sols',
type: 'theme',
},
{
label: 'Agriculture',
type: 'theme',
thesaurus: {
id: 'abcd',
url: new URL('http://abcd.com'),
name: 'A thesaurus',
},
},
],
},
rootEl
)
expect(rootAsString()).toEqual(`<root>
<gmd:identificationInfo>
<gmd:MD_DataIdentification>
<gmd:descriptiveKeywords>
<gmd:MD_Keywords>
<gmd:type>
<gmd:MD_KeywordTypeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_KeywordTypeCode" codeListValue="theme"/>
</gmd:type>
<gmd:keyword>
<gco:CharacterString>Usage des sols</gco:CharacterString>
</gmd:keyword>
</gmd:MD_Keywords>
</gmd:descriptiveKeywords>
<gmd:descriptiveKeywords>
<gmd:MD_Keywords>
<gmd:type>
<gmd:MD_KeywordTypeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_KeywordTypeCode" codeListValue="theme"/>
</gmd:type>
<gmd:thesaurusName>
<gmd:CI_Citation>
<gmd:title>
<gco:CharacterString>A thesaurus</gco:CharacterString>
</gmd:title>
<gmd:identifier>
<gmd:MD_Identifier>
<gmd:code>
<gmx:Anchor xlink:href="http://abcd.com/">abcd</gmx:Anchor>
</gmd:code>
</gmd:MD_Identifier>
</gmd:identifier>
</gmd:CI_Citation>
</gmd:thesaurusName>
<gmd:keyword>
<gco:CharacterString>Agriculture</gco:CharacterString>
</gmd:keyword>
</gmd:MD_Keywords>
</gmd:descriptiveKeywords>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
</root>`)
})
})
Expand Down
7 changes: 4 additions & 3 deletions libs/api/metadata-converter/src/lib/iso19139/write-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,14 @@ export function createThesaurus(thesaurus: KeywordThesaurus) {
}

export function appendKeywords(keywords: Keyword[]) {
// keywords are grouped by thesaurus if they have one, otherwise by type
const keywordsByThesaurus: Keyword[][] = keywords.reduce((acc, keyword) => {
const thesaurusId = keyword.thesaurus?.id
const type = keyword.type
let existingGroup = acc.find((group) =>
group[0].thesaurus
? group[0].thesaurus.id === thesaurusId
: group[0].type === type
thesaurusId
? group[0].thesaurus?.id === thesaurusId
: group[0].type === type && !group[0].thesaurus
)
if (!existingGroup) {
existingGroup = []
Expand Down

0 comments on commit 73be4e4

Please sign in to comment.