blob: b48e86afe27fb7b84983ce9acf216eb04de46484 [file] [log] [blame]
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -07001#
ChrisC5e9feb22017-06-21 02:38:57 -07002# CLDS stored procedures
3#
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -07004
ChrisC5e9feb22017-06-21 02:38:57 -07005USE cldsdb4;
6
7DROP PROCEDURE IF EXISTS upd_event;
8DROP PROCEDURE IF EXISTS ins_event;
9DROP PROCEDURE IF EXISTS del_all_model_instances;
10DROP PROCEDURE IF EXISTS del_model_instance;
11DROP PROCEDURE IF EXISTS ins_model_instance;
12DROP PROCEDURE IF EXISTS set_model;
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070013DROP PROCEDURE IF EXISTS get_model;
14DROP PROCEDURE IF EXISTS get_model_template;
ChrisC5e9feb22017-06-21 02:38:57 -070015DROP PROCEDURE IF EXISTS set_template;
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070016DROP PROCEDURE IF EXISTS get_template;
Determe, Sebastien (sd378r)7a58af82018-06-06 13:47:21 +020017DROP PROCEDURE IF EXISTS del_model;
sebdet6651e172018-09-03 14:39:21 +020018DROP PROCEDURE IF EXISTS set_new_tosca_model_version;
19DROP PROCEDURE IF EXISTS set_tosca_model;
20DROP PROCEDURE IF EXISTS set_dictionary;
21DROP PROCEDURE IF EXISTS set_dictionary_elements;
ChrisC5e9feb22017-06-21 02:38:57 -070022DELIMITER //
23CREATE 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)b3a21f72017-08-08 02:58:27 -070027 OUT v_template_bpmn_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070028 OUT v_template_bpmn_text MEDIUMTEXT,
29 OUT v_template_image_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070030 OUT v_template_image_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070031 OUT v_template_image_text MEDIUMTEXT,
32 OUT v_template_doc_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070033 OUT v_template_doc_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070034 OUT v_template_doc_text MEDIUMTEXT)
35BEGIN
36 SELECT t.template_id,
37 tb.template_bpmn_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070038 tb.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070039 tb.template_bpmn_text,
40 ti.template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070041 ti.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070042 ti.template_image_text,
43 td.template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070044 td.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070045 td.template_doc_text
46 INTO v_template_id,
47 v_template_bpmn_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070048 v_template_bpmn_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070049 v_template_bpmn_text,
50 v_template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070051 v_template_image_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070052 v_template_image_text,
53 v_template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070054 v_template_doc_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070055 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;
64END;
65CREATE PROCEDURE set_template
66 (IN v_template_name VARCHAR(80),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070067 IN v_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070068 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)b3a21f72017-08-08 02:58:27 -070073 OUT v_template_bpmn_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070074 OUT v_template_image_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070075 OUT v_template_image_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070076 OUT v_template_doc_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070077 OUT v_template_doc_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -070078BEGIN
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)b3a21f72017-08-08 02:58:27 -070087 v_template_bpmn_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070088 v_old_template_bpmn_text,
89 v_template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070090 v_template_image_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070091 v_old_template_image_text,
92 v_template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070093 v_template_doc_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070094 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)b3a21f72017-08-08 02:58:27 -0700106 (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;
ChrisC5e9feb22017-06-21 02:38:57 -0700109 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)b3a21f72017-08-08 02:58:27 -0700113 (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;
ChrisC5e9feb22017-06-21 02:38:57 -0700116 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)b3a21f72017-08-08 02:58:27 -0700120 (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;
ChrisC5e9feb22017-06-21 02:38:57 -0700123 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;
129END;
130CREATE 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)b3a21f72017-08-08 02:58:27 -0700135 OUT v_service_type_id VARCHAR(80),
136 OUT v_deployment_id VARCHAR(80),
sebdet25793862018-11-08 17:11:10 +0100137 OUT v_deployment_status_url VARCHAR(300),
ChrisC5e9feb22017-06-21 02:38:57 -0700138 OUT v_template_name VARCHAR(80),
139 OUT v_template_id VARCHAR(36),
140 OUT v_model_prop_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700141 OUT v_model_prop_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700142 OUT v_model_prop_text MEDIUMTEXT,
143 OUT v_model_blueprint_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700144 OUT v_model_blueprint_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700145 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)b3a21f72017-08-08 02:58:27 -0700150 OUT v_event_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -0700151BEGIN
152 SELECT m.control_name_prefix,
153 m.control_name_uuid,
154 m.model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700155 m.service_type_id,
156 m.deployment_id,
sebdet25793862018-11-08 17:11:10 +0100157 m.deployment_status_url,
ChrisC5e9feb22017-06-21 02:38:57 -0700158 t.template_name,
159 m.template_id,
160 mp.model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700161 mp.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700162 mp.model_prop_text,
163 mb.model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700164 mb.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700165 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)b3a21f72017-08-08 02:58:27 -0700170 e.user_id
ChrisC5e9feb22017-06-21 02:38:57 -0700171 INTO v_control_name_prefix,
172 v_control_name_uuid,
173 v_model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700174 v_service_type_id,
175 v_deployment_id,
sebdet25793862018-11-08 17:11:10 +0100176 v_deployment_status_url,
ChrisC5e9feb22017-06-21 02:38:57 -0700177 v_template_name,
178 v_template_id,
179 v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700180 v_model_prop_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700181 v_model_prop_text,
182 v_model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700183 v_model_blueprint_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700184 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)b3a21f72017-08-08 02:58:27 -0700189 v_event_user_id
ChrisC5e9feb22017-06-21 02:38:57 -0700190 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;
208END;
209CREATE 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)b3a21f72017-08-08 02:58:27 -0700214 OUT v_service_type_id VARCHAR(80),
215 OUT v_deployment_id VARCHAR(80),
sebdet25793862018-11-08 17:11:10 +0100216 OUT v_deployment_status_url VARCHAR(300),
ChrisC5e9feb22017-06-21 02:38:57 -0700217 OUT v_template_name VARCHAR(80),
218 OUT v_template_id VARCHAR(36),
219 OUT v_model_prop_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700220 OUT v_model_prop_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700221 OUT v_model_prop_text MEDIUMTEXT,
222 OUT v_model_blueprint_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700223 OUT v_model_blueprint_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700224 OUT v_model_blueprint_text MEDIUMTEXT,
225 OUT v_template_bpmn_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700226 OUT v_template_bpmn_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700227 OUT v_template_bpmn_text MEDIUMTEXT,
228 OUT v_template_image_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700229 OUT v_template_image_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700230 OUT v_template_image_text MEDIUMTEXT,
231 OUT v_template_doc_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700232 OUT v_template_doc_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700233 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)b3a21f72017-08-08 02:58:27 -0700238 OUT v_event_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -0700239BEGIN
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)b3a21f72017-08-08 02:58:27 -0700245 v_service_type_id,
246 v_deployment_id,
sebdet25793862018-11-08 17:11:10 +0100247 v_deployment_status_url,
ChrisC5e9feb22017-06-21 02:38:57 -0700248 v_template_name,
249 v_template_id,
250 v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700251 v_model_prop_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700252 v_model_prop_text,
253 v_model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700254 v_model_blueprint_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700255 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)b3a21f72017-08-08 02:58:27 -0700260 v_event_user_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700261 CALL get_template(
262 v_template_name,
263 v_template_id,
264 v_template_bpmn_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700265 v_template_bpmn_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700266 v_template_bpmn_text,
267 v_template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700268 v_template_image_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700269 v_template_image_text,
270 v_template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700271 v_template_doc_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700272 v_template_doc_text);
273 END;
274CREATE PROCEDURE set_model
275 (IN v_model_name VARCHAR(80),
276 IN v_template_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700277 IN v_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700278 IN v_model_prop_text MEDIUMTEXT,
279 IN v_model_blueprint_text MEDIUMTEXT,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700280 IN v_service_type_id VARCHAR(80),
281 IN v_deployment_id VARCHAR(80),
sebdet25793862018-11-08 17:11:10 +0100282 IN v_deployment_status_url VARCHAR(300),
ChrisC5e9feb22017-06-21 02:38:57 -0700283 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)b3a21f72017-08-08 02:58:27 -0700287 OUT v_model_prop_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700288 OUT v_model_blueprint_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700289 OUT v_model_blueprint_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700290 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)b3a21f72017-08-08 02:58:27 -0700294 OUT v_event_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -0700295BEGIN
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)b3a21f72017-08-08 02:58:27 -0700302 DECLARE v_old_service_type_id VARCHAR(80);
303 DECLARE v_old_deployment_id VARCHAR(80);
sebdet25793862018-11-08 17:11:10 +0100304 DECLARE v_old_deployment_status_url VARCHAR(300);
ChrisC5e9feb22017-06-21 02:38:57 -0700305 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)b3a21f72017-08-08 02:58:27 -0700311 v_old_service_type_id,
312 v_old_deployment_id,
sebdet25793862018-11-08 17:11:10 +0100313 v_old_deployment_status_url,
ChrisC5e9feb22017-06-21 02:38:57 -0700314 v_old_template_name,
315 v_old_template_id,
316 v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700317 v_model_prop_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700318 v_old_model_prop_text,
319 v_model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700320 v_model_blueprint_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700321 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)b3a21f72017-08-08 02:58:27 -0700326 v_event_user_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700327 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
sebdet25793862018-11-08 17:11:10 +0100336 (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);
ChrisC5e9feb22017-06-21 02:38:57 -0700338 # 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)b3a21f72017-08-08 02:58:27 -0700341 SET v_event_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700342 SET v_event_id = UUID();
343 INSERT INTO event
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700344 (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);
ChrisC5e9feb22017-06-21 02:38:57 -0700346 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)b3a21f72017-08-08 02:58:27 -0700363 (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;
ChrisC5e9feb22017-06-21 02:38:57 -0700366 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)b3a21f72017-08-08 02:58:27 -0700370 (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;
ChrisC5e9feb22017-06-21 02:38:57 -0700373 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)b3a21f72017-08-08 02:58:27 -0700377 model_blueprint_id = v_model_blueprint_id,
378 service_type_id = v_service_type_id,
sebdet25793862018-11-08 17:11:10 +0100379 deployment_id = v_deployment_id,
380 deployment_status_url = v_deployment_status_url
ChrisC5e9feb22017-06-21 02:38:57 -0700381 WHERE model_id = v_model_id;
382END;
383CREATE 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))
389BEGIN
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);
398END;
399CREATE 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))
404BEGIN
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;
415END;
416CREATE PROCEDURE del_all_model_instances
417 (IN v_control_name_uuid VARCHAR(36),
418 OUT v_model_id VARCHAR(36))
419BEGIN
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;
426END;
427CREATE 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)b3a21f72017-08-08 02:58:27 -0700431 IN v_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700432 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))
437BEGIN
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)b3a21f72017-08-08 02:58:27 -0700448 (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);
ChrisC5e9feb22017-06-21 02:38:57 -0700450 UPDATE model
451 SET event_id = v_event_id
452 WHERE model_id = v_model_id;
453END;
454CREATE PROCEDURE upd_event
455 (IN v_event_id VARCHAR(36),
456 IN v_process_instance_id VARCHAR(80))
457BEGIN
458 UPDATE event
459 SET process_instance_id = v_process_instance_id
460 WHERE event_id = v_event_id;
Determe, Sebastien (sd378r)7a58af82018-06-06 13:47:21 +0200461END;
sebdetac3eeb32018-09-21 17:46:12 +0200462CREATE PROCEDURE del_model
463(IN v_model_name VARCHAR(80))
Determe, Sebastien (sd378r)7a58af82018-06-06 13:47:21 +0200464BEGIN
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;
sebdetac3eeb32018-09-21 17:46:12 +0200472END;
sebdet6651e172018-09-03 14:39:21 +0200473
474CREATE 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))
481BEGIN
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);
486END;
487
488CREATE 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))
497BEGIN
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);
506END;
507
508CREATE PROCEDURE set_dictionary
509 (IN v_dictionary_name VARCHAR(80),
510 IN v_user_id VARCHAR(80),
511 OUT v_dictionary_id VARCHAR(36))
512BEGIN
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);
517END;
518
519CREATE 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))
527BEGIN
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);
532END;
ChrisC5e9feb22017-06-21 02:38:57 -0700533//
534DELIMITER ;