-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(converter): improve contacts writing in ISO
- Loading branch information
Showing
5 changed files
with
293 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
@@ -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>`) | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ import { | |
findNestedElement, | ||
findNestedElements, | ||
readAttribute, | ||
removeAllChildren, | ||
removeChildren, | ||
removeChildrenByName, | ||
setTextContent, | ||
|
@@ -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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ import { | |
} from '../xml-utils' | ||
import { | ||
getISODuration, | ||
writeContacts, | ||
writeContactsForResource, | ||
writeKeywords, | ||
writeOnlineResources, | ||
writeResourceCreated, | ||
|
@@ -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( | ||
|
Oops, something went wrong.