Commit d63ae491 authored by Gilles Mouchard's avatar Gilles Mouchard
Browse files

Updated POST/PUT reviews.

parent b82d93e2
Pipeline #18091 passed with stages
in 10 minutes and 19 seconds
......@@ -16757,8 +16757,11 @@ paths:
content:
application/json:
schema:
type: string
description: informational message
description: IDs of inserted artefacts (i.e. review documents)
type: array
items:
description: ID of inserted artefact (i.e. review document)
type: string
401:
description: Unauthorized operation, returns an error message
headers:
......@@ -16850,6 +16853,14 @@ paths:
$ref: '#/components/headers/Access-Control-Allow-Methods'
Access-Control-Allow-Headers:
$ref: '#/components/headers/Access-Control-Allow-Headers'
content:
application/json:
schema:
description: IDs of inserted or updated artefacts (i.e. review documents)
type: array
items:
description: ID of inserted or updated artefact (i.e. review document)
type: string
401:
description: Unauthorized operation, returns an error message
headers:
......
......@@ -67,7 +67,6 @@
}
},
"required": [
"reviewID",
"reviewTitle",
"reviewOpenDate",
"reviewAuthor",
......
......@@ -24,7 +24,7 @@
* @param {string} dbName - database name
* @param {Array.<Object>} review_documents - Review documents
*
* @return {Promise} a promise
* @return {Promise.<Array<string> >} a promise (resolve argument is an array of document unique IDs in the collection)
*/
function insert_reviews(dbName, review_documents)
{
......
......@@ -25,11 +25,43 @@
* @param {Array.<Object>} review_documents - Review documents
* @param {boolean} update - flag to enable/disable replacing Review documents
*
* @return {Promise} a promise
* @return {Promise.<Array<string> >} a promise (resolve argument is an array of document unique IDs in the collection)
*/
function insert_update_reviews(dbName, review_documents, update)
{
return this.insert_update_documents(dbName, 'Reviews', review_documents, update, { signature : { reviewID : 1 } });
return new Promise(function(resolve, reject)
{
// If the reviewID field is present, convert it to a MongoDB Object ID, or allocate a new one
const ObjectID = require('mongodb').ObjectID;
try
{
review_documents.forEach((review_document) =>
{
try
{
review_document.reviewID = (review_document.hasOwnProperty('reviewID') ? new ObjectID(review_document.reviewID) : new ObjectID()).toHexString();
}
catch(err)
{
throw this.BadRequest('reviewID field is invalid: ' + err.message);
}
});
}
catch(err)
{
reject(this.Error(err));
return;
}
this.insert_update_documents(dbName, 'Reviews', review_documents, update, { signature : { reviewID : 1 } }).then(() =>
{
resolve(review_documents.map((review_document) => review_document.reviewID));
}).catch((err) =>
{
reject(this.Error(err));
});
}.bind(this));
}
exports.insert_update_reviews = insert_update_reviews;
......@@ -246,6 +246,7 @@ const { update_reviews } = require('./update_reviews');
const { insert_update_reviews } = require('./insert_update_reviews');
const { get_reviews } = require('./get_reviews');
const { delete_reviews } = require('./delete_reviews');
const { preprocess_reviews } = require('./preprocess_reviews');
const fs = require('fs');
const path = require('path');
......@@ -1786,6 +1787,7 @@ class PKM
this.preprocess['annotationsACSLPP'] = preprocess_cpp_annotations.bind(this);
this.preprocess['commentsCPP'] = preprocess_cpp_comments.bind(this);
this.preprocess['Logs'] = preprocess_logs.bind(this);
this.preprocess['Reviews'] = preprocess_reviews.bind(this);
this.get_file_collection_names().forEach((collection_name) =>
{
this.preprocess[collection_name] = preprocess_files.bind(this);
......@@ -2439,6 +2441,7 @@ class PKM
// case 'Tools' : return '';
// case 'TESTARSettings' : return '';
// case 'MethodologyStatus' : return '';
// case 'Reviews' : return '';
}
return undefined;
......
/*
* This file is part of PKM (Persistent Knowledge Monitor).
* Copyright (c) 2020 Capgemini Group, Commissariat à l'énergie atomique et aux énergies alternatives,
* OW2, Sysgo AG, Technikon, Tree Technology, Universitat Politècnica de València.
*
* PKM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation.
*
* PKM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this. If not, see <https://www.gnu.org/licenses/>.
*/
/** Preprocess review documents
*
* @memberof PKM
* @instance
* @param {Array.<Object>} review_documents - review documents
* @param {Object} [options] - options
*
* @return {Promise<Array.<Object>>} a promise
*/
function preprocess_reviews(review_documents, options = {})
{
return new Promise(function(resolve, reject)
{
try
{
review_documents.forEach((review_document) =>
{
[ 'reviewOpenDate', 'reviewCompletedDate' ].forEach((key) =>
{
if(review_document.hasOwnProperty(key) && !(review_document[key] instanceof Date))
{
let date = new Date(review_document[key]);
if((date instanceof Date) && isNaN(date.getTime()))
{
throw this.BadRequest('Invalidate date format for \'' + key + '\'');
}
review_document[key] = date;
}
});
});
}
catch(err)
{
reject(this.Error(err));
return;
}
resolve(review_documents);
}.bind(this));
}
module.exports.preprocess_reviews = preprocess_reviews;
......@@ -24,7 +24,7 @@
* @param {string} dbName - database name
* @param {Array.<Object>} review_documents - Review documents
*
* @return {Promise} a promise
* @return {Promise.<Array<string> >} a promise (resolve argument is an array of document unique IDs in the collection)
*/
function update_reviews(dbName, review_documents)
{
......
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="date" content='12/14/21'>
<meta name="date" content='12/16/21'>
<title>D1.5 Open source PKM server-side software</title>
<link rel="stylesheet" href='../style/style.css' type="text/css">
</head>
......@@ -44,7 +44,7 @@
<p>Chapter 2, which is intended for users and system administrators, presents the building, configuration, and installation process of the PKM and parsers. Chapters 3, 4, and 5, which are intended for developers, present the PKM implementation. Chapter 6 concludes this document. The appendix talks about the Javascript SDK of the PKM server, the generation flow of the REST servers and SDKs for the clients, and the test procedure that was implemented to automate the test of the PKM server and more generally the DECODER Project tool-chain.</p>
</div>
<div id="footer">
<span><a href="../index.html">D1.5 Open source PKM server-side software</a> - 12/14/21</span>
<span><a href="../index.html">D1.5 Open source PKM server-side software</a> - 12/16/21</span>
</div>
</body>
</html>
......@@ -1627,7 +1627,6 @@
}
},
&quot;required&quot;: [
&quot;reviewID&quot;,
&quot;reviewTitle&quot;,
&quot;reviewOpenDate&quot;,
&quot;reviewAuthor&quot;,
......
......@@ -1649,7 +1649,6 @@ The schema below for the reviews can be downloaded from the [pkm-api gitlab repo
}
},
"required": [
"reviewID",
"reviewTitle",
"reviewOpenDate",
"reviewAuthor",
......
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="date" content='12/14/21'>
<meta name="date" content='12/16/21'>
<title>D1.5 Open source PKM server-side software</title>
<link rel="stylesheet" href='../style/style.css' type="text/css">
</head>
......@@ -86,7 +86,7 @@
<p>Appendix A.2 contains detailed explanations about implementation design of the REST server that provides developer with the REST API.</p>
</div>
<div id="footer">
<span><a href="../index.html">D1.5 Open source PKM server-side software</a> - 12/14/21</span>
<span><a href="../index.html">D1.5 Open source PKM server-side software</a> - 12/16/21</span>
</div>
</body>
</html>
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="date" content='12/14/21'>
<meta name="date" content='12/16/21'>
<title>D1.5 Open source PKM server-side software</title>
<link rel="stylesheet" href='../style/style.css' type="text/css">
</head>
......@@ -22,7 +22,7 @@
<p>The PKM server have also its own limitations that deserve attention in future developments. The PKM files, and more generally the artefacts in the PKM, have no revision numbers so that it is not easy to track progressive enhancement of the knowledge in the PKM. The PKM users management, especially concerning the user’s roles, is tightly geared to the MongoDB user’s management, which is database oriented, but it is not necessarily convenient for a SaaS approach. Direct upload (as attachment in a POST HTTP request) toward the database is unsupported due to the limitations of OpenAPI supporting tools.</p>
</div>
<div id="footer">
<span><a href="../index.html">D1.5 Open source PKM server-side software</a> - 12/14/21</span>
<span><a href="../index.html">D1.5 Open source PKM server-side software</a> - 12/16/21</span>
</div>
</body>
</html>
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="date" content='12/14/21'>
<meta name="date" content='12/16/21'>
<title>D1.4 Open source client-side software</title>
<link rel="stylesheet" href='../style/style.css' type="text/css">
</head>
......@@ -65,7 +65,7 @@
<p>Figure 3 shows the logical organization of this document (chapter numbers are highlighted in blue circles), which follows the order of actions to use properly the PKM and the parsers. Chapter 2 shows how to get the general server information such as the version numbers. Chapter 3 presents the management of the user’s session and particularly the way to authenticate with the PKM. Chapters 4 and 5 present the administrative tasks such as the users and project management. Chapter 6 presents how to deal with Git repositories. Chapter 7 shows how to populate the PKM with artefacts. Chapter 8 presents how to invoke parser to generate new artefacts. Chapter 9 shows how to query artefacts of a project. Chapter 10 concludes this document. The Appendix details the REST APIs and the command line interface (CLI).</p>
</div>
<div id="footer">
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/14/21</span>
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/16/21</span>
</div>
</body>
</html>
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="date" content='12/14/21'>
<meta name="date" content='12/16/21'>
<title>D1.4 Open source client-side software</title>
<link rel="stylesheet" href='../style/style.css' type="text/css">
</head>
......@@ -20,7 +20,7 @@
<p>This document has described the PKM APIs: a command line interface (CLI) and REST APIs. While the command line interface has been historically the first PKM API available, the REST APIs made it obsolete because it was unsuitable for a SaaS deployment where the data and computing resources are deported in the cloud. Indeed, the REST APIs have allowed connecting the DECODER Project tools together over communication networks and creating a GUI front-end as a web application. Every components of the DECODER Project tool-chain, running on separate docker containers, are now able to exchange thanks to these REST APIs. Using the OpenAPI specifications made it easier to document REST APIs and write SDKs for PKM and parsers clients. The REST APIs will permit extending the DECODER Project tool-chain and connecting third party tools to the existing tool-chain. Hopefully, containerized tool-chain components and the REST APIs should enable a SaaS deployment in the future.</p>
</div>
<div id="footer">
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/14/21</span>
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/16/21</span>
</div>
</body>
</html>
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="date" content='12/14/21'>
<meta name="date" content='12/16/21'>
<title>D1.4 Open source client-side software</title>
<link rel="stylesheet" href='../style/style.css' type="text/css">
</head>
......@@ -66,7 +66,7 @@
}</code></pre>
</div>
<div id="footer">
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/14/21</span>
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/16/21</span>
</div>
</body>
</html>
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="date" content='12/14/21'>
<meta name="date" content='12/16/21'>
<title>D1.4 Open source client-side software</title>
<link rel="stylesheet" href='../style/style.css' type="text/css">
</head>
......@@ -37,7 +37,7 @@
<p>This operation creates another the user’s session, and returns a new PKM access key that identifies the new user’s session. The new user’s session is independent from the original user’s session which means that when the later ends, the former is still alive, and vice-versa.</p>
</div>
<div id="footer">
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/14/21</span>
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/16/21</span>
</div>
</body>
</html>
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="date" content='12/14/21'>
<meta name="date" content='12/16/21'>
<title>D1.4 Open source client-side software</title>
<link rel="stylesheet" href='../style/style.css' type="text/css">
</head>
......@@ -143,7 +143,7 @@
<p>The writer do not recommend the use of these legacy commands.</p>
</div>
<div id="footer">
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/14/21</span>
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/16/21</span>
</div>
</body>
</html>
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="date" content='12/14/21'>
<meta name="date" content='12/16/21'>
<title>D1.4 Open source client-side software</title>
<link rel="stylesheet" href='../style/style.css' type="text/css">
</head>
......@@ -124,7 +124,7 @@
<p>The writer do not recommend the use of these legacy commands.</p>
</div>
<div id="footer">
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/14/21</span>
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/16/21</span>
</div>
</body>
</html>
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="date" content='12/14/21'>
<meta name="date" content='12/16/21'>
<title>D1.4 Open source client-side software</title>
<link rel="stylesheet" href='../style/style.css' type="text/css">
</head>
......@@ -113,7 +113,7 @@
<p>Note that the default behavior of the PKM is to fully synchronize the PKM Files and the Git working trees before and after running a Git command sequence, and after when deleting some files in a Git working tree.</p>
</div>
<div id="footer">
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/14/21</span>
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/16/21</span>
</div>
</body>
</html>
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="date" content='12/14/21'>
<meta name="date" content='12/16/21'>
<title>D1.4 Open source client-side software</title>
<link rel="stylesheet" href='../style/style.css' type="text/css">
</head>
......@@ -1008,7 +1008,7 @@
<p>When the query part is missing, this deletes all the Methodology phases.</p>
</div>
<div id="footer">
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/14/21</span>
<span><a href="../index.html">D1.4 Open source client-side software</a> - 12/16/21</span>
</div>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment