Skip to content

Commit

Permalink
Merge pull request #562 from salimkanoun/dev
Browse files Browse the repository at this point in the history
0.6.2
  • Loading branch information
salimkanoun authored May 12, 2021
2 parents d454865 + 890fd6f commit bc5f15b
Show file tree
Hide file tree
Showing 33 changed files with 323 additions and 326 deletions.
25 changes: 21 additions & 4 deletions BackEnd/adapter/bullAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const REDIS_OPTIONS = {
}

const queues = [];
const CLEAN_GRACE = 50;
const CLEAN_GRACE = 0;
const DEFAULT_POOL_SIZE = 10;

class Queue extends event.EventEmitter {
Expand Down Expand Up @@ -49,6 +49,10 @@ class Queue extends event.EventEmitter {
}
this.emit('error', err);
});
this._queue.on('failed', (job, err) => {
console.log(err);
this.emit('failed', job, err);
});
queues.push(this);
}

Expand Down Expand Up @@ -122,7 +126,14 @@ class Queue extends event.EventEmitter {
* Remove all jobs of the queue
* @returns {Promise<>} Promise resolved when the clean is done
*/
clean = () => Promise.all(Object.values(Queue._JOB_STATES_CLEAN).map(x => this._queue.clean(CLEAN_GRACE, x)));
clean = async () => {
await Promise.all(Object.values(Queue._JOB_STATES_CLEAN).map(x => this._queue.clean(CLEAN_GRACE, x)))

await this._queue.getActive().then(
jobs => Promise.all(jobs.map(job => job.releaseLock().then(
() => job.remove()))));

};

/**
* Returns a promise completed when the queue is ready
Expand All @@ -146,16 +157,17 @@ class Queue extends event.EventEmitter {

static _batch_processor(processor) {
return async (job, done) => {
job.progress(new Array(job.data.jobs.length).fill(null));
let subJobs = job.data.jobs.map((j, i) => {
return {
data: j,
progress: async (progress = null) => {
let prog = await job.progress() || [];
let prog = await job.progress();
if (progress) {
prog[i] = progress;
await job.progress(prog);
}
return prog;
return prog[i];
}
}
});
Expand Down Expand Up @@ -216,6 +228,10 @@ class Job {
update(data) {
return this._bullJob.update(data);
}

remove() {
return this._bullJob.remove()
}
}

Queue.Job = Job;
Expand Down Expand Up @@ -256,6 +272,7 @@ class BatchedJob extends Job {
this._bullJob.data.jobs[this._i] = data;
return this._bullJob.update(this._bullJob.data);
}

}

Queue.JOB_STATES = {
Expand Down
4 changes: 2 additions & 2 deletions BackEnd/controllers/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const addDeleteTask = async (req, res) => {
*/
const addRetrieveTask = async (req, res) => {

let answers = req.body.retrieveArray
let id = await RetrieveTask.createTask(req.roles.username, req.body.projectName, answers);
let retrieveArray = req.body.retrieveArray
let id = await RetrieveTask.createTask(req.roles.username, req.body.projectName, retrieveArray);
res.send(id)
}

Expand Down
1 change: 1 addition & 0 deletions BackEnd/model/Ldap.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const Ldap = {

getAllCorrespondences: async () => {
const correspondances = await DistantUser.getAllLocalRoleAndLdapGroup()
let results = []
correspondances.forEach( (correspondance) => {
results.push({ localRole: correspondance.local_role, ldapGroup: correspondance.ldap_group })
});
Expand Down
2 changes: 1 addition & 1 deletion BackEnd/model/Orthanc.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class Orthanc {
}

async makeAnon(level, orthancID, profile, newAccessionNumber, newPatientID, newPatientName, newStudyDescription, synchronous) {
let postData = this.buildAnonQuery(profile, newAccessionNumber, newPatientID, newPatientName, newStudyDescription, synchronous);
let postData = this.buildAnonQuery(profile, newAccessionNumber, newPatientID, newPatientName, newStudyDescription, synchronous)
const answer = await ReverseProxy.getAnswer('/' + level + '/' + orthancID + '/anonymize', 'POST', postData)
return answer
}
Expand Down
2 changes: 1 addition & 1 deletion BackEnd/model/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class Users {
async getLDAPUserRight() {

//Get Ldap Group having a local role correspondance
const ldapMatches = await DistantUser.getAllDistantUser()
const ldapMatches = await DistantUser.getAllLocalRoleAndLdapGroup()

//Flatten known LdapGroup in Array
let knownLdapGroups = ldapMatches.map((match) => {
Expand Down
14 changes: 10 additions & 4 deletions BackEnd/model/tasks/AnonTask.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const {OTJSForbiddenException} = require("../../Exceptions/OTJSErrors");
const { OTJSForbiddenException } = require("../../Exceptions/OTJSErrors");
const TaskType = require("../TaskType");
const Queue = require('../../adapter/bullAdapter');
const Orthanc = require('../Orthanc');
const {v4: uuid} = require('uuid');
const { v4: uuid } = require('uuid');

let orthanc = new Orthanc();
const JOBS_TTL = 5;
Expand Down Expand Up @@ -159,7 +159,7 @@ class AnonTask {
*/
static async delete(taskId) {
let anonJobs = await AnonTask._getJobs(taskId);
anonJobs.forEach(job => job.remove()); //Delete jobs of the task
anonJobs.forEach(job => { job.remove() }); //Delete jobs of the task
}

/**
Expand Down Expand Up @@ -198,7 +198,13 @@ class AnonTask {
let item = job.data.item

//Requesting orthanc API to anonymize a study
let anonAnswer = await orthanc.makeAnon('studies', item.orthancStudyID, item.profile, item.newAccessionNumber, item.newPatientID, item.newPatientName, item.newStudyDescription, false);


let anonAnswer = await orthanc.makeAnon('studies', item.orthancStudyID, item.profile, item.newAccessionNumber, item.newPatientID, item.newPatientName, item.newStudyDescription, false).catch((err) => {
console.error(item)
console.error(err);
done(err);
})

//Monitor orthanc job
orthanc.monitorJob(anonAnswer.Path, (response) => {
Expand Down
4 changes: 2 additions & 2 deletions BackEnd/model/tasks/ExportTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class ExportTask {
* Remove all jobs for export
*/
static async flush() {
await Promise.all(JOBS_STATUS.map(x => archiveQueue.clean()));
await Promise.all(JOBS_STATUS.map(x => exporter.sendQueue.clean(1, x)));
archiveQueue.clean()
exporter.sendQueue.clean()
}

/**
Expand Down
30 changes: 16 additions & 14 deletions BackEnd/model/tasks/RetrieveTask.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const {OTJSForbiddenException, OTJSNotFoundException} = require("../../Exceptions/OTJSErrors");
const { OTJSForbiddenException, OTJSNotFoundException, OTJSBadRequestException } = require("../../Exceptions/OTJSErrors");
const Orthanc = require("../Orthanc");
const TaskType = require("../TaskType");
const Queue = require("../../adapter/bullAdapter");
const OrthancQueryAnswer = require("../OrthancData/queries-answer/OrthancQueryAnswer");
const {v4: uuid} = require('uuid');
const { v4: uuid } = require('uuid');
const schedule = require('node-schedule');
const Options = require('../Options');
const time = require('../../utils/time');
Expand All @@ -29,8 +29,10 @@ class RetrieveTask {

let retrieve = 0;
for (const job of retrieveJobs) {
retrieve += await job.progress();
let jobProgress = await job.progress()
if (jobProgress != null) retrieve += jobProgress
}

retrieve /= (retrieveJobs.length === 0 ? 1 : retrieveJobs.length);
return {
validation,
Expand Down Expand Up @@ -110,17 +112,18 @@ class RetrieveTask {
*/
static async validateTask(id) {
let task = await RetrieveTask.getTask(id);
if (task === null) throw new OTJSNotFoundException("No task of this kind");

let jobs = await validationQueue.getJobs();
if (task === null) throw new OTJSNotFoundException("No task of this kind");
if (task.progress.validation != 100 ) throw OTJSBadRequestException("Items validation still in progress")
let jobs = await validationQueue.getJobs()

let jobsData = [];
for (const job of jobs) {
jobsData.push(
{
data: job.data
});
if (!await job.finished()) return;
}
);
}
await retrieveQueue.addJobs(jobsData);
}
Expand All @@ -138,15 +141,14 @@ class RetrieveTask {
let progress = await RetrieveTask.getProgress(validationJobs, retrieveJobs);

//Making state
let state = null;
if (progress.validation === 0) {
state = 'waiting validation';
} else if (progress.validation < 100) {
state = 'validation';
let state = null

if (progress.validation < 100) {
state = 'validating robot';
} else if (progress.validation === 100 && progress.retrieve === 0 && retrieveJobs.length === 0) {
state = 'waiting retireve'
state = 'waiting admin validation'
} else if (progress.validation === 100 && progress.retrieve < 100 && retrieveJobs.length !== 0) {
state = 'retrieve';
state = 'retrieving';
} else if (progress.validation === 100 && progress.retrieve === 100 && retrieveJobs.length !== 0) {
state = 'completed';
for (const job of validationJobs) {
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orthanctoolsjsfront",
"version": "0.1.0",
"version": "0.6.2",
"proxy": "http://localhost:4000",
"private": true,
"dependencies": {
Expand Down
3 changes: 1 addition & 2 deletions FrontEnd/src/assets/styles/orthancToolsJs.css
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,5 @@ button > p {
}

.table-responsive {
overflow-x: visible;

overflow-x: auto;
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class EndpointsOptions extends Component{
render = () => {
return (
<div>
<h2>Endpoint Options</h2>
<h2>Export Transcoding </h2>
<div className='grid-form-group'>
<label htmlFor="export_transcoding">Transfer Syntax : </label>
<Select single options={TRANSCODING_OPTIONS} name='export_transcoding' value={this.getSelectedObject(TRANSCODING_OPTIONS, this.state.export_transcoding)} onChange={this.handleChangeSelect} />
Expand Down
3 changes: 2 additions & 1 deletion FrontEnd/src/components/Admin/Labels/LabelRootPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class LabelRootPanel extends Component {
state = {
userManagement: null,
labels: [],
search: ''
search: '',
createLabel:''
}

componentDidMount() {
Expand Down
20 changes: 11 additions & 9 deletions FrontEnd/src/components/Admin/Labels/UserManagementModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ export default class UserManagementModal
<Modal.Body>
<Table striped bordered hover>
<thead>
<th>Users</th>
<tr><th>Users</th></tr>
</thead>
{this.state.userlabels.map(userlabel => <tr
className={'d-flex justify-content-between align-content-center'}>
<p>{this.state.users.filter(user => user.id === userlabel.user_id)[0].username}</p>
<Button variant={"danger"}
onClick={() => apis.userlabel.deleteUserLabel(userlabel.user_id, this.props.label).then(() => this._refreshUserLabels())}>
{'X'}
</Button>
</tr>)}
<tbody>
{this.state.userlabels.map(userlabel => <tr key={userlabel.user_id}
className={'d-flex justify-content-between align-content-center'}>
<td>{this.state.users.filter(user => user.id === userlabel.user_id)[0].username}</td>
<td><Button variant={"danger"}
onClick={() => apis.userlabel.deleteUserLabel(userlabel.user_id, this.props.label).then(() => this._refreshUserLabels())}>
{'X'}
</Button></td>
</tr>)}
</tbody>
</Table>
<UserSelect
users={this.state.users.filter(user => !this.state.userlabels.map(ul => ul.user_id).includes(user.id))}
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/src/components/Admin/Labels/UserSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class UserSelect extends Component {
render() {
let elements = this.props.users
.filter(user => user.username.includes(this.state.value))
.map(user => <Dropdown.Item eventKey={user.username}>{user.username}</Dropdown.Item>)
.map(user => <Dropdown.Item key={user.username} eventKey={user.username}>{user.username}</Dropdown.Item>)

return (
<Dropdown onSelect={this.handleSelect} show={this.state.show}>
Expand Down
10 changes: 7 additions & 3 deletions FrontEnd/src/components/Admin/Robots/RobotStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ export default class RobotStatus extends Component {
dataField: 'queriesNb',
text: 'Number of Queries'
}, {
dataField: 'progress',
text: 'Progress'
dataField: 'validation',
text: 'Progress Validation'
}, {
dataField: 'retrieve',
text: 'Progress Retrieve'
}, {
dataField: 'state',
text: 'State'
Expand Down Expand Up @@ -107,7 +110,8 @@ export default class RobotStatus extends Component {
key: Math.random(),
name: robotJob.details.projectName,
username: robotJob.creator,
progress: (robotJob.progress.retrieve+robotJob.progress.validation)/2,
retrieve: robotJob.progress.retrieve + '%',
validation: robotJob.progress.validation + '%',
state: robotJob.state,
queriesNb: robotJob.details.items.length,
valid: robotJob.details.valid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class CreateMatch extends Component {
let roles = []
try {
let existingsRoles = await apis.role.getRoles()
existingsRoles.map( (role) => {
existingsRoles.forEach( (role) => {
roles.push({value : role.name, label : role.name})
})
} catch (error) {
Expand Down
Loading

0 comments on commit bc5f15b

Please sign in to comment.