Compare commits

...

233 Commits

Author SHA1 Message Date
Luca Frosini dc8595d13e Fixed serialization of unknown properties 2024-04-19 12:11:27 +02:00
Luca Frosini 8ac4511bde Fixed property name 2024-04-16 14:54:41 +02:00
Luca Frosini 0559bc031f Added additional properties names 2024-01-25 17:17:51 +01:00
Luca Frosini 6eecea2ab1 Allowing extra properties in Context 2024-01-24 17:19:15 +01:00
Luca Frosini c68826637c Fixed list of allowed properties starting with _ or @ 2024-01-24 17:18:46 +01:00
luca.frosini acf51f9dfb Added property types group 2023-11-06 17:30:52 +01:00
luca.frosini ef74dd31ea Added expiring time to TypesKnowledge 2023-10-31 15:50:16 +01:00
luca.frosini 118e058c90 Fixed bug 2023-10-30 16:48:51 +01:00
luca.frosini 6dc26a43b8 Fixed variable initialization 2023-10-30 15:55:17 +01:00
luca.frosini 8b7aa5660a Improved solution 2023-10-27 18:11:58 +02:00
luca.frosini 27854806df Fixed changelog 2023-10-27 14:51:30 +02:00
luca.frosini b05f0c51f3 Improved knowledge and tree solution 2023-10-27 14:50:16 +02:00
luca.frosini 6db5256e70 Improved solution 2023-10-26 18:11:50 +02:00
luca.frosini b3cb92f55a Improving class 2023-10-26 17:59:10 +02:00
luca.frosini 58b688a9ad Added missing authorship 2023-10-26 17:28:35 +02:00
luca.frosini 590be162b8 Refactoring packages 2023-10-26 17:26:24 +02:00
luca.frosini 185030acc2 Reorganizing packages 2023-10-26 17:22:53 +02:00
luca.frosini 58e5e70db6 Reorganized packages 2023-10-26 17:19:01 +02:00
luca.frosini 9a32f3c534 Improved code 2023-10-26 16:35:03 +02:00
luca.frosini d2b715a318 Fixed method visibility 2023-10-26 15:41:01 +02:00
luca.frosini ff0c6aec9d Improved solution 2023-10-26 15:31:08 +02:00
luca.frosini d1d9ae4a4a Improved solution 2023-10-26 15:25:07 +02:00
luca.frosini e403b2459c Creating model knowledge 2023-10-25 18:01:11 +02:00
luca.frosini 3895abdac3 Improving support for model knowledge 2023-10-24 15:18:48 +02:00
luca.frosini f4761c0a6f Removed -SNAPSHOT for release 2023-07-21 14:21:46 +02:00
luca.frosini 8594d113e0 Added ignore 2023-06-21 16:29:17 +02:00
luca.frosini 01a185894c Ignored MacOs File 2023-06-21 11:40:23 +02:00
Luca Frosini 1368f707c8 Improved unmarshalling in ElementMapper 2023-05-17 18:12:34 +02:00
Luca Frosini f9137ffff9 Fixed UUID Utility 2023-05-16 16:43:56 +02:00
Luca Frosini c36d76c19c Fixed unmarshaller 2023-05-15 12:25:30 +02:00
Luca Frosini c48eae1355 Improved IS Model Organization 2023-05-12 17:47:58 +02:00
Luca Frosini 05787952be Improved documentation with cross reference 2023-05-12 15:00:41 +02:00
Luca Frosini e6311a4f30 Added constant 2023-05-10 17:29:54 +02:00
Luca Frosini 644dc86b66 id as been moved after type 2023-05-05 13:16:53 +02:00
Luca Frosini c222b74d44 Added json serilization directive 2023-05-05 11:01:48 +02:00
Luca Frosini 2b1f3fa9a3 Added properties order 2023-05-04 18:12:19 +02:00
Luca Frosini ccb259432f Added id as first member in serialization 2023-05-04 18:08:30 +02:00
Luca Frosini 5180428d24 Fixed changelog 2023-05-03 17:30:49 +02:00
Luca Frosini a511ae8209 Updated documentation via doc generator 2023-05-02 18:05:24 +02:00
Luca Frosini eb35bf947f Fixed changelog 2023-04-28 17:55:20 +02:00
Luca Frosini 409bf29cd4 Unknown subtypes deserializiation decoupled from jackson version 2023-04-28 17:49:43 +02:00
Luca Frosini 4b06b1b6bc Added expectedtype property to keep track of original type 2023-04-28 17:16:31 +02:00
Luca Frosini 21407336bb Fixed supertypes inclusion rule from NON_NULL to NON_EMPTY 2023-04-28 15:18:52 +02:00
Luca Frosini 12280dc9fd Remove unused import 2023-04-28 14:54:28 +02:00
Luca Frosini b403ce9f85 Fixing property order 2023-04-28 14:41:03 +02:00
Luca Frosini 4333855ebc Reorganizing property order 2023-04-28 14:34:29 +02:00
Luca Frosini 86f015cb21 uuid property has been renamed to id 2023-04-28 11:33:29 +02:00
Luca Frosini a79ed8fd56 Ordering Json Properties 2023-04-27 16:30:10 +02:00
Luca Frosini ad6018d5fb Reorganizing json 2023-04-27 14:46:08 +02:00
Luca Frosini 10563e6b02 Added useful comment 2023-04-27 11:17:08 +02:00
Luca Frosini 817c875b86 Changed superclasses in typeSuperTypes 2023-04-27 11:14:35 +02:00
Luca Frosini 3511b7d248 Added missing JsonIgnore annotation 2023-04-27 10:59:20 +02:00
Luca Frosini b26681665e added getTypeName() function in Element 2023-04-27 10:50:37 +02:00
Luca Frosini a5f2953fe7 Changed CLASS and SUPERCLASSES constant names 2023-04-27 10:40:36 +02:00
Luca Frosini 49c04191db Changed '@class' to 'type' 2023-04-26 21:39:57 +02:00
Luca Frosini 4562d463e8 Fixed changelog 2023-04-26 10:56:16 +02:00
Luca Frosini 941b47eb14 Fixed method 2023-04-21 17:01:22 +02:00
Luca Frosini 010e62f4fa Reorganized utilities and their usage 2023-04-21 15:56:44 +02:00
Luca Frosini 4b18898fd0 Redesigning E/R instance definition 2023-04-20 16:59:02 +02:00
Luca Frosini c7f6431d4c Redesigning E/R instance definition 2023-04-20 13:22:57 +02:00
Luca Frosini d170e1707d Redesigning E/R instance definition 2023-04-20 12:08:45 +02:00
Luca Frosini 60ef7ae655 Redesigning E/R instance definition 2023-04-20 11:16:26 +02:00
Luca Frosini a977dc0faf Redesigning E/R instance definition 2023-04-20 11:09:22 +02:00
Luca Frosini cba11607d0 Redesigning E/R instance definition 2023-04-20 10:27:01 +02:00
Luca Frosini 3c3788f930 Improved UUID manager 2023-04-20 10:00:46 +02:00
Luca Frosini 746748494a Redesigning E/R instance definition 2023-04-19 16:38:40 +02:00
Luca Frosini 66af46bc5d fixed doc 2023-04-19 11:37:37 +02:00
Luca Frosini ec9e319792 Redesigning E/R instance definition 2023-04-18 17:51:23 +02:00
Luca Frosini 85f75fff2a Removed -SNAPSHOT to release the component 2023-03-03 11:42:39 +01:00
Luca Frosini c8329223c1 Fixed changelog 2023-02-27 15:13:39 +01:00
Luca Frosini ddf5199d8c Removed Encrypted Property and added Vault 2023-02-27 15:07:41 +01:00
Luca Frosini d591e9a89d Removed unneeded warning 2023-02-22 10:26:39 +01:00
Luca Frosini c558dd197d Commented version 2023-02-10 17:19:47 +01:00
Luca Frosini 40a41fef73 updated documentation 2023-02-10 17:05:16 +01:00
Luca Frosini 5278282866 Added check to declared version and changelog versions 2023-02-10 17:03:50 +01:00
Luca Frosini e5ccf89c0c Removed old already commented constants 2023-02-10 16:56:24 +01:00
Luca Frosini fd4de16328 Fixed version 2023-02-10 16:40:09 +01:00
Luca Frosini 26b4ec420c Added change in PropagationConstraint type 2023-02-10 16:31:22 +01:00
Luca Frosini fecf5e94e3 improving code 2023-02-10 12:12:24 +01:00
Luca Frosini a7838e5bbe suppressed warning 2023-02-09 16:57:46 +01:00
Luca Frosini 2fb5af7c94 Suppressed warning 2023-02-09 16:57:20 +01:00
Luca Frosini e5ee5b7268 Fixed changelog 2023-02-09 16:56:43 +01:00
Luca Frosini 54edc72147 Upgraded ContextTest 2023-02-09 16:44:54 +01:00
Luca Frosini 7b66a22a6f Fixed dependecy scope 2023-02-09 15:42:53 +01:00
Luca Frosini ede4d6ae72 Enhanced gcube-bom version 2023-02-09 12:13:43 +01:00
Luca Frosini b8197182ae Migrated tests to authorization-utils 2023-02-09 11:56:40 +01:00
Luca Frosini 6dbf0838c6 Enhanced major version 2023-02-09 10:29:38 +01:00
Luca Frosini 6fd730edb1 Added model validation on request 2023-02-08 18:21:03 +01:00
Luca Frosini 57f38b273f Renamed class 2023-02-08 18:07:24 +01:00
Luca Frosini e0ac0ef65b Added model knowledge analyser 2023-02-08 18:06:19 +01:00
Luca Frosini b093e25ecf Improved knowledge creation 2023-02-08 17:56:13 +01:00
Luca Frosini 09d6c5dedc Improved class functionality 2023-02-08 16:58:12 +01:00
Luca Frosini 155c684ba8 Fixed names 2023-02-07 17:05:50 +01:00
Luca Frosini 80f2aba06d Improved code 2023-02-07 15:45:02 +01:00
Luca Frosini 5321570886 Improving ModelKnowledge creation 2023-02-07 15:15:22 +01:00
Luca Frosini d7d609bbf8 Reorganized discovery and usage knowledge 2023-02-07 14:06:39 +01:00
Luca Frosini 7a68609de3 Fixed test 2023-02-06 18:57:55 +01:00
Luca Frosini 417647922c Fixing logback 2023-02-06 18:53:01 +01:00
Luca Frosini ba30725032 Fixing code 2023-02-06 18:52:08 +01:00
Luca Frosini affa4a4f7b Renamed class 2023-02-06 18:16:16 +01:00
Luca Frosini 982cce370c Refactoring 2023-02-06 18:03:47 +01:00
Luca Frosini 484690555a Refactoring 2023-02-06 17:43:51 +01:00
Luca Frosini 446adc09a1 Removed old classes 2023-02-06 17:36:53 +01:00
Luca Frosini 833a69d8d5 Reorganizng code 2023-02-06 17:04:25 +01:00
Luca Frosini 879cf9b81f Refactoring 2023-02-06 16:35:30 +01:00
Luca Frosini c7985f7aad Reoganinizing library 2023-02-06 14:15:01 +01:00
Luca Frosini 7a3a98549f Renamed classes 2023-02-06 11:07:52 +01:00
Luca Frosini a346762e59 fixed error 2023-02-03 19:13:47 +01:00
Luca Frosini a7d98b821d Implementing knowledge 2023-02-03 19:13:04 +01:00
Luca Frosini a1573b5238 Generalising Tree 2023-02-03 17:53:42 +01:00
Luca Frosini 019dabf8a8 Fixed function name 2023-02-03 15:57:31 +01:00
Luca Frosini 6fcead807d Refactoring 2023-02-03 14:51:25 +01:00
Luca Frosini 7a0a262cdb Reorganizing classes 2023-02-03 14:45:15 +01:00
Luca Frosini 5e607461f1 Renaming objects 2023-02-03 14:44:42 +01:00
Luca Frosini 1f6d21b9a0 Reorganizing packages of IS Model 2023-02-03 14:39:25 +01:00
Luca Frosini e5329b1627 Fixed chagenlog 2023-02-02 21:07:47 +01:00
Luca Frosini af4de28ebb Added remove in propagation constraint 2023-02-02 19:34:47 +01:00
Luca Frosini 7307eefeab fixed method visibility 2023-02-02 16:38:15 +01:00
Luca Frosini 7129eee9f1 Added classes to manages tree types 2023-02-02 15:39:02 +01:00
Luca Frosini 0983c65505 Improving documentation 2023-01-26 18:51:22 +01:00
Luca Frosini 5497bfaf6e Adding sphinx documentation 2023-01-26 18:28:54 +01:00
Luca Frosini 93d00bd4f0 Fixed doc 2023-01-26 17:48:56 +01:00
Luca Frosini 151d99cfe9 Integrating Sphinx 2023-01-26 13:51:51 +01:00
Luca Frosini 6f3399278b Added rst doc 2023-01-25 23:28:10 +01:00
Luca Frosini 8035828d49 Fixed bug in compareTo 2023-01-24 19:52:34 +01:00
Luca Frosini ce0ddaedd6 Added @Final annotation to interfaces and final modifier to classes 2023-01-24 19:52:18 +01:00
Luca Frosini 39df1b24cd Added class Discovery to make new model discovery easier 2023-01-24 19:25:45 +01:00
Luca Frosini 1fdadfb170 Added the possibility to exclude is model package 2023-01-24 19:23:02 +01:00
Luca Frosini b36310c650 Fixed compareTo 2023-01-24 17:21:09 +01:00
Luca Frosini 71ad29c9ce Added missing toString method 2023-01-23 15:33:33 +01:00
Luca Frosini de1bb75c56 LinkedEntity is now comparable 2023-01-20 17:49:19 +01:00
Luca Frosini c0c36bdf9c Improved code 2023-01-20 16:46:22 +01:00
Luca Frosini 8771c62ed1 Improved descriptions to produce a better documentation 2023-01-20 11:22:52 +01:00
Luca Frosini c4bb0ffcf3 Added useful method 2023-01-19 12:00:15 +01:00
Luca Frosini 86b4e14de4 Documentation generator has been moved in a dedicated component 2022-12-13 10:29:15 +01:00
Luca Frosini b5e7f8e685 Implementing documentation generator 2022-12-12 10:24:05 +01:00
Luca Frosini 45d5a3a131 Adding documenation generation 2022-12-10 18:00:52 +01:00
Luca Frosini 401745d7dc Added classes to generate rst tables for documentation 2022-12-10 16:21:37 +01:00
Luca Frosini 87afd8e5a2 Removed -SNAPSHOT to release the component 2022-10-19 12:18:54 +02:00
Luca Frosini 949f2fde36 Fixed changelog 2022-07-20 16:21:34 +02:00
Luca Frosini 2eb8bbb0b9 Added date serialization specification 2022-06-13 10:21:21 +02:00
Luca Frosini 7f964ad5d2 Fixing JSON serialization 2022-02-01 16:48:11 +01:00
Luca Frosini b95f923636 Fixed CHANGELOG 2021-10-28 11:16:39 +02:00
Luca Frosini 32cb6ac3ba Added test for QueryTemplate 2021-10-26 21:33:30 +02:00
Luca Frosini 1d93d60bdf Added functionality to instantiate query from template using default
values or provided values
2021-10-26 20:49:03 +02:00
Luca Frosini 05b06ce6fa Fixed QueryTemplate model 2021-10-25 18:12:04 +02:00
Luca Frosini 28d1218876 moved operators back to the resource-registry 2021-10-25 12:12:53 +02:00
Luca Frosini dd3b48a40b Moved query operators (logical and condtional) from resource-registry 2021-10-25 11:41:50 +02:00
Luca Frosini d5dacac45f Renamed package to be aligned with all the rest of IS components 2021-10-25 11:38:06 +02:00
Luca Frosini 4e97771a16 Aligned package names 2021-10-25 10:58:30 +02:00
Luca Frosini beb54469fb Using UUIDManager to generate a random UUID 2021-10-22 20:09:27 +02:00
Luca Frosini 83d14611c7 Removed version and changelog. It seems not needed 2021-10-22 10:16:05 +02:00
Luca Frosini 92c986ad27 Reorganized packages 2021-10-21 17:24:53 +02:00
Luca Frosini 11b218fdec Improved UUID management 2021-10-21 16:29:35 +02:00
Luca Frosini 42a650167b Removed wrong Abstract annotation and fixed property names 2021-10-21 16:01:38 +02:00
Luca Frosini f2fbfc7b66 Added Reserved UUID class 2021-10-21 16:00:58 +02:00
Luca Frosini 7f5512571c Reorganizing Information System Model 2021-10-21 12:47:50 +02:00
Luca Frosini c0b5908960 Fixing types 2021-10-21 11:56:01 +02:00
Luca Frosini 66fead0851 Renamed TypeVersion class to Version 2021-10-21 10:11:45 +02:00
Luca Frosini 05b6b65fee Improving classes to support query templates 2021-10-20 19:55:13 +02:00
Luca Frosini 833b2f5805 Adding types to support query templates 2021-10-20 19:16:48 +02:00
Luca Frosini 18b9124e86 Adding Query Templates 2021-10-20 18:39:53 +02:00
Luca Frosini b454e52e67 Added Direction enum 2021-10-20 15:23:25 +02:00
Luca Frosini 633ff9c3ab Fixed generic type name 2021-07-05 15:43:07 +02:00
Luca Frosini cabedceeb3 Aligned distro files with new specification 2021-06-29 18:19:02 +02:00
Luca Frosini 4124291551 Ignoring property in json serialization useful for java classes only 2021-06-29 17:34:54 +02:00
Luca Frosini 9217daea21 Enhanced major in version 2021-06-29 14:56:39 +02:00
Luca Frosini 0dbff9a834 Fixed test 2021-06-23 10:50:12 +02:00
Luca Frosini cf2dfd4b10 Aligned Header properties name 2021-03-08 11:18:24 +01:00
Luca Frosini cf0aa2c3f6 Merge branch 'feature/20306' of gitea@code-repo.d4science.org:gCubeSystem/information-system-model.git into feature/20306 2021-03-02 17:15:39 +01:00
Luca Frosini 64c91978fe Fixed wiki link in doc 2021-03-02 16:16:04 +01:00
Luca Frosini 5828ed0e2d Fixed javadoc 2021-02-28 21:13:36 +01:00
Luca Frosini 9503d52737 Moved a link a in a comment from http to https refs #20782 2021-02-22 09:44:04 +01:00
Luca Frosini 65eb4d6777 Fixed logback.xml for tests 2021-02-19 17:38:12 +01:00
Luca Frosini f8503e359d Added useful methods 2021-02-18 18:22:11 +01:00
Luca Frosini f18743308b Improved Resource definition 2021-02-18 15:14:24 +01:00
Luca Frosini 6ddcd7c7fd Fixed umarshalling 2021-02-17 16:14:22 +01:00
Luca Frosini 16d9735851 Fixed AccessType 2021-02-12 12:08:30 +01:00
Luca Frosini 8bb0e6aa5d Reorganising AccessType hierarchically 2021-02-12 11:46:45 +01:00
Luca Frosini 384be462bb Fixed AccessType from type definition. Added Assertion on tests 2021-02-11 22:09:02 +01:00
Luca Frosini 62752a369d Improved test readability 2021-02-11 21:01:24 +01:00
Luca Frosini f5b6885b8c Removed uneeded tests 2021-02-11 20:53:59 +01:00
Luca Frosini d23ca0e246 Fixed corner case 2021-02-11 17:37:42 +01:00
Luca Frosini fec18df298 Fixed CHANGELOG 2021-02-11 17:31:59 +01:00
Luca Frosini ece3fd1245 Fixed CHANGELOG 2021-02-11 17:26:22 +01:00
Luca Frosini 60e9de983a Fixed unmarshalling in case of unknown types 2021-02-11 17:24:46 +01:00
Luca Frosini 44056157e1 Added the possibility to get the AccessType from Type definition 2021-02-11 17:24:22 +01:00
Luca Frosini 603e8f2cf7 Renamed convenient interface 2021-02-05 11:32:37 +01:00
Luca Frosini 2cac6ddc63 Added convenient interface to identify Entity and Relation 2021-02-05 11:30:47 +01:00
Luca Frosini 15d8dce3e3 Fixed superclasses list 2021-01-29 16:31:01 +01:00
Luca Frosini a33a0dac63 Fixed CHANGELOG 2021-01-28 23:21:15 +01:00
Luca Frosini e8bae24bd0 Fixed CHANGELOG 2021-01-28 23:18:50 +01:00
Luca Frosini 83a60d72ee Fixed typo 2021-01-28 23:16:53 +01:00
Luca Frosini 4ccc840377 Added convenient method to get type name from an instance 2021-01-28 23:15:46 +01:00
Luca Frosini a8e1b0da6e Fixed getType 2021-01-27 11:57:16 +01:00
Luca Frosini af24bde831 Fixed authorship 2021-01-20 17:26:13 +01:00
Luca Frosini c507a063c6 Added missing/Fixed authorship on classes 2021-01-20 17:03:02 +01:00
Luca Frosini d490efab78 Fixed code 2021-01-20 15:54:20 +01:00
Luca Frosini 502ba899f7 Fixed bug on property type name representation 2021-01-20 15:53:00 +01:00
Luca Frosini 72ddb4718a Fixed code readability 2021-01-20 15:15:50 +01:00
Luca Frosini d326783ef2 Added important comment 2021-01-20 12:24:41 +01:00
Luca Frosini bddc3b2556 Fixed code style 2021-01-20 10:17:23 +01:00
Luca Frosini 97105446cb Fixed property definition 2021-01-19 17:22:22 +01:00
Luca Frosini 3879c340a3 Changing the way to serialise a type of a property 2021-01-19 15:32:25 +01:00
Luca Frosini 268878d9f7 Changing the way to serialise a type of a property 2021-01-19 15:32:19 +01:00
Luca Frosini 613fc76259 Changing the way to serialise a type of a property 2021-01-19 11:21:53 +01:00
Luca Frosini df1736f39b Changing the way to serialise the type of a property 2021-01-19 09:20:52 +01:00
Luca Frosini 5fcc630820 Changing the way to serialise the type of a property 2021-01-19 09:20:21 +01:00
Luca Frosini 37074ff322 Adding BasePropertyType to remove OrientDBType 2021-01-17 22:50:50 +01:00
Luca Frosini bae57c6ea8 Fixed method name 2021-01-15 17:57:06 +01:00
Luca Frosini 8e755e02c3 Added the proper _PROPERTY suffix to propagationConstraint property name 2021-01-13 21:53:16 +01:00
Luca Frosini 2b5b897dc0 Fixed Type 2021-01-07 11:16:40 +01:00
Luca Frosini 4a7bc55991 Fixed tests 2020-12-23 15:39:58 +01:00
Luca Frosini 5dcd3bce57 Added changes in changelog 2020-12-23 14:08:22 +01:00
Luca Frosini 9d9da57029 Added change in CHANGELOG 2020-12-23 14:05:11 +01:00
Luca Frosini e6ec2574f7 Fixed CHANGELOG.md 2020-12-23 14:03:30 +01:00
Luca Frosini 346b52a1b6 Fixed types 2020-12-23 10:33:17 +01:00
Luca Frosini cb8dee2c9d Added missed documentation to types 2020-12-23 10:08:38 +01:00
Luca Frosini d0c664fc92 Added annotation to the JavaDoc 2020-12-21 16:02:03 +01:00
Luca Frosini a5fac85d9a Annotated ISProperty annotation so that is included in the Javadoc 2020-12-18 12:23:21 +01:00
Luca Frosini 82e7a03b3c Improved javadoc and types and properties description. 2020-12-18 12:06:31 +01:00
Luca Frosini 5835d8c67b Annotated types to properly create type definition 2020-12-15 17:38:06 +01:00
Luca Frosini e697ef2cf5 Using annotation to define name, description, version and chagelog for
any Element
2020-12-15 11:28:34 +01:00
Luca Frosini 0915af9dc1 fixed changelog 2020-12-14 11:14:56 +01:00
Luca Frosini 21fcb502f2 Type deserialization is compliant with old version without CHANGELOG 2020-12-14 10:10:49 +01:00
Luca Frosini 745bb9eb3e Fixed CHANGELOG retrieving 2020-12-14 09:21:14 +01:00
Luca Frosini 619dd586c1 Added type changelog 2020-12-11 17:28:56 +01:00
Luca Frosini b0b5fdf3cd Added version managed with a dedicated type in TypeDefinition 2020-12-11 13:09:02 +01:00
Luca Frosini c593c383a6 Add version information on IS type 2020-12-11 09:47:14 +01:00
Luca Frosini 7763dd4abb Removed -SNAPSHOT to release the component 2020-11-25 15:15:46 +01:00
Luca Frosini dfc73f5281 upgraded gcube-bom 2020-11-25 15:14:31 +01:00
Luca Frosini f16b30bd09 Added support to include additional properties in Property types
[#20012]
2020-11-09 15:46:01 +01:00
Luca Frosini 1d74ee7905 Fixed API 2020-11-03 16:33:48 +01:00
155 changed files with 6832 additions and 2009 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
target
.classpath
.project
/.DS_Store

View File

@ -1,3 +1,4 @@
/org.eclipse.jdt.core.prefs
/org.eclipse.core.resources.prefs
/org.eclipse.m2e.core.prefs
/org.eclipse.jdt.ui.prefs

View File

@ -2,8 +2,45 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Information System Model
## [v7.1.0-SNAPSHOT]
## [v4.0.0] [r5.0.0]
- Improved support for model knowledge [#25922]
## [v7.0.0]
- Reorganized E/R format [#24992]
- Added missing expected type field when the provided type does not have the exact class in the classpath
## [v6.0.0]
- Modified models discovery to make it easier and more powerful [#24548]
- Discovery create trees of discovered types both globally and model based [#24548]
- Added possibility to declare a type Final which means that it cannot be extended [#24554]
- Fixed default value of propagation constraint of remove action for ConsistsOf to 'cascade' [#24223]
- Added "delete" propagation constraint property [#24222]
- Removed Encrypted Property Type and added Vault instead [#24655]
## [v5.0.0]
- Added the possibility to get AccessType from Type definition [#20695]
- Solved issue on unmarshalling of unknown types using best known type looking superclasses property [#20694]
- Aligned model with the model defined in Luca Frosini PhD dissertation [#20367]
- Using annotation to document the types with name, description, version and changelog [#20306][#20315]
- Generalized the way the type of a property is defined [#20516]
- Added reserved UUID management
- Added support for context names included in header among UUIDs [#22090]
- Added support for Json Query [#22047]
- Added support for Query Templates [#22091]
## [v4.1.0] [r5.0.0] - 2020-11-25
- Added support to include additional properties in Property types [#20012]
## [v4.0.0] [r4.26.0] - 2020-10-29
- Switched JSON management to gcube-jackson [#19116]

26
FUNDING.md Normal file
View File

@ -0,0 +1,26 @@
# Acknowledgments
The projects leading to this software have received funding from a series of European Union programmes including:
- the Sixth Framework Programme for Research and Technological Development
- [DILIGENT](https://cordis.europa.eu/project/id/004260) (grant no. 004260).
- the Seventh Framework Programme for research, technological development and demonstration
- [D4Science](https://cordis.europa.eu/project/id/212488) (grant no. 212488);
- [D4Science-II](https://cordis.europa.eu/project/id/239019) (grant no.239019);
- [ENVRI](https://cordis.europa.eu/project/id/283465) (grant no. 283465);
- [iMarine](https://cordis.europa.eu/project/id/283644) (grant no. 283644);
- [EUBrazilOpenBio](https://cordis.europa.eu/project/id/288754) (grant no. 288754).
- the H2020 research and innovation programme
- [SoBigData](https://cordis.europa.eu/project/id/654024) (grant no. 654024);
- [PARTHENOS](https://cordis.europa.eu/project/id/654119) (grant no. 654119);
- [EGI-Engage](https://cordis.europa.eu/project/id/654142) (grant no. 654142);
- [ENVRI PLUS](https://cordis.europa.eu/project/id/654182) (grant no. 654182);
- [BlueBRIDGE](https://cordis.europa.eu/project/id/675680) (grant no. 675680);
- [PerformFISH](https://cordis.europa.eu/project/id/727610) (grant no. 727610);
- [AGINFRA PLUS](https://cordis.europa.eu/project/id/731001) (grant no. 731001);
- [DESIRA](https://cordis.europa.eu/project/id/818194) (grant no. 818194);
- [ARIADNEplus](https://cordis.europa.eu/project/id/823914) (grant no. 823914);
- [RISIS 2](https://cordis.europa.eu/project/id/824091) (grant no. 824091);
- [EOSC-Pillar](https://cordis.europa.eu/project/id/857650) (grant no. 857650);
- [Blue Cloud](https://cordis.europa.eu/project/id/862409) (grant no. 862409);
- [SoBigData-PlusPlus](https://cordis.europa.eu/project/id/871042) (grant no. 871042);

View File

@ -46,26 +46,4 @@ open-source software toolkit used for building and operating Hybrid Data
Infrastructures enabling the dynamic deployment of Virtual Research Environments
by favouring the realisation of reuse oriented policies.
The projects leading to this software have received funding from a series of European Union programmes including:
- the Sixth Framework Programme for Research and Technological Development
- DILIGENT (grant no. 004260).
- the Seventh Framework Programme for research, technological development and demonstration
- D4Science (grant no. 212488);
- D4Science-II (grant no.239019);
- ENVRI (grant no. 283465);
- iMarine(grant no. 283644);
- EUBrazilOpenBio (grant no. 288754).
- the H2020 research and innovation programme
- SoBigData (grant no. 654024);
- PARTHENOS (grant no. 654119);
- EGIEngage (grant no. 654142);
- ENVRIplus (grant no. 654182);
- BlueBRIDGE (grant no. 675680);
- PerformFish (grant no. 727610);
- AGINFRAplus (grant no. 731001);
- DESIRA (grant no. 818194);
- ARIADNEplus (grant no. 823914);
- RISIS2 (grant no. 824091);
The projects leading to this software have received funding from a series of European Union programmes see [FUNDING.md](FUNDING.md)

20
docs/Makefile Normal file
View File

@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

54
docs/conf.py Normal file
View File

@ -0,0 +1,54 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'Information System (IS) Model'
copyright = '2023, Luca Frosini (ISTI-CNR)'
author = 'Luca Frosini (ISTI-CNR)'
# The full version, including alpha/beta/rc tags
# release = '6.0.0'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = []
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

305
docs/index.rst Normal file
View File

@ -0,0 +1,305 @@
.. _Property:
Property
========
This is the base type for any Property
.. table:: **Property**
+------------------------------------------------------+------+------------+-------------+
| Name | Type | Attributes | Description |
+======================================================+======+============+=============+
| This type does not define any additional attributes. |
+------------------------------------------------------+------+------------+-------------+
The **Property** current version is 1.0.0.
Changelog:
* **1.0.0**: First Version.
.. _Encrypted:
Encrypted
---------
This type is used to properly manage values must be stored safely (e.g. encrypted) in the IS.
.. table:: **Encrypted** ``extends`` **Property**
+-------+--------+--------------------------------------------------------+-------------------------------------+
| Name | Type | Attributes | Description |
+=======+========+========================================================+=====================================+
| value | String | ``Mandatory:true`` ``ReadOnly:false`` ``NotNull:true`` | The value to store safely in the IS |
+-------+--------+--------------------------------------------------------+-------------------------------------+
The **Encrypted** current version is 1.0.0.
Changelog:
* **1.0.0**: First Version.
.. _Metadata:
Metadata
--------
This type provides metadata per every IdentifiableElement
.. table:: **Metadata** ``extends`` **Property**
+----------------+--------+--------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
| Name | Type | Attributes | Description |
+================+========+========================================================+=========================================================================================================================================+
| createdBy | String | ``Mandatory:true`` ``ReadOnly:true`` ``NotNull:true`` | The user that created the Entity or the Relation. It is initialized at Creation Time. |
+----------------+--------+--------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
| creationTime | Date | ``Mandatory:true`` ``ReadOnly:true`` ``NotNull:true`` | Creation time. It is represented in the format yyyy-MM-dd HH:mm:ss.SSS Z. |
+----------------+--------+--------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
| lastUpdateBy | String | ``Mandatory:true`` ``ReadOnly:false`` ``NotNull:true`` | The user that made the last update to the Entity or the Relation. At Creation Time, it assumes the same value of createdBy. |
+----------------+--------+--------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
| lastUpdateTime | Date | ``Mandatory:true`` ``ReadOnly:false`` ``NotNull:true`` | Last Update time. At creation time it assumes the same value of creationTime. It is represented in the format yyyy-MM-dd HH:mm:ss.SSS Z |
+----------------+--------+--------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
The **Metadata** current version is 1.0.0.
Changelog:
* **1.0.0**: First Version.
.. _PropagationConstraint:
PropagationConstraint
---------------------
This type provides propagation constraint for Relation
.. table:: **PropagationConstraint** ``extends`` **Property**
+--------+--------+-----------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Name | Type | Attributes | Description |
+========+========+=====================================================================================================+======================================================================================================================================================================================================================+
| add | String | ``Mandatory:true`` ``ReadOnly:false`` ``NotNull:true`` ``Regex:^(propagate|unpropagate)$`` | It indicates the behaviour to implement for the target Entity when an 'add' action is performed on the source Resource. Add action is the operation of adding an instance to a context. |
+--------+--------+-----------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| delete | String | ``Mandatory:true`` ``ReadOnly:false`` ``NotNull:true`` ``Regex:^(cascadeWhenOrphan|cascade|keep)$`` | It indicates the behaviour to implement for the target Entity when a 'delete' action is performed on the source Resource. Delet action is the operation of deleting an instance (it has an impact on all contexts). |
+--------+--------+-----------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| remove | String | ``Mandatory:true`` ``ReadOnly:false`` ``NotNull:true`` ``Regex:^(cascadeWhenOrphan|cascade|keep)$`` | It indicates the behaviour to implement for the target Entity when a 'remove' action is performed on the source Resource. Remove actions is the operation of removing an instance from a context. |
+--------+--------+-----------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
The **PropagationConstraint** current version is 1.1.0.
Changelog:
* **1.1.0**: Added 'delete' propagation constraint;
* **1.0.0**: First Version;
.. _Entity:
Entity
======
This is the base type for any Entity
.. table:: **Entity**
+------------+----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
| Properties |
+============+============================+====================================================================================================================================================+============================================================================================+
| **Name** | **Type** | **Attributes** | **Description** |
+------------+----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
| id | String | ``Mandatory:true`` ``ReadOnly:true`` ``NotNull:true`` ``Regex:^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$`` | This UUID is be used to identify the instance univocally. |
+------------+----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
| metadata | :ref:`Metadata <Metadata>` | ``Mandatory:true`` ``ReadOnly:false`` ``NotNull:true`` | Metadata associated with the instance that is automatically created/updated by the system. |
+------------+----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------+
The **Entity** current version is 1.0.0.
Changelog:
* **1.0.0**: First Version.
.. _Resource:
Resource
--------
This is the base type for any Resource
.. table:: **Resource** ``extends`` **Entity**
+-------------------------------------------------------+----------+--------------+--------+-------------+
| Source | Relation | Multiplicity | Target | Description |
+=======================================================+==========+==============+========+=============+
| **Facets** |
+-------------------------------------------------------+----------+--------------+--------+-------------+
| No specific facets usage defined for this type. |
+-------------------------------------------------------+----------+--------------+--------+-------------+
| **Resource Relations** |
+-------------------------------------------------------+----------+--------------+--------+-------------+
| No specific Resource relations defined for this type. |
+-------------------------------------------------------+----------+--------------+--------+-------------+
The **Resource** current version is 1.0.0.
Changelog:
* **1.0.0**: First Version.
.. _Facet:
Facet
-----
This is the base type for any Facet
.. table:: **Facet** ``extends`` **Entity**
+------------------------------------------------------+--------------+------------------+-----------------+-----------------+
| Properties |
+======================================================+==============+==================+=================+=================+
| **Name** | **Type** | **Attributes** | **Description** |
+------------------------------------------------------+--------------+------------------+-----------------+-----------------+
| This type does not define any additional attributes. |
+------------------------------------------------------+--------------+------------------+-----------------+-----------------+
| **Known Usage** |
+------------------------------------------------------+--------------+------------------+-----------------+-----------------+
| **Source** | **Relation** | **Multiplicity** | **Target** | **Description** |
+------------------------------------------------------+--------------+------------------+-----------------+-----------------+
| No specific known usage for this type. |
+------------------------------------------------------+--------------+------------------+-----------------+-----------------+
The **Facet** current version is 1.0.0.
Changelog:
* **1.0.0**: First Version.
.. _Relation:
Relation
========
This is the base type for any Relation
.. table:: **Relation**
+----------------------------+------------------------------------------------------+----------------------------------------------------------+------------------------+----------------------------------------+
| **Definition** |
+============================+======================================================+==========================================================+========================+========================================+
| **Source** | **Relation** | **Multiplicity** | **Target** | **Description** |
+----------------------------+------------------------------------------------------+----------------------------------------------------------+------------------------+----------------------------------------+
| :ref:`Resource <Resource>` | :ref:`Relation <Relation>` | 0..n | :ref:`Entity <Entity>` | This is the base type for any Relation |
+----------------------------+------------------------------------------------------+----------------------------------------------------------+------------------------+----------------------------------------+
| **Properties** |
+----------------------------+------------------------------------------------------+----------------------------------------------------------+------------------------+----------------------------------------+
| **Name** | **Type** | **Attributes** | **Description** |
+----------------------------+------------------------------------------------------+----------------------------------------------------------+------------------------+----------------------------------------+
| propagationConstraint | :ref:`PropagationConstraint <PropagationConstraint>` | ``Mandatory:false`` ``ReadOnly:false`` ``NotNull:false`` | |
+----------------------------+------------------------------------------------------+----------------------------------------------------------+------------------------+----------------------------------------+
The **Relation** current version is 1.0.0.
Changelog:
* **1.0.0**: First Version.
.. _IsRelatedTo:
IsRelatedTo
-----------
This is the base type for any IsRelatedTo relation
.. table:: **IsRelatedTo** ``extends`` **Relation**
+------------------------------------------------------+----------------------------------+------------------+----------------------------+----------------------------------------------------+
| **Definition** |
+======================================================+==================================+==================+============================+====================================================+
| **Source** | **Relation** | **Multiplicity** | **Target** | **Description** |
+------------------------------------------------------+----------------------------------+------------------+----------------------------+----------------------------------------------------+
| :ref:`Resource <Resource>` | :ref:`IsRelatedTo <IsRelatedTo>` | 0..n | :ref:`Resource <Resource>` | This is the base type for any IsRelatedTo relation |
+------------------------------------------------------+----------------------------------+------------------+----------------------------+----------------------------------------------------+
| **Properties** |
+------------------------------------------------------+----------------------------------+------------------+----------------------------+----------------------------------------------------+
| **Name** | **Type** | **Attributes** | **Description** |
+------------------------------------------------------+----------------------------------+------------------+----------------------------+----------------------------------------------------+
| This type does not define any additional attributes. |
+------------------------------------------------------+----------------------------------+------------------+----------------------------+----------------------------------------------------+
| **Known Usage** |
+------------------------------------------------------+----------------------------------+------------------+----------------------------+----------------------------------------------------+
| **Source** | **Relation** | **Multiplicity** | **Target** | **Description** |
+------------------------------------------------------+----------------------------------+------------------+----------------------------+----------------------------------------------------+
| No specific known usage for this type. |
+------------------------------------------------------+----------------------------------+------------------+----------------------------+----------------------------------------------------+
The **IsRelatedTo** current version is 1.0.0.
Changelog:
* **1.0.0**: First Version.
.. _ConsistsOf:
ConsistsOf
----------
This is the base type for any ConsistsOf relation
.. table:: **ConsistsOf** ``extends`` **Relation**
+------------------------------------------------------+--------------------------------+------------------+----------------------+---------------------------------------------------+
| **Definition** |
+======================================================+================================+==================+======================+===================================================+
| **Source** | **Relation** | **Multiplicity** | **Target** | **Description** |
+------------------------------------------------------+--------------------------------+------------------+----------------------+---------------------------------------------------+
| :ref:`Resource <Resource>` | :ref:`ConsistsOf <ConsistsOf>` | 0..n | :ref:`Facet <Facet>` | This is the base type for any ConsistsOf relation |
+------------------------------------------------------+--------------------------------+------------------+----------------------+---------------------------------------------------+
| **Properties** |
+------------------------------------------------------+--------------------------------+------------------+----------------------+---------------------------------------------------+
| **Name** | **Type** | **Attributes** | **Description** |
+------------------------------------------------------+--------------------------------+------------------+----------------------+---------------------------------------------------+
| This type does not define any additional attributes. |
+------------------------------------------------------+--------------------------------+------------------+----------------------+---------------------------------------------------+
| **Known Usage** |
+------------------------------------------------------+--------------------------------+------------------+----------------------+---------------------------------------------------+
| **Source** | **Relation** | **Multiplicity** | **Target** | **Description** |
+------------------------------------------------------+--------------------------------+------------------+----------------------+---------------------------------------------------+
| No specific known usage for this type. |
+------------------------------------------------------+--------------------------------+------------------+----------------------+---------------------------------------------------+
The **ConsistsOf** current version is 1.0.0.
Changelog:
* **1.0.0**: First Version.

BIN
docs/is-model-er.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
docs/is-model.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

35
docs/make.bat Normal file
View File

@ -0,0 +1,35 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd

47
pom.xml
View File

@ -10,7 +10,7 @@
<groupId>org.gcube.information-system</groupId>
<artifactId>information-system-model</artifactId>
<version>4.0.0</version>
<version>7.1.0-SNAPSHOT</version>
<name>Information System Model</name>
<description>Information System Model is the reference model of the gCube Information System</description>
<packaging>jar</packaging>
@ -31,7 +31,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>2.0.0</version>
<version>2.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -51,10 +51,6 @@
<groupId>org.gcube.common</groupId>
<artifactId>gcube-jackson-core</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@ -63,13 +59,15 @@
<!-- Test Dependencies -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<artifactId>authorization-utils</artifactId>
<version>[2.2.0, 3.0.0-SNAPSHOT)</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
@ -83,4 +81,29 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Sphinx plugin' -->
<plugin>
<groupId>kr.motd.maven</groupId>
<artifactId>sphinx-maven-plugin</artifactId>
<version>2.10.0</version>
<configuration>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/docs</outputDirectory>
<builder>html</builder>
<configDirectory>${basedir}/docs</configDirectory>
<sourceDirectory>${basedir}/docs</sourceDirectory>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -7,7 +7,8 @@ import java.io.StringWriter;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.utils.TypeUtility;
/**
* @author Luca Frosini (ISTI - CNR)
@ -20,6 +21,12 @@ public class ElementImpl implements Element {
*/
private static final long serialVersionUID = 7338083489551084860L;
@Override
public String getTypeName() {
return TypeUtility.getTypeName(this.getClass());
}
@Override
public String toString(){
StringWriter stringWriter = new StringWriter();
@ -30,4 +37,5 @@ public class ElementImpl implements Element {
return super.toString();
}
}
}

View File

@ -1,13 +1,17 @@
package org.gcube.informationsystem.base.impl.entities;
import java.io.StringWriter;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.impl.ElementImpl;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.serialization.ElementMapper;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=EntityElement.NAME)
public abstract class EntityElementImpl extends ElementImpl implements EntityElement {
@ -16,20 +20,31 @@ public abstract class EntityElementImpl extends ElementImpl implements EntityEle
*/
private static final long serialVersionUID = -4488771434017342703L;
protected Header header;
protected UUID uuid;
protected Metadata metadata;
protected EntityElementImpl(){
super();
}
@Override
public Header getHeader() {
return header;
public UUID getID() {
return uuid;
}
@Override
public void setID(UUID uuid) {
this.uuid = uuid;
}
@Override
public void setHeader(Header header){
this.header = header;
public Metadata getMetadata() {
return metadata;
}
@Override
public void setMetadata(Metadata metadata){
this.metadata = metadata;
}
@Override
@ -40,7 +55,7 @@ public abstract class EntityElementImpl extends ElementImpl implements EntityEle
return stringWriter.toString();
}catch(Exception e){
try {
ElementMapper.marshal(this.header, stringWriter);
ElementMapper.marshal(this.metadata, stringWriter);
return stringWriter.toString();
} catch(Exception e1){
return super.toString();

View File

@ -1,9 +1,18 @@
package org.gcube.informationsystem.base.impl.properties;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.impl.ElementImpl;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.serialization.ElementMapper;
/**
* @author Luca Frosini (ISTI - CNR)
@ -16,8 +25,87 @@ public class PropertyElementImpl extends ElementImpl implements Property {
*/
private static final long serialVersionUID = 1396998430221747445L;
protected List<String> supertypes;
protected String expectedtype;
@JsonIgnore
protected Map<String, Object> additionalProperties;
/**
* Used to allow to have an additional property starting with '_' or '@'
*/
@JsonIgnore
protected final Set<String> allowedAdditionalKeys;
public PropertyElementImpl() {
super();
this.additionalProperties = new HashMap<>();
this.allowedAdditionalKeys = new HashSet<>();
}
@Override
public List<String> getSupertypes() {
return this.supertypes;
}
@Override
public String getExpectedtype() {
return this.expectedtype;
}
@Override
public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}
@Override
public void setAdditionalProperties(Map<String, Object> additionalProperties) {
this.additionalProperties = additionalProperties;
}
@Override
public Object getAdditionalProperty(String key) {
return additionalProperties.get(key);
}
@Override
public void setAdditionalProperty(String key, Object value) {
if(!allowedAdditionalKeys.contains(key)){
if(key.startsWith("_")) {
return;
}
if(key.startsWith("@")) {
return;
}
}
/*
Additional properties are not deserialized to the proper property type.
The first attempt was to try to write a specific deserializer but it fails.
This fix the issue.
*/
try {
if(value instanceof Map<?,?>) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String,Object>) value;
if(map.containsKey(Element.TYPE_PROPERTY)) {
String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map);
Property property = ElementMapper.unmarshal(Property.class, reserialized);
value = property;
}
}
}catch (Throwable e) {
e.getMessage();
// Any type of error/exception must be catched
}
/* END of fix to properly deserialize Property types*/
this.additionalProperties.put(key, value);
}
public void addAllowedAdditionalKey(String allowedAdditionalKey){
this.allowedAdditionalKeys.add(allowedAdditionalKey);
}
}

View File

@ -1,11 +1,16 @@
package org.gcube.informationsystem.base.impl.relations;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.impl.ElementImpl;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Metadata;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=RelationElement.NAME)
public abstract class RelationElementImpl<S extends EntityElement, T extends EntityElement> extends ElementImpl implements RelationElement<S, T> {
@ -14,7 +19,8 @@ public abstract class RelationElementImpl<S extends EntityElement, T extends Ent
*/
private static final long serialVersionUID = 28704968813390512L;
protected Header header;
protected UUID uuid;
protected Metadata metadata;
protected S source;
protected T target;
@ -22,21 +28,31 @@ public abstract class RelationElementImpl<S extends EntityElement, T extends Ent
protected RelationElementImpl() {
super();
}
protected RelationElementImpl(S source, T target) {
this();
this.source = source;
this.target = target;
}
@Override
public UUID getID() {
return uuid;
}
@Override
public Header getHeader() {
return header;
public void setID(UUID uuid) {
this.uuid = uuid;
}
@Override
public void setHeader(Header header){
this.header = header;
public Metadata getMetadata() {
return metadata;
}
@Override
public void setMetadata(Metadata metadata){
this.metadata = metadata;
}
@Override

View File

@ -4,6 +4,8 @@
package org.gcube.informationsystem.base.reference;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.gcube.informationsystem.base.impl.entities.EntityElementImpl;
import org.gcube.informationsystem.base.impl.properties.PropertyElementImpl;
@ -11,10 +13,10 @@ import org.gcube.informationsystem.base.impl.relations.RelationElementImpl;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.context.impl.entities.ContextImpl;
import org.gcube.informationsystem.context.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
import org.gcube.informationsystem.contexts.impl.entities.ContextImpl;
import org.gcube.informationsystem.contexts.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.impl.entities.DummyFacet;
import org.gcube.informationsystem.model.impl.entities.DummyResource;
import org.gcube.informationsystem.model.impl.entities.EntityImpl;
@ -32,6 +34,10 @@ import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.queries.templates.impl.entities.QueryTemplateImpl;
import org.gcube.informationsystem.queries.templates.impl.properties.TemplateVariableImpl;
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
import org.gcube.informationsystem.types.impl.entities.EntityTypeImpl;
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
import org.gcube.informationsystem.types.impl.properties.PropertyTypeImpl;
@ -44,37 +50,60 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
* Enumerates the basic type names.
*
* @author Luca Frosini (ISTI - CNR)
*/
public enum AccessType {
PROPERTY_ELEMENT(PropertyElement.class, PropertyElement.NAME, PropertyElementImpl.class, null),
PROPERTY_DEFINITION(PropertyDefinition.class, PropertyDefinition.NAME, PropertyDefinitionImpl.class, null),
PROPERTY_TYPE(PropertyType.class, PropertyType.NAME, PropertyTypeImpl.class, null),
TEMPLATE_VARIABLE(TemplateVariable.class, TemplateVariable.NAME, TemplateVariableImpl.class, null),
PROPERTY(Property.class, Property.NAME, PropertyImpl.class, null),
CONTEXT(Context.class, Context.NAME, ContextImpl.class, null),
IS_PARENT_OF(IsParentOf.class, IsParentOf.NAME, IsParentOfImpl.class, null),
PROPERTY_DEFINITION(PropertyDefinition.class, PropertyDefinition.NAME, PropertyDefinitionImpl.class, null),
// TYPE_DEFINITION(TypeDefinition.class, TypeDefinition.NAME, TypeDefinitionImpl.class, null),
PROPERTY_TYPE(PropertyType.class, PropertyType.NAME, PropertyTypeImpl.class, null),
ENTITY_TYPE(EntityType.class, EntityType.NAME, EntityTypeImpl.class, null),
RELATION_TYPE(RelationType.class, RelationType.NAME, RelationTypeImpl.class, null),
ENTITY_ELEMENT(EntityElement.class, EntityElement.NAME, EntityElementImpl.class, null),
ENTITY_TYPE(EntityType.class, EntityType.NAME, EntityTypeImpl.class, null),
QUERY_TEMPLATE(QueryTemplate.class, QueryTemplate.NAME, QueryTemplateImpl.class, null),
CONTEXT(Context.class, Context.NAME, ContextImpl.class, null),
ENTITY(Entity.class, Entity.NAME, EntityImpl.class, null),
RESOURCE(Resource.class, Resource.NAME, ResourceImpl.class, DummyResource.class),
FACET(Facet.class, Facet.NAME, FacetImpl.class, DummyFacet.class),
RELATION_ELEMENT(RelationElement.class, RelationElement.NAME, RelationElementImpl.class, null),
RELATION_TYPE(RelationType.class, RelationType.NAME, RelationTypeImpl.class, null),
IS_PARENT_OF(IsParentOf.class, IsParentOf.NAME, IsParentOfImpl.class, null),
RELATION(Relation.class, Relation.NAME, RelationImpl.class, null),
IS_RELATED_TO(IsRelatedTo.class, IsRelatedTo.NAME, IsRelatedToImpl.class, DummyIsRelatedTo.class),
CONSISTS_OF(ConsistsOf.class, ConsistsOf.NAME, ConsistsOfImpl.class, null);
private static Logger logger = LoggerFactory.getLogger(AccessType.class);
private static AccessType[] modelTypes;
private static AccessType[] erTypes;
private static Set<String> names;
static {
names = new HashSet<>();
AccessType[] accessTypes = AccessType.values();
for (AccessType accessType : accessTypes) {
String name = accessType.getName();
names.add(name);
}
modelTypes = new AccessType[] {
AccessType.PROPERTY,
AccessType.RESOURCE, AccessType.FACET,
AccessType.IS_RELATED_TO, AccessType.CONSISTS_OF
};
erTypes = new AccessType[] {
AccessType.RESOURCE, AccessType.FACET,
AccessType.IS_RELATED_TO, AccessType.CONSISTS_OF
};
}
private final Class<? extends Element> clz;
private final Class<? extends Element> implementationClass;
private final Class<? extends Element> dummyImplementationClass;
@ -119,6 +148,26 @@ public enum AccessType {
return name;
}
public static Set<String> names(){
return names;
}
/**
* Provide the access type from the name provided type name as argument
* @param typeName type name
* @return the AccessType from the name provided type name as argument, null otherwise
*/
public static AccessType getAccessType(String typeName) {
AccessType[] accessTypes = AccessType.values();
for (AccessType accessType : accessTypes) {
String name = accessType.getName();
if(name.compareTo(typeName)==0) {
return accessType;
}
}
return null;
}
public static AccessType getAccessType(Class<?> clz) {
AccessType ret =null;
@ -142,4 +191,21 @@ public enum AccessType {
throw new RuntimeException(error);
}
}
/**
* @return an array of AccessTypes containing only
* Model Types (i.e. Property, Resource, Facet, IsRelatedTo, ConsistsOf)
*/
public static AccessType[] getModelTypes() {
return modelTypes;
}
/**
* @return an array of AccessTypes containing only
* Entity/Relation Model Types (i.e. Resource, Facet, IsRelatedTo, ConsistsOf)
*/
public static AccessType[] getERTypes() {
return erTypes;
}
}

View File

@ -0,0 +1,20 @@
package org.gcube.informationsystem.base.reference;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public enum Direction {
IN, OUT, BOTH;
public Direction opposite() {
if(this.equals(IN)) {
return OUT;
}else if(this.equals(OUT)) {
return IN;
} else {
return BOTH;
}
}
}

View File

@ -5,26 +5,35 @@ package org.gcube.informationsystem.base.reference;
import java.io.Serializable;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Abstract
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = Element.CLASS_PROPERTY)
@JsonPropertyOrder({ Element.TYPE_PROPERTY })
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = Element.TYPE_PROPERTY)
// @JsonTypeIdResolver(ElementTypeIdResolver.class)
@TypeMetadata(name = Element.NAME, description = "This is the base type for Element", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface Element extends Serializable {
public static final String NAME = "Element"; //Element.class.getSimpleName();
public static final String CLASS_PROPERTY = "@class";
public static final String SUPERCLASSES_PROPERTY = "@superClasses";
public static final String TYPE_PROPERTY = "type";
/**
* DateTime Pattern to be used to serialize Dates in every element
*/
public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS Z";
@JsonIgnore
public String getTypeName();
}

View File

@ -1,16 +1,36 @@
package org.gcube.informationsystem.base.reference;
import org.gcube.informationsystem.model.reference.properties.Header;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.informationsystem.model.reference.properties.Metadata;
/**
* This interfaces is an helper to identify elements could be identified via {@link Metadata}
*
* @author Luca Frosini (ISTI - CNR)
* this is just a useful interface
*/
@JsonPropertyOrder({ Element.TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
public interface IdentifiableElement extends Element {
public static final String HEADER_PROPERTY = "header";
public Header getHeader();
public static final String ID_PROPERTY = "id";
public static final String METADATA_PROPERTY = "metadata";
@JsonGetter(value = ID_PROPERTY)
public UUID getID();
@JsonSetter(value = ID_PROPERTY)
public void setID(UUID uuid);
@JsonInclude(Include.NON_NULL)
@JsonGetter(value = METADATA_PROPERTY)
public Metadata getMetadata();
@JsonSetter(value = METADATA_PROPERTY)
public void setMetadata(Metadata metadata);
public void setHeader(Header header);
}

View File

@ -4,7 +4,8 @@ import java.util.Map;
/**
* This interfaces is an helper to identify elements supporting Schema Mixed.
* i.e. elements which instances could have additional properties in respect to the ones defined in the schema
* i.e. elements which instances could have additional properties in respect to the ones defined in the schema
*
* @author Luca Frosini (ISTI - CNR)
*/
public interface SchemaMixedElement extends Element {

View File

@ -1,22 +1,43 @@
package org.gcube.informationsystem.base.reference.entities;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
@JsonPropertyOrder({ Element.TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
//@JsonDeserialize(as=EntityElementImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = EntityElement.NAME, description = "This is the base type for any EntityElement", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface EntityElement extends Element, IdentifiableElement {
public static final String NAME = "EntityElement"; //Entity.class.getSimpleName();
/* Overriding getHeader method to create Header property in type */
@ISProperty(name=HEADER_PROPERTY, mandatory=true, nullable=false)
@ISProperty(name = ID_PROPERTY, description = "This UUID is be used to identify the instance univocally.", readonly = true, mandatory = true, nullable = false)
@Override
public Header getHeader();
public UUID getID();
@Override
public void setID(UUID uuid);
@ISProperty(name=METADATA_PROPERTY, mandatory=true, nullable=false, description="Metadata associated with the instance that is automatically created/updated by the system.")
@Override
public Metadata getMetadata();
@Override
public void setMetadata(Metadata metadata);
}

View File

@ -3,17 +3,21 @@ package org.gcube.informationsystem.base.reference.properties;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.impl.properties.PropertyElementImpl;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* Root Class for Property types.
* It creates a base common type, which is useful for management purpose.
*
* @author Luca Frosini (ISTI - CNR)
* Root Class for Property types. It creates a base common type, which is useful
* for management purpose.
*/
@JsonDeserialize(as=PropertyElementImpl.class)
@TypeMetadata(name = PropertyElement.NAME, description = "This is the base type for any PropertyElement", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface PropertyElement extends Element {
public static final String NAME = "PropertyElement"; //PropertyElement.class.getSimpleName();
public static final String DESCRIPTION = "This is the very base class for Property";
public static final String VERSION = "1.0.0";
}

View File

@ -1,16 +1,26 @@
package org.gcube.informationsystem.base.reference.relations;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Abstract
//@JsonDeserialize(as=RelationElementImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = RelationElement.NAME, description = "This is the base type for any RelationElement", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface RelationElement<S extends EntityElement, T extends EntityElement> extends Element, IdentifiableElement {
public static final String NAME = "RelationElement"; // RelationElement.class.getSimpleName();
@ -18,10 +28,19 @@ public interface RelationElement<S extends EntityElement, T extends EntityElemen
public static final String SOURCE_PROPERTY = "source";
public static final String TARGET_PROPERTY = "target";
/* Overriding getHeader method to create Header property in type */
@ISProperty(name = HEADER_PROPERTY, mandatory = true, nullable = false)
@ISProperty(name = ID_PROPERTY, description = "This UUID is be used to identify the instance univocally.", readonly = true, mandatory = true, nullable = false)
@Override
public Header getHeader();
public UUID getID();
@Override
public void setID(UUID uuid);
@ISProperty(name=METADATA_PROPERTY, mandatory=true, nullable=false, description="Metadata associated with the instance that is automatically created/updated by the system.")
@Override
public Metadata getMetadata();
@Override
public void setMetadata(Metadata metadata);
@JsonGetter(value=SOURCE_PROPERTY)
public S getSource();

View File

@ -1,141 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.context.impl.entities;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.informationsystem.base.impl.entities.EntityElementImpl;
import org.gcube.informationsystem.context.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=Context.NAME)
public final class ContextImpl extends EntityElementImpl implements Context {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -5070590328223454087L;
protected String name;
protected IsParentOf parent;
protected List<IsParentOf> children;
protected ContextImpl() {
super();
this.parent = null;
this.children = new ArrayList<>();
}
public ContextImpl(String name) {
this(name, null);
}
public ContextImpl(String name, UUID uuid) {
this();
this.name = name;
if(uuid == null){
uuid = UUID.randomUUID();
}
this.header = new HeaderImpl(uuid);
}
@Override
public String getName() {
return this.name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public IsParentOf getParent() {
return parent;
}
@Override
public void setParent(UUID uuid) {
Context parent = null;
if(uuid!=null) {
parent = new ContextImpl();
parent.setHeader(new HeaderImpl(uuid));
}
setParent(parent);
}
@Override
public void setParent(Context context) {
IsParentOf isParentOf = null;
if(context!=null) {
isParentOf = new IsParentOfImpl(context, this);
}
setParent(isParentOf);
}
@JsonSetter(value=PARENT_PROPERTY)
protected void setParentFromJson(IsParentOf isParentOf) throws JsonProcessingException {
if(isParentOf!=null) {
Context parent = isParentOf.getSource();
isParentOf.setTarget(this);
((ContextImpl) parent).addChild(isParentOf);
}
setParent(isParentOf);
}
@Override
public void setParent(IsParentOf isParentOf) {
this.parent = isParentOf;
}
@Override
public List<IsParentOf> getChildren() {
return children;
}
@JsonSetter(value=CHILDREN_PROPERTY)
protected void setChildrenFromJson(List<IsParentOf> children) throws JsonProcessingException {
for(IsParentOf isParentOf : children){
addChildFromJson(isParentOf);
}
}
protected void addChildFromJson(IsParentOf isParentOf) throws JsonProcessingException {
isParentOf.setSource(this);
addChild(isParentOf);
}
@Override
public void addChild(UUID uuid) {
Context child = new ContextImpl();
child.setHeader(new HeaderImpl(uuid));
addChild(child);
}
@Override
public void addChild(Context child) {
IsParentOf isParentOf = new IsParentOfImpl(this, child);
this.addChild(isParentOf);
}
@Override
public void addChild(IsParentOf isParentOf) {
((ContextImpl) isParentOf.getTarget()).setParent(this);
children.add(isParentOf);
}
}

View File

@ -1,60 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.context.reference.entities;
import java.util.List;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.context.impl.entities.ContextImpl;
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.types.annotations.ISProperty;
/**
* @author Luca Frosini (ISTI - CNR) This Entity is for internal use only
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Context
*/
@JsonDeserialize(as = ContextImpl.class)
public interface Context extends EntityElement {
public static final String NAME = "Context"; // Context.class.getSimpleName();
public static final String NAME_PROPERTY = "name";
public static final String PARENT_PROPERTY = "parent";
public static final String CHILDREN_PROPERTY = "children";
@ISProperty(name = NAME_PROPERTY, mandatory = true, nullable = false)
public String getName();
public void setName(String name);
@JsonGetter
@JsonIgnoreProperties({ Relation.TARGET_PROPERTY })
public IsParentOf getParent();
@JsonIgnore
public void setParent(UUID uuid);
@JsonIgnore
public void setParent(Context context);
@JsonIgnore
public void setParent(IsParentOf isParentOf);
@JsonGetter
@JsonIgnoreProperties({ Relation.SOURCE_PROPERTY })
public List<IsParentOf> getChildren();
public void addChild(UUID uuid);
public void addChild(Context child);
public void addChild(IsParentOf isParentOf);
}

View File

@ -0,0 +1,231 @@
/**
*
*/
package org.gcube.informationsystem.contexts.impl.entities;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.informationsystem.base.impl.entities.EntityElementImpl;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.contexts.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.utils.UUIDManager;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=Context.NAME)
public final class ContextImpl extends EntityElementImpl implements Context {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -5070590328223454087L;
protected UUID uuid;
protected String name;
protected IsParentOf parent;
protected List<IsParentOf> children;
@JsonIgnore
protected Map<String, Object> additionalProperties;
@JsonIgnore
/**
* Used to allow to have an additional property starting with '_' or '@'
*/
protected final Set<String> allowedAdditionalKeys;
protected ContextImpl() {
super();
this.parent = null;
this.children = new ArrayList<>();
this.additionalProperties = new HashMap<>();
this.allowedAdditionalKeys = new HashSet<>();
}
public ContextImpl(UUID uuid) {
this(null, uuid);
}
public ContextImpl(String name) {
this(name, null);
}
public ContextImpl(String name, UUID uuid) {
this();
this.name = name;
if(uuid == null){
uuid = UUIDManager.getInstance().generateValidUUID();
}
this.uuid = uuid;
this.metadata = new MetadataImpl();
}
/**
* @return the uuid
*/
@Override
public UUID getID() {
return uuid;
}
@Override
public void setID(UUID uuid) {
this.uuid = uuid;
}
@Override
public String getName() {
return this.name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public IsParentOf getParent() {
return parent;
}
@Override
public void setParent(UUID uuid) {
Context parent = null;
if(uuid!=null) {
parent = new ContextImpl(uuid);
parent.setMetadata(new MetadataImpl());
}
setParent(parent);
}
@Override
public void setParent(Context context) {
IsParentOf isParentOf = null;
if(context!=null) {
isParentOf = new IsParentOfImpl(context, this);
}
setParent(isParentOf);
}
@JsonSetter(value=PARENT_PROPERTY)
protected void setParentFromJson(IsParentOf isParentOf) throws JsonProcessingException {
if(isParentOf!=null) {
Context parent = isParentOf.getSource();
isParentOf.setTarget(this);
((ContextImpl) parent).addChild(isParentOf);
}
setParent(isParentOf);
}
@Override
public void setParent(IsParentOf isParentOf) {
this.parent = isParentOf;
}
@Override
public List<IsParentOf> getChildren() {
return children;
}
@JsonSetter(value=CHILDREN_PROPERTY)
protected void setChildrenFromJson(List<IsParentOf> children) throws JsonProcessingException {
for(IsParentOf isParentOf : children){
addChildFromJson(isParentOf);
}
}
protected void addChildFromJson(IsParentOf isParentOf) throws JsonProcessingException {
isParentOf.setSource(this);
addChild(isParentOf);
}
@Override
public void addChild(UUID uuid) {
Context child = new ContextImpl(uuid);
child.setMetadata(new MetadataImpl());
addChild(child);
}
@Override
public void addChild(Context child) {
IsParentOf isParentOf = new IsParentOfImpl(this, child);
this.addChild(isParentOf);
}
@Override
public void addChild(IsParentOf isParentOf) {
// ((ContextImpl) isParentOf.getTarget()).setParent(this);
isParentOf.setSource(this);
children.add(isParentOf);
}
@Override
public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}
@Override
public void setAdditionalProperties(Map<String, Object> additionalProperties) {
this.additionalProperties = additionalProperties;
}
@Override
public Object getAdditionalProperty(String key) {
return additionalProperties.get(key);
}
@Override
public void setAdditionalProperty(String key, Object value) {
if(!allowedAdditionalKeys.contains(key)){
if(key.startsWith("_")) {
return;
}
if(key.startsWith("@")) {
return;
}
}
/*
Additional properties are not deserialized to the proper property type.
The first attempt was to try to write a specific deserializer but it fails.
This fix the issue.
*/
try {
if(value instanceof Map<?,?>) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String,Object>) value;
if(map.containsKey(Element.TYPE_PROPERTY)) {
String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map);
Property property = ElementMapper.unmarshal(Property.class, reserialized);
value = property;
}
}
}catch (Throwable e) {
e.getMessage();
// Any type of error/exception must be catched
}
/* END of fix to properly deserialize Property types*/
this.additionalProperties.put(key, value);
}
}

View File

@ -1,12 +1,12 @@
/**
*
*/
package org.gcube.informationsystem.context.impl.relations;
package org.gcube.informationsystem.contexts.impl.relations;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.impl.relations.RelationElementImpl;
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
/**
* @author Luca Frosini (ISTI - CNR)

View File

@ -0,0 +1,136 @@
/**
*
*/
package org.gcube.informationsystem.contexts.reference.entities;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.base.reference.SchemaMixedElement;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.contexts.impl.entities.ContextImpl;
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.serialization.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Context
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as = ContextImpl.class)
@JsonPropertyOrder({ Element.TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY})
@TypeMetadata(name = Context.NAME, description = "This type is the used to define a Context", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface Context extends EntityElement, SchemaMixedElement {
public static final String NAME = "Context"; // Context.class.getSimpleName();
public static final String NAME_PROPERTY = "name";
public static final String PARENT_PROPERTY = "parent";
public static final String CHILDREN_PROPERTY = "children";
/**
* {
* ...
* "availableAt" : [
* "https://i-marine.d4science.org/group/alienandinvasivespecies",
* "https://services.d4science.org/group/alienandinvasivespecies"
* ]
* ...
* }
* For non VRE context this field could be null or could have multiple value
* For VRE it is normally one value only (but some exception could exists
*/
public static final String AVAILABLE_AT_PROPERTY = "availableAt";
//
/**
* This information is provided to allowed user only (by role)
* {
* ...
* "fullpaths" : [
* {
* "fullpath": "/gcube/devsec/myTest",
* "time": "2023-12-11 15:35:41.289 +0000", // Same of creationTime in metadata
* },
* {
* "fullpath": "/gcube/devsec/myTestVRE",
* "time": "2023-12-13 16:13:12.336 +0000",
* }
* {
* "fullpath": "/gcube/devsec/myVRE",
* "time": "2023-12-18 12:37:48.172 +0000", // Same of lastUpdateTime in metadata
* }
* ]
* ...
* }
*/
public static final String CONTEXT_FULLPATH_CHANGES_LOG_PROPERTY = "fullpathChangelog";
/**
* This information is provided to allowed user only (by role)
* The symmetric key for the context
*/
public static final String CONTEXT_KEY_PROPERTY = "key";
@ISProperty(name = NAME_PROPERTY, mandatory = true, nullable = false)
public String getName();
public void setName(String name);
@JsonGetter
@JsonIgnoreProperties({ Relation.TARGET_PROPERTY })
public IsParentOf getParent();
@JsonIgnore
public void setParent(UUID uuid);
@JsonIgnore
public void setParent(Context context);
@JsonIgnore
public void setParent(IsParentOf isParentOf);
@JsonGetter
@JsonIgnoreProperties({ Relation.SOURCE_PROPERTY })
public List<IsParentOf> getChildren();
public void addChild(UUID uuid);
public void addChild(Context child);
public void addChild(IsParentOf isParentOf);
@JsonAnyGetter
@JsonSerialize(using = AdditionalPropertiesSerializer.class)
@Override
public Map<String,Object> getAdditionalProperties();
@Override
public void setAdditionalProperties(Map<String,Object> additionalProperties);
@Override
public Object getAdditionalProperty(String key);
@JsonAnySetter
@Override
public void setAdditionalProperty(String key, Object value);
}

View File

@ -1,21 +1,31 @@
/**
*
*/
package org.gcube.informationsystem.context.reference.relations;
package org.gcube.informationsystem.contexts.reference.relations;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.context.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.contexts.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#IsParentOf
*
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isParentOf
*/
@JsonDeserialize(as = IsParentOfImpl.class)
@JsonPropertyOrder({ Element.TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY})
@TypeMetadata(name = IsParentOf.NAME, description = "This type is the used to define parental relations between Context", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface IsParentOf extends RelationElement<Context,Context> {
public static final String NAME = "IsParentOf"; //IsParentOf.class.getSimpleName();

View File

@ -0,0 +1,15 @@
/**
*
*/
package org.gcube.informationsystem.discovery;
import org.gcube.informationsystem.base.reference.Element;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public interface DiscoveredElementAction<E extends Element> {
public void analizeElement(Class<E> e) throws Exception;
}

View File

@ -0,0 +1,160 @@
/**
*
*/
package org.gcube.informationsystem.discovery;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.utils.ReflectionUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class Discovery<E extends Element> {
public static Logger logger = LoggerFactory.getLogger(Discovery.class);
protected final Class<E> root;
protected final Set<Package> packages;
protected final List<Class<E>> discoveredElements;
protected final List<DiscoveredElementAction<Element>> discoveredElementActions;
protected boolean discovered;
public Discovery(Class<E> root) throws Exception {
this.root = root;
this.packages = new HashSet<>();
this.discovered = false;
this.discoveredElements = new ArrayList<>();
this.discoveredElementActions = new ArrayList<>();
add(root);
}
public List<Class<E>> getDiscoveredElements() {
return discoveredElements;
}
@SuppressWarnings("unchecked")
public synchronized void addDiscoveredElementActions(DiscoveredElementAction<Element> discoveredElementAction) throws Exception {
discoveredElementActions.add(discoveredElementAction);
if(discovered) {
for(Class<E> clz : discoveredElements) {
discoveredElementAction.analizeElement((Class<Element>) clz);
}
}
}
@SuppressWarnings("unchecked")
public synchronized void executeDiscoveredElementActions(DiscoveredElementAction<Element> discoveredElementAction) throws Exception {
if(discovered) {
for(Class<E> clz : discoveredElements) {
discoveredElementAction.analizeElement((Class<Element>) clz);
}
}
}
public void addPackage(Package p) {
packages.add(p);
}
public void addPackages(Collection<Package> packages) {
for(Package p : packages) {
addPackage(p);
}
}
@SuppressWarnings("unchecked")
protected void add(Class<E> clz) throws Exception {
if(!discoveredElements.contains(clz)) {
discoveredElements.add(clz);
for(DiscoveredElementAction<Element> discoveredElementAction : discoveredElementActions) {
discoveredElementAction.analizeElement((Class<Element>) clz);
}
logger.info("+ Added {}.", clz);
}
}
protected void analizeElement(Class<E> clz) throws Exception {
logger.trace("Analizyng {}", clz);
if(!clz.isInterface()) {
logger.trace("- Discarding {} because is not an interface", clz);
return;
}
if(!root.isAssignableFrom(clz)) {
logger.trace("- Discarding {} because is not a {}", clz, root.getSimpleName());
return;
}
if(discoveredElements.contains(clz)) {
logger.trace("- Discarding {} because was already managed", clz);
return;
}
Class<?>[] interfaces = clz.getInterfaces();
for(Class<?> interfaceClass : interfaces) {
@SuppressWarnings("unchecked")
Class<E> parent = (Class<E>) interfaceClass;
analizeElement(parent);
}
if(root == PropertyElement.class) {
for(Method m : clz.getDeclaredMethods()) {
m.setAccessible(true);
if(m.isAnnotationPresent(ISProperty.class)) {
if(Map.class.isAssignableFrom(m.getReturnType()) || Set.class.isAssignableFrom(m.getReturnType())
|| List.class.isAssignableFrom(m.getReturnType())) {
Type[] typeArguments = ((ParameterizedType) m.getGenericReturnType()).getActualTypeArguments();
for(Type t : typeArguments) {
@SuppressWarnings("unchecked")
Class<? extends PropertyElement> tClass = (Class<? extends PropertyElement>) t;
if(root.isAssignableFrom(tClass)) {
@SuppressWarnings("unchecked")
Class<E> type = (Class<E>) tClass;
analizeElement(type);
}
}
} else if(root.isAssignableFrom(m.getReturnType())) {
@SuppressWarnings("unchecked")
Class<E> eClz = (Class<E>) m.getReturnType();
analizeElement(eClz);
}
}
}
}
add(clz);
}
public synchronized void discover() throws Exception {
this.discovered = false;
for(Package p : packages) {
List<Class<?>> classes = ReflectionUtility.getClassesForPackage(p);
for(Class<?> clz : classes) {
@SuppressWarnings("unchecked")
Class<E> eClz = (Class<E>) clz;
analizeElement(eClz);
}
}
this.discovered = true;
}
}

View File

@ -0,0 +1,34 @@
package org.gcube.informationsystem.discovery;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Element;
public class ISModelRegistrationProvider implements RegistrationProvider {
public static final String IS_MODEL_NAME = "Information System (IS) Model";
private static Set<Package> packages;
static {
packages = new HashSet<>();
for(AccessType accessType : AccessType.getModelTypes()) {
Class<Element> clz = accessType.getTypeClass();
packages.add(clz.getPackage());
}
}
@Override
public Collection<Package> getPackagesToRegister() {
return ISModelRegistrationProvider.packages;
}
@Override
public String getModelName() {
return IS_MODEL_NAME;
}
}

View File

@ -0,0 +1,29 @@
package org.gcube.informationsystem.discovery;
import java.util.Collection;
/**
* Any model requires to register the defined types.
* To accomplish this, it must implement this interface
* returning the list of packages containing the interfaces
* representing the model.
*
* Any registration provider MUST have a constructor with no arguments
*
* @author Luca Frosini (ISTI - CNR)
*/
public interface RegistrationProvider {
/**
* The name of the Model
* @return
*/
public String getModelName();
/**
* This method must return the list of packages to be registered
* @return the list of packages to register
*/
public Collection<Package> getPackagesToRegister();
}

View File

@ -0,0 +1,63 @@
/**
*
*/
package org.gcube.informationsystem.discovery.knowledge;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.discovery.DiscoveredElementAction;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.tree.Tree;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class AddElementToTreeAction implements DiscoveredElementAction<Element> {
protected Tree<Class<Element>> tree;
protected UsageKnowledge facetKnowledge;
protected UsageKnowledge resourceKnowledge;
public UsageKnowledge getFacetKnowledge() {
return facetKnowledge;
}
public void setFacetKnowledge(UsageKnowledge facetKnowledge) {
this.facetKnowledge = facetKnowledge;
}
public UsageKnowledge getResourceKnowledge() {
return resourceKnowledge;
}
public void setResourceKnowledge(UsageKnowledge resourceKnowledge) {
this.resourceKnowledge = resourceKnowledge;
}
public AddElementToTreeAction(Tree<Class<Element>> tree) {
this.tree = tree;
}
@Override
public void analizeElement(Class<Element> e) throws Exception {
tree.addNode(e);
createUsageKnowledge(e);
}
protected void createUsageKnowledge(Class<Element> e) {
if (e.isAssignableFrom(Resource.class)) {
return;
}
if(facetKnowledge!=null && resourceKnowledge!=null) {
Type type = TypeMapper.createTypeDefinition(e);
ResourceType rt = (ResourceType) type;
facetKnowledge.addAll(rt.getFacets());
resourceKnowledge.addAll(rt.getResources());
}
}
}

View File

@ -0,0 +1,49 @@
package org.gcube.informationsystem.discovery.knowledge;
import java.util.LinkedHashSet;
import java.util.Set;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.model.knowledge.TypeInformation;
import org.gcube.informationsystem.types.TypeMapper;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ClassInformation implements TypeInformation<Class<Element>> {
@Override
public String getIdentifier(Class<Element> clz) {
return TypeMapper.getType(clz);
}
@Override
public Set<String> getParentIdentifiers(Class<Element> root, Class<Element> clz) {
Set<String> ret = new LinkedHashSet<>();
if(clz == root) {
return ret;
}
Class<?>[] interfaces = clz.getInterfaces();
for(Class<?> i : interfaces) {
if(root.isAssignableFrom(i)) {
@SuppressWarnings("unchecked")
String id = getIdentifier((Class<Element>) i);
ret.add(id);
}
}
return ret;
}
@Override
public AccessType getAccessType(Class<Element> clz) {
return AccessType.getAccessType(clz);
}
@Override
public Class<Element> getRoot(AccessType accessType) {
return accessType.getTypeClass();
}
}

View File

@ -0,0 +1,108 @@
package org.gcube.informationsystem.discovery.knowledge;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.ServiceLoader;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.discovery.Discovery;
import org.gcube.informationsystem.discovery.RegistrationProvider;
import org.gcube.informationsystem.tree.Tree;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class Knowledge {
public static Logger logger = LoggerFactory.getLogger(Knowledge.class);
private static Knowledge instance;
public static Knowledge getInstance() throws Exception {
return getInstance(false);
}
public static Knowledge getInstance(boolean forceRediscover) throws Exception {
if(forceRediscover) {
instance = null;
}
if(instance == null) {
instance = new Knowledge();
instance.discover();
}
return instance;
}
protected ModelKnowledge allKnowledge;
protected Map<String, ModelKnowledge> modelKnowledges;
protected Map<String, RegistrationProvider> registrationProviders;
private Knowledge() {
}
public ModelKnowledge getAllKnowledge() {
return allKnowledge;
}
public ModelKnowledge getModelKnowledge(RegistrationProvider rp) {
return modelKnowledges.get(rp.getModelName());
}
public ModelKnowledge getModelKnowledge(String modelName) {
return modelKnowledges.get(modelName);
}
public void validateModelKnowledge(RegistrationProvider rp) throws Exception {
ModelKnowledge modelKnowledge = getModelKnowledge(rp);
ModelKnowledgeValidator ra = new ModelKnowledgeValidator(rp);
AccessType[] accessTypes = AccessType.getModelTypes();
for(AccessType accessType : accessTypes) {
logger.trace("Going to analise discovered types of '{}' for model '{}'", accessType.getName(), rp.getModelName());
Discovery<Element> discovery = modelKnowledge.getDiscovery(accessType);
discovery.executeDiscoveredElementActions(ra);
logger.trace("Going to analise tree of '{}' type for model '{}'", accessType.getName(), rp.getModelName());
Tree<Class<Element>> tree = modelKnowledge.getClassesTree(accessType);
tree.elaborate(ra);
}
}
public void validateModelKnowledge(String modelName) throws Exception {
RegistrationProvider rp = registrationProviders.get(modelName);
validateModelKnowledge(rp);
}
public void discover() throws Exception {
allKnowledge = new ModelKnowledge();
modelKnowledges = new LinkedHashMap<>();
registrationProviders = new LinkedHashMap<>();
ServiceLoader<? extends RegistrationProvider> providers = ServiceLoader
.load(RegistrationProvider.class);
for(RegistrationProvider rp : providers) {
registrationProviders.put(rp.getModelName(), rp);
ModelKnowledge modelKnowledge = new ModelKnowledge();
modelKnowledges.put(rp.getModelName(), modelKnowledge);
modelKnowledge.addPackages(rp.getPackagesToRegister());
modelKnowledge.createKnowledge();
allKnowledge.addPackages(rp.getPackagesToRegister());
}
allKnowledge.createKnowledge();
}
}

View File

@ -0,0 +1,109 @@
package org.gcube.informationsystem.discovery.knowledge;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.discovery.Discovery;
import org.gcube.informationsystem.serialization.ElementMappingAction;
import org.gcube.informationsystem.tree.Tree;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ModelKnowledge {
private static final Logger logger = LoggerFactory.getLogger(ModelKnowledge.class);
protected boolean created;
protected Map<AccessType, UsageKnowledge> usageKnowledges;
protected Map<AccessType, Tree<Class<Element>>> trees;
protected Map<AccessType, Discovery<Element>> discoveries;
protected Set<Package> packages;
public ModelKnowledge() {
this.packages = new HashSet<>();
reset();
}
private void reset() {
this.created = false;
this.usageKnowledges = new HashMap<>();
this.trees = new HashMap<>();
this.discoveries = new HashMap<>();
}
public UsageKnowledge getUsageKnowledge(AccessType accessType) {
if(!created) {
throw new RuntimeException("You must invoke createKnowledge() first");
}
return usageKnowledges.get(accessType);
}
public synchronized void createKnowledge(boolean force) throws Exception {
if(force) {
logger.info("Going to force Knowledge recreation");
reset();
}
createKnowledge();
}
public void addPackages(Collection<Package> packages) {
this.packages.addAll(packages);
}
public synchronized void createKnowledge() throws Exception {
if(created) {
logger.trace("Knowledge has been already created.");
return;
}
AccessType[] modelTypes = AccessType.getModelTypes();
ClassInformation classInformation = new ClassInformation();
for(AccessType accessType : modelTypes) {
Class<Element> clz = accessType.getTypeClass();
Tree<Class<Element>> tree = new Tree<>(clz, classInformation);
trees.put(accessType, tree);
AddElementToTreeAction aetta = new AddElementToTreeAction(tree);
if(accessType == AccessType.RESOURCE) {
UsageKnowledge facetKnowledge = new UsageKnowledge();
this.usageKnowledges.put(AccessType.FACET, facetKnowledge);
aetta.setFacetKnowledge(facetKnowledge);
UsageKnowledge resourceKnowledge = new UsageKnowledge();
this.usageKnowledges.put(AccessType.RESOURCE, resourceKnowledge);
aetta.setResourceKnowledge(resourceKnowledge);
}
Discovery<Element> discovery = new Discovery<>(clz);
discoveries.put(accessType, discovery);
discovery.addPackages(packages);
discovery.addDiscoveredElementActions(new ElementMappingAction());
discovery.addDiscoveredElementActions(aetta);
discovery.discover();
}
this.created = true;
}
public synchronized Tree<Class<Element>> getClassesTree(AccessType accessType) {
return trees.get(accessType);
}
public synchronized Discovery<Element> getDiscovery(AccessType accessType) {
return discoveries.get(accessType);
}
}

View File

@ -0,0 +1,80 @@
/**
*
*/
package org.gcube.informationsystem.discovery.knowledge;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.discovery.DiscoveredElementAction;
import org.gcube.informationsystem.discovery.RegistrationProvider;
import org.gcube.informationsystem.tree.Node;
import org.gcube.informationsystem.tree.NodeElaborator;
import org.gcube.informationsystem.types.TypeMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ModelKnowledgeValidator implements DiscoveredElementAction<Element>, NodeElaborator<Class<Element>> {
public static Logger logger = LoggerFactory.getLogger(ModelKnowledgeValidator.class);
protected RegistrationProvider rp;
private Collection<Package> packages;
private List<Class<Element>> baseTypes;
public ModelKnowledgeValidator(RegistrationProvider rp) {
this.rp = rp;
this.packages = rp.getPackagesToRegister();
this.baseTypes = new ArrayList<>();
AccessType[] accessTypes = AccessType.getModelTypes();
for(AccessType accessType : accessTypes) {
this.baseTypes.add(accessType.getTypeClass());
}
}
@Override
public void analizeElement(Class<Element> e) throws Exception {
String typeName = TypeMapper.getType(e);
if(baseTypes.contains(e)) {
logger.info("- Type {} is the root type", typeName);
return;
}
if(packages.contains(e.getPackage())) {
logger.info("- Type {} belongs to {} as expected", typeName, rp.getModelName());
}else {
logger.error("- Type {} DOES NOT belong to {} as expected. This is very strange and should not occurr.", typeName, rp.getModelName());
throw new Exception("Type " + typeName + " DOES NOT belong to " + rp.getModelName() +" as expected. This is very strange and should not occurr.");
}
}
@Override
public void elaborate(Node<Class<Element>> node, int level) throws Exception {
Class<Element> e = node.getNodeElement();
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < level; ++i) {
stringBuffer.append(Node.INDENTATION);
}
String typeName = TypeMapper.getType(e);
if(node.getTree().getRootNode().getNodeElement() == e) {
logger.info("{}- Type {} is the root type", stringBuffer.toString(), typeName);
return;
}
if(packages.contains(e.getPackage())) {
logger.info("{}- Type {} belongs to {} as expected", stringBuffer.toString(), typeName, rp.getModelName());
}else {
logger.error("{}- Type {} DOES NOT belong to {} as expected. This is very strange and should not occurr.", stringBuffer.toString(), typeName, rp.getModelName());
throw new Exception("Type " + typeName + " DOES NOT belong to " + rp.getModelName() +" as expected. This is very strange and should not occurr.");
}
}
}

View File

@ -0,0 +1,55 @@
package org.gcube.informationsystem.discovery.knowledge;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class UsageKnowledge {
protected Map<String, Set<LinkedEntity>> map;
public UsageKnowledge(){
this.map = new LinkedHashMap<>();
}
protected void add(String typeName, LinkedEntity linkedEntity) {
Set<LinkedEntity> list = map.get(typeName);
if(list==null) {
list = new TreeSet<>();
map.put(typeName, list);
}
list.add(linkedEntity);
}
public void add(LinkedEntity linkedEntity) {
if(linkedEntity!=null) {
String source = linkedEntity.getSource();
add(source, linkedEntity);
String relation = linkedEntity.getRelation();
add(relation, linkedEntity);
String target = linkedEntity.getTarget();
add(target, linkedEntity);
}
}
public void addAll(Collection<LinkedEntity> linkedEntities) {
if(linkedEntities!=null) {
for(LinkedEntity le : linkedEntities) {
add(le);
}
}
}
public Set<LinkedEntity> getUsage(String typeName){
Set<LinkedEntity> list = map.get(typeName);
return list;
}
}

View File

@ -5,12 +5,17 @@ package org.gcube.informationsystem.model.impl.entities;
import java.util.UUID;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@TypeMetadata(name = Facet.NAME, description = "This is a dummy type for Facet", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public class DummyFacet extends FacetImpl implements Facet {
/**
@ -20,7 +25,8 @@ public class DummyFacet extends FacetImpl implements Facet {
public DummyFacet(UUID uuid) {
super();
this.header = new HeaderImpl(uuid);
this.uuid = uuid;
this.metadata = new MetadataImpl();
}
public DummyFacet(){

View File

@ -5,12 +5,17 @@ package org.gcube.informationsystem.model.impl.entities;
import java.util.UUID;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@TypeMetadata(name = Resource.NAME, description = "This is a dummy type for Resource", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public class DummyResource extends ResourceImpl implements Resource {
/**
@ -20,7 +25,8 @@ public class DummyResource extends ResourceImpl implements Resource {
public DummyResource(UUID uuid){
super();
this.header = new HeaderImpl(uuid);
this.uuid = uuid;
this.metadata = new MetadataImpl();
}
public DummyResource(){

View File

@ -3,8 +3,14 @@
*/
package org.gcube.informationsystem.model.impl.entities;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.impl.entities.EntityElementImpl;
import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.model.reference.entities.Entity;
/**
@ -18,9 +24,31 @@ public abstract class EntityImpl extends EntityElementImpl implements Entity {
*/
private static final long serialVersionUID = -4488771434017342703L;
protected List<String> supertypes;
protected String expectedtype;
protected Map<UUID,String> contexts;
protected EntityImpl(){
super();
this.header = null;
this.metadata = null;
}
@Override
public List<String> getSupertypes() {
return this.supertypes;
}
@Override
public String getExpectedtype() {
return this.expectedtype;
}
public Map<UUID,String> getContexts(){
return this.contexts;
}
@JsonSetter(value = ERElement.CONTEXTS_PROPERTY)
protected void setContexts(Map<UUID,String> contexts) {
this.contexts = contexts;
}
}

View File

@ -13,7 +13,7 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.serialization.ElementMapper;
/**
* @author Luca Frosini (ISTI - CNR)
@ -39,7 +39,6 @@ public abstract class FacetImpl extends EntityImpl implements Facet {
super();
this.additionalProperties = new HashMap<>();
this.allowedAdditionalKeys = new HashSet<>();
this.allowedAdditionalKeys.add(SUPERCLASSES_PROPERTY);
}
@Override
@ -77,7 +76,7 @@ public abstract class FacetImpl extends EntityImpl implements Facet {
if(value instanceof Map<?,?>) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String,Object>) value;
if(map.containsKey(Element.CLASS_PROPERTY)) {
if(map.containsKey(Element.TYPE_PROPERTY)) {
String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map);
Property property = ElementMapper.unmarshal(Property.class, reserialized);
value = property;

View File

@ -177,14 +177,12 @@ public abstract class ResourceImpl extends EntityImpl implements Resource {
throw new RuntimeException(message);
}
if (relation.getSource().getHeader()!= null &&
relation.getSource().getHeader().getUUID() != null &&
this.header !=null &&
this.header.getUUID() != null &&
relation.getSource().getHeader().getUUID().compareTo(this.header.getUUID())!=0) {
if (relation.getSource().getMetadata()!= null &&
relation.getSource().getID() != null &&
this.metadata !=null &&
this.uuid != null &&
relation.getSource().getID().compareTo(this.uuid)!=0) {
throw new RuntimeException(message);
}
if(relation.getSource()!=this){

View File

@ -3,11 +3,8 @@
*/
package org.gcube.informationsystem.model.impl.properties;
import java.security.Key;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
/**
@ -22,36 +19,20 @@ public class EncryptedImpl extends PropertyImpl implements Encrypted {
private static final long serialVersionUID = 7823031209294161865L;
@JsonIgnore
protected String encryptedValue;
protected String value;
public EncryptedImpl() {
super();
}
@Override
public String getEncryptedValue() {
return encryptedValue;
public String getValue() {
return value;
}
@Override
public void setEncryptedValue(String encryptedValue) {
this.encryptedValue = encryptedValue;
}
public static String encrypt(String value) throws Exception {
return StringEncrypter.getEncrypter().encrypt(value);
}
public static String decrypt(String value) throws Exception {
return StringEncrypter.getEncrypter().decrypt(value);
}
public static String encrypt(String value, Key key) throws Exception {
return StringEncrypter.getEncrypter().encrypt(value, key);
}
public static String decrypt(String value, Key key) throws Exception {
return StringEncrypter.getEncrypter().decrypt(value, key);
public void setValue(String value) {
this.value = value;
}
}

View File

@ -1,70 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.properties;
import java.util.Date;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.model.reference.properties.Header;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=Header.NAME)
public final class HeaderImpl extends PropertyImpl implements Header {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 5102553511155113169L;
protected UUID uuid;
protected String creator;
protected String modifiedBy;
protected Date creationTime;
protected Date lastUpdateTime;
public HeaderImpl() {
super();
}
public HeaderImpl(UUID uuid) {
this.uuid = uuid;
}
/**
* @return the uuid
*/
@Override
public UUID getUUID() {
return uuid;
}
@Override
public void setUUID(UUID uuid) {
this.uuid = uuid;
}
@Override
public String getCreator() {
return creator;
}
@Override
public String getModifiedBy() {
return modifiedBy;
}
@Override
public Date getCreationTime() {
return creationTime;
}
@Override
public Date getLastUpdateTime() {
return lastUpdateTime;
}
}

View File

@ -0,0 +1,51 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.properties;
import java.util.Date;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.model.reference.properties.Metadata;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=Metadata.NAME)
public final class MetadataImpl extends PropertyImpl implements Metadata {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 5102553511155113169L;
protected String createdBy;
protected Date creationTime;
protected String lastUpdateBy;
protected Date lastUpdateTime;
public MetadataImpl() {
super();
}
@Override
public String getCreatedBy() {
return createdBy;
}
@Override
public Date getCreationTime() {
return creationTime;
}
@Override
public String getLastUpdateBy() {
return lastUpdateBy;
}
@Override
public Date getLastUpdateTime() {
return lastUpdateTime;
}
}

View File

@ -12,35 +12,29 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=PropagationConstraint.NAME)
public class PropagationConstraintImpl extends PropertyImpl implements PropagationConstraint {
public final class PropagationConstraintImpl extends PropertyImpl implements PropagationConstraint {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -4708881022038107688L;
@JsonFormat(shape=JsonFormat.Shape.STRING)
@JsonProperty(value=REMOVE_PROPERTY)
protected RemoveConstraint removeConstraint;
@JsonFormat(shape=JsonFormat.Shape.STRING)
@JsonProperty(value=ADD_PROPERTY)
protected AddConstraint addConstraint;
@JsonFormat(shape=JsonFormat.Shape.STRING)
@JsonProperty(value=DELETE_PROPERTY)
protected DeleteConstraint deleteConstraint;
@JsonFormat(shape=JsonFormat.Shape.STRING)
@JsonProperty(value=REMOVE_PROPERTY)
protected RemoveConstraint removeConstraint;
public PropagationConstraintImpl(){
super();
}
@Override
public RemoveConstraint getRemoveConstraint() {
return this.removeConstraint;
}
@Override
public void setRemoveConstraint(RemoveConstraint removeConstraint) {
this.removeConstraint = removeConstraint;
}
@Override
public AddConstraint getAddConstraint() {
return this.addConstraint;
@ -51,4 +45,24 @@ public class PropagationConstraintImpl extends PropertyImpl implements Propagati
this.addConstraint = addConstraint;
}
@Override
public DeleteConstraint getDeleteConstraint() {
return this.deleteConstraint;
}
@Override
public void setDeleteConstraint(DeleteConstraint deleteConstraint) {
this.deleteConstraint = deleteConstraint;
}
@Override
public RemoveConstraint getRemoveConstraint() {
return this.removeConstraint;
}
@Override
public void setRemoveConstraint(RemoveConstraint removeConstraint) {
this.removeConstraint = removeConstraint;
}
}

View File

@ -9,6 +9,7 @@ import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.DeleteConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
@ -29,10 +30,7 @@ public class ConsistsOfImpl<S extends Resource, T extends Facet> extends
}
public ConsistsOfImpl(S source, T target) {
super(source, target, null);
propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setAddConstraint(AddConstraint.propagate);
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan);
this(source, target, null);
}
public ConsistsOfImpl(S source, T target,
@ -41,7 +39,8 @@ public class ConsistsOfImpl<S extends Resource, T extends Facet> extends
if(this.propagationConstraint==null) {
this.propagationConstraint = new PropagationConstraintImpl();
this.propagationConstraint.setAddConstraint(AddConstraint.propagate);
this.propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan);
this.propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
this.propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade);
}
}

View File

@ -3,15 +3,18 @@
*/
package org.gcube.informationsystem.model.impl.relations;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=IsRelatedTo.NAME)
@TypeMetadata(name = IsRelatedTo.NAME, description = "This is a dummy type for IsRelatedTo", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public class DummyIsRelatedTo<S extends Resource, T extends Resource>
extends IsRelatedToImpl<S, T> implements IsRelatedTo<S, T>{

View File

@ -8,6 +8,7 @@ import org.gcube.informationsystem.model.impl.properties.PropagationConstraintIm
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.DeleteConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
@ -28,10 +29,7 @@ public abstract class IsRelatedToImpl<S extends Resource, T extends Resource> ex
}
public IsRelatedToImpl(S source, T target) {
super(source, target, null);
propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
propagationConstraint.setRemoveConstraint(RemoveConstraint.keep);
this(source, target, null);
}
public IsRelatedToImpl(S source, T target,
@ -41,6 +39,7 @@ public abstract class IsRelatedToImpl<S extends Resource, T extends Resource> ex
this.propagationConstraint = new PropagationConstraintImpl();
this.propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
this.propagationConstraint.setRemoveConstraint(RemoveConstraint.keep);
this.propagationConstraint.setDeleteConstraint(DeleteConstraint.keep);
}
}

View File

@ -5,19 +5,23 @@ package org.gcube.informationsystem.model.impl.relations;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.impl.relations.RelationElementImpl;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.serialization.ElementMapper;
/**
* @author Luca Frosini (ISTI - CNR)
@ -31,6 +35,10 @@ public abstract class RelationImpl<S extends Resource, T extends Entity>
*/
private static final long serialVersionUID = -6249979476879235053L;
protected List<String> supertypes;
protected String expectedtype;
protected Map<UUID,String> contexts;
protected PropagationConstraint propagationConstraint;
@JsonIgnore
@ -45,7 +53,6 @@ public abstract class RelationImpl<S extends Resource, T extends Entity>
super();
this.additionalProperties = new HashMap<>();
this.allowedAdditionalKeys = new HashSet<>();
this.allowedAdditionalKeys.add(SUPERCLASSES_PROPERTY);
}
protected RelationImpl(S source, T target,
@ -56,6 +63,26 @@ public abstract class RelationImpl<S extends Resource, T extends Entity>
this.propagationConstraint = propagationConstraint;
}
@Override
public List<String> getSupertypes() {
return this.supertypes;
}
@Override
public String getExpectedtype() {
return this.expectedtype;
}
public Map<UUID,String> getContexts(){
return this.contexts;
}
@JsonSetter(value = ERElement.CONTEXTS_PROPERTY)
protected void setContexts(Map<UUID,String> contexts) {
this.contexts = contexts;
}
@Override
public PropagationConstraint getPropagationConstraint() {
return this.propagationConstraint;
@ -85,7 +112,7 @@ public abstract class RelationImpl<S extends Resource, T extends Entity>
if (key.startsWith("@")) {
return;
}
if (key.compareTo(PROPAGATION_CONSTRAINT) == 0) {
if (key.compareTo(PROPAGATION_CONSTRAINT_PROPERTY) == 0) {
return;
}
if (key.compareTo(TARGET_PROPERTY) == 0) {
@ -105,7 +132,7 @@ public abstract class RelationImpl<S extends Resource, T extends Entity>
if(value instanceof Map<?,?>) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String,Object>) value;
if(map.containsKey(Element.CLASS_PROPERTY)) {
if(map.containsKey(Element.TYPE_PROPERTY)) {
String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map);
Property property = ElementMapper.unmarshal(Property.class, reserialized);
value = property;

View File

@ -0,0 +1,315 @@
package org.gcube.informationsystem.model.knowledge;
import java.util.AbstractMap.SimpleEntry;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.tree.Node;
import org.gcube.informationsystem.tree.Tree;
import org.gcube.informationsystem.types.PropertyTypeName;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ModelKnowledge<T, TI extends TypeInformation<T>> {
private static final Logger logger = LoggerFactory.getLogger(ModelKnowledge.class);
protected TI typeInformation;
protected Map<AccessType, Tree<T>> trees;
protected UsageKnowledge<Entry<String,PropertyDefinition>> propertyUsage;
protected Map<AccessType, UsageKnowledge<LinkedEntity>> erTypesUsage;
protected Map<String, AccessType> locate;
public ModelKnowledge(TI typeInformation) {
this.typeInformation = typeInformation;
reset();
}
protected void reset() {
this.trees = new HashMap<>();
this.erTypesUsage = new HashMap<>();
this.locate = new HashMap<>();
AccessType[] modelTypes = AccessType.getModelTypes();
for(AccessType accessType : modelTypes) {
/*
* T t = typeInformation.getRoot(accessType);
* Tree<T> tree = new Tree<>(t, typeInformation);
*/
Tree<T> tree = new Tree<>(typeInformation);
trees.put(accessType, tree);
if(accessType == AccessType.PROPERTY) {
/*
* In this case we get the type which uses such a property
* and the property definition.
* In this way we have a complete overview of the usage of the
* property type
*/
propertyUsage = new UsageKnowledge<>(accessType);
}else {
UsageKnowledge<LinkedEntity> usageKnowledge = new UsageKnowledge<LinkedEntity>(accessType);
erTypesUsage.put(accessType, usageKnowledge);
}
}
}
protected void addUsage(LinkedEntity linkedEntity, UsageKnowledge<LinkedEntity> relationUsage, UsageKnowledge<LinkedEntity> targetEntityUsage) {
if (linkedEntity != null) {
UsageKnowledge<LinkedEntity> resourceUsage = erTypesUsage.get(AccessType.RESOURCE);
String source = linkedEntity.getSource();
resourceUsage.add(source, linkedEntity);
String relation = linkedEntity.getRelation();
relationUsage.add(relation, linkedEntity);
String target = linkedEntity.getTarget();
targetEntityUsage.add(target, linkedEntity);
}
}
protected void addAllUsage(Collection<LinkedEntity> linkedEntities, UsageKnowledge<LinkedEntity> relationUsage, UsageKnowledge<LinkedEntity> targetEntityUsage) {
if(linkedEntities!=null) {
for(LinkedEntity le : linkedEntities) {
addUsage(le, relationUsage, targetEntityUsage);
}
}
}
protected void addPropertyUsage(T t, Set<PropertyDefinition> properties) {
if(properties==null || properties.size()==0) {
return;
}
String typeName = typeInformation.getIdentifier(t);
for(PropertyDefinition propertyDefinition : properties) {
PropertyTypeName propertyTypeName = ((PropertyDefinitionImpl) propertyDefinition).getPropertyTypeName();
if(propertyTypeName.isGenericType()) {
SimpleEntry<String,PropertyDefinition> entry = new SimpleEntry<>(typeName, propertyDefinition);
propertyUsage.add(propertyTypeName.getGenericClassName(), entry);
}
}
}
protected void addEntityMetadataUsage(T t) {
Type type = TypeMapper.createTypeDefinition(EntityElement.class);
addPropertyUsage(t, type.getProperties());
}
protected void addRelationMetadataUsage(T t) {
Type type = TypeMapper.createTypeDefinition(RelationElement.class);
addPropertyUsage(t, type.getProperties());
}
protected void addPropagationConstraintUsage(T t) {
Type type = TypeMapper.createTypeDefinition(Relation.class);
addPropertyUsage(t, type.getProperties());
}
public void addAllType(Collection<T> types) {
Set<T> toRetry = new HashSet<>();
for(T t : types) {
logger.trace("Going to add {}", typeInformation.getIdentifier(t));
try {
addType(t);
}catch (RuntimeException e) {
toRetry.add(t);
}
}
if(types.size()==toRetry.size()) {
throw new RuntimeException("Unable to find parent for " + toRetry.toString());
}
if(toRetry.size()>0) {
addAllType(toRetry);
}
}
public void addType(T t) {
AccessType accessType = typeInformation.getAccessType(t);
String typeName = typeInformation.getIdentifier(t);
if(locate.get(typeName)!=null) {
logger.trace("The type {} was already added to the ModelKnowledge", typeName);
return;
}
Tree<T> tree = trees.get(accessType);
tree.addNode(t);
locate.put(typeName, accessType);
UsageKnowledge<LinkedEntity> resourceUsage = erTypesUsage.get(AccessType.RESOURCE);
UsageKnowledge<LinkedEntity> facetUsage = erTypesUsage.get(AccessType.FACET);
UsageKnowledge<LinkedEntity> isRelatedToUsage = erTypesUsage.get(AccessType.IS_RELATED_TO);
UsageKnowledge<LinkedEntity> consistsOfUsage = erTypesUsage.get(AccessType.CONSISTS_OF);
switch (accessType) {
case PROPERTY:
// Nothing to do
break;
case RESOURCE:
ResourceType resourceType = (ResourceType) t;
addAllUsage(resourceType.getFacets(), consistsOfUsage, facetUsage);
addAllUsage(resourceType.getResources(), isRelatedToUsage, resourceUsage);
/*
* Metadata is defined in parent type i.e. EntityElement.
* We want to have a reference to all Base type
*/
if(typeName.compareTo(Resource.NAME)==0) {
addEntityMetadataUsage(t);
}
break;
case FACET:
FacetType facetType = (FacetType) t;
/*
* Metadata is defined in parent type i.e. EntityElement.
* We want to have a reference to all Base type
*/
if(typeName.compareTo(Facet.NAME)==0) {
addEntityMetadataUsage(t);
}
addPropertyUsage(t, facetType.getProperties());
break;
case IS_RELATED_TO:
IsRelatedToType isRelatedToType = (IsRelatedToType) t;
/*
* Metadata is defined in parent type i.e. RelationElement.
* We want to have a reference to all Base type
*/
if(typeName.compareTo(IsRelatedTo.NAME)==0) {
addRelationMetadataUsage(t);
addPropagationConstraintUsage(t);
}
addPropertyUsage(t, isRelatedToType.getProperties());
break;
case CONSISTS_OF:
ConsistsOfType consistsOfType = (ConsistsOfType) t;
/*
* Metadata is defined in parent type i.e. RelationElement.
* We want to have a reference to all Base type
*/
if(typeName.compareTo(ConsistsOf.NAME)==0) {
addRelationMetadataUsage(t);
addPropagationConstraintUsage(t);
}
addPropertyUsage(t, consistsOfType.getProperties());
break;
default:
break;
}
}
public Tree<T> getTree(AccessType accessType) {
return trees.get(accessType);
}
public UsageKnowledge<?> getModelTypesUsage(AccessType accessType) {
List<AccessType> modelTypes = Arrays.asList(AccessType.getModelTypes());
if(!modelTypes.contains(accessType)) {
throw new RuntimeException("Only ModelTypes are allowed, i.e. " + modelTypes.toString());
}
if(accessType == AccessType.PROPERTY) {
return propertyUsage;
}else {
return erTypesUsage.get(accessType);
}
}
public UsageKnowledge<LinkedEntity> getERTypesUsage(AccessType accessType) {
List<AccessType> erTypes = Arrays.asList(AccessType.getERTypes());
if(!erTypes.contains(accessType)) {
throw new RuntimeException("Only ERTypes are allowed, i.e. " + erTypes.toString());
}
return erTypesUsage.get(accessType);
}
public UsageKnowledge<Entry<String,PropertyDefinition>> getPropertyUsage(){
return propertyUsage;
}
public UsageKnowledge<LinkedEntity> getResourceUsage() {
return erTypesUsage.get(AccessType.RESOURCE);
}
public UsageKnowledge<LinkedEntity> getFacetUsage() {
return erTypesUsage.get(AccessType.FACET);
}
public UsageKnowledge<LinkedEntity> getIsRelatedToUsage() {
return erTypesUsage.get(AccessType.IS_RELATED_TO);
}
public UsageKnowledge<LinkedEntity> getConsistsOfUsage() {
return erTypesUsage.get(AccessType.CONSISTS_OF);
}
/**
* Return the type if it is contained in the Knowledge
* @param typeName the type we are looking for
* @return the Type
* @throws RuntimeException
*/
public T getTypeByName(String typeName) throws RuntimeException {
return getNodeByName(typeName).getNodeElement();
}
/**
* Return the node fro the type if it is contained in the Knowledge
* @param typeName the type we are looking for
* @return the Type
* @throws RuntimeException
*/
public Node<T> getNodeByName(String typeName) throws RuntimeException {
AccessType accessType = locate.get(typeName);
if(accessType==null) {
throw new RuntimeException("The type " + typeName + " is not contained in the Knowledge");
}
Tree<T> tree = trees.get(accessType);
return tree.getNodeByIdentifier(typeName);
}
}

View File

@ -0,0 +1,15 @@
package org.gcube.informationsystem.model.knowledge;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.tree.NodeInformation;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public interface TypeInformation<T> extends NodeInformation<T> {
public AccessType getAccessType(T t);
public T getRoot(AccessType accessType);
}

View File

@ -0,0 +1,21 @@
package org.gcube.informationsystem.model.knowledge;
import java.util.Collection;
import org.gcube.informationsystem.base.reference.AccessType;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public interface TypesDiscoverer<T> {
/**
* This function discover all available types of a certain
* AccessType. Allowed AccessTypes are only IS Model Types
* see {@link AccessType#getModelTypes()}
* @param accessType
* @return
*/
public Collection<T> discover(AccessType accessType);
}

View File

@ -0,0 +1,35 @@
package org.gcube.informationsystem.model.knowledge;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.gcube.informationsystem.base.reference.AccessType;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class UsageKnowledge<U> {
protected Map<String, List<U>> map;
public UsageKnowledge(AccessType accessType){
this.map = new LinkedHashMap<>();
}
public void add(String typeName, U u) {
List<U> list = map.get(typeName);
if(list==null) {
list = new ArrayList<>();
map.put(typeName, list);
}
list.add(u);
}
public List<U> getUsage(String typeName){
List<U> list = map.get(typeName);
return list;
}
}

View File

@ -0,0 +1,31 @@
package org.gcube.informationsystem.model.reference;
import java.util.Map;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
/**
* This interfaces is an helper to identify elements of the model
* i.e. Resource, Facet, IsRelatedTo, ConsistsOf
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY })
public interface ERElement extends IdentifiableElement, ModelElement {
/**
* Used when requested to include contexts in metadata.
* This is not a native property (it is just generated by server for administration clients convenience)
*/
public static final String CONTEXTS_PROPERTY = "contexts";
@JsonInclude(Include.NON_NULL)
@JsonGetter(value = CONTEXTS_PROPERTY)
public Map<UUID,String> getContexts();
}

View File

@ -0,0 +1,34 @@
package org.gcube.informationsystem.model.reference;
import java.util.List;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.informationsystem.base.reference.Element;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY })
public interface ModelElement extends Element {
public static final String SUPERTYPES_PROPERTY = "supertypes";
/*
* This is the key used by the deserializer to indicate the expected type
* which instead has been deserialized using the best available
* supertype
*/
public static final String EXPECTED_TYPE_PROPERTY = "expectedtype";
@JsonInclude(Include.NON_EMPTY)
@JsonGetter(value = SUPERTYPES_PROPERTY)
public List<String> getSupertypes();
@JsonInclude(Include.NON_EMPTY)
@JsonGetter(value = EXPECTED_TYPE_PROPERTY)
public String getExpectedtype();
}

View File

@ -3,20 +3,29 @@
*/
package org.gcube.informationsystem.model.reference.entities;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Entity
*
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Basic_Concepts
*/
@Abstract
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY })
//@JsonDeserialize(as=EntityImpl.class) Do not uncomment to manage subclasses
public interface Entity extends EntityElement {
@TypeMetadata(name = Entity.NAME, description = "This is the base type for any Entity", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface Entity extends EntityElement, ERElement {
public static final String NAME = "Entity"; //Entity.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Entities";
public static final String VERSION = "1.0.0";
}

View File

@ -6,20 +6,24 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.gcube.informationsystem.base.reference.SchemaMixedElement;
import org.gcube.informationsystem.serialization.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Facets
*
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Facet
*/
@Abstract
// @JsonDeserialize(as=FacetImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = "Facet", description = "This is the base type for any Facet", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface Facet extends Entity, SchemaMixedElement {
public static final String NAME = "Facet"; //Facet.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Facets";
public static final String VERSION = "1.0.0";
@JsonAnyGetter
@JsonSerialize(using = AdditionalPropertiesSerializer.class)

View File

@ -8,33 +8,43 @@ import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.RelatedResourcesEntry;
import org.gcube.informationsystem.types.annotations.ResourceSchema;
import org.gcube.informationsystem.types.annotations.ResourceSchemaEntry;
import org.gcube.informationsystem.types.annotations.ResourceSchemaRelatedEntry;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Resource
*
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Resources
*/
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY, Resource.CONSISTS_OF_PROPERTY, Resource.IS_RELATED_TO_PROPERTY })
// @JsonDeserialize(as=ResourceImpl.class) Do not uncomment to manage subclasses
@ResourceSchema(
facets={
@ResourceSchemaEntry(relation=ConsistsOf.class, facet=Facet.class, min=1, description="Any Resource consists of one or more Facets which describes the different aspects of the resource."),
},
resources= {
@ResourceSchemaRelatedEntry(source=Resource.class, relation=IsRelatedTo.class, target=Resource.class, description="Any Resource can be related to any other resource.")
@RelatedResourcesEntry(source=Resource.class, relation=IsRelatedTo.class, target=Resource.class, description="Any Resource can be related to any other resource.")
}
)
@TypeMetadata(name = Resource.NAME, description = "This is the base type for any Resource", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface Resource extends Entity {
public static final String NAME = "Resource"; //Resource.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Resources";
public static final String VERSION = "1.0.0";
public static final String CONSISTS_OF_PROPERTY = "consistsOf";
public static final String IS_RELATED_TO_PROPERTY = "isRelatedTo";

View File

@ -5,24 +5,27 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=EncryptedImpl.class)
@TypeMetadata(name = Encrypted.NAME, description = "This type is used to properly manage values must be stored safely (e.g. encrypted) in the IS.", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface Encrypted extends Property {
public static final String NAME = "Encrypted"; //Encrypted.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Encrypted values";
public static final String VERSION = "1.0.0";
public static final String NAME = "Encrypted"; // Encrypted.class.getSimpleName();
public static final String VALUE = "value";
@ISProperty(name=VALUE, readonly=false, mandatory=true, nullable=false)
@ISProperty(name=VALUE, readonly=false, mandatory=true, nullable=false, description = "The value to store safely in the IS")
@JsonGetter(value=VALUE)
public String getEncryptedValue();
public String getValue();
@JsonSetter(value=VALUE)
public void setEncryptedValue(String encryptedValue);
public void setValue(String value);
}

View File

@ -1,54 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.reference.properties;
import java.util.Date;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonFormat;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.types.annotations.ISProperty;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Header
*/
@JsonDeserialize(as=HeaderImpl.class)
public interface Header extends Property {
public static final String NAME = "Header"; // Header.class.getSimpleName();
/**
* Used to set Creator when the user is not known
*/
public static final String UNKNOWN_USER = "UNKNOWN_USER";
public static final String UUID_PROPERTY = "uuid";
public static final String CREATOR_PROPERTY = "creator";
public static final String MODIFIED_BY_PROPERTY = "modifiedBy";
public static final String CREATION_TIME_PROPERTY = "creationTime";
public static final String LAST_UPDATE_TIME_PROPERTY = "lastUpdateTime";
@ISProperty(name = UUID_PROPERTY, readonly = true, mandatory = true, nullable = false)
public UUID getUUID();
public void setUUID(UUID uuid);
@ISProperty(name = CREATOR_PROPERTY, readonly = true, mandatory = true, nullable = false)
public String getCreator();
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
@ISProperty(name = CREATION_TIME_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Date getCreationTime();
@ISProperty(name = MODIFIED_BY_PROPERTY, mandatory = true, nullable = false)
public String getModifiedBy();
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
@ISProperty(name = LAST_UPDATE_TIME_PROPERTY, mandatory = true, nullable = false)
public Date getLastUpdateTime();
}

View File

@ -0,0 +1,54 @@
/**
*
*/
package org.gcube.informationsystem.model.reference.properties;
import java.util.Date;
import org.gcube.com.fasterxml.jackson.annotation.JsonFormat;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=MetadataImpl.class)
@TypeMetadata(name = Metadata.NAME, description = "This type provides metadata per every IdentifiableElement", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@Final
public interface Metadata extends Property {
public static final String NAME = "Metadata"; // Metadata.class.getSimpleName();
/**
* Used to set Creator when the user is not known
*/
public static final String UNKNOWN_USER = "UNKNOWN_USER";
public static final String HIDDEN_FOR_PRIVACY_USER = "HIDDEN_FOR_PRIVACY";
public static final String CREATED_BY_PROPERTY = "createdBy";
public static final String CREATION_TIME_PROPERTY = "creationTime";
public static final String LAST_UPDATE_BY_PROPERTY = "lastUpdateBy";
public static final String LAST_UPDATE_TIME_PROPERTY = "lastUpdateTime";
@ISProperty(name = CREATED_BY_PROPERTY, description = "The user that created the Entity or the Relation. It is initialized at Creation Time.", readonly = true, mandatory = true, nullable = false)
public String getCreatedBy();
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
@ISProperty(name = CREATION_TIME_PROPERTY, description = "Creation time. It is represented in the format " + Element.DATETIME_PATTERN + ".", readonly = true, mandatory = true, nullable = false)
public Date getCreationTime();
@ISProperty(name = LAST_UPDATE_BY_PROPERTY, description = "The user that made the last update to the Entity or the Relation. At Creation Time, it assumes the same value of " + CREATED_BY_PROPERTY + ".", mandatory = true, nullable = false)
public String getLastUpdateBy();
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
@ISProperty(name = LAST_UPDATE_TIME_PROPERTY, description = "Last Update time. At creation time it assumes the same value of " + CREATION_TIME_PROPERTY + ". It is represented in the format " + Element.DATETIME_PATTERN, mandatory = true, nullable = false)
public Date getLastUpdateTime();
}

View File

@ -5,62 +5,124 @@ package org.gcube.informationsystem.model.reference.properties;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
* At any time entities and relations can be added or removed to/from a context or deleted.
* The PropagationConstraint property contained in each relation is a property
* which indicates the behaviour to be held on a target entity
* when an event related to a context occurs in the source resource
* or directly to the relation.
*
* The default values of propagation constraints are:
* - IsRelatedTo: delete=keep, remove=keep, add=unpropagate;
* - ConsistsOf : delete=cascade, remove=cascade, add=propagate.
*
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Propagation_Constraint
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=PropagationConstraintImpl.class)
@TypeMetadata(name = PropagationConstraint.NAME, description = "This type provides propagation constraint for Relation", version = "1.1.0")
@Change(version = "1.1.0", description = "Added 'delete' propagation constraint")
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@Final
public interface PropagationConstraint extends Property {
public static final String NAME = "PropagationConstraint"; // PropagationConstraint.class.getSimpleName();
public static final String REMOVE_PROPERTY = "remove";
public static final String ADD_PROPERTY = "add";
public enum RemoveConstraint {
/**
* When the source Entity is removed also the target
* Entity is removed but if and only if the latter has no other
* incoming Relation.
*/
cascadeWhenOrphan,
/**
* When the source Entity is removed also the target
* Entity is removed.
*/
cascade,
/**
* When the source Entity is removed the target Entity
* is keep.
*/
keep
}
public static final String DELETE_PROPERTY = "delete";
public static final String REMOVE_PROPERTY = "remove";
public enum AddConstraint {
/**
* When an 'add' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'add' action is performed on
* the relation and its target Entity.
*/
propagate,
/**
* When an 'add' action is performed on the source Entity of the relation,
* is performed on source relation only. Trying to perform an 'add' action on
* the relation has no effects.
*/
unpropagate
}
@ISProperty(name=REMOVE_PROPERTY)
public RemoveConstraint getRemoveConstraint();
public enum DeleteConstraint {
/**
* When a 'delete' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'delete' action apart on
* the relation is performed to the target entity if it has no other incoming relations
*/
cascadeWhenOrphan,
/**
* When a 'delete' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'delete' action is performed on
* the relation and its target entity;
*/
cascade,
/**
* When a 'delete' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'delete' action is performed on
* relation but never to the target entity.
*/
keep
}
public void setRemoveConstraint(RemoveConstraint removeConstraint);
@ISProperty(name=ADD_PROPERTY)
public enum RemoveConstraint {
/**
* When a 'remove' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'remove' action apart on
* the relation is performed to the target entity if it has no other incoming relations
*/
cascadeWhenOrphan,
/**
* When a 'remove' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'remove' action is performed on
* the relation and its target entity;
*/
cascade,
/**
* When a 'remove' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'remove' action is performed on
* relation but never to the target entity.
*/
keep
}
@ISProperty(name=ADD_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when an 'add' action is performed on the source Resource. Add action is the operation of adding an instance to a context.", mandatory = true, nullable = false)
public AddConstraint getAddConstraint();
public void setAddConstraint(AddConstraint addConstraint);
@ISProperty(name=DELETE_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when a 'delete' action is performed on the source Resource. Delet action is the operation of deleting an instance (it has an impact on all contexts).", mandatory = true, nullable = false)
public DeleteConstraint getDeleteConstraint();
public void setDeleteConstraint(DeleteConstraint deleteConstraint);
@ISProperty(name=REMOVE_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when a 'remove' action is performed on the source Resource. Remove actions is the operation of removing an instance from a context.", mandatory = true, nullable = false)
public RemoveConstraint getRemoveConstraint();
public void setRemoveConstraint(RemoveConstraint removeConstraint);
}

View File

@ -3,21 +3,51 @@
*/
package org.gcube.informationsystem.model.reference.properties;
import java.util.Map;
import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.SchemaMixedElement;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.model.impl.properties.PropertyImpl;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.serialization.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* Root Class for Property types.
* It creates a base common type, which is useful for management purpose.
*
* @author Luca Frosini (ISTI - CNR)
* Root Class for Property types. It creates a base common type, which is useful
* for management purpose.
*/
// @JsonIgnoreProperties(ignoreUnknown=true)
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY })
@JsonDeserialize(as=PropertyImpl.class)
public interface Property extends PropertyElement {
@TypeMetadata(name = Property.NAME, description = "This is the base type for any Property", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface Property extends PropertyElement, SchemaMixedElement, ModelElement {
public static final String NAME = "Property"; //Property.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Properties";
public static final String VERSION = "1.0.0";
@JsonAnyGetter
@JsonSerialize(using = AdditionalPropertiesSerializer.class)
@Override
public Map<String,Object> getAdditionalProperties();
@Override
public void setAdditionalProperties(Map<String,Object> additionalProperties);
@Override
public Object getAdditionalProperty(String key);
@JsonAnySetter
@Override
public void setAdditionalProperty(String key, Object value);
}

View File

@ -7,12 +7,18 @@ import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#ConsistsOf
*
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#consistsOf
*/
@JsonDeserialize(as=ConsistsOfImpl.class)
@TypeMetadata(name = ConsistsOf.NAME, description = "This is the base type for any ConsistsOf relation", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface ConsistsOf<S extends Resource, T extends Facet>
extends Relation<S, T> {

View File

@ -5,14 +5,19 @@ package org.gcube.informationsystem.model.reference.relations;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
* This Relation is for internal use only
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isRelatedTo
*
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#IsRelatedTo
*/
@Abstract
// @JsonDeserialize(as=IsRelatedToImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = IsRelatedTo.NAME, description = "This is the base type for any IsRelatedTo relation", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface IsRelatedTo<S extends Resource, T extends Resource>
extends Relation<S, T> {

View File

@ -10,28 +10,43 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.base.reference.SchemaMixedElement;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.serialization.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Relations
*
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Relation
*/
@Abstract
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY, Relation.PROPAGATION_CONSTRAINT_PROPERTY })
// @JsonDeserialize(as=RelationImpl.class) Do not uncomment to manage subclasses
public interface Relation<S extends Resource, T extends Entity> extends RelationElement<S,T>, SchemaMixedElement {
@TypeMetadata(name = Relation.NAME, description = "This is the base type for any Relation", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface Relation<S extends Resource, T extends Entity> extends RelationElement<S,T>, SchemaMixedElement, ERElement {
public static final String NAME = "Relation"; //Relation.class.getSimpleName();
public static final String PROPAGATION_CONSTRAINT = "propagationConstraint";
public static final String PROPAGATION_CONSTRAINT_PROPERTY = "propagationConstraint";
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties({Resource.CONSISTS_OF_PROPERTY, Resource.IS_RELATED_TO_PROPERTY})
@JsonGetter(value = SOURCE_PROPERTY)
@Override
@ -49,7 +64,8 @@ public interface Relation<S extends Resource, T extends Entity> extends Relation
@Override
public void setTarget(T target);
@ISProperty(name = PROPAGATION_CONSTRAINT)
@JsonGetter(value = PROPAGATION_CONSTRAINT_PROPERTY)
@ISProperty(name = PROPAGATION_CONSTRAINT_PROPERTY)
public PropagationConstraint getPropagationConstraint();
@JsonAnyGetter

View File

@ -0,0 +1,156 @@
package org.gcube.informationsystem.queries.templates.impl.entities;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.informationsystem.base.impl.entities.EntityElementImpl;
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=QueryTemplate.NAME)
public class QueryTemplateImpl extends EntityElementImpl implements QueryTemplate {
/**
* Generated Serial version UID
*/
private static final long serialVersionUID = -1096809036997782113L;
protected String name;
protected String description;
protected ObjectMapper objectMapper;
protected JsonNode template;
protected Map<String, TemplateVariable> templateVariables;
protected JsonNode params;
public QueryTemplateImpl() {
this.templateVariables = new HashMap<>();
this.objectMapper = new ObjectMapper();
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public String getDescription() {
return description;
}
@Override
public void setDescription(String description) {
this.description = description;
}
@Override
public String getTemplateAsString() throws JsonProcessingException {
return objectMapper.writeValueAsString(template);
}
@Override
public void setTemplate(String template) throws JsonProcessingException, IOException {
this.template = objectMapper.readTree(template);
}
@Override
public JsonNode getTemplate() {
return template;
}
@Override
public void setTemplate(JsonNode template) {
this.template = template;
}
@Override
public Map<String, TemplateVariable> getTemplateVariables() {
return templateVariables;
}
@Override
public void addTemplateVariable(TemplateVariable templateVariable) {
String name = templateVariable.getName();
this.templateVariables.put(name, templateVariable);
}
@Override
public ObjectNode getParamsFromDefaultValues() {
ObjectNode objectNode = objectMapper.createObjectNode();
for(TemplateVariable tv : templateVariables.values()) {
objectNode.put(tv.getName(), tv.getDefaultValue());
}
return objectNode;
}
@Override
public JsonNode getJsonQuery() throws Exception {
ObjectNode objectNode = getParamsFromDefaultValues();
return getJsonQuery(objectNode);
}
protected JsonNode replaceVariables(JsonNode jsonNode) throws Exception {
Iterator<String> fieldNames = jsonNode.fieldNames();
while(fieldNames.hasNext()) {
String fieldName = fieldNames.next();
JsonNode node = jsonNode.get(fieldName);
switch (node.getNodeType()) {
case OBJECT:
node = replaceVariables(node);
((ObjectNode) jsonNode).set(fieldName, node);
break;
case ARRAY:
ArrayNode arrayNode = (ArrayNode) node;
for(int i = 0; i < arrayNode.size(); i++) {
JsonNode arrayElement = arrayNode.get(i);
arrayElement = replaceVariables(arrayElement);
arrayNode.set(i, arrayElement);
}
break;
case STRING:
String value = node.asText();
if(templateVariables.containsKey(value)) {
JsonNode jn = params.get(value);
if(jn == null) {
throw new Exception("No value provided for " + value + " variables");
}
((ObjectNode) jsonNode).set(fieldName, jn);
}
break;
default:
break;
}
}
return jsonNode;
}
@Override
public JsonNode getJsonQuery(JsonNode values) throws Exception {
this.params = values;
JsonNode query = template.deepCopy();
query = replaceVariables(query);
return query;
}
}

View File

@ -0,0 +1,59 @@
/**
*
*/
package org.gcube.informationsystem.queries.templates.impl.properties;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.impl.properties.PropertyElementImpl;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=TemplateVariable.NAME)
public class TemplateVariableImpl extends PropertyElementImpl implements TemplateVariable {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 2628113641100130640L;
protected String name;
protected String description;
protected String defaultValue;
public TemplateVariableImpl() {
super();
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public String getDescription() {
return description;
}
@Override
public void setDescription(String description) {
this.description = description;
}
@Override
public String getDefaultValue() {
return defaultValue;
}
@Override
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
}

View File

@ -0,0 +1,99 @@
package org.gcube.informationsystem.queries.templates.reference.entities;
import java.io.IOException;
import java.util.Map;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.queries.templates.impl.entities.QueryTemplateImpl;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonIgnoreProperties(ignoreUnknown=true)
@JsonDeserialize(as=QueryTemplateImpl.class)
@TypeMetadata(name = QueryTemplate.NAME, description = "The type used to store Query Templates", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface QueryTemplate extends EntityElement {
public static final String NAME = "QueryTemplate"; //QueryTemplate.class.getSimpleName();
public static final String NAME_PROPERTY = "name";
public static final String DESCRIPTION_PROPERTY = "description";
public static final String TEMPLATE_PROPERTY = "template";
public static final String TEMPLATE_VARIABLES_PROPERTY = "templateVariables";
@ISProperty(name = NAME_PROPERTY, description = "The name of the Query Template. Among UUID univocally identifiy the Query Template.", readonly = true, mandatory = true, nullable = false)
public String getName();
public void setName(String name);
@ISProperty(name = DESCRIPTION_PROPERTY, description = "The description of the Query Template.", readonly = false, mandatory = true, nullable = false)
public String getDescription();
public void setDescription(String description);
@JsonIgnore
@ISProperty(name = TEMPLATE_PROPERTY, description = "The Query Template. It can contains query variables to be replaced to obtain a runnable query.", readonly = false, mandatory = true, nullable = false)
public String getTemplateAsString() throws JsonProcessingException;
@JsonIgnore
public void setTemplate(String template) throws JsonProcessingException, IOException;
@JsonSetter(value = TEMPLATE_PROPERTY)
public void setTemplate(JsonNode template);
@JsonGetter(value = TEMPLATE_PROPERTY)
public JsonNode getTemplate();
@JsonGetter(value = TEMPLATE_VARIABLES_PROPERTY)
@ISProperty(name = TEMPLATE_VARIABLES_PROPERTY, description = "The Query Template Variables. It can contains Query Template Variable to be replaced to obtain a runnable query.", readonly = false, mandatory = true, nullable = false)
public Map<String, TemplateVariable> getTemplateVariables();
@JsonIgnore
/**
* Adding variable which already exists, the previous value will be override.
* @param templateDefaultValue
*/
public void addTemplateVariable(TemplateVariable templateVariable);
/**
* Create an ObjectNode which can be used as parameters to obtain a
* JSON Query from the Query Template.
* It uses the default values provided in TemplateVariables.
* @return the created object node
*/
@JsonIgnore
public ObjectNode getParamsFromDefaultValues();
/**
* @return the JsonQuery replacing the variables using the default values contained in TemplateVariables
* @throws Exception
*/
@JsonIgnore
public JsonNode getJsonQuery() throws Exception;
/**
* @param values
* @return the JsonQuery replacing the variables using the provided values
* @throws Exception
*/
@JsonIgnore
public JsonNode getJsonQuery(JsonNode values) throws Exception;
}

View File

@ -0,0 +1,40 @@
package org.gcube.informationsystem.queries.templates.reference.properties;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.queries.templates.impl.properties.TemplateVariableImpl;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=TemplateVariableImpl.class)
@TypeMetadata(name = TemplateVariable.NAME, description = "This is the class used to define the a TemplateVariable", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface TemplateVariable extends PropertyElement {
public static final String NAME = "TemplateVariable"; // TemplateVariable.class.getSimpleName();
public static final String VARIABLE_NAME_PROPERTY = "name";
public static final String VARIABLE_DESCRIPTION_PROPERTY = "description";
public static final String VARIABLE_DEFAULT_VALUE_PROPERTY = "defaultValue";
@ISProperty(name = VARIABLE_NAME_PROPERTY, description = "The name of the Query Template Variable.", readonly = true, mandatory = true, nullable = false)
public String getName();
public void setName(String name);
@ISProperty(name = VARIABLE_DESCRIPTION_PROPERTY, description = "The description of the Query Template Variable.", readonly = false, mandatory = true, nullable = false)
public String getDescription();
public void setDescription(String description);
@ISProperty(name = VARIABLE_DEFAULT_VALUE_PROPERTY, description = "The default value of the Query Template Variable. The default value is used as is to the query. If the value needs quotation or escaping please include them to the default value", readonly = false, mandatory = true, nullable = false)
public String getDefaultValue();
public void setDefaultValue(String defaultValue);
}

View File

@ -1,4 +1,4 @@
package org.gcube.informationsystem.utils;
package org.gcube.informationsystem.serialization;
import java.io.IOException;
import java.util.Map;
@ -8,6 +8,9 @@ import org.gcube.com.fasterxml.jackson.databind.SerializerProvider;
import org.gcube.com.fasterxml.jackson.databind.ser.std.StdSerializer;
import org.gcube.informationsystem.model.reference.properties.Property;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class AdditionalPropertiesSerializer extends StdSerializer<Object>{
public AdditionalPropertiesSerializer() {

View File

@ -1,7 +1,7 @@
/**
*
*/
package org.gcube.informationsystem.utils;
package org.gcube.informationsystem.serialization;
import java.io.IOException;
import java.util.ArrayList;
@ -24,12 +24,15 @@ import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.types.TypeMapper;
/**
* This is not used anymore.
* Keeping the class in case something is not solved
* @author Luca Frosini (ISTI - CNR)
*
*/
@Deprecated
public class ElementDeserializer<ISM extends Element> extends StdDeserializer<ISM> {
private static final long serialVersionUID = -2551569658316955137L;
@ -58,10 +61,13 @@ public class ElementDeserializer<ISM extends Element> extends StdDeserializer<IS
List<TextNode> toBeKeepSuperClasses = new ArrayList<>();
ObjectNode objectNode = (ObjectNode) treeNode;
if(!objectNode.has(ModelElement.EXPECTED_TYPE_PROPERTY)) {
objectNode.set(ModelElement.EXPECTED_TYPE_PROPERTY, objectNode.get(Element.TYPE_PROPERTY));
}
try {
JsonNode superClassesTreeNode = objectNode
.get(Element.SUPERCLASSES_PROPERTY);
.get(ModelElement.SUPERTYPES_PROPERTY);
if (superClassesTreeNode != null
&& superClassesTreeNode.isArray()) {
ArrayNode arrayNode = (ArrayNode) superClassesTreeNode;
@ -121,7 +127,7 @@ public class ElementDeserializer<ISM extends Element> extends StdDeserializer<IS
@SuppressWarnings("unchecked")
String typeName = TypeMapper.getType((Class<? extends Element>) candidatedSuperClass);
objectNode.set(Element.CLASS_PROPERTY, new TextNode(typeName));
objectNode.set(Element.TYPE_PROPERTY, new TextNode(typeName));
JsonParser jsonParser = jsonFactory.createParser(objectNode
.toString());
jsonParser.nextToken();

View File

@ -0,0 +1,435 @@
package org.gcube.informationsystem.serialization;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gcube.com.fasterxml.jackson.core.JsonGenerationException;
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.com.fasterxml.jackson.databind.DeserializationFeature;
import org.gcube.com.fasterxml.jackson.databind.JavaType;
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.SerializationFeature;
import org.gcube.com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeType;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.discovery.Discovery;
import org.gcube.informationsystem.discovery.knowledge.Knowledge;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@SuppressWarnings("unchecked")
public abstract class ElementMapper {
private static Logger logger = LoggerFactory.getLogger(ElementMapper.class);
protected static final ObjectMapper mapper;
protected static final Map<String, Class<? extends Element>> knownTypes;
/**
* @return the ObjectMapper
*/
public static ObjectMapper getObjectMapper() {
return mapper;
}
static {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.getSerializationConfig().with(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
/*
* Instructing Jackson to serialize any Date in the defined pattern
*/
SimpleDateFormat sdf = new SimpleDateFormat(Element.DATETIME_PATTERN);
mapper.setDateFormat(sdf);
knownTypes = new HashMap<>();
List<Package> packages = new ArrayList<Package>();
Class<Type> tdClz = Type.class;
ElementMapper.registerSubtype(tdClz);
packages.add(tdClz.getPackage());
AccessType[] accessTypes = AccessType.values();
for(AccessType accessType : accessTypes) {
@SuppressWarnings("rawtypes")
Class clz = accessType.getTypeClass();
if(!Type.class.isAssignableFrom(clz)) {
Class<Element> dummyClz = accessType.getDummyImplementationClass();
if(dummyClz != null) {
// ElementMapper.registerSubtypes(clz, dummyClz);
ElementMapper.registerSubtype(dummyClz);
}else {
ElementMapper.registerSubtype(clz);
}
packages.add(clz.getPackage());
}
}
Set<AccessType> baseTypes = new LinkedHashSet<>();
baseTypes.add(AccessType.PROPERTY_ELEMENT);
baseTypes.add(AccessType.ENTITY_ELEMENT);
baseTypes.add(AccessType.RELATION_ELEMENT);
for(AccessType accessType : baseTypes) {
Class<Element> clz = accessType.getTypeClass();
try {
Discovery<? extends Element> discovery = new Discovery<>(clz);
discovery.addPackages(packages);
discovery.addDiscoveredElementActions(new ElementMappingAction());
discovery.discover();
}catch (Exception e) {
throw new RuntimeException(e);
}
}
try {
Knowledge.getInstance();
}catch (Exception e) {
throw new RuntimeException(e);
}
}
// This add the ElementDeserializer which has been deprecated thank to the fix in
// public static <El extends Element> void registerSubtypes(Class<El> clz, Class<El> implementationClass) {
// String typeName = TypeMapper.getType(clz);
// SimpleModule isModule = new SimpleModule(typeName);
// isModule.addDeserializer(clz, new ElementDeserializer<>(clz, mapper));
// mapper.registerModule(isModule);
// registerSubtype(implementationClass);
// }
public static <El extends Element> void registerSubtype(Class<El> clz) {
String typeName = TypeMapper.getType(clz);
knownTypes.put(typeName, clz);
mapper.registerSubtypes(clz);
}
/**
* Write the serialization of a given resource to a given
* {@link OutputStream} .
*
* @param object the resource
* @param stream the stream in input
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
public static <T extends OutputStream, El extends Element> T marshal(El object, T stream)
throws JsonGenerationException, JsonMappingException, IOException {
mapper.writeValue(stream, object);
return stream;
}
/**
* Write the serialization of a given resource to a given {@link Writer} .
* @param object the resource
* @param writer the writer in input
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
public static <T extends Writer, El extends Element> T marshal(El object, T writer)
throws JsonGenerationException, JsonMappingException, IOException {
mapper.writeValue(writer, object);
return writer;
}
/**
* Return the String serialization of a given object
* @param object the object to marshal
* @return the String serialization of a given resource
* @throws JsonProcessingException
*/
public static <El extends Element> String marshal(El object) throws JsonProcessingException {
return mapper.writeValueAsString(object);
}
/**
* Return the String serialization of a given list
* @param list the list to marshal
* @return the String serialization of a given list
* @throws JsonProcessingException
*/
public static <El extends Element> String marshal(List<El> list) throws JsonProcessingException {
JavaType type = mapper.getTypeFactory().constructCollectionType(List.class, Element.class);
return mapper.writerFor(type).writeValueAsString(list);
}
/**
* Return the String serialization of a given array
* @param array the array to marshal
* @return the String serialization of a given array
* @throws JsonProcessingException
*/
public static <El extends Element> String marshal(El[] array) throws JsonProcessingException {
return mapper.writeValueAsString(array);
}
protected static StringBuffer getError(String unknownType) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(unknownType);
stringBuffer.append(" is an unknown type. Please provide ");
stringBuffer.append(ModelElement.SUPERTYPES_PROPERTY);
stringBuffer.append(" property as string array to allow to instantiate the most appropriated class.");
return stringBuffer;
}
protected static ObjectNode setTypeToBestAvailable(ObjectNode objectNode) {
String unknownType = objectNode.get(Element.TYPE_PROPERTY).asText();
ArrayNode arrayNode = (ArrayNode) objectNode.get(ModelElement.SUPERTYPES_PROPERTY);
String candidatedSupertype = null;
if(arrayNode!=null) {
for(int i = 0; i < arrayNode.size(); i++) {
String superType = arrayNode.get(i).asText();
if(knownTypes.containsKey(superType)) {
candidatedSupertype = superType;
try {
// Checking if it is one of the base type. In some cases we need to use dummy
// implementation
AccessType accessType = AccessType.getAccessType(superType);
// It is one of the BaseType.
// Looking if we need to set the dummy implementation class
if(accessType.getDummyImplementationClass()!=null) {
// This should not happen because the type has been assigned already to the dummy class.
candidatedSupertype = accessType.getDummyImplementationClass().getSimpleName();
}
} catch(Exception ex) {
// can continue discovery
}
break;
}
}
}
if(candidatedSupertype!=null) {
if(!objectNode.has(ModelElement.EXPECTED_TYPE_PROPERTY)) {
objectNode.set(ModelElement.EXPECTED_TYPE_PROPERTY, objectNode.get(Element.TYPE_PROPERTY));
}
objectNode.set(Element.TYPE_PROPERTY, new TextNode(candidatedSupertype));
objectNode.remove(ModelElement.SUPERTYPES_PROPERTY);
return objectNode;
}
StringBuffer stringBuffer = getError(unknownType);
logger.trace("Unable to unmarshall {}. {}", objectNode.toString(), stringBuffer.toString());
throw new RuntimeException(stringBuffer.toString());
}
protected static JsonNode analizeTypes(ObjectNode objectNode) {
String cls = null;
JsonNode typeJN = objectNode.get(Element.TYPE_PROPERTY);
if(typeJN !=null) {
cls = objectNode.get(Element.TYPE_PROPERTY).asText();
}
if(cls==null && objectNode.getNodeType()==JsonNodeType.OBJECT) {
cls = Property.NAME;
}
if(!knownTypes.containsKey(cls)) {
objectNode = setTypeToBestAvailable(objectNode);
}
Iterator<String> iterator = objectNode.fieldNames();
while(iterator.hasNext()) {
String fieldName = iterator.next();
JsonNode jn = objectNode.get(fieldName);
switch (jn.getNodeType()) {
case OBJECT:
jn = analizeTypes((ObjectNode)jn);
break;
case ARRAY:
jn = analizeTypes((ArrayNode) jn);
break;
default:
break;
}
objectNode.replace(fieldName, jn);
}
return objectNode;
}
protected static ArrayNode analizeTypes(ArrayNode arrayNode) {
ArrayNode ret = mapper.createArrayNode();
for(JsonNode jsonNode : arrayNode) {
switch (jsonNode.getNodeType()) {
case OBJECT:
jsonNode = analizeTypes((ObjectNode) jsonNode);
break;
case ARRAY:
jsonNode = analizeTypes((ArrayNode) jsonNode);
break;
default:
break;
}
ret.add(jsonNode);
}
return ret;
}
/**
* Creates a resource of given class from its serialization in a given
* {@link Reader}.
* @param clz the class of the resource
* @param reader the reader
* @return the resource
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
*/
public static <El extends Element> El unmarshal(Class<El> clz, Reader reader)
throws JsonParseException, JsonMappingException, IOException {
try {
return mapper.readValue(reader, clz);
} catch (InvalidTypeIdException e) {
if(!ModelElement.class.isAssignableFrom(clz)) {
throw e;
}
JsonNode jsonNode = mapper.readTree(reader);
jsonNode = analizeTypes((ObjectNode) jsonNode);
try {
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
}catch (Throwable t) {
throw e;
}
}
}
/**
* Creates a resource of given class from its serialization in a given
* {@link InputStream}.
* @param clz the class of the resource
* @param stream the stream
* @return the resource
* @throws IOException
* @throws JsonMappingException
* @throws JsonParseException
*/
public static <El extends Element> El unmarshal(Class<El> clz, InputStream stream)
throws JsonParseException, JsonMappingException, IOException {
try {
return mapper.readValue(stream, clz);
} catch (InvalidTypeIdException e) {
if(!ModelElement.class.isAssignableFrom(clz)) {
throw e;
}
JsonNode jsonNode = mapper.readTree(stream);
jsonNode = analizeTypes((ObjectNode) jsonNode);
try {
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
}catch (Throwable t) {
throw e;
}
}
}
/**
* Creates a resource of given class from its serialization in a given String
* @param clz the class of the resource
* @param string
* @return the resource
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
*/
public static <El extends Element> El unmarshal(Class<El> clz, String string)
throws JsonParseException, JsonMappingException, IOException {
try {
return mapper.readValue(string, clz);
} catch (InvalidTypeIdException e) {
if(!ModelElement.class.isAssignableFrom(clz)) {
throw e;
}
JsonNode jsonNode = mapper.readTree(string);
jsonNode = analizeTypes((ObjectNode) jsonNode);
try {
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
}catch (Throwable t) {
throw e;
}
}
}
public static <El extends Element> List<El> unmarshalList(Class<El> clz, String string)
throws JsonParseException, JsonMappingException, IOException {
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, clz);
try {
return mapper.readValue(string, type);
} catch (InvalidTypeIdException e) {
if(!ModelElement.class.isAssignableFrom(clz)) {
throw e;
}
List<El> ret = new ArrayList<>();
ArrayNode arrayNode = (ArrayNode) mapper.readTree(string);
try {
for(JsonNode jsonNode : arrayNode) {
jsonNode = analizeTypes((ObjectNode) jsonNode);
ret.add(ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode)));
}
}catch (Throwable t) {
throw e;
}
return ret;
}
}
public static <El extends Element> List<El> unmarshalList(String string)
throws JsonParseException, JsonMappingException, IOException {
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, Element.class);
try {
return mapper.readValue(string, type);
} catch (InvalidTypeIdException e) {
List<El> ret = new ArrayList<>();
ArrayNode arrayNode = (ArrayNode) mapper.readTree(string);
try {
for(JsonNode jsonNode : arrayNode) {
jsonNode = analizeTypes((ObjectNode) jsonNode);
ret.add((El) ElementMapper.unmarshal(Element.class, mapper.writeValueAsString(jsonNode)));
}
}catch (Throwable t) {
throw e;
}
return ret;
}
}
}

View File

@ -0,0 +1,19 @@
/**
*
*/
package org.gcube.informationsystem.serialization;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.discovery.DiscoveredElementAction;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ElementMappingAction implements DiscoveredElementAction<Element> {
@Override
public void analizeElement(Class<Element> e) throws Exception {
ElementMapper.registerSubtype(e);
}
}

View File

@ -0,0 +1,123 @@
package org.gcube.informationsystem.tree;
import java.util.Set;
import java.util.TreeSet;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class Node<T> implements Comparable<Node<T>> {
public static String INDENTATION = "\t";
private T t;
private Tree<T> tree;
private Node<T> parent;
private Set<Node<T>> children;
public Node(T t) {
this.t = t;
this.children = new TreeSet<>();
}
public Tree<T> getTree() {
return tree;
}
void setTree(Tree<T> tree) {
this.tree = tree;
}
public T getNodeElement() {
return t;
}
public Node<T> getParent() {
return parent;
}
public Node<T> setParent(Node<T> parent) {
this.parent = parent;
return this;
}
public Node<T> addChild(Node<T> child) {
children.add(child);
child.setParent(this);
child.setTree(tree);
return this;
}
public Set<Node<T>> getChildrenNodes() {
return children;
}
public Set<T> getChildrenElement() {
Set<T> children = new TreeSet<>();
for (Node<T> child : this.children) {
children.add(child.t);
}
return children;
}
@Override
public String toString() {
return printTree(0).toString();
}
private StringBuffer printTree(int level) {
StringBuffer stringBuffer = new StringBuffer();
NodeElaborator<T> nodeElaborator = new NodeElaborator<T>() {
@Override
public void elaborate(Node<T> node, int level) throws Exception {
for (int i = 0; i < level; ++i) {
stringBuffer.append(Node.INDENTATION);
}
stringBuffer.append(tree.getNodeInformation().getIdentifier(node.getNodeElement()));
stringBuffer.append("\n");
}
};
try {
elaborate(nodeElaborator, level);
}catch (Exception e) {
throw new RuntimeException(e);
}
return stringBuffer;
}
@Override
public int compareTo(Node<T> other) {
if (this == other) {
return 0;
}
if (other == null) {
return -1;
}
if (getClass() != other.getClass()) {
return -1;
}
NodeInformation<T> ni = tree.getNodeInformation();
return ni.getIdentifier(t).compareTo(ni.getIdentifier(other.t));
}
public void elaborate(NodeElaborator<T> nodeElaborator) throws Exception {
elaborate(nodeElaborator, 0);
}
protected void elaborate(NodeElaborator<T> nodeElaborator, int level) throws Exception {
nodeElaborator.elaborate(this, level);
for (Node<T> child : children) {
child.elaborate(nodeElaborator, level+1);
}
}
}

View File

@ -0,0 +1,10 @@
package org.gcube.informationsystem.tree;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public interface NodeElaborator<T> {
public void elaborate(Node<T> node, int level) throws Exception;
}

View File

@ -0,0 +1,14 @@
package org.gcube.informationsystem.tree;
import java.util.Set;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public interface NodeInformation<T> {
public String getIdentifier(T t);
public Set<String> getParentIdentifiers(T root, T t);
}

View File

@ -0,0 +1,124 @@
package org.gcube.informationsystem.tree;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class Tree<T> {
private boolean allowMultipleInheritance;
private Node<T> rootNode;
private NodeInformation<T> ni;
private Map<String, Node<T>> locate;
public Tree() {
this.allowMultipleInheritance = true;
this.locate = new HashMap<>();
}
public Tree(NodeInformation<T> ni) {
this();
setNodeInformation(ni);
}
public Tree(T root, NodeInformation<T> ni) {
this(ni);
setRoot(root);
}
/**
* Set the NodeInformation if and only if it was not previously set.
* Otherwise this function has no effect.
* @param ni the NodeInformation to set
*/
public void setNodeInformation(NodeInformation<T> ni) {
if(this.ni==null) {
this.ni = ni;
}
}
/**
* Set the root if and only if it was not previously set.
* Otherwise this function has no effect.
* This function raises a RuntimeException is the
* NodeInformation was not previously set.
* @param root the root to set
*/
public void setRoot(T root) throws RuntimeException {
if(this.ni==null) {
throw new RuntimeException("You must set the NodeInformation instance first");
}
if(this.rootNode==null) {
this.rootNode = new Node<>(root);
this.rootNode.setTree(this);
String identifier = ni.getIdentifier(root);
this.locate.put(identifier, rootNode);
}
}
public void setAllowMultipleInheritance(boolean allowMultipleInheritance) {
this.allowMultipleInheritance = allowMultipleInheritance;
}
public NodeInformation<T> getNodeInformation() {
return ni;
}
public Node<T> addNode(T t) {
String identifier = ni.getIdentifier(t);
if(locate.containsKey(identifier)) {
// has been already added
return locate.get(identifier);
}
Node<T> node = new Node<>(t);
node.setTree(this);
Set<String> parentIdentifiers = ni.getParentIdentifiers(rootNode!= null ? rootNode.getNodeElement() : null, t);
if(parentIdentifiers==null || parentIdentifiers.size()==0) {
if(this.rootNode==null) {
this.rootNode = node;
}else {
throw new RuntimeException("A Tree cannot have two root. " + t.toString() + " has not parent.");
}
} else {
for(String parentIdentifier : parentIdentifiers) {
Node<T> parentNode = locate.get(parentIdentifier);
if(parentNode==null) {
throw new RuntimeException("I can find parent for " + identifier + ". Missing parent is " + parentIdentifier);
}
parentNode.addChild(node);
if(!allowMultipleInheritance) {
break;
}
}
}
this.locate.put(identifier, node);
return node;
}
public Node<T> getRootNode() {
return rootNode;
}
@Override
public String toString() {
return rootNode.toString();
}
public void elaborate(NodeElaborator<T> nodeElaborator) throws Exception {
rootNode.elaborate(nodeElaborator);
}
public Node<T> getNodeByIdentifier(String identifier){
return locate.get(identifier);
}
}

View File

@ -1,170 +0,0 @@
package org.gcube.informationsystem.types;
/*
*
* * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com)
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
* * For more information: http://www.orientechnologies.com
*
*/
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.gcube.informationsystem.model.reference.properties.Property;
/**
* @author Lucio Lelii (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
* Create a mapping with OrientDB Types
* https://orientdb.gitbooks.io/orientdb-manual/content/orientdb.wiki/Types.html
* and gCube IS Types
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Property
* The code is copied from OrientDB source Code
* https://github.com/orientechnologies/orientdb/blob/master/core/src/main/java/com/orientechnologies/orient/core/metadata/schema/OType.java
* and adapted for gCube purpose.
*/
public class OrientDBType {
public enum OType {
BOOLEAN("Boolean", 0),
INTEGER("Integer", 1),
SHORT("Short", 2),
LONG("Long", 3),
FLOAT("Float", 4),
DOUBLE("Double", 5),
DATETIME("Datetime", 6),
STRING("String", 7),
BYNARY("Bynary", 8),
PROPERTY("Property", 9),
PROPERTYLIST("Property List", 10),
PROPERTYSET("Property Set", 11),
PROPERTYMAP("Property Map", 12),
BYTE("Byte", 17),
BINARY("Binary", 8);
private String stringValue;
private int intValue;
OType(String stringValue, int intValue) {
this.stringValue = stringValue;
this.intValue = intValue;
}
public String getStringValue() {
return stringValue;
}
public int getIntValue() {
return intValue;
}
}
protected static final Map<Class<?>,OType> TYPES_BY_CLASS = new HashMap<Class<?>,OType>();
static {
// This is made by hand because not all types should be add.
TYPES_BY_CLASS.put(Boolean.TYPE, OType.BOOLEAN);
TYPES_BY_CLASS.put(Boolean.class, OType.BOOLEAN);
TYPES_BY_CLASS.put(Integer.TYPE, OType.INTEGER);
TYPES_BY_CLASS.put(Integer.class, OType.INTEGER);
TYPES_BY_CLASS.put(BigInteger.class, OType.INTEGER);
TYPES_BY_CLASS.put(Short.TYPE, OType.SHORT);
TYPES_BY_CLASS.put(Short.class, OType.SHORT);
TYPES_BY_CLASS.put(Long.TYPE, OType.LONG);
TYPES_BY_CLASS.put(Long.class, OType.LONG);
TYPES_BY_CLASS.put(Float.TYPE, OType.FLOAT);
TYPES_BY_CLASS.put(Float.class, OType.FLOAT);
TYPES_BY_CLASS.put(Double.TYPE, OType.DOUBLE);
TYPES_BY_CLASS.put(Double.class, OType.DOUBLE);
TYPES_BY_CLASS.put(Date.class, OType.DATETIME);
TYPES_BY_CLASS.put(Calendar.class, OType.DATETIME);
TYPES_BY_CLASS.put(String.class, OType.STRING);
TYPES_BY_CLASS.put(Character.class, OType.STRING);
TYPES_BY_CLASS.put(Character.TYPE, OType.STRING);
TYPES_BY_CLASS.put(Property.class, OType.PROPERTY);
TYPES_BY_CLASS.put(List.class, OType.PROPERTYLIST);
TYPES_BY_CLASS.put(Set.class, OType.PROPERTYSET);
TYPES_BY_CLASS.put(Map.class, OType.PROPERTYMAP);
TYPES_BY_CLASS.put(Byte.TYPE, OType.BYTE);
TYPES_BY_CLASS.put(Byte.class, OType.BYTE);
TYPES_BY_CLASS.put(byte[].class, OType.BYNARY);
TYPES_BY_CLASS.put(Byte[].class, OType.BYNARY);
TYPES_BY_CLASS.put(Enum.class, OType.STRING);
TYPES_BY_CLASS.put(URI.class, OType.STRING);
TYPES_BY_CLASS.put(URL.class, OType.STRING);
TYPES_BY_CLASS.put(UUID.class, OType.STRING);
}
/**
* Return the correspondent type by checking the "assignability" of the
* class received as parameter.
*
* @param iClass Class to check
* @return OType instance if found, otherwise null
*/
public static OType getTypeByClass(final Class<?> iClass) {
if(iClass == null) {
return null;
}
OType type = TYPES_BY_CLASS.get(iClass);
if(type == null && Enum.class.isAssignableFrom(iClass)) {
type = TYPES_BY_CLASS.get(Enum.class);
}
return type;
}
}

View File

@ -0,0 +1,396 @@
package org.gcube.informationsystem.types;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.utils.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class PropertyTypeName {
private static Logger logger = LoggerFactory.getLogger(PropertyTypeName.class);
public enum BaseTypeGroup {
ANY( BaseType.values()),
BOOLEAN( new BaseType[]{ BaseType.BOOLEAN } ),
NUMERIC( new BaseType[]{ BaseType.INTEGER, BaseType.SHORT, BaseType.LONG, BaseType.FLOAT }),
STRING( new BaseType[]{ BaseType.STRING }),
DATE( new BaseType[]{ BaseType.DATE } ),
BITS( new BaseType[]{ BaseType.BINARY, BaseType.BYTE } ),
COMPLEX( new BaseType[]{ BaseType.PROPERTY } ),
COLLECTION( new BaseType[]{ BaseType.LIST, BaseType.SET } ),
MAP( new BaseType[]{ BaseType.MAP });
private final BaseType[] group;
private BaseTypeGroup(BaseType[] group) {
this.group = group;
}
public BaseType[] getGroup() {
return group;
}
}
public enum BaseType {
BOOLEAN("Boolean"),
INTEGER("Integer"),
SHORT("Short"),
LONG("Long"),
FLOAT("Float"),
DOUBLE("Double"),
DATE("Date"),
STRING("String"),
BINARY("Binary"),
BYTE("Byte"),
/*
* All base types which DON'T have a generic must be defined BEFORE BaseType.PROPERTY
*/
PROPERTY("Property"),
/*
* All base types which have a generic must be defined AFTER BaseType.PROPERTY
*/
LIST("List"),
SET("Set"),
MAP("Map");
private final String stringValue;
BaseType(final String stringValue) {
this.stringValue = stringValue;
}
@Override
public String toString() {
return stringValue;
}
protected static final Map<String, BaseType> map;
static {
map = new HashMap<>();
for(BaseType baseType : BaseType.values()) {
map.put(baseType.stringValue, baseType);
}
}
public static BaseType getBaseTypeFromString(String type) {
BaseType baseType = map.get(type);
if(baseType==null) {
throw new IllegalArgumentException("No BaseType having '" + type + "' as string value. Allowed values are " + map.keySet());
}
return baseType;
}
}
protected static final Map<Class<?>,BaseType> BASE_PROPERTY_TYPES_BY_CLASS;
static {
BASE_PROPERTY_TYPES_BY_CLASS = new HashMap<>();
// This is made by hand because not all types should be add.
BASE_PROPERTY_TYPES_BY_CLASS.put(Boolean.TYPE, BaseType.BOOLEAN);
BASE_PROPERTY_TYPES_BY_CLASS.put(Boolean.class, BaseType.BOOLEAN);
BASE_PROPERTY_TYPES_BY_CLASS.put(Integer.TYPE, BaseType.INTEGER);
BASE_PROPERTY_TYPES_BY_CLASS.put(Integer.class, BaseType.INTEGER);
BASE_PROPERTY_TYPES_BY_CLASS.put(BigInteger.class, BaseType.INTEGER);
BASE_PROPERTY_TYPES_BY_CLASS.put(Short.TYPE, BaseType.SHORT);
BASE_PROPERTY_TYPES_BY_CLASS.put(Short.class, BaseType.SHORT);
BASE_PROPERTY_TYPES_BY_CLASS.put(Long.TYPE, BaseType.LONG);
BASE_PROPERTY_TYPES_BY_CLASS.put(Long.class, BaseType.LONG);
BASE_PROPERTY_TYPES_BY_CLASS.put(Float.TYPE, BaseType.FLOAT);
BASE_PROPERTY_TYPES_BY_CLASS.put(Float.class, BaseType.FLOAT);
BASE_PROPERTY_TYPES_BY_CLASS.put(Double.TYPE, BaseType.DOUBLE);
BASE_PROPERTY_TYPES_BY_CLASS.put(Double.class, BaseType.DOUBLE);
BASE_PROPERTY_TYPES_BY_CLASS.put(Date.class, BaseType.DATE);
BASE_PROPERTY_TYPES_BY_CLASS.put(Calendar.class, BaseType.DATE);
BASE_PROPERTY_TYPES_BY_CLASS.put(String.class, BaseType.STRING);
BASE_PROPERTY_TYPES_BY_CLASS.put(Character.TYPE, BaseType.STRING);
BASE_PROPERTY_TYPES_BY_CLASS.put(Character.class, BaseType.STRING);
BASE_PROPERTY_TYPES_BY_CLASS.put(Byte.TYPE, BaseType.BYTE);
BASE_PROPERTY_TYPES_BY_CLASS.put(Byte.class, BaseType.BYTE);
BASE_PROPERTY_TYPES_BY_CLASS.put(byte[].class, BaseType.BINARY);
BASE_PROPERTY_TYPES_BY_CLASS.put(Byte[].class, BaseType.BINARY);
BASE_PROPERTY_TYPES_BY_CLASS.put(PropertyElement.class, BaseType.PROPERTY);
BASE_PROPERTY_TYPES_BY_CLASS.put(List.class, BaseType.LIST);
BASE_PROPERTY_TYPES_BY_CLASS.put(Set.class, BaseType.SET);
BASE_PROPERTY_TYPES_BY_CLASS.put(Map.class, BaseType.MAP);
BASE_PROPERTY_TYPES_BY_CLASS.put(Enum.class, BaseType.STRING);
BASE_PROPERTY_TYPES_BY_CLASS.put(URI.class, BaseType.STRING);
BASE_PROPERTY_TYPES_BY_CLASS.put(URL.class, BaseType.STRING);
BASE_PROPERTY_TYPES_BY_CLASS.put(UUID.class, BaseType.STRING);
BASE_PROPERTY_TYPES_BY_CLASS.put(Version.class, BaseType.STRING);
}
/**
* Return the correspondent type by checking the "assignability" of the
* class received as parameter.
*
* @param clazz Class to check
* @return BasePropertyType instance if found, otherwise null
*/
public static BaseType getBaseTypeByClass(final Class<?> clazz) {
if(clazz == null) {
return null;
}
BaseType type = BASE_PROPERTY_TYPES_BY_CLASS.get(clazz);
if(type == null) {
for(Class<?> c : BASE_PROPERTY_TYPES_BY_CLASS.keySet()) {
if(c.isAssignableFrom(clazz)) {
type = BASE_PROPERTY_TYPES_BY_CLASS.get(c);
}
}
}
return type;
}
protected BaseType baseType;
protected boolean genericType;
protected BaseType genericBaseType;
protected String genericClassName;
public PropertyTypeName(String type) {
setType(type);
}
public PropertyTypeName(Method method) {
baseType = null;
genericType = false;
genericBaseType = null;
genericClassName = null;
Class<?> clz = method.getReturnType();
logger.trace("Return Type for method {} is {}", method, clz);
baseType = PropertyTypeName.getBaseTypeByClass(clz);
if(baseType == BaseType.PROPERTY){
if(clz != PropertyElement.class){
@SuppressWarnings("unchecked")
Class<? extends Element> type = (Class<? extends Element>) clz;
genericType = true;
genericClassName = TypeMapper.getType(type);
return;
}
}
if(baseType!=null) {
if(baseType.ordinal()>BaseType.PROPERTY.ordinal()){
genericType = true;
java.lang.reflect.Type genericReturnType = method.getGenericReturnType();
logger.trace("Generic Return Type for method {} is {}", method, genericReturnType);
java.lang.reflect.Type[] actualTypeArguments = ((ParameterizedType) genericReturnType).getActualTypeArguments();
java.lang.reflect.Type genericType = null;
for(java.lang.reflect.Type t : actualTypeArguments){
logger.trace("Generic Return Type {} for method {} - Actual Type Argument : {}", genericReturnType, method, t);
genericType = t;
}
genericBaseType = PropertyTypeName.getBaseTypeByClass((Class<?>) genericType);
if(genericBaseType!= null && genericBaseType.ordinal()>BaseType.PROPERTY.ordinal()) {
throw new IllegalArgumentException("The generic of a " + baseType.toString() + " cannot be a Set, a List or a Map.");
}
if(genericBaseType == BaseType.PROPERTY){
@SuppressWarnings("unchecked")
Class<? extends Element> genericElementType = (Class<? extends Element>) genericType;
genericClassName = TypeMapper.getType(genericElementType);
}
}
}else {
throw new IllegalArgumentException("Type " + clz.getSimpleName() + " not supported as property type");
}
}
public void setType(String type) {
int indexOfMinor = type.indexOf("<");
if(indexOfMinor == -1) {
genericType = false;
}else {
genericType = true;
}
if(!genericType) {
try {
baseType = BaseType.getBaseTypeFromString(type);
if(baseType.ordinal()>BaseType.PROPERTY.ordinal()) {
throw new IllegalArgumentException("Set, List and Map must specify a generic type, e.g. Set<Property>, List<Integer>.");
}
return;
}catch (IllegalArgumentException e) {
baseType = BaseType.PROPERTY;
genericType = true;
genericClassName = type;
return;
}
}
String cleanTypeFromGeneric = type.substring(0,indexOfMinor);
baseType = BaseType.getBaseTypeFromString(cleanTypeFromGeneric);
if(genericType) {
if(baseType.ordinal()<=BaseType.PROPERTY.ordinal()) {
throw new IllegalArgumentException("Only Set, List and Map can be generic. Map can only have String as Key");
}
}
// Getting the pat inside <....>
String generic = type.substring(indexOfMinor+1, type.length()-1);
if(baseType == BaseType.MAP) {
int l = generic.length();
generic = generic.replace(BaseType.STRING.toString() + ",", "");
if(l!=(BaseType.STRING.stringValue.length() + 1 + generic.length())) {
throw new IllegalArgumentException("A Map can only has String as key e.g. Map<String,Integer>");
}
}
try {
genericBaseType = BaseType.getBaseTypeFromString(generic);
}catch (IllegalArgumentException e) {
genericBaseType = BaseType.PROPERTY;
genericClassName = generic;
}
if(genericBaseType!= null && genericBaseType.ordinal()>BaseType.PROPERTY.ordinal()) {
throw new IllegalArgumentException("The generic of a " + baseType.toString() + " cannot be a Set, a List or a Map.");
}
}
public String getType() {
StringBuffer stringBuffer = new StringBuffer();
switch (baseType) {
case PROPERTY:
if(genericClassName != null) {
stringBuffer.append(genericClassName);
}else {
stringBuffer.append(baseType.toString());
}
break;
case SET: case LIST: case MAP:
stringBuffer.append(baseType.toString());
stringBuffer.append("<");
if(baseType == BaseType.MAP) {
stringBuffer.append(BaseType.STRING.toString());
stringBuffer.append(",");
}
if(genericClassName != null) {
stringBuffer.append(genericClassName);
}else {
stringBuffer.append(genericBaseType.toString());
}
stringBuffer.append(">");
break;
default:
stringBuffer.append(baseType.toString());
break;
}
return stringBuffer.toString();
}
@Override
public String toString() {
return getType();
}
public BaseType getBaseType() {
return baseType;
}
public boolean isGenericType() {
return genericType;
}
public BaseType getGenericBaseType() {
return genericBaseType;
}
public String getGenericClassName() {
return genericClassName;
}
@Override
public int hashCode() {
return Objects.hash(baseType, genericBaseType, genericClassName, genericType);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PropertyTypeName other = (PropertyTypeName) obj;
return baseType == other.baseType && genericBaseType == other.genericBaseType
&& Objects.equals(genericClassName, other.genericClassName) && genericType == other.genericType;
}
}

View File

@ -1,8 +1,10 @@
package org.gcube.informationsystem.types;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.com.fasterxml.jackson.databind.DeserializationFeature;
@ -10,7 +12,10 @@ import org.gcube.com.fasterxml.jackson.databind.JavaType;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.Changelog;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
@ -20,20 +25,19 @@ import org.gcube.informationsystem.types.reference.properties.PropertyType;
import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
import org.gcube.informationsystem.types.reference.relations.RelationType;
import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class TypeMapper {
private final static String NAME = "NAME";
protected static final ObjectMapper mapper;
static {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, false);
mapper.registerSubtypes(Type.class);
@ -48,10 +52,6 @@ public class TypeMapper {
mapper.registerSubtypes(PropertyType.class);
mapper.registerSubtypes(PropertyDefinition.class);
mapper.registerSubtypes(LinkedEntity.class);
// TODO
// mapper.registerSubtypes(LinkedResource.class);
// mapper.registerSubtypes(LinkedFacet.class);
}
public static String serializeTypeDefinition(Type type) throws Exception{
@ -59,7 +59,7 @@ public class TypeMapper {
return json;
}
public static Type deserializeTypeDefinition(String json) throws Exception{
public static Type deserializeTypeDefinition(String json) throws Exception {
Type type = mapper.readValue(json, Type.class);
return type;
}
@ -88,22 +88,117 @@ public class TypeMapper {
return serializeTypeDefinition(type);
}
public static String getType(Class<? extends Element> clz){
if(clz.isAnnotationPresent(JsonTypeName.class)) {
JsonTypeName jsonTypeName = clz.getAnnotation(JsonTypeName.class);
return jsonTypeName.value();
}
return getStaticStringFieldByName(clz, NAME, clz.getSimpleName());
public static <E extends Element> String getType(E e){
return getType(e.getClass());
}
public static String getStaticStringFieldByName(Class<? extends Element> clz, String fieldName, String defaultValue){
Field field;
try {
field = clz.getDeclaredField(fieldName);
field.setAccessible(true);
return (String) field.get(null);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
return defaultValue;
public static String getType(Class<? extends Element> clz){
String classSimpleName = clz.getSimpleName();
String name = null;
if(!clz.isInterface()) {
if(clz.isAnnotationPresent(JsonTypeName.class)) {
JsonTypeName jsonTypeName = clz.getAnnotation(JsonTypeName.class);
name = jsonTypeName.value();
if(name==null || name.compareTo("")==0) {
throw new RuntimeException("Invalid annotation @JsonTypeName for type " + classSimpleName);
}
return name;
}
}
if(clz.isAnnotationPresent(TypeMetadata.class)) {
TypeMetadata typeMetadata = clz.getAnnotation(TypeMetadata.class);
String typeMetadataName = typeMetadata.name();
if(typeMetadataName!=null && typeMetadataName.compareTo("")!=0) {
/*
if(name!=null && typeMetadataName.compareTo(name)!=0) {
throw new RuntimeException("Name in annotation @TypeMetadata differ from annotation in @JsonTypeName for type " + classSimpleName + ". Please be coerent");
}
*/
return typeMetadataName;
}else {
throw new RuntimeException("Invalid Name in annotation @TypeMetadata for type " + classSimpleName);
}
}else {
throw new RuntimeException("You must provide @TypeMetadata for " + classSimpleName);
}
}
public static String getTypeDescription(Class<? extends Element> clz){
String classSimpleName = clz.getSimpleName();
if(clz.isAnnotationPresent(TypeMetadata.class)) {
TypeMetadata typeMetadata = clz.getAnnotation(TypeMetadata.class);
String description = typeMetadata.description();
if(description!=null && description.compareTo("")!=0) {
return description;
}else {
throw new RuntimeException("Invalid Description in annotation @TypeMetadata for type " + classSimpleName);
}
}else {
throw new RuntimeException("You must provide @TypeMetadata for " + classSimpleName);
}
}
public static Version getTypeVersion(Class<? extends Element> clz){
String classSimpleName = clz.getSimpleName();
if(clz.isAnnotationPresent(TypeMetadata.class)) {
TypeMetadata typeMetadata = clz.getAnnotation(TypeMetadata.class);
return new Version(typeMetadata.version());
}else {
throw new RuntimeException("You must provide @TypeMetadata for " + classSimpleName);
}
}
public static Map<Version, String> getTypeChangelog(Class<? extends Element> clz){
Map<Version, String> map = new HashMap<>();
if(clz.isAnnotationPresent(Changelog.class)) {
Changelog changelog = clz.getAnnotation(Changelog.class);
Change[] changes = changelog.value();
for(Change change : changes) {
String version = change.version();
Version typeVersion = new Version(version);
if(map.containsKey(typeVersion)) {
throw new RuntimeException("Duplicated version " + version +" in @Change annotation");
}
String description = change.description();
if(description==null || description.compareTo("")==0) {
throw new RuntimeException("A valid description for version " + version +" must be provided in @Change annotation");
}
map.put(typeVersion, description);
}
}
if(!map.containsKey(Version.MINIMAL_VERSION)) {
map.putAll(TypeImpl.DEFAULT_CHANGELOG_MAP);
}
Version typeVersion = getTypeVersion(clz);
if (!map.containsKey(typeVersion)) {
throw new RuntimeException("The Type " + clz.getSimpleName() + " does not provided the appropriated changelog Map");
}
List<Version> versions = new ArrayList<>(map.keySet());
versions.sort(new Comparator<Version>() {
@Override
public int compare(Version o1, Version o2) {
/* o2.compareTo(o1) and not vice-versa
* because we want descending order
*/
return o2.compareTo(o1);
}
});
if(versions.get(0).compareTo(typeVersion)!=0) {
throw new RuntimeException("The Type declared version (i.e."+ typeVersion.toString() +") does not match the highest version declared in changelog (i.e. "+ versions.get(0) + "). Please fix your type.");
}
return map;
}
}

View File

@ -9,12 +9,13 @@ import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.relations.Relation;
/**
* @author Luca Frosini (ISTI - CNR)
* It indicates that the {@link Entity} or the {@link Relation} is abstract and
* cannot be instantiated.
* This is needed because the type definition is made with interface so that
* even used the java abstract keyword is useless because it cannot be retrieved
* using reflection (interfaces are always abstract)
*
* @author Luca Frosini (ISTI - CNR)
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)

View File

@ -0,0 +1,19 @@
package org.gcube.informationsystem.types.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.gcube.informationsystem.base.reference.Element;
/**
* It indicates that the {@link Element} is final and cannot be extended/derived.
* This is needed because the type definition is made with interface.
* @author Luca Frosini (ISTI - CNR)
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Final {
}

View File

@ -1,5 +1,6 @@
package org.gcube.informationsystem.types.annotations;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@ -10,12 +11,14 @@ import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
/**
* @author Luca Frosini (ISTI - CNR)
* It is used by {@link TypeMapper} to identify which getter method are
* related to and {@link Entity} {@link PropertyDefinition}.
* The name of the property is obtained by removing "get" or "is" from method
* name and lower casing the first letter.
*
* @author Luca Frosini (ISTI - CNR)
*/
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ISProperty {

View File

@ -13,15 +13,16 @@ import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
/**
* @author Luca Frosini (ISTI - CNR)
* It is used by {@link TypeMapper} to identify which getter method are
* related to and {@link Entity} {@link PropertyDefinition}.
* The name of the property is obtained by removing "get" or "is" from method
* name and lower casing the first letter.
*
* @author Luca Frosini (ISTI - CNR)
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ResourceSchemaRelatedEntry {
public @interface RelatedResourcesEntry {
@JsonProperty
Class<? extends Resource> source() default Resource.class;
@ -36,10 +37,4 @@ public @interface ResourceSchemaRelatedEntry {
@JsonProperty
String description() default "";
@JsonProperty
int min() default 0;
@JsonProperty
int max() default -1;
}

View File

@ -1,5 +1,6 @@
package org.gcube.informationsystem.types.annotations;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@ -8,11 +9,12 @@ import java.lang.annotation.Target;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ResourceSchema {
ResourceSchemaEntry[] facets() default {};
ResourceSchemaRelatedEntry[] resources() default {};
RelatedResourcesEntry[] resources() default {};
}

View File

@ -13,11 +13,12 @@ import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
/**
* @author Luca Frosini (ISTI - CNR)
* It is used by {@link TypeMapper} to identify which getter method are
* related to and {@link Entity} {@link PropertyDefinition}.
* The name of the property is obtained by removing "get" or "is" from method
* name and lower casing the first letter.
*
* @author Luca Frosini (ISTI - CNR)
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)

View File

@ -3,19 +3,28 @@ package org.gcube.informationsystem.types.impl;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.TypeVariable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.entities.EntityTypeImpl;
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
@ -23,135 +32,183 @@ import org.gcube.informationsystem.types.impl.properties.PropertyTypeImpl;
import org.gcube.informationsystem.types.impl.relations.RelationTypeImpl;
import org.gcube.informationsystem.types.reference.Type;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.utils.TypeUtility;
import org.gcube.informationsystem.utils.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class TypeImpl implements Type {
private static Logger logger = LoggerFactory.getLogger(TypeImpl.class);
/**
* Generated Serial version UID
*/
private static final long serialVersionUID = -4333954207969059451L;
public static final Map<Version, String> DEFAULT_CHANGELOG_MAP;
private static final Map<String, String> DEFAULT_CHANGELOG_MAP_KEY_AS_STRING;
public final static String DESCRIPTION = "DESCRIPTION";
static {
DEFAULT_CHANGELOG_MAP = new HashMap<>();
DEFAULT_CHANGELOG_MAP.put(new Version(Version.MINIMAL_VERSION_STRING), Version.MINIMAL_VERSION_DESCRIPTION);
DEFAULT_CHANGELOG_MAP_KEY_AS_STRING = new HashMap<>();
DEFAULT_CHANGELOG_MAP_KEY_AS_STRING.put(Version.MINIMAL_VERSION_STRING, Version.MINIMAL_VERSION_DESCRIPTION);
}
protected Header header;
protected UUID uuid;
protected Metadata metadata;
protected String name;
protected String description;
@JsonProperty(value="abstract")
protected Version version;
@JsonProperty(value = CHANGELOG_PROPERTY, required = false)
@JsonInclude(Include.NON_NULL)
protected Map<Version, String> changelog;
@JsonProperty(value = ABSTRACT_PROPERTY)
protected boolean abstractType;
protected Set<String> superClasses;
@JsonProperty(value = FINAL_PROPERTY)
protected boolean finalClass;
protected Set<String> extendedTypes;
protected Set<PropertyDefinition> properties;
protected <E extends Element> Set<String> retrieveSuperClasses(Class<? extends E> type, Class<E> baseClass, String topSuperClass){
protected <E extends Element> Set<String> retrieveSuperClasses(Class<? extends E> type, Class<E> baseClass,
String topSuperClass) {
Set<String> interfaceList = new HashSet<>();
if(type==baseClass){
if(topSuperClass!=null) {
if (type == baseClass) {
if (topSuperClass != null) {
interfaceList.add(topSuperClass);
}
return interfaceList;
}
Class<?>[] interfaces = type.getInterfaces();
for (Class<?> interfaceClass : interfaces) {
if(!baseClass.isAssignableFrom(interfaceClass)){
if (!baseClass.isAssignableFrom(interfaceClass)) {
continue;
}
@SuppressWarnings("unchecked")
Class<? extends Element> clz = (Class<? extends Element>) interfaceClass;
Class<? extends Element> clz = (Class<? extends Element>) interfaceClass;
interfaceList.add(TypeMapper.getType(clz));
}
return interfaceList;
}
protected Set<PropertyDefinition> retrieveListOfProperties(Class<?> type){
Set<PropertyDefinition> properties = new HashSet<>();
for (Method m : type.getDeclaredMethods()){
protected Set<PropertyDefinition> retrieveListOfProperties(Class<?> clz) {
Set<PropertyDefinition> properties = new TreeSet<>();
for (Method m : clz.getDeclaredMethods()) {
m.setAccessible(true);
if(m.isAnnotationPresent(ISProperty.class)){
if(m.isBridge()) {
if (m.isAnnotationPresent(ISProperty.class)) {
if (m.isBridge()) {
continue;
}
ISProperty propAnnotation = m.getAnnotation(ISProperty.class);
PropertyDefinition prop = new PropertyDefinitionImpl(propAnnotation, m);
properties.add(prop);
logger.trace("Property {} retrieved in type {} ", prop, type.getSimpleName());
}
logger.trace("Property {} retrieved in type {} ", prop, clz.getSimpleName());
}
}
if(properties.size()==0) {
properties = null;
}
return properties;
}
protected Class<?> getGenericClass(java.lang.reflect.Type type){
protected Class<?> getGenericClass(java.lang.reflect.Type type) {
TypeVariable<?> typeVariable = (TypeVariable<?>) type;
java.lang.reflect.Type[] bounds = typeVariable.getBounds();
java.lang.reflect.Type t = bounds[0];
if(t instanceof ParameterizedType) {
if (t instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) t;
return (Class<?>) parameterizedType.getRawType();
}
return (Class<?>) t;
return (Class<?>) t;
}
@SuppressWarnings({"rawtypes", "unchecked"})
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Type getInstance(Class<? extends Element> clz) {
Type typeDefinition = null;
try {
if(EntityElement.class.isAssignableFrom(clz)) {
if (EntityElement.class.isAssignableFrom(clz)) {
typeDefinition = EntityTypeImpl.getEntityTypeDefinitionInstance((Class<? extends EntityElement>) clz);
return typeDefinition;
} else if(RelationElement.class.isAssignableFrom(clz)){
typeDefinition = RelationTypeImpl.getRelationTypeDefinitionInstance((Class<? extends RelationElement<?,?>>) clz);
} else if (RelationElement.class.isAssignableFrom(clz)) {
typeDefinition = RelationTypeImpl
.getRelationTypeDefinitionInstance((Class<? extends RelationElement<?, ?>>) clz);
return typeDefinition;
} else if(PropertyElement.class.isAssignableFrom(clz)){
} else if (PropertyElement.class.isAssignableFrom(clz)) {
typeDefinition = new PropertyTypeImpl(clz);
return typeDefinition;
} else if(Type.class.isAssignableFrom(clz)) {
} else if (Type.class.isAssignableFrom(clz)) {
typeDefinition = new TypeImpl(clz);
return typeDefinition;
} else {
throw new RuntimeException("Serialization required");
}
} finally {
if(typeDefinition!=null) {
if (typeDefinition != null) {
logger.debug("{} : {} ", clz, typeDefinition);
}
}
}
protected TypeImpl() {
}
protected TypeImpl() {}
protected TypeImpl(Class<? extends Element> clz) {
this.name = TypeMapper.getType(clz);
this.description = TypeMapper.getStaticStringFieldByName(clz, DESCRIPTION, "");
this.abstractType = false;
this.description = TypeMapper.getTypeDescription(clz);
this.version = TypeMapper.getTypeVersion(clz);
this.changelog = TypeMapper.getTypeChangelog(clz);
if(clz.isAnnotationPresent(Abstract.class)){
this.abstractType = false;
if (clz.isAnnotationPresent(Abstract.class)) {
this.abstractType = true;
}
if(clz.isAnnotationPresent(Final.class)) {
this.finalClass = true;
}
}
@Override
public Header getHeader() {
return header;
public UUID getID() {
return uuid;
}
@Override
public void setID(UUID uuid) {
this.uuid = uuid;
}
@Override
public void setHeader(Header header){
this.header = header;
public Metadata getMetadata() {
return metadata;
}
@Override
public void setMetadata(Metadata metadata) {
this.metadata = metadata;
}
@Override
public String getName() {
return name;
@ -163,17 +220,79 @@ public class TypeImpl implements Type {
}
@Override
public boolean isAbstract() {
return abstractType;
public Version getVersion() {
return version;
}
@JsonGetter(value = VERSION_PROPERTY)
public String getVersionAsString() {
return version.toString();
}
@JsonSetter(value = VERSION_PROPERTY)
public void setVersion(String version) {
this.version = new Version(version);
}
@Override
public Set<String> getSuperClasses() {
return superClasses;
public Map<Version, String> getChangelog() {
return changelog;
}
@JsonGetter(value = CHANGELOG_PROPERTY)
@JsonInclude(Include.NON_NULL)
public Map<String, String> getChangelogWithVersionAsString() {
if(this.changelog==null) {
return DEFAULT_CHANGELOG_MAP_KEY_AS_STRING;
}
Map<String, String> map = new HashMap<>();
for (Version typeVersion : changelog.keySet()) {
map.put(typeVersion.toString(), changelog.get(typeVersion));
}
return map;
}
@JsonSetter(value=CHANGELOG_PROPERTY)
public void setChangelog(Map<String, String> changelog) {
if(changelog==null) {
this.changelog = DEFAULT_CHANGELOG_MAP;
return;
}
this.changelog = new HashMap<>();
for (String version : changelog.keySet()) {
this.changelog.put(new Version(version), changelog.get(version));
}
}
@Override
public boolean isAbstract() {
return abstractType;
}
@Override
public boolean isFinal() {
return finalClass;
}
@Override
public Set<String> getExtendedTypes() {
return extendedTypes;
}
@JsonInclude(Include.NON_EMPTY)
public Set<PropertyDefinition> getProperties() {
return properties;
}
@Override
@JsonIgnore
public AccessType getAccessType() {
return null;
}
@Override
public String getTypeName() {
return TypeUtility.getTypeName(this.getClass());
}
}

View File

@ -1,16 +1,23 @@
package org.gcube.informationsystem.types.impl.entities;
import java.io.StringWriter;
import java.util.HashSet;
import java.util.Set;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.informationsystem.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
/**
* @author Luca Frosini (ISTI - CNR)
@ -23,6 +30,16 @@ public class EntityTypeImpl extends TypeImpl implements EntityType {
*/
private static final long serialVersionUID = 2614315845213942880L;
private static Set<String> entityTypeAccesTypes;
static {
entityTypeAccesTypes = new HashSet<>();
entityTypeAccesTypes.add(EntityType.NAME);
entityTypeAccesTypes.add(ResourceType.NAME);
entityTypeAccesTypes.add(FacetType.NAME);
}
// private static final String VERTEX_CLASS_NAME = "V";
public static EntityType getEntityTypeDefinitionInstance(Class<? extends EntityElement> clz) {
@ -49,13 +66,17 @@ public class EntityTypeImpl extends TypeImpl implements EntityType {
if(EntityType.class.isAssignableFrom(clz)){
@SuppressWarnings("unchecked")
Class<? extends EntityType> c = (Class<? extends EntityType>) clz;
this.superClasses = retrieveSuperClasses(c, EntityType.class, EntityElement.NAME);
this.extendedTypes = retrieveSuperClasses(c, EntityType.class, EntityElement.NAME);
} else if(Context.class.isAssignableFrom(clz)){
@SuppressWarnings("unchecked")
Class<? extends Context> c = (Class<? extends Context>) clz;
this.superClasses = retrieveSuperClasses(c, Context.class, EntityElement.NAME);
this.extendedTypes = retrieveSuperClasses(c, Context.class, EntityElement.NAME);
} else if(QueryTemplate.class.isAssignableFrom(clz)){
@SuppressWarnings("unchecked")
Class<? extends QueryTemplate> c = (Class<? extends QueryTemplate>) clz;
this.extendedTypes = retrieveSuperClasses(c, QueryTemplate.class, EntityElement.NAME);
} else if(EntityElement.class.isAssignableFrom(clz)){
this.superClasses = retrieveSuperClasses(clz, EntityElement.class, null);
this.extendedTypes = retrieveSuperClasses(clz, EntityElement.class, null);
} else {
throw new RuntimeException("Type Hierachy Error for class " + clz.getSimpleName());
}
@ -70,16 +91,16 @@ public class EntityTypeImpl extends TypeImpl implements EntityType {
* We need to copy them.
*/
protected Header header;
protected Metadata metadata;
@Override
public Header getHeader() {
return header;
public Metadata getMetadata() {
return metadata;
}
@Override
public void setHeader(Header header){
this.header = header;
public void setMetadata(Metadata metadata){
this.metadata = metadata;
}
@Override
@ -90,12 +111,35 @@ public class EntityTypeImpl extends TypeImpl implements EntityType {
return stringWriter.toString();
}catch(Exception e){
try {
ElementMapper.marshal(this.header, stringWriter);
ElementMapper.marshal(this.metadata, stringWriter);
return stringWriter.toString();
} catch(Exception e1){
return super.toString();
}
}
}
@Override
@JsonIgnore
public AccessType getAccessType() {
if(name.compareTo(Context.NAME)==0) {
return AccessType.CONTEXT;
}
if(name.compareTo(EntityElement.NAME)==0) {
return AccessType.ENTITY_ELEMENT;
}
if(name.compareTo(QueryTemplate.NAME)==0) {
return AccessType.QUERY_TEMPLATE;
}
if(entityTypeAccesTypes.contains(name)) {
return AccessType.ENTITY_TYPE;
}
return AccessType.ENTITY;
}
}

View File

@ -2,7 +2,9 @@ package org.gcube.informationsystem.types.impl.entities;
import java.util.Set;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.types.reference.entities.FacetType;
@ -12,7 +14,7 @@ import org.gcube.informationsystem.types.reference.properties.PropertyDefinition
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=FacetType.NAME)
public class FacetTypeImpl extends EntityTypeImpl implements FacetType {
public final class FacetTypeImpl extends EntityTypeImpl implements FacetType {
/**
* Generated Serial Version UID
@ -27,7 +29,7 @@ public class FacetTypeImpl extends EntityTypeImpl implements FacetType {
public FacetTypeImpl(Class<? extends Facet> clz) {
super(clz);
this.superClasses = retrieveSuperClasses(clz, Facet.class, Entity.NAME);
this.extendedTypes = retrieveSuperClasses(clz, Facet.class, Entity.NAME);
this.properties = retrieveListOfProperties(clz);
}
@ -36,4 +38,10 @@ public class FacetTypeImpl extends EntityTypeImpl implements FacetType {
return properties;
}
@Override
@JsonIgnore
public AccessType getAccessType() {
return AccessType.FACET;
}
}

View File

@ -3,13 +3,15 @@ package org.gcube.informationsystem.types.impl.entities;
import java.util.ArrayList;
import java.util.List;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.annotations.ResourceSchema;
import org.gcube.informationsystem.types.annotations.ResourceSchemaEntry;
import org.gcube.informationsystem.types.annotations.ResourceSchemaRelatedEntry;
import org.gcube.informationsystem.types.annotations.RelatedResourcesEntry;
import org.gcube.informationsystem.types.impl.properties.LinkedEntityImpl;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
@ -18,7 +20,7 @@ import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=ResourceType.NAME)
public class ResourceTypeImpl extends EntityTypeImpl implements ResourceType {
public final class ResourceTypeImpl extends EntityTypeImpl implements ResourceType {
/**
* Generated Serial Version UID
@ -35,7 +37,7 @@ public class ResourceTypeImpl extends EntityTypeImpl implements ResourceType {
public ResourceTypeImpl(Class<? extends Resource> clz) {
super(clz);
this.superClasses = retrieveSuperClasses(clz, Resource.class, Entity.NAME);
this.extendedTypes = retrieveSuperClasses(clz, Resource.class, Entity.NAME);
setResourceSchemaEntries(clz);
}
@ -46,24 +48,28 @@ public class ResourceTypeImpl extends EntityTypeImpl implements ResourceType {
this.resources = new ArrayList<>();
ResourceSchema[] resourceSchemaArray = clz.getAnnotationsByType(ResourceSchema.class);
for(ResourceSchemaEntry resourceSchemaEntry : resourceSchemaArray[0].facets()) {
LinkedEntityImpl resourceSchemaEntryDefinition = new LinkedEntityImpl();
resourceSchemaEntryDefinition.setSource(TypeMapper.getType(clz));
resourceSchemaEntryDefinition.setRelation(TypeMapper.getType(resourceSchemaEntry.relation()));
resourceSchemaEntryDefinition.setTarget(TypeMapper.getType(resourceSchemaEntry.facet()));
resourceSchemaEntryDefinition.setDescription(resourceSchemaEntry.description());
resourceSchemaEntryDefinition.setMin(resourceSchemaEntry.min());
resourceSchemaEntryDefinition.setMax(resourceSchemaEntry.max());
this.facets.add(resourceSchemaEntryDefinition);
LinkedEntity linkedEntity = new LinkedEntityImpl();
linkedEntity.setSource(TypeMapper.getType(clz));
linkedEntity.setRelation(TypeMapper.getType(resourceSchemaEntry.relation()));
linkedEntity.setTarget(TypeMapper.getType(resourceSchemaEntry.facet()));
linkedEntity.setDescription(resourceSchemaEntry.description());
linkedEntity.setMin(resourceSchemaEntry.min());
linkedEntity.setMax(resourceSchemaEntry.max());
this.facets.add(linkedEntity);
}
for(ResourceSchemaRelatedEntry resourceSchemaRelatedEntry : resourceSchemaArray[0].resources()) {
LinkedEntity resourceSchemaEntryDefinition = new LinkedEntityImpl();
resourceSchemaEntryDefinition.setSource(TypeMapper.getType(resourceSchemaRelatedEntry.source()));
resourceSchemaEntryDefinition.setRelation(TypeMapper.getType(resourceSchemaRelatedEntry.relation()));
resourceSchemaEntryDefinition.setTarget(TypeMapper.getType(resourceSchemaRelatedEntry.target()));
resourceSchemaEntryDefinition.setDescription(resourceSchemaRelatedEntry.description());
resourceSchemaEntryDefinition.setMin(resourceSchemaRelatedEntry.min());
resourceSchemaEntryDefinition.setMax(resourceSchemaRelatedEntry.max());
this.resources.add(resourceSchemaEntryDefinition);
for(RelatedResourcesEntry resourceSchemaRelatedEntry : resourceSchemaArray[0].resources()) {
LinkedEntity linkedEntity = new LinkedEntityImpl();
linkedEntity.setSource(TypeMapper.getType(resourceSchemaRelatedEntry.source()));
linkedEntity.setRelation(TypeMapper.getType(resourceSchemaRelatedEntry.relation()));
linkedEntity.setTarget(TypeMapper.getType(resourceSchemaRelatedEntry.target()));
linkedEntity.setDescription(resourceSchemaRelatedEntry.description());
/*
* We cannot impose any constraint on related resources.
* The annotation are only for documentation purpose.
*/
linkedEntity.setMin(0);
linkedEntity.setMax(-1);
this.resources.add(linkedEntity);
}
}
}
@ -78,4 +84,10 @@ public class ResourceTypeImpl extends EntityTypeImpl implements ResourceType {
return resources;
}
@Override
@JsonIgnore
public AccessType getAccessType() {
return AccessType.RESOURCE;
}
}

View File

@ -3,6 +3,8 @@
*/
package org.gcube.informationsystem.types.impl.properties;
import java.util.Objects;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.impl.properties.PropertyElementImpl;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
@ -93,4 +95,75 @@ public final class LinkedEntityImpl extends PropertyElementImpl implements Linke
}
}
@Override
public int hashCode() {
return Objects.hash(source, relation, target, min, max, description);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
LinkedEntityImpl other = (LinkedEntityImpl) obj;
return Objects.equals(source, other.source) &&
Objects.equals(relation, other.relation) &&
Objects.equals(target, other.target) &&
Objects.equals(min, other.min) &&
Objects.equals(max, other.max) &&
Objects.equals(description, other.description);
}
protected int compareIntegers(Integer thisInt, Integer otherInt) {
Integer thisInteger = thisInt == null ? Integer.MAX_VALUE : thisInt;
Integer otherInteger = otherInt == null ? Integer.MAX_VALUE : otherInt;
return thisInteger.compareTo(otherInteger);
}
@Override
public int compareTo(LinkedEntity other) {
if (this == other) {
return 0;
}
if (other == null) {
return -1;
}
if (getClass() != other.getClass()) {
return -1;
}
LinkedEntityImpl o = (LinkedEntityImpl) other;
int ret = 0;
ret = source.compareTo(o.source);
if(ret != 0) {
return ret;
}
ret = relation.compareTo(o.relation);
if(ret != 0) {
return ret;
}
ret = target.compareTo(o.target);
if(ret != 0) {
return ret;
}
ret = compareIntegers(max, o.max);
if(ret != 0) {
return ret;
}
ret = compareIntegers(min, o.min);
if(ret != 0) {
return ret;
}
return description.compareTo(o.description);
}
}

View File

@ -1,24 +1,25 @@
package org.gcube.informationsystem.types.impl.properties;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.net.URI;
import java.net.URL;
import java.util.Objects;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.types.OrientDBType;
import org.gcube.informationsystem.types.OrientDBType.OType;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.PropertyTypeName;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.utils.TypeUtility;
import org.gcube.informationsystem.utils.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
// @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
@JsonTypeName(value=PropertyDefinition.NAME)
public final class PropertyDefinitionImpl implements PropertyDefinition {
@ -28,11 +29,11 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
*/
private static final long serialVersionUID = -5925314595659292025L;
private static Logger logger = LoggerFactory.getLogger(TypeImpl.class);
private static Logger logger = LoggerFactory.getLogger(PropertyDefinitionImpl.class);
public final static String UUID_PATTERN = "^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$";
public final static String URI_PATTERN = null;
public final static String URL_PATTERN = null;
public final static String UUID_REGEX = "^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$";
public final static String URI_REGEX = null;
public final static String URL_REGEX = null;
private String name= "";
private String description= "";
@ -42,9 +43,7 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
private Integer max= null;
private Integer min= null;
private String regexp= null;
private Integer linkedType = null;
private String linkedClass = null;
private Integer type=null;
private PropertyTypeName propertyTypeName = null;
private static String getPropertyNameFromMethodName(Method method){
String name = method.getName();
@ -74,75 +73,47 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
this.mandatory= propertyAnnotation.mandatory();
this.notnull = !propertyAnnotation.nullable();
this.readonly = propertyAnnotation.readonly();
if(propertyAnnotation.max()>0) this.max = propertyAnnotation.max();
if(propertyAnnotation.max()>=propertyAnnotation.min() && propertyAnnotation.min()>0) this.min = propertyAnnotation.min();
if(!propertyAnnotation.regexpr().isEmpty()) this.regexp = propertyAnnotation.regexpr();
logger.trace("Looking for property type {}", method.getReturnType());
@SuppressWarnings("unchecked")
Class<? extends Element> type = (Class<? extends Element>) method.getReturnType();
this.type = OType.PROPERTY.getIntValue();
if(PropertyElement.class.isAssignableFrom(type)){
if(type != PropertyElement.class){
this.linkedClass = TypeMapper.getType(type);
}
}else if (OrientDBType.getTypeByClass(type)!=null) {
this.type = OrientDBType.getTypeByClass(type).getIntValue();
if(this.type > 9 && this.type <= 12){
java.lang.reflect.Type genericReturnType = method.getGenericReturnType();
logger.trace("Generic Return Type {} for method {}", genericReturnType, method);
java.lang.reflect.Type[] actualTypeArguments = ((ParameterizedType) genericReturnType).getActualTypeArguments();
java.lang.reflect.Type genericType = null;
for(java.lang.reflect.Type t : actualTypeArguments){
logger.trace("Generic Return Type {} for method {} - Actual Type Argument : {}", genericReturnType, method, t);
genericType = t;
}
@SuppressWarnings("unchecked")
Class<? extends Element> genericClass = (Class<? extends Element>) genericType;
OType linkedOType = OrientDBType.getTypeByClass(genericClass);
if(linkedOType!=null){
this.linkedType = linkedOType.getIntValue();
}else{
this.linkedClass = TypeMapper.getType(genericClass);
}
}
if((this.regexp==null || this.regexp.compareTo("")==0 )&& this.type==OType.STRING.getIntValue()){
if(Enum.class.isAssignableFrom(type)){
Object[] constants = type.getEnumConstants();
StringBuilder stringBuilder = new StringBuilder("^(");
for(int i=0; i<constants.length; i++){
stringBuilder.append(constants[i].toString());
if(i<constants.length-1){
stringBuilder.append("|");
}
}
stringBuilder.append(")$");
this.regexp = stringBuilder.toString();
}
if(UUID.class.isAssignableFrom(type)){
this.regexp = UUID_PATTERN;
}
if(URI.class.isAssignableFrom(type)){
this.regexp = URI_PATTERN;
}
if(URL.class.isAssignableFrom(type)){
this.regexp = URL_PATTERN;
}
}
if(this.regexp!=null && this.regexp.compareTo("")==0){
this.regexp = null;
}
} else {
throw new RuntimeException("Type " + type.getSimpleName() + " not reconized");
if(propertyAnnotation.max()>0) {
this.max = propertyAnnotation.max();
}
if(propertyAnnotation.max()>=propertyAnnotation.min() && propertyAnnotation.min()>0) {
this.min = propertyAnnotation.min();
}
this.propertyTypeName = new PropertyTypeName(method);
Class<?> clz = method.getReturnType();
logger.trace("Return Type for method {} is {}", method, clz);
if(!propertyAnnotation.regexpr().isEmpty()) this.regexp = propertyAnnotation.regexpr();
if(this.regexp==null || this.regexp.compareTo("")==0 ){
if(Enum.class.isAssignableFrom(clz)){
Object[] constants = clz.getEnumConstants();
StringBuilder stringBuilder = new StringBuilder("^(");
for(int i=0; i<constants.length; i++){
stringBuilder.append(constants[i].toString());
if(i<constants.length-1){
stringBuilder.append("|");
}
}
stringBuilder.append(")$");
this.regexp = stringBuilder.toString();
}
if(UUID.class.isAssignableFrom(clz)){
this.regexp = UUID_REGEX;
}
if(URI.class.isAssignableFrom(clz)){
this.regexp = URI_REGEX;
}
if(URL.class.isAssignableFrom(clz)){
this.regexp = URL_REGEX;
}
if(Version.class.isAssignableFrom(clz)){
this.regexp = Version.VERSION_REGEX;
}
}
}
@Override
@ -186,26 +157,18 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
}
@Override
public Integer getLinkedType() {
return linkedType;
public String getPropertyType() {
return propertyTypeName.toString();
}
@Override
public String getLinkedClass() {
return linkedClass;
}
@Override
public Integer getType() {
return type;
@JsonSetter(value = PropertyDefinition.PROPERTY_TYPE_PROPERTY)
public void setPropertyType(String type) {
this.propertyTypeName = new PropertyTypeName(type);
}
@JsonIgnore
public String getTypeStringValue() {
if(type==null){
return null;
}
return OType.values()[type].getStringValue();
public PropertyTypeName getPropertyTypeName() {
return propertyTypeName;
}
@Override
@ -213,10 +176,115 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
return "Property [name=" + name + ", description=" + description
+ ", mandatory=" + mandatory + ", readonly=" + readonly
+ ", notnull=" + notnull + ", max=" + max + ", min="
+ min + ", regexpr=" + regexp + ", type = " + type
+ " (" + getTypeStringValue() + "), linkedType = " + linkedType + ", linkedClass = "
+ linkedClass + "]";
+ min + ", regexpr=" + regexp + ", type=" + propertyTypeName.toString() + "]";
}
@Override
public int hashCode() {
return Objects.hash(name, description, mandatory, readonly, notnull, max, min, regexp, propertyTypeName.toString());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
PropertyDefinitionImpl other = (PropertyDefinitionImpl) obj;
return Objects.equals(name, other.name) &&
Objects.equals(description, other.description) &&
mandatory == other.mandatory &&
readonly == other.readonly &&
notnull == other.notnull &&
Objects.equals(max, other.max) &&
Objects.equals(min, other.min) &&
Objects.equals(regexp, other.regexp) &&
Objects.equals(propertyTypeName.toString(), other.propertyTypeName.toString());
}
protected int compareIntegers(Integer thisInt, Integer otherInt) {
Integer thisInteger = thisInt == null ? Integer.MAX_VALUE : thisInt;
Integer otherInteger = otherInt == null ? Integer.MAX_VALUE : otherInt;
return thisInteger.compareTo(otherInteger);
}
@Override
public int compareTo(PropertyDefinition other) {
if (this == other) {
return 0;
}
if (other == null) {
return -1;
}
if (getClass() != other.getClass()) {
return -1;
}
PropertyDefinitionImpl o = (PropertyDefinitionImpl) other;
int ret = 0;
ret = name.compareTo(o.name);
if(ret != 0) {
return ret;
}
ret = description.compareTo(o.description);
if(ret != 0) {
return ret;
}
ret = Boolean.compare(mandatory, o.mandatory);
if(ret != 0) {
return ret;
}
ret = Boolean.compare(readonly, o.readonly);
if(ret != 0) {
return ret;
}
ret = Boolean.compare(notnull, o.notnull);
if(ret != 0) {
return ret;
}
ret = compareIntegers(max, o.max);
if(ret != 0) {
return ret;
}
ret = compareIntegers(min, o.min);
if(ret != 0) {
return ret;
}
if(regexp==null && o.regexp!=null) {
return -1;
}
if(o.regexp==null && regexp!=null) {
return -1;
}
if(!(regexp==null && o.regexp==null)) {
ret = regexp.compareTo(o.regexp);
if(ret != 0) {
return ret;
}
}
return propertyTypeName.toString().compareTo(o.propertyTypeName.toString());
}
@Override
public String getTypeName() {
return TypeUtility.getTypeName(this.getClass());
}
}

View File

@ -1,13 +1,23 @@
package org.gcube.informationsystem.types.impl.properties;
import java.io.StringWriter;
import java.util.HashSet;
import java.util.Set;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.types.reference.properties.PropertyType;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value = PropertyType.NAME)
public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
implements PropertyType<P> {
@ -19,14 +29,26 @@ public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
protected Set<PropertyDefinition> properties;
private static Set<String> propertyElementAccesTypes;
static {
propertyElementAccesTypes = new HashSet<>();
propertyElementAccesTypes.add(PropertyElement.NAME);
propertyElementAccesTypes.add(LinkedEntity.NAME);
propertyElementAccesTypes.add(TemplateVariable.NAME);
}
protected PropertyTypeImpl() {
super();
}
public PropertyTypeImpl(Class<P> clz) {
super(clz);
this.superClasses = retrieveSuperClasses(clz, PropertyElement.class,
this.extendedTypes = retrieveSuperClasses(clz, PropertyElement.class,
clz == PropertyElement.class ? null : PropertyElement.NAME);
this.properties = retrieveListOfProperties(clz);
}
@Override
@ -34,4 +56,39 @@ public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
return properties;
}
@Override
@JsonIgnore
public AccessType getAccessType() {
if(name.compareTo(PropertyType.NAME)==0) {
return AccessType.PROPERTY_TYPE;
}
if(name.compareTo(PropertyDefinition.NAME)==0) {
return AccessType.PROPERTY_DEFINITION;
}
if(propertyElementAccesTypes.contains(name)) {
return AccessType.PROPERTY_ELEMENT;
}
return AccessType.PROPERTY;
}
@Override
public String toString(){
StringWriter stringWriter = new StringWriter();
try {
ElementMapper.marshal(this, stringWriter);
return stringWriter.toString();
}catch(Exception e){
try {
ElementMapper.marshal(this.metadata, stringWriter);
return stringWriter.toString();
} catch(Exception e1){
return super.toString();
}
}
}
}

View File

@ -2,7 +2,9 @@ package org.gcube.informationsystem.types.impl.relations;
import java.lang.reflect.Type;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
@ -17,7 +19,7 @@ import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=ConsistsOfType.NAME)
public class ConsistsOfTypeImpl extends RelationTypeImpl<ResourceType, FacetType> implements ConsistsOfType {
public final class ConsistsOfTypeImpl extends RelationTypeImpl<ResourceType, FacetType> implements ConsistsOfType {
/**
* Generated Serial Version UID
@ -31,7 +33,7 @@ public class ConsistsOfTypeImpl extends RelationTypeImpl<ResourceType, FacetType
public ConsistsOfTypeImpl(Class<? extends ConsistsOf<? extends Resource, ? extends Facet>> clz) {
super(clz);
this.superClasses = retrieveSuperClasses(clz, ConsistsOf.class, Relation.NAME);
this.extendedTypes = retrieveSuperClasses(clz, ConsistsOf.class, Relation.NAME);
this.properties = retrieveListOfProperties(clz);
@ -56,4 +58,11 @@ public class ConsistsOfTypeImpl extends RelationTypeImpl<ResourceType, FacetType
this.source = new ResourceTypeImpl((Class<? extends Resource>) sourceClass);
this.target = new FacetTypeImpl((Class<? extends Facet>) targetClass);
}
@Override
@JsonIgnore
public AccessType getAccessType() {
return AccessType.CONSISTS_OF;
}
}

View File

@ -2,7 +2,9 @@ package org.gcube.informationsystem.types.impl.relations;
import java.lang.reflect.Type;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
@ -14,7 +16,7 @@ import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=IsRelatedToType.NAME)
public class IsRelatedToTypeImpl extends RelationTypeImpl<ResourceType, ResourceType> implements IsRelatedToType {
public final class IsRelatedToTypeImpl extends RelationTypeImpl<ResourceType, ResourceType> implements IsRelatedToType {
/**
* Generated Serial Version UID
@ -28,7 +30,7 @@ public class IsRelatedToTypeImpl extends RelationTypeImpl<ResourceType, Resource
public IsRelatedToTypeImpl(Class<? extends IsRelatedTo<? extends Resource, ? extends Resource>> clz) {
super(clz);
this.superClasses = retrieveSuperClasses(clz, IsRelatedTo.class, Relation.NAME);
this.extendedTypes = retrieveSuperClasses(clz, IsRelatedTo.class, Relation.NAME);
this.properties = retrieveListOfProperties(clz);
@ -53,4 +55,11 @@ public class IsRelatedToTypeImpl extends RelationTypeImpl<ResourceType, Resource
this.source = new ResourceTypeImpl((Class<? extends Resource>) sourceClass);
this.target = new ResourceTypeImpl((Class<? extends Resource>) targetClass);
}
@Override
@JsonIgnore
public AccessType getAccessType() {
return AccessType.IS_RELATED_TO;
}
}

Some files were not shown because too many files have changed in this diff Show More