Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 1 | # |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 2 | # CLDS stored procedures |
| 3 | # |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 4 | |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 5 | USE cldsdb4; |
| 6 | |
| 7 | DROP PROCEDURE IF EXISTS upd_event; |
| 8 | DROP PROCEDURE IF EXISTS ins_event; |
| 9 | DROP PROCEDURE IF EXISTS del_all_model_instances; |
| 10 | DROP PROCEDURE IF EXISTS del_model_instance; |
| 11 | DROP PROCEDURE IF EXISTS ins_model_instance; |
| 12 | DROP PROCEDURE IF EXISTS set_model; |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 13 | DROP PROCEDURE IF EXISTS get_model; |
| 14 | DROP PROCEDURE IF EXISTS get_model_template; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 15 | DROP PROCEDURE IF EXISTS set_template; |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 16 | DROP PROCEDURE IF EXISTS get_template; |
Determe, Sebastien (sd378r) | 7a58af8 | 2018-06-06 13:47:21 +0200 | [diff] [blame] | 17 | DROP PROCEDURE IF EXISTS del_model; |
sebdet | 6651e17 | 2018-09-03 14:39:21 +0200 | [diff] [blame] | 18 | DROP PROCEDURE IF EXISTS set_new_tosca_model_version; |
| 19 | DROP PROCEDURE IF EXISTS set_tosca_model; |
| 20 | DROP PROCEDURE IF EXISTS set_dictionary; |
| 21 | DROP PROCEDURE IF EXISTS set_dictionary_elements; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 22 | DELIMITER // |
| 23 | CREATE PROCEDURE get_template |
| 24 | (IN v_template_name VARCHAR(80), |
| 25 | OUT v_template_id VARCHAR(36), |
| 26 | OUT v_template_bpmn_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 27 | OUT v_template_bpmn_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 28 | OUT v_template_bpmn_text MEDIUMTEXT, |
| 29 | OUT v_template_image_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 30 | OUT v_template_image_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 31 | OUT v_template_image_text MEDIUMTEXT, |
| 32 | OUT v_template_doc_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 33 | OUT v_template_doc_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 34 | OUT v_template_doc_text MEDIUMTEXT) |
| 35 | BEGIN |
| 36 | SELECT t.template_id, |
| 37 | tb.template_bpmn_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 38 | tb.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 39 | tb.template_bpmn_text, |
| 40 | ti.template_image_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 41 | ti.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 42 | ti.template_image_text, |
| 43 | td.template_doc_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 44 | td.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 45 | td.template_doc_text |
| 46 | INTO v_template_id, |
| 47 | v_template_bpmn_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 48 | v_template_bpmn_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 49 | v_template_bpmn_text, |
| 50 | v_template_image_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 51 | v_template_image_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 52 | v_template_image_text, |
| 53 | v_template_doc_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 54 | v_template_doc_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 55 | v_template_doc_text |
| 56 | FROM template t, |
| 57 | template_bpmn tb, |
| 58 | template_image ti, |
| 59 | template_doc td |
| 60 | WHERE t.template_bpmn_id = tb.template_bpmn_id |
| 61 | AND t.template_image_id = ti.template_image_id |
| 62 | AND t.template_doc_id = td.template_doc_id |
| 63 | AND t.template_name = v_template_name; |
| 64 | END; |
| 65 | CREATE PROCEDURE set_template |
| 66 | (IN v_template_name VARCHAR(80), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 67 | IN v_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 68 | IN v_template_bpmn_text MEDIUMTEXT, |
| 69 | IN v_template_image_text MEDIUMTEXT, |
| 70 | IN v_template_doc_text MEDIUMTEXT, |
| 71 | OUT v_template_id VARCHAR(36), |
| 72 | OUT v_template_bpmn_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 73 | OUT v_template_bpmn_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 74 | OUT v_template_image_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 75 | OUT v_template_image_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 76 | OUT v_template_doc_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 77 | OUT v_template_doc_user_id VARCHAR(80)) |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 78 | BEGIN |
| 79 | DECLARE v_old_template_bpmn_text MEDIUMTEXT; |
| 80 | DECLARE v_old_template_image_text MEDIUMTEXT; |
| 81 | DECLARE v_old_template_doc_text MEDIUMTEXT; |
| 82 | SET v_template_id = NULL; |
| 83 | CALL get_template( |
| 84 | v_template_name, |
| 85 | v_template_id, |
| 86 | v_template_bpmn_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 87 | v_template_bpmn_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 88 | v_old_template_bpmn_text, |
| 89 | v_template_image_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 90 | v_template_image_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 91 | v_old_template_image_text, |
| 92 | v_template_doc_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 93 | v_template_doc_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 94 | v_old_template_doc_text); |
| 95 | IF v_template_id IS NULL THEN |
| 96 | BEGIN |
| 97 | SET v_template_id = UUID(); |
| 98 | INSERT INTO template |
| 99 | (template_id, template_name) |
| 100 | VALUES (v_template_id, v_template_name); |
| 101 | END; |
| 102 | END IF; |
| 103 | IF v_template_bpmn_id IS NULL OR v_template_bpmn_text <> v_old_template_bpmn_text THEN |
| 104 | SET v_template_bpmn_id = UUID(); |
| 105 | INSERT INTO template_bpmn |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 106 | (template_bpmn_id, template_id, template_bpmn_text, user_id) |
| 107 | VALUES (v_template_bpmn_id, v_template_id, v_template_bpmn_text, v_user_id); |
| 108 | SET v_template_bpmn_user_id = v_user_id; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 109 | END IF; |
| 110 | IF v_template_image_id IS NULL OR v_template_image_text <> v_old_template_image_text THEN |
| 111 | SET v_template_image_id = UUID(); |
| 112 | INSERT INTO template_image |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 113 | (template_image_id, template_id, template_image_text, user_id) |
| 114 | VALUES (v_template_image_id, v_template_id, v_template_image_text, v_user_id); |
| 115 | SET v_template_image_user_id = v_user_id; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 116 | END IF; |
| 117 | IF v_template_doc_id IS NULL OR v_template_doc_text <> v_old_template_doc_text THEN |
| 118 | SET v_template_doc_id = UUID(); |
| 119 | INSERT INTO template_doc |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 120 | (template_doc_id, template_id, template_doc_text, user_id) |
| 121 | VALUES (v_template_doc_id, v_template_id, v_template_doc_text, v_user_id); |
| 122 | SET v_template_doc_user_id = v_user_id; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 123 | END IF; |
| 124 | UPDATE template |
| 125 | SET template_bpmn_id = v_template_bpmn_id, |
| 126 | template_image_id = v_template_image_id, |
| 127 | template_doc_id = v_template_doc_id |
| 128 | WHERE template_id = v_template_id; |
| 129 | END; |
| 130 | CREATE PROCEDURE get_model |
| 131 | (IN v_model_name VARCHAR(80), |
| 132 | OUT v_control_name_prefix VARCHAR(80), |
| 133 | INOUT v_control_name_uuid VARCHAR(36), |
| 134 | OUT v_model_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 135 | OUT v_service_type_id VARCHAR(80), |
| 136 | OUT v_deployment_id VARCHAR(80), |
sebdet | 2579386 | 2018-11-08 17:11:10 +0100 | [diff] [blame] | 137 | OUT v_deployment_status_url VARCHAR(300), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 138 | OUT v_template_name VARCHAR(80), |
| 139 | OUT v_template_id VARCHAR(36), |
| 140 | OUT v_model_prop_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 141 | OUT v_model_prop_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 142 | OUT v_model_prop_text MEDIUMTEXT, |
| 143 | OUT v_model_blueprint_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 144 | OUT v_model_blueprint_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 145 | OUT v_model_blueprint_text MEDIUMTEXT, |
| 146 | OUT v_event_id VARCHAR(36), |
| 147 | OUT v_action_cd VARCHAR(80), |
| 148 | OUT v_action_state_cd VARCHAR(80), |
| 149 | OUT v_event_process_instance_id VARCHAR(80), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 150 | OUT v_event_user_id VARCHAR(80)) |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 151 | BEGIN |
| 152 | SELECT m.control_name_prefix, |
| 153 | m.control_name_uuid, |
| 154 | m.model_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 155 | m.service_type_id, |
| 156 | m.deployment_id, |
sebdet | 2579386 | 2018-11-08 17:11:10 +0100 | [diff] [blame] | 157 | m.deployment_status_url, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 158 | t.template_name, |
| 159 | m.template_id, |
| 160 | mp.model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 161 | mp.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 162 | mp.model_prop_text, |
| 163 | mb.model_blueprint_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 164 | mb.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 165 | mb.model_blueprint_text, |
| 166 | e.event_id, |
| 167 | e.action_cd, |
| 168 | e.action_state_cd, |
| 169 | e.process_instance_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 170 | e.user_id |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 171 | INTO v_control_name_prefix, |
| 172 | v_control_name_uuid, |
| 173 | v_model_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 174 | v_service_type_id, |
| 175 | v_deployment_id, |
sebdet | 2579386 | 2018-11-08 17:11:10 +0100 | [diff] [blame] | 176 | v_deployment_status_url, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 177 | v_template_name, |
| 178 | v_template_id, |
| 179 | v_model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 180 | v_model_prop_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 181 | v_model_prop_text, |
| 182 | v_model_blueprint_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 183 | v_model_blueprint_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 184 | v_model_blueprint_text, |
| 185 | v_event_id, |
| 186 | v_action_cd, |
| 187 | v_action_state_cd, |
| 188 | v_event_process_instance_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 189 | v_event_user_id |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 190 | FROM model m, |
| 191 | template t, |
| 192 | model_properties mp, |
| 193 | model_blueprint mb, |
| 194 | event e |
| 195 | WHERE m.template_id = t.template_id |
| 196 | AND m.model_prop_id = mp.model_prop_id |
| 197 | AND m.model_blueprint_id = mb.model_blueprint_id |
| 198 | AND m.event_id = e.event_id |
| 199 | AND (m.model_name = v_model_name |
| 200 | OR m.control_name_uuid = v_control_name_uuid); |
| 201 | SELECT model_instance_id, |
| 202 | vm_name, |
| 203 | location, |
| 204 | timestamp |
| 205 | FROM model_instance |
| 206 | WHERE model_id = v_model_id |
| 207 | ORDER BY 2; |
| 208 | END; |
| 209 | CREATE PROCEDURE get_model_template |
| 210 | (IN v_model_name VARCHAR(80), |
| 211 | OUT v_control_name_prefix VARCHAR(80), |
| 212 | INOUT v_control_name_uuid VARCHAR(36), |
| 213 | OUT v_model_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 214 | OUT v_service_type_id VARCHAR(80), |
| 215 | OUT v_deployment_id VARCHAR(80), |
sebdet | 2579386 | 2018-11-08 17:11:10 +0100 | [diff] [blame] | 216 | OUT v_deployment_status_url VARCHAR(300), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 217 | OUT v_template_name VARCHAR(80), |
| 218 | OUT v_template_id VARCHAR(36), |
| 219 | OUT v_model_prop_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 220 | OUT v_model_prop_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 221 | OUT v_model_prop_text MEDIUMTEXT, |
| 222 | OUT v_model_blueprint_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 223 | OUT v_model_blueprint_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 224 | OUT v_model_blueprint_text MEDIUMTEXT, |
| 225 | OUT v_template_bpmn_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 226 | OUT v_template_bpmn_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 227 | OUT v_template_bpmn_text MEDIUMTEXT, |
| 228 | OUT v_template_image_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 229 | OUT v_template_image_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 230 | OUT v_template_image_text MEDIUMTEXT, |
| 231 | OUT v_template_doc_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 232 | OUT v_template_doc_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 233 | OUT v_template_doc_text MEDIUMTEXT, |
| 234 | OUT v_event_id VARCHAR(36), |
| 235 | OUT v_action_cd VARCHAR(80), |
| 236 | OUT v_action_state_cd VARCHAR(80), |
| 237 | OUT v_event_process_instance_id VARCHAR(80), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 238 | OUT v_event_user_id VARCHAR(80)) |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 239 | BEGIN |
| 240 | CALL get_model( |
| 241 | v_model_name, |
| 242 | v_control_name_prefix, |
| 243 | v_control_name_uuid, |
| 244 | v_model_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 245 | v_service_type_id, |
| 246 | v_deployment_id, |
sebdet | 2579386 | 2018-11-08 17:11:10 +0100 | [diff] [blame] | 247 | v_deployment_status_url, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 248 | v_template_name, |
| 249 | v_template_id, |
| 250 | v_model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 251 | v_model_prop_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 252 | v_model_prop_text, |
| 253 | v_model_blueprint_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 254 | v_model_blueprint_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 255 | v_model_blueprint_text, |
| 256 | v_event_id, |
| 257 | v_action_cd, |
| 258 | v_action_state_cd, |
| 259 | v_event_process_instance_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 260 | v_event_user_id); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 261 | CALL get_template( |
| 262 | v_template_name, |
| 263 | v_template_id, |
| 264 | v_template_bpmn_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 265 | v_template_bpmn_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 266 | v_template_bpmn_text, |
| 267 | v_template_image_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 268 | v_template_image_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 269 | v_template_image_text, |
| 270 | v_template_doc_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 271 | v_template_doc_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 272 | v_template_doc_text); |
| 273 | END; |
| 274 | CREATE PROCEDURE set_model |
| 275 | (IN v_model_name VARCHAR(80), |
| 276 | IN v_template_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 277 | IN v_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 278 | IN v_model_prop_text MEDIUMTEXT, |
| 279 | IN v_model_blueprint_text MEDIUMTEXT, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 280 | IN v_service_type_id VARCHAR(80), |
| 281 | IN v_deployment_id VARCHAR(80), |
sebdet | 2579386 | 2018-11-08 17:11:10 +0100 | [diff] [blame] | 282 | IN v_deployment_status_url VARCHAR(300), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 283 | INOUT v_control_name_prefix VARCHAR(80), |
| 284 | INOUT v_control_name_uuid VARCHAR(36), |
| 285 | OUT v_model_id VARCHAR(36), |
| 286 | OUT v_model_prop_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 287 | OUT v_model_prop_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 288 | OUT v_model_blueprint_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 289 | OUT v_model_blueprint_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 290 | OUT v_event_id VARCHAR(36), |
| 291 | OUT v_action_cd VARCHAR(80), |
| 292 | OUT v_action_state_cd VARCHAR(80), |
| 293 | OUT v_event_process_instance_id VARCHAR(80), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 294 | OUT v_event_user_id VARCHAR(80)) |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 295 | BEGIN |
| 296 | DECLARE v_old_template_name VARCHAR(80); |
| 297 | DECLARE v_old_template_id VARCHAR(36); |
| 298 | DECLARE v_old_control_name_prefix VARCHAR(80); |
| 299 | DECLARE v_old_control_name_uuid VARCHAR(36); |
| 300 | DECLARE v_old_model_prop_text MEDIUMTEXT; |
| 301 | DECLARE v_old_model_blueprint_text MEDIUMTEXT; |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 302 | DECLARE v_old_service_type_id VARCHAR(80); |
| 303 | DECLARE v_old_deployment_id VARCHAR(80); |
sebdet | 2579386 | 2018-11-08 17:11:10 +0100 | [diff] [blame] | 304 | DECLARE v_old_deployment_status_url VARCHAR(300); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 305 | SET v_model_id = NULL; |
| 306 | CALL get_model( |
| 307 | v_model_name, |
| 308 | v_old_control_name_prefix, |
| 309 | v_old_control_name_uuid, |
| 310 | v_model_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 311 | v_old_service_type_id, |
| 312 | v_old_deployment_id, |
sebdet | 2579386 | 2018-11-08 17:11:10 +0100 | [diff] [blame] | 313 | v_old_deployment_status_url, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 314 | v_old_template_name, |
| 315 | v_old_template_id, |
| 316 | v_model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 317 | v_model_prop_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 318 | v_old_model_prop_text, |
| 319 | v_model_blueprint_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 320 | v_model_blueprint_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 321 | v_old_model_blueprint_text, |
| 322 | v_event_id, |
| 323 | v_action_cd, |
| 324 | v_action_state_cd, |
| 325 | v_event_process_instance_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 326 | v_event_user_id); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 327 | IF v_model_id IS NULL THEN |
| 328 | BEGIN |
| 329 | # UUID can be provided initially but cannot be updated |
| 330 | # if not provided (this is expected) then it will be set here |
| 331 | IF v_control_name_uuid IS NULL THEN |
| 332 | SET v_control_name_uuid = UUID(); |
| 333 | END IF; |
| 334 | SET v_model_id = v_control_name_uuid; |
| 335 | INSERT INTO model |
sebdet | 2579386 | 2018-11-08 17:11:10 +0100 | [diff] [blame] | 336 | (model_id, model_name, template_id, control_name_prefix, control_name_uuid, service_type_id, deployment_id, deployment_status_url) |
| 337 | VALUES (v_model_id, v_model_name, v_template_id, v_control_name_prefix, v_control_name_uuid, v_service_type_id, v_deployment_id,v_deployment_status_url); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 338 | # since just created model, insert CREATED event as initial default event |
| 339 | SET v_action_cd = 'CREATE'; |
| 340 | SET v_action_state_cd = 'COMPLETED'; |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 341 | SET v_event_user_id = v_user_id; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 342 | SET v_event_id = UUID(); |
| 343 | INSERT INTO event |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 344 | (event_id, model_id, action_cd, action_state_cd, user_id) |
| 345 | VALUES (v_event_id, v_model_id, v_action_cd, v_action_state_cd, v_event_user_id); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 346 | UPDATE model |
| 347 | SET event_id = v_event_id |
| 348 | WHERE model_id = v_model_id; |
| 349 | END; |
| 350 | ELSE |
| 351 | BEGIN |
| 352 | # use old control_name_prefix if null value is provided |
| 353 | IF v_control_name_prefix IS NULL THEN |
| 354 | SET v_control_name_prefix = v_old_control_name_prefix; |
| 355 | END IF; |
| 356 | # UUID can not be updated after initial insert |
| 357 | SET v_control_name_uuid = v_old_control_name_uuid; |
| 358 | END; |
| 359 | END IF; |
| 360 | IF v_model_prop_id IS NULL OR v_model_prop_text <> v_old_model_prop_text THEN |
| 361 | SET v_model_prop_id = UUID(); |
| 362 | INSERT INTO model_properties |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 363 | (model_prop_id, model_id, model_prop_text, user_id) |
| 364 | VALUES (v_model_prop_id, v_model_id, v_model_prop_text, v_user_id); |
| 365 | SET v_model_prop_user_id = v_user_id; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 366 | END IF; |
| 367 | IF v_model_blueprint_id IS NULL OR v_model_blueprint_text <> v_old_model_blueprint_text THEN |
| 368 | SET v_model_blueprint_id = UUID(); |
| 369 | INSERT INTO model_blueprint |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 370 | (model_blueprint_id, model_id, model_blueprint_text, user_id) |
| 371 | VALUES (v_model_blueprint_id, v_model_id, v_model_blueprint_text, v_user_id); |
| 372 | SET v_model_blueprint_user_id = v_user_id; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 373 | END IF; |
| 374 | UPDATE model |
| 375 | SET control_name_prefix = v_control_name_prefix, |
| 376 | model_prop_id = v_model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 377 | model_blueprint_id = v_model_blueprint_id, |
| 378 | service_type_id = v_service_type_id, |
sebdet | 2579386 | 2018-11-08 17:11:10 +0100 | [diff] [blame] | 379 | deployment_id = v_deployment_id, |
| 380 | deployment_status_url = v_deployment_status_url |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 381 | WHERE model_id = v_model_id; |
| 382 | END; |
| 383 | CREATE PROCEDURE ins_model_instance |
| 384 | (IN v_control_name_uuid VARCHAR(36), |
| 385 | IN v_vm_name VARCHAR(250), |
| 386 | IN v_location VARCHAR(250), |
| 387 | OUT v_model_id VARCHAR(36), |
| 388 | OUT v_model_instance_id VARCHAR(36)) |
| 389 | BEGIN |
| 390 | SELECT m.model_id |
| 391 | INTO v_model_id |
| 392 | FROM model m |
| 393 | WHERE m.control_name_uuid = v_control_name_uuid; |
| 394 | SET v_model_instance_id = UUID(); |
| 395 | INSERT INTO model_instance |
| 396 | (model_instance_id, model_id, vm_name, location) |
| 397 | VALUES (v_model_instance_id, v_model_id, v_vm_name, v_location); |
| 398 | END; |
| 399 | CREATE PROCEDURE del_model_instance |
| 400 | (IN v_control_name_uuid VARCHAR(36), |
| 401 | IN v_vm_name VARCHAR(250), |
| 402 | OUT v_model_id VARCHAR(36), |
| 403 | OUT v_model_instance_id VARCHAR(36)) |
| 404 | BEGIN |
| 405 | SELECT m.model_id, i.model_instance_id |
| 406 | INTO v_model_id, |
| 407 | v_model_instance_id |
| 408 | FROM model m, |
| 409 | model_instance i |
| 410 | WHERE m.model_id = i.model_id |
| 411 | AND m.control_name_uuid = v_control_name_uuid |
| 412 | AND i.vm_name = v_vm_name; |
| 413 | DELETE FROM model_instance |
| 414 | WHERE model_instance_id = v_model_instance_id; |
| 415 | END; |
| 416 | CREATE PROCEDURE del_all_model_instances |
| 417 | (IN v_control_name_uuid VARCHAR(36), |
| 418 | OUT v_model_id VARCHAR(36)) |
| 419 | BEGIN |
| 420 | SELECT m.model_id |
| 421 | INTO v_model_id |
| 422 | FROM model m |
| 423 | WHERE m.control_name_uuid = v_control_name_uuid; |
| 424 | DELETE FROM model_instance |
| 425 | WHERE model_id = v_model_id; |
| 426 | END; |
| 427 | CREATE PROCEDURE ins_event |
| 428 | (IN v_model_name VARCHAR(80), |
| 429 | IN v_control_name_prefix VARCHAR(80), |
| 430 | IN v_control_name_uuid VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 431 | IN v_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 432 | IN v_action_cd VARCHAR(80), |
| 433 | IN v_action_state_cd VARCHAR(80), |
| 434 | IN v_process_instance_id VARCHAR(80), |
| 435 | OUT v_model_id VARCHAR(36), |
| 436 | OUT v_event_id VARCHAR(36)) |
| 437 | BEGIN |
| 438 | DECLARE v_prev_event_id VARCHAR(36); |
| 439 | SELECT m.model_id, |
| 440 | m.event_id |
| 441 | INTO v_model_id, |
| 442 | v_prev_event_id |
| 443 | FROM model m |
| 444 | WHERE m.model_name = v_model_name |
| 445 | OR m.control_name_uuid = v_control_name_uuid; |
| 446 | SET v_event_id = UUID(); |
| 447 | INSERT INTO event |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 448 | (event_id, model_id, action_cd, action_state_cd, prev_event_id, process_instance_id, user_id) |
| 449 | VALUES (v_event_id, v_model_id, v_action_cd, v_action_state_cd, v_prev_event_id, v_process_instance_id, v_user_id); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 450 | UPDATE model |
| 451 | SET event_id = v_event_id |
| 452 | WHERE model_id = v_model_id; |
| 453 | END; |
| 454 | CREATE PROCEDURE upd_event |
| 455 | (IN v_event_id VARCHAR(36), |
| 456 | IN v_process_instance_id VARCHAR(80)) |
| 457 | BEGIN |
| 458 | UPDATE event |
| 459 | SET process_instance_id = v_process_instance_id |
| 460 | WHERE event_id = v_event_id; |
Determe, Sebastien (sd378r) | 7a58af8 | 2018-06-06 13:47:21 +0200 | [diff] [blame] | 461 | END; |
sebdet | ac3eeb3 | 2018-09-21 17:46:12 +0200 | [diff] [blame] | 462 | CREATE PROCEDURE del_model |
| 463 | (IN v_model_name VARCHAR(80)) |
Determe, Sebastien (sd378r) | 7a58af8 | 2018-06-06 13:47:21 +0200 | [diff] [blame] | 464 | BEGIN |
| 465 | DECLARE v_model_id VARCHAR(36); |
| 466 | SELECT model_id INTO v_model_id from model where model_name = v_model_name; |
| 467 | UPDATE model set event_id = null, model_blueprint_id = null, model_prop_id = null where model_id = v_model_id; |
| 468 | DELETE from event where model_id = v_model_id; |
| 469 | DELETE from model_blueprint where model_id = v_model_id; |
| 470 | DELETE from model_properties where model_id = v_model_id; |
| 471 | DELETE from model where model_id = v_model_id; |
sebdet | ac3eeb3 | 2018-09-21 17:46:12 +0200 | [diff] [blame] | 472 | END; |
sebdet | 6651e17 | 2018-09-03 14:39:21 +0200 | [diff] [blame] | 473 | |
| 474 | CREATE PROCEDURE set_new_tosca_model_version |
| 475 | (IN v_tosca_model_id VARCHAR(36), |
| 476 | IN v_version DOUBLE, |
| 477 | IN v_tosca_model_yaml MEDIUMTEXT, |
| 478 | IN v_tosca_model_json MEDIUMTEXT, |
| 479 | IN v_user_id VARCHAR(80), |
| 480 | OUT v_revision_id VARCHAR(36)) |
| 481 | BEGIN |
| 482 | SET v_revision_id = UUID(); |
| 483 | INSERT INTO tosca_model_revision |
| 484 | (tosca_model_revision_id, tosca_model_id, version, tosca_model_yaml, tosca_model_json, user_id) |
| 485 | VALUES (v_revision_id, v_tosca_model_id, v_version, v_tosca_model_yaml, v_tosca_model_json, v_user_id); |
| 486 | END; |
| 487 | |
| 488 | CREATE PROCEDURE set_tosca_model |
| 489 | (IN v_tosca_model_name VARCHAR(80), |
| 490 | IN v_policy_type VARCHAR(80), |
| 491 | IN v_user_id VARCHAR(80), |
| 492 | IN v_tosca_model_yaml MEDIUMTEXT, |
| 493 | IN v_tosca_model_json MEDIUMTEXT, |
| 494 | IN v_version DOUBLE, |
| 495 | OUT v_tosca_model_id VARCHAR(36), |
| 496 | OUT v_revision_id VARCHAR(36)) |
| 497 | BEGIN |
| 498 | SET v_tosca_model_id = UUID(); |
| 499 | INSERT INTO tosca_model |
| 500 | (tosca_model_id, tosca_model_name, policy_type, user_id) |
| 501 | VALUES (v_tosca_model_id, v_tosca_model_name, v_policy_type, v_user_id); |
| 502 | SET v_revision_id = UUID(); |
| 503 | INSERT INTO tosca_model_revision |
| 504 | (tosca_model_revision_id, tosca_model_id, version, tosca_model_yaml, tosca_model_json, user_id) |
| 505 | VALUES (v_revision_id, v_tosca_model_id, v_version, v_tosca_model_yaml, v_tosca_model_json, v_user_id); |
| 506 | END; |
| 507 | |
| 508 | CREATE PROCEDURE set_dictionary |
| 509 | (IN v_dictionary_name VARCHAR(80), |
| 510 | IN v_user_id VARCHAR(80), |
| 511 | OUT v_dictionary_id VARCHAR(36)) |
| 512 | BEGIN |
| 513 | SET v_dictionary_id = UUID(); |
| 514 | INSERT INTO dictionary |
| 515 | (dictionary_id, dictionary_name, created_by, modified_by) |
| 516 | VALUES (v_dictionary_id, v_dictionary_name, v_user_id, v_user_id); |
| 517 | END; |
| 518 | |
| 519 | CREATE PROCEDURE set_dictionary_elements |
| 520 | (IN v_dictionary_id VARCHAR(36), |
| 521 | IN v_dict_element_name VARCHAR(250), |
| 522 | IN v_dict_element_short_name VARCHAR(80), |
| 523 | IN v_dict_element_description VARCHAR(250), |
| 524 | IN v_dict_element_type VARCHAR(80), |
| 525 | IN v_user_id VARCHAR(80), |
| 526 | OUT v_dict_element_id VARCHAR(36)) |
| 527 | BEGIN |
| 528 | SET v_dict_element_id = UUID(); |
| 529 | INSERT INTO dictionary_elements |
| 530 | (dict_element_id, dictionary_id, dict_element_name, dict_element_short_name, dict_element_description, dict_element_type, created_by, modified_by) |
| 531 | VALUES (v_dict_element_id, v_dictionary_id, v_dict_element_name, v_dict_element_short_name, v_dict_element_description, v_dict_element_type, v_user_id, v_user_id); |
| 532 | END; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 533 | // |
| 534 | DELIMITER ; |