-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
and some more fixes for codacy issues
- Loading branch information
Showing
3 changed files
with
89 additions
and
68 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,84 +1,116 @@ | ||
import urlJoin from 'url-join' | ||
import { getDatabases } from '../../database/database.js' | ||
import utils from '../../utils/utils.js' | ||
import urlJoin from "url-join"; | ||
import { getDatabases } from "../../database/database.js"; | ||
import utils from "../../utils/utils.js"; | ||
|
||
function getLinks(neutralUrl, format, name, links) { | ||
|
||
function getTypeFromFormat(format) { | ||
var _formats = ['json', 'html'] | ||
var _encodings = ['application/json', 'text/html'] | ||
var _formats = ["json", "html"]; | ||
var _encodings = ["application/json", "text/html"]; | ||
|
||
var i = _formats.indexOf(format); | ||
return _encodings[i] | ||
return _encodings[i]; | ||
} | ||
|
||
links.push({ href: urlJoin(neutralUrl, `?f=${format}`), rel: `self`, type: getTypeFromFormat(format), title: `The Document` }) | ||
utils.getAlternateFormats(format, ['json', 'html']).forEach(altFormat => { | ||
links.push({ href: urlJoin(neutralUrl, `?f=${altFormat}`), rel: `alternate`, type: getTypeFromFormat(altFormat), title: `The Document as ${altFormat}` }) | ||
}) | ||
|
||
links.push({ | ||
href: urlJoin(neutralUrl, `?f=${format}`), | ||
rel: `self`, | ||
type: getTypeFromFormat(format), | ||
title: `The Document`, | ||
}); | ||
utils.getAlternateFormats(format, ["json", "html"]).forEach((altFormat) => { | ||
links.push({ | ||
href: urlJoin(neutralUrl, `?f=${altFormat}`), | ||
rel: `alternate`, | ||
type: getTypeFromFormat(altFormat), | ||
title: `The Document as ${altFormat}`, | ||
}); | ||
}); | ||
} | ||
|
||
function getChildrenLinks(neutralUrl, format, name, links) { | ||
|
||
function getTypeFromFormat(format) { | ||
var _formats = ['json', 'geojson', 'html', 'csv'] | ||
var _encodings = ['application/geo+json', 'application/geo+json', 'text/html', 'text/csv'] | ||
|
||
var _formats = ["json", "geojson", "html", "csv"]; | ||
var _encodings = [ | ||
"application/geo+json", | ||
"application/geo+json", | ||
"text/html", | ||
"text/csv", | ||
]; | ||
|
||
var i = _formats.indexOf(format); | ||
return _encodings[i] | ||
return _encodings[i]; | ||
} | ||
|
||
links.push({ href: urlJoin(neutralUrl, `items?f=${format}`), rel: `items`, type: getTypeFromFormat(format), title: `Access the features in the collection as ${format}` }) | ||
utils.getAlternateFormats(format, ['json', 'html', 'csv']).forEach(altFormat => { | ||
links.push({ href: urlJoin(neutralUrl, `items?f=${altFormat}`), rel: `items`, type: getTypeFromFormat(altFormat), title: `Access the features in the collection as ${altFormat}` }) | ||
}) | ||
links.push({ | ||
href: urlJoin(neutralUrl, `items?f=${format}`), | ||
rel: `items`, | ||
type: getTypeFromFormat(format), | ||
title: `Access the features in the collection as ${format}`, | ||
}); | ||
utils | ||
.getAlternateFormats(format, ["json", "html", "csv"]) | ||
.forEach((altFormat) => { | ||
links.push({ | ||
href: urlJoin(neutralUrl, `items?f=${altFormat}`), | ||
rel: `items`, | ||
type: getTypeFromFormat(altFormat), | ||
title: `Access the features in the collection as ${altFormat}`, | ||
}); | ||
}); | ||
} | ||
|
||
function getMetaData(neutralUrl, format, name, document) { | ||
|
||
var content = {} | ||
var content = {}; | ||
// A local identifier for the collection that is unique for the dataset; | ||
content.id = name // required | ||
content.id = name; // required | ||
// An optional title and description for the collection; | ||
content.title = document.name | ||
content.description = document.description | ||
content.attribution = 'this dataset is attributed to the municipality of amstelveen' | ||
content.links = [] | ||
content.title = document.name; | ||
content.description = document.description; | ||
content.attribution = | ||
"this dataset is attributed to the municipality of amstelveen"; | ||
content.links = []; | ||
|
||
getLinks(neutralUrl, format, name, content.links) | ||
getChildrenLinks(neutralUrl, format, name, content.links) | ||
getLinks(neutralUrl, format, name, content.links); | ||
getChildrenLinks(neutralUrl, format, name, content.links); | ||
|
||
// An optional extent that can be used to provide an indication of the spatial and temporal | ||
// An optional extent that can be used to provide an indication of the spatial and temporal | ||
// extent of the collection - typically derived from the data; | ||
content.extent = document.extent | ||
content.extent = document.extent; | ||
// Requirement 16 A and B | ||
|
||
// An optional indicator about the type of the items in the collection | ||
// An optional indicator about the type of the items in the collection | ||
// (the default value, if the indicator is not provided, is 'feature'). | ||
content.itemType = 'feature' | ||
// An optional list of coordinate reference systems (CRS) in which geometries may be returned by the server. | ||
content.itemType = "feature"; | ||
// An optional list of coordinate reference systems (CRS) in which geometries may be returned by the server. | ||
// The default value is a list with the default CRS (WGS 84 with axis order longitude/latitude); | ||
content.crs = document.crs | ||
content.storageCrs = document.storageCrs | ||
content.crs = document.crs; | ||
content.storageCrs = document.storageCrs; | ||
|
||
return content | ||
return content; | ||
} | ||
|
||
function get(neutralUrl, format, collectionId, callback) { | ||
var query = { type: "FeatureCollection", name: `${collectionId}` }; | ||
var projection = { name: 1, crs: 1, _id: 1 }; | ||
|
||
var query = { type: 'FeatureCollection', name: `${collectionId}` }; | ||
var projection = { name: 1, crs: 1, _id: 1 } | ||
|
||
var collections = getDatabases() | ||
var collection = collections[collectionId] | ||
var collections = getDatabases(); | ||
var collection = collections[collectionId]; | ||
if (!collection) | ||
return callback({ 'httpCode': 404, 'code': `Collection not found: ${collectionId}`, 'description': 'Make sure you use an existing collectionId. See /Collections' }, undefined); | ||
|
||
var content = getMetaData(neutralUrl, format, collectionId, collection) | ||
return callback( | ||
{ | ||
httpCode: 404, | ||
code: `Collection not found: ${collectionId}`, | ||
description: | ||
"Make sure you use an existing collectionId. See /Collections", | ||
}, | ||
undefined | ||
); | ||
|
||
var content = getMetaData(neutralUrl, format, collectionId, collection); | ||
|
||
return callback(undefined, content); | ||
} | ||
|
||
export default { | ||
get | ||
} | ||
get, | ||
}; |
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