Skip to content

Commit

Permalink
feat(converter): improve contacts writing in ISO
Browse files Browse the repository at this point in the history
  • Loading branch information
jahow committed Sep 24, 2024
1 parent ce0c151 commit d8df3f0
Show file tree
Hide file tree
Showing 5 changed files with 293 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
writeLandingPage,
writeLineage,
writeOnlineResources,
writeOwnerOrganization,
writeRecordCreated,
writeRecordPublished,
writeRecordUpdated,
Expand Down Expand Up @@ -60,7 +59,7 @@ export class Iso191153Converter extends Iso19139Converter {
this.writers['resourcePublished'] = writeResourcePublished
this.writers['contacts'] = writeContacts
this.writers['contactsForResource'] = writeContactsForResource
this.writers['ownerOrganization'] = writeOwnerOrganization
this.writers['ownerOrganization'] = () => undefined // fixme: find a way to store this value properly
this.writers['landingPage'] = writeLandingPage
this.writers['lineage'] = writeLineage
this.writers['onlineResources'] = writeOnlineResources
Expand Down
156 changes: 156 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
@@ -1,5 +1,6 @@
import { GENERIC_DATASET_RECORD } from '../fixtures/generic.records'
import {
writeContacts,
writeContactsForResource,
writeOnlineResources,
writeRecordCreated,
Expand Down Expand Up @@ -449,6 +450,161 @@ describe('write parts', () => {
</gmd:transferOptions>
</gmd:MD_Distribution>
</gmd:distributionInfo>
</root>`)
})
})

describe('writeContacts', () => {
it('works with incomplete contacts', () => {
const contacts = [
{
firstName: 'John',
role: 'point_of_contact',
email: '[email protected]',
},
{
lastName: 'Doe',
role: 'contributor',
email: '[email protected]',
organization: {
name: 'ACME',
},
},
]
const modified: DatasetRecord = {
...datasetRecord,
contacts,
contactsForResource: contacts,
}
writeContacts(modified, rootEl)
writeContactsForResource(modified, rootEl)
expect(rootAsString()).toEqual(`<root>
<gmd:contact>
<cit:CI_Responsibility>
<cit:role>
<cit:CI_RoleCode codeList="https://standards.iso.org/iso/19115/resources/Codelists/cat/codelists.xml#CI_RoleCode" codeListValue="pointOfContact">pointOfContact</cit:CI_RoleCode>
</cit:role>
<cit:party>
<cit:CI_Organisation>
<cit:contactInfo>
<cit:CI_Contact>
<cit:address>
<cit:CI_Address>
<cit:electronicMailAddress>
<gco:CharacterString>[email protected]</gco:CharacterString>
</cit:electronicMailAddress>
</cit:CI_Address>
</cit:address>
</cit:CI_Contact>
</cit:contactInfo>
<cit:individual>
<cit:CI_Individual>
<cit:name>
<gco:CharacterString>John</gco:CharacterString>
</cit:name>
</cit:CI_Individual>
</cit:individual>
</cit:CI_Organisation>
</cit:party>
</cit:CI_Responsibility>
</gmd:contact>
<gmd:contact>
<cit:CI_Responsibility>
<cit:role>
<cit:CI_RoleCode codeList="https://standards.iso.org/iso/19115/resources/Codelists/cat/codelists.xml#CI_RoleCode" codeListValue="contributor">contributor</cit:CI_RoleCode>
</cit:role>
<cit:party>
<cit:CI_Organisation>
<cit:name>
<gco:CharacterString>ACME</gco:CharacterString>
</cit:name>
<cit:contactInfo>
<cit:CI_Contact>
<cit:address>
<cit:CI_Address>
<cit:electronicMailAddress>
<gco:CharacterString>[email protected]</gco:CharacterString>
</cit:electronicMailAddress>
</cit:CI_Address>
</cit:address>
</cit:CI_Contact>
</cit:contactInfo>
<cit:individual>
<cit:CI_Individual>
<cit:name>
<gco:CharacterString>Doe</gco:CharacterString>
</cit:name>
</cit:CI_Individual>
</cit:individual>
</cit:CI_Organisation>
</cit:party>
</cit:CI_Responsibility>
</gmd:contact>
<gmd:identificationInfo>
<gmd:MD_DataIdentification>
<mri:pointOfContact>
<cit:CI_Responsibility>
<cit:role>
<cit:CI_RoleCode codeList="https://standards.iso.org/iso/19115/resources/Codelists/cat/codelists.xml#CI_RoleCode" codeListValue="pointOfContact">pointOfContact</cit:CI_RoleCode>
</cit:role>
<cit:party>
<cit:CI_Organisation>
<cit:contactInfo>
<cit:CI_Contact>
<cit:address>
<cit:CI_Address>
<cit:electronicMailAddress>
<gco:CharacterString>[email protected]</gco:CharacterString>
</cit:electronicMailAddress>
</cit:CI_Address>
</cit:address>
</cit:CI_Contact>
</cit:contactInfo>
<cit:individual>
<cit:CI_Individual>
<cit:name>
<gco:CharacterString>John</gco:CharacterString>
</cit:name>
</cit:CI_Individual>
</cit:individual>
</cit:CI_Organisation>
</cit:party>
</cit:CI_Responsibility>
</mri:pointOfContact>
<mri:pointOfContact>
<cit:CI_Responsibility>
<cit:role>
<cit:CI_RoleCode codeList="https://standards.iso.org/iso/19115/resources/Codelists/cat/codelists.xml#CI_RoleCode" codeListValue="contributor">contributor</cit:CI_RoleCode>
</cit:role>
<cit:party>
<cit:CI_Organisation>
<cit:name>
<gco:CharacterString>ACME</gco:CharacterString>
</cit:name>
<cit:contactInfo>
<cit:CI_Contact>
<cit:address>
<cit:CI_Address>
<cit:electronicMailAddress>
<gco:CharacterString>[email protected]</gco:CharacterString>
</cit:electronicMailAddress>
</cit:CI_Address>
</cit:address>
</cit:CI_Contact>
</cit:contactInfo>
<cit:individual>
<cit:CI_Individual>
<cit:name>
<gco:CharacterString>Doe</gco:CharacterString>
</cit:name>
</cit:CI_Individual>
</cit:individual>
</cit:CI_Organisation>
</cit:party>
</cit:CI_Responsibility>
</mri:pointOfContact>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
</root>`)
})
})
Expand Down
28 changes: 0 additions & 28 deletions libs/api/metadata-converter/src/lib/iso19115-3/write-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
findNestedElement,
findNestedElements,
readAttribute,
removeAllChildren,
removeChildren,
removeChildrenByName,
setTextContent,
Expand Down Expand Up @@ -213,33 +212,6 @@ export function writeResourcePublished(
appendResourceDate(record.resourcePublished, 'publication')(rootEl)
}

export function writeOwnerOrganization(
record: CatalogRecord,
rootEl: XmlElement
) {
// if no contact matches the owner org, create an empty one
const ownerContact: Individual = record.contacts.find(
(contact) => contact.organization.name === record.ownerOrganization.name
)
pipe(
findChildOrCreate('mdb:contact'),
removeAllChildren(),
appendResponsibleParty(
ownerContact
? {
...ownerContact,
// owner responsible party is always point of contact
role: 'point_of_contact',
}
: {
organization: record.ownerOrganization,
email: '[email protected]',
role: 'point_of_contact',
}
)
)(rootEl)
}

export function appendResponsibleParty(contact: Individual) {
const fullName = namePartsToFull(contact.firstName, contact.lastName)

Expand Down
125 changes: 125 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 @@ -9,6 +9,8 @@ import {
} from '../xml-utils'
import {
getISODuration,
writeContacts,
writeContactsForResource,
writeKeywords,
writeOnlineResources,
writeResourceCreated,
Expand Down Expand Up @@ -785,6 +787,129 @@ describe('write parts', () => {
})
})

describe('writeContacts', () => {
it('works with incomplete contacts', () => {
const contacts = [
{
firstName: 'John',
role: 'point_of_contact',
email: '[email protected]',
},
{
lastName: 'Doe',
role: 'contributor',
email: '[email protected]',
organization: {
name: 'ACME',
},
},
]
const modified: DatasetRecord = {
...datasetRecord,
contacts,
contactsForResource: contacts,
}
writeContacts(modified, rootEl)
writeContactsForResource(modified, rootEl)
expect(rootAsString()).toEqual(`<root>
<gmd:contact>
<gmd:CI_ResponsibleParty>
<gmd:individualName>
<gco:CharacterString>John</gco:CharacterString>
</gmd:individualName>
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:address>
<gmd:CI_Address>
<gmd:electronicMailAddress>
<gco:CharacterString>[email protected]</gco:CharacterString>
</gmd:electronicMailAddress>
</gmd:CI_Address>
</gmd:address>
</gmd:CI_Contact>
</gmd:contactInfo>
<gmd:role>
<gmd:CI_RoleCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_RoleCode" codeListValue="pointOfContact"/>
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:contact>
<gmd:contact>
<gmd:CI_ResponsibleParty>
<gmd:individualName>
<gco:CharacterString>Doe</gco:CharacterString>
</gmd:individualName>
<gmd:organisationName>
<gco:CharacterString>ACME</gco:CharacterString>
</gmd:organisationName>
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:address>
<gmd:CI_Address>
<gmd:electronicMailAddress>
<gco:CharacterString>[email protected]</gco:CharacterString>
</gmd:electronicMailAddress>
</gmd:CI_Address>
</gmd:address>
</gmd:CI_Contact>
</gmd:contactInfo>
<gmd:role>
<gmd:CI_RoleCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_RoleCode" codeListValue="contributor"/>
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:contact>
<gmd:identificationInfo>
<gmd:MD_DataIdentification>
<gmd:pointOfContact>
<gmd:CI_ResponsibleParty>
<gmd:individualName>
<gco:CharacterString>John</gco:CharacterString>
</gmd:individualName>
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:address>
<gmd:CI_Address>
<gmd:electronicMailAddress>
<gco:CharacterString>[email protected]</gco:CharacterString>
</gmd:electronicMailAddress>
</gmd:CI_Address>
</gmd:address>
</gmd:CI_Contact>
</gmd:contactInfo>
<gmd:role>
<gmd:CI_RoleCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_RoleCode" codeListValue="pointOfContact"/>
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:pointOfContact>
<gmd:pointOfContact>
<gmd:CI_ResponsibleParty>
<gmd:individualName>
<gco:CharacterString>Doe</gco:CharacterString>
</gmd:individualName>
<gmd:organisationName>
<gco:CharacterString>ACME</gco:CharacterString>
</gmd:organisationName>
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:address>
<gmd:CI_Address>
<gmd:electronicMailAddress>
<gco:CharacterString>[email protected]</gco:CharacterString>
</gmd:electronicMailAddress>
</gmd:CI_Address>
</gmd:address>
</gmd:CI_Contact>
</gmd:contactInfo>
<gmd:role>
<gmd:CI_RoleCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_RoleCode" codeListValue="contributor"/>
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:pointOfContact>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
</root>`)
})
})

describe('getISODuration', () => {
it('keeps a partial weekly period', () => {
expect(
Expand Down
Loading

0 comments on commit d8df3f0

Please sign in to comment.