blob: aa8edb81a6c4534e07b23543923b78c3c783578f [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),
ChrisC5e9feb22017-06-21 02:38:57 -0700137 OUT v_template_name VARCHAR(80),
138 OUT v_template_id VARCHAR(36),
139 OUT v_model_prop_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700140 OUT v_model_prop_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700141 OUT v_model_prop_text MEDIUMTEXT,
142 OUT v_model_blueprint_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700143 OUT v_model_blueprint_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700144 OUT v_model_blueprint_text MEDIUMTEXT,
145 OUT v_event_id VARCHAR(36),
146 OUT v_action_cd VARCHAR(80),
147 OUT v_action_state_cd VARCHAR(80),
148 OUT v_event_process_instance_id VARCHAR(80),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700149 OUT v_event_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -0700150BEGIN
151 SELECT m.control_name_prefix,
152 m.control_name_uuid,
153 m.model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700154 m.service_type_id,
155 m.deployment_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700156 t.template_name,
157 m.template_id,
158 mp.model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700159 mp.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700160 mp.model_prop_text,
161 mb.model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700162 mb.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700163 mb.model_blueprint_text,
164 e.event_id,
165 e.action_cd,
166 e.action_state_cd,
167 e.process_instance_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700168 e.user_id
ChrisC5e9feb22017-06-21 02:38:57 -0700169 INTO v_control_name_prefix,
170 v_control_name_uuid,
171 v_model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700172 v_service_type_id,
173 v_deployment_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700174 v_template_name,
175 v_template_id,
176 v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700177 v_model_prop_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700178 v_model_prop_text,
179 v_model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700180 v_model_blueprint_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700181 v_model_blueprint_text,
182 v_event_id,
183 v_action_cd,
184 v_action_state_cd,
185 v_event_process_instance_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700186 v_event_user_id
ChrisC5e9feb22017-06-21 02:38:57 -0700187 FROM model m,
188 template t,
189 model_properties mp,
190 model_blueprint mb,
191 event e
192 WHERE m.template_id = t.template_id
193 AND m.model_prop_id = mp.model_prop_id
194 AND m.model_blueprint_id = mb.model_blueprint_id
195 AND m.event_id = e.event_id
196 AND (m.model_name = v_model_name
197 OR m.control_name_uuid = v_control_name_uuid);
198 SELECT model_instance_id,
199 vm_name,
200 location,
201 timestamp
202 FROM model_instance
203 WHERE model_id = v_model_id
204 ORDER BY 2;
205END;
206CREATE PROCEDURE get_model_template
207 (IN v_model_name VARCHAR(80),
208 OUT v_control_name_prefix VARCHAR(80),
209 INOUT v_control_name_uuid VARCHAR(36),
210 OUT v_model_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700211 OUT v_service_type_id VARCHAR(80),
212 OUT v_deployment_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700213 OUT v_template_name VARCHAR(80),
214 OUT v_template_id VARCHAR(36),
215 OUT v_model_prop_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700216 OUT v_model_prop_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700217 OUT v_model_prop_text MEDIUMTEXT,
218 OUT v_model_blueprint_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700219 OUT v_model_blueprint_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700220 OUT v_model_blueprint_text MEDIUMTEXT,
221 OUT v_template_bpmn_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700222 OUT v_template_bpmn_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700223 OUT v_template_bpmn_text MEDIUMTEXT,
224 OUT v_template_image_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700225 OUT v_template_image_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700226 OUT v_template_image_text MEDIUMTEXT,
227 OUT v_template_doc_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700228 OUT v_template_doc_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700229 OUT v_template_doc_text MEDIUMTEXT,
230 OUT v_event_id VARCHAR(36),
231 OUT v_action_cd VARCHAR(80),
232 OUT v_action_state_cd VARCHAR(80),
233 OUT v_event_process_instance_id VARCHAR(80),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700234 OUT v_event_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -0700235BEGIN
236 CALL get_model(
237 v_model_name,
238 v_control_name_prefix,
239 v_control_name_uuid,
240 v_model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700241 v_service_type_id,
242 v_deployment_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700243 v_template_name,
244 v_template_id,
245 v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700246 v_model_prop_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700247 v_model_prop_text,
248 v_model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700249 v_model_blueprint_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700250 v_model_blueprint_text,
251 v_event_id,
252 v_action_cd,
253 v_action_state_cd,
254 v_event_process_instance_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700255 v_event_user_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700256 CALL get_template(
257 v_template_name,
258 v_template_id,
259 v_template_bpmn_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700260 v_template_bpmn_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700261 v_template_bpmn_text,
262 v_template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700263 v_template_image_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700264 v_template_image_text,
265 v_template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700266 v_template_doc_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700267 v_template_doc_text);
268 END;
269CREATE PROCEDURE set_model
270 (IN v_model_name VARCHAR(80),
271 IN v_template_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700272 IN v_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700273 IN v_model_prop_text MEDIUMTEXT,
274 IN v_model_blueprint_text MEDIUMTEXT,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700275 IN v_service_type_id VARCHAR(80),
276 IN v_deployment_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700277 INOUT v_control_name_prefix VARCHAR(80),
278 INOUT v_control_name_uuid VARCHAR(36),
279 OUT v_model_id VARCHAR(36),
280 OUT v_model_prop_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700281 OUT v_model_prop_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700282 OUT v_model_blueprint_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700283 OUT v_model_blueprint_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700284 OUT v_event_id VARCHAR(36),
285 OUT v_action_cd VARCHAR(80),
286 OUT v_action_state_cd VARCHAR(80),
287 OUT v_event_process_instance_id VARCHAR(80),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700288 OUT v_event_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -0700289BEGIN
290 DECLARE v_old_template_name VARCHAR(80);
291 DECLARE v_old_template_id VARCHAR(36);
292 DECLARE v_old_control_name_prefix VARCHAR(80);
293 DECLARE v_old_control_name_uuid VARCHAR(36);
294 DECLARE v_old_model_prop_text MEDIUMTEXT;
295 DECLARE v_old_model_blueprint_text MEDIUMTEXT;
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700296 DECLARE v_old_service_type_id VARCHAR(80);
297 DECLARE v_old_deployment_id VARCHAR(80);
ChrisC5e9feb22017-06-21 02:38:57 -0700298 SET v_model_id = NULL;
299 CALL get_model(
300 v_model_name,
301 v_old_control_name_prefix,
302 v_old_control_name_uuid,
303 v_model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700304 v_old_service_type_id,
305 v_old_deployment_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700306 v_old_template_name,
307 v_old_template_id,
308 v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700309 v_model_prop_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700310 v_old_model_prop_text,
311 v_model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700312 v_model_blueprint_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700313 v_old_model_blueprint_text,
314 v_event_id,
315 v_action_cd,
316 v_action_state_cd,
317 v_event_process_instance_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700318 v_event_user_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700319 IF v_model_id IS NULL THEN
320 BEGIN
321 # UUID can be provided initially but cannot be updated
322 # if not provided (this is expected) then it will be set here
323 IF v_control_name_uuid IS NULL THEN
324 SET v_control_name_uuid = UUID();
325 END IF;
326 SET v_model_id = v_control_name_uuid;
327 INSERT INTO model
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700328 (model_id, model_name, template_id, control_name_prefix, control_name_uuid, service_type_id, deployment_id)
329 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);
ChrisC5e9feb22017-06-21 02:38:57 -0700330 # since just created model, insert CREATED event as initial default event
331 SET v_action_cd = 'CREATE';
332 SET v_action_state_cd = 'COMPLETED';
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700333 SET v_event_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700334 SET v_event_id = UUID();
335 INSERT INTO event
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700336 (event_id, model_id, action_cd, action_state_cd, user_id)
337 VALUES (v_event_id, v_model_id, v_action_cd, v_action_state_cd, v_event_user_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700338 UPDATE model
339 SET event_id = v_event_id
340 WHERE model_id = v_model_id;
341 END;
342 ELSE
343 BEGIN
344 # use old control_name_prefix if null value is provided
345 IF v_control_name_prefix IS NULL THEN
346 SET v_control_name_prefix = v_old_control_name_prefix;
347 END IF;
348 # UUID can not be updated after initial insert
349 SET v_control_name_uuid = v_old_control_name_uuid;
350 END;
351 END IF;
352 IF v_model_prop_id IS NULL OR v_model_prop_text <> v_old_model_prop_text THEN
353 SET v_model_prop_id = UUID();
354 INSERT INTO model_properties
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700355 (model_prop_id, model_id, model_prop_text, user_id)
356 VALUES (v_model_prop_id, v_model_id, v_model_prop_text, v_user_id);
357 SET v_model_prop_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700358 END IF;
359 IF v_model_blueprint_id IS NULL OR v_model_blueprint_text <> v_old_model_blueprint_text THEN
360 SET v_model_blueprint_id = UUID();
361 INSERT INTO model_blueprint
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700362 (model_blueprint_id, model_id, model_blueprint_text, user_id)
363 VALUES (v_model_blueprint_id, v_model_id, v_model_blueprint_text, v_user_id);
364 SET v_model_blueprint_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700365 END IF;
366 UPDATE model
367 SET control_name_prefix = v_control_name_prefix,
368 model_prop_id = v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700369 model_blueprint_id = v_model_blueprint_id,
370 service_type_id = v_service_type_id,
371 deployment_id = v_deployment_id
ChrisC5e9feb22017-06-21 02:38:57 -0700372 WHERE model_id = v_model_id;
373END;
374CREATE PROCEDURE ins_model_instance
375 (IN v_control_name_uuid VARCHAR(36),
376 IN v_vm_name VARCHAR(250),
377 IN v_location VARCHAR(250),
378 OUT v_model_id VARCHAR(36),
379 OUT v_model_instance_id VARCHAR(36))
380BEGIN
381 SELECT m.model_id
382 INTO v_model_id
383 FROM model m
384 WHERE m.control_name_uuid = v_control_name_uuid;
385 SET v_model_instance_id = UUID();
386 INSERT INTO model_instance
387 (model_instance_id, model_id, vm_name, location)
388 VALUES (v_model_instance_id, v_model_id, v_vm_name, v_location);
389END;
390CREATE PROCEDURE del_model_instance
391 (IN v_control_name_uuid VARCHAR(36),
392 IN v_vm_name VARCHAR(250),
393 OUT v_model_id VARCHAR(36),
394 OUT v_model_instance_id VARCHAR(36))
395BEGIN
396 SELECT m.model_id, i.model_instance_id
397 INTO v_model_id,
398 v_model_instance_id
399 FROM model m,
400 model_instance i
401 WHERE m.model_id = i.model_id
402 AND m.control_name_uuid = v_control_name_uuid
403 AND i.vm_name = v_vm_name;
404 DELETE FROM model_instance
405 WHERE model_instance_id = v_model_instance_id;
406END;
407CREATE PROCEDURE del_all_model_instances
408 (IN v_control_name_uuid VARCHAR(36),
409 OUT v_model_id VARCHAR(36))
410BEGIN
411 SELECT m.model_id
412 INTO v_model_id
413 FROM model m
414 WHERE m.control_name_uuid = v_control_name_uuid;
415 DELETE FROM model_instance
416 WHERE model_id = v_model_id;
417END;
418CREATE PROCEDURE ins_event
419 (IN v_model_name VARCHAR(80),
420 IN v_control_name_prefix VARCHAR(80),
421 IN v_control_name_uuid VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700422 IN v_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700423 IN v_action_cd VARCHAR(80),
424 IN v_action_state_cd VARCHAR(80),
425 IN v_process_instance_id VARCHAR(80),
426 OUT v_model_id VARCHAR(36),
427 OUT v_event_id VARCHAR(36))
428BEGIN
429 DECLARE v_prev_event_id VARCHAR(36);
430 SELECT m.model_id,
431 m.event_id
432 INTO v_model_id,
433 v_prev_event_id
434 FROM model m
435 WHERE m.model_name = v_model_name
436 OR m.control_name_uuid = v_control_name_uuid;
437 SET v_event_id = UUID();
438 INSERT INTO event
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700439 (event_id, model_id, action_cd, action_state_cd, prev_event_id, process_instance_id, user_id)
440 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 -0700441 UPDATE model
442 SET event_id = v_event_id
443 WHERE model_id = v_model_id;
444END;
445CREATE PROCEDURE upd_event
446 (IN v_event_id VARCHAR(36),
447 IN v_process_instance_id VARCHAR(80))
448BEGIN
449 UPDATE event
450 SET process_instance_id = v_process_instance_id
451 WHERE event_id = v_event_id;
Determe, Sebastien (sd378r)7a58af82018-06-06 13:47:21 +0200452END;
sebdetac3eeb32018-09-21 17:46:12 +0200453CREATE PROCEDURE del_model
454(IN v_model_name VARCHAR(80))
Determe, Sebastien (sd378r)7a58af82018-06-06 13:47:21 +0200455BEGIN
456 DECLARE v_model_id VARCHAR(36);
457 SELECT model_id INTO v_model_id from model where model_name = v_model_name;
458 UPDATE model set event_id = null, model_blueprint_id = null, model_prop_id = null where model_id = v_model_id;
459 DELETE from event where model_id = v_model_id;
460 DELETE from model_blueprint where model_id = v_model_id;
461 DELETE from model_properties where model_id = v_model_id;
462 DELETE from model where model_id = v_model_id;
sebdetac3eeb32018-09-21 17:46:12 +0200463END;
sebdet6651e172018-09-03 14:39:21 +0200464
465CREATE PROCEDURE set_new_tosca_model_version
466 (IN v_tosca_model_id VARCHAR(36),
467 IN v_version DOUBLE,
468 IN v_tosca_model_yaml MEDIUMTEXT,
469 IN v_tosca_model_json MEDIUMTEXT,
470 IN v_user_id VARCHAR(80),
471 OUT v_revision_id VARCHAR(36))
472BEGIN
473 SET v_revision_id = UUID();
474 INSERT INTO tosca_model_revision
475 (tosca_model_revision_id, tosca_model_id, version, tosca_model_yaml, tosca_model_json, user_id)
476 VALUES (v_revision_id, v_tosca_model_id, v_version, v_tosca_model_yaml, v_tosca_model_json, v_user_id);
477END;
478
479CREATE PROCEDURE set_tosca_model
480 (IN v_tosca_model_name VARCHAR(80),
481 IN v_policy_type VARCHAR(80),
482 IN v_user_id VARCHAR(80),
483 IN v_tosca_model_yaml MEDIUMTEXT,
484 IN v_tosca_model_json MEDIUMTEXT,
485 IN v_version DOUBLE,
486 OUT v_tosca_model_id VARCHAR(36),
487 OUT v_revision_id VARCHAR(36))
488BEGIN
489 SET v_tosca_model_id = UUID();
490 INSERT INTO tosca_model
491 (tosca_model_id, tosca_model_name, policy_type, user_id)
492 VALUES (v_tosca_model_id, v_tosca_model_name, v_policy_type, v_user_id);
493 SET v_revision_id = UUID();
494 INSERT INTO tosca_model_revision
495 (tosca_model_revision_id, tosca_model_id, version, tosca_model_yaml, tosca_model_json, user_id)
496 VALUES (v_revision_id, v_tosca_model_id, v_version, v_tosca_model_yaml, v_tosca_model_json, v_user_id);
497END;
498
499CREATE PROCEDURE set_dictionary
500 (IN v_dictionary_name VARCHAR(80),
501 IN v_user_id VARCHAR(80),
502 OUT v_dictionary_id VARCHAR(36))
503BEGIN
504 SET v_dictionary_id = UUID();
505 INSERT INTO dictionary
506 (dictionary_id, dictionary_name, created_by, modified_by)
507 VALUES (v_dictionary_id, v_dictionary_name, v_user_id, v_user_id);
508END;
509
510CREATE PROCEDURE set_dictionary_elements
511 (IN v_dictionary_id VARCHAR(36),
512 IN v_dict_element_name VARCHAR(250),
513 IN v_dict_element_short_name VARCHAR(80),
514 IN v_dict_element_description VARCHAR(250),
515 IN v_dict_element_type VARCHAR(80),
516 IN v_user_id VARCHAR(80),
517 OUT v_dict_element_id VARCHAR(36))
518BEGIN
519 SET v_dict_element_id = UUID();
520 INSERT INTO dictionary_elements
521 (dict_element_id, dictionary_id, dict_element_name, dict_element_short_name, dict_element_description, dict_element_type, created_by, modified_by)
522 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);
523END;
ChrisC5e9feb22017-06-21 02:38:57 -0700524//
525DELIMITER ;