Skip to content

Commit

Permalink
added the output part of results path
Browse files Browse the repository at this point in the history
  • Loading branch information
lathoub committed Sep 11, 2024
1 parent 0d68d92 commit e6c08f5
Show file tree
Hide file tree
Showing 17 changed files with 300 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ ID=demoservice

PORT=80

LIMIT=1000
LIMIT=10
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"cors": "^2.8.5",
"debug": "^4.3.5",
"docker-cli-js": "^2.10.0",
"express": "^4.18.2",
"express": "^4.20.0",
"jsonpath-plus": "^9.0.0",
"morgan": "^1.10.0",
"proj4": "^2.11.0",
Expand Down
2 changes: 1 addition & 1 deletion processen/addNumbers.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"outputs": {
"sum": {
"title": "Addition of 2 numbers",
"title": "Sum of 2 numbers",
"description": "A number literal output.",
"schema": {
"type": "number",
Expand Down
24 changes: 12 additions & 12 deletions processen/addNumbers/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ if (__dirname === undefined) console.log("need node 20.16 or higher");
* @param {*} callback
* @returns {*}
*/
export async function launch(process, job, isAsync, parameters, callback) {
export async function launch(process_, job, isAsync, parameters, callback) {
var values = [];
for (let [key, processInput] of Object.entries(process.inputs)) {
for (let [key, processInput] of Object.entries(process_.inputs)) {
if (parameters.inputs[key] == undefined)
return callback(
{ code: 400, description: `${key} not found` },
Expand Down Expand Up @@ -46,7 +46,7 @@ export async function launch(process, job, isAsync, parameters, callback) {
child.stdout.on("data", (d) => {
let content = {};

for (let [key, output] of Object.entries(process.outputs)) {
for (let [key, output] of Object.entries(process_.outputs)) {
let result = {};
result.id = key;

Expand All @@ -71,9 +71,9 @@ export async function launch(process, job, isAsync, parameters, callback) {
job.updated = new Date().toISOString();
job.results = content;

if (process.subscriber && process.subscriber.successUri) {
if (process_.subscriber && process_.subscriber.successUri) {
http
.post(process.subscriber.successUri, content)
.post(process_.subscriber.successUri, content)
.then(function (response) {
console.log(response);
})
Expand All @@ -90,9 +90,9 @@ export async function launch(process, job, isAsync, parameters, callback) {
job.finished = new Date().toISOString();
job.updated = new Date().toISOString();

if (process.subscriber && process.subscriber.failedUri) {
if (process_.subscriber && process_.subscriber.failedUri) {
http
.post(process.subscriber.failedUri, job.message)
.post(process_.subscriber.failedUri, job.message)
.then(function (response) {
console.log(response);
})
Expand Down Expand Up @@ -129,9 +129,9 @@ export async function launch(process, job, isAsync, parameters, callback) {
job.finished = new Date().toISOString();
job.updated = new Date().toISOString();

if (process.subscriber && process.subscriber.failedUri) {
if (process_.subscriber && process_.subscriber.failedUri) {
http
.post(process.subscriber.failedUri, job.message)
.post(process_.subscriber.failedUri, job.message)
.then(function (response) {
console.log(response);
})
Expand All @@ -145,7 +145,7 @@ export async function launch(process, job, isAsync, parameters, callback) {
let content = {};

// bring result into content
for (let [key, output] of Object.entries(process.outputs)) {
for (let [key, output] of Object.entries(process_.outputs)) {
let result = {};
result.id = key;

Expand All @@ -169,9 +169,9 @@ export async function launch(process, job, isAsync, parameters, callback) {
job.updated = new Date().toISOString();
job.results = content;

if (process.subscriber && process.subscriber.successUri) {
if (process_.subscriber && process_.subscriber.successUri) {
http
.post(process.subscriber.successUri, content)
.post(process_.subscriber.successUri, content)
.then(function (response) {
console.log(response);
})
Expand Down
12 changes: 6 additions & 6 deletions processen/countFeatures/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import http from "axios";
*
* @export
* @param {*} job
* @param {*} process
* @param {*} process_
* @param {*} parameters
* @param {*} callback
* @returns {*}
*/
export async function launch(process, job, isAsync, parameters, callback) {
export async function launch(process_, job, isAsync, parameters, callback) {
var values = [];
for (let [key, processInput] of Object.entries(process.inputs)) {
for (let [key, processInput] of Object.entries(process_.inputs)) {
if (parameters.inputs[key] == undefined)
return callback(
{ code: 400, description: `${key} not found` },
Expand All @@ -39,7 +39,7 @@ export async function launch(process, job, isAsync, parameters, callback) {
let content = {};

// bring result into content
for (let [key, output] of Object.entries(process.outputs)) {
for (let [key, output] of Object.entries(process_.outputs)) {
let result = {};
result.id = key;

Expand All @@ -63,9 +63,9 @@ export async function launch(process, job, isAsync, parameters, callback) {
job.updated = new Date().toISOString();
job.results = content;

if (process.subscriber && process.subscriber.successUri) {
if (process_.subscriber && process_.subscriber.successUri) {
http
.post(process.subscriber.successUri, content)
.post(process_.subscriber.successUri, content)
.then(function (response) {
console.log(response);
})
Expand Down
10 changes: 5 additions & 5 deletions processen/echoService/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ if (__dirname === undefined) console.log("need node 20.16 or higher");
* @param {*} callback
* @returns {*}
*/
export async function launch(process, job, isAsync, parameters, callback) {
export async function launch(process_, job, isAsync, parameters, callback) {
var values = [];
for (let [key, processInput] of Object.entries(process.inputs)) {
for (let [key, processInput] of Object.entries(process_.inputs)) {
if (parameters.inputs[key] == undefined)
return callback(
{ code: 400, description: `${key} not found` },
Expand Down Expand Up @@ -73,7 +73,7 @@ export async function launch(process, job, isAsync, parameters, callback) {
http
.get(values[0])
.then(function (response) {
for (let [key, output] of Object.entries(process.outputs)) {
for (let [key, output] of Object.entries(process_.outputs)) {
let result = {};
result.id = key;

Expand All @@ -98,9 +98,9 @@ export async function launch(process, job, isAsync, parameters, callback) {
job.updated = new Date().toISOString();
job.results = content;

if (process.subscriber && process.subscriber.successUri) {
if (process_.subscriber && process_.subscriber.successUri) {
http
.post(process.subscriber.successUri, content)
.post(process_.subscriber.successUri, content)
.then(function (response) {
console.log(response);
})
Expand Down
2 changes: 2 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ app.use(
})
);

app.set("json spaces", 2); // TODO: only when running DEBUG

// Deal with 'options' prior to cors,
app.options("*", mwOptions);

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/features/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function get(req, res, next) {

var options = {};
options.offset = Number(req.query.offset) || 0;
options.limit = Number(req.query.limit) || 1000;
options.limit = Number(req.query.limit) || Number(process.env.LIMIT);

// remve not to be confused with other query parameters
delete req.query.offset;
Expand Down
49 changes: 49 additions & 0 deletions src/controllers/processes/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import accepts from "accepts";
import output from "../../models/processes/output.js";
import utils from "../../utils/utils.js";

export function get(req, res) {
// (ADR) /core/no-trailing-slash Leave off trailing slashes from URIs (if not, 404)
// https://gitdocumentatie.logius.nl/publicatie/api/adr/#/core/no-trailing-slash
if (utils.ifTrailingSlash(req, res)) return;

var jobId = req.params.jobId;
var outputId = req.params.outputId;

var formatFreeUrl = utils.getFormatFreeUrl(req);
var serviceUrl = utils.getServiceUrl(req);

var accept = accepts(req);
var format = accept.type(["json", "html"]);

output.get(formatFreeUrl, format, jobId, outputId, function (err, content) {
if (err) {
res
.status(err.httpCode)
.json({ code: err.code, description: err.description });
return;
}

switch (format) {
case "json":
// Recommendations 10, Links included in payload of responses SHOULD also be
// included as Link headers in the HTTP response according to RFC 8288, Clause 3.
// This recommendation does not apply, if there are a large number of links included
// in a response or a link is not known when the HTTP headers of the response are created.
res.status(200).json(content);
break;
case `html`:
// Recommendations 10, Links included in payload of responses SHOULD also be
// included as Link headers in the HTTP response according to RFC 8288, Clause 3.
// This recommendation does not apply, if there are a large number of links included
// in a response or a link is not known when the HTTP headers of the response are created.
res.status(200).render(`results`, { content, serviceUrl });
break;
default:
res.status(400).json({
code: "InvalidParameterValue",
description: `${accept} is an invalid format`,
});
}
});
}
24 changes: 12 additions & 12 deletions src/models/processes/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getLinks(neutralUrl, format, name, links) {
});
}

function getContent(neutralUrl, process, body) {
function getContent(neutralUrl, process_, body) {
var content = {};
// A local identifier for the collection that is unique for the dataset;
content.id = name; // required
Expand Down Expand Up @@ -42,8 +42,8 @@ function post(neutralUrl, processId, parameters, prefer, callback) {
let serviceUrl = neutralUrl.substring(0, neutralUrl.indexOf("/processes"));

var processes = getProcesses();
var process = structuredClone(processes[processId]);
if (!process)
var process_ = structuredClone(processes[processId]);
if (!process_)
return callback(
{
code: 404,
Expand All @@ -53,7 +53,7 @@ function post(neutralUrl, processId, parameters, prefer, callback) {
);

// check parameters against the process input parameter definition
for (let [key, processInput] of Object.entries(process.inputs)) {
for (let [key, processInput] of Object.entries(process_.inputs)) {
if (parameters.inputs[key] == undefined)
return callback(
{ code: 400, description: `${key} not found` },
Expand All @@ -76,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 All @@ -85,7 +85,7 @@ function post(neutralUrl, processId, parameters, prefer, callback) {

// prepare for the launcher (launcher has a fixed name: launcher.js)
let pathToLauncher = join(
process.location.replace(/\.[^/.]+$/, ""),
process_.location.replace(/\.[^/.]+$/, ""),
"launch.js"
);
const fileExists = existsSync(pathToLauncher);
Expand All @@ -101,7 +101,7 @@ function post(neutralUrl, processId, parameters, prefer, callback) {
// async/sync is determined by the HTTP header prefer
if (
prefer.includes("async") &&
!process.jobControlOptions.includes("async-execute")
!process_.jobControlOptions.includes("async-execute")
)
return callback(
{
Expand All @@ -116,10 +116,10 @@ function post(neutralUrl, processId, parameters, prefer, callback) {
let job = create(processId, prefer.includes("async"));

// resolve all :<> with content
if (process.subscriber) {
for (var key in process.subscriber) {
if (process.subscriber.hasOwnProperty(key)) {
process.subscriber[key] = process.subscriber[key]
if (process_.subscriber) {
for (var key in process_.subscriber) {
if (process_.subscriber.hasOwnProperty(key)) {
process_.subscriber[key] = process_.subscriber[key]
.replaceAll(":serviceUrl", serviceUrl)
.replaceAll(":jobId", job.jobID);
}
Expand All @@ -128,7 +128,7 @@ function post(neutralUrl, processId, parameters, prefer, callback) {

execute(
pathToLauncher,
process,
process_,
job,
prefer.includes("async"),
parameters,
Expand Down
6 changes: 3 additions & 3 deletions src/models/processes/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ export function get(neutralUrl, format, jobId, callback) {
*
* @export
* @param {*} path
* @param {*} process
* @param {*} process_
* @param {*} parameters
* @param {*} job
* @param {*} callback
*/
export function execute(path, process, job, isAsync, parameters, callback) {
export function execute(path, process_, job, isAsync, parameters, callback) {
try {
import(path)
.then((module) => {
module.launch(
process,
process_,
job,
isAsync,
parameters,
Expand Down
Loading

0 comments on commit e6c08f5

Please sign in to comment.