Compare commits
No commits in common. "master" and "v4.1.0" have entirely different histories.
|
@ -1,4 +1,3 @@
|
|||
target
|
||||
.classpath
|
||||
.project
|
||||
/.DS_Store
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/org.eclipse.jdt.core.prefs
|
||||
/org.eclipse.core.resources.prefs
|
||||
/org.eclipse.m2e.core.prefs
|
||||
/org.eclipse.jdt.ui.prefs
|
||||
|
|
36
CHANGELOG.md
36
CHANGELOG.md
|
@ -2,45 +2,13 @@ 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]
|
||||
- Generalized the way the type of a property is defined [#20516]
|
||||
- Added reserved UUID management
|
||||
- Added support for context names included in header among UUIDs [#22090]
|
||||
- Added support for Json Query [#22047]
|
||||
- Added support for Query Templates [#22091]
|
||||
|
||||
## [v4.1.0] [r5.0.0] - 2020-11-25
|
||||
## [v4.1.0]
|
||||
|
||||
- Added support to include additional properties in Property types [#20012]
|
||||
|
||||
|
||||
## [v4.0.0] [r4.26.0] - 2020-10-29
|
||||
## [v4.0.0] [r4.26.0]
|
||||
|
||||
- Switched JSON management to gcube-jackson [#19116]
|
||||
|
||||
|
|
26
FUNDING.md
26
FUNDING.md
|
@ -1,26 +0,0 @@
|
|||
# Acknowledgments
|
||||
|
||||
The projects leading to this software have received funding from a series of European Union programmes including:
|
||||
|
||||
- the Sixth Framework Programme for Research and Technological Development
|
||||
- [DILIGENT](https://cordis.europa.eu/project/id/004260) (grant no. 004260).
|
||||
- the Seventh Framework Programme for research, technological development and demonstration
|
||||
- [D4Science](https://cordis.europa.eu/project/id/212488) (grant no. 212488);
|
||||
- [D4Science-II](https://cordis.europa.eu/project/id/239019) (grant no.239019);
|
||||
- [ENVRI](https://cordis.europa.eu/project/id/283465) (grant no. 283465);
|
||||
- [iMarine](https://cordis.europa.eu/project/id/283644) (grant no. 283644);
|
||||
- [EUBrazilOpenBio](https://cordis.europa.eu/project/id/288754) (grant no. 288754).
|
||||
- the H2020 research and innovation programme
|
||||
- [SoBigData](https://cordis.europa.eu/project/id/654024) (grant no. 654024);
|
||||
- [PARTHENOS](https://cordis.europa.eu/project/id/654119) (grant no. 654119);
|
||||
- [EGI-Engage](https://cordis.europa.eu/project/id/654142) (grant no. 654142);
|
||||
- [ENVRI PLUS](https://cordis.europa.eu/project/id/654182) (grant no. 654182);
|
||||
- [BlueBRIDGE](https://cordis.europa.eu/project/id/675680) (grant no. 675680);
|
||||
- [PerformFISH](https://cordis.europa.eu/project/id/727610) (grant no. 727610);
|
||||
- [AGINFRA PLUS](https://cordis.europa.eu/project/id/731001) (grant no. 731001);
|
||||
- [DESIRA](https://cordis.europa.eu/project/id/818194) (grant no. 818194);
|
||||
- [ARIADNEplus](https://cordis.europa.eu/project/id/823914) (grant no. 823914);
|
||||
- [RISIS 2](https://cordis.europa.eu/project/id/824091) (grant no. 824091);
|
||||
- [EOSC-Pillar](https://cordis.europa.eu/project/id/857650) (grant no. 857650);
|
||||
- [Blue Cloud](https://cordis.europa.eu/project/id/862409) (grant no. 862409);
|
||||
- [SoBigData-PlusPlus](https://cordis.europa.eu/project/id/871042) (grant no. 871042);
|
24
README.md
24
README.md
|
@ -46,4 +46,26 @@ open-source software toolkit used for building and operating Hybrid Data
|
|||
Infrastructures enabling the dynamic deployment of Virtual Research Environments
|
||||
by favouring the realisation of reuse oriented policies.
|
||||
|
||||
The projects leading to this software have received funding from a series of European Union programmes see [FUNDING.md](FUNDING.md)
|
||||
The projects leading to this software have received funding from a series of European Union programmes including:
|
||||
|
||||
- the Sixth Framework Programme for Research and Technological Development
|
||||
- DILIGENT (grant no. 004260).
|
||||
- the Seventh Framework Programme for research, technological development and demonstration
|
||||
- D4Science (grant no. 212488);
|
||||
- D4Science-II (grant no.239019);
|
||||
- ENVRI (grant no. 283465);
|
||||
- iMarine(grant no. 283644);
|
||||
- EUBrazilOpenBio (grant no. 288754).
|
||||
- the H2020 research and innovation programme
|
||||
- SoBigData (grant no. 654024);
|
||||
- PARTHENOS (grant no. 654119);
|
||||
- EGIEngage (grant no. 654142);
|
||||
- ENVRIplus (grant no. 654182);
|
||||
- BlueBRIDGE (grant no. 675680);
|
||||
- PerformFish (grant no. 727610);
|
||||
- AGINFRAplus (grant no. 731001);
|
||||
- DESIRA (grant no. 818194);
|
||||
- ARIADNEplus (grant no. 823914);
|
||||
- RISIS2 (grant no. 824091);
|
||||
|
||||
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
# 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
54
docs/conf.py
|
@ -1,54 +0,0 @@
|
|||
# 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
305
docs/index.rst
|
@ -1,305 +0,0 @@
|
|||
|
||||
.. _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.
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 22 KiB |
Binary file not shown.
Before Width: | Height: | Size: 16 KiB |
|
@ -1,35 +0,0 @@
|
|||
@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
|
48
pom.xml
48
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>information-system-model</artifactId>
|
||||
<version>7.1.0-SNAPSHOT</version>
|
||||
<version>4.1.0</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.4.0</version>
|
||||
<version>2.0.1</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -51,22 +51,25 @@
|
|||
<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>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-utils</artifactId>
|
||||
<version>[2.2.0, 3.0.0-SNAPSHOT)</version>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-authorization</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
@ -80,29 +83,4 @@
|
|||
<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>
|
|
@ -7,8 +7,7 @@ import java.io.StringWriter;
|
|||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
import org.gcube.informationsystem.utils.TypeUtility;
|
||||
import org.gcube.informationsystem.utils.ElementMapper;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -21,12 +20,6 @@ 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();
|
||||
|
@ -37,5 +30,4 @@ public class ElementImpl implements Element {
|
|||
return super.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,17 +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.Metadata;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
import org.gcube.informationsystem.utils.ElementMapper;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value=EntityElement.NAME)
|
||||
public abstract class EntityElementImpl extends ElementImpl implements EntityElement {
|
||||
|
||||
|
@ -20,31 +16,20 @@ public abstract class EntityElementImpl extends ElementImpl implements EntityEle
|
|||
*/
|
||||
private static final long serialVersionUID = -4488771434017342703L;
|
||||
|
||||
protected UUID uuid;
|
||||
protected Metadata metadata;
|
||||
protected Header header;
|
||||
|
||||
protected EntityElementImpl(){
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setID(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
public Header getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metadata getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadata(Metadata metadata){
|
||||
this.metadata = metadata;
|
||||
public void setHeader(Header header){
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,7 +40,7 @@ public abstract class EntityElementImpl extends ElementImpl implements EntityEle
|
|||
return stringWriter.toString();
|
||||
}catch(Exception e){
|
||||
try {
|
||||
ElementMapper.marshal(this.metadata, stringWriter);
|
||||
ElementMapper.marshal(this.header, stringWriter);
|
||||
return stringWriter.toString();
|
||||
} catch(Exception e1){
|
||||
return super.toString();
|
||||
|
|
|
@ -2,7 +2,6 @@ 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;
|
||||
|
||||
|
@ -12,7 +11,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.serialization.ElementMapper;
|
||||
import org.gcube.informationsystem.utils.ElementMapper;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -25,34 +24,21 @@ 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() {
|
||||
|
@ -89,7 +75,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.TYPE_PROPERTY)) {
|
||||
if(map.containsKey(Element.CLASS_PROPERTY)) {
|
||||
String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map);
|
||||
Property property = ElementMapper.unmarshal(Property.class, reserialized);
|
||||
value = property;
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
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.Metadata;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value=RelationElement.NAME)
|
||||
public abstract class RelationElementImpl<S extends EntityElement, T extends EntityElement> extends ElementImpl implements RelationElement<S, T> {
|
||||
|
||||
|
@ -19,8 +14,7 @@ public abstract class RelationElementImpl<S extends EntityElement, T extends Ent
|
|||
*/
|
||||
private static final long serialVersionUID = 28704968813390512L;
|
||||
|
||||
protected UUID uuid;
|
||||
protected Metadata metadata;
|
||||
protected Header header;
|
||||
|
||||
protected S source;
|
||||
protected T target;
|
||||
|
@ -28,31 +22,21 @@ 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 void setID(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
public Header getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metadata getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadata(Metadata metadata){
|
||||
this.metadata = metadata;
|
||||
public void setHeader(Header header){
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
package org.gcube.informationsystem.base.reference;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.informationsystem.base.impl.entities.EntityElementImpl;
|
||||
import org.gcube.informationsystem.base.impl.properties.PropertyElementImpl;
|
||||
|
@ -13,10 +11,10 @@ import org.gcube.informationsystem.base.impl.relations.RelationElementImpl;
|
|||
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
||||
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
|
||||
import org.gcube.informationsystem.base.reference.relations.RelationElement;
|
||||
import org.gcube.informationsystem.contexts.impl.entities.ContextImpl;
|
||||
import org.gcube.informationsystem.contexts.impl.relations.IsParentOfImpl;
|
||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
|
||||
import org.gcube.informationsystem.context.impl.entities.ContextImpl;
|
||||
import org.gcube.informationsystem.context.impl.relations.IsParentOfImpl;
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
||||
import org.gcube.informationsystem.model.impl.entities.DummyFacet;
|
||||
import org.gcube.informationsystem.model.impl.entities.DummyResource;
|
||||
import org.gcube.informationsystem.model.impl.entities.EntityImpl;
|
||||
|
@ -34,10 +32,6 @@ import org.gcube.informationsystem.model.reference.properties.Property;
|
|||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.queries.templates.impl.entities.QueryTemplateImpl;
|
||||
import org.gcube.informationsystem.queries.templates.impl.properties.TemplateVariableImpl;
|
||||
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
|
||||
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
|
||||
import org.gcube.informationsystem.types.impl.entities.EntityTypeImpl;
|
||||
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
|
||||
import org.gcube.informationsystem.types.impl.properties.PropertyTypeImpl;
|
||||
|
@ -50,60 +44,37 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Enumerates the basic type names.
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
* Enumerates the basic type names.
|
||||
*/
|
||||
public enum AccessType {
|
||||
|
||||
PROPERTY_ELEMENT(PropertyElement.class, PropertyElement.NAME, PropertyElementImpl.class, null),
|
||||
PROPERTY_DEFINITION(PropertyDefinition.class, PropertyDefinition.NAME, PropertyDefinitionImpl.class, null),
|
||||
PROPERTY_TYPE(PropertyType.class, PropertyType.NAME, PropertyTypeImpl.class, null),
|
||||
TEMPLATE_VARIABLE(TemplateVariable.class, TemplateVariable.NAME, TemplateVariableImpl.class, null),
|
||||
PROPERTY(Property.class, Property.NAME, PropertyImpl.class, null),
|
||||
|
||||
ENTITY_ELEMENT(EntityElement.class, EntityElement.NAME, EntityElementImpl.class, null),
|
||||
ENTITY_TYPE(EntityType.class, EntityType.NAME, EntityTypeImpl.class, null),
|
||||
QUERY_TEMPLATE(QueryTemplate.class, QueryTemplate.NAME, QueryTemplateImpl.class, null),
|
||||
CONTEXT(Context.class, Context.NAME, ContextImpl.class, null),
|
||||
IS_PARENT_OF(IsParentOf.class, IsParentOf.NAME, IsParentOfImpl.class, null),
|
||||
|
||||
PROPERTY_DEFINITION(PropertyDefinition.class, PropertyDefinition.NAME, PropertyDefinitionImpl.class, null),
|
||||
|
||||
// TYPE_DEFINITION(TypeDefinition.class, TypeDefinition.NAME, TypeDefinitionImpl.class, null),
|
||||
PROPERTY_TYPE(PropertyType.class, PropertyType.NAME, PropertyTypeImpl.class, null),
|
||||
ENTITY_TYPE(EntityType.class, EntityType.NAME, EntityTypeImpl.class, null),
|
||||
RELATION_TYPE(RelationType.class, RelationType.NAME, RelationTypeImpl.class, null),
|
||||
|
||||
ENTITY_ELEMENT(EntityElement.class, EntityElement.NAME, EntityElementImpl.class, null),
|
||||
ENTITY(Entity.class, Entity.NAME, EntityImpl.class, null),
|
||||
RESOURCE(Resource.class, Resource.NAME, ResourceImpl.class, DummyResource.class),
|
||||
FACET(Facet.class, Facet.NAME, FacetImpl.class, DummyFacet.class),
|
||||
|
||||
RELATION_ELEMENT(RelationElement.class, RelationElement.NAME, RelationElementImpl.class, null),
|
||||
RELATION_TYPE(RelationType.class, RelationType.NAME, RelationTypeImpl.class, null),
|
||||
IS_PARENT_OF(IsParentOf.class, IsParentOf.NAME, IsParentOfImpl.class, null),
|
||||
RELATION(Relation.class, Relation.NAME, RelationImpl.class, null),
|
||||
IS_RELATED_TO(IsRelatedTo.class, IsRelatedTo.NAME, IsRelatedToImpl.class, DummyIsRelatedTo.class),
|
||||
CONSISTS_OF(ConsistsOf.class, ConsistsOf.NAME, ConsistsOfImpl.class, null);
|
||||
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(AccessType.class);
|
||||
|
||||
private static AccessType[] modelTypes;
|
||||
private static AccessType[] erTypes;
|
||||
private static Set<String> names;
|
||||
|
||||
static {
|
||||
names = new HashSet<>();
|
||||
AccessType[] accessTypes = AccessType.values();
|
||||
for (AccessType accessType : accessTypes) {
|
||||
String name = accessType.getName();
|
||||
names.add(name);
|
||||
}
|
||||
|
||||
modelTypes = new AccessType[] {
|
||||
AccessType.PROPERTY,
|
||||
AccessType.RESOURCE, AccessType.FACET,
|
||||
AccessType.IS_RELATED_TO, AccessType.CONSISTS_OF
|
||||
};
|
||||
|
||||
erTypes = new AccessType[] {
|
||||
AccessType.RESOURCE, AccessType.FACET,
|
||||
AccessType.IS_RELATED_TO, AccessType.CONSISTS_OF
|
||||
};
|
||||
}
|
||||
|
||||
private final Class<? extends Element> clz;
|
||||
private final Class<? extends Element> implementationClass;
|
||||
private final Class<? extends Element> dummyImplementationClass;
|
||||
|
@ -148,26 +119,6 @@ public enum AccessType {
|
|||
return name;
|
||||
}
|
||||
|
||||
public static Set<String> names(){
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the access type from the name provided type name as argument
|
||||
* @param typeName type name
|
||||
* @return the AccessType from the name provided type name as argument, null otherwise
|
||||
*/
|
||||
public static AccessType getAccessType(String typeName) {
|
||||
AccessType[] accessTypes = AccessType.values();
|
||||
for (AccessType accessType : accessTypes) {
|
||||
String name = accessType.getName();
|
||||
if(name.compareTo(typeName)==0) {
|
||||
return accessType;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AccessType getAccessType(Class<?> clz) {
|
||||
AccessType ret =null;
|
||||
|
||||
|
@ -191,21 +142,4 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
package org.gcube.informationsystem.base.reference;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.informationsystem.types.PropertyTypeName;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public interface Attribute {
|
||||
|
||||
public static final String NAME = "Attribute"; // Attribute.class.getSimpleName();
|
||||
|
||||
public static final String NAME_PROPERTY = "name";
|
||||
public static final String DESCRIPTION_PROPERTY = "description";
|
||||
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 PROPERTY_TYPE_PROPERTY = "propertyType";
|
||||
public static final String DEFAULT_VALUE_PROPERTY = "defaultValue";
|
||||
|
||||
public String getName();
|
||||
|
||||
public void setName(String name);
|
||||
|
||||
public String getDescription();
|
||||
|
||||
public void setDescription(String description);
|
||||
|
||||
public String getPropertyType();
|
||||
|
||||
public void setPropertyType(String type);
|
||||
|
||||
@JsonIgnore
|
||||
public PropertyTypeName getPropertyTypeName();
|
||||
|
||||
public Object getDefaultValue();
|
||||
|
||||
public void setDefaultValue(Object defaultValue);
|
||||
|
||||
public Integer getMax();
|
||||
|
||||
public void setMax(Integer max);
|
||||
|
||||
public Integer getMin();
|
||||
|
||||
public void setMin(Integer min);
|
||||
|
||||
public String getRegexp();
|
||||
|
||||
public void setRegexp(String regexp);
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package org.gcube.informationsystem.base.reference;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public interface AttributeDefinition extends Attribute {
|
||||
|
||||
public static final String MANDATORY_PROPERTY = "mandatory";
|
||||
public static final String READ_ONLY_PROPERTY = "readonly";
|
||||
public static final String NOT_NULL_PROPERTY = "notnull";
|
||||
|
||||
public boolean isMandatory();
|
||||
|
||||
public void setMandatory(boolean mandatory);
|
||||
|
||||
public boolean isReadonly();
|
||||
|
||||
public void setReadonly(boolean readonly);
|
||||
|
||||
public boolean isNotnull();
|
||||
|
||||
public void setNotnull(boolean notnull);
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package org.gcube.informationsystem.base.reference;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public enum Direction {
|
||||
|
||||
IN, OUT, BOTH;
|
||||
|
||||
public Direction opposite() {
|
||||
if(this.equals(IN)) {
|
||||
return OUT;
|
||||
}else if(this.equals(OUT)) {
|
||||
return IN;
|
||||
} else {
|
||||
return BOTH;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,35 +5,26 @@ package org.gcube.informationsystem.base.reference;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import org.gcube.informationsystem.types.annotations.Abstract;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Abstract
|
||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY })
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = Element.TYPE_PROPERTY)
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = Element.CLASS_PROPERTY)
|
||||
// @JsonTypeIdResolver(ElementTypeIdResolver.class)
|
||||
@TypeMetadata(name = Element.NAME, description = "This is the base type for Element", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface Element extends Serializable {
|
||||
|
||||
public static final String NAME = "Element"; //Element.class.getSimpleName();
|
||||
|
||||
public static final String TYPE_PROPERTY = "type";
|
||||
public static final String CLASS_PROPERTY = "@class";
|
||||
|
||||
public static final String SUPERCLASSES_PROPERTY = "@superClasses";
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,36 +1,16 @@
|
|||
package org.gcube.informationsystem.base.reference;
|
||||
|
||||
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;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
|
||||
/**
|
||||
* This interfaces is an helper to identify elements could be identified via {@link Metadata}
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* this is just a useful interface
|
||||
*/
|
||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
|
||||
public interface IdentifiableElement extends Element {
|
||||
|
||||
public static final String ID_PROPERTY = "id";
|
||||
public static final String METADATA_PROPERTY = "metadata";
|
||||
|
||||
@JsonGetter(value = ID_PROPERTY)
|
||||
public UUID getID();
|
||||
public static final String HEADER_PROPERTY = "header";
|
||||
|
||||
@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 Header getHeader();
|
||||
|
||||
public void setHeader(Header header);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,7 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* This interfaces is an helper to identify elements supporting Schema Mixed.
|
||||
* i.e. elements which instances could have additional properties in respect to the ones defined in the schema
|
||||
*
|
||||
* i.e. elements which instances could have additional properties in respect to the ones defined in the schema
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public interface SchemaMixedElement extends Element {
|
||||
|
|
|
@ -1,43 +1,22 @@
|
|||
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.Metadata;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
import org.gcube.informationsystem.types.annotations.Abstract;
|
||||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Abstract
|
||||
@JsonIgnoreProperties(ignoreUnknown=true)
|
||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
|
||||
//@JsonDeserialize(as=EntityElementImpl.class) Do not uncomment to manage subclasses
|
||||
@TypeMetadata(name = EntityElement.NAME, description = "This is the base type for any EntityElement", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface EntityElement extends Element, IdentifiableElement {
|
||||
|
||||
public static final String NAME = "EntityElement"; //Entity.class.getSimpleName();
|
||||
|
||||
@ISProperty(name = ID_PROPERTY, description = "This UUID is be used to identify the instance univocally.", readonly = true, mandatory = true, nullable = false)
|
||||
/* Overriding getHeader method to create Header property in type */
|
||||
@ISProperty(name=HEADER_PROPERTY, mandatory=true, nullable=false)
|
||||
@Override
|
||||
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);
|
||||
public Header getHeader();
|
||||
|
||||
}
|
|
@ -3,21 +3,17 @@ package org.gcube.informationsystem.base.reference.properties;
|
|||
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.gcube.informationsystem.base.impl.properties.PropertyElementImpl;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* Root Class for Property types.
|
||||
* It creates a base common type, which is useful for management purpose.
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* Root Class for Property types. It creates a base common type, which is useful
|
||||
* for management purpose.
|
||||
*/
|
||||
@JsonDeserialize(as=PropertyElementImpl.class)
|
||||
@TypeMetadata(name = PropertyElement.NAME, description = "This is the base type for any PropertyElement", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface PropertyElement extends Element {
|
||||
|
||||
public static final String NAME = "PropertyElement"; //PropertyElement.class.getSimpleName();
|
||||
public static final String DESCRIPTION = "This is the very base class for Property";
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
}
|
||||
|
|
|
@ -1,26 +1,16 @@
|
|||
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.Metadata;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
import org.gcube.informationsystem.types.annotations.Abstract;
|
||||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Abstract
|
||||
//@JsonDeserialize(as=RelationElementImpl.class) Do not uncomment to manage subclasses
|
||||
@TypeMetadata(name = RelationElement.NAME, description = "This is the base type for any RelationElement", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface RelationElement<S extends EntityElement, T extends EntityElement> extends Element, IdentifiableElement {
|
||||
|
||||
public static final String NAME = "RelationElement"; // RelationElement.class.getSimpleName();
|
||||
|
@ -28,19 +18,10 @@ public interface RelationElement<S extends EntityElement, T extends EntityElemen
|
|||
public static final String SOURCE_PROPERTY = "source";
|
||||
public static final String TARGET_PROPERTY = "target";
|
||||
|
||||
@ISProperty(name = ID_PROPERTY, description = "This UUID is be used to identify the instance univocally.", readonly = true, mandatory = true, nullable = false)
|
||||
/* Overriding getHeader method to create Header property in type */
|
||||
@ISProperty(name = HEADER_PROPERTY, mandatory = true, nullable = false)
|
||||
@Override
|
||||
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);
|
||||
public Header getHeader();
|
||||
|
||||
@JsonGetter(value=SOURCE_PROPERTY)
|
||||
public S getSource();
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.context.impl.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.gcube.informationsystem.base.impl.entities.EntityElementImpl;
|
||||
import org.gcube.informationsystem.context.impl.relations.IsParentOfImpl;
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
||||
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
||||
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value=Context.NAME)
|
||||
public final class ContextImpl extends EntityElementImpl implements Context {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
*/
|
||||
private static final long serialVersionUID = -5070590328223454087L;
|
||||
|
||||
protected String name;
|
||||
|
||||
protected IsParentOf parent;
|
||||
protected List<IsParentOf> children;
|
||||
|
||||
protected ContextImpl() {
|
||||
super();
|
||||
this.parent = null;
|
||||
this.children = new ArrayList<>();
|
||||
}
|
||||
|
||||
public ContextImpl(String name) {
|
||||
this(name, null);
|
||||
}
|
||||
|
||||
public ContextImpl(String name, UUID uuid) {
|
||||
this();
|
||||
this.name = name;
|
||||
if(uuid == null){
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
this.header = new HeaderImpl(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IsParentOf getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setParent(UUID uuid) {
|
||||
Context parent = null;
|
||||
if(uuid!=null) {
|
||||
parent = new ContextImpl();
|
||||
parent.setHeader(new HeaderImpl(uuid));
|
||||
}
|
||||
setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(Context context) {
|
||||
IsParentOf isParentOf = null;
|
||||
if(context!=null) {
|
||||
isParentOf = new IsParentOfImpl(context, this);
|
||||
}
|
||||
setParent(isParentOf);
|
||||
}
|
||||
|
||||
@JsonSetter(value=PARENT_PROPERTY)
|
||||
protected void setParentFromJson(IsParentOf isParentOf) throws JsonProcessingException {
|
||||
if(isParentOf!=null) {
|
||||
Context parent = isParentOf.getSource();
|
||||
isParentOf.setTarget(this);
|
||||
((ContextImpl) parent).addChild(isParentOf);
|
||||
}
|
||||
setParent(isParentOf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(IsParentOf isParentOf) {
|
||||
this.parent = isParentOf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IsParentOf> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
@JsonSetter(value=CHILDREN_PROPERTY)
|
||||
protected void setChildrenFromJson(List<IsParentOf> children) throws JsonProcessingException {
|
||||
for(IsParentOf isParentOf : children){
|
||||
addChildFromJson(isParentOf);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addChildFromJson(IsParentOf isParentOf) throws JsonProcessingException {
|
||||
isParentOf.setSource(this);
|
||||
addChild(isParentOf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChild(UUID uuid) {
|
||||
Context child = new ContextImpl();
|
||||
child.setHeader(new HeaderImpl(uuid));
|
||||
addChild(child);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChild(Context child) {
|
||||
IsParentOf isParentOf = new IsParentOfImpl(this, child);
|
||||
this.addChild(isParentOf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChild(IsParentOf isParentOf) {
|
||||
// ((ContextImpl) isParentOf.getTarget()).setParent(this);
|
||||
isParentOf.setSource(this);
|
||||
children.add(isParentOf);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.contexts.impl.relations;
|
||||
package org.gcube.informationsystem.context.impl.relations;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.base.impl.relations.RelationElementImpl;
|
||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.context.reference.entities;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
||||
import org.gcube.informationsystem.context.impl.entities.ContextImpl;
|
||||
import org.gcube.informationsystem.context.reference.relations.IsParentOf;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) This Entity is for internal use only
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Context
|
||||
*/
|
||||
@JsonDeserialize(as = ContextImpl.class)
|
||||
public interface Context extends EntityElement {
|
||||
|
||||
public static final String NAME = "Context"; // Context.class.getSimpleName();
|
||||
|
||||
public static final String NAME_PROPERTY = "name";
|
||||
public static final String PARENT_PROPERTY = "parent";
|
||||
public static final String CHILDREN_PROPERTY = "children";
|
||||
|
||||
@ISProperty(name = NAME_PROPERTY, mandatory = true, nullable = false)
|
||||
public String getName();
|
||||
|
||||
public void setName(String name);
|
||||
|
||||
@JsonGetter
|
||||
@JsonIgnoreProperties({ Relation.TARGET_PROPERTY })
|
||||
public IsParentOf getParent();
|
||||
|
||||
@JsonIgnore
|
||||
public void setParent(UUID uuid);
|
||||
|
||||
@JsonIgnore
|
||||
public void setParent(Context context);
|
||||
|
||||
@JsonIgnore
|
||||
public void setParent(IsParentOf isParentOf);
|
||||
|
||||
@JsonGetter
|
||||
@JsonIgnoreProperties({ Relation.SOURCE_PROPERTY })
|
||||
public List<IsParentOf> getChildren();
|
||||
|
||||
public void addChild(UUID uuid);
|
||||
|
||||
public void addChild(Context child);
|
||||
|
||||
public void addChild(IsParentOf isParentOf);
|
||||
|
||||
}
|
|
@ -1,31 +1,21 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.contexts.reference.relations;
|
||||
package org.gcube.informationsystem.context.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;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
import org.gcube.informationsystem.context.impl.relations.IsParentOfImpl;
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
|
||||
/**
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#IsParentOf
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isParentOf
|
||||
*/
|
||||
@JsonDeserialize(as = IsParentOfImpl.class)
|
||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY})
|
||||
@TypeMetadata(name = IsParentOf.NAME, description = "This type is the used to define parental relations between Context", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface IsParentOf extends RelationElement<Context,Context> {
|
||||
|
||||
public static final String NAME = "IsParentOf"; //IsParentOf.class.getSimpleName();
|
|
@ -1,231 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.contexts.impl.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.gcube.informationsystem.base.impl.entities.EntityElementImpl;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.contexts.impl.relations.IsParentOfImpl;
|
||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
|
||||
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
|
||||
import org.gcube.informationsystem.model.reference.properties.Property;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
import org.gcube.informationsystem.utils.UUIDManager;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value=Context.NAME)
|
||||
public final class ContextImpl extends EntityElementImpl implements Context {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
*/
|
||||
private static final long serialVersionUID = -5070590328223454087L;
|
||||
|
||||
protected UUID uuid;
|
||||
protected String name;
|
||||
|
||||
protected IsParentOf parent;
|
||||
protected List<IsParentOf> children;
|
||||
|
||||
@JsonIgnore
|
||||
protected Map<String, Object> additionalProperties;
|
||||
|
||||
@JsonIgnore
|
||||
/**
|
||||
* Used to allow to have an additional property starting with '_' or '@'
|
||||
*/
|
||||
protected final Set<String> allowedAdditionalKeys;
|
||||
|
||||
protected ContextImpl() {
|
||||
super();
|
||||
this.parent = null;
|
||||
this.children = new ArrayList<>();
|
||||
this.additionalProperties = new HashMap<>();
|
||||
this.allowedAdditionalKeys = new HashSet<>();
|
||||
}
|
||||
|
||||
public ContextImpl(UUID uuid) {
|
||||
this(null, uuid);
|
||||
}
|
||||
|
||||
public ContextImpl(String name) {
|
||||
this(name, null);
|
||||
}
|
||||
|
||||
public ContextImpl(String name, UUID uuid) {
|
||||
this();
|
||||
this.name = name;
|
||||
if(uuid == null){
|
||||
uuid = UUIDManager.getInstance().generateValidUUID();
|
||||
}
|
||||
this.uuid = uuid;
|
||||
this.metadata = new MetadataImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the uuid
|
||||
*/
|
||||
@Override
|
||||
public UUID getID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setID(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IsParentOf getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setParent(UUID uuid) {
|
||||
Context parent = null;
|
||||
if(uuid!=null) {
|
||||
parent = new ContextImpl(uuid);
|
||||
parent.setMetadata(new MetadataImpl());
|
||||
}
|
||||
setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(Context context) {
|
||||
IsParentOf isParentOf = null;
|
||||
if(context!=null) {
|
||||
isParentOf = new IsParentOfImpl(context, this);
|
||||
}
|
||||
setParent(isParentOf);
|
||||
}
|
||||
|
||||
@JsonSetter(value=PARENT_PROPERTY)
|
||||
protected void setParentFromJson(IsParentOf isParentOf) throws JsonProcessingException {
|
||||
if(isParentOf!=null) {
|
||||
Context parent = isParentOf.getSource();
|
||||
isParentOf.setTarget(this);
|
||||
((ContextImpl) parent).addChild(isParentOf);
|
||||
}
|
||||
setParent(isParentOf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(IsParentOf isParentOf) {
|
||||
this.parent = isParentOf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IsParentOf> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
@JsonSetter(value=CHILDREN_PROPERTY)
|
||||
protected void setChildrenFromJson(List<IsParentOf> children) throws JsonProcessingException {
|
||||
for(IsParentOf isParentOf : children){
|
||||
addChildFromJson(isParentOf);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addChildFromJson(IsParentOf isParentOf) throws JsonProcessingException {
|
||||
isParentOf.setSource(this);
|
||||
addChild(isParentOf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChild(UUID uuid) {
|
||||
Context child = new ContextImpl(uuid);
|
||||
child.setMetadata(new MetadataImpl());
|
||||
addChild(child);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChild(Context child) {
|
||||
IsParentOf isParentOf = new IsParentOfImpl(this, child);
|
||||
this.addChild(isParentOf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChild(IsParentOf isParentOf) {
|
||||
// ((ContextImpl) isParentOf.getTarget()).setParent(this);
|
||||
isParentOf.setSource(this);
|
||||
children.add(isParentOf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAdditionalProperties() {
|
||||
return additionalProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdditionalProperties(Map<String, Object> additionalProperties) {
|
||||
this.additionalProperties = additionalProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAdditionalProperty(String key) {
|
||||
return additionalProperties.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdditionalProperty(String key, Object value) {
|
||||
|
||||
if(!allowedAdditionalKeys.contains(key)){
|
||||
if(key.startsWith("_")) {
|
||||
return;
|
||||
}
|
||||
if(key.startsWith("@")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Additional properties are not deserialized to the proper property type.
|
||||
The first attempt was to try to write a specific deserializer but it fails.
|
||||
This fix the issue.
|
||||
*/
|
||||
try {
|
||||
if(value instanceof Map<?,?>) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String,Object>) value;
|
||||
if(map.containsKey(Element.TYPE_PROPERTY)) {
|
||||
String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map);
|
||||
Property property = ElementMapper.unmarshal(Property.class, reserialized);
|
||||
value = property;
|
||||
}
|
||||
}
|
||||
}catch (Throwable e) {
|
||||
e.getMessage();
|
||||
// Any type of error/exception must be catched
|
||||
}
|
||||
/* END of fix to properly deserialize Property types*/
|
||||
|
||||
this.additionalProperties.put(key, value);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.contexts.reference.entities;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||
import org.gcube.informationsystem.base.reference.SchemaMixedElement;
|
||||
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
||||
import org.gcube.informationsystem.contexts.impl.entities.ContextImpl;
|
||||
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.serialization.AdditionalPropertiesSerializer;
|
||||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Context
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonDeserialize(as = ContextImpl.class)
|
||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY})
|
||||
@TypeMetadata(name = Context.NAME, description = "This type is the used to define a Context", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface Context extends EntityElement, SchemaMixedElement {
|
||||
|
||||
public static final String NAME = "Context"; // Context.class.getSimpleName();
|
||||
|
||||
public static final String NAME_PROPERTY = "name";
|
||||
public static final String PARENT_PROPERTY = "parent";
|
||||
public static final String CHILDREN_PROPERTY = "children";
|
||||
|
||||
/**
|
||||
* {
|
||||
* ...
|
||||
* "availableAt" : [
|
||||
* "https://i-marine.d4science.org/group/alienandinvasivespecies",
|
||||
* "https://services.d4science.org/group/alienandinvasivespecies"
|
||||
* ]
|
||||
* ...
|
||||
* }
|
||||
* For non VRE context this field could be null or could have multiple value
|
||||
* For VRE it is normally one value only (but some exception could exists
|
||||
*/
|
||||
public static final String AVAILABLE_AT_PROPERTY = "availableAt";
|
||||
|
||||
//
|
||||
/**
|
||||
* This information is provided to allowed user only (by role)
|
||||
* {
|
||||
* ...
|
||||
* "fullpaths" : [
|
||||
* {
|
||||
* "fullpath": "/gcube/devsec/myTest",
|
||||
* "time": "2023-12-11 15:35:41.289 +0000", // Same of creationTime in metadata
|
||||
* },
|
||||
* {
|
||||
* "fullpath": "/gcube/devsec/myTestVRE",
|
||||
* "time": "2023-12-13 16:13:12.336 +0000",
|
||||
* }
|
||||
* {
|
||||
* "fullpath": "/gcube/devsec/myVRE",
|
||||
* "time": "2023-12-18 12:37:48.172 +0000", // Same of lastUpdateTime in metadata
|
||||
* }
|
||||
* ]
|
||||
* ...
|
||||
* }
|
||||
*/
|
||||
public static final String CONTEXT_FULLPATH_CHANGES_LOG_PROPERTY = "fullpathChangelog";
|
||||
|
||||
/**
|
||||
* This information is provided to allowed user only (by role)
|
||||
* The symmetric key for the context
|
||||
*/
|
||||
public static final String CONTEXT_KEY_PROPERTY = "key";
|
||||
|
||||
|
||||
@ISProperty(name = NAME_PROPERTY, mandatory = true, nullable = false)
|
||||
public String getName();
|
||||
|
||||
public void setName(String name);
|
||||
|
||||
@JsonGetter
|
||||
@JsonIgnoreProperties({ Relation.TARGET_PROPERTY })
|
||||
public IsParentOf getParent();
|
||||
|
||||
@JsonIgnore
|
||||
public void setParent(UUID uuid);
|
||||
|
||||
@JsonIgnore
|
||||
public void setParent(Context context);
|
||||
|
||||
@JsonIgnore
|
||||
public void setParent(IsParentOf isParentOf);
|
||||
|
||||
@JsonGetter
|
||||
@JsonIgnoreProperties({ Relation.SOURCE_PROPERTY })
|
||||
public List<IsParentOf> getChildren();
|
||||
|
||||
public void addChild(UUID uuid);
|
||||
|
||||
public void addChild(Context child);
|
||||
|
||||
public void addChild(IsParentOf isParentOf);
|
||||
|
||||
@JsonAnyGetter
|
||||
@JsonSerialize(using = AdditionalPropertiesSerializer.class)
|
||||
@Override
|
||||
public Map<String,Object> getAdditionalProperties();
|
||||
|
||||
@Override
|
||||
public void setAdditionalProperties(Map<String,Object> additionalProperties);
|
||||
|
||||
@Override
|
||||
public Object getAdditionalProperty(String key);
|
||||
|
||||
@JsonAnySetter
|
||||
@Override
|
||||
public void setAdditionalProperty(String key, Object value);
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
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();
|
||||
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,17 +5,12 @@ package org.gcube.informationsystem.model.impl.entities;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
|
||||
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@TypeMetadata(name = Facet.NAME, description = "This is a dummy type for Facet", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public class DummyFacet extends FacetImpl implements Facet {
|
||||
|
||||
/**
|
||||
|
@ -25,8 +20,7 @@ public class DummyFacet extends FacetImpl implements Facet {
|
|||
|
||||
public DummyFacet(UUID uuid) {
|
||||
super();
|
||||
this.uuid = uuid;
|
||||
this.metadata = new MetadataImpl();
|
||||
this.header = new HeaderImpl(uuid);
|
||||
}
|
||||
|
||||
public DummyFacet(){
|
||||
|
|
|
@ -5,17 +5,12 @@ package org.gcube.informationsystem.model.impl.entities;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
|
||||
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@TypeMetadata(name = Resource.NAME, description = "This is a dummy type for Resource", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public class DummyResource extends ResourceImpl implements Resource {
|
||||
|
||||
/**
|
||||
|
@ -25,8 +20,7 @@ public class DummyResource extends ResourceImpl implements Resource {
|
|||
|
||||
public DummyResource(UUID uuid){
|
||||
super();
|
||||
this.uuid = uuid;
|
||||
this.metadata = new MetadataImpl();
|
||||
this.header = new HeaderImpl(uuid);
|
||||
}
|
||||
|
||||
public DummyResource(){
|
||||
|
|
|
@ -3,14 +3,8 @@
|
|||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -24,31 +18,9 @@ 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.metadata = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSupertypes() {
|
||||
return this.supertypes;
|
||||
this.header = null;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.serialization.ElementMapper;
|
||||
import org.gcube.informationsystem.utils.ElementMapper;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -39,6 +39,7 @@ public abstract class FacetImpl extends EntityImpl implements Facet {
|
|||
super();
|
||||
this.additionalProperties = new HashMap<>();
|
||||
this.allowedAdditionalKeys = new HashSet<>();
|
||||
this.allowedAdditionalKeys.add(SUPERCLASSES_PROPERTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -76,7 +77,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.TYPE_PROPERTY)) {
|
||||
if(map.containsKey(Element.CLASS_PROPERTY)) {
|
||||
String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map);
|
||||
Property property = ElementMapper.unmarshal(Property.class, reserialized);
|
||||
value = property;
|
||||
|
|
|
@ -177,12 +177,14 @@ public abstract class ResourceImpl extends EntityImpl implements Resource {
|
|||
throw new RuntimeException(message);
|
||||
}
|
||||
|
||||
if (relation.getSource().getMetadata()!= null &&
|
||||
relation.getSource().getID() != null &&
|
||||
this.metadata !=null &&
|
||||
this.uuid != null &&
|
||||
relation.getSource().getID().compareTo(this.uuid)!=0) {
|
||||
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) {
|
||||
|
||||
throw new RuntimeException(message);
|
||||
|
||||
}
|
||||
|
||||
if(relation.getSource()!=this){
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
package org.gcube.informationsystem.model.impl.properties;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.types.PropertyTypeName.BaseType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class AttributeUtility {
|
||||
|
||||
protected Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public static void checkRegex(String regex, String text) {
|
||||
try {
|
||||
if(regex==null) {
|
||||
return;
|
||||
}
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
if(text!=null) {
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
if(!matcher.find()) {
|
||||
throw new RuntimeException("The value '" + text + "' does not match the requested regular expression '" + regex + "'.");
|
||||
}
|
||||
}
|
||||
} catch (PatternSyntaxException e) {
|
||||
throw new RuntimeException("'" + regex + "' is not a valid regular expression", e);
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static String evaluateNullForDefaultValue(String defaultValueAsString) {
|
||||
if(defaultValueAsString==null || defaultValueAsString.compareTo("null")==0) {
|
||||
return null;
|
||||
}
|
||||
return defaultValueAsString;
|
||||
}
|
||||
|
||||
public static Object evaluateDefaultValueStringAccordingBaseType(BaseType baseType, String defaultValueAsString) {
|
||||
|
||||
if(defaultValueAsString==null || defaultValueAsString.compareTo("null")==0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(defaultValueAsString!=null) {
|
||||
switch (baseType) {
|
||||
case BOOLEAN:
|
||||
return Boolean.parseBoolean(defaultValueAsString);
|
||||
|
||||
case INTEGER:
|
||||
return Integer.parseInt(defaultValueAsString);
|
||||
|
||||
case SHORT:
|
||||
return Short.parseShort(defaultValueAsString);
|
||||
|
||||
case LONG:
|
||||
return Long.parseLong(defaultValueAsString);
|
||||
|
||||
case FLOAT:
|
||||
return Float.parseFloat(defaultValueAsString);
|
||||
|
||||
case DOUBLE:
|
||||
return Double.parseDouble(defaultValueAsString);
|
||||
|
||||
case DATE:
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(Element.DATETIME_PATTERN);
|
||||
try {
|
||||
return sdf.parse(defaultValueAsString);
|
||||
} catch (ParseException e) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("Error while parsing annotated default ");
|
||||
stringBuffer.append(Date.class.getSimpleName());
|
||||
stringBuffer.append(". The provided default value is '");
|
||||
stringBuffer.append(defaultValueAsString);
|
||||
stringBuffer.append("' which does not match the pattern '");
|
||||
stringBuffer.append(Element.DATETIME_PATTERN);
|
||||
stringBuffer.append("'.");
|
||||
throw new RuntimeException(stringBuffer.toString(), e);
|
||||
}
|
||||
|
||||
case STRING:
|
||||
return defaultValueAsString;
|
||||
|
||||
case BINARY:
|
||||
return defaultValueAsString.getBytes();
|
||||
|
||||
case BYTE:
|
||||
return Byte.parseByte(defaultValueAsString);
|
||||
|
||||
case PROPERTY:
|
||||
return null;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -3,8 +3,11 @@
|
|||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -19,20 +22,36 @@ public class EncryptedImpl extends PropertyImpl implements Encrypted {
|
|||
private static final long serialVersionUID = 7823031209294161865L;
|
||||
|
||||
@JsonIgnore
|
||||
protected String value;
|
||||
protected String encryptedValue;
|
||||
|
||||
public EncryptedImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
public String getEncryptedValue() {
|
||||
return encryptedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.model.impl.properties;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value=Header.NAME)
|
||||
public final class HeaderImpl extends PropertyImpl implements Header {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
*/
|
||||
private static final long serialVersionUID = 5102553511155113169L;
|
||||
|
||||
protected UUID uuid;
|
||||
protected String creator;
|
||||
protected String modifiedBy;
|
||||
protected Date creationTime;
|
||||
protected Date lastUpdateTime;
|
||||
|
||||
public HeaderImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
public HeaderImpl(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the uuid
|
||||
*/
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUUID(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModifiedBy() {
|
||||
return modifiedBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastUpdateTime() {
|
||||
return lastUpdateTime;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.model.impl.properties;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value=Metadata.NAME)
|
||||
public final class MetadataImpl extends PropertyImpl implements Metadata {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
*/
|
||||
private static final long serialVersionUID = 5102553511155113169L;
|
||||
|
||||
protected String createdBy;
|
||||
protected Date creationTime;
|
||||
protected String lastUpdateBy;
|
||||
protected Date lastUpdateTime;
|
||||
|
||||
public MetadataImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLastUpdateBy() {
|
||||
return lastUpdateBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastUpdateTime() {
|
||||
return lastUpdateTime;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,29 +12,35 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra
|
|||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value=PropagationConstraint.NAME)
|
||||
public final class PropagationConstraintImpl extends PropertyImpl implements PropagationConstraint {
|
||||
public class PropagationConstraintImpl extends PropertyImpl implements PropagationConstraint {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
*/
|
||||
private static final long serialVersionUID = -4708881022038107688L;
|
||||
|
||||
@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;
|
||||
|
||||
@JsonFormat(shape=JsonFormat.Shape.STRING)
|
||||
@JsonProperty(value=ADD_PROPERTY)
|
||||
protected AddConstraint addConstraint;
|
||||
|
||||
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;
|
||||
|
@ -45,24 +51,4 @@ public final class PropagationConstraintImpl extends PropertyImpl implements Pro
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ 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;
|
||||
|
||||
|
@ -30,7 +29,10 @@ public class ConsistsOfImpl<S extends Resource, T extends Facet> extends
|
|||
}
|
||||
|
||||
public ConsistsOfImpl(S source, T target) {
|
||||
this(source, target, null);
|
||||
super(source, target, null);
|
||||
propagationConstraint = new PropagationConstraintImpl();
|
||||
propagationConstraint.setAddConstraint(AddConstraint.propagate);
|
||||
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan);
|
||||
}
|
||||
|
||||
public ConsistsOfImpl(S source, T target,
|
||||
|
@ -39,8 +41,7 @@ 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.cascade);
|
||||
this.propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade);
|
||||
this.propagationConstraint.setRemoveConstraint(RemoveConstraint.cascadeWhenOrphan);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,18 +3,15 @@
|
|||
*/
|
||||
package org.gcube.informationsystem.model.impl.relations;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@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)
|
||||
@JsonTypeName(value=IsRelatedTo.NAME)
|
||||
public class DummyIsRelatedTo<S extends Resource, T extends Resource>
|
||||
extends IsRelatedToImpl<S, T> implements IsRelatedTo<S, T>{
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ 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;
|
||||
|
||||
|
@ -29,7 +28,10 @@ public abstract class IsRelatedToImpl<S extends Resource, T extends Resource> ex
|
|||
}
|
||||
|
||||
public IsRelatedToImpl(S source, T target) {
|
||||
this(source, target, null);
|
||||
super(source, target, null);
|
||||
propagationConstraint = new PropagationConstraintImpl();
|
||||
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
|
||||
propagationConstraint.setRemoveConstraint(RemoveConstraint.keep);
|
||||
}
|
||||
|
||||
public IsRelatedToImpl(S source, T target,
|
||||
|
@ -39,7 +41,6 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,23 +5,19 @@ 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.serialization.ElementMapper;
|
||||
import org.gcube.informationsystem.utils.ElementMapper;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
|
@ -35,10 +31,6 @@ 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
|
||||
|
@ -53,6 +45,7 @@ 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,
|
||||
|
@ -63,26 +56,6 @@ 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;
|
||||
|
@ -112,7 +85,7 @@ public abstract class RelationImpl<S extends Resource, T extends Entity>
|
|||
if (key.startsWith("@")) {
|
||||
return;
|
||||
}
|
||||
if (key.compareTo(PROPAGATION_CONSTRAINT_PROPERTY) == 0) {
|
||||
if (key.compareTo(PROPAGATION_CONSTRAINT) == 0) {
|
||||
return;
|
||||
}
|
||||
if (key.compareTo(TARGET_PROPERTY) == 0) {
|
||||
|
@ -132,7 +105,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.TYPE_PROPERTY)) {
|
||||
if(map.containsKey(Element.CLASS_PROPERTY)) {
|
||||
String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map);
|
||||
Property property = ElementMapper.unmarshal(Property.class, reserialized);
|
||||
value = property;
|
||||
|
|
|
@ -1,315 +0,0 @@
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
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);
|
||||
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
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);
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package org.gcube.informationsystem.model.reference;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||
|
||||
/**
|
||||
* This interfaces is an helper to identify elements of the model
|
||||
* i.e. Resource, Facet, IsRelatedTo, ConsistsOf
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY })
|
||||
public interface ERElement extends IdentifiableElement, ModelElement {
|
||||
|
||||
/**
|
||||
* Used when requested to include contexts in metadata.
|
||||
* This is not a native property (it is just generated by server for administration clients convenience)
|
||||
*/
|
||||
public static final String CONTEXTS_PROPERTY = "contexts";
|
||||
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonGetter(value = CONTEXTS_PROPERTY)
|
||||
public Map<UUID,String> getContexts();
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
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();
|
||||
|
||||
}
|
|
@ -3,29 +3,20 @@
|
|||
*/
|
||||
package org.gcube.informationsystem.model.reference.entities;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
||||
import org.gcube.informationsystem.model.reference.ERElement;
|
||||
import org.gcube.informationsystem.model.reference.ModelElement;
|
||||
import org.gcube.informationsystem.types.annotations.Abstract;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
|
||||
/**
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Entity
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Basic_Concepts
|
||||
*/
|
||||
@Abstract
|
||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY })
|
||||
//@JsonDeserialize(as=EntityImpl.class) Do not uncomment to manage subclasses
|
||||
@TypeMetadata(name = Entity.NAME, description = "This is the base type for any Entity", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface Entity extends EntityElement, ERElement {
|
||||
public interface Entity extends EntityElement {
|
||||
|
||||
public static final String NAME = "Entity"; //Entity.class.getSimpleName();
|
||||
public static final String DESCRIPTION = "This is the base class for Entities";
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
}
|
||||
|
|
|
@ -6,24 +6,20 @@ 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.Version;
|
||||
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Facet
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Facets
|
||||
*/
|
||||
@Abstract
|
||||
// @JsonDeserialize(as=FacetImpl.class) Do not uncomment to manage subclasses
|
||||
@TypeMetadata(name = "Facet", description = "This is the base type for any Facet", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface Facet extends Entity, SchemaMixedElement {
|
||||
|
||||
public static final String NAME = "Facet"; //Facet.class.getSimpleName();
|
||||
public static final String DESCRIPTION = "This is the base class for Facets";
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
@JsonAnyGetter
|
||||
@JsonSerialize(using = AdditionalPropertiesSerializer.class)
|
||||
|
|
|
@ -8,43 +8,33 @@ 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.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
import org.gcube.informationsystem.types.annotations.ResourceSchemaRelatedEntry;
|
||||
|
||||
/**
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Resource
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Resources
|
||||
*/
|
||||
@Abstract
|
||||
@JsonIgnoreProperties(ignoreUnknown=true)
|
||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY, Resource.CONSISTS_OF_PROPERTY, Resource.IS_RELATED_TO_PROPERTY })
|
||||
// @JsonDeserialize(as=ResourceImpl.class) Do not uncomment to manage subclasses
|
||||
@ResourceSchema(
|
||||
facets={
|
||||
@ResourceSchemaEntry(relation=ConsistsOf.class, facet=Facet.class, min=1, description="Any Resource consists of one or more Facets which describes the different aspects of the resource."),
|
||||
},
|
||||
resources= {
|
||||
@RelatedResourcesEntry(source=Resource.class, relation=IsRelatedTo.class, target=Resource.class, description="Any Resource can be related to any other resource.")
|
||||
@ResourceSchemaRelatedEntry(source=Resource.class, relation=IsRelatedTo.class, target=Resource.class, description="Any Resource can be related to any other resource.")
|
||||
}
|
||||
)
|
||||
@TypeMetadata(name = Resource.NAME, description = "This is the base type for any Resource", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface Resource extends Entity {
|
||||
|
||||
public static final String NAME = "Resource"; //Resource.class.getSimpleName();
|
||||
public static final String DESCRIPTION = "This is the base class for Resources";
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
public static final String CONSISTS_OF_PROPERTY = "consistsOf";
|
||||
public static final String IS_RELATED_TO_PROPERTY = "isRelatedTo";
|
||||
|
|
|
@ -5,27 +5,24 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
|
|||
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
|
||||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonDeserialize(as=EncryptedImpl.class)
|
||||
@TypeMetadata(name = Encrypted.NAME, description = "This type is used to properly manage values must be stored safely (e.g. encrypted) in the IS.", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface Encrypted extends Property {
|
||||
|
||||
public static final String NAME = "Encrypted"; // Encrypted.class.getSimpleName();
|
||||
public static final String NAME = "Encrypted"; //Encrypted.class.getSimpleName();
|
||||
public static final String DESCRIPTION = "This is the base class for Encrypted values";
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
public static final String VALUE = "value";
|
||||
|
||||
@ISProperty(name=VALUE, readonly=false, mandatory=true, nullable=false, description = "The value to store safely in the IS")
|
||||
@ISProperty(name=VALUE, readonly=false, mandatory=true, nullable=false)
|
||||
@JsonGetter(value=VALUE)
|
||||
public String getValue();
|
||||
public String getEncryptedValue();
|
||||
|
||||
@JsonSetter(value=VALUE)
|
||||
public void setValue(String value);
|
||||
public void setEncryptedValue(String encryptedValue);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.model.reference.properties;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
||||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Header
|
||||
*/
|
||||
@JsonDeserialize(as=HeaderImpl.class)
|
||||
public interface Header extends Property {
|
||||
|
||||
public static final String NAME = "Header"; // Header.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* Used to set Creator when the user is not known
|
||||
*/
|
||||
public static final String UNKNOWN_USER = "UNKNOWN_USER";
|
||||
|
||||
public static final String UUID_PROPERTY = "uuid";
|
||||
public static final String CREATOR_PROPERTY = "creator";
|
||||
public static final String MODIFIED_BY_PROPERTY = "modifiedBy";
|
||||
public static final String CREATION_TIME_PROPERTY = "creationTime";
|
||||
public static final String LAST_UPDATE_TIME_PROPERTY = "lastUpdateTime";
|
||||
|
||||
/**
|
||||
* 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, readonly = true, mandatory = true, nullable = false)
|
||||
public UUID getUUID();
|
||||
|
||||
public void setUUID(UUID uuid);
|
||||
|
||||
@ISProperty(name = CREATOR_PROPERTY, readonly = true, mandatory = true, nullable = false)
|
||||
public String getCreator();
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
|
||||
@ISProperty(name = CREATION_TIME_PROPERTY, readonly = true, mandatory = true, nullable = false)
|
||||
public Date getCreationTime();
|
||||
|
||||
@ISProperty(name = MODIFIED_BY_PROPERTY, mandatory = true, nullable = false)
|
||||
public String getModifiedBy();
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
|
||||
@ISProperty(name = LAST_UPDATE_TIME_PROPERTY, mandatory = true, nullable = false)
|
||||
public Date getLastUpdateTime();
|
||||
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.model.reference.properties;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
|
||||
import org.gcube.informationsystem.types.annotations.Final;
|
||||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonDeserialize(as=MetadataImpl.class)
|
||||
@TypeMetadata(name = Metadata.NAME, description = "This type provides metadata per every IdentifiableElement", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
@Final
|
||||
public interface Metadata extends Property {
|
||||
|
||||
public static final String NAME = "Metadata"; // Metadata.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* Used to set Creator when the user is not known
|
||||
*/
|
||||
public static final String UNKNOWN_USER = "UNKNOWN_USER";
|
||||
public static final String HIDDEN_FOR_PRIVACY_USER = "HIDDEN_FOR_PRIVACY";
|
||||
|
||||
public static final String CREATED_BY_PROPERTY = "createdBy";
|
||||
public static final String CREATION_TIME_PROPERTY = "creationTime";
|
||||
public static final String LAST_UPDATE_BY_PROPERTY = "lastUpdateBy";
|
||||
public static final String LAST_UPDATE_TIME_PROPERTY = "lastUpdateTime";
|
||||
|
||||
@ISProperty(name = CREATED_BY_PROPERTY, description = "The user that created the Entity or the Relation. It is initialized at Creation Time.", readonly = true, mandatory = true, nullable = false)
|
||||
public String getCreatedBy();
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
|
||||
@ISProperty(name = CREATION_TIME_PROPERTY, description = "Creation time. It is represented in the format " + Element.DATETIME_PATTERN + ".", readonly = true, mandatory = true, nullable = false)
|
||||
public Date getCreationTime();
|
||||
|
||||
@ISProperty(name = LAST_UPDATE_BY_PROPERTY, description = "The user that made the last update to the Entity or the Relation. At Creation Time, it assumes the same value of " + CREATED_BY_PROPERTY + ".", mandatory = true, nullable = false)
|
||||
public String getLastUpdateBy();
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
|
||||
@ISProperty(name = LAST_UPDATE_TIME_PROPERTY, description = "Last Update time. At creation time it assumes the same value of " + CREATION_TIME_PROPERTY + ". It is represented in the format " + Element.DATETIME_PATTERN, mandatory = true, nullable = false)
|
||||
public Date getLastUpdateTime();
|
||||
|
||||
}
|
|
@ -5,127 +5,62 @@ 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.Changelog;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
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 property
|
||||
* which indicates the behaviour to be held on a target entity
|
||||
* when an event related to a context occurs in the source resource
|
||||
* or directly to the relation.
|
||||
*
|
||||
* The default values of propagation constraints are:
|
||||
* - IsRelatedTo: delete=keep, remove=keep, add=unpropagate;
|
||||
* - ConsistsOf : delete=cascade, remove=cascade, add=propagate.
|
||||
*
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Propagation_Constraint
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Propagation_Constraint
|
||||
*/
|
||||
@JsonDeserialize(as=PropagationConstraintImpl.class)
|
||||
@TypeMetadata(name = PropagationConstraint.NAME, description = "This type provides propagation constraint for Relation", version = "1.1.0")
|
||||
@Changelog({
|
||||
@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 ADD_PROPERTY = "add";
|
||||
public static final String DELETE_PROPERTY = "delete";
|
||||
|
||||
public static final String REMOVE_PROPERTY = "remove";
|
||||
|
||||
public enum AddConstraint {
|
||||
|
||||
/**
|
||||
* When an 'add' action is performed on the source Entity of the relation,
|
||||
* or directly on the relation, then the same 'add' action is performed on
|
||||
* the relation and its target Entity.
|
||||
*/
|
||||
propagate,
|
||||
|
||||
/**
|
||||
* When an 'add' action is performed on the source Entity of the relation,
|
||||
* is performed on source relation only. Trying to perform an 'add' action on
|
||||
* the relation has no effects.
|
||||
*/
|
||||
unpropagate
|
||||
|
||||
}
|
||||
|
||||
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 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
|
||||
* When the source Entity is removed also the target
|
||||
* Entity is removed but if and only if the latter has no other
|
||||
* incoming Relation.
|
||||
*/
|
||||
cascadeWhenOrphan,
|
||||
|
||||
/**
|
||||
* When 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;
|
||||
* When the source Entity is removed also the target
|
||||
* Entity is removed.
|
||||
*/
|
||||
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.
|
||||
* When the source Entity is removed the target Entity
|
||||
* is keep.
|
||||
*/
|
||||
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 enum AddConstraint {
|
||||
|
||||
propagate,
|
||||
|
||||
unpropagate
|
||||
|
||||
}
|
||||
|
||||
@ISProperty(name=REMOVE_PROPERTY)
|
||||
public RemoveConstraint getRemoveConstraint();
|
||||
|
||||
public void setRemoveConstraint(RemoveConstraint removeConstraint);
|
||||
|
||||
|
||||
@ISProperty(name=ADD_PROPERTY)
|
||||
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);
|
||||
|
||||
}
|
||||
|
|
|
@ -7,33 +7,25 @@ import java.util.Map;
|
|||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.base.reference.SchemaMixedElement;
|
||||
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
|
||||
import org.gcube.informationsystem.model.impl.properties.PropertyImpl;
|
||||
import org.gcube.informationsystem.model.reference.ModelElement;
|
||||
import org.gcube.informationsystem.serialization.AdditionalPropertiesSerializer;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
|
||||
|
||||
/**
|
||||
* Root Class for Property types.
|
||||
* It creates a base common type, which is useful for management purpose.
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* Root Class for Property types. It creates a base common type, which is useful
|
||||
* for management purpose.
|
||||
*/
|
||||
// @JsonIgnoreProperties(ignoreUnknown=true)
|
||||
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY })
|
||||
@JsonDeserialize(as=PropertyImpl.class)
|
||||
@TypeMetadata(name = Property.NAME, description = "This is the base type for any Property", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface Property extends PropertyElement, SchemaMixedElement, ModelElement {
|
||||
public interface Property extends PropertyElement, SchemaMixedElement {
|
||||
|
||||
public static final String NAME = "Property"; //Property.class.getSimpleName();
|
||||
public static final String DESCRIPTION = "This is the base class for Properties";
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
@JsonAnyGetter
|
||||
@JsonSerialize(using = AdditionalPropertiesSerializer.class)
|
||||
|
|
|
@ -7,18 +7,12 @@ import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
|||
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#ConsistsOf
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#consistsOf
|
||||
*/
|
||||
@JsonDeserialize(as=ConsistsOfImpl.class)
|
||||
@TypeMetadata(name = ConsistsOf.NAME, description = "This is the base type for any ConsistsOf relation", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface ConsistsOf<S extends Resource, T extends Facet>
|
||||
extends Relation<S, T> {
|
||||
|
||||
|
|
|
@ -5,19 +5,14 @@ package org.gcube.informationsystem.model.reference.relations;
|
|||
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.types.annotations.Abstract;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#IsRelatedTo
|
||||
* This Relation is for internal use only
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isRelatedTo
|
||||
*/
|
||||
@Abstract
|
||||
// @JsonDeserialize(as=IsRelatedToImpl.class) Do not uncomment to manage subclasses
|
||||
@TypeMetadata(name = IsRelatedTo.NAME, description = "This is the base type for any IsRelatedTo relation", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface IsRelatedTo<S extends Resource, T extends Resource>
|
||||
extends Relation<S, T> {
|
||||
|
||||
|
|
|
@ -10,43 +10,28 @@ 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.Version;
|
||||
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Relation
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Relations
|
||||
*/
|
||||
@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 type for any Relation", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface Relation<S extends Resource, T extends Entity> extends RelationElement<S,T>, SchemaMixedElement, ERElement {
|
||||
public interface Relation<S extends Resource, T extends Entity> extends RelationElement<S,T>, SchemaMixedElement {
|
||||
|
||||
public static final String NAME = "Relation"; //Relation.class.getSimpleName();
|
||||
|
||||
public static final String PROPAGATION_CONSTRAINT_PROPERTY = "propagationConstraint";
|
||||
public static final String PROPAGATION_CONSTRAINT = "propagationConstraint";
|
||||
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties({Resource.CONSISTS_OF_PROPERTY, Resource.IS_RELATED_TO_PROPERTY})
|
||||
@JsonGetter(value = SOURCE_PROPERTY)
|
||||
@Override
|
||||
|
@ -64,8 +49,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)
|
||||
@ISProperty(name = PROPAGATION_CONSTRAINT)
|
||||
public PropagationConstraint getPropagationConstraint();
|
||||
|
||||
@JsonAnyGetter
|
||||
|
|
|
@ -1,212 +0,0 @@
|
|||
package org.gcube.informationsystem.queries.templates.impl.entities;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.informationsystem.base.impl.entities.EntityElementImpl;
|
||||
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
|
||||
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value=QueryTemplate.NAME)
|
||||
public class QueryTemplateImpl extends EntityElementImpl implements QueryTemplate {
|
||||
|
||||
/**
|
||||
* Generated Serial version UID
|
||||
*/
|
||||
private static final long serialVersionUID = -1096809036997782113L;
|
||||
|
||||
protected String name;
|
||||
protected String description;
|
||||
|
||||
protected ObjectMapper objectMapper;
|
||||
protected JsonNode template;
|
||||
|
||||
|
||||
protected Map<String, TemplateVariable> templateVariables;
|
||||
protected JsonNode params;
|
||||
|
||||
public QueryTemplateImpl() {
|
||||
this.templateVariables = new HashMap<>();
|
||||
this.objectMapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateAsString() throws JsonProcessingException {
|
||||
return objectMapper.writeValueAsString(template);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemplate(String template) throws JsonProcessingException, IOException {
|
||||
this.template = objectMapper.readTree(template);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemplate(JsonNode template) {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, TemplateVariable> getTemplateVariables() {
|
||||
return templateVariables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTemplateVariable(TemplateVariable templateVariable) {
|
||||
String name = templateVariable.getName();
|
||||
this.templateVariables.put(name, templateVariable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectNode getParamsFromDefaultValues() {
|
||||
ObjectNode objectNode = objectMapper.createObjectNode();
|
||||
|
||||
for(TemplateVariable tv : templateVariables.values()) {
|
||||
Object defaultValue = tv.getDefaultValue();
|
||||
JsonNode jsonNode = ElementMapper.getObjectMapper().valueToTree(defaultValue);
|
||||
objectNode.put(tv.getName(), jsonNode);
|
||||
|
||||
// if(defaultValue instanceof Integer) {
|
||||
// objectNode.put(tv.getName(), (Integer) defaultValue);
|
||||
// continue;
|
||||
// }
|
||||
// if(defaultValue instanceof Boolean) {
|
||||
// objectNode.put(tv.getName(), (Boolean) defaultValue);
|
||||
// continue;
|
||||
// }
|
||||
// if(defaultValue instanceof Integer) {
|
||||
// objectNode.put(tv.getName(), (Integer) defaultValue);
|
||||
// continue;
|
||||
// }
|
||||
// if(defaultValue instanceof Short) {
|
||||
// objectNode.put(tv.getName(), (Short) defaultValue);
|
||||
// continue;
|
||||
// }
|
||||
// if(defaultValue instanceof Long) {
|
||||
// objectNode.put(tv.getName(), (Long) defaultValue);
|
||||
// continue;
|
||||
// }
|
||||
// if(defaultValue instanceof Float) {
|
||||
// objectNode.put(tv.getName(), (Float) defaultValue);
|
||||
// continue;
|
||||
// }
|
||||
// if(defaultValue instanceof Double) {
|
||||
// objectNode.put(tv.getName(), (Double) defaultValue);
|
||||
// continue;
|
||||
// }
|
||||
// if(defaultValue instanceof Date) {
|
||||
// SimpleDateFormat sdf = new SimpleDateFormat(Element.DATETIME_PATTERN);
|
||||
// objectNode.put(tv.getName(), sdf.format((Date)defaultValue));
|
||||
// continue;
|
||||
// }
|
||||
// if(defaultValue instanceof String) {
|
||||
// objectNode.put(tv.getName(), (String) defaultValue);
|
||||
// continue;
|
||||
// }
|
||||
// if(defaultValue instanceof Byte[]) {
|
||||
// objectNode.put(tv.getName(), defaultValue.toString().getBytes());
|
||||
// continue;
|
||||
// }
|
||||
// if(defaultValue instanceof Byte) {
|
||||
// objectNode.put(tv.getName(), (Byte) defaultValue);
|
||||
// continue;
|
||||
// }
|
||||
// if(defaultValue instanceof Property) {
|
||||
// JsonNode jsonNode = ElementMapper.getObjectMapper().valueToTree(defaultValue);
|
||||
// objectNode.put(tv.getName(), jsonNode);
|
||||
// continue;
|
||||
// }
|
||||
|
||||
}
|
||||
return objectNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode getJsonQuery() throws Exception {
|
||||
ObjectNode objectNode = getParamsFromDefaultValues();
|
||||
return getJsonQuery(objectNode);
|
||||
}
|
||||
|
||||
protected JsonNode replaceVariables(JsonNode jsonNode) throws Exception {
|
||||
Iterator<String> fieldNames = jsonNode.fieldNames();
|
||||
while(fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode node = jsonNode.get(fieldName);
|
||||
switch (node.getNodeType()) {
|
||||
case OBJECT:
|
||||
node = replaceVariables(node);
|
||||
((ObjectNode) jsonNode).set(fieldName, node);
|
||||
break;
|
||||
|
||||
case ARRAY:
|
||||
ArrayNode arrayNode = (ArrayNode) node;
|
||||
for(int i = 0; i < arrayNode.size(); i++) {
|
||||
JsonNode arrayElement = arrayNode.get(i);
|
||||
arrayElement = replaceVariables(arrayElement);
|
||||
arrayNode.set(i, arrayElement);
|
||||
}
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
String value = node.asText();
|
||||
if(templateVariables.containsKey(value)) {
|
||||
JsonNode jn = params.get(value);
|
||||
if(jn == null) {
|
||||
throw new Exception("No value provided for " + value + " variables");
|
||||
}
|
||||
((ObjectNode) jsonNode).set(fieldName, jn);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return jsonNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode getJsonQuery(JsonNode values) throws Exception {
|
||||
this.params = values;
|
||||
JsonNode query = template.deepCopy();
|
||||
query = replaceVariables(query);
|
||||
return query;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.queries.templates.impl.properties;
|
||||
|
||||
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.properties.PropertyElementImpl;
|
||||
import org.gcube.informationsystem.model.impl.properties.AttributeUtility;
|
||||
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
|
||||
import org.gcube.informationsystem.types.PropertyTypeName;
|
||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value=TemplateVariable.NAME)
|
||||
public class TemplateVariableImpl extends PropertyElementImpl implements TemplateVariable {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
*/
|
||||
private static final long serialVersionUID = 2628113641100130640L;
|
||||
|
||||
protected String name;
|
||||
protected String description;
|
||||
private Integer max= null;
|
||||
private Integer min= null;
|
||||
private String regexp= null;
|
||||
private PropertyTypeName propertyTypeName = null;
|
||||
protected Object defaultValue;
|
||||
|
||||
public TemplateVariableImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMax(Integer max) {
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMin(Integer min) {
|
||||
this.min = min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegexp() {
|
||||
return regexp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRegexp(String regexp) {
|
||||
AttributeUtility.checkRegex(regexp, null);
|
||||
this.regexp = regexp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPropertyType() {
|
||||
return propertyTypeName.toString();
|
||||
}
|
||||
|
||||
@JsonSetter(value = PropertyDefinition.PROPERTY_TYPE_PROPERTY)
|
||||
public void setPropertyType(String type) {
|
||||
this.propertyTypeName = new PropertyTypeName(type);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public PropertyTypeName getPropertyTypeName() {
|
||||
return propertyTypeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultValue(Object defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TemplateVariable ["
|
||||
+ "name=" + name
|
||||
+ ", description=" + description
|
||||
+ ", max=" + max
|
||||
+ ", min=" + min
|
||||
+ ", regexpr=" + regexp
|
||||
+ ", type=" + propertyTypeName.toString()
|
||||
+ ", defaultValue=" + (defaultValue == null ? "null" : defaultValue.toString())
|
||||
+ "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
package org.gcube.informationsystem.queries.templates.reference.entities;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
||||
import org.gcube.informationsystem.queries.templates.impl.entities.QueryTemplateImpl;
|
||||
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
|
||||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown=true)
|
||||
@JsonDeserialize(as=QueryTemplateImpl.class)
|
||||
@TypeMetadata(name = QueryTemplate.NAME, description = "The type used to store Query Templates", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface QueryTemplate extends EntityElement {
|
||||
|
||||
public static final String NAME = "QueryTemplate"; //QueryTemplate.class.getSimpleName();
|
||||
|
||||
public static final String NAME_PROPERTY = "name";
|
||||
public static final String DESCRIPTION_PROPERTY = "description";
|
||||
|
||||
public static final String TEMPLATE_PROPERTY = "template";
|
||||
public static final String TEMPLATE_VARIABLES_PROPERTY = "templateVariables";
|
||||
|
||||
@ISProperty(name = NAME_PROPERTY, description = "The name of the Query Template. Among UUID univocally identifiy the Query Template.", readonly = true, mandatory = true, nullable = false)
|
||||
public String getName();
|
||||
|
||||
public void setName(String name);
|
||||
|
||||
@ISProperty(name = DESCRIPTION_PROPERTY, description = "The description of the Query Template.", readonly = false, mandatory = true, nullable = false)
|
||||
public String getDescription();
|
||||
|
||||
public void setDescription(String description);
|
||||
|
||||
@JsonIgnore
|
||||
@ISProperty(name = TEMPLATE_PROPERTY, description = "The Query Template. It can contains query variables to be replaced to obtain a runnable query.", readonly = false, mandatory = true, nullable = false)
|
||||
public String getTemplateAsString() throws JsonProcessingException;
|
||||
|
||||
@JsonIgnore
|
||||
public void setTemplate(String template) throws JsonProcessingException, IOException;
|
||||
|
||||
@JsonSetter(value = TEMPLATE_PROPERTY)
|
||||
public void setTemplate(JsonNode template);
|
||||
|
||||
@JsonGetter(value = TEMPLATE_PROPERTY)
|
||||
public JsonNode getTemplate();
|
||||
|
||||
@JsonGetter(value = TEMPLATE_VARIABLES_PROPERTY)
|
||||
@ISProperty(name = TEMPLATE_VARIABLES_PROPERTY, description = "The Query Template Variables. It can contains Query Template Variable to be replaced to obtain a runnable query.", readonly = false, mandatory = true, nullable = false)
|
||||
public Map<String, TemplateVariable> getTemplateVariables();
|
||||
|
||||
@JsonIgnore
|
||||
/**
|
||||
* Adding variable which already exists, the previous value will be override.
|
||||
* @param templateDefaultValue
|
||||
*/
|
||||
public void addTemplateVariable(TemplateVariable templateVariable);
|
||||
|
||||
/**
|
||||
* Create an ObjectNode which can be used as parameters to obtain a
|
||||
* JSON Query from the Query Template.
|
||||
* It uses the default values provided in TemplateVariables.
|
||||
* @return the created object node
|
||||
*/
|
||||
@JsonIgnore
|
||||
public ObjectNode getParamsFromDefaultValues();
|
||||
|
||||
/**
|
||||
* @return the JsonQuery replacing the variables using the default values contained in TemplateVariables
|
||||
* @throws Exception
|
||||
*/
|
||||
@JsonIgnore
|
||||
public JsonNode getJsonQuery() throws Exception;
|
||||
|
||||
/**
|
||||
* @param values
|
||||
* @return the JsonQuery replacing the variables using the provided values
|
||||
* @throws Exception
|
||||
*/
|
||||
@JsonIgnore
|
||||
public JsonNode getJsonQuery(JsonNode values) throws Exception;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package org.gcube.informationsystem.queries.templates.reference.properties;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.gcube.informationsystem.base.reference.Attribute;
|
||||
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
|
||||
import org.gcube.informationsystem.queries.templates.impl.properties.TemplateVariableImpl;
|
||||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonDeserialize(as=TemplateVariableImpl.class)
|
||||
@TypeMetadata(name = TemplateVariable.NAME, description = "This is the class used to define the a TemplateVariable", version = Version.MINIMAL_VERSION_STRING)
|
||||
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
|
||||
public interface TemplateVariable extends PropertyElement, Attribute {
|
||||
|
||||
public static final String NAME = "TemplateVariable"; // TemplateVariable.class.getSimpleName();
|
||||
|
||||
|
||||
@ISProperty(name = Attribute.NAME_PROPERTY, description = "The name of the Query Template Variable.", readonly = true, mandatory = true, nullable = false)
|
||||
public String getName();
|
||||
|
||||
@ISProperty(name = Attribute.DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
|
||||
public String getDescription();
|
||||
|
||||
@ISProperty(name = Attribute.MAX_PROPERTY, readonly = false, mandatory = true, nullable = false)
|
||||
public Integer getMax();
|
||||
|
||||
@ISProperty(name = Attribute.MIN_PROPERTY, readonly = false, mandatory = true, nullable = false)
|
||||
public Integer getMin();
|
||||
|
||||
@ISProperty(name = Attribute.REGEX_PROPERTY, readonly = false, mandatory = true, nullable = false)
|
||||
public String getRegexp();
|
||||
|
||||
@ISProperty(name = Attribute.PROPERTY_TYPE_PROPERTY, readonly = false, mandatory = true, nullable = false)
|
||||
public String getPropertyType();
|
||||
|
||||
@ISProperty(name = Attribute.DEFAULT_VALUE_PROPERTY, readonly = false, mandatory = false, nullable = true)
|
||||
public Object getDefaultValue();
|
||||
|
||||
}
|
|
@ -1,435 +0,0 @@
|
|||
package org.gcube.informationsystem.serialization;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonGenerationException;
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.gcube.com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JavaType;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import org.gcube.com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.discovery.Discovery;
|
||||
import org.gcube.informationsystem.discovery.knowledge.Knowledge;
|
||||
import org.gcube.informationsystem.model.reference.ModelElement;
|
||||
import org.gcube.informationsystem.model.reference.properties.Property;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class ElementMapper {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ElementMapper.class);
|
||||
|
||||
protected static final ObjectMapper mapper;
|
||||
|
||||
protected static final Map<String, Class<? extends Element>> knownTypes;
|
||||
|
||||
/**
|
||||
* @return the ObjectMapper
|
||||
*/
|
||||
public static ObjectMapper getObjectMapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
static {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
mapper.getSerializationConfig().with(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
|
||||
|
||||
/*
|
||||
* Instructing Jackson to serialize any Date in the defined pattern
|
||||
*/
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(Element.DATETIME_PATTERN);
|
||||
mapper.setDateFormat(sdf);
|
||||
|
||||
knownTypes = new HashMap<>();
|
||||
|
||||
List<Package> packages = new ArrayList<Package>();
|
||||
|
||||
Class<Type> tdClz = Type.class;
|
||||
ElementMapper.registerSubtype(tdClz);
|
||||
packages.add(tdClz.getPackage());
|
||||
|
||||
AccessType[] accessTypes = AccessType.values();
|
||||
for(AccessType accessType : accessTypes) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
Class clz = accessType.getTypeClass();
|
||||
if(!Type.class.isAssignableFrom(clz)) {
|
||||
Class<Element> dummyClz = accessType.getDummyImplementationClass();
|
||||
if(dummyClz != null) {
|
||||
// ElementMapper.registerSubtypes(clz, dummyClz);
|
||||
ElementMapper.registerSubtype(dummyClz);
|
||||
}else {
|
||||
ElementMapper.registerSubtype(clz);
|
||||
}
|
||||
packages.add(clz.getPackage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Set<AccessType> baseTypes = new LinkedHashSet<>();
|
||||
baseTypes.add(AccessType.PROPERTY_ELEMENT);
|
||||
baseTypes.add(AccessType.ENTITY_ELEMENT);
|
||||
baseTypes.add(AccessType.RELATION_ELEMENT);
|
||||
|
||||
for(AccessType accessType : baseTypes) {
|
||||
Class<Element> clz = accessType.getTypeClass();
|
||||
try {
|
||||
Discovery<? extends Element> discovery = new Discovery<>(clz);
|
||||
discovery.addPackages(packages);
|
||||
discovery.addDiscoveredElementActions(new ElementMappingAction());
|
||||
discovery.discover();
|
||||
}catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Knowledge.getInstance();
|
||||
}catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// This add the ElementDeserializer which has been deprecated thank to the fix in
|
||||
// public static <El extends Element> void registerSubtypes(Class<El> clz, Class<El> implementationClass) {
|
||||
// String typeName = TypeMapper.getType(clz);
|
||||
// SimpleModule isModule = new SimpleModule(typeName);
|
||||
// isModule.addDeserializer(clz, new ElementDeserializer<>(clz, mapper));
|
||||
// mapper.registerModule(isModule);
|
||||
// registerSubtype(implementationClass);
|
||||
// }
|
||||
|
||||
public static <El extends Element> void registerSubtype(Class<El> clz) {
|
||||
String typeName = TypeMapper.getType(clz);
|
||||
knownTypes.put(typeName, clz);
|
||||
mapper.registerSubtypes(clz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the serialization of a given resource to a given
|
||||
* {@link OutputStream} .
|
||||
*
|
||||
* @param object the resource
|
||||
* @param stream the stream in input
|
||||
* @throws IOException
|
||||
* @throws JsonMappingException
|
||||
* @throws JsonGenerationException
|
||||
*/
|
||||
public static <T extends OutputStream, El extends Element> T marshal(El object, T stream)
|
||||
throws JsonGenerationException, JsonMappingException, IOException {
|
||||
mapper.writeValue(stream, object);
|
||||
return stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the serialization of a given resource to a given {@link Writer} .
|
||||
* @param object the resource
|
||||
* @param writer the writer in input
|
||||
* @throws IOException
|
||||
* @throws JsonMappingException
|
||||
* @throws JsonGenerationException
|
||||
*/
|
||||
public static <T extends Writer, El extends Element> T marshal(El object, T writer)
|
||||
throws JsonGenerationException, JsonMappingException, IOException {
|
||||
mapper.writeValue(writer, object);
|
||||
return writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the String serialization of a given object
|
||||
* @param object the object to marshal
|
||||
* @return the String serialization of a given resource
|
||||
* @throws JsonProcessingException
|
||||
*/
|
||||
public static <El extends Element> String marshal(El object) throws JsonProcessingException {
|
||||
return mapper.writeValueAsString(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the String serialization of a given list
|
||||
* @param list the list to marshal
|
||||
* @return the String serialization of a given list
|
||||
* @throws JsonProcessingException
|
||||
*/
|
||||
public static <El extends Element> String marshal(List<El> list) throws JsonProcessingException {
|
||||
JavaType type = mapper.getTypeFactory().constructCollectionType(List.class, Element.class);
|
||||
return mapper.writerFor(type).writeValueAsString(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the String serialization of a given array
|
||||
* @param array the array to marshal
|
||||
* @return the String serialization of a given array
|
||||
* @throws JsonProcessingException
|
||||
*/
|
||||
public static <El extends Element> String marshal(El[] array) throws JsonProcessingException {
|
||||
return mapper.writeValueAsString(array);
|
||||
}
|
||||
|
||||
protected static StringBuffer getError(String unknownType) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(unknownType);
|
||||
stringBuffer.append(" is an unknown type. Please provide ");
|
||||
stringBuffer.append(ModelElement.SUPERTYPES_PROPERTY);
|
||||
stringBuffer.append(" property as string array to allow to instantiate the most appropriated class.");
|
||||
return stringBuffer;
|
||||
}
|
||||
|
||||
protected static ObjectNode setTypeToBestAvailable(ObjectNode objectNode) {
|
||||
String unknownType = objectNode.get(Element.TYPE_PROPERTY).asText();
|
||||
ArrayNode arrayNode = (ArrayNode) objectNode.get(ModelElement.SUPERTYPES_PROPERTY);
|
||||
|
||||
String candidatedSupertype = null;
|
||||
if(arrayNode!=null) {
|
||||
for(int i = 0; i < arrayNode.size(); i++) {
|
||||
String superType = arrayNode.get(i).asText();
|
||||
if(knownTypes.containsKey(superType)) {
|
||||
candidatedSupertype = superType;
|
||||
try {
|
||||
// Checking if it is one of the base type. In some cases we need to use dummy
|
||||
// implementation
|
||||
AccessType accessType = AccessType.getAccessType(superType);
|
||||
// It is one of the BaseType.
|
||||
// Looking if we need to set the dummy implementation class
|
||||
if(accessType.getDummyImplementationClass()!=null) {
|
||||
// This should not happen because the type has been assigned already to the dummy class.
|
||||
candidatedSupertype = accessType.getDummyImplementationClass().getSimpleName();
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
// can continue discovery
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(candidatedSupertype!=null) {
|
||||
if(!objectNode.has(ModelElement.EXPECTED_TYPE_PROPERTY)) {
|
||||
objectNode.set(ModelElement.EXPECTED_TYPE_PROPERTY, objectNode.get(Element.TYPE_PROPERTY));
|
||||
}
|
||||
objectNode.set(Element.TYPE_PROPERTY, new TextNode(candidatedSupertype));
|
||||
objectNode.remove(ModelElement.SUPERTYPES_PROPERTY);
|
||||
return objectNode;
|
||||
}
|
||||
|
||||
StringBuffer stringBuffer = getError(unknownType);
|
||||
logger.trace("Unable to unmarshall {}. {}", objectNode.toString(), stringBuffer.toString());
|
||||
throw new RuntimeException(stringBuffer.toString());
|
||||
}
|
||||
|
||||
protected static JsonNode analizeTypes(ObjectNode objectNode) {
|
||||
String cls = null;
|
||||
|
||||
JsonNode typeJN = objectNode.get(Element.TYPE_PROPERTY);
|
||||
if(typeJN !=null) {
|
||||
cls = objectNode.get(Element.TYPE_PROPERTY).asText();
|
||||
}
|
||||
|
||||
if(cls==null && objectNode.getNodeType()==JsonNodeType.OBJECT) {
|
||||
cls = Property.NAME;
|
||||
}
|
||||
|
||||
if(!knownTypes.containsKey(cls)) {
|
||||
objectNode = setTypeToBestAvailable(objectNode);
|
||||
}
|
||||
Iterator<String> iterator = objectNode.fieldNames();
|
||||
while(iterator.hasNext()) {
|
||||
String fieldName = iterator.next();
|
||||
JsonNode jn = objectNode.get(fieldName);
|
||||
switch (jn.getNodeType()) {
|
||||
case OBJECT:
|
||||
jn = analizeTypes((ObjectNode)jn);
|
||||
break;
|
||||
|
||||
case ARRAY:
|
||||
jn = analizeTypes((ArrayNode) jn);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
objectNode.replace(fieldName, jn);
|
||||
}
|
||||
return objectNode;
|
||||
}
|
||||
|
||||
protected static ArrayNode analizeTypes(ArrayNode arrayNode) {
|
||||
ArrayNode ret = mapper.createArrayNode();
|
||||
|
||||
for(JsonNode jsonNode : arrayNode) {
|
||||
|
||||
switch (jsonNode.getNodeType()) {
|
||||
case OBJECT:
|
||||
jsonNode = analizeTypes((ObjectNode) jsonNode);
|
||||
break;
|
||||
|
||||
case ARRAY:
|
||||
jsonNode = analizeTypes((ArrayNode) jsonNode);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ret.add(jsonNode);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a resource of given class from its serialization in a given
|
||||
* {@link Reader}.
|
||||
* @param clz the class of the resource
|
||||
* @param reader the reader
|
||||
* @return the resource
|
||||
* @throws JsonParseException
|
||||
* @throws JsonMappingException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static <El extends Element> El unmarshal(Class<El> clz, Reader reader)
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
try {
|
||||
return mapper.readValue(reader, clz);
|
||||
} catch (InvalidTypeIdException e) {
|
||||
if(!ModelElement.class.isAssignableFrom(clz)) {
|
||||
throw e;
|
||||
}
|
||||
JsonNode jsonNode = mapper.readTree(reader);
|
||||
jsonNode = analizeTypes((ObjectNode) jsonNode);
|
||||
try {
|
||||
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
|
||||
}catch (Throwable t) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a resource of given class from its serialization in a given
|
||||
* {@link InputStream}.
|
||||
* @param clz the class of the resource
|
||||
* @param stream the stream
|
||||
* @return the resource
|
||||
* @throws IOException
|
||||
* @throws JsonMappingException
|
||||
* @throws JsonParseException
|
||||
*/
|
||||
public static <El extends Element> El unmarshal(Class<El> clz, InputStream stream)
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
try {
|
||||
return mapper.readValue(stream, clz);
|
||||
} catch (InvalidTypeIdException e) {
|
||||
if(!ModelElement.class.isAssignableFrom(clz)) {
|
||||
throw e;
|
||||
}
|
||||
JsonNode jsonNode = mapper.readTree(stream);
|
||||
jsonNode = analizeTypes((ObjectNode) jsonNode);
|
||||
try {
|
||||
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
|
||||
}catch (Throwable t) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a resource of given class from its serialization in a given String
|
||||
* @param clz the class of the resource
|
||||
* @param string
|
||||
* @return the resource
|
||||
* @throws JsonParseException
|
||||
* @throws JsonMappingException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static <El extends Element> El unmarshal(Class<El> clz, String string)
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
try {
|
||||
return mapper.readValue(string, clz);
|
||||
} catch (InvalidTypeIdException e) {
|
||||
if(!ModelElement.class.isAssignableFrom(clz)) {
|
||||
throw e;
|
||||
}
|
||||
JsonNode jsonNode = mapper.readTree(string);
|
||||
jsonNode = analizeTypes((ObjectNode) jsonNode);
|
||||
try {
|
||||
return ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode));
|
||||
}catch (Throwable t) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <El extends Element> List<El> unmarshalList(Class<El> clz, String string)
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, clz);
|
||||
try {
|
||||
return mapper.readValue(string, type);
|
||||
} catch (InvalidTypeIdException e) {
|
||||
if(!ModelElement.class.isAssignableFrom(clz)) {
|
||||
throw e;
|
||||
}
|
||||
List<El> ret = new ArrayList<>();
|
||||
ArrayNode arrayNode = (ArrayNode) mapper.readTree(string);
|
||||
try {
|
||||
for(JsonNode jsonNode : arrayNode) {
|
||||
jsonNode = analizeTypes((ObjectNode) jsonNode);
|
||||
ret.add(ElementMapper.unmarshal(clz, mapper.writeValueAsString(jsonNode)));
|
||||
}
|
||||
}catch (Throwable t) {
|
||||
throw e;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public static <El extends Element> List<El> unmarshalList(String string)
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, Element.class);
|
||||
try {
|
||||
return mapper.readValue(string, type);
|
||||
} catch (InvalidTypeIdException e) {
|
||||
List<El> ret = new ArrayList<>();
|
||||
ArrayNode arrayNode = (ArrayNode) mapper.readTree(string);
|
||||
try {
|
||||
for(JsonNode jsonNode : arrayNode) {
|
||||
jsonNode = analizeTypes((ObjectNode) jsonNode);
|
||||
ret.add((El) ElementMapper.unmarshal(Element.class, mapper.writeValueAsString(jsonNode)));
|
||||
}
|
||||
}catch (Throwable t) {
|
||||
throw e;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package org.gcube.informationsystem.tree;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public interface NodeElaborator<T> {
|
||||
|
||||
public void elaborate(Node<T> node, int level) throws Exception;
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
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);
|
||||
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
package org.gcube.informationsystem.types;
|
||||
/*
|
||||
*
|
||||
* * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com)
|
||||
* *
|
||||
* * Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* * you may not use this file except in compliance with the License.
|
||||
* * You may obtain a copy of the License at
|
||||
* *
|
||||
* * http://www.apache.org/licenses/LICENSE-2.0
|
||||
* *
|
||||
* * Unless required by applicable law or agreed to in writing, software
|
||||
* * distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* * See the License for the specific language governing permissions and
|
||||
* * limitations under the License.
|
||||
* *
|
||||
* * For more information: http://www.orientechnologies.com
|
||||
*
|
||||
*/
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.model.reference.properties.Property;
|
||||
|
||||
/**
|
||||
* @author Lucio Lelii (ISTI - CNR)
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* Create a mapping with OrientDB Types
|
||||
* https://orientdb.gitbooks.io/orientdb-manual/content/orientdb.wiki/Types.html
|
||||
* and gCube IS Types
|
||||
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Property
|
||||
* The code is copied from OrientDB source Code
|
||||
* https://github.com/orientechnologies/orientdb/blob/master/core/src/main/java/com/orientechnologies/orient/core/metadata/schema/OType.java
|
||||
* and adapted for gCube purpose.
|
||||
*/
|
||||
public class OrientDBType {
|
||||
|
||||
public enum OType {
|
||||
BOOLEAN("Boolean", 0),
|
||||
|
||||
INTEGER("Integer", 1),
|
||||
|
||||
SHORT("Short", 2),
|
||||
|
||||
LONG("Long", 3),
|
||||
|
||||
FLOAT("Float", 4),
|
||||
|
||||
DOUBLE("Double", 5),
|
||||
|
||||
DATETIME("Datetime", 6),
|
||||
|
||||
STRING("String", 7),
|
||||
|
||||
BYNARY("Bynary", 8),
|
||||
|
||||
PROPERTY("Property", 9),
|
||||
|
||||
PROPERTYLIST("Property List", 10),
|
||||
|
||||
PROPERTYSET("Property Set", 11),
|
||||
|
||||
PROPERTYMAP("Property Map", 12),
|
||||
|
||||
BYTE("Byte", 17),
|
||||
|
||||
BINARY("Binary", 8);
|
||||
|
||||
private String stringValue;
|
||||
private int intValue;
|
||||
|
||||
OType(String stringValue, int intValue) {
|
||||
this.stringValue = stringValue;
|
||||
this.intValue = intValue;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
public int getIntValue() {
|
||||
return intValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static final Map<Class<?>,OType> TYPES_BY_CLASS = new HashMap<Class<?>,OType>();
|
||||
|
||||
static {
|
||||
|
||||
// This is made by hand because not all types should be add.
|
||||
TYPES_BY_CLASS.put(Boolean.TYPE, OType.BOOLEAN);
|
||||
TYPES_BY_CLASS.put(Boolean.class, OType.BOOLEAN);
|
||||
|
||||
TYPES_BY_CLASS.put(Integer.TYPE, OType.INTEGER);
|
||||
TYPES_BY_CLASS.put(Integer.class, OType.INTEGER);
|
||||
TYPES_BY_CLASS.put(BigInteger.class, OType.INTEGER);
|
||||
|
||||
TYPES_BY_CLASS.put(Short.TYPE, OType.SHORT);
|
||||
TYPES_BY_CLASS.put(Short.class, OType.SHORT);
|
||||
|
||||
TYPES_BY_CLASS.put(Long.TYPE, OType.LONG);
|
||||
TYPES_BY_CLASS.put(Long.class, OType.LONG);
|
||||
|
||||
TYPES_BY_CLASS.put(Float.TYPE, OType.FLOAT);
|
||||
TYPES_BY_CLASS.put(Float.class, OType.FLOAT);
|
||||
|
||||
TYPES_BY_CLASS.put(Double.TYPE, OType.DOUBLE);
|
||||
TYPES_BY_CLASS.put(Double.class, OType.DOUBLE);
|
||||
|
||||
TYPES_BY_CLASS.put(Date.class, OType.DATETIME);
|
||||
TYPES_BY_CLASS.put(Calendar.class, OType.DATETIME);
|
||||
|
||||
TYPES_BY_CLASS.put(String.class, OType.STRING);
|
||||
TYPES_BY_CLASS.put(Character.class, OType.STRING);
|
||||
TYPES_BY_CLASS.put(Character.TYPE, OType.STRING);
|
||||
|
||||
TYPES_BY_CLASS.put(Property.class, OType.PROPERTY);
|
||||
|
||||
TYPES_BY_CLASS.put(List.class, OType.PROPERTYLIST);
|
||||
|
||||
TYPES_BY_CLASS.put(Set.class, OType.PROPERTYSET);
|
||||
|
||||
TYPES_BY_CLASS.put(Map.class, OType.PROPERTYMAP);
|
||||
|
||||
TYPES_BY_CLASS.put(Byte.TYPE, OType.BYTE);
|
||||
TYPES_BY_CLASS.put(Byte.class, OType.BYTE);
|
||||
|
||||
TYPES_BY_CLASS.put(byte[].class, OType.BYNARY);
|
||||
TYPES_BY_CLASS.put(Byte[].class, OType.BYNARY);
|
||||
|
||||
TYPES_BY_CLASS.put(Enum.class, OType.STRING);
|
||||
TYPES_BY_CLASS.put(URI.class, OType.STRING);
|
||||
TYPES_BY_CLASS.put(URL.class, OType.STRING);
|
||||
TYPES_BY_CLASS.put(UUID.class, OType.STRING);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the correspondent type by checking the "assignability" of the
|
||||
* class received as parameter.
|
||||
*
|
||||
* @param iClass Class to check
|
||||
* @return OType instance if found, otherwise null
|
||||
*/
|
||||
public static OType getTypeByClass(final Class<?> iClass) {
|
||||
if(iClass == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
OType type = TYPES_BY_CLASS.get(iClass);
|
||||
|
||||
if(type == null && Enum.class.isAssignableFrom(iClass)) {
|
||||
type = TYPES_BY_CLASS.get(Enum.class);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,429 +0,0 @@
|
|||
package org.gcube.informationsystem.types;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class PropertyTypeName {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(PropertyTypeName.class);
|
||||
|
||||
public enum BaseTypeGroup {
|
||||
|
||||
ANY( BaseType.values()),
|
||||
BOOLEAN( new BaseType[]{ BaseType.BOOLEAN } ),
|
||||
NUMERIC( new BaseType[]{ BaseType.INTEGER, BaseType.SHORT, BaseType.LONG, BaseType.FLOAT }),
|
||||
STRING( new BaseType[]{ BaseType.STRING }),
|
||||
DATE( new BaseType[]{ BaseType.DATE } ),
|
||||
BITS( new BaseType[]{ BaseType.BINARY, BaseType.BYTE } ),
|
||||
COMPLEX( new BaseType[]{ BaseType.PROPERTY } ),
|
||||
COLLECTION( new BaseType[]{ BaseType.LIST, BaseType.SET } ),
|
||||
MAP( new BaseType[]{ BaseType.MAP });
|
||||
|
||||
private final BaseType[] group;
|
||||
|
||||
private BaseTypeGroup(BaseType[] group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public BaseType[] getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum BaseType {
|
||||
|
||||
ANY("Any"),
|
||||
|
||||
BOOLEAN("Boolean"),
|
||||
|
||||
INTEGER("Integer"),
|
||||
|
||||
SHORT("Short"),
|
||||
|
||||
LONG("Long"),
|
||||
|
||||
FLOAT("Float"),
|
||||
|
||||
DOUBLE("Double"),
|
||||
|
||||
DATE("Date"),
|
||||
|
||||
STRING("String"),
|
||||
|
||||
BINARY("Binary"),
|
||||
|
||||
BYTE("Byte"),
|
||||
|
||||
/*
|
||||
* All base types which DON'T have a generic must be defined BEFORE BaseType.PROPERTY
|
||||
*/
|
||||
|
||||
PROPERTY("Property"),
|
||||
|
||||
/*
|
||||
* All base types which have a generic must be defined AFTER BaseType.PROPERTY
|
||||
*/
|
||||
|
||||
LIST("List"),
|
||||
|
||||
SET("Set"),
|
||||
|
||||
MAP("Map");
|
||||
|
||||
private final String stringValue;
|
||||
|
||||
BaseType(final String stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
protected static final Map<String, BaseType> map;
|
||||
|
||||
static {
|
||||
map = new HashMap<>();
|
||||
for(BaseType baseType : BaseType.values()) {
|
||||
map.put(baseType.stringValue, baseType);
|
||||
}
|
||||
}
|
||||
|
||||
public static BaseType getBaseTypeFromString(String type) {
|
||||
BaseType baseType = map.get(type);
|
||||
if(baseType==null) {
|
||||
throw new IllegalArgumentException("No BaseType having '" + type + "' as string value. Allowed values are " + map.keySet());
|
||||
}
|
||||
return baseType;
|
||||
}
|
||||
}
|
||||
|
||||
protected static final Map<Class<?>,BaseType> BASE_PROPERTY_TYPES_BY_CLASS;
|
||||
protected static final Map<Class<?>,String> REGEX_BY_CLASS_MAPPED_AS_STRING;
|
||||
|
||||
static {
|
||||
BASE_PROPERTY_TYPES_BY_CLASS = new HashMap<>();
|
||||
|
||||
// This is made by hand because not all types should be add.
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Boolean.TYPE, BaseType.BOOLEAN);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Boolean.class, BaseType.BOOLEAN);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Integer.TYPE, BaseType.INTEGER);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Integer.class, BaseType.INTEGER);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(BigInteger.class, BaseType.INTEGER);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Short.TYPE, BaseType.SHORT);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Short.class, BaseType.SHORT);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Long.TYPE, BaseType.LONG);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Long.class, BaseType.LONG);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Float.TYPE, BaseType.FLOAT);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Float.class, BaseType.FLOAT);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Double.TYPE, BaseType.DOUBLE);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Double.class, BaseType.DOUBLE);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Date.class, BaseType.DATE);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Calendar.class, BaseType.DATE);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(String.class, BaseType.STRING);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Character.TYPE, BaseType.STRING);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Character.class, BaseType.STRING);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Byte.TYPE, BaseType.BYTE);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Byte.class, BaseType.BYTE);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(byte[].class, BaseType.BINARY);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Byte[].class, BaseType.BINARY);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(PropertyElement.class, BaseType.PROPERTY);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(List.class, BaseType.LIST);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Set.class, BaseType.SET);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Map.class, BaseType.MAP);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Enum.class, BaseType.STRING);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(URI.class, BaseType.STRING);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(URL.class, BaseType.STRING);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(UUID.class, BaseType.STRING);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Version.class, BaseType.STRING);
|
||||
|
||||
|
||||
REGEX_BY_CLASS_MAPPED_AS_STRING = new HashMap<>();
|
||||
REGEX_BY_CLASS_MAPPED_AS_STRING.put(URI.class, PropertyTypeName.URI_REGEX);
|
||||
REGEX_BY_CLASS_MAPPED_AS_STRING.put(URL.class, PropertyTypeName.URL_REGEX);
|
||||
REGEX_BY_CLASS_MAPPED_AS_STRING.put(UUID.class,PropertyTypeName.UUID_REGEX);
|
||||
REGEX_BY_CLASS_MAPPED_AS_STRING.put(Version.class, Version.VERSION_REGEX);
|
||||
|
||||
}
|
||||
|
||||
public final static String URI_REGEX = null;
|
||||
public final static String URL_REGEX = null;
|
||||
public final static String UUID_REGEX = "^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$";
|
||||
|
||||
|
||||
public static String getRegexByClass(Class<?> clz) {
|
||||
if(Enum.class.isAssignableFrom(clz)){
|
||||
Object[] constants = clz.getEnumConstants();
|
||||
StringBuilder stringBuilder = new StringBuilder("^(");
|
||||
for(int i=0; i<constants.length; i++){
|
||||
stringBuilder.append(constants[i].toString());
|
||||
if(i<constants.length-1){
|
||||
stringBuilder.append("|");
|
||||
}
|
||||
}
|
||||
stringBuilder.append(")$");
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
return REGEX_BY_CLASS_MAPPED_AS_STRING.get(clz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the correspondent type by checking the "assignability" of the
|
||||
* class received as parameter.
|
||||
*
|
||||
* @param clazz Class to check
|
||||
* @return BasePropertyType instance if found, otherwise null
|
||||
*/
|
||||
public static BaseType getBaseTypeByClass(final Class<?> clazz) {
|
||||
if(clazz == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(clazz == Object.class) {
|
||||
return BaseType.ANY;
|
||||
}
|
||||
|
||||
BaseType type = BASE_PROPERTY_TYPES_BY_CLASS.get(clazz);
|
||||
if(type == null) {
|
||||
for(Class<?> c : BASE_PROPERTY_TYPES_BY_CLASS.keySet()) {
|
||||
if(c.isAssignableFrom(clazz)) {
|
||||
type = BASE_PROPERTY_TYPES_BY_CLASS.get(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
protected BaseType baseType;
|
||||
protected boolean genericType;
|
||||
protected BaseType genericBaseType;
|
||||
protected String genericClassName;
|
||||
|
||||
public PropertyTypeName(String type) {
|
||||
setType(type);
|
||||
}
|
||||
|
||||
public PropertyTypeName(Method method) {
|
||||
baseType = null;
|
||||
genericType = false;
|
||||
genericBaseType = null;
|
||||
genericClassName = null;
|
||||
|
||||
Class<?> clz = method.getReturnType();
|
||||
logger.trace("Return Type for method {} is {}", method, clz);
|
||||
|
||||
baseType = PropertyTypeName.getBaseTypeByClass(clz);
|
||||
|
||||
if(baseType == BaseType.PROPERTY){
|
||||
if(clz != PropertyElement.class){
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Element> type = (Class<? extends Element>) clz;
|
||||
genericType = true;
|
||||
genericClassName = TypeMapper.getType(type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(baseType!=null) {
|
||||
if(baseType.ordinal()>BaseType.PROPERTY.ordinal()){
|
||||
genericType = true;
|
||||
|
||||
java.lang.reflect.Type genericReturnType = method.getGenericReturnType();
|
||||
logger.trace("Generic Return Type for method {} is {}", method, genericReturnType);
|
||||
|
||||
java.lang.reflect.Type[] actualTypeArguments = ((ParameterizedType) genericReturnType).getActualTypeArguments();
|
||||
|
||||
java.lang.reflect.Type genericType = null;
|
||||
for(java.lang.reflect.Type t : actualTypeArguments){
|
||||
logger.trace("Generic Return Type {} for method {} - Actual Type Argument : {}", genericReturnType, method, t);
|
||||
genericType = t;
|
||||
}
|
||||
|
||||
genericBaseType = PropertyTypeName.getBaseTypeByClass((Class<?>) genericType);
|
||||
if(genericBaseType!= null && genericBaseType.ordinal()>BaseType.PROPERTY.ordinal()) {
|
||||
throw new IllegalArgumentException("The generic of a " + baseType.toString() + " cannot be a Set, a List or a Map.");
|
||||
}
|
||||
|
||||
if(genericBaseType == BaseType.PROPERTY){
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Element> genericElementType = (Class<? extends Element>) genericType;
|
||||
genericClassName = TypeMapper.getType(genericElementType);
|
||||
}
|
||||
|
||||
}
|
||||
}else {
|
||||
throw new IllegalArgumentException("Type " + clz.getSimpleName() + " not supported as property type");
|
||||
}
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
int indexOfMinor = type.indexOf("<");
|
||||
if(indexOfMinor == -1) {
|
||||
genericType = false;
|
||||
}else {
|
||||
genericType = true;
|
||||
}
|
||||
|
||||
if(!genericType) {
|
||||
try {
|
||||
baseType = BaseType.getBaseTypeFromString(type);
|
||||
if(baseType.ordinal()>BaseType.PROPERTY.ordinal()) {
|
||||
throw new IllegalArgumentException("Set, List and Map must specify a generic type, e.g. Set<Property>, List<Integer>.");
|
||||
}
|
||||
return;
|
||||
}catch (IllegalArgumentException e) {
|
||||
baseType = BaseType.PROPERTY;
|
||||
genericType = true;
|
||||
genericClassName = type;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String cleanTypeFromGeneric = type.substring(0,indexOfMinor);
|
||||
baseType = BaseType.getBaseTypeFromString(cleanTypeFromGeneric);
|
||||
if(genericType) {
|
||||
if(baseType.ordinal()<=BaseType.PROPERTY.ordinal()) {
|
||||
throw new IllegalArgumentException("Only Set, List and Map can be generic. Map can only have String as Key");
|
||||
}
|
||||
}
|
||||
|
||||
// Getting the pat inside <....>
|
||||
String generic = type.substring(indexOfMinor+1, type.length()-1);
|
||||
|
||||
if(baseType == BaseType.MAP) {
|
||||
int l = generic.length();
|
||||
generic = generic.replace(BaseType.STRING.toString() + ",", "");
|
||||
if(l!=(BaseType.STRING.stringValue.length() + 1 + generic.length())) {
|
||||
throw new IllegalArgumentException("A Map can only has String as key e.g. Map<String,Integer>");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
genericBaseType = BaseType.getBaseTypeFromString(generic);
|
||||
}catch (IllegalArgumentException e) {
|
||||
genericBaseType = BaseType.PROPERTY;
|
||||
genericClassName = generic;
|
||||
}
|
||||
|
||||
if(genericBaseType!= null && genericBaseType.ordinal()>BaseType.PROPERTY.ordinal()) {
|
||||
throw new IllegalArgumentException("The generic of a " + baseType.toString() + " cannot be a Set, a List or a Map.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
|
||||
switch (baseType) {
|
||||
|
||||
case PROPERTY:
|
||||
if(genericClassName != null) {
|
||||
stringBuffer.append(genericClassName);
|
||||
}else {
|
||||
stringBuffer.append(baseType.toString());
|
||||
}
|
||||
break;
|
||||
|
||||
case SET: case LIST: case MAP:
|
||||
stringBuffer.append(baseType.toString());
|
||||
stringBuffer.append("<");
|
||||
if(baseType == BaseType.MAP) {
|
||||
stringBuffer.append(BaseType.STRING.toString());
|
||||
stringBuffer.append(",");
|
||||
}
|
||||
|
||||
if(genericClassName != null) {
|
||||
stringBuffer.append(genericClassName);
|
||||
}else {
|
||||
stringBuffer.append(genericBaseType.toString());
|
||||
}
|
||||
|
||||
stringBuffer.append(">");
|
||||
break;
|
||||
|
||||
default:
|
||||
stringBuffer.append(baseType.toString());
|
||||
break;
|
||||
}
|
||||
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getType();
|
||||
}
|
||||
|
||||
|
||||
public BaseType getBaseType() {
|
||||
return baseType;
|
||||
}
|
||||
|
||||
public boolean isGenericType() {
|
||||
return genericType;
|
||||
}
|
||||
|
||||
public BaseType getGenericBaseType() {
|
||||
return genericBaseType;
|
||||
}
|
||||
|
||||
public String getGenericClassName() {
|
||||
return genericClassName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(baseType, genericBaseType, genericClassName, genericType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
PropertyTypeName other = (PropertyTypeName) obj;
|
||||
return baseType == other.baseType && genericBaseType == other.genericBaseType
|
||||
&& Objects.equals(genericClassName, other.genericClassName) && genericType == other.genericType;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,8 @@
|
|||
package org.gcube.informationsystem.types;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
|
@ -12,10 +10,7 @@ import org.gcube.com.fasterxml.jackson.databind.JavaType;
|
|||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.types.impl.TypeImpl;
|
||||
import org.gcube.informationsystem.types.reference.Change;
|
||||
import org.gcube.informationsystem.types.reference.Changelog;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.types.reference.TypeMetadata;
|
||||
import org.gcube.informationsystem.types.reference.entities.EntityType;
|
||||
import org.gcube.informationsystem.types.reference.entities.FacetType;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||
|
@ -25,19 +20,20 @@ import org.gcube.informationsystem.types.reference.properties.PropertyType;
|
|||
import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
|
||||
import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
|
||||
import org.gcube.informationsystem.types.reference.relations.RelationType;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class TypeMapper {
|
||||
|
||||
private final static String NAME = "NAME";
|
||||
|
||||
|
||||
protected static final ObjectMapper mapper;
|
||||
|
||||
static {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, false);
|
||||
|
||||
mapper.registerSubtypes(Type.class);
|
||||
|
||||
|
@ -52,6 +48,10 @@ public class TypeMapper {
|
|||
mapper.registerSubtypes(PropertyType.class);
|
||||
mapper.registerSubtypes(PropertyDefinition.class);
|
||||
mapper.registerSubtypes(LinkedEntity.class);
|
||||
|
||||
// TODO
|
||||
// mapper.registerSubtypes(LinkedResource.class);
|
||||
// mapper.registerSubtypes(LinkedFacet.class);
|
||||
}
|
||||
|
||||
public static String serializeTypeDefinition(Type type) throws Exception{
|
||||
|
@ -59,7 +59,7 @@ public class TypeMapper {
|
|||
return json;
|
||||
}
|
||||
|
||||
public static Type deserializeTypeDefinition(String json) throws Exception {
|
||||
public static Type deserializeTypeDefinition(String json) throws Exception{
|
||||
Type type = mapper.readValue(json, Type.class);
|
||||
return type;
|
||||
}
|
||||
|
@ -88,117 +88,22 @@ public class TypeMapper {
|
|||
return serializeTypeDefinition(type);
|
||||
}
|
||||
|
||||
public static <E extends Element> String getType(E e){
|
||||
return getType(e.getClass());
|
||||
}
|
||||
|
||||
public static String getType(Class<? extends Element> clz){
|
||||
String classSimpleName = clz.getSimpleName();
|
||||
String name = null;
|
||||
|
||||
if(!clz.isInterface()) {
|
||||
if(clz.isAnnotationPresent(JsonTypeName.class)) {
|
||||
JsonTypeName jsonTypeName = clz.getAnnotation(JsonTypeName.class);
|
||||
name = jsonTypeName.value();
|
||||
if(name==null || name.compareTo("")==0) {
|
||||
throw new RuntimeException("Invalid annotation @JsonTypeName for type " + classSimpleName);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
if(clz.isAnnotationPresent(JsonTypeName.class)) {
|
||||
JsonTypeName jsonTypeName = clz.getAnnotation(JsonTypeName.class);
|
||||
return jsonTypeName.value();
|
||||
}
|
||||
|
||||
if(clz.isAnnotationPresent(TypeMetadata.class)) {
|
||||
TypeMetadata typeMetadata = clz.getAnnotation(TypeMetadata.class);
|
||||
String typeMetadataName = typeMetadata.name();
|
||||
if(typeMetadataName!=null && typeMetadataName.compareTo("")!=0) {
|
||||
/*
|
||||
if(name!=null && typeMetadataName.compareTo(name)!=0) {
|
||||
throw new RuntimeException("Name in annotation @TypeMetadata differ from annotation in @JsonTypeName for type " + classSimpleName + ". Please be coerent");
|
||||
}
|
||||
*/
|
||||
return typeMetadataName;
|
||||
}else {
|
||||
throw new RuntimeException("Invalid Name in annotation @TypeMetadata for type " + classSimpleName);
|
||||
}
|
||||
}else {
|
||||
throw new RuntimeException("You must provide @TypeMetadata for " + classSimpleName);
|
||||
}
|
||||
|
||||
return getStaticStringFieldByName(clz, NAME, clz.getSimpleName());
|
||||
}
|
||||
|
||||
public static String getTypeDescription(Class<? extends Element> clz){
|
||||
String classSimpleName = clz.getSimpleName();
|
||||
if(clz.isAnnotationPresent(TypeMetadata.class)) {
|
||||
TypeMetadata typeMetadata = clz.getAnnotation(TypeMetadata.class);
|
||||
String description = typeMetadata.description();
|
||||
if(description!=null && description.compareTo("")!=0) {
|
||||
return description;
|
||||
}else {
|
||||
throw new RuntimeException("Invalid Description in annotation @TypeMetadata for type " + classSimpleName);
|
||||
}
|
||||
}else {
|
||||
throw new RuntimeException("You must provide @TypeMetadata for " + classSimpleName);
|
||||
public static String getStaticStringFieldByName(Class<? extends Element> clz, String fieldName, String defaultValue){
|
||||
Field field;
|
||||
try {
|
||||
field = clz.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return (String) field.get(null);
|
||||
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static Version getTypeVersion(Class<? extends Element> clz){
|
||||
String classSimpleName = clz.getSimpleName();
|
||||
if(clz.isAnnotationPresent(TypeMetadata.class)) {
|
||||
TypeMetadata typeMetadata = clz.getAnnotation(TypeMetadata.class);
|
||||
return new Version(typeMetadata.version());
|
||||
}else {
|
||||
throw new RuntimeException("You must provide @TypeMetadata for " + classSimpleName);
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Version, String> getTypeChangelog(Class<? extends Element> clz){
|
||||
Map<Version, String> map = new HashMap<>();
|
||||
|
||||
if(clz.isAnnotationPresent(Changelog.class)) {
|
||||
Changelog changelog = clz.getAnnotation(Changelog.class);
|
||||
Change[] changes = changelog.value();
|
||||
for(Change change : changes) {
|
||||
String version = change.version();
|
||||
Version typeVersion = new Version(version);
|
||||
if(map.containsKey(typeVersion)) {
|
||||
throw new RuntimeException("Duplicated version " + version +" in @Change annotation");
|
||||
}
|
||||
|
||||
String description = change.description();
|
||||
if(description==null || description.compareTo("")==0) {
|
||||
throw new RuntimeException("A valid description for version " + version +" must be provided in @Change annotation");
|
||||
}
|
||||
|
||||
map.put(typeVersion, description);
|
||||
}
|
||||
}
|
||||
|
||||
if(!map.containsKey(Version.MINIMAL_VERSION)) {
|
||||
map.putAll(TypeImpl.DEFAULT_CHANGELOG_MAP);
|
||||
}
|
||||
|
||||
Version typeVersion = getTypeVersion(clz);
|
||||
if (!map.containsKey(typeVersion)) {
|
||||
throw new RuntimeException("The Type " + clz.getSimpleName() + " does not provided the appropriated changelog Map");
|
||||
}
|
||||
|
||||
List<Version> versions = new ArrayList<>(map.keySet());
|
||||
versions.sort(new Comparator<Version>() {
|
||||
|
||||
@Override
|
||||
public int compare(Version o1, Version o2) {
|
||||
/* o2.compareTo(o1) and not vice-versa
|
||||
* because we want descending order
|
||||
*/
|
||||
return o2.compareTo(o1);
|
||||
}
|
||||
});
|
||||
|
||||
if(versions.get(0).compareTo(typeVersion)!=0) {
|
||||
throw new RuntimeException("The Type declared version (i.e."+ typeVersion.toString() +") does not match the highest version declared in changelog (i.e. "+ versions.get(0) + "). Please fix your type.");
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,13 +9,12 @@ import org.gcube.informationsystem.model.reference.entities.Entity;
|
|||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* It indicates that the {@link Entity} or the {@link Relation} is abstract and
|
||||
* cannot be instantiated.
|
||||
* This is needed because the type definition is made with interface so that
|
||||
* even used the java abstract keyword is useless because it cannot be retrieved
|
||||
* using reflection (interfaces are always abstract)
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
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 {
|
||||
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package org.gcube.informationsystem.types.annotations;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -11,14 +10,12 @@ import org.gcube.informationsystem.types.TypeMapper;
|
|||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* It is used by {@link TypeMapper} to identify which getter method are
|
||||
* related to and {@link Entity} {@link PropertyDefinition}.
|
||||
* The name of the property is obtained by removing "get" or "is" from method
|
||||
* name and lower casing the first letter.
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Documented
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ISProperty {
|
||||
|
@ -31,6 +28,5 @@ public @interface ISProperty {
|
|||
int min() default -1;
|
||||
int max() default -1;
|
||||
String regexpr() default "";
|
||||
String defaultValue() default "null";
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.gcube.informationsystem.types.annotations;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -9,12 +8,11 @@ import java.lang.annotation.Target;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Documented
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ResourceSchema {
|
||||
|
||||
ResourceSchemaEntry[] facets() default {};
|
||||
|
||||
RelatedResourcesEntry[] resources() default {};
|
||||
ResourceSchemaRelatedEntry[] resources() default {};
|
||||
}
|
||||
|
|
|
@ -13,12 +13,11 @@ import org.gcube.informationsystem.types.TypeMapper;
|
|||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* It is used by {@link TypeMapper} to identify which getter method are
|
||||
* related to and {@link Entity} {@link PropertyDefinition}.
|
||||
* The name of the property is obtained by removing "get" or "is" from method
|
||||
* name and lower casing the first letter.
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
@ -13,16 +13,15 @@ import org.gcube.informationsystem.types.TypeMapper;
|
|||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
* It is used by {@link TypeMapper} to identify which getter method are
|
||||
* related to and {@link Entity} {@link PropertyDefinition}.
|
||||
* The name of the property is obtained by removing "get" or "is" from method
|
||||
* name and lower casing the first letter.
|
||||
*
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface RelatedResourcesEntry {
|
||||
public @interface ResourceSchemaRelatedEntry {
|
||||
|
||||
@JsonProperty
|
||||
Class<? extends Resource> source() default Resource.class;
|
||||
|
@ -37,4 +36,10 @@ public @interface RelatedResourcesEntry {
|
|||
@JsonProperty
|
||||
String description() default "";
|
||||
|
||||
@JsonProperty
|
||||
int min() default 0;
|
||||
|
||||
@JsonProperty
|
||||
int max() default -1;
|
||||
|
||||
}
|
|
@ -3,28 +3,19 @@ package org.gcube.informationsystem.types.impl;
|
|||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
||||
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
|
||||
import org.gcube.informationsystem.base.reference.relations.RelationElement;
|
||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
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;
|
||||
|
@ -32,183 +23,135 @@ import org.gcube.informationsystem.types.impl.properties.PropertyTypeImpl;
|
|||
import org.gcube.informationsystem.types.impl.relations.RelationTypeImpl;
|
||||
import org.gcube.informationsystem.types.reference.Type;
|
||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
import org.gcube.informationsystem.utils.TypeUtility;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class TypeImpl implements Type {
|
||||
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(TypeImpl.class);
|
||||
|
||||
|
||||
/**
|
||||
* Generated Serial version UID
|
||||
*/
|
||||
private static final long serialVersionUID = -4333954207969059451L;
|
||||
|
||||
public static final Map<Version, String> DEFAULT_CHANGELOG_MAP;
|
||||
private static final Map<String, String> DEFAULT_CHANGELOG_MAP_KEY_AS_STRING;
|
||||
|
||||
static {
|
||||
DEFAULT_CHANGELOG_MAP = new HashMap<>();
|
||||
DEFAULT_CHANGELOG_MAP.put(new Version(Version.MINIMAL_VERSION_STRING), Version.MINIMAL_VERSION_DESCRIPTION);
|
||||
DEFAULT_CHANGELOG_MAP_KEY_AS_STRING = new HashMap<>();
|
||||
DEFAULT_CHANGELOG_MAP_KEY_AS_STRING.put(Version.MINIMAL_VERSION_STRING, Version.MINIMAL_VERSION_DESCRIPTION);
|
||||
}
|
||||
public final static String DESCRIPTION = "DESCRIPTION";
|
||||
|
||||
protected UUID uuid;
|
||||
protected Metadata metadata;
|
||||
protected Header header;
|
||||
|
||||
protected String name;
|
||||
protected String description;
|
||||
protected Version version;
|
||||
@JsonProperty(value = CHANGELOG_PROPERTY, required = false)
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
protected Map<Version, String> changelog;
|
||||
|
||||
@JsonProperty(value = ABSTRACT_PROPERTY)
|
||||
@JsonProperty(value="abstract")
|
||||
protected boolean abstractType;
|
||||
protected Set<String> superClasses;
|
||||
|
||||
@JsonProperty(value = FINAL_PROPERTY)
|
||||
protected boolean finalClass;
|
||||
|
||||
protected Set<String> extendedTypes;
|
||||
|
||||
protected Set<PropertyDefinition> properties;
|
||||
|
||||
protected <E extends Element> Set<String> retrieveSuperClasses(Class<? extends E> type, Class<E> baseClass,
|
||||
String topSuperClass) {
|
||||
|
||||
protected <E extends Element> Set<String> retrieveSuperClasses(Class<? extends E> type, Class<E> baseClass, String topSuperClass){
|
||||
Set<String> interfaceList = new HashSet<>();
|
||||
|
||||
if (type == baseClass) {
|
||||
if (topSuperClass != null) {
|
||||
|
||||
if(type==baseClass){
|
||||
if(topSuperClass!=null) {
|
||||
interfaceList.add(topSuperClass);
|
||||
}
|
||||
return interfaceList;
|
||||
}
|
||||
|
||||
|
||||
Class<?>[] interfaces = type.getInterfaces();
|
||||
|
||||
|
||||
for (Class<?> interfaceClass : interfaces) {
|
||||
|
||||
if (!baseClass.isAssignableFrom(interfaceClass)) {
|
||||
|
||||
if(!baseClass.isAssignableFrom(interfaceClass)){
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Element> clz = (Class<? extends Element>) interfaceClass;
|
||||
Class<? extends Element> clz = (Class<? extends Element>) interfaceClass;
|
||||
interfaceList.add(TypeMapper.getType(clz));
|
||||
}
|
||||
|
||||
return interfaceList;
|
||||
}
|
||||
|
||||
protected Set<PropertyDefinition> retrieveListOfProperties(Class<?> clz) {
|
||||
Set<PropertyDefinition> properties = new TreeSet<>();
|
||||
for (Method m : clz.getDeclaredMethods()) {
|
||||
|
||||
protected Set<PropertyDefinition> retrieveListOfProperties(Class<?> type){
|
||||
Set<PropertyDefinition> properties = new HashSet<>();
|
||||
for (Method m : type.getDeclaredMethods()){
|
||||
m.setAccessible(true);
|
||||
if (m.isAnnotationPresent(ISProperty.class)) {
|
||||
if (m.isBridge()) {
|
||||
if(m.isAnnotationPresent(ISProperty.class)){
|
||||
if(m.isBridge()) {
|
||||
continue;
|
||||
}
|
||||
ISProperty propAnnotation = m.getAnnotation(ISProperty.class);
|
||||
PropertyDefinition prop = new PropertyDefinitionImpl(propAnnotation, m);
|
||||
properties.add(prop);
|
||||
logger.trace("Property {} retrieved in type {} ", prop, clz.getSimpleName());
|
||||
}
|
||||
logger.trace("Property {} retrieved in type {} ", prop, type.getSimpleName());
|
||||
}
|
||||
|
||||
}
|
||||
if(properties.size()==0) {
|
||||
properties = null;
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
protected Class<?> getGenericClass(java.lang.reflect.Type type) {
|
||||
|
||||
protected Class<?> getGenericClass(java.lang.reflect.Type type){
|
||||
TypeVariable<?> typeVariable = (TypeVariable<?>) type;
|
||||
java.lang.reflect.Type[] bounds = typeVariable.getBounds();
|
||||
java.lang.reflect.Type t = bounds[0];
|
||||
if (t instanceof ParameterizedType) {
|
||||
if(t instanceof ParameterizedType) {
|
||||
ParameterizedType parameterizedType = (ParameterizedType) t;
|
||||
return (Class<?>) parameterizedType.getRawType();
|
||||
}
|
||||
return (Class<?>) t;
|
||||
return (Class<?>) t;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static Type getInstance(Class<? extends Element> clz) {
|
||||
Type typeDefinition = null;
|
||||
try {
|
||||
if (EntityElement.class.isAssignableFrom(clz)) {
|
||||
if(EntityElement.class.isAssignableFrom(clz)) {
|
||||
typeDefinition = EntityTypeImpl.getEntityTypeDefinitionInstance((Class<? extends EntityElement>) clz);
|
||||
return typeDefinition;
|
||||
} else if (RelationElement.class.isAssignableFrom(clz)) {
|
||||
typeDefinition = RelationTypeImpl
|
||||
.getRelationTypeDefinitionInstance((Class<? extends RelationElement<?, ?>>) clz);
|
||||
} else if(RelationElement.class.isAssignableFrom(clz)){
|
||||
typeDefinition = RelationTypeImpl.getRelationTypeDefinitionInstance((Class<? extends RelationElement<?,?>>) clz);
|
||||
return typeDefinition;
|
||||
} else if (PropertyElement.class.isAssignableFrom(clz)) {
|
||||
} else if(PropertyElement.class.isAssignableFrom(clz)){
|
||||
typeDefinition = new PropertyTypeImpl(clz);
|
||||
return typeDefinition;
|
||||
} else if (Type.class.isAssignableFrom(clz)) {
|
||||
} else if(Type.class.isAssignableFrom(clz)) {
|
||||
typeDefinition = new TypeImpl(clz);
|
||||
return typeDefinition;
|
||||
} else {
|
||||
throw new RuntimeException("Serialization required");
|
||||
}
|
||||
} finally {
|
||||
if (typeDefinition != null) {
|
||||
if(typeDefinition!=null) {
|
||||
logger.debug("{} : {} ", clz, typeDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected TypeImpl() {
|
||||
}
|
||||
|
||||
|
||||
protected TypeImpl() {}
|
||||
|
||||
protected TypeImpl(Class<? extends Element> clz) {
|
||||
this.name = TypeMapper.getType(clz);
|
||||
this.description = TypeMapper.getTypeDescription(clz);
|
||||
this.version = TypeMapper.getTypeVersion(clz);
|
||||
|
||||
this.changelog = TypeMapper.getTypeChangelog(clz);
|
||||
|
||||
this.description = TypeMapper.getStaticStringFieldByName(clz, DESCRIPTION, "");
|
||||
this.abstractType = false;
|
||||
|
||||
if (clz.isAnnotationPresent(Abstract.class)) {
|
||||
|
||||
if(clz.isAnnotationPresent(Abstract.class)){
|
||||
this.abstractType = true;
|
||||
}
|
||||
|
||||
if(clz.isAnnotationPresent(Final.class)) {
|
||||
this.finalClass = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setID(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
public Header getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metadata getMetadata() {
|
||||
return metadata;
|
||||
public void setHeader(Header header){
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadata(Metadata metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -219,80 +162,18 @@ public class TypeImpl implements Type {
|
|||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@JsonGetter(value = VERSION_PROPERTY)
|
||||
public String getVersionAsString() {
|
||||
return version.toString();
|
||||
}
|
||||
|
||||
@JsonSetter(value = VERSION_PROPERTY)
|
||||
public void setVersion(String version) {
|
||||
this.version = new Version(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Version, String> getChangelog() {
|
||||
return changelog;
|
||||
}
|
||||
|
||||
@JsonGetter(value = CHANGELOG_PROPERTY)
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public Map<String, String> getChangelogWithVersionAsString() {
|
||||
if(this.changelog==null) {
|
||||
return DEFAULT_CHANGELOG_MAP_KEY_AS_STRING;
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (Version typeVersion : changelog.keySet()) {
|
||||
map.put(typeVersion.toString(), changelog.get(typeVersion));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@JsonSetter(value=CHANGELOG_PROPERTY)
|
||||
public void setChangelog(Map<String, String> changelog) {
|
||||
if(changelog==null) {
|
||||
this.changelog = DEFAULT_CHANGELOG_MAP;
|
||||
return;
|
||||
}
|
||||
this.changelog = new HashMap<>();
|
||||
for (String version : changelog.keySet()) {
|
||||
this.changelog.put(new Version(version), changelog.get(version));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstract() {
|
||||
return abstractType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSuperClasses() {
|
||||
return superClasses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinal() {
|
||||
return finalClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getExtendedTypes() {
|
||||
return extendedTypes;
|
||||
}
|
||||
|
||||
@JsonInclude(Include.NON_EMPTY)
|
||||
public Set<PropertyDefinition> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public AccessType getAccessType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return TypeUtility.getTypeName(this.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,23 +1,16 @@
|
|||
package org.gcube.informationsystem.types.impl.entities;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||
import org.gcube.informationsystem.context.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.Metadata;
|
||||
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
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)
|
||||
|
@ -30,16 +23,6 @@ public class EntityTypeImpl extends TypeImpl implements EntityType {
|
|||
*/
|
||||
private static final long serialVersionUID = 2614315845213942880L;
|
||||
|
||||
private static Set<String> entityTypeAccesTypes;
|
||||
|
||||
static {
|
||||
entityTypeAccesTypes = new HashSet<>();
|
||||
entityTypeAccesTypes.add(EntityType.NAME);
|
||||
entityTypeAccesTypes.add(ResourceType.NAME);
|
||||
entityTypeAccesTypes.add(FacetType.NAME);
|
||||
}
|
||||
|
||||
|
||||
// private static final String VERTEX_CLASS_NAME = "V";
|
||||
|
||||
public static EntityType getEntityTypeDefinitionInstance(Class<? extends EntityElement> clz) {
|
||||
|
@ -66,17 +49,13 @@ public class EntityTypeImpl extends TypeImpl implements EntityType {
|
|||
if(EntityType.class.isAssignableFrom(clz)){
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends EntityType> c = (Class<? extends EntityType>) clz;
|
||||
this.extendedTypes = retrieveSuperClasses(c, EntityType.class, EntityElement.NAME);
|
||||
this.superClasses = retrieveSuperClasses(c, EntityType.class, EntityElement.NAME);
|
||||
} else if(Context.class.isAssignableFrom(clz)){
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Context> c = (Class<? extends Context>) clz;
|
||||
this.extendedTypes = retrieveSuperClasses(c, Context.class, EntityElement.NAME);
|
||||
} else if(QueryTemplate.class.isAssignableFrom(clz)){
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends QueryTemplate> c = (Class<? extends QueryTemplate>) clz;
|
||||
this.extendedTypes = retrieveSuperClasses(c, QueryTemplate.class, EntityElement.NAME);
|
||||
this.superClasses = retrieveSuperClasses(c, Context.class, EntityElement.NAME);
|
||||
} else if(EntityElement.class.isAssignableFrom(clz)){
|
||||
this.extendedTypes = retrieveSuperClasses(clz, EntityElement.class, null);
|
||||
this.superClasses = retrieveSuperClasses(clz, EntityElement.class, null);
|
||||
} else {
|
||||
throw new RuntimeException("Type Hierachy Error for class " + clz.getSimpleName());
|
||||
}
|
||||
|
@ -91,16 +70,16 @@ public class EntityTypeImpl extends TypeImpl implements EntityType {
|
|||
* We need to copy them.
|
||||
*/
|
||||
|
||||
protected Metadata metadata;
|
||||
protected Header header;
|
||||
|
||||
@Override
|
||||
public Metadata getMetadata() {
|
||||
return metadata;
|
||||
public Header getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadata(Metadata metadata){
|
||||
this.metadata = metadata;
|
||||
public void setHeader(Header header){
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,35 +90,12 @@ public class EntityTypeImpl extends TypeImpl implements EntityType {
|
|||
return stringWriter.toString();
|
||||
}catch(Exception e){
|
||||
try {
|
||||
ElementMapper.marshal(this.metadata, stringWriter);
|
||||
ElementMapper.marshal(this.header, stringWriter);
|
||||
return stringWriter.toString();
|
||||
} catch(Exception e1){
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public AccessType getAccessType() {
|
||||
|
||||
if(name.compareTo(Context.NAME)==0) {
|
||||
return AccessType.CONTEXT;
|
||||
}
|
||||
|
||||
if(name.compareTo(EntityElement.NAME)==0) {
|
||||
return AccessType.ENTITY_ELEMENT;
|
||||
}
|
||||
|
||||
if(name.compareTo(QueryTemplate.NAME)==0) {
|
||||
return AccessType.QUERY_TEMPLATE;
|
||||
}
|
||||
|
||||
if(entityTypeAccesTypes.contains(name)) {
|
||||
return AccessType.ENTITY_TYPE;
|
||||
}
|
||||
|
||||
return AccessType.ENTITY;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,7 @@ package org.gcube.informationsystem.types.impl.entities;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.types.reference.entities.FacetType;
|
||||
|
@ -14,7 +12,7 @@ import org.gcube.informationsystem.types.reference.properties.PropertyDefinition
|
|||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value=FacetType.NAME)
|
||||
public final class FacetTypeImpl extends EntityTypeImpl implements FacetType {
|
||||
public class FacetTypeImpl extends EntityTypeImpl implements FacetType {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
|
@ -29,7 +27,7 @@ public final class FacetTypeImpl extends EntityTypeImpl implements FacetType {
|
|||
|
||||
public FacetTypeImpl(Class<? extends Facet> clz) {
|
||||
super(clz);
|
||||
this.extendedTypes = retrieveSuperClasses(clz, Facet.class, Entity.NAME);
|
||||
this.superClasses = retrieveSuperClasses(clz, Facet.class, Entity.NAME);
|
||||
this.properties = retrieveListOfProperties(clz);
|
||||
}
|
||||
|
||||
|
@ -38,10 +36,4 @@ public final class FacetTypeImpl extends EntityTypeImpl implements FacetType {
|
|||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public AccessType getAccessType() {
|
||||
return AccessType.FACET;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,15 +3,13 @@ package org.gcube.informationsystem.types.impl.entities;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
import org.gcube.informationsystem.types.annotations.ResourceSchema;
|
||||
import org.gcube.informationsystem.types.annotations.ResourceSchemaEntry;
|
||||
import org.gcube.informationsystem.types.annotations.RelatedResourcesEntry;
|
||||
import org.gcube.informationsystem.types.annotations.ResourceSchemaRelatedEntry;
|
||||
import org.gcube.informationsystem.types.impl.properties.LinkedEntityImpl;
|
||||
import org.gcube.informationsystem.types.reference.entities.ResourceType;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
|
@ -20,7 +18,7 @@ import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
|||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value=ResourceType.NAME)
|
||||
public final class ResourceTypeImpl extends EntityTypeImpl implements ResourceType {
|
||||
public class ResourceTypeImpl extends EntityTypeImpl implements ResourceType {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
|
@ -37,7 +35,7 @@ public final class ResourceTypeImpl extends EntityTypeImpl implements ResourceTy
|
|||
public ResourceTypeImpl(Class<? extends Resource> clz) {
|
||||
super(clz);
|
||||
|
||||
this.extendedTypes = retrieveSuperClasses(clz, Resource.class, Entity.NAME);
|
||||
this.superClasses = retrieveSuperClasses(clz, Resource.class, Entity.NAME);
|
||||
|
||||
setResourceSchemaEntries(clz);
|
||||
}
|
||||
|
@ -48,28 +46,24 @@ public final class ResourceTypeImpl extends EntityTypeImpl implements ResourceTy
|
|||
this.resources = new ArrayList<>();
|
||||
ResourceSchema[] resourceSchemaArray = clz.getAnnotationsByType(ResourceSchema.class);
|
||||
for(ResourceSchemaEntry resourceSchemaEntry : resourceSchemaArray[0].facets()) {
|
||||
LinkedEntity linkedEntity = new LinkedEntityImpl();
|
||||
linkedEntity.setSource(TypeMapper.getType(clz));
|
||||
linkedEntity.setRelation(TypeMapper.getType(resourceSchemaEntry.relation()));
|
||||
linkedEntity.setTarget(TypeMapper.getType(resourceSchemaEntry.facet()));
|
||||
linkedEntity.setDescription(resourceSchemaEntry.description());
|
||||
linkedEntity.setMin(resourceSchemaEntry.min());
|
||||
linkedEntity.setMax(resourceSchemaEntry.max());
|
||||
this.facets.add(linkedEntity);
|
||||
LinkedEntityImpl resourceSchemaEntryDefinition = new LinkedEntityImpl();
|
||||
resourceSchemaEntryDefinition.setSource(TypeMapper.getType(clz));
|
||||
resourceSchemaEntryDefinition.setRelation(TypeMapper.getType(resourceSchemaEntry.relation()));
|
||||
resourceSchemaEntryDefinition.setTarget(TypeMapper.getType(resourceSchemaEntry.facet()));
|
||||
resourceSchemaEntryDefinition.setDescription(resourceSchemaEntry.description());
|
||||
resourceSchemaEntryDefinition.setMin(resourceSchemaEntry.min());
|
||||
resourceSchemaEntryDefinition.setMax(resourceSchemaEntry.max());
|
||||
this.facets.add(resourceSchemaEntryDefinition);
|
||||
}
|
||||
for(RelatedResourcesEntry resourceSchemaRelatedEntry : resourceSchemaArray[0].resources()) {
|
||||
LinkedEntity linkedEntity = new LinkedEntityImpl();
|
||||
linkedEntity.setSource(TypeMapper.getType(resourceSchemaRelatedEntry.source()));
|
||||
linkedEntity.setRelation(TypeMapper.getType(resourceSchemaRelatedEntry.relation()));
|
||||
linkedEntity.setTarget(TypeMapper.getType(resourceSchemaRelatedEntry.target()));
|
||||
linkedEntity.setDescription(resourceSchemaRelatedEntry.description());
|
||||
/*
|
||||
* We cannot impose any constraint on related resources.
|
||||
* The annotation are only for documentation purpose.
|
||||
*/
|
||||
linkedEntity.setMin(0);
|
||||
linkedEntity.setMax(-1);
|
||||
this.resources.add(linkedEntity);
|
||||
for(ResourceSchemaRelatedEntry resourceSchemaRelatedEntry : resourceSchemaArray[0].resources()) {
|
||||
LinkedEntity resourceSchemaEntryDefinition = new LinkedEntityImpl();
|
||||
resourceSchemaEntryDefinition.setSource(TypeMapper.getType(resourceSchemaRelatedEntry.source()));
|
||||
resourceSchemaEntryDefinition.setRelation(TypeMapper.getType(resourceSchemaRelatedEntry.relation()));
|
||||
resourceSchemaEntryDefinition.setTarget(TypeMapper.getType(resourceSchemaRelatedEntry.target()));
|
||||
resourceSchemaEntryDefinition.setDescription(resourceSchemaRelatedEntry.description());
|
||||
resourceSchemaEntryDefinition.setMin(resourceSchemaRelatedEntry.min());
|
||||
resourceSchemaEntryDefinition.setMax(resourceSchemaRelatedEntry.max());
|
||||
this.resources.add(resourceSchemaEntryDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,10 +78,4 @@ public final class ResourceTypeImpl extends EntityTypeImpl implements ResourceTy
|
|||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public AccessType getAccessType() {
|
||||
return AccessType.RESOURCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
*/
|
||||
package org.gcube.informationsystem.types.impl.properties;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.base.impl.properties.PropertyElementImpl;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
|
@ -95,75 +93,4 @@ public final class LinkedEntityImpl extends PropertyElementImpl implements Linke
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(source, relation, target, min, max, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
LinkedEntityImpl other = (LinkedEntityImpl) obj;
|
||||
return Objects.equals(source, other.source) &&
|
||||
Objects.equals(relation, other.relation) &&
|
||||
Objects.equals(target, other.target) &&
|
||||
Objects.equals(min, other.min) &&
|
||||
Objects.equals(max, other.max) &&
|
||||
Objects.equals(description, other.description);
|
||||
}
|
||||
|
||||
protected int compareIntegers(Integer thisInt, Integer otherInt) {
|
||||
Integer thisInteger = thisInt == null ? Integer.MAX_VALUE : thisInt;
|
||||
Integer otherInteger = otherInt == null ? Integer.MAX_VALUE : otherInt;
|
||||
return thisInteger.compareTo(otherInteger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LinkedEntity other) {
|
||||
if (this == other) {
|
||||
return 0;
|
||||
}
|
||||
if (other == null) {
|
||||
return -1;
|
||||
}
|
||||
if (getClass() != other.getClass()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
LinkedEntityImpl o = (LinkedEntityImpl) other;
|
||||
|
||||
int ret = 0;
|
||||
ret = source.compareTo(o.source);
|
||||
if(ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = relation.compareTo(o.relation);
|
||||
if(ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = target.compareTo(o.target);
|
||||
if(ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = compareIntegers(max, o.max);
|
||||
if(ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = compareIntegers(min, o.min);
|
||||
if(ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return description.compareTo(o.description);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,24 @@
|
|||
package org.gcube.informationsystem.types.impl.properties;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.model.impl.properties.AttributeUtility;
|
||||
import org.gcube.informationsystem.types.PropertyTypeName;
|
||||
import org.gcube.informationsystem.base.reference.Element;
|
||||
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
|
||||
import org.gcube.informationsystem.types.OrientDBType;
|
||||
import org.gcube.informationsystem.types.OrientDBType.OType;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
import org.gcube.informationsystem.types.annotations.ISProperty;
|
||||
import org.gcube.informationsystem.types.impl.TypeImpl;
|
||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
import org.gcube.informationsystem.utils.TypeUtility;
|
||||
import org.gcube.informationsystem.utils.Version;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
// @JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
|
||||
@JsonTypeName(value=PropertyDefinition.NAME)
|
||||
public final class PropertyDefinitionImpl implements PropertyDefinition {
|
||||
|
@ -30,11 +28,11 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
|
|||
*/
|
||||
private static final long serialVersionUID = -5925314595659292025L;
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(PropertyDefinitionImpl.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(TypeImpl.class);
|
||||
|
||||
public final static String UUID_REGEX = "^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$";
|
||||
public final static String URI_REGEX = null;
|
||||
public final static String URL_REGEX = null;
|
||||
public final static String UUID_PATTERN = "^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$";
|
||||
public final static String URI_PATTERN = null;
|
||||
public final static String URL_PATTERN = null;
|
||||
|
||||
private String name= "";
|
||||
private String description= "";
|
||||
|
@ -44,8 +42,9 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
|
|||
private Integer max= null;
|
||||
private Integer min= null;
|
||||
private String regexp= null;
|
||||
private PropertyTypeName propertyTypeName = null;
|
||||
private Object defaultValue = null;
|
||||
private Integer linkedType = null;
|
||||
private String linkedClass = null;
|
||||
private Integer type=null;
|
||||
|
||||
private static String getPropertyNameFromMethodName(Method method){
|
||||
String name = method.getName();
|
||||
|
@ -75,53 +74,75 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
|
|||
this.mandatory= propertyAnnotation.mandatory();
|
||||
this.notnull = !propertyAnnotation.nullable();
|
||||
this.readonly = propertyAnnotation.readonly();
|
||||
if(propertyAnnotation.max()>0) {
|
||||
this.max = propertyAnnotation.max();
|
||||
}
|
||||
if(propertyAnnotation.max()>=propertyAnnotation.min() && propertyAnnotation.min()>0) {
|
||||
this.min = propertyAnnotation.min();
|
||||
}
|
||||
|
||||
this.propertyTypeName = new PropertyTypeName(method);
|
||||
this.propertyTypeName = new PropertyTypeName(method);
|
||||
String defaultValueAsString = propertyAnnotation.defaultValue();
|
||||
defaultValueAsString = AttributeUtility.evaluateNullForDefaultValue(defaultValueAsString);
|
||||
|
||||
// The default value is evaluated to test if compliant with the declared type
|
||||
this.defaultValue = AttributeUtility.evaluateDefaultValueStringAccordingBaseType(propertyTypeName.getBaseType(), defaultValueAsString);
|
||||
|
||||
Class<?> clz = method.getReturnType();
|
||||
logger.trace("Return Type for method {} is {}", method, clz);
|
||||
|
||||
if(propertyAnnotation.max()>0) this.max = propertyAnnotation.max();
|
||||
if(propertyAnnotation.max()>=propertyAnnotation.min() && propertyAnnotation.min()>0) this.min = propertyAnnotation.min();
|
||||
if(!propertyAnnotation.regexpr().isEmpty()) this.regexp = propertyAnnotation.regexpr();
|
||||
if(this.regexp==null || this.regexp.compareTo("")==0 ){
|
||||
if(Enum.class.isAssignableFrom(clz)){
|
||||
Object[] constants = clz.getEnumConstants();
|
||||
StringBuilder stringBuilder = new StringBuilder("^(");
|
||||
for(int i=0; i<constants.length; i++){
|
||||
stringBuilder.append(constants[i].toString());
|
||||
if(i<constants.length-1){
|
||||
stringBuilder.append("|");
|
||||
}
|
||||
|
||||
logger.trace("Looking for property type {}", method.getReturnType());
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Element> type = (Class<? extends Element>) method.getReturnType();
|
||||
this.type = OType.PROPERTY.getIntValue();
|
||||
|
||||
if(PropertyElement.class.isAssignableFrom(type)){
|
||||
if(type != PropertyElement.class){
|
||||
this.linkedClass = TypeMapper.getType(type);
|
||||
}
|
||||
}else if (OrientDBType.getTypeByClass(type)!=null) {
|
||||
this.type = OrientDBType.getTypeByClass(type).getIntValue();
|
||||
if(this.type > 9 && this.type <= 12){
|
||||
java.lang.reflect.Type genericReturnType = method.getGenericReturnType();
|
||||
logger.trace("Generic Return Type {} for method {}", genericReturnType, method);
|
||||
|
||||
java.lang.reflect.Type[] actualTypeArguments = ((ParameterizedType) genericReturnType).getActualTypeArguments();
|
||||
|
||||
java.lang.reflect.Type genericType = null;
|
||||
for(java.lang.reflect.Type t : actualTypeArguments){
|
||||
logger.trace("Generic Return Type {} for method {} - Actual Type Argument : {}", genericReturnType, method, t);
|
||||
genericType = t;
|
||||
}
|
||||
stringBuilder.append(")$");
|
||||
this.regexp = stringBuilder.toString();
|
||||
}
|
||||
if(UUID.class.isAssignableFrom(clz)){
|
||||
this.regexp = UUID_REGEX;
|
||||
}
|
||||
if(URI.class.isAssignableFrom(clz)){
|
||||
this.regexp = URI_REGEX;
|
||||
}
|
||||
if(URL.class.isAssignableFrom(clz)){
|
||||
this.regexp = URL_REGEX;
|
||||
}
|
||||
if(Version.class.isAssignableFrom(clz)){
|
||||
this.regexp = Version.VERSION_REGEX;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Element> genericClass = (Class<? extends Element>) genericType;
|
||||
OType linkedOType = OrientDBType.getTypeByClass(genericClass);
|
||||
if(linkedOType!=null){
|
||||
this.linkedType = linkedOType.getIntValue();
|
||||
}else{
|
||||
this.linkedClass = TypeMapper.getType(genericClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if((this.regexp==null || this.regexp.compareTo("")==0 )&& this.type==OType.STRING.getIntValue()){
|
||||
if(Enum.class.isAssignableFrom(type)){
|
||||
Object[] constants = type.getEnumConstants();
|
||||
StringBuilder stringBuilder = new StringBuilder("^(");
|
||||
for(int i=0; i<constants.length; i++){
|
||||
stringBuilder.append(constants[i].toString());
|
||||
if(i<constants.length-1){
|
||||
stringBuilder.append("|");
|
||||
}
|
||||
}
|
||||
stringBuilder.append(")$");
|
||||
this.regexp = stringBuilder.toString();
|
||||
}
|
||||
if(UUID.class.isAssignableFrom(type)){
|
||||
this.regexp = UUID_PATTERN;
|
||||
}
|
||||
if(URI.class.isAssignableFrom(type)){
|
||||
this.regexp = URI_PATTERN;
|
||||
}
|
||||
if(URL.class.isAssignableFrom(type)){
|
||||
this.regexp = URL_PATTERN;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.regexp!=null && this.regexp.compareTo("")==0){
|
||||
this.regexp = null;
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new RuntimeException("Type " + type.getSimpleName() + " not reconized");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -129,251 +150,73 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
|
|||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMandatory() {
|
||||
return mandatory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMandatory(boolean mandatory) {
|
||||
this.mandatory = mandatory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadonly() {
|
||||
return readonly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadonly(boolean readonly) {
|
||||
this.readonly = readonly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNotnull() {
|
||||
return notnull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNotnull(boolean notnull) {
|
||||
this.notnull = notnull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMax(Integer max) {
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMin(Integer min) {
|
||||
this.min = min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegexp() {
|
||||
return regexp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRegexp(String regexp) {
|
||||
AttributeUtility.checkRegex(regexp, null);
|
||||
this.regexp = regexp;
|
||||
public Integer getLinkedType() {
|
||||
return linkedType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPropertyType() {
|
||||
return propertyTypeName.toString();
|
||||
public String getLinkedClass() {
|
||||
return linkedClass;
|
||||
}
|
||||
|
||||
@JsonSetter(value = PropertyDefinition.PROPERTY_TYPE_PROPERTY)
|
||||
public void setPropertyType(String type) {
|
||||
this.propertyTypeName = new PropertyTypeName(type);
|
||||
|
||||
@Override
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public PropertyTypeName getPropertyTypeName() {
|
||||
return propertyTypeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultValue(Object defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
public String getTypeStringValue() {
|
||||
if(type==null){
|
||||
return null;
|
||||
}
|
||||
return OType.values()[type].getStringValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PropertyDefinition ["
|
||||
+ "name=" + name
|
||||
+ ", description=" + description
|
||||
+ ", mandatory=" + mandatory
|
||||
+ ", readonly=" + readonly
|
||||
+ ", notnull=" + notnull
|
||||
+ ", max=" + max
|
||||
+ ", min=" + min
|
||||
+ ", regexpr=" + regexp
|
||||
+ ", type=" + propertyTypeName.toString()
|
||||
+ ", defaultValue=" + (defaultValue == null ? "null" : defaultValue.toString())
|
||||
+ "]";
|
||||
return "Property [name=" + name + ", description=" + description
|
||||
+ ", mandatory=" + mandatory + ", readonly=" + readonly
|
||||
+ ", notnull=" + notnull + ", max=" + max + ", min="
|
||||
+ min + ", regexpr=" + regexp + ", type = " + type
|
||||
+ " (" + getTypeStringValue() + "), linkedType = " + linkedType + ", linkedClass = "
|
||||
+ linkedClass + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, description, mandatory, readonly, notnull, max, min, regexp, propertyTypeName.toString(), defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
PropertyDefinitionImpl other = (PropertyDefinitionImpl) obj;
|
||||
return Objects.equals(name, other.name) &&
|
||||
Objects.equals(description, other.description) &&
|
||||
mandatory == other.mandatory &&
|
||||
readonly == other.readonly &&
|
||||
notnull == other.notnull &&
|
||||
Objects.equals(max, other.max) &&
|
||||
Objects.equals(min, other.min) &&
|
||||
Objects.equals(regexp, other.regexp) &&
|
||||
Objects.equals(propertyTypeName.toString(), other.propertyTypeName.toString()) &&
|
||||
Objects.equals(defaultValue, other.defaultValue);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
ret = propertyTypeName.toString().compareTo(o.propertyTypeName.toString());
|
||||
if(ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
if(defaultValue==null && o.defaultValue!=null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(o.defaultValue==null && defaultValue!=null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(defaultValue!=null && o.defaultValue!=null) {
|
||||
if(defaultValue.getClass()!=o.defaultValue.getClass()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return TypeUtility.getTypeName(this.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,23 +1,13 @@
|
|||
package org.gcube.informationsystem.types.impl.properties;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
|
||||
import org.gcube.informationsystem.queries.templates.reference.properties.TemplateVariable;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
import org.gcube.informationsystem.types.impl.TypeImpl;
|
||||
import org.gcube.informationsystem.types.reference.properties.LinkedEntity;
|
||||
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
|
||||
import org.gcube.informationsystem.types.reference.properties.PropertyType;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value = PropertyType.NAME)
|
||||
public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
|
||||
implements PropertyType<P> {
|
||||
|
@ -29,26 +19,14 @@ public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
|
|||
|
||||
protected Set<PropertyDefinition> properties;
|
||||
|
||||
private static Set<String> propertyElementAccesTypes;
|
||||
|
||||
static {
|
||||
propertyElementAccesTypes = new HashSet<>();
|
||||
propertyElementAccesTypes.add(PropertyElement.NAME);
|
||||
propertyElementAccesTypes.add(LinkedEntity.NAME);
|
||||
propertyElementAccesTypes.add(TemplateVariable.NAME);
|
||||
}
|
||||
|
||||
|
||||
protected PropertyTypeImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PropertyTypeImpl(Class<P> clz) {
|
||||
super(clz);
|
||||
this.extendedTypes = retrieveSuperClasses(clz, PropertyElement.class,
|
||||
this.superClasses = retrieveSuperClasses(clz, PropertyElement.class,
|
||||
clz == PropertyElement.class ? null : PropertyElement.NAME);
|
||||
|
||||
this.properties = retrieveListOfProperties(clz);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,39 +34,4 @@ public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
|
|||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public AccessType getAccessType() {
|
||||
|
||||
if(name.compareTo(PropertyType.NAME)==0) {
|
||||
return AccessType.PROPERTY_TYPE;
|
||||
}
|
||||
|
||||
if(name.compareTo(PropertyDefinition.NAME)==0) {
|
||||
return AccessType.PROPERTY_DEFINITION;
|
||||
}
|
||||
|
||||
if(propertyElementAccesTypes.contains(name)) {
|
||||
return AccessType.PROPERTY_ELEMENT;
|
||||
}
|
||||
|
||||
return AccessType.PROPERTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
try {
|
||||
ElementMapper.marshal(this, stringWriter);
|
||||
return stringWriter.toString();
|
||||
}catch(Exception e){
|
||||
try {
|
||||
ElementMapper.marshal(this.metadata, stringWriter);
|
||||
return stringWriter.toString();
|
||||
} catch(Exception e1){
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -2,9 +2,7 @@ package org.gcube.informationsystem.types.impl.relations;
|
|||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
|
@ -19,7 +17,7 @@ import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
|
|||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@JsonTypeName(value=ConsistsOfType.NAME)
|
||||
public final class ConsistsOfTypeImpl extends RelationTypeImpl<ResourceType, FacetType> implements ConsistsOfType {
|
||||
public class ConsistsOfTypeImpl extends RelationTypeImpl<ResourceType, FacetType> implements ConsistsOfType {
|
||||
|
||||
/**
|
||||
* Generated Serial Version UID
|
||||
|
@ -33,7 +31,7 @@ public final class ConsistsOfTypeImpl extends RelationTypeImpl<ResourceType, Fac
|
|||
public ConsistsOfTypeImpl(Class<? extends ConsistsOf<? extends Resource, ? extends Facet>> clz) {
|
||||
super(clz);
|
||||
|
||||
this.extendedTypes = retrieveSuperClasses(clz, ConsistsOf.class, Relation.NAME);
|
||||
this.superClasses = retrieveSuperClasses(clz, ConsistsOf.class, Relation.NAME);
|
||||
|
||||
this.properties = retrieveListOfProperties(clz);
|
||||
|
||||
|
@ -58,11 +56,4 @@ public final class ConsistsOfTypeImpl extends RelationTypeImpl<ResourceType, Fac
|
|||
this.source = new ResourceTypeImpl((Class<? extends Resource>) sourceClass);
|
||||
this.target = new FacetTypeImpl((Class<? extends Facet>) targetClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public AccessType getAccessType() {
|
||||
return AccessType.CONSISTS_OF;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue