Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d36e04ff
authored
Jun 08, 2016
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Comments added to database tables and appropriate REFERENCE statements in foreign key fields
parent
5f9e03f7
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
156 additions
and
77 deletions
sails/bootstrap.sh
sails/playbook.yml
sails/roles/database/files/init-ignoresymbolstix.sql
sails/roles/database/files/pictodb-schema.sql
sails/roles/database/files/triggers-enrolments-integrity-constraints.sql
sails/roles/database/files/triggers-sessions-integrity-constraints.sql
sails/src/test/api/stu-spec.js
sails/src/test/api/sup-spec.js
sails/bootstrap.sh
View file @
d36e04ff
...
...
@@ -2,11 +2,11 @@
echo
"-- Running pictogram server"
if
[
-e
"src/app.js"
]
;
then
cd
src
&&
npm start
cd
src
&&
forever start app.js
--debug
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
cd
/home/vagrant/sync/src
&&
npm start
cd
/home/vagrant/sync/src
&&
forever start app.js
--debug
else
echo
"-- app.js not found, cannot run pictogram server"
exit
...
...
sails/playbook.yml
View file @
d36e04ff
...
...
@@ -6,3 +6,4 @@
roles
:
-
webapp
-
server
sails/roles/database/files/init-ignoresymbolstix.sql
0 → 100644
View file @
d36e04ff
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
;
sails/roles/database/files/pictodb-schema.sql
View file @
d36e04ff
...
...
@@ -41,7 +41,8 @@ CREATE TABLE IF NOT EXISTS `action` (
KEY
`fk_sup_act`
(
`id_sup`
),
KEY
`fk_stu_act`
(
`id_stu`
),
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"
;
-- --------------------------------------------------------
...
...
sails/roles/database/files/triggers-enrolments-integrity-constraints.sql
View file @
d36e04ff
...
...
@@ -8,7 +8,14 @@ DELIMITER ;;
CREATE
TRIGGER
TRG_NEW_STUDENT_MAXENROLMENTS
BEFORE
INSERT
ON
student
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
;
IF
new
.
id_off
IS
NOT
NULL
THEN
SELECT
...
...
@@ -30,7 +37,13 @@ END;;
CREATE
TRIGGER
TRG_NEW_STUDENT_UPDATE_ENROLMENTS
AFTER
INSERT
ON
student
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
office
...
...
@@ -44,7 +57,14 @@ END;;
CREATE
TRIGGER
TRG_MODIFY_STUDENT_ENROLMENTS
AFTER
UPDATE
ON
student
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
(
old
.
id_off
IS
NOT
NULL
)
THEN
UPDATE
...
...
@@ -75,7 +95,14 @@ END;;
CREATE
TRIGGER
TRG_DELETE_STUDENT_ENROLMENTS
AFTER
DELETE
ON
student
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
UPDATE
office
...
...
sails/roles/database/files/triggers-sessions-integrity-constraints.sql
View file @
d36e04ff
...
...
@@ -11,20 +11,20 @@ CREATE FUNCTION getOpenTry(idstu INT)
RETURNS
INT
READS
SQL
DATA
BEGIN
DECLARE
id_opentry
INT
;
DECLARE
id_opentry
INT
;
SELECT
T
.
id
INTO
id_opentry
FROM
FROM
try
T
,
working_session
WS
,
instruction
I
,
method
M
WHERE
T
.
id_ws
=
WS
.
id
AND
WS
.
id_ins
=
I
.
id
AND
WHERE
T
.
id_ws
=
WS
.
id
AND
WS
.
id_ins
=
I
.
id
AND
I
.
id_met
=
M
.
id
AND
M
.
id_stu
=
idstu
AND
T
.
end
IS
NULL
;
return
id_opentry
;
return
id_opentry
;
END
;;
--
-- Memory table in order to recover data about current working sessions
...
...
@@ -55,8 +55,8 @@ CREATE PROCEDURE newTry(idstu INT, idsup INT, idws INT)
MODIFIES
SQL
DATA
BEGIN
DECLARE
idopentry
int
;
INSERT
INTO
try
(
`id_ws`
)
INSERT
INTO
try
(
`id_ws`
)
VALUES
(
idws
);
SET
idopentry
=
LAST_INSERT_ID
();
...
...
@@ -67,25 +67,25 @@ BEGIN
idws
,
idopentry
,
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
;;
--
-- It deletes current try for a given session
CREATE
PROCEDURE
deleteOpenTry
(
ws
INT
)
BEGIN
BEGIN
DECLARE
idopentry
INT
;
SELECT
id_opentry
INTO
idopentry
FROM
FROM
stu_opentry
WHERE
id_ws
=
ws
;
IF
(
idopentry
IS
NOT
NULL
)
THEN
DELETE
FROM
try
WHERE
id
=
idopentry
;
WHERE
id_ws
=
ws
;
IF
(
idopentry
IS
NOT
NULL
)
THEN
DELETE
FROM
try
WHERE
id
=
idopentry
;
END
IF
;
END
;;
...
...
@@ -95,17 +95,23 @@ END;;
CREATE
TRIGGER
TRG_SESSION_NEW
AFTER
INSERT
ON
working_session
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
;
SELECT
DISTINCT
M
.
id_stu
INTO
idstu
FROM
FROM
instruction
I
,
method
M
WHERE
I
.
id
=
new
.
id_ins
AND
WHERE
I
.
id
=
new
.
id_ins
AND
I
.
id_met
=
M
.
id
;
UPDATE
instruction
SET
status
=
'started'
WHERE
id
=
new
.
id_ins
;
...
...
@@ -113,7 +119,7 @@ BEGIN
CALL
newTry
(
idstu
,
new
.
id_sup
,
new
.
id
);
END
;;
-- Integrity rule 2: when a session is closed, last try must be discharged
-- when: state COM, event a4
-- current is to NULL (integrity rule 6)
...
...
@@ -121,7 +127,14 @@ END;;
CREATE
TRIGGER
TRG_SESSION_CLOSED
AFTER
UPDATE
ON
working_session
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
CALL
deleteOpenTry
(
new
.
id
);
END
IF
;
...
...
@@ -134,61 +147,74 @@ END;;
CREATE
TRIGGER
TRG_NEW_EVENT_ONSESSION
BEFORE
INSERT
ON
action
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
idtry
INT
;
SET
idstu
=
NEW
.
id_stu
;
SELECT
id_opentry
INTO
idtry
FROM
FROM
stu_opentry
WHERE
id_stu
=
idstu
;
WHERE
id_stu
=
idstu
;
IF
(
idtry
IS
NOT
NULL
)
THEN
SET
NEW
.
id_try
=
idtry
;
END
IF
;
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
-- when: state COM, event a4
-- Integrity rule 5: when a session is continued after a pause and new try is created
-- when: state PAU, event a3
-- when: state COM, event a4
-- Integrity rule 5: when a session is continued after a pause and new try is created
-- when: state PAU, event a3
-- 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
AFTER
INSERT
ON
action
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
idsup_ws
INT
;
DECLARE
idws
INT
;
DECLARE
idsup_ws
INT
;
DECLARE
idws
INT
;
CASE
NEW
.
type
WHEN
'Show'
THEN
WHEN
'Show'
THEN
SELECT
id_ws
,
id_sup
,
id_opentry
INTO
idws
,
idsup_ws
,
idopentry
FROM
FROM
stu_opentry
WHERE
id_stu
=
NEW
.
id_stu
;
IF
(
idopentry
IS
NOT
NULL
and
NEW
.
id_sup
IS
NULL
)
THEN
WHERE
id_stu
=
NEW
.
id_stu
;
IF
(
idopentry
IS
NOT
NULL
and
NEW
.
id_sup
IS
NULL
)
THEN
UPDATE
`try`
SET
end
=
NOW
()
WHERE
id
=
idopentry
;
SET
end
=
NOW
()
WHERE
id
=
idopentry
;
call
newTry
(
new
.
id_stu
,
idsup_ws
,
idws
);
END
IF
;
WHEN
'Pause'
THEN
END
IF
;
WHEN
'Pause'
THEN
SELECT
id_ws
,
id_opentry
INTO
idws
,
idopentry
FROM
stu_opentry
WHERE
id_stu
=
NEW
.
id_stu
;
IF
(
idopentry
IS
NULL
)
THEN
id_stu
=
NEW
.
id_stu
;
IF
(
idopentry
IS
NULL
)
THEN
call
newTry
(
new
.
id_stu
,
new
.
id_sup
,
idws
);
ELSE
call
deleteOpenTry
(
idws
);
END
IF
;
ELSE
BEGIN
END
;
END
CASE
;
ELSE
call
deleteOpenTry
(
idws
);
END
IF
;
ELSE
BEGIN
END
;
END
CASE
;
END
;;
...
...
@@ -207,16 +233,23 @@ ALTER TABLE `working_session`
CREATE
TRIGGER
TRG_SESSION_CLOSING
BEFORE
UPDATE
ON
working_session
FOR
EACH
ROW
BEGIN
IF
((
new
.
end
IS
NOT
NULL
)
AND
(
new
.
current
IS
NOT
NULL
))
THEN
thisTrigger
:
BEGIN
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
;
END
IF
;
END
IF
;
END
;;
-- Integrity rule 8: Every action requires a valid try or null
-- 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
;;
--
...
...
@@ -225,7 +258,13 @@ ALTER TABLE `action`
CREATE
TRIGGER
TRG_TRY_EVALUATED
AFTER
UPDATE
ON
try
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
idws
INT
;
DECLARE
ws_end
DATE
;
...
...
@@ -233,16 +272,13 @@ BEGIN
FROM
stu_opentry
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
UPDATE
stu_opentry
SET
end
=
new
.
end
,
total_tries
=
total_tries
+
1
WHERE
id_ws
=
idws
;
END
IF
;
END
IF
;
END
;;
DELIMITER
;
sails/src/test/api/stu-spec.js
View file @
d36e04ff
...
...
@@ -9,13 +9,17 @@ describe('Student API', function () {
delete
studentAgentData
.
password
;
studentAgentData
.
current_method
=
'Test Method'
;
studentAgentData
.
current_instruction
=
'Test Instruction'
;
supervisorAgent
.
get
(
'/stu/'
+
studentAgent
.
data
.
id
)
.
send
()
.
expect
(
200
)
.
expect
(
studentAgentData
)
.
end
(
done
);
.
end
((
error
)
=>
{
if
(
error
)
{
throw
error
;
};
done
();
});
});
it
(
'GET /stu/:id_stu/supervisors'
,
function
(
done
)
{
supervisorAgent
...
...
sails/src/test/api/sup-spec.js
View file @
d36e04ff
...
...
@@ -66,11 +66,12 @@ describe('Supervisor API', function () {
})
.
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
()
.
expect
(
200
)
.
expect
(
function
(
response
)
{
assert
.
isArray
(
response
.
body
);
assert
.
isAtLeast
(
response
.
body
.
length
,
1
,
'category 41 is empty'
);
response
.
body
.
forEach
(
function
(
picto
)
{
assert
.
isObject
(
picto
);
assert
.
isNumber
(
picto
.
source
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment