Skip to content

Commit

Permalink
fixing some more codacy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lathoub committed Sep 9, 2024
1 parent 42acbbf commit 8cfed97
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/models/processes/callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function post(neutralUrl, jobId, query, callback) {
undefined
);

/*
/*
switch (query.type) {
}
*/
Expand Down
14 changes: 8 additions & 6 deletions src/models/processes/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ function post(neutralUrl, processId, parameters, prefer, callback) {

// check parameters against the process input parameter definition
for (let [key, processInput] of Object.entries(process.inputs)) {
if (parameters.inputs[key] == undefined)
return callback({ code: 400, description: `${key} not found` }, undefined);
if (parameters.inputs[key] == undefined)
return callback(
{ code: 400, description: `${key} not found` },
undefined
);
switch (processInput.schema.type) {
case "number":
if (typeof parameters.inputs[key] !== "number")
if (typeof parameters.inputs[key] !== "number")
return callback(
{
code: 400,
Expand All @@ -73,7 +76,7 @@ function post(neutralUrl, processId, parameters, prefer, callback) {
}

for (let [key, processInput] of Object.entries(parameters.inputs)) {
if (process.inputs[key] == undefined)
if (process.inputs[key] == undefined)
return callback(
{ code: 400, description: `${key} not found in process definition` },
undefined
Expand Down Expand Up @@ -130,8 +133,7 @@ function post(neutralUrl, processId, parameters, prefer, callback) {
prefer.includes("async"),
parameters,
function (err, content) {
if (err)
return callback(err, undefined);
if (err) return callback(err, undefined);

// indication in the header of the location of the
// newly created job resource
Expand Down
18 changes: 14 additions & 4 deletions src/models/processes/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ function getLinks(neutralUrl, format, jobId, links) {
return _encodings[i];
}

links.push({ href: urlJoin(neutralUrl, jobId, `?f=${format}`), rel: `self`, type: getTypeFromFormat(format), title: `Job information as ${format}` })
utils.getAlternateFormats(format, ['json', 'html']).forEach(altFormat => {
links.push({ href: urlJoin(neutralUrl, jobId, `?f=${altFormat}`), rel: `alternate`, type: getTypeFromFormat(altFormat), title: `Job information as ${altFormat}` })
})
links.push({
href: urlJoin(neutralUrl, jobId, `?f=${format}`),
rel: `self`,
type: getTypeFromFormat(format),
title: `Job information as ${format}`,
});
utils.getAlternateFormats(format, ["json", "html"]).forEach((altFormat) => {
links.push({
href: urlJoin(neutralUrl, jobId, `?f=${altFormat}`),
rel: `alternate`,
type: getTypeFromFormat(altFormat),
title: `Job information as ${altFormat}`,
});
});

links.push({
href: urlJoin(neutralUrl, jobId, "results", `?f=${format}`),
Expand Down
11 changes: 7 additions & 4 deletions src/models/processes/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ export function create(processId, isAsync) {
}

function e7() {
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c =>
(+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) =>
(
+c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (+c / 4)))
).toString(16)
);
}

let job = {};
job.processID = processId;
job.jobID = e7();
Expand All @@ -80,7 +83,7 @@ function get(neutralUrl, format, callback) {
// (OAPIC P2) Requirement 3A: The content of that response SHALL be based upon the JSON schema collections.yaml.
var content = {};

content.links = getContent(neutralUrl, format)
content.links = getContent(neutralUrl, format);

content.jobs = [];

Expand Down
106 changes: 67 additions & 39 deletions src/models/processes/process.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,90 @@
import urlJoin from 'url-join'
import utils from '../../utils/utils.js'
import { getProcesses } from '../../database/processes.js'
import urlJoin from "url-join";
import utils from "../../utils/utils.js";
import { getProcesses } from "../../database/processes.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,), rel: `self`, type: getTypeFromFormat(format), title: `Process description as ${format}` })
utils.getAlternateFormats(format, ['json', 'html']).forEach(altFormat => {
links.push({ href: urlJoin(neutralUrl, `?f=${altFormat}`), rel: `alternate`, type: getTypeFromFormat(altFormat), title: `Process description as ${altFormat}` })
})

let serviceUrl = neutralUrl.substring(0, neutralUrl.indexOf('processes'));

links.push({ href: urlJoin(serviceUrl, 'jobs?f=html'), rel: `http://www.opengis.net/def/rel/ogc/1.0/job-list`, type: 'text/html', title: `Jobs list as HTML` })
links.push({ href: urlJoin(serviceUrl, 'jobs?f=json'), rel: `http://www.opengis.net/def/rel/ogc/1.0/job-list`, type: 'application/json', title: `Jobs list as JSON` })

links.push({ href: urlJoin(neutralUrl, 'execution'), rel: `http://www.opengis.net/def/rel/ogc/1.0/execute`, title: `Execute endpoint` })
links.push({
href: urlJoin(neutralUrl),
rel: `self`,
type: getTypeFromFormat(format),
title: `Process description as ${format}`,
});
utils.getAlternateFormats(format, ["json", "html"]).forEach((altFormat) => {
links.push({
href: urlJoin(neutralUrl, `?f=${altFormat}`),
rel: `alternate`,
type: getTypeFromFormat(altFormat),
title: `Process description as ${altFormat}`,
});
});

let serviceUrl = neutralUrl.substring(0, neutralUrl.indexOf("processes"));

links.push({
href: urlJoin(serviceUrl, "jobs?f=html"),
rel: `http://www.opengis.net/def/rel/ogc/1.0/job-list`,
type: "text/html",
title: `Jobs list as HTML`,
});
links.push({
href: urlJoin(serviceUrl, "jobs?f=json"),
rel: `http://www.opengis.net/def/rel/ogc/1.0/job-list`,
type: "application/json",
title: `Jobs list as JSON`,
});

links.push({
href: urlJoin(neutralUrl, "execution"),
rel: `http://www.opengis.net/def/rel/ogc/1.0/execute`,
title: `Execute endpoint`,
});
}

function getContent(neutralUrl, format, name, process) {
var content = {};
content.id = process.id;
content.title = process.title;
content.description = process.description;
content.version = process.version;
content.jobControlOptions = process.jobControlOptions;
content.outputTransmission = process.outputTransmission;

var content = {}
content.id = process.id
content.title = process.title
content.description = process.description
content.version = process.version
content.jobControlOptions = process.jobControlOptions
content.outputTransmission = process.outputTransmission

content.inputs = process.inputs
content.outputs = process.outputs
content.inputs = process.inputs;
content.outputs = process.outputs;

content.links = []
content.links = [];

getLinks(neutralUrl, format, name, content.links)
getLinks(neutralUrl, format, name, content.links);

return content
return content;
}

function get(neutralUrl, format, processId, callback) {

var processes = getProcesses()
var process = processes[processId]
var processes = getProcesses();
var process = processes[processId];
if (!process)
return callback({ 'httpCode': 404, 'code': `Process not found: ${processId}`, 'description': 'Make sure you use an existing processId. See /processes' }, undefined);
return callback(
{
httpCode: 404,
code: `Process not found: ${processId}`,
description: "Make sure you use an existing processId. See /processes",
},
undefined
);

var content = getContent(neutralUrl, format, processId, process)
var content = getContent(neutralUrl, format, processId, process);

return callback(undefined, content);
}

export default {
get
}
get,
};
111 changes: 71 additions & 40 deletions src/models/processes/processes.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,96 @@
import urlJoin from 'url-join'
import utils from '../../utils/utils.js'
import { getProcesses } from '../../database/processes.js'

function getLinks(neutralUrl, format, name, links) {
import urlJoin from "url-join";
import utils from "../../utils/utils.js";
import { getProcesses } from "../../database/processes.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, name ), type: getTypeFromFormat(format), rel: `self`, title: `process description as ${format}` })
utils.getAlternateFormats(format, ['json', 'html']).forEach(altFormat => {
links.push({ href: urlJoin(neutralUrl, name, `?f=${altFormat}`), rel: `alternate`, type: getTypeFromFormat(altFormat), title: `Process description as ${altFormat}` })
})

let serviceUrl = neutralUrl.substring(0, neutralUrl.indexOf('processes'));

links.push({ href: urlJoin(serviceUrl, 'jobs?f=html'), rel: `http://www.opengis.net/def/rel/ogc/1.0/job-list`, type: 'text/html', title: `Jobs list as HTML` })
links.push({ href: urlJoin(serviceUrl, 'jobs?f=json'), rel: `http://www.opengis.net/def/rel/ogc/1.0/job-list`, type: 'application/json', title: `Jobs list as JSON` })

links.push({ href: urlJoin(neutralUrl, name, 'execution'), rel: `http://www.opengis.net/def/rel/ogc/1.0/execute`, title: `Execute endpoint` })
links.push({
href: urlJoin(neutralUrl, name),
type: getTypeFromFormat(format),
rel: `self`,
title: `process description as ${format}`,
});
utils.getAlternateFormats(format, ["json", "html"]).forEach((altFormat) => {
links.push({
href: urlJoin(neutralUrl, name, `?f=${altFormat}`),
rel: `alternate`,
type: getTypeFromFormat(altFormat),
title: `Process description as ${altFormat}`,
});
});

let serviceUrl = neutralUrl.substring(0, neutralUrl.indexOf("processes"));

links.push({
href: urlJoin(serviceUrl, "jobs?f=html"),
rel: `http://www.opengis.net/def/rel/ogc/1.0/job-list`,
type: "text/html",
title: `Jobs list as HTML`,
});
links.push({
href: urlJoin(serviceUrl, "jobs?f=json"),
rel: `http://www.opengis.net/def/rel/ogc/1.0/job-list`,
type: "application/json",
title: `Jobs list as JSON`,
});

links.push({
href: urlJoin(neutralUrl, name, "execution"),
rel: `http://www.opengis.net/def/rel/ogc/1.0/execute`,
title: `Execute endpoint`,
});
}

function getContent(neutralUrl, format, name, document) {
var content = {};
content.id = document.id;
content.title = document.title;
content.description = document.description;
content.version = document.version;
content.jobControlOptions = document.jobControlOptions;
content.outputTransmission = document.outputTransmission;

var content = {}
content.id = document.id
content.title = document.title
content.description = document.description
content.version = document.version
content.jobControlOptions = document.jobControlOptions
content.outputTransmission = document.outputTransmission

content.links = []
content.links = [];

getLinks(neutralUrl, format, name, content.links)
getLinks(neutralUrl, format, name, content.links);

return content
return content;
}

function get(neutralUrl, format, callback) {

var content = {};

content.links = []
content.links = [];
// (OAPIC P2) Requirement 2B. The API SHALL support the HTTP GET operation on all links to a Collections Resource that have the relation type
content.links.push({ href: urlJoin(neutralUrl, `?f=${format}`), rel: `self`, type: utils.getTypeFromFormat(format), title: `This document` })
utils.getAlternateFormats(format, ['json', 'html']).forEach(altFormat => {
content.links.push({ href: urlJoin(neutralUrl, `?f=${altFormat}`), rel: `alternate`, type: utils.getTypeFromFormat(altFormat), title: `This document as ${altFormat}` })
})
content.links.push({
href: urlJoin(neutralUrl, `?f=${format}`),
rel: `self`,
type: utils.getTypeFromFormat(format),
title: `This document`,
});
utils.getAlternateFormats(format, ["json", "html"]).forEach((altFormat) => {
content.links.push({
href: urlJoin(neutralUrl, `?f=${altFormat}`),
rel: `alternate`,
type: utils.getTypeFromFormat(altFormat),
title: `This document as ${altFormat}`,
});
});

content.processes = [];

var processes = getProcesses()
var processes = getProcesses();

// get content per :process
for (var name in processes) {
var process = getContent(neutralUrl, format, name, processes[name])
var process = getContent(neutralUrl, format, name, processes[name]);
content.processes.push(process);
}

Expand All @@ -68,4 +99,4 @@ function get(neutralUrl, format, callback) {

export default {
get,
}
};
2 changes: 1 addition & 1 deletion src/models/processes/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function getLinks(neutralUrl, format, links) {
}

export function getContent(neutralUrl, format, job) {
var content = job.results
var content = job.results;
content.links = [];

getLinks(neutralUrl, format, content.links);
Expand Down

0 comments on commit 8cfed97

Please sign in to comment.