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

removed dataset enrichment from dcat plugin #31

Merged
merged 7 commits into from
Feb 7, 2023
Merged

Conversation

sansth1010
Copy link
Collaborator

Please ignore the failed test cases for now. It will be resolved before the merge to beta branch.

PR for #5618

@sansth1010 sansth1010 changed the title removed dataset enrichment from dcat plugin [DNM] - removed dataset enrichment from dcat plugin Feb 1, 2023
@sansth1010 sansth1010 changed the base branch from main to beta February 1, 2023 17:03
src/dcat-us/dataset-formatter.ts Outdated Show resolved Hide resolved
src/index.ts Outdated

if (!dcatConfig) {
dcatConfig = _.get(siteModel, 'data.feeds.dcatUS11');
const { res: { locals: { feedTemplate, feedTemplateTransforms, nonEditableTemplateFields } } }: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably allow for the feedTemplate to arrive on the req.query as well. req.query.feedTemplate used by default, if not, check in locals.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do feedTemplateTransforms and nonEditableTemplateFields come from?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rgwozdz feedTemplateTransforms and nonEditableTemplateFields comes from Koop instance and is part of feed templates.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you link to where we assign to locals?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably allow for the feedTemplate to arrive on the req.query as well. req.query.feedTemplate used by default, if not, check in locals.

Do we allow feed template through query in output plugin as well? The logic of converting template passed via query to feedTemplate object already exists in our koop instance (hub-feeds-api). Regular users would just create feedTemplate object pass it to locals in koop instance. We can implement parsing template via query in output plugin itself but should remove the query template parsing logic from hub feeds api.

can you link to where we assign to locals?

It can be found here. Recent PR on hub feeds api. https://devtopia.esri.com/dc/hub-feeds-api/pull/128

src/index.ts Outdated
// Request a single dataset if id is provided, else default to site's catalog
const id = String(req.query.id || '');
req.res.locals.searchRequest = this.getDatasetSearchRequest(id, apiTerms) || this.getCatalogSearchRequest(req, _.get(siteModel, 'data.catalog'), apiTerms);
const { stream: dcatStream } = getDataStreamDcatUs11(feedTemplate, feedTemplateTransforms, nonEditableTemplateFields);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this will fail if the user's Koop instance doesn't add all these things to locals. Are these parameters things that could conceivable arrive on the req.query or req.body? Also are there default we can use in the event the request doesn't have all of these? If not, it would seem that we would want to a 400 error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these parameters things that could conceivable arrive on the req.query or req.body?

Currently, we expect users using the plugin to have a feed template object in their koop instance but we can allow template to be passed via req.query or req.body but should remove existing template parsing via query in hub feeds api as it would be redundant.

Also are there default we can use in the event the request doesn't have all of these? I

We could have a default one but dcat us feed has properties like title, landingPage whose values are dynamic. Feed template is essential to map these keys to appropriate values from datasource. There is no common data source as providers could be different. so, common mapping is not possible.

it would seem that we would want to a 400 error.

Currently responds if 400 error if feedTemplate not set.

@sansth1010 sansth1010 requested a review from rgwozdz February 3, 2023 06:50
@sansth1010 sansth1010 removed the draft label Feb 3, 2023
@sansth1010 sansth1010 changed the title [DNM] - removed dataset enrichment from dcat plugin removed dataset enrichment from dcat plugin Feb 3, 2023
src/index.ts Outdated
} = req;

if (!feedTemplate) {
throw new RemoteServerError('DCAT-US 1.1 feed template is not provided.', null, 400);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't want a "RemoteServerError" as it indicates the error originates from some other upstream server. You'd use this to distinguish an error originating from the hub-search service as opposed to the Koop feeds service.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created Custom error for errors originating at DCAT plugin.

theme: dcatDataset.spatial && ['geospatial']
}, null, '\t'), 2);
} catch (err) {
throw new RemoteServerError(err?.message || 'Error parsing feed template', null, 400);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't want a "RemoteServerError" as it indicates the error originates from some other upstream server. You'd use this to distinguish an error originating from the hub-search service as opposed to the Koop feeds service.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created Custom error for errors originating at DCAT plugin.

hubDataset.license = null;
}

export function formatDcatDataset(hubDataset: any, feedTemplate: DcatDatasetTemplate, feedTemplateTransforms: TransformsList) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the output plugin so it shouldn't have any knowledge that it is working with hubDatasets, so you should change the name of the param to something generic. Let's also change the name of this function to compileDcatFeedEntry.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! renamed hubDataset to feedData and renamed formatDcatDataset to compileDcatFeedEntry

) {
const siteModel = { item: { url: hostname } } as unknown as IModel;
async function generateDcatFeed(dataset, template, templateTransforms) {
// const siteModel = { item: { url: hostname } } as unknown as IModel;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Comment has been removed.


return indent(JSON.stringify(dcatDataset, null, '\t'), 2);
function removeUninterpolatedDistributions(distributions: any[]) {
return distributions.filter((distro) => !(typeof distro === 'string' && distro.match(/{{.+}}/)?.length));
}

// HUBJS CANDIDATE
function indent(str: string, nTabs = 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is indenting required for feeds to work? It will increase the payload size.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but this indenting might have been one of the requirements for displaying feed. @thomas-hervey can let us know. Otherwise, we can remove the indentation entirely.

@sansth1010 sansth1010 requested a review from rgwozdz February 4, 2023 04:52
src/index.ts Outdated
import { fetchSite, getHubApiUrl, getPortalApiUrl, hubApiRequest, IHubRequestOptions, RemoteServerError } from '@esri/hub-common';
import { IContentSearchRequest, SortDirection } from '@esri/hub-search';

import { RemoteServerError } from '@esri/hub-common';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this import is no longer require?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import has been removed.

Copy link
Member

@rgwozdz rgwozdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just the one import to remove.

Is there any coverage tooling on this repo? Curious where we are in terms of test coverage.

@sansth1010
Copy link
Collaborator Author

@rgwozdz : Test coverage as follows:

image

I do not think there is a coverage tooling on this repo yet but we can set it up.

@sansth1010 sansth1010 merged commit 7ee42b3 into beta Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants