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

filter search down to required fields #8

Merged
merged 3 commits into from
Oct 13, 2021
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG.md

## Unreleased
Added
- Improved performance by limiting search requests to required terms [#8](https://github.com/koopjs/koop-output-dcat-us-11/pull/8)

## 1.2.0
Added
- Custom configurations can be passed through the `dcatConfig` query param [#6](https://github.com/koopjs/koop-output-dcat-us-11/pull/6)
Expand Down
2 changes: 1 addition & 1 deletion example-app/config/default.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"port": "8080",
"arcgisPortal": "https://www.arcgis.com"
"arcgisPortal": "https://qaext.arcgis.com"
}
6 changes: 6 additions & 0 deletions src/dcat-us/_generate-distributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import * as _ from 'lodash';
const WFS_SERVER = 'WFSServer';
const WMS_SERVER = 'WMSServer';

export const DISTRIBUTION_DEPENDENCIES = [
'layer.geometryType',
'server.spatialReference',
'metadata.metadata.distInfo.distTranOps.onLineSrc'
];

/*
* Generate DCAT Distributions
*/
Expand Down
2 changes: 1 addition & 1 deletion src/dcat-us/base-dataset-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const baseDatasetTemplate = {
contactPoint: {
'@type': 'vcard:Contact',
fn: '{{owner}}',
// hasEmail: '{{org.portalProperties.links.contactUs.url:optional}}' TODO - re-enable when supported
hasEmail: '{{orgContactEmail:optional}}'
},
accessLevel: 'public'
};
56 changes: 28 additions & 28 deletions src/dcat-us/dataset-formatter.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dcatTemplate, formatDcatDataset } from './dataset-formatter';
import { buildDatasetTemplate, formatDcatDataset } from './dataset-formatter';

it('dcatHelper: it does not allow customizations to overwrite critical fields', () => {
const customizations = {
Expand All @@ -13,27 +13,27 @@ it('dcatHelper: it does not allow customizations to overwrite critical fields',
hasEmail: 'mailto:dcat.support@dc.gov',
},
};
const template = dcatTemplate(customizations);
const template = buildDatasetTemplate(customizations);
expect(template['@type']).not.toBe('SABOTAGE');
expect(template.contactPoint['@type']).not.toBe('SABOTAGE');
});

it('dcatHelper: it does not throw an error if there are no customizations', () => {
const customizations = undefined;
const template = dcatTemplate(customizations);
const template = buildDatasetTemplate(customizations);
expect(template).toBeTruthy();
});

it('dcatHelper: it does not throw an error customizations are null', () => {
const customizations = null;
const template = dcatTemplate(customizations);
const template = buildDatasetTemplate(customizations);
expect(template).toBeTruthy();
});

describe('formatDcatDataset', () => {
const siteUrl = 'https://foobar.hub.arcgis.com';

it('object: should render links with the correct SRID', () => {
it('should render links with the correct SRID', () => {
const dataset = {
owner: 'fpgis.CALFIRE',
created: 1570747289000,
Expand Down Expand Up @@ -131,11 +131,11 @@ describe('formatDcatDataset', () => {
spatial: '-123.8832,35.0024,-118.3281,42.0122',
theme: ['geospatial'],
};
const actual = JSON.parse(formatDcatDataset(dataset, siteUrl));
const actual = JSON.parse(formatDcatDataset(dataset, siteUrl, buildDatasetTemplate()));
expect(actual).toEqual(expected);
});

it('object: should render links without the srid', () => {
it('should render links without the srid', () => {
const dataset = {
owner: 'fpgis.CALFIRE',
created: 1570747289000,
Expand Down Expand Up @@ -220,11 +220,11 @@ describe('formatDcatDataset', () => {
spatial: '-123.8832,35.0024,-118.3281,42.0122',
theme: ['geospatial'],
};
const actual = JSON.parse(formatDcatDataset(dataset, siteUrl));
const actual = JSON.parse(formatDcatDataset(dataset, siteUrl, buildDatasetTemplate()));
expect(actual).toEqual(expected);
});

it('object: should override theme when theme customizations is an empty array', () => {
it('should override theme when theme customizations is an empty array', () => {
const dataset = {
owner: 'fpgis.CALFIRE',
created: 1570747289000,
Expand Down Expand Up @@ -310,12 +310,12 @@ describe('formatDcatDataset', () => {
theme: ['geospatial'],
};
const actual = JSON.parse(
formatDcatDataset(dataset, siteUrl, { theme: [] }),
formatDcatDataset(dataset, siteUrl, buildDatasetTemplate({ theme: [] })),
);
expect(actual).toEqual(expected);
});

it('object: should _NOT_ override theme when theme customizations is supplied', () => {
it('should _NOT_ override theme when theme customizations is supplied', () => {
const dataset = {
owner: 'fpgis.CALFIRE',
created: 1570747289000,
Expand Down Expand Up @@ -401,12 +401,12 @@ describe('formatDcatDataset', () => {
theme: ['my theme'],
};
const actual = JSON.parse(
formatDcatDataset(dataset, siteUrl, { theme: ['my theme'] }),
formatDcatDataset(dataset, siteUrl, buildDatasetTemplate({ theme: ['my theme'] })),
);
expect(actual).toEqual(expected);
});

it('object: should render links with the correct SRID', () => {
it('should render links with the correct SRID', () => {
const dataset = {
owner: 'fpgis.CALFIRE',
created: 1570747289000,
Expand Down Expand Up @@ -495,11 +495,11 @@ describe('formatDcatDataset', () => {
spatial: '-123.8832,35.0024,-118.3281,42.0122',
theme: ['geospatial'],
};
const actual = JSON.parse(formatDcatDataset(dataset, siteUrl));
const actual = JSON.parse(formatDcatDataset(dataset, siteUrl, buildDatasetTemplate()));
expect(actual).toEqual(expected);
});

it('object: license should display structuredLicense url', () => {
it('license should display structuredLicense url', () => {
const dataset = {
owner: 'fpgis.CALFIRE',
created: 1570747289000,
Expand Down Expand Up @@ -531,11 +531,11 @@ describe('formatDcatDataset', () => {
};
const expectedLicense = 'https://google.com';

const actual = JSON.parse(formatDcatDataset(dataset, siteUrl));
const actual = JSON.parse(formatDcatDataset(dataset, siteUrl, buildDatasetTemplate()));
expect(actual.license).toEqual(expectedLicense);
});

it('object: license should be empty when structuredLicense.url is unavailable', () => {
it('license should be empty when structuredLicense.url is unavailable', () => {
const dataset = {
owner: 'fpgis.CALFIRE',
created: 1570747289000,
Expand Down Expand Up @@ -567,11 +567,11 @@ describe('formatDcatDataset', () => {
};
const expectedLicense = null;

const actual = JSON.parse(formatDcatDataset(dataset, siteUrl));
const actual = JSON.parse(formatDcatDataset(dataset, siteUrl, buildDatasetTemplate()));
expect(actual.license).toEqual(expectedLicense);
});

it('object: license should display null when structuredLicense is unavailable', () => {
it('license should display null when structuredLicense is unavailable', () => {
const dataset = {
owner: 'fpgis.CALFIRE',
created: 1570747289000,
Expand Down Expand Up @@ -602,11 +602,11 @@ describe('formatDcatDataset', () => {
};
const expectedLicense = null;

const actual = JSON.parse(formatDcatDataset(dataset, siteUrl));
const actual = JSON.parse(formatDcatDataset(dataset, siteUrl, buildDatasetTemplate()));
expect(actual.license).toEqual(expectedLicense);
});

test('object: Hub Page gets default keyword when no tags', () => {
test('Hub Page gets default keyword when no tags', () => {
const datasetWithNoTags = {
owner: 'fpgis.CALFIRE',
type: 'Hub Page',
Expand Down Expand Up @@ -647,20 +647,20 @@ describe('formatDcatDataset', () => {
};
const expectedKeyword = 'ArcGIS Hub page';
expect(
JSON.parse(formatDcatDataset(datasetWithNoTags, siteUrl)).keyword[0],
JSON.parse(formatDcatDataset(datasetWithNoTags, siteUrl, buildDatasetTemplate())).keyword[0],
).toBe(expectedKeyword);
expect(
JSON.parse(formatDcatDataset({ ...datasetWithNoTags, tags: [] }, siteUrl))
JSON.parse(formatDcatDataset({ ...datasetWithNoTags, tags: [] }, siteUrl, buildDatasetTemplate()))
.keyword[0],
).toBe(expectedKeyword);
expect(
JSON.parse(
formatDcatDataset({ ...datasetWithNoTags, tags: [''] }, siteUrl),
formatDcatDataset({ ...datasetWithNoTags, tags: [''] }, siteUrl, buildDatasetTemplate()),
).keyword[0],
).toBe(expectedKeyword);
});

it('object: should create custom distribution when data is supplied', () => {
it('should create custom distribution when data is supplied', () => {
const dataset = {
owner: 'fpgis.CALFIRE',
created: 1570747289000,
Expand Down Expand Up @@ -712,11 +712,11 @@ describe('formatDcatDataset', () => {
description: 'endpoint',
};

const actual = JSON.parse(formatDcatDataset(dataset, siteUrl));
const actual = JSON.parse(formatDcatDataset(dataset, siteUrl, buildDatasetTemplate()));
expect(actual.distribution.pop()).toEqual(expectedDistribution);
});

it('object: doesnt blow up when onLineSrc is not an array', () => {
it('doesnt blow up when onLineSrc is not an array', () => {
const dataset = {
owner: 'fpgis.CALFIRE',
created: 1570747289000,
Expand Down Expand Up @@ -757,7 +757,7 @@ describe('formatDcatDataset', () => {
};

try {
formatDcatDataset(dataset, siteUrl);
formatDcatDataset(dataset, siteUrl, buildDatasetTemplate());
} catch {
fail('Should not throw!');
}
Expand Down
12 changes: 5 additions & 7 deletions src/dcat-us/dataset-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import { IItem } from '@esri/arcgis-rest-portal';
type HubDatasetAttributes = Record<string, any>;
export type DcatDatasetTemplate = Record<string, any>;

export function formatDcatDataset (hubDataset: HubDatasetAttributes, siteUrl: string, dcatCustomizations: DcatDatasetTemplate = {}) {
export function formatDcatDataset (hubDataset: HubDatasetAttributes, siteUrl: string, datasetTemplate: DcatDatasetTemplate) {
const landingPage = `${siteUrl}/datasets/${hubDataset.id}`;

const template = dcatTemplate(dcatCustomizations);

const { structuredLicense: { url = null } = {} } = hubDataset;

const defaultDataset = {
Expand All @@ -34,7 +32,7 @@ export function formatDcatDataset (hubDataset: HubDatasetAttributes, siteUrl: st
}
};

const dcatDataset = Object.assign({}, defaultDataset, adlib(template, hubDataset, transforms));
const dcatDataset = Object.assign({}, defaultDataset, adlib(datasetTemplate, hubDataset, transforms));

if (isPage(hubDataset as IItem) && !hasTags(hubDataset)) {
dcatDataset.keyword = ['ArcGIS Hub page'];
Expand All @@ -47,7 +45,7 @@ export function formatDcatDataset (hubDataset: HubDatasetAttributes, siteUrl: st

// https://project-open-data.cio.gov/v1.1/schema/#theme
// allow theme to be overrriden
if (_.isEmpty(dcatCustomizations.theme)) {
if (_.isEmpty(datasetTemplate.theme)) {
dcatDataset.theme = ['geospatial'];
}
}
Expand Down Expand Up @@ -83,7 +81,7 @@ function scrubProtectedKeys (customizations: DcatDatasetTemplate): DcatDatasetTe
return scrubbedCustomizations;
}

export function dcatTemplate (customizations: DcatDatasetTemplate): DcatDatasetTemplate {
const customConfig = scrubProtectedKeys(customizations || {});
export function buildDatasetTemplate (customizations: DcatDatasetTemplate = {}): DcatDatasetTemplate {
const customConfig = scrubProtectedKeys(customizations);
return Object.assign({}, baseDatasetTemplate, customConfig);
}
Loading