Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose provider information from capabilities #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export type {
WmtsMatrixSet,
} from './wmts/model.js';
export type {
Address,
Contact,
Provider,
LayerStyle,
BoundingBox,
FetchOptions,
Expand Down
25 changes: 25 additions & 0 deletions src/shared/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,38 @@ export type BoundingBox = [number, number, number, number];

export type CrsCode = string;

export interface Address {
deliveryPoint?: string;
city?: string;
administrativeArea?: string;
postalCode?: string;
country?: string;
}

export interface Contact {
name?: string;
organization?: string;
position?: string;
phone?: string;
fax?: string;
address?: Address;
email?: string;
}

export interface Provider {
name?: string;
site?: string;
contact?: Contact;
}

export type GenericEndpointInfo = {
name: string;
title: string;
abstract: string;
fees: string;
constraints: string;
keywords: string[];
provider?: Provider;
/**
* Can contain the list of outputFormats from a WFS GetCapabilities,
* or the list of 'Formats' from a WMS GetCapabilities
Expand Down
60 changes: 60 additions & 0 deletions src/shared/ows.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// @ts-expect-error ts-migrate(7016)
import capabilitiesWfs110 from '../../fixtures/wfs/capabilities-pigma-1-1-0.xml';
// @ts-expect-error ts-migrate(7016)
import capabilitiesWfs200 from '../../fixtures/wfs/capabilities-pigma-2-0-0.xml';
// @ts-expect-error ts-migrate(7016)
import capabilitiesWmts from '../../fixtures/wmts/ogcsample.xml';
import { parseXmlString } from './xml-utils.js';
import { readProviderFromCapabilities } from './ows.js';

const wfsProvider = {
name: 'GIP ATGeRi',
site: '',
contact: {
name: 'PIGMA',
position: '',
phone: '05.57.85.40.42',
fax: '',
address: {
deliveryPoint: '',
city: 'Bordeaux',
administrativeArea: '',
postalCode: '33075',
country: '',
},
email: 'admin.pigma@gipatgeri.fr',
},
};

describe('OWS utils', () => {
it('can read provider information from WFS capabilities (2.0.0)', () => {
const doc = parseXmlString(capabilitiesWfs200);
expect(readProviderFromCapabilities(doc)).toEqual(wfsProvider);
});
it('can read provider information from WFS capabilities (1.1.0)', () => {
const doc = parseXmlString(capabilitiesWfs110);
expect(readProviderFromCapabilities(doc)).toEqual(wfsProvider);
});
it('can read provider information from WMTS capabilities', () => {
const expectedProvider = {
name: 'MiraMon',
site: 'http://www.creaf.uab.cat/miramon',
contact: {
name: 'Joan Maso Pau',
position: 'Senior Software Engineer',
phone: '+34 93 581 1312',
fax: '+34 93 581 4151',
address: {
deliveryPoint: 'Fac Ciencies UAB',
city: 'Bellaterra',
administrativeArea: 'Barcelona',
postalCode: '08193',
country: 'Spain',
},
email: 'joan.maso@uab.cat',
},
};
const doc = parseXmlString(capabilitiesWmts);
expect(readProviderFromCapabilities(doc)).toEqual(expectedProvider);
});
});
52 changes: 52 additions & 0 deletions src/shared/ows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { XmlDocument } from '@rgrove/parse-xml';
import type { Provider } from './models.js';
import {
findChildElement,
getElementAttribute,
getElementText,
getRootElement,
} from './xml-utils.js';

/**
* Read standard OWS provider information from capabilities
* @param capabilitiesDoc
*/
export function readProviderFromCapabilities(
capabilitiesDoc: XmlDocument
): Provider {
const serviceProvider = findChildElement(
getRootElement(capabilitiesDoc),
'ServiceProvider'
);
const serviceContact = findChildElement(serviceProvider, 'ServiceContact');
const contactInfo = findChildElement(serviceContact, 'ContactInfo');
const phone = findChildElement(contactInfo, 'Phone');
const address = findChildElement(contactInfo, 'Address');
return {
name: getElementText(findChildElement(serviceProvider, 'ProviderName')),
site: getElementAttribute(
findChildElement(serviceProvider, 'ProviderSite'),
'xlink:href'
),
contact: {
name: getElementText(findChildElement(serviceContact, 'IndividualName')),
position: getElementText(
findChildElement(serviceContact, 'PositionName')
),
phone: getElementText(findChildElement(phone, 'Voice')),
fax: getElementText(findChildElement(phone, 'Facsimile')),
address: {
deliveryPoint: getElementText(
findChildElement(address, 'DeliveryPoint')
),
city: getElementText(findChildElement(address, 'City')),
administrativeArea: getElementText(
findChildElement(address, 'AdministrativeArea')
),
postalCode: getElementText(findChildElement(address, 'PostalCode')),
country: getElementText(findChildElement(address, 'Country')),
},
email: getElementText(findChildElement(address, 'ElectronicMailAddress')),
},
};
}
20 changes: 20 additions & 0 deletions src/wfs/capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,29 @@ describe('WFS capabilities', () => {
keywords: ['WFS', 'WMS', 'GEOSERVER'],
outputFormats: [],
};
const provider = {
name: 'GIP ATGeRi',
site: '',
contact: {
name: 'PIGMA',
position: '',
phone: '05.57.85.40.42',
fax: '',
address: {
deliveryPoint: '',
city: 'Bordeaux',
administrativeArea: '',
postalCode: '33075',
country: '',
},
email: 'admin.pigma@gipatgeri.fr',
},
};
it('reads the service info (2.0.0)', () => {
const doc = parseXmlString(capabilities200);
expect(readInfoFromCapabilities(doc)).toEqual({
...expectedInfo,
provider,
outputFormats: [
'application/gml+xml; version=3.2',
'DXF',
Expand Down Expand Up @@ -208,6 +227,7 @@ describe('WFS capabilities', () => {
const doc = parseXmlString(capabilities110);
expect(readInfoFromCapabilities(doc)).toEqual({
...expectedInfo,
provider,
outputFormats: [
'text/xml; subtype=gml/3.1.1',
'DXF',
Expand Down
7 changes: 7 additions & 0 deletions src/wfs/capabilities.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { readProviderFromCapabilities } from '../shared/ows.js';
import {
findChildElement,
findChildrenElement,
Expand Down Expand Up @@ -91,6 +92,11 @@ export function readInfoFromCapabilities(
'Keyword'
).map(getElementText);
}
let provider;
// no provider information defined in capabilities for WFS 1.0.0
if (version !== '1.0.0') {
provider = readProviderFromCapabilities(capabilitiesDoc);
}

return {
title: getElementText(findChildElement(service, 'Title')),
Expand All @@ -99,6 +105,7 @@ export function readInfoFromCapabilities(
fees: getElementText(findChildElement(service, 'Fees')),
constraints: getElementText(findChildElement(service, 'AccessConstraints')),
keywords,
provider,
outputFormats: readOutputFormatsFromCapabilities(capabilitiesDoc),
};
}
Expand Down
18 changes: 18 additions & 0 deletions src/wfs/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,24 @@ describe('WfsEndpoint', () => {
name: 'WFS',
title: "Service WFS de l'IDS régionale PIGMA",
keywords: ['WFS', 'WMS', 'GEOSERVER'],
provider: {
name: 'GIP ATGeRi',
site: '',
contact: {
name: 'PIGMA',
position: '',
phone: '05.57.85.40.42',
fax: '',
address: {
deliveryPoint: '',
city: 'Bordeaux',
administrativeArea: '',
postalCode: '33075',
country: '',
},
email: 'admin.pigma@gipatgeri.fr',
},
},
outputFormats: [
'application/gml+xml; version=3.2',
'DXF',
Expand Down
17 changes: 17 additions & 0 deletions src/wms/capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,23 @@ describe('WMS capabilities', () => {
'WMS 1.3.0',
'SLD 1.1.0',
],
provider: {
contact: {
name: 'Support BRGM',
organization: 'BRGM',
position: 'pointOfContact',
phone: '+33(0)2 38 64 34 34',
fax: '+33(0)2 38 64 35 18',
address: {
deliveryPoint: '3, Avenue Claude Guillemin, BP36009',
city: 'Orléans',
administrativeArea: 'Centre',
postalCode: '45060',
country: 'France',
},
email: 'contact-brgm@brgm.fr',
},
},
};

it('reads the service info (1.3.0)', () => {
Expand Down
48 changes: 48 additions & 0 deletions src/wms/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
CrsCode,
GenericEndpointInfo,
LayerStyle,
type Provider,
} from '../shared/models.js';
import { WmsLayerAttribution, WmsLayerFull, WmsVersion } from './model.js';

Expand Down Expand Up @@ -73,6 +74,7 @@ export function readInfoFromCapabilities(
)
.map(getElementText)
.filter((v, i, arr) => arr.indexOf(v) === i);
const provider = readProviderFromCapabilities(capabilitiesDoc);

return {
title: getElementText(findChildElement(service, 'Title')),
Expand All @@ -81,6 +83,7 @@ export function readInfoFromCapabilities(
outputFormats: formats,
fees: getElementText(findChildElement(service, 'Fees')),
constraints: getElementText(findChildElement(service, 'AccessConstraints')),
provider,
keywords,
};
}
Expand Down Expand Up @@ -220,3 +223,48 @@ function parseLayerAttribution(attributionEl: XmlElement): WmsLayerAttribution {
...(logoUrl && { logoUrl }),
};
}

/**
* Read provider information from capabilities
* @param capabilitiesDoc
*/
function readProviderFromCapabilities(capabilitiesDoc: XmlDocument): Provider {
const service = findChildElement(getRootElement(capabilitiesDoc), 'Service');
const contactInformation = findChildElement(service, 'ContactInformation');
const contactPersonPrimary = findChildElement(
contactInformation,
'ContactPersonPrimary'
);
const address = findChildElement(contactInformation, 'ContactAddress');
return {
contact: {
name: getElementText(
findChildElement(contactPersonPrimary, 'ContactPerson')
),
organization: getElementText(
findChildElement(contactPersonPrimary, 'ContactOrganization')
),
position: getElementText(
findChildElement(contactInformation, 'ContactPosition')
),
phone: getElementText(
findChildElement(contactInformation, 'ContactVoiceTelephone')
),
fax: getElementText(
findChildElement(contactInformation, 'ContactFacsimileTelephone')
),
address: {
deliveryPoint: getElementText(findChildElement(address, 'Address')),
city: getElementText(findChildElement(address, 'City')),
administrativeArea: getElementText(
findChildElement(address, 'StateOrProvince')
),
postalCode: getElementText(findChildElement(address, 'PostCode')),
country: getElementText(findChildElement(address, 'Country')),
},
email: getElementText(
findChildElement(contactInformation, 'ContactElectronicMailAddress')
),
},
};
}
17 changes: 17 additions & 0 deletions src/wms/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,23 @@ describe('WmsEndpoint', () => {
'WMS 1.3.0',
'SLD 1.1.0',
],
provider: {
contact: {
name: 'Support BRGM',
organization: 'BRGM',
position: 'pointOfContact',
phone: '+33(0)2 38 64 34 34',
fax: '+33(0)2 38 64 35 18',
address: {
deliveryPoint: '3, Avenue Claude Guillemin, BP36009',
city: 'Orléans',
administrativeArea: 'Centre',
postalCode: '45060',
country: 'France',
},
email: 'contact-brgm@brgm.fr',
},
},
});
});
});
Expand Down
Loading