-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
src/index.ts
Outdated
|
||
if (!dcatConfig) { | ||
dcatConfig = _.get(siteModel, 'data.feeds.dcatUS11'); | ||
const { res: { locals: { feedTemplate, feedTemplateTransforms, nonEditableTemplateFields } } }: { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/index.ts
Outdated
} = req; | ||
|
||
if (!feedTemplate) { | ||
throw new RemoteServerError('DCAT-US 1.1 feed template is not provided.', null, 400); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/dcat-us/dataset-formatter.ts
Outdated
theme: dcatDataset.spatial && ['geospatial'] | ||
}, null, '\t'), 2); | ||
} catch (err) { | ||
throw new RemoteServerError(err?.message || 'Error parsing feed template', null, 400); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/dcat-us/dataset-formatter.ts
Outdated
hubDataset.license = null; | ||
} | ||
|
||
export function formatDcatDataset(hubDataset: any, feedTemplate: DcatDatasetTemplate, feedTemplateTransforms: TransformsList) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
src/dcat-us/index.test.ts
Outdated
) { | ||
const siteModel = { item: { url: hostname } } as unknown as IModel; | ||
async function generateDcatFeed(dataset, template, templateTransforms) { | ||
// const siteModel = { item: { url: hostname } } as unknown as IModel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment I think.
There was a problem hiding this comment.
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.
src/dcat-us/dataset-formatter.ts
Outdated
|
||
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
@rgwozdz : Test coverage as follows: I do not think there is a coverage tooling on this repo yet but we can set it up. |
Please ignore the failed test cases for now. It will be resolved before the merge to beta branch.
PR for #5618