Compare commits

..

No commits in common. "master" and "r5.14.0" have entirely different histories.

140 changed files with 1333 additions and 5687 deletions

1
.gitignore vendored
View File

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

View File

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

View File

@ -2,34 +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]
- Generalise 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]

View File

@ -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)

View File

@ -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']

View File

@ -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

View File

@ -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

View File

@ -1,964 +0,0 @@
.. _update_type_definition:
How to update a type definition
================================
This guide provides a concrete example of how to update a type definition while respecting backwards compatibility.
Imagine you have defined the following facet:
.. code:: java
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.reference.entities.Facet;
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.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
/**
* EventFacet captures information on a certain event/happening characterising the life cycle of the resource.
*
* Examples of an event are the start time of a virtual machine or the activation time of an electronic service.
*
* https://wiki.gcube-system.org/gcube/GCube_Model#Event_Facet
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=EventFacetImpl.class)
@TypeMetadata(
name = EventFacet.NAME,
description = "EventFacet captures information on a certain event/happening characterising the life cycle of the resource. "
+ "Examples of an event are the start time of a virtual machine or the activation time of an electronic service.",
version = Version.MINIMAL_VERSION_STRING
)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface EventFacet extends Facet {
public static final String NAME = "EventFacet"; // EventFacet.class.getSimpleName();
@JsonFormat(shape= JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
@ISProperty(description = "The time the event took place/occurred", mandatory=true, nullable=false)
public Date getDate();
public void setDate(Date date);
@ISProperty(description = "The typology of event", mandatory=true, nullable=false)
public String getEvent();
public void setEvent(String event);
}
which produces the following type definition:
.. code:: javascript
{
"type": "FacetType",
"id": "b76de0ac-048a-43a0-ae4f-e3fdb1a7d27c",
"name": "EventFacet",
"description": "EventFacet captures information on a certain event/happening characterising the life cycle of the resource. Examples of an event are the start time of a virtual machine or the activation time of an electronic service.",
"properties":
[
{
"type": "PropertyDefinition",
"name": "date",
"description": "The time the event took place/occurred",
"mandatory": true,
"readonly": false,
"notnull": true,
"max": null,
"min": null,
"regexp": null,
"defaultValue": null,
"propertyType": "Date"
},
{
"type": "PropertyDefinition",
"name": "event",
"description": "The typology of event",
"mandatory": true,
"readonly": false,
"notnull": true,
"max": null,
"min": null,
"regexp": null,
"defaultValue": null,
"propertyType": "String"
}
],
"version": "1.0.0",
"changelog": { "1.0.0": "First Version" },
"abstract": false,
"final": false,
"extendedTypes": [ "Facet" ]
}
At a certain point, the ``information-system-model`` introduces the following ``Property`` type, which models an event.
.. code:: java
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.EventImpl;
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=EventImpl.class)
@TypeMetadata(name = Event.NAME, description = "This type provides information regarding an event using the Five Ws (checklist) https://en.wikipedia.org/wiki/Five_Ws", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@Final
public interface Event extends Property {
public static final String NAME = "Event"; // Event.class.getSimpleName();
public static final String WHAT_PROPERTY = "what";
public static final String WHEN_PROPERTY = "when";
public static final String WHO_PROPERTY = "who";
public static final String WHERE_PROPERTY = "where";
public static final String WHY_PROPERTY = "why";
public static final String HOW_PROPERTY = "how";
@ISProperty(name = WHAT_PROPERTY, description = "WHAT happened.", readonly = true, mandatory = true, nullable = false)
public String getWhat();
public void setWhat(String what);
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
@ISProperty(name = WHEN_PROPERTY, description = "WHEN the event occured. It is represented in the format " + Element.DATETIME_PATTERN + ".", readonly = true, mandatory = true, nullable = false)
public Date getWhen();
public void setWhen(Date when);
@ISProperty(name = WHO_PROPERTY, description = "WHO triggered the event.", readonly = true, mandatory = false, nullable = false)
public String getWho();
public void setWho(String who);
@ISProperty(name = WHERE_PROPERTY, description = "The location (can be virtual) WHERE the event occurred.", readonly = true, mandatory = false, nullable = false)
public String getWhere();
public void setWhere(String where);
@ISProperty(name = WHY_PROPERTY, description = "The reason WHY the event occurred.", readonly = true, mandatory = false, nullable = false)
public String getWhy();
public void setWhy(String why);
@ISProperty(name = HOW_PROPERTY, description = "How the event occurred.", readonly = true, mandatory = false, nullable = false)
public String getHow();
public void setHow(String how);
}
which produces the following type definition:
.. code:: javascript
{
"type": "PropertyType",
"id" : "",
"name": "Event",
"description": "This type provides information regarding an event using the Five Ws (checklist) https://en.wikipedia.org/wiki/Five_Ws",
"properties":
[
{
"type": "PropertyDefinition",
"name": "how",
"description": "How the event occurred.",
"mandatory": false,
"readonly": true,
"notnull": true,
"max": null,
"min": null,
"regexp": null,
"defaultValue": null,
"propertyType": "String"
},
{
"type": "PropertyDefinition",
"name": "what",
"description": "WHAT happened.",
"mandatory": true,
"readonly": true,
"notnull": true,
"max": null,
"min": null,
"regexp": null,
"defaultValue": null,
"propertyType": "String"
},
{
"type": "PropertyDefinition",
"name": "when",
"description": "WHEN the event occured. It is represented in the format yyyy-MM-dd HH:mm:ss.SSS Z.",
"mandatory": true,
"readonly": true,
"notnull": true,
"max": null,
"min": null,
"regexp": null,
"defaultValue": null,
"propertyType": "Date"
},
{
"type": "PropertyDefinition",
"name": "where",
"description": "The location (can be virtual) WHERE the event occurred.",
"mandatory": false,
"readonly": true,
"notnull": true,
"max": null,
"min": null,
"regexp": null,
"defaultValue": null,
"propertyType": "String"
},
{
"type": "PropertyDefinition",
"name": "who",
"description": "WHO triggered the event.",
"mandatory": false,
"readonly": true,
"notnull": true,
"max": null,
"min": null,
"regexp": null,
"defaultValue": null,
"propertyType": "String"
},
{
"type": "PropertyDefinition",
"name": "why",
"description": "The reason WHY the event occurred.",
"mandatory": false,
"readonly": true,
"notnull": true,
"max": null,
"min": null,
"regexp": null,
"defaultValue": null,
"propertyType": "String"
}
],
"version": "1.0.0",
"changelog": { "1.0.0": "First Version" },
"abstract": false,
"final": true,
"extendedTypes": [ "Property" ]
}
So imagine you want to update the ``EventFacet`` type definition to use this property type instead of the ``date`` and ``event`` properties.
The objective is to obtain a facet with ``event`` property as an ``Event``.
To update the ``EventFacet`` there are different strategies:
Java Backwards Compatibility
----------------------------
This solution is Java compliant from a code perspective.
Moreover, instances using the old format are properly deserialised.
.. code:: java
/**
* EventFacet captures information on a certain event/happening characterising the life cycle of the resource.
*
* Examples of an event are the start time of a virtual machine or the activation time of an electronic service.
*
* https://wiki.gcube-system.org/gcube/GCube_Model#Event_Facet
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=EventFacetImpl.class)
@TypeMetadata(
name = EventFacet.NAME,
description = "EventFacet captures information on a certain event/happening characterising the life cycle of the resource. "
+ "Examples of an event are the start time of a virtual machine or the activation time of an electronic service.",
version = EventFacet.VERSION
)
@Changelog ({
@Change(version = EventFacet.VERSION, description = "Switching to {@link Event} Property added in the information-system-model"),
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
})
public interface EventFacet extends Facet {
public static final String NAME = "EventFacet"; // EventFacet.class.getSimpleName();
public static final String VERSION = "2.0.0";
public static final String EVENT_PROPERTY = "event";
@Deprecated
/**
* This method will be removed soon.
* Use {@link EventFacet#getTheEvent()} method which return {@link Event} instance.
* The date can be retrieved by using {@link Event#getWhen()} method.
*
* @return the date of the occurred event.
*/
public Date getDate();
@Deprecated
/**
* This method will be removed soon.
* Use {@link EventFacet#setEvent(Event event)}.
* The date can be set in {@link Event} instance by using
* {@link Event#setWhen(Date date)} method.
*
* @param date the date of the occurred event.
* which is the same of the 'when' Date of the {@link Event} instance.
*/
public void setDate(Date date);
@Deprecated
/**
* This method will be removed soon.
* Use {@link EventFacet#getTheEvent()} method which return {@link Event} instance.
* The deprecated 'event' String can be retrieved by using {@link Event#getWhat()} method.
*
* @return the string of event, e.g. active
*/
public String getEvent();
@Deprecated
/**
* This method will be removed soon.
* Use {@link EventFacet#setEvent(Event event)}.
* The deprecated 'event' String can be set in {@link Event} instance by using
* {@link Event#setWhat(String what)} method.
*
* @param event the string of the event to set, e.g. failed
* which is the same of the 'what' String of the {@link Event} instance.
*/
public void setEvent(String event);
/**
* Actually is not mandatory for backward compatibility.
* In the next version this method will be deprecated to and it will be replaced
* by a method with the following signature:
*
* public Event getEvent()
*
* This is not actually possible because we need to maintain
* {@link EventFacet#getEvent()} for backward compatibility
*
* @return the event
*/
@ISProperty(name=EVENT_PROPERTY, type=Object.class, description = "The event eventually described by the five W (What, When, Who, Where, Why)", mandatory=false, nullable=false)
public Event getTheEvent();
/**
* Set the event
* @param event the event to set
*/
public void setEvent(Event event);
}
which produces the following type definition:
.. code:: javascript
{
"type": "FacetType",
"id": "b76de0ac-048a-43a0-ae4f-e3fdb1a7d27c",
"name": "EventFacet",
"description": "EventFacet captures information on a certain event/happening characterising the life cycle of the resource. Examples of an event are the start time of a virtual machine or the activation time of an electronic service.",
"properties": [
{
"type": "PropertyDefinition",
"name": "event",
"description": "The event eventually described by the five W (What, When, Who, Where, Why)",
"mandatory": false,
"readonly": false,
"notnull": true,
"max": null,
"min": null,
"regexp": null,
"defaultValue": null,
"propertyType": "Any"
}
],
"version": "2.0.0",
"changelog": {
"2.0.0": "Switching to {@link Event} Property added in the information-system-model",
"1.0.0": "First Version"
},
"abstract": false,
"final": false,
"extendedTypes": [ "Facet" ]
}
The implementation should be something like this:
.. code:: java
import java.util.Date;
import java.util.LinkedHashMap;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
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.databind.ObjectMapper;
import org.gcube.informationsystem.model.impl.entities.FacetImpl;
import org.gcube.informationsystem.model.impl.properties.EventImpl;
import org.gcube.informationsystem.model.reference.properties.Event;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value = EventFacet.NAME)
public class EventFacetImpl extends FacetImpl implements EventFacet {
/**
* Generated Serial version UID
*/
private static final long serialVersionUID = -4130548762073254058L;
protected Event event;
@Override
@Deprecated
/**
* {@inheritDoc}
*
* This function is actually a shortcut to
* {@link EventFacet#getTheEvent()}.{@link Event#getWhen()}
*/
@JsonIgnore
public Date getDate() {
if(event==null) {
return null;
}
return event.getWhen();
}
@Override
@Deprecated
/**
* {@inheritDoc}
*
* This function is actually a shortcut to
* {@link EventFacet#getTheEvent()}.{@link Event#setWhen(Date date)}
*
* It eventually instantiate {@link Event} if null.
*/
@JsonSetter("date")
public void setDate(Date date) {
if(event == null) {
event = new EventImpl();
}
event.setWhen(date);
}
@Override
@Deprecated
/**
* {@inheritDoc}
*
* This function is actually a shortcut to
* {@link EventFacet#getTheEvent()}.{@link Event#getWhat()}
*/
@JsonIgnore
public String getEvent() {
if(event==null) {
return null;
}
return event.getWhat();
}
@Override
@Deprecated
/**
* {@inheritDoc}
*
* This function is actually a shortcut to
* {@link EventFacet#getTheEvent()}.{@link Event#setWhat(String what)}.
*
* It eventually instantiate {@link Event} if null.
*/
@JsonIgnore
public void setEvent(String event) {
if(event == null) {
this.event = new EventImpl();
}
this.event.setWhat(event);
}
@Override
/**
* {@inheritDoc}
*/
@JsonGetter(EventFacet.EVENT_PROPERTY)
public Event getTheEvent() {
return event;
}
@Override
/**
* {@inheritDoc}
*/
@JsonIgnore
public void setEvent(Event event) {
this.event = event;
}
@JsonSetter(EventFacet.EVENT_PROPERTY)
protected void setGenericEvent(Object event) {
if(event instanceof String) {
setEvent((String) event);
}
if(event instanceof LinkedHashMap<?, ?>) {
ObjectMapper objectMapper = ElementMapper.getObjectMapper();
Event theEvent = objectMapper.convertValue(event, Event.class);
setEvent(theEvent);
}
}
}
With this strategy, any Java client reading the event facet instantiated with the old
model will remap the ``date`` and ``event`` properties to an instance of ``Event`` named ``event``.
We receive:
.. code:: javascript
{
"type": "EventFacet",
"id": "d9f91175-8c33-4f68-8619-48e6feca4e47",
"date": "2024-01-08 12:52:59.907 +0100",
"event": "certified"
}
which will be serialized/deserialized in turn as:
.. code:: javascript
{
"type": "EventFacet",
"id": "d9f91175-8c33-4f68-8619-48e6feca4e47",
"event": {
"type": "Event",
"what": "certified",
"when": "2024-01-08 11:52:59.907 +0000",
"who": null,
"where": null,
"why": null,
"how": null
}
}
The problem of this solution is that if the facet is updated to the new format in the server and
if there are old clients they will not be able to work with the new version.
With this solution the ``event`` property in the server is of type ANY (an Object in Java)
.. code:: java
@ISProperty(name=EVENT_PROPERTY, type=Object.class, description = ....
public Event getTheEvent();
The ``@ISProperty`` annotation specifies the type of the property ``type=Object.class`` instead of letting the system to get the type from the function return, i.e. ``Event``.
The type definition in JSON has:
.. code:: javascript
"propertyType": "Any"
PRO:
* the name of the variable is already ``event`` as we want as final objective.
CONS:
* the server cannot check the validity of the variable received from an updating client.
The future release of ``EventFacet`` will
* remove ``type=Object.class`` from ``@ISProperty`` annotation;
* remove deprecated methods from the Java interface and its implementation:
* ``public Date getDate();``
* ``public void setDate(Date date);``
* ``public String getEvent();``
* ``public void setEvent(String event);``
* deprecate ``public Event getTheEvent();``
* add ``public Event getEvent();``
**To summarize**:
This solution is capable of reading old format existing instances,
but it always updates the instances to the new format, which cannot be used by an old client.
Java and Javascript Backwards Compatibility
-------------------------------------------
This solution is Java compliant from a code perspective and the old properties are keep for old clients.
.. code:: java
import java.util.Date;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.properties.Event;
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;
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
/**
* EventFacet captures information on a certain event/happening characterising the life cycle of the resource.
*
* Examples of an event are the start time of a virtual machine or the activation time of an electronic service.
*
* https://wiki.gcube-system.org/gcube/GCube_Model#Event_Facet
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=EventFacetImpl.class)
@TypeMetadata(
name = EventFacet.NAME,
description = "EventFacet captures information on a certain event/happening characterising the life cycle of the resource. "
+ "Examples of an event are the start time of a virtual machine or the activation time of an electronic service.",
version = EventFacet.VERSION
)
@Changelog ({
@Change(version = EventFacet.VERSION, description = "Switching to {@link Event} Property added in the information-system-model"),
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
})
public interface EventFacet extends Facet {
public static final String NAME = "EventFacet"; // EventFacet.class.getSimpleName();
public static final String VERSION = "2.0.0";
public static final String EVENT_PROPERTY = "theEvent";
@Deprecated
/**
* This method will be removed soon.
* Use {@link EventFacet#getTheEvent()} method which return {@link Event} instance.
* The date can be retrieved by using {@link Event#getWhen()} method.
*
* @return the date of the occurred event.
*/
public Date getDate();
@Deprecated
/**
* This method will be removed soon.
* Use {@link EventFacet#setEvent(Event event)}.
* The date can be set in {@link Event} instance by using
* {@link Event#setWhen(Date date)} method.
*
* @param date the date of the occurred event.
* which is the same of the 'when' Date of the {@link Event} instance.
*/
public void setDate(Date date);
@Deprecated
/**
* This method will be removed soon.
* Use {@link EventFacet#getTheEvent()} method which return {@link Event} instance.
* The deprecated 'event' String can be retrieved by using {@link Event#getWhat()} method.
*
* @return the string of event, e.g. active
*/
public String getEvent();
@Deprecated
/**
* This method will be removed soon.
* Use {@link EventFacet#setEvent(Event event)}.
* The deprecated 'event' String can be set in {@link Event} instance by using
* {@link Event#setWhat(String what)} method.
*
* @param event the string of the event to set, e.g. failed
* which is the same of the 'what' String of the {@link Event} instance.
*/
public void setEvent(String event);
/**
* Actually is not mandatory for backward compatibility.
* In the next version this method will be deprecated to and it will be replaced
* by a method with the following signature
*
* public Event getEvent()
*
* This is not actually possible because we need to maintain
* {@link EventFacet#getEvent()} for backward compatibility
*
* @return the event
*/
@ISProperty(name=EVENT_PROPERTY, description = "The event eventually described by the five W (What, When, Who, Where, Why)", mandatory=false, nullable=false)
public Event getTheEvent();
/**
* Set the event
* @param event the event to set
*/
public void setEvent(Event event);
}
With the following definition
.. code:: javascript
{
"type": "FacetType",
"id": "b76de0ac-048a-43a0-ae4f-e3fdb1a7d27c",
"name": "EventFacet",
"description": "EventFacet captures information on a certain event/happening characterising the life cycle of the resource. Examples of an event are the start time of a virtual machine or the activation time of an electronic service.",
"properties":
[
{
"type": "PropertyDefinition",
"name": "theEvent",
"description": "The event eventually described by the five W (What, When, Who, Where, Why)",
"mandatory": false,
"readonly": false,
"notnull": true,
"max": null,
"min": null,
"regexp": null,
"defaultValue": null,
"propertyType": "Event"
}
],
"version": "2.0.0",
"changelog": {
"2.0.0": "Switching to {@link Event} Property added in the information-system-model",
"1.0.0": "First Version"
},
"abstract": false,
"final": false,
"extendedTypes": [ "Facet" ]
}
The implementation should be the following:
.. code:: java
import java.util.Date;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
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.entities.FacetImpl;
import org.gcube.informationsystem.model.impl.properties.EventImpl;
import org.gcube.informationsystem.model.reference.properties.Event;
import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value = EventFacet.NAME)
public class EventFacetImpl extends FacetImpl implements EventFacet {
/**
* Generated Serial version UID
*/
private static final long serialVersionUID = -4130548762073254058L;
protected Event theEvent;
@Override
@Deprecated
/**
* {@inheritDoc}
*
* This function is actually a shortcut to
* {@link EventFacet#getTheEvent()}.{@link Event#getWhen()}
*/
public Date getDate() {
if(theEvent==null) {
return null;
}
return theEvent.getWhen();
}
@Override
@Deprecated
/**
* {@inheritDoc}
*
* This function is actually a shortcut to
* {@link EventFacet#getTheEvent()}.{@link Event#setWhen(Date date)}
*
* It eventually instantiate {@link Event} if null.
*/
@JsonSetter("date")
public void setDate(Date date) {
if(theEvent == null) {
theEvent = new EventImpl();
}
theEvent.setWhen(date);
}
@Override
@Deprecated
/**
* {@inheritDoc}
*
* This function is actually a shortcut to
* {@link EventFacet#getTheEvent()}.{@link Event#getWhat()}
*/
public String getEvent() {
if(theEvent==null) {
return null;
}
return theEvent.getWhat();
}
@Override
@Deprecated
/**
* {@inheritDoc}
*
* This function is actually a shortcut to
* {@link EventFacet#getTheEvent()}.{@link Event#setWhat(String what)}.
*
* It eventually instantiate {@link Event} if null.
*/
@JsonSetter("event")
public void setEvent(String event) {
if(event == null) {
this.theEvent = new EventImpl();
}
this.theEvent.setWhat(event);
}
@Override
/**
* {@inheritDoc}
*/
@JsonGetter(EventFacet.EVENT_PROPERTY)
public Event getTheEvent() {
return theEvent;
}
@Override
/**
* {@inheritDoc}
*/
@JsonIgnore
@JsonSetter(EventFacet.EVENT_PROPERTY)
public void setEvent(Event event) {
this.theEvent = event;
}
}
With this strategy, any Java client reading the event facet instantiated with the old
model will remap the 'date' and 'event' properties to an instance of 'Event' named 'theEvent'.
The old properties 'date' and 'event' properties are still available for old clients.
We receive
.. code:: javascript
{
"type": "EventFacet",
"id": "d9f91175-8c33-4f68-8619-48e6feca4e47",
"date": "2024-01-08 12:52:59.907 +0100",
"event": "certified"
}
which will be serialized/deserialized in turn as:
.. code:: javascript
{
"type": "EventFacet",
"id": "d9f91175-8c33-4f68-8619-48e6feca4e47",
"date": "2024-01-08 12:52:59.907 +0100"
"event": "certified",
"theEvent": {
"type": "Event",
"what": "certified",
"when": "2024-01-08 11:52:59.907 +0000",
"who": null,
"where": null,
"why": null,
"how": null
}
}
With this solution we use ``theEvent`` property in the server of type Event which validity can be checked by the server:
PRO:
* the server can check the validity of the variable received from an updating client.
CONS:
* the name of the variable is ``theEvent`` and only in a future step will be changed.
The future release of ``EventFacet`` will
* remove deprecated methods from the Java interface and its implementation:
* ``public Date getDate();``
* ``public void setDate(Date date);``
* ``public String getEvent();``
* ``public void setEvent(String event);``
* deprecate ``public Event getTheEvent();``
* add ``public Event getEvent();``
Both ``event`` and ``theEvent`` will coexist until the next version.
This solution has the following issue:
``date`` and ``event`` may not align with ``theEvent`` if updated by old clients.
The proposed implementation involves ``setTheEvent()``, which could potentially overwrite
``date`` and ``event`` if invoked by Jackson beforehand.
Therefore, implementing this correctly requires careful consideration.
It's important to note that only old clients might disalign the date.
As a result, the most advanced values always reside in the old properties.
Conversely, a new client would have already corrected and aligned them.
Of course, there is no resolution for bugged new clients causing misalignments,
but that's a separate issue not covered in this guide.
**To summarize**:
This solution is capable of reading old format existing instances.
New clients update the properties in both old and new formats.
It can be used by old clients, but new clients must take into account that an update
made by an old client causes misalignment of the date and event properties with the
corresponding properties contained in the ``theEvent`` property.

48
pom.xml
View File

@ -10,7 +10,7 @@
<groupId>org.gcube.information-system</groupId>
<artifactId>information-system-model</artifactId>
<version>7.1.0-SNAPSHOT</version>
<version>5.0.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.1.0</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>

View File

@ -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();
}
}
}

View File

@ -1,11 +1,12 @@
package org.gcube.informationsystem.base.impl.entities;
import java.util.UUID;
import java.io.StringWriter;
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.model.reference.properties.Header;
import org.gcube.informationsystem.utils.ElementMapper;
/**
* @author Luca Frosini (ISTI - CNR)
@ -18,31 +19,36 @@ 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;
public Header getHeader() {
return header;
}
@Override
public void setHeader(Header header){
this.header = header;
}
@Override
public String toString(){
StringWriter stringWriter = new StringWriter();
try {
ElementMapper.marshal(this, stringWriter);
return stringWriter.toString();
}catch(Exception e){
try {
ElementMapper.marshal(this.header, stringWriter);
return stringWriter.toString();
} catch(Exception e1){
return super.toString();
}
}
}
@Override
public void setID(UUID uuid) {
this.uuid = uuid;
}
@Override
public Metadata getMetadata() {
return metadata;
}
@Override
public void setMetadata(Metadata metadata){
this.metadata = metadata;
}
}

View File

@ -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;

View File

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

View File

@ -64,24 +64,23 @@ public enum AccessType {
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),
QUERY_TEMPLATE(QueryTemplate.class, QueryTemplate.NAME, QueryTemplateImpl.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_PARENT_OF(IsParentOf.class, IsParentOf.NAME, IsParentOfImpl.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 {
@ -91,17 +90,6 @@ public enum AccessType {
String name = accessType.getName();
names.add(name);
}
modelTypes = new AccessType[] {
AccessType.PROPERTY,
AccessType.RESOURCE, AccessType.FACET,
AccessType.IS_RELATED_TO, AccessType.CONSISTS_OF
};
erTypes = new AccessType[] {
AccessType.RESOURCE, AccessType.FACET,
AccessType.IS_RELATED_TO, AccessType.CONSISTS_OF
};
}
private final Class<? extends Element> clz;
@ -191,21 +179,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;
}
}

View File

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

View File

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

View File

@ -5,8 +5,6 @@ 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;
@ -17,23 +15,21 @@ 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)
@TypeMetadata(name = Element.NAME, description = "This is the base class 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();
}

View File

@ -1,36 +1,17 @@
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}
* This interfaces is an helper to identify elements could be identified via {@link Header}
*
* @author Luca Frosini (ISTI - CNR)
*/
@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);
}

View File

@ -1,12 +1,9 @@
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;
@ -18,26 +15,16 @@ import org.gcube.informationsystem.utils.Version;
*/
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
@JsonPropertyOrder({ Element.TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY })
//@JsonDeserialize(as=EntityElementImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = EntityElement.NAME, description = "This is the base type for any EntityElement", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = EntityElement.NAME, description = "This is the base class 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();
}

View File

@ -14,7 +14,7 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=PropertyElementImpl.class)
@TypeMetadata(name = PropertyElement.NAME, description = "This is the base type for any PropertyElement", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = PropertyElement.NAME, description = "This is the base class for any PropertyElement", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface PropertyElement extends Element {

View File

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

View File

@ -4,32 +4,24 @@
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.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.utils.UUIDManager;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=Context.NAME)
public class ContextImpl extends EntityElementImpl implements Context {
public final class ContextImpl extends EntityElementImpl implements Context {
/**
* Generated Serial Version UID
@ -38,30 +30,13 @@ public class ContextImpl extends EntityElementImpl implements Context {
protected String name;
protected String state;
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) {
@ -72,10 +47,9 @@ public class ContextImpl extends EntityElementImpl implements Context {
this();
this.name = name;
if(uuid == null){
uuid = UUIDManager.getInstance().generateValidUUID();
uuid = UUIDManager.generateValidRandomUUID();
}
this.uuid = uuid;
this.metadata = new MetadataImpl();
this.header = new HeaderImpl(uuid);
}
@Override
@ -87,16 +61,6 @@ public class ContextImpl extends EntityElementImpl implements Context {
public void setName(String name) {
this.name = name;
}
@Override
public String getState() {
return this.state;
}
@Override
public void setState(String state) {
this.state = state;
}
@Override
public IsParentOf getParent() {
@ -108,8 +72,8 @@ public class ContextImpl extends EntityElementImpl implements Context {
public void setParent(UUID uuid) {
Context parent = null;
if(uuid!=null) {
parent = new ContextImpl(uuid);
parent.setMetadata(new MetadataImpl());
parent = new ContextImpl();
parent.setHeader(new HeaderImpl(uuid));
}
setParent(parent);
}
@ -157,8 +121,8 @@ public class ContextImpl extends EntityElementImpl implements Context {
@Override
public void addChild(UUID uuid) {
Context child = new ContextImpl(uuid);
child.setMetadata(new MetadataImpl());
Context child = new ContextImpl();
child.setHeader(new HeaderImpl(uuid));
addChild(child);
}
@ -174,56 +138,5 @@ public class ContextImpl extends EntityElementImpl implements Context {
isParentOf.setSource(this);
children.add(isParentOf);
}
@Override
public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}
@Override
public void setAdditionalProperties(Map<String, Object> additionalProperties) {
this.additionalProperties = additionalProperties;
}
@Override
public Object getAdditionalProperty(String key) {
return additionalProperties.get(key);
}
@Override
public void setAdditionalProperty(String key, Object value) {
if(!allowedAdditionalKeys.contains(key)){
if(key.startsWith("_")) {
return;
}
if(key.startsWith("@")) {
return;
}
}
/*
Additional properties are not deserialized to the proper property type.
The first attempt was to try to write a specific deserializer but it fails.
This fix the issue.
*/
try {
if(value instanceof Map<?,?>) {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String,Object>) value;
if(map.containsKey(Element.TYPE_PROPERTY)) {
String reserialized = ElementMapper.getObjectMapper().writeValueAsString(map);
Property property = ElementMapper.unmarshal(Property.class, reserialized);
value = property;
}
}
}catch (Throwable e) {
e.getMessage();
// Any type of error/exception must be catched
}
/* END of fix to properly deserialize Property types*/
this.additionalProperties.put(key, value);
}
}

View File

@ -4,26 +4,16 @@
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.Final;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
@ -35,49 +25,20 @@ import org.gcube.informationsystem.utils.Version;
* @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)
@TypeMetadata(name = Context.NAME, description = "This class is the used to define a Context", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@Final
public interface Context extends EntityElement, SchemaMixedElement {
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";
/**
* Indicates the state of Context.
* See #27706
*
* The resource-registry only knows:
* - created
* - active
* - deleted
*
* Other statuses can be set by a Manager.
* The resource-registry will allow the management of instances
* from non-managers if and only if the state is active.
*
* The resource-registry sets the states according to the following:
*
* A newly created Context is set as created. Only a manager can use the instances collection;
* The active state can be set only by a Manager;
* When a context is deleted, the state is set to deleted, and the security space is removed,
* but the Vertex representing the Context will be maintained see #19428.
*/
public static final String STATE = "state";
@ISProperty(name = NAME_PROPERTY, mandatory = true, nullable = false)
public String getName();
public void setName(String name);
@ISProperty(name = STATE)
public String getState();
public void setState(String state);
@JsonGetter
@JsonIgnoreProperties({ Relation.TARGET_PROPERTY })
@ -101,21 +62,5 @@ public interface Context extends EntityElement, SchemaMixedElement {
public void addChild(Context child);
public void addChild(IsParentOf isParentOf);
@JsonAnyGetter
@JsonSerialize(using = AdditionalPropertiesSerializer.class)
@Override
public Map<String,Object> getAdditionalProperties();
@Override
public void setAdditionalProperties(Map<String,Object> additionalProperties);
@Override
public Object getAdditionalProperty(String key);
@JsonAnySetter
@Override
public void setAdditionalProperty(String key, Object value);
}

View File

@ -6,10 +6,7 @@ package org.gcube.informationsystem.contexts.reference.relations;
import org.gcube.com.fasterxml.jackson.annotation.JsonGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.base.reference.relations.RelationElement;
import org.gcube.informationsystem.contexts.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.contexts.reference.entities.Context;
@ -23,8 +20,7 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@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)
@TypeMetadata(name = IsParentOf.NAME, description = "This class is the used to define parental relations between Context", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface IsParentOf extends RelationElement<Context,Context> {

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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());
}
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

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

View File

@ -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.");
}
}
}

View File

@ -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;
}
}

View File

@ -5,7 +5,7 @@ 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;
@ -14,7 +14,7 @@ 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)
@TypeMetadata(name = Facet.NAME, description = "This is a dummy class 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 +25,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(){

View File

@ -5,7 +5,7 @@ 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;
@ -14,7 +14,7 @@ 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)
@TypeMetadata(name = Resource.NAME, description = "This is a dummy class 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 +25,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(){

View File

@ -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;
}
}

View File

@ -13,7 +13,7 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.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;

View File

@ -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){

View File

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

View File

@ -1,164 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.properties;
import java.util.Date;
import java.util.Objects;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.model.reference.properties.Event;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=Event.NAME)
public class EventImpl extends PropertyImpl implements Event {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 5102553511155113169L;
protected String what;
protected Date when;
protected String who;
protected String where;
protected String why;
protected String how;
public EventImpl() {
super();
}
@Override
public String getWhat() {
return what;
}
@Override
public void setWhat(String what) {
this.what = what;
}
@Override
public Date getWhen() {
return when;
}
@Override
public void setWhen(Date when) {
this.when = when;
}
@Override
public String getWho() {
return who;
}
@Override
public void setWho(String who) {
this.who = who;
}
@Override
public String getWhere() {
return where;
}
@Override
public void setWhere(String where) {
this.where = where;
}
@Override
public String getWhy() {
return why;
}
@Override
public void setWhy(String why) {
this.why = why;
}
@Override
public String getHow() {
return how;
}
@Override
public void setHow(String how) {
this.how = how;
}
private int compareStrings(String sThis, String sOther) {
return 0;
}
@Override
public int compareTo(Event o) {
if(o == null) {
return 1;
}
int compare = 0;
if(this.when==null) {
if(o.getWhen()==null) {
compare = 0;
}else {
compare = 1;
}
}else {
if(o.getWhen()==null) {
compare = -1;
}else {
compare = this.when.compareTo(o.getWhen());
}
}
if(compare!=0) {
return compare;
}
compare = compareStrings(this.what,o.getWhat());
if(compare!=0) {
return compare;
}
compare = compareStrings(this.who,o.getWho());
if(compare!=0) {
return compare;
}
compare = compareStrings(where,o.getWhere());
if(compare!=0) {
return compare;
}
compare = compareStrings(why,o.getWhy());
if(compare!=0) {
return compare;
}
compare = compareStrings(how,o.getHow());
return compare;
}
@Override
public int hashCode() {
return Objects.hash(how, what, when, where, who, why);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
EventImpl other = (EventImpl) obj;
return Objects.equals(how, other.how) && Objects.equals(what, other.what) && Objects.equals(when, other.when)
&& Objects.equals(where, other.where) && Objects.equals(who, other.who)
&& Objects.equals(why, other.why);
}
}

View File

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

View File

@ -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;
}
}

View File

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

View File

@ -13,7 +13,7 @@ import org.gcube.informationsystem.utils.Version;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@TypeMetadata(name = IsRelatedTo.NAME, description = "This is a dummy type for IsRelatedTo", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = IsRelatedTo.NAME, description = "This is a dummy class for IsRelatedTo", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public class DummyIsRelatedTo<S extends Resource, T extends Resource>
extends IsRelatedToImpl<S, T> implements IsRelatedTo<S, T>{

View File

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

View File

@ -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;
@ -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;

View File

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

View File

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

View File

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

View File

@ -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;
}
}

View File

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

View File

@ -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();
}

View File

@ -3,12 +3,8 @@
*/
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;
@ -20,9 +16,8 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@Abstract
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY })
//@JsonDeserialize(as=EntityImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = Entity.NAME, description = "This is the base type for any Entity", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = Entity.NAME, description = "This is the base class for Entities", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface Entity extends EntityElement, ERElement {

View File

@ -6,10 +6,10 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.gcube.informationsystem.base.reference.SchemaMixedElement;
import org.gcube.informationsystem.serialization.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.utils.Version;
/**
@ -19,7 +19,7 @@ import org.gcube.informationsystem.utils.Version;
*/
@Abstract
// @JsonDeserialize(as=FacetImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = "Facet", description = "This is the base type for any Facet", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = "Facet", description = "This is the base class for Facets", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface Facet extends Entity, SchemaMixedElement {

View File

@ -8,17 +8,12 @@ import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.RelatedResourcesEntry;
import org.gcube.informationsystem.types.annotations.ResourceSchema;
import org.gcube.informationsystem.types.annotations.ResourceSchemaEntry;
import org.gcube.informationsystem.types.annotations.RelatedResourcesEntry;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
@ -30,7 +25,6 @@ import org.gcube.informationsystem.utils.Version;
*/
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY, IdentifiableElement.ID_PROPERTY, IdentifiableElement.METADATA_PROPERTY, ERElement.CONTEXTS_PROPERTY, Resource.CONSISTS_OF_PROPERTY, Resource.IS_RELATED_TO_PROPERTY })
// @JsonDeserialize(as=ResourceImpl.class) Do not uncomment to manage subclasses
@ResourceSchema(
facets={
@ -40,7 +34,7 @@ import org.gcube.informationsystem.utils.Version;
@RelatedResourcesEntry(source=Resource.class, relation=IsRelatedTo.class, target=Resource.class, description="Any Resource can be related to any other resource.")
}
)
@TypeMetadata(name = Resource.NAME, description = "This is the base type for any Resource", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = Resource.NAME, description = "This is the base class for Resources", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface Resource extends Entity {

View File

@ -13,19 +13,18 @@ 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)
@TypeMetadata(name = Encrypted.NAME, description = "This is the base class for Encrypted values", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface Encrypted extends Property {
public static final String NAME = "Encrypted"; // Encrypted.class.getSimpleName();
public static final String VALUE = "value";
@ISProperty(name=VALUE, readonly=false, mandatory=true, nullable=false, 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);
}

View File

@ -1,67 +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.annotation.JsonInclude;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.model.impl.properties.EventImpl;
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=EventImpl.class)
@TypeMetadata(name = Event.NAME, description = "This type provides information regarding an event using the Five Ws (checklist) https://en.wikipedia.org/wiki/Five_Ws", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
@JsonInclude(JsonInclude.Include.NON_NULL)
public interface Event extends Property, Comparable<Event> {
public static final String NAME = "Event"; // Event.class.getSimpleName();
public static final String WHAT_PROPERTY = "what";
public static final String WHEN_PROPERTY = "when";
public static final String WHO_PROPERTY = "who";
public static final String WHERE_PROPERTY = "where";
public static final String WHY_PROPERTY = "why";
public static final String HOW_PROPERTY = "how";
@ISProperty(name = WHAT_PROPERTY, description = "WHAT happened.", readonly = true, mandatory = true, nullable = false)
public String getWhat();
public void setWhat(String what);
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Element.DATETIME_PATTERN)
@ISProperty(name = WHEN_PROPERTY, description = "WHEN the event occured. It is represented in the format " + Element.DATETIME_PATTERN + ".", readonly = true, mandatory = true, nullable = false)
public Date getWhen();
public void setWhen(Date when);
@ISProperty(name = WHO_PROPERTY, description = "WHO triggered the event.", readonly = true, mandatory = false, nullable = false)
public String getWho();
public void setWho(String who);
@ISProperty(name = WHERE_PROPERTY, description = "The location (can be virtual) WHERE the event occurred.", readonly = true, mandatory = false, nullable = false)
public String getWhere();
public void setWhere(String where);
@ISProperty(name = WHY_PROPERTY, description = "The reason WHY the event occurred.", readonly = true, mandatory = false, nullable = false)
public String getWhy();
public void setWhy(String why);
@ISProperty(name = HOW_PROPERTY, description = "How the event occurred.", readonly = true, mandatory = false, nullable = false)
public String getHow();
public void setHow(String how);
}

View File

@ -4,51 +4,64 @@
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.MetadataImpl;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
/**
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Header
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=MetadataImpl.class)
@TypeMetadata(name = Metadata.NAME, description = "This type provides metadata per every IdentifiableElement", version = Version.MINIMAL_VERSION_STRING)
@JsonDeserialize(as=HeaderImpl.class)
@TypeMetadata(name = Header.NAME, description = "This class 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 interface Header extends Property {
public static final String NAME = "Metadata"; // Metadata.class.getSimpleName();
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 HIDDEN_FOR_PRIVACY_USER = "HIDDEN_FOR_PRIVACY";
public static final String UUID_PROPERTY = "uuid";
public static final String CREATED_BY_PROPERTY = "createdBy";
public static final String CREATION_TIME_PROPERTY = "creationTime";
public static final String LAST_UPDATE_BY_PROPERTY = "lastUpdateBy";
public static final String LAST_UPDATE_TIME_PROPERTY = "lastUpdateTime";
@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)
/**
* Used when requested to include contexts in header.
* This is not a native property (it is just generated by server for administration clients convenience)
*/
public static final String __CONTEXTS = "contexts";
@ISProperty(name = UUID_PROPERTY, description = "This UUID is be used to identify the Entity or the Relation univocally.", readonly = true, mandatory = true, nullable = false)
public UUID getUUID();
public void setUUID(UUID uuid);
@ISProperty(name = CREATED_BY_PROPERTY, description = "The user that created the Entity or the Relation. It is initialized at creation time. ", readonly = true, mandatory = true, nullable = false)
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)
@ISProperty(name = CREATION_TIME_PROPERTY, description = "Creation time. It represents the difference, measured in milliseconds, between the creation time and midnight, January 1, 1970, UTC.", readonly = true, mandatory = true, nullable = false)
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)
@ISProperty(name = LAST_UPDATE_BY_PROPERTY, description = "The user that made the last update to the Entity or the Relation. At creation time, it assumes the same value of creator.", mandatory = true, nullable = false)
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)
@ISProperty(name = LAST_UPDATE_TIME_PROPERTY, description = "Last Update time. At creation time it assumes the same value of creationTime. It represents the difference, measured in milliseconds, between the creation time and midnight, January 1, 1970, UTC.", mandatory = true, nullable = false)
public Date getLastUpdateTime();
}

View File

