Compare commits

...

138 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
127 changed files with 3895 additions and 1235 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,13 +2,34 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Information System Model
## [v7.1.0-SNAPSHOT]
- 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]
- Generalise the way the type of a property is defined [#20516]
- 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]

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>5.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.1.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,12 +1,13 @@
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)
@ -19,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
@ -43,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

@ -2,6 +2,7 @@ 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;
@ -11,7 +12,7 @@ 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.utils.ElementMapper;
import org.gcube.informationsystem.serialization.ElementMapper;
/**
* @author Luca Frosini (ISTI - CNR)
@ -24,21 +25,34 @@ 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;
@JsonIgnore
/**
* 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<>();
this.allowedAdditionalKeys.add(SUPERCLASSES_PROPERTY);
}
@Override
public List<String> getSupertypes() {
return this.supertypes;
}
@Override
public String getExpectedtype() {
return this.expectedtype;
}
@Override
public Map<String, Object> getAdditionalProperties() {
@ -75,7 +89,7 @@ public class PropertyElementImpl extends ElementImpl implements Property {
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

@ -1,10 +1,12 @@
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)
@ -17,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;
@ -25,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

@ -64,23 +64,24 @@ public enum AccessType {
ENTITY_ELEMENT(EntityElement.class, EntityElement.NAME, EntityElementImpl.class, null),
ENTITY_TYPE(EntityType.class, EntityType.NAME, EntityTypeImpl.class, null),
CONTEXT(Context.class, Context.NAME, ContextImpl.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),
RELATION(Relation.class, Relation.NAME, RelationImpl.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 {
@ -90,6 +91,17 @@ public enum AccessType {
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;
@ -179,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

@ -5,6 +5,8 @@ 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;
@ -15,21 +17,23 @@ 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 class for Element", version = Version.MINIMAL_VERSION_STRING)
@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,17 +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 Header}
* This interfaces is an helper to identify elements could be identified via {@link Metadata}
*
* @author Luca Frosini (ISTI - CNR)
*/
@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

@ -1,9 +1,12 @@
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;
@ -15,16 +18,26 @@ import org.gcube.informationsystem.utils.Version;
*/
@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 class for any EntityElement", version = Version.MINIMAL_VERSION_STRING)
@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

@ -14,7 +14,7 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=PropertyElementImpl.class)
@TypeMetadata(name = PropertyElement.NAME, description = "This is the base class for any PropertyElement", version = Version.MINIMAL_VERSION_STRING)
@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 {

View File

@ -1,11 +1,13 @@
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;
@ -17,7 +19,7 @@ import org.gcube.informationsystem.utils.Version;
*/
@Abstract
//@JsonDeserialize(as=RelationElementImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = RelationElement.NAME, description = "This is the base class for any RelationElement", version = Version.MINIMAL_VERSION_STRING)
@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 {
@ -26,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

@ -4,17 +4,25 @@
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.HeaderImpl;
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;
/**
@ -28,15 +36,31 @@ public final class ContextImpl extends EntityElementImpl implements Context {
*/
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) {
@ -47,9 +71,23 @@ public final class ContextImpl extends EntityElementImpl implements Context {
this();
this.name = name;
if(uuid == null){
uuid = UUIDManager.generateValidRandomUUID();
uuid = UUIDManager.getInstance().generateValidUUID();
}
this.header = new HeaderImpl(uuid);
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
@ -72,8 +110,8 @@ public final class ContextImpl extends EntityElementImpl implements Context {
public void setParent(UUID uuid) {
Context parent = null;
if(uuid!=null) {
parent = new ContextImpl();
parent.setHeader(new HeaderImpl(uuid));
parent = new ContextImpl(uuid);
parent.setMetadata(new MetadataImpl());
}
setParent(parent);
}
@ -121,8 +159,8 @@ public final class ContextImpl extends EntityElementImpl implements Context {
@Override
public void addChild(UUID uuid) {
Context child = new ContextImpl();
child.setHeader(new HeaderImpl(uuid));
Context child = new ContextImpl(uuid);
child.setMetadata(new MetadataImpl());
addChild(child);
}
@ -139,4 +177,55 @@ public final class ContextImpl extends EntityElementImpl implements Context {
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

@ -4,16 +4,25 @@
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;
@ -25,16 +34,62 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as = ContextImpl.class)
@TypeMetadata(name = Context.NAME, description = "This class is the used to define a Context", version = Version.MINIMAL_VERSION_STRING)
@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 {
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();
@ -62,5 +117,20 @@ public interface Context extends EntityElement {
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

@ -6,7 +6,10 @@ 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.contexts.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.contexts.reference.entities.Context;
@ -20,7 +23,8 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as = IsParentOfImpl.class)
@TypeMetadata(name = IsParentOf.NAME, description = "This class is the used to define parental relations between Context", version = Version.MINIMAL_VERSION_STRING)
@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> {

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,7 +5,7 @@ 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;
@ -14,7 +14,7 @@ import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@TypeMetadata(name = Facet.NAME, description = "This is a dummy class for Facet", version = Version.MINIMAL_VERSION_STRING)
@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 {
@ -25,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,7 +5,7 @@ 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;
@ -14,7 +14,7 @@ import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@TypeMetadata(name = Resource.NAME, description = "This is a dummy class for Resource", version = Version.MINIMAL_VERSION_STRING)
@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 {
@ -25,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

@ -4,49 +4,30 @@
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;
import org.gcube.informationsystem.model.reference.properties.Metadata;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=Header.NAME)
public final class HeaderImpl extends PropertyImpl implements Header {
@JsonTypeName(value=Metadata.NAME)
public final class MetadataImpl extends PropertyImpl implements Metadata {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 5102553511155113169L;
protected UUID uuid;
protected String createdBy;
protected Date creationTime;
protected String lastUpdateBy;
protected Date lastUpdateTime;
public HeaderImpl() {
public MetadataImpl() {
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 getCreatedBy() {
return createdBy;

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

@ -13,7 +13,7 @@ import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@TypeMetadata(name = IsRelatedTo.NAME, description = "This is a dummy class for IsRelatedTo", version = Version.MINIMAL_VERSION_STRING)
@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;
@ -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

@ -1,13 +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
* i.e. Resource, Facet, IsRelatedTo, ConsistsOf
*
* @author Luca Frosini (ISTI - CNR)
*/
public interface ERElement extends IdentifiableElement {
@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,8 +3,12 @@
*/
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;
@ -16,8 +20,9 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@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
@TypeMetadata(name = Entity.NAME, description = "This is the base class for Entities", version = Version.MINIMAL_VERSION_STRING)
@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 {

View File

@ -6,10 +6,10 @@ 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.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.utils.Version;
/**
@ -19,7 +19,7 @@ import org.gcube.informationsystem.utils.Version;
*/
@Abstract
// @JsonDeserialize(as=FacetImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = "Facet", description = "This is the base class for Facets", version = Version.MINIMAL_VERSION_STRING)
@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 {

View File

@ -8,12 +8,17 @@ 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.RelatedResourcesEntry;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
@ -25,6 +30,7 @@ import org.gcube.informationsystem.utils.Version;
*/
@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={
@ -34,7 +40,7 @@ import org.gcube.informationsystem.utils.Version;
@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 class for Resources", version = Version.MINIMAL_VERSION_STRING)
@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 {

View File

@ -13,18 +13,19 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=EncryptedImpl.class)
@TypeMetadata(name = Encrypted.NAME, description = "This is the base class for Encrypted values", version = Version.MINIMAL_VERSION_STRING)
@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 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

@ -4,64 +4,51 @@
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.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;
/**
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Header
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=HeaderImpl.class)
@TypeMetadata(name = Header.NAME, description = "This class provides metadata per every IdentifiableElement", version = Version.MINIMAL_VERSION_STRING)
@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)
public interface Header extends Property {
@Final
public interface Metadata extends Property {
public static final String NAME = "Header"; // Header.class.getSimpleName();
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 UUID_PROPERTY = "uuid";
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";
/**
* Used when requested to include contexts in header.
* This is not a native property (it is just generated by server for administration clients convenience)
*/
public static final String __CONTEXTS = "contexts";
@ISProperty(name = UUID_PROPERTY, description = "This UUID is be used to identify the Entity or the Relation univocally.", readonly = true, mandatory = true, nullable = false)
public UUID getUUID();
public void setUUID(UUID uuid);
@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)
@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 represents the difference, measured in milliseconds, between the creation time and midnight, January 1, 1970, UTC.", readonly = true, mandatory = true, nullable = false)
@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 creator.", mandatory = true, nullable = false)
@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 creationTime. It represents the difference, measured in milliseconds, between the creation time and midnight, January 1, 1970, UTC.", mandatory = true, nullable = false)
@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,6 +5,7 @@ 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;
@ -12,58 +13,37 @@ import org.gcube.informationsystem.utils.Version;
/**
* 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 predefined Property type
* 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 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: remove=keep, add=unpropagate;
* - ConsistsOf : remove=cascadeWhenOrphan, add=propagate.
* - 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 class provides propation constraint for Relation", version = Version.MINIMAL_VERSION_STRING)
@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 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
}
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
* or directly on the relation, then the same 'add' action is performed on
* the relation and its target Entity.
*/
propagate,
@ -77,17 +57,72 @@ public interface PropagationConstraint extends Property {
}
@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 are: (i) the operation of removing an instance from a context; (ii) the operation of deleting an instance (it has an impact on all contexts).", mandatory = true, nullable = false)
public RemoveConstraint getRemoveConstraint();
public void setRemoveConstraint(RemoveConstraint removeConstraint);
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 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

@ -7,14 +7,17 @@ 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.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.utils.Version;
/**
@ -24,10 +27,11 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
// @JsonIgnoreProperties(ignoreUnknown=true)
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY })
@JsonDeserialize(as=PropertyImpl.class)
@TypeMetadata(name = Property.NAME, description = "This is the base class for Properties", version = Version.MINIMAL_VERSION_STRING)
@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 {
public interface Property extends PropertyElement, SchemaMixedElement, ModelElement {
public static final String NAME = "Property"; //Property.class.getSimpleName();

View File

@ -17,7 +17,7 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=ConsistsOfImpl.class)
@TypeMetadata(name = ConsistsOf.NAME, description = "This is the base class for ConsistsOf relations", version = Version.MINIMAL_VERSION_STRING)
@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

@ -16,7 +16,7 @@ import org.gcube.informationsystem.utils.Version;
*/
@Abstract
// @JsonDeserialize(as=IsRelatedToImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = IsRelatedTo.NAME, description = "This is the base class for IsRelatedTo relations", version = Version.MINIMAL_VERSION_STRING)
@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,18 +10,24 @@ 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.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.utils.Version;
/**
@ -30,8 +36,9 @@ import org.gcube.informationsystem.utils.Version;
* 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
@TypeMetadata(name = Relation.NAME, description = "This is the base class for Relations", version = Version.MINIMAL_VERSION_STRING)
@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 {
@ -39,6 +46,7 @@ public interface Relation<S extends Resource, T extends Entity> extends Relation
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
@ -56,6 +64,7 @@ public interface Relation<S extends Resource, T extends Entity> extends Relation
@Override
public void setTarget(T target);
@JsonGetter(value = PROPAGATION_CONSTRAINT_PROPERTY)
@ISProperty(name = PROPAGATION_CONSTRAINT_PROPERTY)
public PropagationConstraint getPropagationConstraint();

View File

@ -1,4 +1,4 @@
package org.gcube.informationsystem.utils;
package org.gcube.informationsystem.serialization;
import java.io.IOException;
import java.util.Map;

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,11 +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;
@ -57,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;
@ -120,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

@ -1,4 +1,4 @@
package org.gcube.informationsystem.utils;
package org.gcube.informationsystem.serialization;
import java.io.IOException;
import java.io.InputStream;
@ -9,9 +9,10 @@ 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.ServiceLoader;
import java.util.Set;
import org.gcube.com.fasterxml.jackson.core.JsonGenerationException;
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
@ -21,18 +22,20 @@ 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.module.SimpleModule;
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.gcube.informationsystem.utils.discovery.ElementSpecilizationDiscovery;
import org.gcube.informationsystem.utils.discovery.RegistrationProvider;
import org.gcube.informationsystem.utils.discovery.SchemaAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -47,7 +50,7 @@ public abstract class ElementMapper {
protected static final ObjectMapper mapper;
protected static final Map<String, Class<? extends Element>> knownTypes;
//
/**
* @return the ObjectMapper
*/
@ -58,6 +61,7 @@ public abstract class ElementMapper {
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
@ -73,7 +77,6 @@ public abstract class ElementMapper {
ElementMapper.registerSubtype(tdClz);
packages.add(tdClz.getPackage());
AccessType[] accessTypes = AccessType.values();
for(AccessType accessType : accessTypes) {
@SuppressWarnings("rawtypes")
@ -81,7 +84,8 @@ public abstract class ElementMapper {
if(!Type.class.isAssignableFrom(clz)) {
Class<Element> dummyClz = accessType.getDummyImplementationClass();
if(dummyClz != null) {
ElementMapper.registerSubtypes(clz, dummyClz);
// ElementMapper.registerSubtypes(clz, dummyClz);
ElementMapper.registerSubtype(dummyClz);
}else {
ElementMapper.registerSubtype(clz);
}
@ -89,42 +93,40 @@ public abstract class ElementMapper {
}
}
registerPackages(packages);
Set<AccessType> baseTypes = new LinkedHashSet<>();
baseTypes.add(AccessType.PROPERTY_ELEMENT);
baseTypes.add(AccessType.ENTITY_ELEMENT);
baseTypes.add(AccessType.RELATION_ELEMENT);
ServiceLoader<? extends RegistrationProvider> regsitrationProviders = ServiceLoader
.load(RegistrationProvider.class);
for(RegistrationProvider registrationProvider : regsitrationProviders) {
registerPackages(registrationProvider.getPackagesToRegister());
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);
}
}
}
public static void registerPackages(List<Package> packages) {
SchemaAction schemaAction = new ElementMappingAction();
try {
ElementSpecilizationDiscovery.manageISM(schemaAction, packages);
} catch(Exception e) {
logger.error("Error registering types", e);
Knowledge.getInstance();
}catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void registerPackages(Package... packages) {
SchemaAction schemaAction = new ElementMappingAction();
try {
ElementSpecilizationDiscovery.manageISM(schemaAction, packages);
} catch(Exception e) {
logger.error("Error registering types", e);
}
}
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);
}
// 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);
@ -197,64 +199,111 @@ public abstract class ElementMapper {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(unknownType);
stringBuffer.append(" is an unknown type. Please provide ");
stringBuffer.append(Element.SUPERCLASSES_PROPERTY);
stringBuffer.append(ModelElement.SUPERTYPES_PROPERTY);
stringBuffer.append(" property as string array to allow to instantiate the most appropriated class.");
return stringBuffer;
}
protected static JsonNode setAvailableSuperclass(JsonNode jsonNode) {
String unknownType = jsonNode.get(Element.CLASS_PROPERTY).asText();
ArrayNode arrayNode = (ArrayNode) jsonNode.get(Element.SUPERCLASSES_PROPERTY);
protected static ObjectNode setTypeToBestAvailable(ObjectNode objectNode) {
String unknownType = objectNode.get(Element.TYPE_PROPERTY).asText();
ArrayNode arrayNode = (ArrayNode) objectNode.get(ModelElement.SUPERTYPES_PROPERTY);
// TODO save original class and superclasses
String candidatedSuperClass = null;
for(int i = 0; i < arrayNode.size(); i++) {
String superClass = arrayNode.get(i).asText();
if(knownTypes.containsKey(superClass)) {
candidatedSuperClass = superClass;
try {
// Checking if it is one of the base type. In some cases we need to use dummy
// implementation
AccessType accessType = Enum.valueOf(AccessType.class, superClass.toUpperCase());
// 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.
candidatedSuperClass = accessType.getDummyImplementationClass().getSimpleName();
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
}
} catch(Exception ex) {
// can continue discovery
break;
}
break;
}
}
if(candidatedSuperClass!=null) {
((ObjectNode) jsonNode).set(Element.CLASS_PROPERTY, new TextNode(candidatedSuperClass));
return jsonNode;
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 {}. {}", jsonNode.toString(), stringBuffer.toString());
logger.trace("Unable to unmarshall {}. {}", objectNode.toString(), stringBuffer.toString());
throw new RuntimeException(stringBuffer.toString());
}
protected static JsonNode analizeFullJson(JsonNode jsonNode) {
String cls = jsonNode.get(Element.CLASS_PROPERTY).asText();
if(!knownTypes.containsKey(cls)) {
jsonNode = setAvailableSuperclass(jsonNode);
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();
}
Iterator<String> iterator = jsonNode.fieldNames();
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 = jsonNode.get(fieldName);
if(jn.getNodeType() == JsonNodeType.OBJECT) {
jn = analizeFullJson(jn);
((ObjectNode) jsonNode).set(fieldName, jn);
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 jsonNode;
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;
}
/**
@ -271,10 +320,17 @@ public abstract class ElementMapper {
throws JsonParseException, JsonMappingException, IOException {
try {
return mapper.readValue(reader, clz);
} catch (JsonMappingException e) {
} catch (InvalidTypeIdException e) {
if(!ModelElement.class.isAssignableFrom(clz)) {
throw e;
}
JsonNode jsonNode = mapper.readTree(reader);
jsonNode = analizeFullJson(jsonNode);
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
jsonNode = analizeTypes((ObjectNode) jsonNode);
try {
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
}catch (Throwable t) {
throw e;
}
}
}
@ -292,10 +348,17 @@ public abstract class ElementMapper {
throws JsonParseException, JsonMappingException, IOException {
try {
return mapper.readValue(stream, clz);
} catch (JsonMappingException e) {
} catch (InvalidTypeIdException e) {
if(!ModelElement.class.isAssignableFrom(clz)) {
throw e;
}
JsonNode jsonNode = mapper.readTree(stream);
jsonNode = analizeFullJson(jsonNode);
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
jsonNode = analizeTypes((ObjectNode) jsonNode);
try {
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
}catch (Throwable t) {
throw e;
}
}
}
@ -312,11 +375,18 @@ public abstract class ElementMapper {
throws JsonParseException, JsonMappingException, IOException {
try {
return mapper.readValue(string, clz);
} catch (JsonMappingException e) {
} catch (InvalidTypeIdException e) {
if(!ModelElement.class.isAssignableFrom(clz)) {
throw e;
}
JsonNode jsonNode = mapper.readTree(string);
jsonNode = analizeFullJson(jsonNode);
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
}
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)
@ -324,12 +394,19 @@ public abstract class ElementMapper {
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, clz);
try {
return mapper.readValue(string, type);
} catch (JsonMappingException e) {
} catch (InvalidTypeIdException e) {
if(!ModelElement.class.isAssignableFrom(clz)) {
throw e;
}
List<El> ret = new ArrayList<>();
ArrayNode arrayNode = (ArrayNode) mapper.readTree(string);
for(JsonNode jsonNode : arrayNode) {
jsonNode = analizeFullJson(jsonNode);
ret.add(ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode)));
try {
for(JsonNode jsonNode : arrayNode) {
jsonNode = analizeTypes((ObjectNode) jsonNode);
ret.add(ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode)));
}
}catch (Throwable t) {
throw e;
}
return ret;
}
@ -340,12 +417,16 @@ public abstract class ElementMapper {
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, Element.class);
try {
return mapper.readValue(string, type);
} catch (JsonMappingException e) {
} catch (InvalidTypeIdException e) {
List<El> ret = new ArrayList<>();
ArrayNode arrayNode = (ArrayNode) mapper.readTree(string);
for(JsonNode jsonNode : arrayNode) {
jsonNode = analizeFullJson(jsonNode);
ret.add((El) ElementMapper.unmarshal(Element.class, mapper.writeValueAsString(jsonNode)));
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

@ -27,6 +27,30 @@ 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"),

View File

@ -1,6 +1,7 @@
package org.gcube.informationsystem.types;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -181,35 +182,23 @@ public class TypeMapper {
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;
}
/*
private final static String NAME = "NAME";
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;
}
}
@SuppressWarnings("unchecked")
public static <O extends Object> O getStaticFieldByName(Class<? extends Element> clz, String fieldName, O defaultValue){
Field field;
try {
field = clz.getDeclaredField(fieldName);
field.setAccessible(true);
return (O) field.get(null);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
return defaultValue;
}
}
*/
}

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

@ -7,6 +7,8 @@ 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;
@ -19,9 +21,10 @@ 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;
@ -29,6 +32,7 @@ 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;
@ -45,12 +49,6 @@ public class TypeImpl implements Type {
*/
private static final long serialVersionUID = -4333954207969059451L;
/*
public final static String DESCRIPTION = "DESCRIPTION";
public final static String VERSION = "VERSION";
public final static String CHANGELOG = "CHANGELOG";
*/
public static final Map<Version, String> DEFAULT_CHANGELOG_MAP;
private static final Map<String, String> DEFAULT_CHANGELOG_MAP_KEY_AS_STRING;
@ -61,9 +59,9 @@ public class TypeImpl implements Type {
DEFAULT_CHANGELOG_MAP_KEY_AS_STRING.put(Version.MINIMAL_VERSION_STRING, Version.MINIMAL_VERSION_DESCRIPTION);
}
protected UUID uuid;
protected Metadata metadata;
protected Header header;
protected String name;
protected String description;
protected Version version;
@ -71,9 +69,13 @@ public class TypeImpl implements Type {
@JsonInclude(Include.NON_NULL)
protected Map<Version, String> changelog;
@JsonProperty(value = "abstract")
@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;
@ -104,9 +106,9 @@ public class TypeImpl implements Type {
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()) {
@ -115,7 +117,7 @@ public class TypeImpl implements Type {
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());
}
}
@ -181,16 +183,30 @@ public class TypeImpl implements Type {
this.abstractType = true;
}
if(clz.isAnnotationPresent(Final.class)) {
this.finalClass = true;
}
}
@Override
public UUID getID() {
return uuid;
}
@Override
public Header getHeader() {
return header;
public void setID(UUID uuid) {
this.uuid = uuid;
}
@Override
public Metadata getMetadata() {
return metadata;
}
@Override
public void setHeader(Header header) {
this.header = header;
public void setMetadata(Metadata metadata) {
this.metadata = metadata;
}
@Override
@ -252,10 +268,15 @@ public class TypeImpl implements Type {
public boolean isAbstract() {
return abstractType;
}
@Override
public boolean isFinal() {
return finalClass;
}
@Override
public Set<String> getSuperClasses() {
return superClasses;
public Set<String> getExtendedTypes() {
return extendedTypes;
}
@JsonInclude(Include.NON_EMPTY)
@ -268,5 +289,10 @@ public class TypeImpl implements Type {
public AccessType getAccessType() {
return null;
}
@Override
public String getTypeName() {
return TypeUtility.getTypeName(this.getClass());
}
}

View File

@ -11,13 +11,13 @@ import org.gcube.informationsystem.base.reference.entities.EntityElement;
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.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
import org.gcube.informationsystem.utils.ElementMapper;
/**
* @author Luca Frosini (ISTI - CNR)
@ -66,17 +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.superClasses = retrieveSuperClasses(c, QueryTemplate.class, EntityElement.NAME);
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());
}
@ -91,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
@ -111,7 +111,7 @@ 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();

View File

@ -14,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
@ -29,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);
}

View File

@ -20,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
@ -37,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);
}

View File

@ -117,4 +117,53 @@ public final class LinkedEntityImpl extends PropertyElementImpl implements Linke
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

@ -12,6 +12,7 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.types.PropertyTypeName;
import org.gcube.informationsystem.types.annotations.ISProperty;
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;
@ -42,7 +43,6 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
private Integer max= null;
private Integer min= null;
private String regexp= null;
private PropertyTypeName propertyTypeName = null;
private static String getPropertyNameFromMethodName(Method method){
@ -157,12 +157,12 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
}
@Override
public String getType() {
public String getPropertyType() {
return propertyTypeName.toString();
}
@JsonSetter(value = PropertyDefinition.TYPE_PROPERTY)
public void setType(String type) {
@JsonSetter(value = PropertyDefinition.PROPERTY_TYPE_PROPERTY)
public void setPropertyType(String type) {
this.propertyTypeName = new PropertyTypeName(type);
}
@ -181,24 +181,110 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
@Override
public int hashCode() {
return Objects.hash(description, mandatory, max, min, name, notnull, propertyTypeName.toString(), readonly, regexp);
return Objects.hash(name, description, mandatory, readonly, notnull, max, min, regexp, propertyTypeName.toString());
}
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
PropertyDefinitionImpl other = (PropertyDefinitionImpl) obj;
return Objects.equals(description, other.description) && mandatory == other.mandatory
&& Objects.equals(max, other.max) && Objects.equals(min, other.min) && Objects.equals(name, other.name)
&& notnull == other.notnull && Objects.equals(propertyTypeName.toString(), other.propertyTypeName.toString())
&& readonly == other.readonly && Objects.equals(regexp, other.regexp);
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,5 +1,6 @@
package org.gcube.informationsystem.types.impl.properties;
import java.io.StringWriter;
import java.util.HashSet;
import java.util.Set;
@ -8,6 +9,7 @@ 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;
@ -43,7 +45,7 @@ public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
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);
@ -72,4 +74,21 @@ public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
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

@ -19,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
@ -33,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);

View File

@ -16,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
@ -30,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);

View File

@ -1,5 +1,6 @@
package org.gcube.informationsystem.types.impl.relations;
import java.io.StringWriter;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@ -13,6 +14,7 @@ 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.serialization.ElementMapper;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.impl.entities.EntityTypeImpl;
import org.gcube.informationsystem.types.reference.entities.EntityType;
@ -56,13 +58,13 @@ public class RelationTypeImpl<S extends EntityType, T extends EntityType>
if(RelationType.class.isAssignableFrom(clz)) {
@SuppressWarnings({"unchecked"})
Class<RelationType<?,?>> c = (Class<RelationType<?,?>>) clz;
this.superClasses = retrieveSuperClasses(c, RelationType.class, RelationElement.NAME);
this.extendedTypes = retrieveSuperClasses(c, RelationType.class, RelationElement.NAME);
} else if(IsParentOf.class.isAssignableFrom(clz)) {
@SuppressWarnings("unchecked")
Class<? extends IsParentOf> c = (Class<? extends IsParentOf>) clz;
this.superClasses = retrieveSuperClasses(c, IsParentOf.class, RelationElement.NAME);
this.extendedTypes = retrieveSuperClasses(c, IsParentOf.class, RelationElement.NAME);
} else if(RelationElement.class.isAssignableFrom(clz)) {
this.superClasses = retrieveSuperClasses(clz, RelationElement.class, null);
this.extendedTypes = retrieveSuperClasses(clz, RelationElement.class, null);
} else {
throw new RuntimeException("Type Hierachy Error");
}
@ -157,4 +159,19 @@ public class RelationTypeImpl<S extends EntityType, T extends EntityType>
return AccessType.RELATION;
}
@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

@ -0,0 +1,41 @@
package org.gcube.informationsystem.types.knowledge;
import java.util.LinkedHashSet;
import java.util.Set;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.reference.Type;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class TypeInformation implements org.gcube.informationsystem.model.knowledge.TypeInformation<Type> {
@Override
public String getIdentifier(Type type) {
return type.getName();
}
@Override
public Set<String> getParentIdentifiers(Type root, Type type) {
if(root!=null && type.getName().compareTo(root.getName())==0) {
return new LinkedHashSet<>();
}
if(root==null && AccessType.getAccessType(type.getName())!=null) {
return new LinkedHashSet<>();
}
return type.getExtendedTypes();
}
@Override
public AccessType getAccessType(Type type) {
return type.getAccessType();
}
@Override
public Type getRoot(AccessType accessType) {
return TypeMapper.createTypeDefinition(accessType.getTypeClass());
}
}

View File

@ -0,0 +1,110 @@
package org.gcube.informationsystem.types.knowledge;
import java.util.Calendar;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import org.gcube.informationsystem.base.reference.AccessType;
import org.gcube.informationsystem.model.knowledge.ModelKnowledge;
import org.gcube.informationsystem.model.knowledge.TypesDiscoverer;
import org.gcube.informationsystem.types.reference.Type;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class TypesKnowledge {
private static TypesKnowledge instance;
public synchronized static TypesKnowledge getInstance() {
if(instance==null) {
instance = new TypesKnowledge();
}
return instance;
}
// in millisec
public static final long DEFAULT_EXPIRING_TIMEOUT;
static {
DEFAULT_EXPIRING_TIMEOUT = TimeUnit.HOURS.toMillis(6);
}
protected boolean initialized;
public int expiringTimeout;
// in millisec used only for logging and debugging
protected Calendar creationTime;
// in millisec
protected Calendar expiringTime;
protected ModelKnowledge<Type, TypeInformation> modelKnowledge;
protected TypesDiscoverer<Type> typesDiscoverer;
public TypesKnowledge() {
initialized = false;
expiringTimeout = (int) DEFAULT_EXPIRING_TIMEOUT;
modelKnowledge = new ModelKnowledge<>(new TypeInformation());
}
public void setExpiringTimeout(int expiringTimeout) {
this.expiringTimeout = expiringTimeout;
}
public TypesDiscoverer<Type> getTypesDiscoverer() {
return typesDiscoverer;
}
public void setTypesDiscoverer(TypesDiscoverer<Type> typesDiscoverer) {
this.typesDiscoverer = typesDiscoverer;
}
public ModelKnowledge<Type, TypeInformation> getModelKnowledge() {
if(!initialized) {
discover();
}else {
Calendar now = Calendar.getInstance();
if(now.after(expiringTime)) {
renew();
}
}
return modelKnowledge;
}
protected synchronized void init(boolean forceReinitialization) {
if(typesDiscoverer!=null && (initialized==false || forceReinitialization)) {
initialized = false;
modelKnowledge = new ModelKnowledge<>(new TypeInformation());
AccessType[] modelTypes = AccessType.getModelTypes();
for(AccessType modelType : modelTypes) {
Collection<Type> types = typesDiscoverer.discover(modelType);
modelKnowledge.addAllType(types);
}
initialized = true;
this.creationTime = Calendar.getInstance();
this.expiringTime = Calendar.getInstance();
this.expiringTime.setTimeInMillis(creationTime.getTimeInMillis());
this.expiringTime.add(Calendar.MILLISECOND, -1);
this.expiringTime.add(Calendar.MILLISECOND, expiringTimeout);
}
}
/**
* This method do nothing if TypesDiscoverer
* was not set.
* Otherwise initialized the ModelKnowledge
* if it was not already initialized.
* To enforce rediscovery use renew method.
*/
public void discover() {
init(false);
}
/**
* Force reinitialization of
*/
public void renew() {
init(true);
}
}

View File

@ -2,12 +2,17 @@ package org.gcube.informationsystem.types.reference;
import java.util.Map;
import java.util.Set;
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.annotation.JsonPropertyOrder;
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.IdentifiableElement;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.utils.Version;
@ -17,21 +22,40 @@ import org.gcube.informationsystem.utils.Version;
*/
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
@TypeMetadata(name = Type.NAME, description = "This is the base class to define any Type", version = Version.MINIMAL_VERSION_STRING)
@JsonPropertyOrder({ Element.TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
@TypeMetadata(name = Type.NAME, description = "This is the base type to define any Type", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
//@JsonDeserialize(as=TypeImpl.class) Do not uncomment to manage subclasses
public interface Type extends IdentifiableElement {
public static final String NAME = "Type"; //Type.class.getSimpleName();
public static final String NAME = "Type"; // Type.class.getSimpleName();
public static final String NAME_PROPERTY = "name";
public static final String DESCRIPTION_PROPERTY = "description";
public static final String VERSION_PROPERTY = "version";
public static final String CHANGELOG_PROPERTY = "changelog";
public static final String ABSTRACT_PROPERTY = "abstract";
public static final String TYPE_SUPERCLASSES_PROPERTY = "superClasses";
public static final String FINAL_PROPERTY = "final";
/* Cannot use 'supertypes' which conflicts with Element */
public static final String EXTENDED_TYPES_PROPERTY = "extendedTypes";
public static final String PROPERTIES_PROPERTY = "properties";
@JsonGetter(value = ID_PROPERTY)
@Override
public UUID getID();
@JsonSetter(value = ID_PROPERTY)
@Override
public void setID(UUID uuid);
@JsonGetter(value = METADATA_PROPERTY)
@Override
public Metadata getMetadata();
@JsonSetter(value = METADATA_PROPERTY)
@Override
public void setMetadata(Metadata metadata);
public String getName();
public String getDescription();
@ -48,9 +72,14 @@ public interface Type extends IdentifiableElement {
@JsonGetter(value = CHANGELOG_PROPERTY)
public Map<String, String> getChangelogWithVersionAsString();
@JsonGetter(value = ABSTRACT_PROPERTY)
public boolean isAbstract();
public Set<String> getSuperClasses();
@JsonGetter(value = FINAL_PROPERTY)
public boolean isFinal();
@JsonGetter(value = EXTENDED_TYPES_PROPERTY)
public Set<String> getExtendedTypes();
public Set<PropertyDefinition> getProperties();

View File

@ -17,13 +17,13 @@ import org.gcube.informationsystem.utils.Version;
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = EntityTypeImpl.class)
@TypeMetadata(name = EntityType.NAME, description = "This class provides information for any EntityType", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = EntityType.NAME, description = "This type provides information for any EntityType", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface EntityType extends Type, EntityElement {
public static final String NAME = "EntityType"; //EntityType.class.getSimpleName();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
/* Type is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
@Override
@ISProperty(name = Type.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ -38,9 +38,9 @@ public interface EntityType extends Type, EntityElement {
public boolean isAbstract();
@Override
@ISProperty(name = Type.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getSuperClasses();
@ISProperty(name = Type.EXTENDED_TYPES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getExtendedTypes();
/* {@link Type} is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
/* Type is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
}

View File

@ -4,6 +4,7 @@ import java.util.Set;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.entities.FacetTypeImpl;
import org.gcube.informationsystem.types.reference.Change;
@ -17,8 +18,9 @@ import org.gcube.informationsystem.utils.Version;
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = FacetTypeImpl.class)
@TypeMetadata(name = FacetType.NAME, description = "This class provides information for the definition of any FacetType", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = FacetType.NAME, description = "This type provides information for the definition of any FacetType", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@Final
public interface FacetType extends EntityType {
public static final String NAME = "FacetType"; //FacetType.class.getSimpleName();

View File

@ -3,6 +3,7 @@ package org.gcube.informationsystem.types.reference.entities;
import java.util.List;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.entities.ResourceTypeImpl;
import org.gcube.informationsystem.types.reference.Change;
@ -14,8 +15,9 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=ResourceTypeImpl.class)
@TypeMetadata(name = ResourceType.NAME, description = "This class provides information for the definition of any ResourceType", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = ResourceType.NAME, description = "This type provides information for the definition of any ResourceType", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@Final
public interface ResourceType extends EntityType {
public static final String NAME = "ResourceType"; //ResourceType.class.getSimpleName();

View File

@ -2,6 +2,7 @@ package org.gcube.informationsystem.types.reference.properties;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.properties.LinkedEntityImpl;
import org.gcube.informationsystem.types.reference.Change;
@ -16,9 +17,10 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=LinkedEntityImpl.class)
@TypeMetadata(name = LinkedEntity.NAME, description = " A convenient type to define a Resource in terms of: mandatory/recommended ConsistsOf->Facets; uggested IsRelatedTo->Resource.", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = LinkedEntity.NAME, description = " A convenient type to define a Resource in terms of: mandatory/recommended ConsistsOf->Facets; suggested IsRelatedTo->Resource.", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface LinkedEntity extends PropertyElement {
@Final
public interface LinkedEntity extends PropertyElement, Comparable<LinkedEntity> {
public static final String NAME = "LinkedEntity"; // LinkedEntity.class.getSimpleName();

View File

@ -3,6 +3,7 @@ package org.gcube.informationsystem.types.reference.properties;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
import org.gcube.informationsystem.types.reference.Change;
@ -14,9 +15,10 @@ import org.gcube.informationsystem.utils.Version;
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = PropertyDefinitionImpl.class)
@TypeMetadata(name = PropertyDefinition.NAME, description = "This class provides information for the definition of any properties", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = PropertyDefinition.NAME, description = "This type provides information for the definition of any properties", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface PropertyDefinition extends PropertyElement {
@Final
public interface PropertyDefinition extends PropertyElement, Comparable<PropertyDefinition> {
public static final String NAME = "PropertyDefinition"; // PropertyDefinition.class.getSimpleName();
@ -28,7 +30,7 @@ public interface PropertyDefinition extends PropertyElement {
public static final String MAX_PROPERTY = "max";
public static final String MIN_PROPERTY = "min";
public static final String REGEX_PROPERTY = "regexp";
public static final String TYPE_PROPERTY = "type";
public static final String PROPERTY_TYPE_PROPERTY = "propertyType";
@ISProperty(name = NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
public String getName();
@ -54,7 +56,7 @@ public interface PropertyDefinition extends PropertyElement {
@ISProperty(name = REGEX_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getRegexp();
@ISProperty(name = TYPE_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getType();
@ISProperty(name = PROPERTY_TYPE_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getPropertyType();
}

View File

@ -1,12 +1,15 @@
package org.gcube.informationsystem.types.reference.properties;
import java.util.Set;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.properties.PropertyTypeImpl;
import org.gcube.informationsystem.types.reference.Change;
@ -19,18 +22,32 @@ import org.gcube.informationsystem.utils.Version;
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = PropertyTypeImpl.class)
@TypeMetadata(name = PropertyType.NAME, description = "This class provides information for any PropertyType", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = PropertyType.NAME, description = "This type provides information for any PropertyType", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@Final
public interface PropertyType<P extends PropertyElement> extends PropertyElement, Type {
public static final String NAME = "PropertyType"; // PropertyTypeDefinition.class.getSimpleName();
public static final String NAME = "PropertyType"; // PropertyType.class.getSimpleName();
@ISProperty(name=IdentifiableElement.HEADER_PROPERTY, mandatory=true, nullable=false)
public Header getHeader();
@JsonGetter(value = ID_PROPERTY)
@ISProperty(name = ID_PROPERTY, description = "This UUID is be used to identify the instance univocally.", readonly = true, mandatory = true, nullable = false)
@Override
public UUID getID();
@JsonSetter(value = ID_PROPERTY)
@Override
public void setID(UUID uuid);
public void setHeader(Header header);
@JsonGetter(value = METADATA_PROPERTY)
@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();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
@JsonSetter(value = METADATA_PROPERTY)
@Override
public void setMetadata(Metadata metadata);
/* Type is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
@Override
@ISProperty(name = Type.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ -45,12 +62,12 @@ public interface PropertyType<P extends PropertyElement> extends PropertyElement
public boolean isAbstract();
@Override
@ISProperty(name = Type.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getSuperClasses();
@ISProperty(name = Type.EXTENDED_TYPES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getExtendedTypes();
@ISProperty(name = Type.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Set<PropertyDefinition> getProperties();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
/*Type is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
}

View File

@ -1,6 +1,7 @@
package org.gcube.informationsystem.types.reference.relations;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.types.impl.relations.ConsistsOfTypeImpl;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
@ -12,8 +13,9 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as = ConsistsOfTypeImpl.class)
@TypeMetadata(name = ConsistsOfType.NAME, description = "This class provides information for any ConsistsOfType", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = ConsistsOfType.NAME, description = "This type provides information for any ConsistsOfType", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@Final
public interface ConsistsOfType extends RelationType<ResourceType, FacetType> {
public static final String NAME = "ConsistsOfType"; // ConsistsOfType.class.getSimpleName();

View File

@ -1,6 +1,7 @@
package org.gcube.informationsystem.types.reference.relations;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.types.impl.relations.IsRelatedToTypeImpl;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
@ -11,8 +12,9 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as = IsRelatedToTypeImpl.class)
@TypeMetadata(name = IsRelatedToType.NAME, description = "This class provides information for any IsRelatedToType", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = IsRelatedToType.NAME, description = "This type provides information for any IsRelatedToType", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@Final
public interface IsRelatedToType extends RelationType<ResourceType, ResourceType> {
public static final String NAME = "IsRelatedToType"; // IsRelatedToType.class.getSimpleName();

View File

@ -19,14 +19,14 @@ import org.gcube.informationsystem.utils.Version;
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = RelationTypeImpl.class)
@TypeMetadata(name = RelationType.NAME, description = "This class provides information for any RelationType", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = RelationType.NAME, description = "This type provides information for any RelationType", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface RelationType<S extends EntityType, T extends EntityType>
extends Type, RelationElement<S,T> {
public static final String NAME = "RelationType"; // RelationType.class.getSimpleName();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
/* Type is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
@Override
@ISProperty(name = Type.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
@ -41,8 +41,8 @@ public interface RelationType<S extends EntityType, T extends EntityType>
public boolean isAbstract();
@Override
@ISProperty(name = Type.TYPE_SUPERCLASSES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getSuperClasses();
@ISProperty(name = Type.EXTENDED_TYPES_PROPERTY, readonly = true, mandatory = true, nullable = false)
public Set<String> getExtendedTypes();
@Override
@ISProperty(name = Type.PROPERTIES_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ -54,11 +54,6 @@ public interface RelationType<S extends EntityType, T extends EntityType>
@Override
public T getTarget();
/* TypeDefinition is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
/*@JsonGetter(value=SOURCE_PROPERTY)
public String getSourceType();
@JsonGetter(value=TARGET_PROPERTY)
public String getTargetType();*/
/* Type is just a Java useful class. The type is not created in the IS. Hence the fields must be redefined */
}

View File

@ -1,38 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.utils;
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.utils.discovery.SchemaAction;
/**
* @author Luca Frosini (ISTI - CNR)
*/
class ElementMappingAction implements SchemaAction {
public ElementMappingAction(){
}
@Override
public <P extends PropertyElement> void managePropertyClass(Class<P> e)
throws Exception {
ElementMapper.registerSubtype(e);
}
@Override
public <E extends EntityElement> void manageEntityClass(Class<E> e)
throws Exception {
ElementMapper.registerSubtype(e);
}
@Override
public <R extends RelationElement<? extends EntityElement, ? extends EntityElement>> void manageRelationClass(
Class<R> r) throws Exception {
ElementMapper.registerSubtype(r);
}
}

View File

@ -0,0 +1,27 @@
package org.gcube.informationsystem.utils;
import java.io.IOException;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class JsonUtility {
private static Logger logger = LoggerFactory.getLogger(JsonUtility.class);
public static JsonNode getJsonNode(String json) throws JsonProcessingException, IOException {
if(json==null || json.compareTo("")==0){
return null;
}
logger.trace("Trying to get Jsonnode from {}", json);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(json);
return jsonNode;
}
}

View File

@ -1,7 +1,7 @@
/**
*
*/
package org.gcube.informationsystem.utils.discovery;
package org.gcube.informationsystem.utils;
import java.io.File;
import java.io.IOException;

View File

@ -0,0 +1,31 @@
package org.gcube.informationsystem.utils;
import java.io.IOException;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.types.TypeMapper;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class TypeUtility {
public static String getTypeName(JsonNode jsonNode){
if(jsonNode.has(Element.TYPE_PROPERTY)) {
return jsonNode.get(Element.TYPE_PROPERTY).asText();
}
return null;
}
public static String getTypeName(String json) throws JsonProcessingException, IOException{
JsonNode jsonNode = JsonUtility.getJsonNode(json);
return getTypeName(jsonNode);
}
public static <E extends Element> String getTypeName(Class<E> clz){
return TypeMapper.getType(clz);
}
}

View File

@ -10,8 +10,17 @@ import java.util.UUID;
*/
public final class UUIDManager {
public static final Set<String> RESERVED_UUID_STRING;
public static final Set<UUID> RESERVED_UUID;
private static final Set<String> RESERVED_UUID_STRING;
private static final Set<UUID> RESERVED_UUID;
private static UUIDManager uuidManager;
public static UUIDManager getInstance() {
if(uuidManager==null) {
uuidManager = new UUIDManager();
}
return uuidManager;
}
private UUIDManager() {
@ -31,27 +40,42 @@ public final class UUIDManager {
}
}
public static boolean isReservedUUID(UUID uuid) {
public boolean isReservedUUID(UUID uuid) {
return RESERVED_UUID.contains(uuid);
}
public static boolean isReservedUUID(String uuid) {
public boolean isReservedUUID(String uuid) {
return RESERVED_UUID_STRING.contains(uuid);
}
public static Set<String> getAllReservedUUIDAsStrings(){
public Set<String> getAllReservedUUIDAsStrings(){
return new TreeSet<>(RESERVED_UUID_STRING);
}
public static Set<UUID> getAllReservedUUID(){
public Set<UUID> getAllReservedUUID(){
return new TreeSet<>(RESERVED_UUID);
}
public static UUID generateValidRandomUUID() {
UUID generated = UUID.randomUUID();
while(RESERVED_UUID.contains(generated)) {
generated = UUID.randomUUID();
}
return generated;
public UUID generateValidUUID() {
return generateValidUUID(null);
}
public UUID generateValidUUID(UUID uuid) {
uuid = uuid==null ? UUID.randomUUID() : uuid;
while(RESERVED_UUID.contains(uuid)) {
uuid = UUID.randomUUID();
}
return uuid;
}
public UUID validateUUID(UUID uuid) throws Exception {
if(RESERVED_UUID.contains(uuid)) {
throw new Exception(uuid.toString() + " UUID is reserved. All the following UUID are reserved " + getAllReservedUUIDAsStrings().toString());
}
return uuid;
}
}

View File

@ -0,0 +1,53 @@
package org.gcube.informationsystem.utils;
import java.io.IOException;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class UUIDUtility {
private static Logger logger = LoggerFactory.getLogger(UUIDUtility.class);
public static UUID getUUID(JsonNode jsonNode){
if(jsonNode.has(IdentifiableElement.ID_PROPERTY)) {
JsonNode jsonNodeID = jsonNode.get(IdentifiableElement.ID_PROPERTY);
if(jsonNodeID!=null && jsonNodeID.isTextual()) {
return UUID.fromString(jsonNodeID.asText());
}
}
return null;
}
public static UUID getUUID(String json) throws JsonProcessingException, IOException {
logger.trace("Trying to get UUID of {} ", json);
JsonNode jsonNode = JsonUtility.getJsonNode(json);
return getUUID(jsonNode);
}
public static String getUUIDAsString(JsonNode jsonNode){
UUID uuid = getUUID(jsonNode);
if(uuid!=null) {
return uuid.toString();
}
return null;
}
public static String getUUIDAsString(String json) throws JsonProcessingException, IOException{
return getUUID(json).toString();
}
public static UUID fromString(String uuidString) throws Exception {
UUID uuid = UUID.fromString(uuidString);
UUIDManager.getInstance().validateUUID(uuid);
return uuid;
}
}

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