[839] | 1 | create schema CollectionDB; |
---|
| 2 | |
---|
| 3 | set search_path = CollectionDB, pg_catalog; |
---|
| 4 | |
---|
| 5 | CREATE OR REPLACE FUNCTION update_Description() RETURNS trigger AS |
---|
| 6 | $$ |
---|
| 7 | DECLARE |
---|
| 8 | i integer; |
---|
| 9 | BEGIN |
---|
| 10 | INSERT INTO CollectionDB.Descriptions (id) VALUES (NEW.id); |
---|
| 11 | RETURN NEW; |
---|
| 12 | END; |
---|
| 13 | $$ LANGUAGE plpgsql; |
---|
| 14 | |
---|
| 15 | CREATE FUNCTION is_in_ows_DataDescription(i integer) RETURNS boolean |
---|
| 16 | LANGUAGE plpgsql |
---|
| 17 | AS $$ |
---|
| 18 | DECLARE |
---|
| 19 | res int; |
---|
| 20 | mymax int; |
---|
| 21 | BEGIN |
---|
| 22 | SELECT id from CollectionDB.ows_DataDescription where id=i INTO res ; |
---|
| 23 | if res is NULL then |
---|
| 24 | return false; |
---|
| 25 | else |
---|
| 26 | return true; |
---|
| 27 | end if; |
---|
| 28 | END; |
---|
| 29 | $$; |
---|
| 30 | |
---|
| 31 | create table CollectionDB.Descriptions ( |
---|
| 32 | id serial primary key |
---|
| 33 | ); |
---|
| 34 | |
---|
| 35 | create table CollectionDB.ows_Metadata ( |
---|
| 36 | id serial primary key, |
---|
| 37 | title text, |
---|
| 38 | role text, |
---|
| 39 | href text |
---|
| 40 | ); |
---|
| 41 | |
---|
| 42 | create table CollectionDB.DescriptionsMetadataAssignment( |
---|
| 43 | descriptions_id int references CollectionDB.Descriptions(id), |
---|
| 44 | metadata_id int references CollectionDB.ows_Metadata(id) |
---|
| 45 | ); |
---|
| 46 | |
---|
| 47 | create table CollectionDB.ows_Keywords ( |
---|
| 48 | id serial primary key, |
---|
| 49 | keyword varchar |
---|
| 50 | ); |
---|
| 51 | |
---|
| 52 | create table CollectionDB.DescriptionsKeywordsAssignment( |
---|
| 53 | descriptions_id int references CollectionDB.Descriptions(id), |
---|
| 54 | keywords_id int references CollectionDB.ows_Keywords(id) |
---|
| 55 | ); |
---|
| 56 | |
---|
| 57 | create table CollectionDB.ows_AdditionalParameters ( |
---|
| 58 | id serial primary key, |
---|
| 59 | title varchar, |
---|
| 60 | role varchar, |
---|
| 61 | href varchar |
---|
| 62 | ); |
---|
| 63 | |
---|
| 64 | create table CollectionDB.DescriptionsAdditionalParametersAssignment ( |
---|
| 65 | descriptions_id int references CollectionDB.Descriptions(id), |
---|
| 66 | additional_parameters_id int references CollectionDB.ows_AdditionalParameters(id) |
---|
| 67 | ); |
---|
| 68 | |
---|
| 69 | -- |
---|
| 70 | -- See reference for primitive datatypes |
---|
| 71 | -- https://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes |
---|
| 72 | -- |
---|
| 73 | create table CollectionDB.PrimitiveDataTypes ( |
---|
| 74 | id serial primary key, |
---|
| 75 | name varchar(255) |
---|
| 76 | ); |
---|
| 77 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('string'); |
---|
| 78 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('boolean'); |
---|
| 79 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('integer'); |
---|
| 80 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('float'); |
---|
| 81 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('double'); |
---|
| 82 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('duration'); |
---|
| 83 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('dateTime'); |
---|
| 84 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('time'); |
---|
| 85 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('date'); |
---|
| 86 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('gYearMonth'); |
---|
| 87 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('gYear'); |
---|
| 88 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('gMonthDay'); |
---|
| 89 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('gDay'); |
---|
| 90 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('gMonth'); |
---|
| 91 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('hexBinary'); |
---|
| 92 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('base64Binary'); |
---|
| 93 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('anyURI'); |
---|
| 94 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('QName'); |
---|
| 95 | INSERT INTO CollectionDB.PrimitiveDataTypes (name) VALUES ('NOTATION'); |
---|
| 96 | |
---|
| 97 | -- |
---|
| 98 | -- List all primitive formats |
---|
| 99 | -- |
---|
| 100 | create table CollectionDB.PrimitiveFormats ( |
---|
| 101 | id serial primary key, |
---|
| 102 | mime_type varchar(255), |
---|
| 103 | encoding varchar(15), |
---|
| 104 | schema varchar(255) |
---|
| 105 | ); |
---|
| 106 | |
---|
| 107 | -- https://tools.ietf.org/html/rfc4180 |
---|
| 108 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type,encoding) VALUES ('text/csv','utf-8'); |
---|
| 109 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type,encoding) VALUES ('text/css','utf-8'); |
---|
| 110 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type,encoding) VALUES ('text/html','utf-8'); |
---|
| 111 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type,encoding) VALUES ('text/javascript','utf-8'); |
---|
| 112 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type,encoding) VALUES ('text/plain','utf-8'); |
---|
| 113 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type,encoding,schema) |
---|
| 114 | VALUES ('text/xml','utf-8','http://schema.opengis.net/gml/3.2.1/gml.xsd'); |
---|
| 115 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type,encoding,schema) |
---|
| 116 | VALUES ('text/xml','utf-8','http://schema.opengis.net/gml/3.1.0/gml.xsd'); |
---|
| 117 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type,encoding) VALUES ('application/gml+xml','utf-8'); |
---|
| 118 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type,encoding) VALUES ('application/json','utf-8'); |
---|
| 119 | -- https://tools.ietf.org/html/rfc3302 |
---|
| 120 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type) VALUES ('image/tiff'); |
---|
| 121 | -- https://www.ietf.org/rfc/rfc4047.txt |
---|
| 122 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type) VALUES ('image/fits'); |
---|
| 123 | -- https://tools.ietf.org/html/rfc3745 |
---|
| 124 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type) VALUES ('image/jp2'); |
---|
| 125 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type) VALUES ('image/png'); |
---|
| 126 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type) VALUES ('image/jpeg'); |
---|
| 127 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type) VALUES ('image/gif'); |
---|
| 128 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type) VALUES ('application/octet-stream'); |
---|
| 129 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type) VALUES ('application/vnd.google-earth.kml+xml'); |
---|
| 130 | -- https://www.iana.org/assignments/media-types/application/zip |
---|
| 131 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type) VALUES ('application/zip'); |
---|
| 132 | -- https://www.iana.org/assignments/media-types/application/xml |
---|
| 133 | INSERT INTO CollectionDB.PrimitiveFormats (mime_type,encoding) VALUES ('application/xml','utf-8'); |
---|
| 134 | |
---|
| 135 | create table CollectionDB.ows_Format ( |
---|
| 136 | id serial primary key, |
---|
| 137 | primitive_format_id int references CollectionDB.PrimitiveFormats(id), |
---|
| 138 | maximum_megabytes int, |
---|
| 139 | def boolean, |
---|
| 140 | use_mapserver bool, |
---|
| 141 | ms_styles text |
---|
| 142 | ); |
---|
| 143 | |
---|
| 144 | create table CollectionDB.ows_DataDescription ( |
---|
| 145 | id serial primary key, |
---|
| 146 | format_id int references CollectionDB.ows_Format(id) |
---|
| 147 | ); |
---|
| 148 | |
---|
| 149 | create table CollectionDB.PrimitiveUom ( |
---|
| 150 | id serial primary key, |
---|
| 151 | uom varchar |
---|
| 152 | ); |
---|
| 153 | -- source : Open Geospatial Consortium - URNs of definitions in ogc namespace |
---|
| 154 | insert into CollectionDB.PrimitiveUom (uom) values ('degree'); |
---|
| 155 | insert into CollectionDB.PrimitiveUom (uom) values ('radian'); |
---|
| 156 | insert into CollectionDB.PrimitiveUom (uom) values ('metre'); |
---|
| 157 | insert into CollectionDB.PrimitiveUom (uom) values ('unity'); |
---|
| 158 | |
---|
| 159 | create table CollectionDB.LiteralDataDomain ( |
---|
| 160 | possible_literal_values varchar, |
---|
| 161 | default_value varchar, |
---|
| 162 | data_type_id int references CollectionDB.PrimitiveDataTypes(id), |
---|
| 163 | uom int references CollectionDB.PrimitiveUom(id), |
---|
| 164 | def boolean |
---|
| 165 | ) inherits (CollectionDB.ows_DataDescription); |
---|
| 166 | alter table CollectionDB.LiteralDataDomain add constraint literal_data_domain_id unique (id); |
---|
| 167 | |
---|
| 168 | create table CollectionDB.BoundingBoxData ( |
---|
| 169 | epsg int |
---|
| 170 | ) inherits (CollectionDB.ows_DataDescription); |
---|
| 171 | alter table CollectionDB.BoundingBoxData add constraint bounding_box_data_id unique (id); |
---|
| 172 | |
---|
| 173 | create table CollectionDB.ComplexData ( |
---|
| 174 | ) inherits (CollectionDB.ows_DataDescription); |
---|
| 175 | alter table CollectionDB.ComplexData add constraint complex_data_id unique (id); |
---|
| 176 | |
---|
| 177 | create table CollectionDB.AllowedValues ( |
---|
| 178 | id serial primary key, |
---|
| 179 | allowed_value varchar(255) |
---|
| 180 | ); |
---|
| 181 | |
---|
| 182 | create table CollectionDB.AllowedValuesAssignment ( |
---|
| 183 | id serial primary key, |
---|
| 184 | literal_data_domain_id int references CollectionDB.LiteralDataDomain (id), |
---|
| 185 | allowed_value_id int references CollectionDB.AllowedValues (id) |
---|
| 186 | ); |
---|
| 187 | |
---|
| 188 | create table CollectionDB.ows_AdditionalParameter ( |
---|
| 189 | id serial primary key, |
---|
| 190 | key varchar, |
---|
| 191 | value varchar, |
---|
| 192 | additional_parameters_id int references CollectionDB.ows_AdditionalParameters(id) |
---|
| 193 | ); |
---|
| 194 | |
---|
| 195 | create table CollectionDB.ows_Input ( |
---|
| 196 | id int primary key default nextval('collectiondb.descriptions_id_seq'::regclass), |
---|
| 197 | title text, |
---|
| 198 | abstract text, |
---|
| 199 | identifier varchar(255), |
---|
| 200 | min_occurs int, |
---|
| 201 | max_occurs int |
---|
| 202 | ); -- inherits (CollectionDB.Descriptions); |
---|
| 203 | alter table CollectionDB.ows_Input add constraint codb_input_id unique (id); |
---|
| 204 | CREATE TRIGGER ows_Input_proc AFTER INSERT ON CollectionDB.ows_Input FOR EACH ROW EXECUTE PROCEDURE update_Description(); |
---|
| 205 | |
---|
| 206 | create table CollectionDB.ows_Output ( |
---|
| 207 | id int primary key default nextval('collectiondb.descriptions_id_seq'::regclass), |
---|
| 208 | title text, |
---|
| 209 | abstract text, |
---|
| 210 | identifier varchar(255) |
---|
| 211 | ); --inherits (CollectionDB.Descriptions); |
---|
| 212 | alter table CollectionDB.ows_Output add constraint codb_output_id unique (id); |
---|
| 213 | CREATE TRIGGER ows_Output_proc AFTER INSERT ON CollectionDB.ows_Output FOR EACH ROW EXECUTE PROCEDURE update_Description(); |
---|
| 214 | |
---|
| 215 | create table CollectionDB.zoo_PrivateMetadata ( |
---|
| 216 | id serial primary key, |
---|
| 217 | identifier varchar, |
---|
| 218 | metadata_date timestamp |
---|
| 219 | ); |
---|
| 220 | |
---|
| 221 | create table CollectionDB.ows_Process ( |
---|
| 222 | id int primary key default nextval('collectiondb.descriptions_id_seq'::regclass), |
---|
| 223 | title text, |
---|
| 224 | abstract text, |
---|
| 225 | identifier varchar(255), |
---|
| 226 | availability boolean, |
---|
| 227 | process_description_xml text, |
---|
| 228 | private_metadata_id int references CollectionDB.zoo_PrivateMetadata(id) |
---|
| 229 | ); -- inherits (CollectionDB.Descriptions); |
---|
| 230 | alter table CollectionDB.ows_Process add constraint codb_process_id unique (id); |
---|
| 231 | alter table CollectionDB.ows_Process add constraint codb_process_identifier unique (identifier); |
---|
| 232 | CREATE TRIGGER ows_Process_proc AFTER INSERT ON CollectionDB.ows_Process FOR EACH ROW EXECUTE PROCEDURE update_Description(); |
---|
| 233 | |
---|
| 234 | create table CollectionDB.InputInputAssignment ( |
---|
| 235 | id serial primary key, |
---|
| 236 | parent_input int references CollectionDB.ows_Input(id), |
---|
| 237 | child_input int references CollectionDB.ows_Input(id) |
---|
| 238 | ); |
---|
| 239 | |
---|
| 240 | create table CollectionDB.InputDataDescriptionAssignment ( |
---|
| 241 | id serial primary key, |
---|
| 242 | input_id int references CollectionDB.ows_Input(id), |
---|
| 243 | data_description_id int check (CollectionDB.is_in_ows_DataDescription(data_description_id)) |
---|
| 244 | ); |
---|
| 245 | |
---|
| 246 | create table CollectionDB.OutputOutputAssignment ( |
---|
| 247 | id serial primary key, |
---|
| 248 | parent_output int references CollectionDB.ows_Output(id), |
---|
| 249 | child_output int references CollectionDB.ows_Output(id) |
---|
| 250 | ); |
---|
| 251 | |
---|
| 252 | create table CollectionDB.OutputDataDescriptionAssignment ( |
---|
| 253 | id serial primary key, |
---|
| 254 | output_id int references CollectionDB.ows_Output(id), |
---|
| 255 | data_description_id int check (CollectionDB.is_in_ows_DataDescription(data_description_id)) |
---|
| 256 | ); |
---|
| 257 | |
---|
| 258 | create table CollectionDB.zoo_ServiceTypes ( |
---|
| 259 | id serial primary key, |
---|
| 260 | service_type varchar |
---|
| 261 | ); |
---|
| 262 | insert into CollectionDB.zoo_ServiceTypes (service_type) VALUES ('HPC'); |
---|
| 263 | insert into CollectionDB.zoo_ServiceTypes (service_type) VALUES ('C'); |
---|
| 264 | insert into CollectionDB.zoo_ServiceTypes (service_type) VALUES ('Java'); |
---|
| 265 | insert into CollectionDB.zoo_ServiceTypes (service_type) VALUES ('Mono'); |
---|
| 266 | insert into CollectionDB.zoo_ServiceTypes (service_type) VALUES ('JS'); |
---|
| 267 | insert into CollectionDB.zoo_ServiceTypes (service_type) VALUES ('PHP'); |
---|
| 268 | insert into CollectionDB.zoo_ServiceTypes (service_type) VALUES ('Python'); |
---|
| 269 | |
---|
| 270 | insert into CollectionDB.zoo_ServiceTypes (service_type) VALUES ('OTB'); |
---|
| 271 | |
---|
| 272 | create table CollectionDB.zoo_DeploymentMetadata ( |
---|
| 273 | id serial primary key, |
---|
| 274 | executable_name varchar, |
---|
| 275 | configuration_identifier varchar, |
---|
| 276 | service_type_id int references CollectionDB.zoo_ServiceTypes(id) |
---|
| 277 | ); |
---|
| 278 | |
---|
| 279 | create table CollectionDB.zoo_PrivateProcessInfo ( |
---|
| 280 | id serial primary key |
---|
| 281 | ); |
---|
| 282 | |
---|
| 283 | create table CollectionDB.PrivateMetadataDeploymentMetadataAssignment ( |
---|
| 284 | id serial primary key, |
---|
| 285 | private_metadata_id int references CollectionDB.zoo_PrivateMetadata(id), |
---|
| 286 | deployment_metadata_id int references CollectionDB.zoo_DeploymentMetadata(id) |
---|
| 287 | ); |
---|
| 288 | |
---|
| 289 | create table CollectionDB.PrivateMetadataPrivateProcessInfoAssignment ( |
---|
| 290 | id serial primary key, |
---|
| 291 | private_metadata_id int references CollectionDB.zoo_PrivateMetadata(id), |
---|
| 292 | private_process_info_id int references CollectionDB.zoo_PrivateProcessInfo(id) |
---|
| 293 | ); |
---|
| 294 | |
---|
| 295 | create table CollectionDB.ProcessInputAssignment ( |
---|
| 296 | id serial primary key, |
---|
| 297 | process_id int references CollectionDB.ows_Process(id), |
---|
| 298 | input_id int references CollectionDB.ows_Input(id), |
---|
| 299 | index int |
---|
| 300 | ); |
---|
| 301 | |
---|
| 302 | create table CollectionDB.ProcessOutputAssignment ( |
---|
| 303 | id serial primary key, |
---|
| 304 | process_id int references CollectionDB.ows_Process(id), |
---|
| 305 | output_id int references CollectionDB.ows_Output(id), |
---|
| 306 | index int |
---|
| 307 | ); |
---|
| 308 | |
---|
| 309 | CREATE OR REPLACE VIEW public.ows_process AS |
---|
| 310 | (SELECT |
---|
| 311 | id, |
---|
| 312 | identifier, |
---|
| 313 | title, |
---|
| 314 | abstract, |
---|
| 315 | (SELECT service_type FROM CollectionDB.zoo_ServiceTypes WHERE id = (SELECT service_type_id FROM CollectionDB.zoo_DeploymentMetadata WHERE id = (SELECT deployment_metadata_id FROM CollectionDB.PrivateMetadataDeploymentmetadataAssignment WHERE private_metadata_id=(SELECT id FROM CollectionDB.zoo_PrivateMetadata WHERE id = CollectionDB.ows_Process.private_metadata_id)))) as service_type, |
---|
[854] | 316 | (SELECT executable_name as service_provider FROM CollectionDB.zoo_DeploymentMetadata WHERE id = (SELECT deployment_metadata_id FROM CollectionDB.PrivateMetadataDeploymentmetadataAssignment WHERE private_metadata_id=(SELECT id FROM CollectionDB.zoo_PrivateMetadata WHERE id = CollectionDB.ows_Process.private_metadata_id))) as service_provider, |
---|
[839] | 317 | availability |
---|
| 318 | FROM CollectionDB.ows_Process |
---|
| 319 | WHERE |
---|
| 320 | availability |
---|
| 321 | ); |
---|