@ -5,48 +5,65 @@ 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 PropagationConstraint property contained in each relation is a predefined Property type
* which indicates the behaviour to be held on a target entity when an event related to a context occurs
* in the source resource or directly to the relation.
*
* The default values of propagation constraints are:
* - IsRelatedTo: delete=keep, remove=keep, add=unpropagate;
* - ConsistsOf : delete=cascade, remove=cascade, add=propagate.
* - IsRelatedTo: remove=keep, add=unpropagate;
* - ConsistsOf : remove=cascadeWhenOrphan, add=propagate.
*
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Propagation_Constraint
*
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=PropagationConstraintImpl.class)
@TypeMetadata(name = PropagationConstraint.NAME, description = "This type provides propagation constraint for Relation", version = "1.1.0")
@Changelog({
@Change(version = "1.1.0", description = "Added 'delete' propagation constraint"),
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
})
@Final
@TypeMetadata(name = PropagationConstraint.NAME, description = "This class provides propation constraint for Relation", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
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 static final String REMOVE_PROPERTY = "remove";
public static final String ADD_PROPERTY = "add";
public enum RemoveConstraint {
/**
* When a remove action is performed on the source Entity of the relation,
* or directly on the relation, then the same remove action apart on
* the relation is performed to the target entity if it has no other incoming relations
*/
cascadeWhenOrphan,
/**
* When a remove action is performed on the source Entity of the relation,
* or directly on the relation, then the same remove action is performed on
* the relation and its target entity;
*/
cascade,
/**
* When a remove action is performed on the source Entity of the relation,
* or directly on the relation, then the same remove action is performed on
* relation but never to the target entity.
*/
keep
}
public enum AddConstraint {
/**
* When an 'add' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'add' action is performed on
* or directly on the relation, then the same add action is performed on
* the relation and its target Entity.
*/
propagate,
@ -60,72 +77,17 @@ public interface PropagationConstraint extends Property {
}
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
}
@ISProperty(name=REMOVE_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when a 'remove' action is performed on the source Resource. Remove actions are: (i) the operation of removing an instance from a context; (ii) the operation of deleting an instance (it has an impact on all contexts).", mandatory = true, nullable = false)
public RemoveConstraint getRemoveConstraint();
public void setRemoveConstraint(RemoveConstraint removeConstraint);
public enum RemoveConstraint {
/**
* When a 'remove' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'remove' action apart on
* the relation is performed to the target entity if it has no other incoming relations
*/
cascadeWhenOrphan,
/**
* When a 'remove' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'remove' action is performed on
* the relation and its target entity;
*/
cascade,
/**
* When a 'remove' action is performed on the source Entity of the relation,
* or directly on the relation, then the same 'remove' action is performed on
* relation but never to the target entity.
*/
keep
}
@ISProperty(name=ADD_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when an 'add' action is performed on the source Resource. Add action is the operation of adding an instance to a context.", mandatory = true, nullable = false)
public AddConstraint getAddConstraint();
public void setAddConstraint(AddConstraint addConstraint);
@ISProperty(name=DELETE_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when a 'delete' action is performed on the source Resource. Delet action is the operation of deleting an instance (it has an impact on all contexts).", mandatory = true, nullable = false)
public DeleteConstraint getDeleteConstraint();
public void setDeleteConstraint(DeleteConstraint deleteConstraint);
@ISProperty(name=REMOVE_PROPERTY, description = "It indicates the behaviour to implement for the target Entity when a 'remove' action is performed on the source Resource. Remove actions is the operation of removing an instance from a context.", mandatory = true, nullable = false)
public RemoveConstraint getRemoveConstraint();
public void setRemoveConstraint(RemoveConstraint removeConstraint);
}

View File

@ -7,17 +7,14 @@ import java.util.Map;
import org.gcube.com.fasterxml.jackson.annotation.JsonAnyGetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonAnySetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.SchemaMixedElement;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.model.impl.properties.PropertyImpl;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.serialization.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
import org.gcube.informationsystem.utils.Version;
/**
@ -27,11 +24,10 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
// @JsonIgnoreProperties(ignoreUnknown=true)
@JsonPropertyOrder({ Element.TYPE_PROPERTY, ModelElement.SUPERTYPES_PROPERTY, ModelElement.EXPECTED_TYPE_PROPERTY })
@JsonDeserialize(as=PropertyImpl.class)
@TypeMetadata(name = Property.NAME, description = "This is the base type for any Property", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = Property.NAME, description = "This is the base class for Properties", 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();

View File

@ -17,7 +17,7 @@ import org.gcube.informationsystem.utils.Version;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=ConsistsOfImpl.class)
@TypeMetadata(name = ConsistsOf.NAME, description = "This is the base type for any ConsistsOf relation", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = ConsistsOf.NAME, description = "This is the base class for ConsistsOf relations", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface ConsistsOf<S extends Resource, T extends Facet>
extends Relation<S, T> {

View File

@ -16,7 +16,7 @@ import org.gcube.informationsystem.utils.Version;
*/
@Abstract
// @JsonDeserialize(as=IsRelatedToImpl.class) Do not uncomment to manage subclasses
@TypeMetadata(name = IsRelatedTo.NAME, description = "This is the base type for any IsRelatedTo relation", version = Version.MINIMAL_VERSION_STRING)
@TypeMetadata(name = IsRelatedTo.NAME, description = "This is the base class for IsRelatedTo relations", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface IsRelatedTo<S extends Resource, T extends Resource>
extends Relation<S, T> {

View File

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

View File

@ -14,7 +14,6 @@ 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)
@ -96,63 +95,8 @@ public class QueryTemplateImpl extends EntityElementImpl implements QueryTemplat
@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;
// }
objectNode.put(tv.getName(), tv.getDefaultValue());
}
return objectNode;
}

View File

@ -3,14 +3,9 @@
*/
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.queries.templates.reference.properties.TemplateVariable;
import org.gcube.informationsystem.types.PropertyTypeName;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.utils.AttributeUtility;
/**
* @author Luca Frosini (ISTI - CNR)
@ -25,11 +20,7 @@ public class TemplateVariableImpl extends PropertyElementImpl implements Templat
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;
protected String defaultValue;
public TemplateVariableImpl() {
super();
@ -54,74 +45,15 @@ public class TemplateVariableImpl extends PropertyElementImpl implements Templat
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() {
public String getDefaultValue() {
return defaultValue;
}
@Override
public void setDefaultValue(Object defaultValue) {
public void setDefaultValue(String 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())
+ "]";
}
}

View File

@ -1,12 +1,10 @@
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.Changelog;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
@ -14,35 +12,29 @@ 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 = TemplateVariable.VERSION)
@Changelog ({
@Change(version = TemplateVariable.VERSION, description = "The type comply with {@link Attribute} which add 'defaultValue'"),
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
})
public interface TemplateVariable extends PropertyElement, Attribute {
@TypeMetadata(name = TemplateVariable.NAME, description = "This is the class used to define the a TemplateVariable", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface TemplateVariable extends PropertyElement {
public static final String NAME = "TemplateVariable"; // TemplateVariable.class.getSimpleName();
public static final String VERSION = "1.1.0";
@ISProperty(name = Attribute.NAME_PROPERTY, description = "The name of the Query Template Variable.", readonly = true, mandatory = true, nullable = false)
public static final String VARIABLE_NAME_PROPERTY = "name";
public static final String VARIABLE_DESCRIPTION_PROPERTY = "description";
public static final String VARIABLE_DEFAULT_VALUE_PROPERTY = "defaultValue";
@ISProperty(name = VARIABLE_NAME_PROPERTY, description = "The name of the Query Template Variable.", readonly = true, mandatory = true, nullable = false)
public String getName();
@ISProperty(name = Attribute.DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
public void setName(String name);
@ISProperty(name = VARIABLE_DESCRIPTION_PROPERTY, description = "The description of the Query Template Variable.", readonly = false, mandatory = true, nullable = false)
public String getDescription();
@ISProperty(name = Attribute.MAX_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Integer getMax();
public void setDescription(String description);
@ISProperty(name = Attribute.MIN_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Integer getMin();
@ISProperty(name = VARIABLE_DEFAULT_VALUE_PROPERTY, description = "The default value of the Query Template Variable. The default value is used as is to the query. If the value needs quotation or escaping please include them to the default value", readonly = false, mandatory = true, nullable = false)
public String getDefaultValue();
@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();
public void setDefaultValue(String defaultValue);
}

View File

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

View File

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

View File

@ -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;
}

View File

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

View File

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

View File

@ -27,34 +27,8 @@ 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"),
@ -121,8 +95,6 @@ public class PropertyTypeName {
}
protected static final Map<Class<?>,BaseType> BASE_PROPERTY_TYPES_BY_CLASS;
protected static final Map<Class<?>,String> REGEX_BY_CLASS_MAPPED_AS_STRING;
protected static final Map<String,String> REGEX_BY_CLASS_MAPPED_AS_STRING_BY_CLASS_NAME;
static {
BASE_PROPERTY_TYPES_BY_CLASS = new HashMap<>();
@ -174,45 +146,6 @@ public class PropertyTypeName {
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);
REGEX_BY_CLASS_MAPPED_AS_STRING_BY_CLASS_NAME = new HashMap<>();
for(Class<?> clz : REGEX_BY_CLASS_MAPPED_AS_STRING.keySet()) {
String className = clz.getSimpleName();
String regex = REGEX_BY_CLASS_MAPPED_AS_STRING.get(clz);
REGEX_BY_CLASS_MAPPED_AS_STRING_BY_CLASS_NAME.put(className, 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);
}
public static String getRegexByClassname(String className) {
return REGEX_BY_CLASS_MAPPED_AS_STRING_BY_CLASS_NAME.get(className);
}
/**
@ -227,11 +160,8 @@ public class PropertyTypeName {
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)) {
@ -239,6 +169,7 @@ public class PropertyTypeName {
}
}
}
return type;
}
@ -247,34 +178,10 @@ public class PropertyTypeName {
protected BaseType genericBaseType;
protected String genericClassName;
protected Class<?> clz;
public PropertyTypeName(String type) {
setType(type);
}
public PropertyTypeName(Class<?> clz) {
baseType = null;
genericType = false;
genericBaseType = null;
genericClassName = null;
logger.trace("The type is {}", 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;
}
}
}
public PropertyTypeName(Method method) {
baseType = null;
genericType = false;
@ -301,13 +208,13 @@ public class PropertyTypeName {
genericType = true;
java.lang.reflect.Type genericReturnType = method.getGenericReturnType();
logger.trace("Generic Type for method {} is {}", method, genericReturnType);
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 Type {} for method {} - Actual Type Argument : {}", genericReturnType, method, t);
logger.trace("Generic Return Type {} for method {} - Actual Type Argument : {}", genericReturnType, method, t);
genericType = t;
}

View File

@ -1,7 +1,6 @@
package org.gcube.informationsystem.types;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -182,23 +181,35 @@ public class TypeMapper {
throw new RuntimeException("The Type " + clz.getSimpleName() + " does not provided the appropriated changelog Map");
}
List<Version> versions = new ArrayList<>(map.keySet());
versions.sort(new Comparator<Version>() {
@Override
public int compare(Version o1, Version o2) {
/* o2.compareTo(o1) and not vice-versa
* because we want descending order
*/
return o2.compareTo(o1);
}
});
if(versions.get(0).compareTo(typeVersion)!=0) {
throw new RuntimeException("The Type declared version (i.e."+ typeVersion.toString() +") does not match the highest version declared in changelog (i.e. "+ versions.get(0) + "). Please fix your type.");
}
return map;
}
/*
private final static String NAME = "NAME";
public static String getStaticStringFieldByName(Class<? extends Element> clz, String fieldName, String defaultValue){
Field field;
try {
field = clz.getDeclaredField(fieldName);
field.setAccessible(true);
return (String) field.get(null);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
return defaultValue;
}
}
@SuppressWarnings("unchecked")
public static <O extends Object> O getStaticFieldByName(Class<? extends Element> clz, String fieldName, O defaultValue){
Field field;
try {
field = clz.getDeclaredField(fieldName);
field.setAccessible(true);
return (O) field.get(null);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
return defaultValue;
}
}
*/
}

View File

@ -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 {
}

View File

@ -1,17 +0,0 @@
package org.gcube.informationsystem.types.annotations;
import org.gcube.informationsystem.types.PropertyTypeName.BaseType;
/**
* This is a facade class.
* {@link ISProperty} has the possibility to specify the type.
* If we don't specify a default in the annotation definition the type is mandatory.
* We need a way to specify a default which means get the return of the annotated method.
* This avoid to the developer to specify something which can be get from the annotated method.
* We can't use Object as default because Object is mapped as {@link BaseType#ANY}
*
* This interface has been defined for this reason.
*/
public interface GetReturnType {
}

