Comments added to database tables and appropriate REFERENCE statements in foreign key fields

parent 5f9e03f7
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
echo "-- Running pictogram server" echo "-- Running pictogram server"
if [ -e "src/app.js" ]; then if [ -e "src/app.js" ]; then
cd src && npm start cd src && forever start app.js --debug
elif [ -e "/vagrant/src/app.js" ]; then elif [ -e "/vagrant/src/app.js" ]; then
cd /vagrant/src && npm start cd /vagrant/src && forever start app.js --debug
elif [ -e "/home/vagrant/sync/src/app.js" ]; then elif [ -e "/home/vagrant/sync/src/app.js" ]; then
cd /home/vagrant/sync/src && npm start cd /home/vagrant/sync/src && forever start app.js --debug
else else
echo "-- app.js not found, cannot run pictogram server" echo "-- app.js not found, cannot run pictogram server"
exit exit
......
...@@ -6,3 +6,4 @@ ...@@ -6,3 +6,4 @@
roles: roles:
- webapp - webapp
- server - server
SET foreign_key_checks=0;
GRANT USAGE ON *.* TO 'pictodbuser'@'localhost';
DROP USER 'pictodbuser'@'localhost';
CREATE USER 'pictodbuser'@'localhost' identified by 'p1KT015';
DROP DATABASE IF EXISTS pictodb;
CREATE DATABASE pictodb;
SET foreign_key_checks=1;
grant all privileges on pictodb.* to pictodbuser;
flush privileges;
...@@ -41,7 +41,8 @@ CREATE TABLE IF NOT EXISTS `action` ( ...@@ -41,7 +41,8 @@ CREATE TABLE IF NOT EXISTS `action` (
KEY `fk_sup_act` (`id_sup`), KEY `fk_sup_act` (`id_sup`),
KEY `fk_stu_act` (`id_stu`), KEY `fk_stu_act` (`id_stu`),
KEY `id_try` (`id_try`) KEY `id_try` (`id_try`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1
COMMENT="This table registers and action performed by a user at a given time, all information of the action is in JSON format in the 'description' column and the operation performed is one of the possible for the 'type' column";
-- -------------------------------------------------------- -- --------------------------------------------------------
......
...@@ -8,7 +8,14 @@ DELIMITER ;; ...@@ -8,7 +8,14 @@ DELIMITER ;;
CREATE TRIGGER TRG_NEW_STUDENT_MAXENROLMENTS CREATE TRIGGER TRG_NEW_STUDENT_MAXENROLMENTS
BEFORE INSERT ON student BEFORE INSERT ON student
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_BEFORE_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
DECLARE max_enr,curr_enr INT; DECLARE max_enr,curr_enr INT;
IF new.id_off IS NOT NULL THEN IF new.id_off IS NOT NULL THEN
SELECT SELECT
...@@ -30,7 +37,13 @@ END;; ...@@ -30,7 +37,13 @@ END;;
CREATE TRIGGER TRG_NEW_STUDENT_UPDATE_ENROLMENTS CREATE TRIGGER TRG_NEW_STUDENT_UPDATE_ENROLMENTS
AFTER INSERT ON student AFTER INSERT ON student
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
UPDATE UPDATE
office office
...@@ -44,7 +57,14 @@ END;; ...@@ -44,7 +57,14 @@ END;;
CREATE TRIGGER TRG_MODIFY_STUDENT_ENROLMENTS CREATE TRIGGER TRG_MODIFY_STUDENT_ENROLMENTS
AFTER UPDATE ON student AFTER UPDATE ON student
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_UPDATE_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
IF NOT (old.id_off<=>new.id_off) THEN IF NOT (old.id_off<=>new.id_off) THEN
IF (old.id_off IS NOT NULL) THEN IF (old.id_off IS NOT NULL) THEN
UPDATE UPDATE
...@@ -75,7 +95,14 @@ END;; ...@@ -75,7 +95,14 @@ END;;
CREATE TRIGGER TRG_DELETE_STUDENT_ENROLMENTS CREATE TRIGGER TRG_DELETE_STUDENT_ENROLMENTS
AFTER DELETE ON student AFTER DELETE ON student
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_DELETE_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
IF old.id_off IS NULL THEN IF old.id_off IS NULL THEN
UPDATE UPDATE
office office
......
...@@ -11,20 +11,20 @@ CREATE FUNCTION getOpenTry(idstu INT) ...@@ -11,20 +11,20 @@ CREATE FUNCTION getOpenTry(idstu INT)
RETURNS INT RETURNS INT
READS SQL DATA READS SQL DATA
BEGIN BEGIN
DECLARE id_opentry INT; DECLARE id_opentry INT;
SELECT T.id INTO id_opentry SELECT T.id INTO id_opentry
FROM FROM
try T, try T,
working_session WS, working_session WS,
instruction I, instruction I,
method M method M
WHERE WHERE
T.id_ws=WS.id AND T.id_ws=WS.id AND
WS.id_ins=I.id AND WS.id_ins=I.id AND
I.id_met=M.id AND I.id_met=M.id AND
M.id_stu=idstu AND T.end IS NULL; M.id_stu=idstu AND T.end IS NULL;
return id_opentry; return id_opentry;
END;; END;;
-- --
-- Memory table in order to recover data about current working sessions -- Memory table in order to recover data about current working sessions
...@@ -55,8 +55,8 @@ CREATE PROCEDURE newTry(idstu INT, idsup INT, idws INT) ...@@ -55,8 +55,8 @@ CREATE PROCEDURE newTry(idstu INT, idsup INT, idws INT)
MODIFIES SQL DATA MODIFIES SQL DATA
BEGIN BEGIN
DECLARE idopentry int; DECLARE idopentry int;
INSERT INTO try(`id_ws`) INSERT INTO try(`id_ws`)
VALUES (idws); VALUES (idws);
SET idopentry=LAST_INSERT_ID(); SET idopentry=LAST_INSERT_ID();
...@@ -67,25 +67,25 @@ BEGIN ...@@ -67,25 +67,25 @@ BEGIN
idws, idws,
idopentry, idopentry,
0, 0,
NOW() NOW()
) )
ON DUPLICATE KEY UPDATE id_stu=idstu, id_sup=idsup, id_ws=idws, id_opentry=idopentry; ON DUPLICATE KEY UPDATE id_stu=idstu, id_sup=idsup, id_ws=idws, id_opentry=idopentry;
END;; END;;
-- --
-- It deletes current try for a given session -- It deletes current try for a given session
CREATE PROCEDURE deleteOpenTry(ws INT) CREATE PROCEDURE deleteOpenTry(ws INT)
BEGIN BEGIN
DECLARE idopentry INT; DECLARE idopentry INT;
SELECT id_opentry INTO idopentry SELECT id_opentry INTO idopentry
FROM FROM
stu_opentry stu_opentry
WHERE WHERE
id_ws = ws; id_ws = ws;
IF (idopentry IS NOT NULL) THEN IF (idopentry IS NOT NULL) THEN
DELETE FROM try DELETE FROM try
WHERE id = idopentry; WHERE id = idopentry;
END IF; END IF;
END;; END;;
...@@ -95,17 +95,23 @@ END;; ...@@ -95,17 +95,23 @@ END;;
CREATE TRIGGER TRG_SESSION_NEW CREATE TRIGGER TRG_SESSION_NEW
AFTER INSERT ON working_session AFTER INSERT ON working_session
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
DECLARE idstu INT; DECLARE idstu INT;
SELECT DISTINCT M.id_stu INTO idstu SELECT DISTINCT M.id_stu INTO idstu
FROM FROM
instruction I, instruction I,
method M method M
WHERE WHERE
I.id=new.id_ins AND I.id=new.id_ins AND
I.id_met=M.id; I.id_met=M.id;
UPDATE instruction UPDATE instruction
SET status='started' SET status='started'
WHERE id=new.id_ins; WHERE id=new.id_ins;
...@@ -113,7 +119,7 @@ BEGIN ...@@ -113,7 +119,7 @@ BEGIN
CALL newTry(idstu, new.id_sup, new.id); CALL newTry(idstu, new.id_sup, new.id);
END;; END;;
-- Integrity rule 2: when a session is closed, last try must be discharged -- Integrity rule 2: when a session is closed, last try must be discharged
-- when: state COM, event a4 -- when: state COM, event a4
-- current is to NULL (integrity rule 6) -- current is to NULL (integrity rule 6)
...@@ -121,7 +127,14 @@ END;; ...@@ -121,7 +127,14 @@ END;;
CREATE TRIGGER TRG_SESSION_CLOSED CREATE TRIGGER TRG_SESSION_CLOSED
AFTER UPDATE ON working_session AFTER UPDATE ON working_session
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_UPDATE_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
IF ((old.end IS NULL) and (new.end IS NOT NULL)) THEN IF ((old.end IS NULL) and (new.end IS NOT NULL)) THEN
CALL deleteOpenTry(new.id); CALL deleteOpenTry(new.id);
END IF; END IF;
...@@ -134,61 +147,74 @@ END;; ...@@ -134,61 +147,74 @@ END;;
CREATE TRIGGER TRG_NEW_EVENT_ONSESSION CREATE TRIGGER TRG_NEW_EVENT_ONSESSION
BEFORE INSERT ON action BEFORE INSERT ON action
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_BEFORE_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
DECLARE idstu INT; DECLARE idstu INT;
DECLARE idtry INT; DECLARE idtry INT;
SET idstu=NEW.id_stu; SET idstu=NEW.id_stu;
SELECT id_opentry INTO idtry SELECT id_opentry INTO idtry
FROM FROM
stu_opentry stu_opentry
WHERE WHERE
id_stu = idstu; id_stu = idstu;
IF (idtry IS NOT NULL) THEN IF (idtry IS NOT NULL) THEN
SET NEW.id_try=idtry; SET NEW.id_try=idtry;
END IF; END IF;
END;; END;;
-- Integrity rule 7: when a sentence is finished, previous try is closed -- Integrity rule 7: when a sentence is finished, previous try is closed
-- and new try is created in case of working session happening -- and new try is created in case of working session happening
-- when: state COM, event a4 -- when: state COM, event a4
-- Integrity rule 5: when a session is continued after a pause and new try is created -- Integrity rule 5: when a session is continued after a pause and new try is created
-- when: state PAU, event a3 -- when: state PAU, event a3
-- Integrity rule 4: when a session is paused, last try must be discharged -- Integrity rule 4: when a session is paused, last try must be discharged
-- when: state SES, event a3 -- when: state SES, event a3
CREATE TRIGGER TRG_NEW_EVENT CREATE TRIGGER TRG_NEW_EVENT
AFTER INSERT ON action AFTER INSERT ON action
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_INSERT_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
DECLARE idopentry INT; DECLARE idopentry INT;
DECLARE idsup_ws INT; DECLARE idsup_ws INT;
DECLARE idws INT; DECLARE idws INT;
CASE NEW.type CASE NEW.type
WHEN 'Show' THEN WHEN 'Show' THEN
SELECT id_ws, id_sup, id_opentry INTO idws, idsup_ws, idopentry SELECT id_ws, id_sup, id_opentry INTO idws, idsup_ws, idopentry
FROM FROM
stu_opentry stu_opentry
WHERE WHERE
id_stu = NEW.id_stu; id_stu = NEW.id_stu;
IF (idopentry IS NOT NULL and NEW.id_sup IS NULL) THEN IF (idopentry IS NOT NULL and NEW.id_sup IS NULL) THEN
UPDATE `try` UPDATE `try`
SET end=NOW() SET end=NOW()
WHERE id=idopentry; WHERE id=idopentry;
call newTry(new.id_stu, idsup_ws, idws); call newTry(new.id_stu, idsup_ws, idws);
END IF; END IF;
WHEN 'Pause' THEN WHEN 'Pause' THEN
SELECT id_ws, id_opentry INTO idws, idopentry SELECT id_ws, id_opentry INTO idws, idopentry
FROM FROM
stu_opentry stu_opentry
WHERE WHERE
id_stu = NEW.id_stu; id_stu = NEW.id_stu;
IF (idopentry IS NULL) THEN IF (idopentry IS NULL) THEN
call newTry(new.id_stu, new.id_sup,idws); call newTry(new.id_stu, new.id_sup,idws);
ELSE ELSE
call deleteOpenTry(idws); call deleteOpenTry(idws);
END IF; END IF;
ELSE BEGIN END; ELSE BEGIN END;
END CASE; END CASE;
END;; END;;
...@@ -207,16 +233,23 @@ ALTER TABLE `working_session` ...@@ -207,16 +233,23 @@ ALTER TABLE `working_session`
CREATE TRIGGER TRG_SESSION_CLOSING CREATE TRIGGER TRG_SESSION_CLOSING
BEFORE UPDATE ON working_session BEFORE UPDATE ON working_session
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((new.end IS NOT NULL) AND (new.current IS NOT NULL)) THEN IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_BEFORE_UPDATE_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
IF ((new.end IS NOT NULL) AND (new.current IS NOT NULL)) THEN
SET new.current=NULL; SET new.current=NULL;
END IF; END IF;
END;; END;;
-- Integrity rule 8: Every action requires a valid try or null -- Integrity rule 8: Every action requires a valid try or null
-- when: state SES, event a3 and a5 -- when: state SES, event a3 and a5
-- --
ALTER TABLE `action` ALTER TABLE `action`
ADD CONSTRAINT `fk_try_act` FOREIGN KEY (`id_try`) REFERENCES `try` (`id`) ON DELETE SET NULL;; ADD CONSTRAINT `fk_try_act` FOREIGN KEY (`id_try`) REFERENCES `try` (`id`) ON DELETE SET NULL;;
-- --
...@@ -225,7 +258,13 @@ ALTER TABLE `action` ...@@ -225,7 +258,13 @@ ALTER TABLE `action`
CREATE TRIGGER TRG_TRY_EVALUATED CREATE TRIGGER TRG_TRY_EVALUATED
AFTER UPDATE ON try AFTER UPDATE ON try
FOR EACH ROW FOR EACH ROW
BEGIN thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE)
OR (@TRIGGER_AFTER_UPDATE_CHECKS = FALSE))
AND (USER() = 'root@localhost')
THEN
LEAVE thisTrigger;
END IF;
DECLARE idopentry INT; DECLARE idopentry INT;
DECLARE idws INT; DECLARE idws INT;
DECLARE ws_end DATE; DECLARE ws_end DATE;
...@@ -233,16 +272,13 @@ BEGIN ...@@ -233,16 +272,13 @@ BEGIN
FROM FROM
stu_opentry stu_opentry
WHERE WHERE
id_ws = NEW.id_ws; id_ws = NEW.id_ws;
IF ( (old.result IS NULL) and (new.result IS NOT NULL) and (new.end>ws_end)) THEN IF ( (old.result IS NULL) and (new.result IS NOT NULL) and (new.end>ws_end)) THEN
UPDATE stu_opentry UPDATE stu_opentry
SET end=new.end, total_tries=total_tries+1 SET end=new.end, total_tries=total_tries+1
WHERE id_ws=idws; WHERE id_ws=idws;
END IF; END IF;
END;; END;;
DELIMITER ; DELIMITER ;
...@@ -9,13 +9,17 @@ describe('Student API', function () { ...@@ -9,13 +9,17 @@ describe('Student API', function () {
delete studentAgentData.password; delete studentAgentData.password;
studentAgentData.current_method = 'Test Method'; studentAgentData.current_method = 'Test Method';
studentAgentData.current_instruction = 'Test Instruction'; studentAgentData.current_instruction = 'Test Instruction';
supervisorAgent supervisorAgent
.get('/stu/' + studentAgent.data.id) .get('/stu/' + studentAgent.data.id)
.send() .send()
.expect(200) .expect(200)
.expect(studentAgentData) .expect(studentAgentData)
.end(done); .end((error) => {
if (error) {
throw error;
};
done();
});
}); });
it('GET /stu/:id_stu/supervisors', function (done) { it('GET /stu/:id_stu/supervisors', function (done) {
supervisorAgent supervisorAgent
......
...@@ -66,11 +66,12 @@ describe('Supervisor API', function () { ...@@ -66,11 +66,12 @@ describe('Supervisor API', function () {
}) })
.end(done); .end(done);
}); });
it('GET /sup/:id/pic_fromcategory/:id_cat', function (done) { it.only('GET /sup/:id/pic_fromcategory/:id_cat', function (done) {
supervisorAgent.get('/sup/' + supervisorAgent.data.id + '/pic_fromcategory/41').send() supervisorAgent.get('/sup/' + supervisorAgent.data.id + '/pic_fromcategory/41').send()
.expect(200) .expect(200)
.expect(function (response) { .expect(function (response) {
assert.isArray(response.body); assert.isArray(response.body);
assert.isAtLeast(response.body.length, 1, 'category 41 is empty');
response.body.forEach(function (picto) { response.body.forEach(function (picto) {
assert.isObject(picto); assert.isObject(picto);
assert.isNumber(picto.source); assert.isNumber(picto.source);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment