Commit 2b09c780 authored by Quentin's avatar Quentin
Browse files

Transformed some functions into async functions

CHanged failHandlers to errorHandlers
Adding functions to handle processes
Fixedan error in SDMC json
parent a02a25e8
......@@ -94,26 +94,24 @@ export default {
}
},
// Post and start the corpus process given the corpus and the pipeline
submitCorpusProcess() {
async submitCorpusProcess() {
const data = {
corpusId: sessionStorage.getItem('corpusId'),
pipelineId: sessionStorage.getItem('pipelineId'),
userId:'5f60db3f30dee22c7d6f6058' // DUMMY ID
}
axios.post('/corpusProcesses', data)
.then( res => {
if (res.data.status !== "success") {
console.error(res.data.message);
this.errorMessage = res.data.message;
}
else {
try {
// Create corpus process
const res = await axios.post('/corpusProcesses', data);
const corpusProcessId = res.data.data.corpusProcess._id;
// Starts it
await axios.post(`/corpusProcesses/${corpusProcessId}/start`);
this.$router.push('/validation');
}
})
.catch( error => {
catch (error) {
console.error(error);
this.errorMessage = error;
})
}
}
},
components: {
......
......@@ -15,11 +15,11 @@
{
"name": "motif_representation",
"label": "Représentation condensée des motifs",
"description": null,
"description": "Trois types d'extraction vous sont proposées :\n\t\t- Fréquents : retourne tout les motifs qui apparaissent plus que le support minimal.\n\t\t-Fermés : ne retourne pas les sous motifs de même ou plus petite fréquence\n\t\tco- Maximaux : ne retourne aucun sous motifs",
"type": "List-Mono",
"items": ["Fermés (tous les motifs)", "Fermés (sans sous-motifs de même fréquence)",
"items": ["Fréquents (tous les motifs)", "Fermés (sans sous-motifs de même fréquence)",
"Maximaux (en ôtant les sous-motifs)"],
"default": "Fermés (tous les motifs)"
"default": "Fréquents (tous les motifs)"
},
{
"name": "minimal_gap",
......@@ -45,6 +45,22 @@
"items": null,
"default": "100"
},
{
"name": "minimal_size",
"label": "Taille minimale",
"description": "Nombre minimal de tokens d'un motif extrait",
"type": "Int",
"items": null,
"default": "0"
},
{
"name": "maximal_size",
"label": "Taille maximale",
"description": "Nombre maximal de tokens d'un motif extrait",
"type": "Int",
"items": null,
"default": "5"
},
{
"name": "categories",
"label": "Appartenance d'une ou plusieurs catégories",
......
......@@ -13,16 +13,17 @@ const path = require('path');
const fs = require('fs');
// DEBUG: find all corpora
exports.debug_corpus_list = function(req, res) {
CorpusModel.find({},(error, corpora) => {
if (error) { errorHandler(res, error); }
else {
successHandler(res, { corpora: corpora } );
exports.debug_corpus_list = async function (req, res) {
try {
const corpora = await CorpusModel.find({});
successHandler(res, { corpora })
}
catch (error) {
errorHandler(res, "debug_corpus_list: " + error);
}
})
}
// Add a new corpus
exports.corpus_create = function(req,res) {
exports.corpus_create = function (req, res) {
console.log("Demande d'ajout d'un corpus:")
console.log(req.body);
const newCorpus = CorpusModel({
......@@ -45,13 +46,13 @@ exports.corpus_create = function(req,res) {
if (error) { errorHandler(res, error); }
else {
console.log("Successfully added the corpus")
successHandler(res, { corpus: corpus}, 201);
successHandler(res, { corpus: corpus }, 201);
}
})
}
exports.corpus_file_upload = function(req, res) {
exports.corpus_file_upload = function (req, res) {
if (!req.files) {
failHandler(res, { uploadedFiles: 'No files were found'});
errorHandler(res, 'corpus_file_upload: No files were sent');
}
else {
let userId = req.body.userId;
......@@ -66,7 +67,7 @@ exports.corpus_file_upload = function(req, res) {
try {
if (files.length) {
files.forEach( file => {
files.forEach(file => {
let filePath = path.join(uploadDirectory, file.name);
if (fs.existsSync(filePath)) {
console.log(`File named ${file.name} already exists, replacing it`);
......@@ -81,7 +82,7 @@ exports.corpus_file_upload = function(req, res) {
console.log(`File named ${files.name} already exists, replacing it`);
}
files.mv(filePath);
resData.push({ name: files.name, mimetype: files.mimetype, size: files.size, path: filePath});
resData.push({ name: files.name, mimetype: files.mimetype, size: files.size, path: filePath });
}
successHandler(res, { uploadedFiles: resData });
}
......@@ -91,51 +92,62 @@ exports.corpus_file_upload = function(req, res) {
}
}
// Get an existing corpus
exports.corpus_get = function(req,res) {
exports.corpus_get = async function (req, res) {
const corpusId = req.params.corpusId;
CorpusModel.findById(corpusId, (error, corpus) => {
if (error) { errorHandler(res, error); }
try {
const corpus = await CorpusModel.findById(corpusId);
if (!corpus) {
failHandler(res, { corpus: `No corpus was found with id: ${corpusId}`}, 404);
errorHandler(res, `corpus_get: No corpus was found with id: ${corpusId}`, 404)
}
else {
successHandler(res, { corpus: corpus});
successHandler(res, { corpus });
}
}
catch (error) {
errorHandler(res, error);
}
})
}
// Modify an existing corpus
exports.corpus_modify = function(req,res) {
exports.corpus_modify = async function (req, res) {
const corpusId = req.params.corpusId;
CorpusModel.findByIdAndUpdate(corpusId, req.body, (error, corpus) => {
if (error) { errorHandler(res, error); }
try {
const corpus = await CorpusModel.findByIdAndUpdate(corpusId, req.body);
if (!corpus) {
failHandler(res, { corpus: `No corpus was found with id: ${corpusId}`}, 404);
errorHandler(res, `corpus_modify: No corpus was found with id: ${corpusId}`, 404);
}
else {
successHandler(res, { corpus: corpus});
successHandler(res, { corpus });
}
}
catch (error) {
errorHandler(res, error);
}
})
}
// Delete an existing corpus
exports.corpus_delete = function(req,res) {
exports.corpus_delete = async function (req, res) {
const corpusId = req.params.corpusId;
CorpusModel.findByIdAndDelete(corpusId, (error, corpus) => {
if (error) { errorHandler(res, error); }
try {
const corpus = await CorpusModel.findByIdAndDelete(corpusId)
if (!corpus) {
failHandler(res, { corpus: `No corpus was found with id: ${corpusId}`}, 404);
errorHandler(res, `corpus_delete: No corpus was found with id: ${corpusId}`, 404);
}
else {
successHandler(res, { corpus: null})
successHandler(res, { corpus: null })
}
}
catch (error) {
errorHandler(res, error);
}
});
}
// Get a summary of an existing corpus
exports.corpus_summary = function(req,res) {
exports.corpus_summary = async function (req, res) {
const corpusId = req.params.corpusId;
CorpusModel.findById(corpusId, (error, corpus) => {
if (error) { errorHandler(res, error); }
try {
const corpus = await CorpusModel.findById(corpusId);
if (!corpus) {
failHandler(res, { corpus: `No corpus was found with id: ${corpusId}`}, 404)
failHandler(res, { corpus: `No corpus was found with id: ${corpusId}` }, 404)
}
else {
// Almost the same than the model, except we only get the number of docs, and not its content.
......@@ -149,39 +161,71 @@ exports.corpus_summary = function(req,res) {
};
successHandler(res, { corpusSummary: corpusSummary });
}
}
catch (error) {
errorHandler(res, error);
}
}
// Get conllu of each documents in a corpus
// Merge it ?
exports.corpus_documents_get = async function (req,res) {
const corpusId = req.params.corpusId;
try {
const corpus = await CorpusModel.findById(corpusId);
if (!corpus) {
errorHandler(res,`corpus_documents_get: No corpus was found with id: ${corpusId}`, 404);
}
else {
let documentConlluList = []
corpus.documents.forEach(document => {
documentConlluList.push(
{ id: document._id, POStags: document.POStags,
lemmas: document.lemmas, tokens: document.tokens, tokensIdx: document.tokensIdx}
);
})
successHandler(res, { documentsConlluList: documentConlluList });
}
}
catch (error) {
errorHandler(res, error);
}
}
// Get a specific document in a corpus
exports.corpus_document_get = function(req, res) {
exports.corpus_document_get = async function (req, res) {
const corpusId = req.params.corpusId;
CorpusModel.findById(corpusId, (error, corpus) => {
if (error) { errorHandler(res, error); }
try {
const corpus = await CorpusModel.findById(corpusId);
if (!corpus) {
errorHandler(res, `No corpus was found with id: ${corpusId}`, 404);
errorHandler(res, `corpus_document_get: No corpus was found with id: ${corpusId}`, 404);
}
else {
let found = false;
const documentId = req.params.documentId;
corpus.documents.forEach( document => {
corpus.documents.forEach(document => {
if (document.id === documentId) {
successHandler(res, { corpus: { document : document }});
successHandler(res, { corpus: { document: document } });
found = true;
}
});
if (found) return;
else {
if (!found) {
errorHandler(res, `No document found at this index: ${documentId}`, 404);
}
}
})
}
catch (error) {
errorHandler(res, error);
}
}
// Change a document in a corpus
exports.corpus_document_modify = function(req, res) {
// NOT FINISHED
exports.corpus_document_modify = async function (req, res) {
const corpusId = req.params.corpusId;
CorpusModel.findById(corpusId, async (error, corpus) => {
if (error) { errorHandler(res, error); }
try {
const corpus = CorpusModel.findById(corpusId);
if (!corpus) {
errorHandler(res, `No corpus was found with id: ${corpusId}`, 404);
errorHandler(res, `corpus_document_modify: No corpus was found with id: ${corpusId}`, 404);
}
else {
const documentId = req.params.documentId;
......@@ -192,7 +236,7 @@ exports.corpus_document_modify = function(req, res) {
return;
}
let found;
corpus.documents.forEach( document => {
corpus.documents.forEach(document => {
if (document.id === documentId) {
document = Object.assign(document, conlluCol);
found = true;
......@@ -202,7 +246,7 @@ exports.corpus_document_modify = function(req, res) {
if (found) {
try {
let savedCorpus = await corpus.save();
successHandler(res, { message: `Successfully modified the document`});
successHandler(res, { message: `Successfully modified the document` });
}
catch (error) {
errorHandler(res, error);
......@@ -212,11 +256,14 @@ exports.corpus_document_modify = function(req, res) {
errorHandler(res, `No document was found with id: ${documentId}`);
}
}
})
}
catch (error) {
return;
}
}
// Change a document in a corpus
exports.corpus_document_basic_process_add = async function(req, res) {
exports.corpus_document_basic_process_add = async function (req, res) {
const corpusId = req.params.corpusId;
const documentId = req.params.documentId;
const basicProcessConlluCols = req.body;
......@@ -231,7 +278,7 @@ exports.corpus_document_basic_process_add = async function(req, res) {
return;
}
let isDocumentFound;
corpus.documents.forEach( document => {
corpus.documents.forEach(document => {
if (document.id === documentId) {
document = Object.assign(document, basicProcessConlluCols);
isDocumentFound = true;
......@@ -243,17 +290,15 @@ exports.corpus_document_basic_process_add = async function(req, res) {
return;
}
let savedCorpus = await corpus.save();
successHandler(res, { message: `Successfully modified the document`});
successHandler(res, { message: `Successfully modified the document` });
}
catch (error) {
errorHandler(res, error);
}
}
// Get a specific report from a document in a corpus
exports.corpus_document_report_get = function(req, res) {
exports.corpus_document_report_get = function (req, res) {
const corpusId = req.params.corpusId;
CorpusModel.findById(corpusId, (error, corpus) => {
if (error) { errorHandler(res, error); }
......@@ -265,12 +310,12 @@ exports.corpus_document_report_get = function(req, res) {
const document = corpus.documents[documentId];
if (!document) {
failHandler(res, { corpus: { document: `No document found at this index: ${documentId}`}}, 404);
failHandler(res, { corpus: { document: `No document found at this index: ${documentId}` } }, 404);
}
else {
// Get the report here
// const report = document.report[...];
successHandler(res, { corpus: { document: document}});
successHandler(res, { corpus: { document: document } });
}
}
})
......
......@@ -2,25 +2,24 @@
// Corpus Process Controller file
// ***
const CorpusProcessModel = require('../models/CorpusProcess.js')['CorpusProcessModel'];
const { CorpusProcessModel } = require('../models/CorpusProcess.js');
const PipelineModel = require('../models/Pipeline.js');
const CorpusProcess = require('../models/CorpusProcess.js');
const responseHelper = require('./lib/responseHelper');
const errorHandler = responseHelper.errorHandler;
const successHandler = responseHelper.successHandler;
const failHandler = responseHelper.failHandler; // For eg. "User not found" is a fail, not an error
const { errorHandler, successHandler } = require('./lib/responseHelper');
const moduleHelper = require('./lib/moduleHelper.js');
// DEBUG: find all corpus processes
exports.debug_corpus_process_list = function(req, res) {
CorpusProcessModel.find({},(error, corpusProcesses) => {
exports.debug_corpus_process_list = function (req, res) {
CorpusProcessModel.find({}, (error, corpusProcesses) => {
if (error) { errorHandler(res, error); }
else {
successHandler(res, { corpusProcesses: corpusProcesses } );
successHandler(res, { corpusProcesses: corpusProcesses });
}
})
}
// Add a new corpus process
exports.corpus_process_create = function(req,res) {
exports.corpus_process_create = function (req, res) {
const newCorpusProcess = CorpusProcessModel({
corpusId: req.body.corpusId,
pipelineId: req.body.pipelineId,
......@@ -30,87 +29,170 @@ exports.corpus_process_create = function(req,res) {
newCorpusProcess.save((error, corpusProcess) => {
if (error) { errorHandler(res, error); }
else {
successHandler(res, { corpusProcess: corpusProcess}, 201);
successHandler(res, { corpusProcess: corpusProcess }, 201);
}
})
}
// Get an existing corpus process
exports.corpus_process_get = function(req,res) {
exports.corpus_process_get = async function (req, res) {
const corpusProcessId = req.params.corpusProcessId;
CorpusProcessModel.findById(corpusProcessId, (error, corpusProcess) => {
if (error) { errorHandler(res, error); }
try {
const corpusProcess = await CorpusProcessModel.findById(corpusProcessId);
if (!corpusProcess) {
failHandler(res, { corpus: `No corpus process was found with id: ${corpusProcessId}`}, 404);
errorHandler(res, `No corpus process was found with id: ${corpusProcessId}`, 404);
}
else {
successHandler(res, { corpusProcess: corpusProcess});
successHandler(res, { corpusProcess });
}
}
catch (error) {
errorHandler(res, error);
}
})
}
// Modify an existing corpus
exports.corpus_process_modify = function(req,res) {
exports.corpus_process_modify = function (req, res) {
const corpusProcessId = req.params.corpusProcessId;
CorpusProcessModel.findByIdAndUpdate(corpusProcessId, req.body, (error, corpusProcess) => {
if (error) { errorHandler(res, error); }
if (!corpusProcess) {
failHandler(res, { corpusProcess: `No corpus process was found with id: ${corpusProcessId}`}, 404);
failHandler(res, { corpusProcess: `No corpus process was found with id: ${corpusProcessId}` }, 404);
}
else {
successHandler(res, { corpusProcess: corpusProcess});
successHandler(res, { corpusProcess: corpusProcess });
}
})
}
// Delete an existing corpus
exports.corpus_process_delete = function(req,res) {
exports.corpus_process_delete = function (req, res) {
const corpusProcessId = req.params.corpusProcessId;
CorpusProcessModel.findByIdAndDelete(corpusProcessId, (error, corpusProcess) => {
if (error) { errorHandler(res, error); }
if (!corpusProcess) {
failHandler(res, { corpusProcess: `No corpus process was found with id: ${corpusProcessId}`}, 404);
failHandler(res, { corpusProcess: `No corpus process was found with id: ${corpusProcessId}` }, 404);
}
else {
successHandler(res, { corpusProcess: null})
successHandler(res, { corpusProcess: null })
}
});
}
// Get the conllu of an existing corpus process
exports.corpus_process_conllu_get = function(res, req) {
exports.corpus_process_conllu_get = function (res, req) {
const corpusProcessId = req.params.corpusProcesId;
CorpusProcessModel.findById(corpusProcessId, (error, corpusProcess) => {
if(error) { errorHandler(res, error); }
if (error) { errorHandler(res, error); }
if (!corpusProcess) {
failHandler(res, { corpusProcess: `No corpus process was found with id: ${corpusProcessId}`}, 404);
failHandler(res, { corpusProcess: `No corpus process was found with id: ${corpusProcessId}` }, 404);
}
else {
// TO BE FILLED
successHandler(res, { corpusProcess: { conllu: 'TBD'} });
successHandler(res, { corpusProcess: { conllu: 'TBD' } });
}
})
}
// Get the status of an existing corpus process
exports.corpus_process_status_get = function(req,res) {
exports.corpus_process_status_get = function (req, res) {
const corpusProcessId = req.params.corpusProcessId;
CorpusProcessModel.findById(corpusProcessId, (error, corpusProcess) => {
if (error) { errorHandler(res, error); }
if (!corpusProcess) {
failHandler(res, { corpusProcess: `No corpus process was found with id: ${corpusProcesId}`}, 404)
failHandler(res, { corpusProcess: `No corpus process was found with id: ${corpusProcesId}` }, 404)
}
else {
//TO BE FILLED
successHandler(res, { corpusProcess: { status: 'TBD'} });
successHandler(res, { corpusProcess: { status: 'TBD' } });
}
})
}
// Get all corpus processes from a user
exports.corpus_process_user_get = function(req, res) {
exports.corpus_process_user_get = function (req, res) {
const userId = req.params.userId;
CorpusProcessModel.find({ userId: userId}, (error, corpusProcesses) => {
CorpusProcessModel.find({ userId: userId }, (error, corpusProcesses) => {
if (error) { errorHandler(res, error); }
if (!corpusProcesses) {
failHandler(res, { corpus: `No corpus processes were found with id: ${corpusProcessId}`}, 404);
failHandler(res, { corpus: `No corpus processes were found with id: ${corpusProcessId}` }, 404);
}
else {
successHandler(res, { corpusProcesses: corpusProcesses})
successHandler(res, { corpusProcesses: corpusProcesses })
}
})
}
// Add a new conllu col and possibly an output from a module
exports.corpus_process_add_process = async function (req, res) {
const corpusProcessId = req.params.corpusProcessId;
try {
let corpusProcess = await CorpusProcessModel.findById(corpusProcessId);
if (!corpusProcess) {
errorHandler(res, `No corpus processes were found with id: ${corpusProcessId}`, 404);
}
else {
if (corpusProcess.conlluCols && corpusProcess.conlluCols.length > 0) {
corpusProcess.conlluCols.push(req.body.conlluCol);
}
else {
corpusProcess.conlluCols = [req.body.conlluCol];
}
if (corpusProcess.outputs && corpusProcess.outputs.length > 0) {
corpusProcess.outputs.push(req.body.output);
}
else {
corpusProcess.outputs = [req.body.output];
}
corpusProcess = await corpusProcess.save();
successHandler(res, { corpusProcess });
}
}
catch (error) {
errorHandler(res, error);
}
}
exports.corpus_process_start = async function (req, res) {
const corpusProcessId = req.params.corpusProcessId;
let corpusProcess;
let started = false;
let pipeline;
try {
corpusProcess = await CorpusProcessModel.findById(corpusProcessId);
corpusProcess.status = 'Started';
await corpusProcess.save();
pipeline = await PipelineModel.findById(corpusProcess.pipelineId);
started = true;
successHandler(res, { message: "Pipeline started" });
}
catch (error) {
errorHandler(res, error);