View File

@ -8,7 +8,6 @@ import java.lang.annotation.Target;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.types.PropertyTypeName.BaseType;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
/**
@ -25,17 +24,6 @@ import org.gcube.informationsystem.types.reference.properties.PropertyDefinition
public @interface ISProperty {
String name() default "";
/**
* If we don't specify a default in the annotation definition, the type becomes mandatory.
* We wanted a way to specify a default that means using the return type of the annotated method.
* This avoids the need for developers to specify something that can be obtained from the annotated method itself.
* We can't use Object as the default because Object is mapped as {@link BaseType#ANY}.
* For this reason, the type {@link GetReturnType} has been set as the default.
*
* Please note that you can't use this functionality for generic types
* like List<String> because it is not accepted by the annotation.
*/
Class<?> type() default GetReturnType.class;
String description() default "";
boolean mandatory() default false;
boolean readonly() default false;
@ -43,6 +31,5 @@ public @interface ISProperty {
int min() default -1;
int max() default -1;
String regexpr() default "";
String defaultValue() default "null";
}

View File

@ -7,8 +7,6 @@ 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;
@ -21,10 +19,9 @@ 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,7 +29,6 @@ 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;
@ -49,6 +45,12 @@ public class TypeImpl implements Type {
*/
private static final long serialVersionUID = -4333954207969059451L;
/*
public final static String DESCRIPTION = "DESCRIPTION";
public final static String VERSION = "VERSION";
public final static String CHANGELOG = "CHANGELOG";
*/
public static final Map<Version, String> DEFAULT_CHANGELOG_MAP;
private static final Map<String, String> DEFAULT_CHANGELOG_MAP_KEY_AS_STRING;
@ -59,9 +61,9 @@ public class TypeImpl implements Type {
DEFAULT_CHANGELOG_MAP_KEY_AS_STRING.put(Version.MINIMAL_VERSION_STRING, Version.MINIMAL_VERSION_DESCRIPTION);
}
protected UUID uuid;
protected Metadata metadata;
protected Header header;
protected String name;
protected String description;
protected Version version;
@ -69,13 +71,9 @@ public class TypeImpl implements Type {
@JsonInclude(Include.NON_NULL)
protected Map<Version, String> changelog;
@JsonProperty(value = ABSTRACT_PROPERTY)
@JsonProperty(value = "abstract")
protected boolean abstractType;
@JsonProperty(value = FINAL_PROPERTY)
protected boolean finalClass;
protected Set<String> extendedTypes;
protected Set<String> superClasses;
protected Set<PropertyDefinition> properties;
@ -106,9 +104,9 @@ public class TypeImpl implements Type {
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()) {
@ -117,7 +115,7 @@ public class TypeImpl implements Type {
ISProperty propAnnotation = m.getAnnotation(ISProperty.class);
PropertyDefinition prop = new PropertyDefinitionImpl(propAnnotation, m);
properties.add(prop);
logger.trace("Property {} retrieved in type {} ", prop, clz.getSimpleName());
logger.trace("Property {} retrieved in type {} ", prop, type.getSimpleName());
}
}
@ -138,7 +136,7 @@ public class TypeImpl implements Type {
return (Class<?>) t;
}
@SuppressWarnings({ "unchecked" })
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Type getInstance(Class<? extends Element> clz) {
Type typeDefinition = null;
try {
@ -150,7 +148,7 @@ public class TypeImpl implements Type {
.getRelationTypeDefinitionInstance((Class<? extends RelationElement<?, ?>>) clz);
return typeDefinition;
} else if (PropertyElement.class.isAssignableFrom(clz)) {
typeDefinition = new PropertyTypeImpl((Class<? extends PropertyElement>) clz);
typeDefinition = new PropertyTypeImpl(clz);
return typeDefinition;
} else if (Type.class.isAssignableFrom(clz)) {
typeDefinition = new TypeImpl(clz);
@ -183,30 +181,16 @@ public class TypeImpl implements Type {
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;
}
@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
@ -268,15 +252,10 @@ public class TypeImpl implements Type {
public boolean isAbstract() {
return abstractType;
}
@Override
public boolean isFinal() {
return finalClass;
}
@Override
public Set<String> getExtendedTypes() {
return extendedTypes;
public Set<String> getSuperClasses() {
return superClasses;
}
@JsonInclude(Include.NON_EMPTY)
@ -289,10 +268,5 @@ public class TypeImpl implements Type {
public AccessType getAccessType() {
return null;
}
@Override
public String getTypeName() {
return TypeUtility.getTypeName(this.getClass());
}
}

View File

@ -11,13 +11,13 @@ import org.gcube.informationsystem.base.reference.entities.EntityElement;
import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.reference.entities.EntityType;
import org.gcube.informationsystem.types.reference.entities.FacetType;
import org.gcube.informationsystem.types.reference.entities.ResourceType;
import org.gcube.informationsystem.utils.ElementMapper;
/**
* @author Luca Frosini (ISTI - CNR)
@ -66,17 +66,17 @@ public class EntityTypeImpl extends TypeImpl implements EntityType {
if(EntityType.class.isAssignableFrom(clz)){
@SuppressWarnings("unchecked")
Class<? extends EntityType> c = (Class<? extends EntityType>) clz;
this.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);
this.superClasses = 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, QueryTemplate.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 +91,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,7 +111,7 @@ 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();

View File

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

View File

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

View File

@ -117,53 +117,4 @@ public final class LinkedEntityImpl extends PropertyElementImpl implements Linke
Objects.equals(description, other.description);
}
protected int compareIntegers(Integer thisInt, Integer otherInt) {
Integer thisInteger = thisInt == null ? Integer.MAX_VALUE : thisInt;
Integer otherInteger = otherInt == null ? Integer.MAX_VALUE : otherInt;
return thisInteger.compareTo(otherInteger);
}
@Override
public int compareTo(LinkedEntity other) {
if (this == other) {
return 0;
}
if (other == null) {
return -1;
}
if (getClass() != other.getClass()) {
return -1;
}
LinkedEntityImpl o = (LinkedEntityImpl) other;
int ret = 0;
ret = source.compareTo(o.source);
if(ret != 0) {
return ret;
}
ret = relation.compareTo(o.relation);
if(ret != 0) {
return ret;
}
ret = target.compareTo(o.target);
if(ret != 0) {
return ret;
}
ret = compareIntegers(max, o.max);
if(ret != 0) {
return ret;
}
ret = compareIntegers(min, o.min);
if(ret != 0) {
return ret;
}
return description.compareTo(o.description);
}
}

View File

@ -11,10 +11,7 @@ import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeName;
import org.gcube.informationsystem.types.PropertyTypeName;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.annotations.GetReturnType;
import org.gcube.informationsystem.types.reference.properties.PropertyDefinition;
import org.gcube.informationsystem.utils.AttributeUtility;
import org.gcube.informationsystem.utils.TypeUtility;
import org.gcube.informationsystem.utils.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -45,8 +42,8 @@ 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 static String getPropertyNameFromMethodName(Method method){
String name = method.getName();
@ -83,25 +80,13 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
this.min = propertyAnnotation.min();
}
Class<?> clz = propertyAnnotation.type();
if(clz==GetReturnType.class) {
// We have to read the return of the method
this.propertyTypeName = new PropertyTypeName(method);
clz = method.getReturnType();
logger.trace("Return Type for method {} is {}", method, clz);
}else {
this.propertyTypeName = new PropertyTypeName(clz);
}
this.propertyTypeName = new PropertyTypeName(method);
String defaultValueAsString = propertyAnnotation.defaultValue();
defaultValueAsString = AttributeUtility.evaluateNullForDefaultValue(defaultValueAsString);
Class<?> clz = method.getReturnType();
logger.trace("Return Type for method {} is {}", method, clz);
// The default value is evaluated to test if compliant with the declared type
this.defaultValue = AttributeUtility.evaluateDefaultValueStringAccordingBaseType(propertyTypeName.getBaseType(), defaultValueAsString);
if(!propertyAnnotation.regexpr().isEmpty()) {
this.regexp = propertyAnnotation.regexpr();
}else {
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("^(");
@ -126,6 +111,7 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
if(Version.class.isAssignableFrom(clz)){
this.regexp = Version.VERSION_REGEX;
}
}
}
@ -135,89 +121,48 @@ 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;
}
@Override
public String getPropertyType() {
public String getType() {
return propertyTypeName.toString();
}
@JsonSetter(value = PropertyDefinition.PROPERTY_TYPE_PROPERTY)
public void setPropertyType(String type) {
@JsonSetter(value = PropertyDefinition.TYPE_PROPERTY)
public void setType(String type) {
this.propertyTypeName = new PropertyTypeName(type);
}
@ -226,160 +171,34 @@ public final class PropertyDefinitionImpl implements PropertyDefinition {
return propertyTypeName;
}
@Override
public Object getDefaultValue() {
return defaultValue;
}
@Override
public void setDefaultValue(Object defaultValue) {
this.defaultValue = defaultValue;
}
@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=" + propertyTypeName.toString() + "]";
}
@Override
public int hashCode() {
return Objects.hash(name, description, mandatory, readonly, notnull, max, min, regexp, propertyTypeName.toString(), defaultValue);
return Objects.hash(description, mandatory, max, min, name, notnull, propertyTypeName.toString(), readonly, regexp);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
if (this == obj)
return true;
}
if (obj == null) {
if (obj == null)
return false;
}
if (getClass() != obj.getClass()) {
if (getClass() != obj.getClass())
return false;
}
PropertyDefinitionImpl other = (PropertyDefinitionImpl) obj;
return Objects.equals(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);
return Objects.equals(description, other.description) && mandatory == other.mandatory
&& Objects.equals(max, other.max) && Objects.equals(min, other.min) && Objects.equals(name, other.name)
&& notnull == other.notnull && Objects.equals(propertyTypeName.toString(), other.propertyTypeName.toString())
&& readonly == other.readonly && Objects.equals(regexp, other.regexp);
}
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());
}
}

View File

@ -1,6 +1,5 @@
package org.gcube.informationsystem.types.impl.properties;
import java.io.StringWriter;
import java.util.HashSet;
import java.util.Set;
@ -9,7 +8,6 @@ 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;
@ -19,8 +17,8 @@ import org.gcube.informationsystem.types.reference.properties.PropertyType;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value = PropertyType.NAME)
public final class PropertyTypeImpl extends TypeImpl
implements PropertyType {
public final class PropertyTypeImpl<P extends PropertyElement> extends TypeImpl
implements PropertyType<P> {
/**
* Generated Serial Version UID
@ -43,9 +41,9 @@ public final class PropertyTypeImpl extends TypeImpl
super();
}
public PropertyTypeImpl(Class<? extends PropertyElement> clz) {
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);
@ -74,21 +72,4 @@ public final class PropertyTypeImpl extends TypeImpl
return AccessType.PROPERTY;
}
@Override
public String toString(){
StringWriter stringWriter = new StringWriter();
try {
ElementMapper.marshal(this, stringWriter);
return stringWriter.toString();
}catch(Exception e){
try {
ElementMapper.marshal(this.metadata, stringWriter);
return stringWriter.toString();
} catch(Exception e1){
return super.toString();
}
}
}
}

View File

@ -19,7 +19,7 @@ import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=ConsistsOfType.NAME)
public final class ConsistsOfTypeImpl extends RelationTypeImpl<ResourceType, FacetType> implements ConsistsOfType {
public class ConsistsOfTypeImpl extends RelationTypeImpl<ResourceType, FacetType> implements ConsistsOfType {
/**
* Generated Serial Version UID
@ -33,7 +33,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);

View File

@ -16,7 +16,7 @@ import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=IsRelatedToType.NAME)
public final class IsRelatedToTypeImpl extends RelationTypeImpl<ResourceType, ResourceType> implements IsRelatedToType {
public class IsRelatedToTypeImpl extends RelationTypeImpl<ResourceType, ResourceType> implements IsRelatedToType {
/**
* Generated Serial Version UID
@ -30,7 +30,7 @@ public final class IsRelatedToTypeImpl extends RelationTypeImpl<ResourceType, Re
public IsRelatedToTypeImpl(Class<? extends IsRelatedTo<? extends Resource, ? extends Resource>> clz) {
super(clz);
this.extendedTypes = retrieveSuperClasses(clz, IsRelatedTo.class, Relation.NAME);
this.superClasses = retrieveSuperClasses(clz, IsRelatedTo.class, Relation.NAME);
this.properties = retrieveListOfProperties(clz);

View File

@ -1,6 +1,5 @@
package org.gcube.informationsystem.types.impl.relations;
import java.io.StringWriter;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@ -14,7 +13,6 @@ import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.types.impl.TypeImpl;
import org.gcube.informationsystem.types.impl.entities.EntityTypeImpl;
import org.gcube.informationsystem.types.reference.entities.EntityType;
@ -58,13 +56,13 @@ public class RelationTypeImpl<S extends EntityType, T extends EntityType>
if(RelationType.class.isAssignableFrom(clz)) {
@SuppressWarnings({"unchecked"})
Class<RelationType<?,?>> c = (Class<RelationType<?,?>>) clz;
this.extendedTypes = retrieveSuperClasses(c, RelationType.class, RelationElement.NAME);
this.superClasses = retrieveSuperClasses(c, RelationType.class, RelationElement.NAME);
} else if(IsParentOf.class.isAssignableFrom(clz)) {
@SuppressWarnings("unchecked")
Class<? extends IsParentOf> c = (Class<? extends IsParentOf>) clz;
this.extendedTypes = retrieveSuperClasses(c, IsParentOf.class, RelationElement.NAME);
this.superClasses = retrieveSuperClasses(c, IsParentOf.class, RelationElement.NAME);
} else if(RelationElement.class.isAssignableFrom(clz)) {
this.extendedTypes = retrieveSuperClasses(clz, RelationElement.class, null);
this.superClasses = retrieveSuperClasses(clz, RelationElement.class, null);
} else {
throw new RuntimeException("Type Hierachy Error");
}
@ -159,19 +157,4 @@ public class RelationTypeImpl<S extends EntityType, T extends EntityType>
return AccessType.RELATION;
}
@Override
public String toString(){
StringWriter stringWriter = new StringWriter();
try {
ElementMapper.marshal(this, stringWriter);
return stringWriter.toString();
}catch(Exception e){
try {
ElementMapper.marshal(this.metadata, stringWriter);
return stringWriter.toString();
} catch(Exception e1){
return super.toString();
}
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,14 +2,10 @@ package org.gcube.informationsystem.types.reference.properties;
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.gcube.com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.gcube.informationsystem.base.reference.Attribute;
import org.gcube.informationsystem.base.reference.AttributeDefinition;
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
import org.gcube.informationsystem.types.annotations.Final;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.types.impl.properties.PropertyDefinitionImpl;
import org.gcube.informationsystem.types.reference.Change;
import org.gcube.informationsystem.types.reference.Changelog;
import org.gcube.informationsystem.types.reference.TypeMetadata;
import org.gcube.informationsystem.utils.Version;
@ -18,45 +14,47 @@ import org.gcube.informationsystem.utils.Version;
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(as = PropertyDefinitionImpl.class)
@TypeMetadata(name = PropertyDefinition.NAME, description = "This type provides information for the definition of any properties", version = PropertyDefinition.VERSION)
@Changelog ({
@Change(version = PropertyDefinition.VERSION, description = "The type comply with {@link AttributeDefinition} which add 'defaultValue'"),
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
})
@Final
public interface PropertyDefinition extends PropertyElement, Comparable<PropertyDefinition>, AttributeDefinition {
@TypeMetadata(name = PropertyDefinition.NAME, description = "This class provides information for the definition of any properties", version = Version.MINIMAL_VERSION_STRING)
@Change(version = Version.MINIMAL_VERSION_STRING, description = Version.MINIMAL_VERSION_DESCRIPTION)
public interface PropertyDefinition extends PropertyElement {
public static final String NAME = "PropertyDefinition"; // PropertyDefinition.class.getSimpleName();
public static final String VERSION = "1.1.0";
@ISProperty(name = Attribute.NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
public static final String NAME_PROPERTY = "name";
public static final String DESCRIPTION_PROPERTY = "description";
public static final String MANDATORY_PROPERTY = "mandatory";
public static final String READ_ONLY_PROPERTY = "readonly";
public static final String NOT_NULL_PROPERTY = "notnull";
public static final String MAX_PROPERTY = "max";
public static final String MIN_PROPERTY = "min";
public static final String REGEX_PROPERTY = "regexp";
public static final String TYPE_PROPERTY = "type";
@ISProperty(name = NAME_PROPERTY, readonly = true, mandatory = true, nullable = false)
public String getName();
@ISProperty(name = Attribute.DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ISProperty(name = DESCRIPTION_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getDescription();
@ISProperty(name = AttributeDefinition.MANDATORY_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue = "false")
@ISProperty(name = MANDATORY_PROPERTY, readonly = false, mandatory = true, nullable = false)
public boolean isMandatory();
@ISProperty(name = AttributeDefinition.READ_ONLY_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue = "false")
@ISProperty(name = READ_ONLY_PROPERTY, readonly = false, mandatory = true, nullable = false)
public boolean isReadonly();
@ISProperty(name = AttributeDefinition.NOT_NULL_PROPERTY, readonly = false, mandatory = true, nullable = false, defaultValue = "false")
@ISProperty(name = NOT_NULL_PROPERTY, readonly = false, mandatory = true, nullable = false)
public boolean isNotnull();
@ISProperty(name = Attribute.MAX_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ISProperty(name = MAX_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Integer getMax();
@ISProperty(name = Attribute.MIN_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ISProperty(name = MIN_PROPERTY, readonly = false, mandatory = true, nullable = false)
public Integer getMin();
@ISProperty(name = Attribute.REGEX_PROPERTY, readonly = false, mandatory = true, nullable = false)
@ISProperty(name = 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();
@ISProperty(name = TYPE_PROPERTY, readonly = false, mandatory = true, nullable = false)
public String getType();
}

View File

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

View File

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

View File

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

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