Creating branch to test maven shadow plugin

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/information-system-model@178663 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2019-03-22 14:18:23 +00:00
parent e5921c82cc
commit cbcdd2c122
108 changed files with 3940 additions and 1215 deletions

View File

@ -22,7 +22,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>

View File

@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="target">
<CLASSES>
<root url="jar://$PROJECT_DIR$/target/information-system-model-2.1.0-SNAPSHOT-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/target/information-system-model-2.1.0-SNAPSHOT.jar!/" />
<root url="jar://$PROJECT_DIR$/target/information-system-model-2.1.0-SNAPSHOT-javadoc.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

9
.idea/modules.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/src/main/main.iml" filepath="$PROJECT_DIR$/src/main/main.iml" />
<module fileurl="file://$PROJECT_DIR$/src/test/test.iml" filepath="$PROJECT_DIR$/src/test/test.iml" />
</modules>
</component>
</project>

191
.idea/workspace.xml Normal file
View File

@ -0,0 +1,191 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="a729638b-8dc9-4324-bc9f-3e5d9ffebbc2" name="Default Changelist" comment="" />
<ignored path="$PROJECT_DIR$/out/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FavoritesManager">
<favorites_list name="information-system-model" />
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="2180" />
<option name="y" value="100" />
<option name="width" value="1400" />
<option name="height" value="1000" />
</component>
<component name="ProjectView">
<navigator currentView="PackagesPane" proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane" />
<pane id="PackagesPane" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="project.structure.last.edited" value="Project" />
<property name="project.structure.proportion" value="0.15" />
<property name="project.structure.side.proportion" value="0.0" />
<property name="settings.editor.selected.configurable" value="project.propCompiler" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="a729638b-8dc9-4324-bc9f-3e5d9ffebbc2" name="Default Changelist" comment="" />
<created>1548929804583</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1548929804583</updated>
</task>
<servers />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
<is-autoscroll-to-source value="true" />
</todo-panel>
<todo-panel id="all">
<are-packages-shown value="true" />
<is-autoscroll-to-source value="true" />
</todo-panel>
</component>
<component name="ToolWindowManager">
<frame x="1971" y="25" width="1869" height="1175" extended-state="6" />
<layout>
<window_info active="true" id="Favorites" sideWeight="0.50071126" side_tool="true" visible="true" weight="0.18540867" />
<window_info id="Image Layers" />
<window_info id="Designer" />
<window_info id="UI Designer" />
<window_info id="Capture Tool" />
<window_info id="Learn" weight="0.32967636" />
<window_info content_ui="combo" id="Project" order="0" sideWeight="0.49928877" visible="true" weight="0.18540867" />
<window_info id="Structure" order="1" sideWeight="0.50071126" side_tool="true" weight="0.18540867" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Terminal" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Messages" visible="true" weight="0.32919848" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" weight="0.32919848" />
<window_info anchor="right" id="Palette" />
<window_info anchor="right" id="Theme Preview" />
<window_info anchor="right" id="Maven" />
<window_info anchor="right" id="Capture Analysis" />
<window_info anchor="right" id="Palette&#9;" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
</component>
<component name="masterDetails">
<states>
<state key="ArtifactsStructureConfigurable.UI">
<settings>
<artifact-editor />
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="FacetStructureConfigurable.UI">
<settings>
<last-edited>No facets are configured</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="GlobalLibrariesConfigurable.UI">
<settings>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="JdkListConfigurable.UI">
<settings>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ModuleStructureConfigurable.UI">
<settings>
<last-edited>main</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
<option value="0.6" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ProjectJDKs.UI">
<settings>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ProjectLibrariesConfigurable.UI">
<settings>
<last-edited>target</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>

View File

@ -5,11 +5,21 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
@ -17,7 +27,10 @@
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

View File

@ -1,6 +0,0 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -1,5 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -1,4 +0,0 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -21,6 +21,8 @@ Authors
--------------------------------------------------
* Luca Frosini (luca.frosini-AT-isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy).
* Lucio Lelii (lucio.lelii-AT-isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy).
Maintainers
-----------
@ -42,14 +44,14 @@ Installation
--------------------------------------------------
Installation documentation is available on-line in the gCube Wiki:
${gcube.wikiRoot}/InformationSystem
${gcube.wikiRoot}/Facet_Based_Resource_Model
Documentation
--------------------------------------------------
Documentation is available on-line in the gCube Wiki:
${gcube.wikiRoot}/InformationSystem
${gcube.wikiRoot}/Facet_Based_Resource_Model
Support

View File

@ -1,5 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<ReleaseNotes>
<Changeset component="org.gcube.information-system.gcube-resources.1-0-0" date="${buildDate}">
<Changeset component="org.gcube.information-system.information-system-model.2-1-0" date="${buildDate}">
<Change>Renamed Embedded to Property #13274</Change>
<Change>Renamed packages with name ending in 'embedded' to end with 'properties' #13274</Change>
<Change>Removed some Property types which have been moved in gCube Model</Change>
<Change>Added support For Encrypted Values #12812</Change>
</Changeset>
<Changeset component="org.gcube.information-system.information-system-model.2-0-0" date="2018-11-20">
<Change>Added missing null checks when adding parent context in ContextImpl class</Change>
<Change>Changed model packages</Change>
<Change>Added RegistrationProvider which is used with ServiceLoader to dinamycally discover models</Change>
</Changeset>
<Changeset component="org.gcube.information-system.information-system-model.1-7-0" date="2018-02-15">
<Change>Added possibility to marshal list and array of ISManageable objects #10796</Change>
</Changeset>
<Changeset component="org.gcube.information-system.information-system-model.1-6-0" date="2017-12-20">
<Change>Changed pom.xml to use new make-servicearchive directive #10158</Change>
<Change>Added modifiedBy property in Header #9999</Change>
<Change>Changed the way to marshall and unmarshall Context with parent and children #10216</Change>
<Change>Improved IS Entity/Relation scanning to support multiple inheritance #5706</Change>
</Changeset>
<Changeset component="org.gcube.information-system.information-system-model.1-5-0" date="2017-07-25">
<Change>Refactored getTypeByClass() method</Change>
</Changeset>
<Changeset component="org.gcube.information-system.information-system-model.1-4-0" date="2017-06-07">
<Change>Defined a custom pattern for DateTimeFormat to support timezone.</Change>
<Change>Added convenient methods to get desired facets or relations specifing class type</Change>
<Change>Change the way to serialize Source resource which was ignored before. Now only the header of the Soruce resource is included which is enough to identify it. This enable the possibility to create a Relation togheter with the target entity</Change>
</Changeset>
<Changeset component="org.gcube.information-system.information-system-model.1-3-0" date="2017-03-16">
<Change>Added deserialization support for unknown types with polymorphism support</Change>
<Change>Improved support for json serilization and deserialization</Change>
<Change>Added Propagation Constraint Concept</Change>
</Changeset>
<Changeset component="org.gcube.information-system.information-system-model.1-2-0" date="2016-12-16">
<Change>Added regex support in schema definition</Change>
<Change>Improved support for json serilization and deserialization</Change>
</Changeset>
<Changeset component="org.gcube.information-system.information-system-model.1-1-0" date="2016-11-03">
<Change>Reorganized package and renamed relations to be compliant with welle known practice</Change>
<Change>Added Utility for json serilization and deserialization</Change>
<Change>Added Jackson annotation to support json serilization and deserialization</Change>
</Changeset>
<Changeset component="org.gcube.information-system.information-system-model.1-0-0" date="2016-07-27">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

View File

@ -1,31 +0,0 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>changelog.xml</include>
<include>profile.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Resource>
<ID />
<Type>Service</Type>
@ -9,6 +10,7 @@
<Version>1.0.0</Version>
<Packages>
<Software>
<Description>${description}</Description>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
@ -16,11 +18,11 @@
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Type>Library</Type>
<Files>
<File>${build.finalName}.jar</File>
<File>${build.finalName}.${project.packaging}</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

60
pom.xml
View File

@ -6,9 +6,10 @@
<artifactId>maven-parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>org.gcube.information-system</groupId>
<artifactId>information-system-model</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<name>Information System Model</name>
<description>Information System Model</description>
<packaging>jar</packaging>
@ -17,7 +18,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<distroDirectory>${project.basedir}/distro</distroDirectory>
<serviceClass>InformationSystem</serviceClass>
<jackson.version>2.2.3</jackson.version>
</properties>
<scm>
@ -26,31 +26,58 @@
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/${project.artifactId}</url>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.information-system</groupId>
<artifactId>information-system-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
<scope>provided</scope>
</dependency>
<!-- Test Dependency -->
<!-- Test Dependencies -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -63,31 +90,20 @@
<version>1.0.13</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
<id>make-servicearchive</id>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,38 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.impl.embedded;
import org.gcube.informationsystem.model.embedded.AccessPolicy;
import org.gcube.informationsystem.model.embedded.ValueSchema;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public class AccessPolicyImpl implements AccessPolicy {
protected ValueSchema policy;
protected String note;
@Override
public ValueSchema getPolicy() {
return this.policy;
}
@Override
public void setPolicy(ValueSchema policy) {
this.policy = policy;
}
@Override
public String getNote() {
return this.note;
}
@Override
public void setNote(String note) {
this.note = note;
}
}

View File

@ -1,40 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.impl.embedded;
import org.gcube.informationsystem.model.embedded.AccessPolicy;
import org.gcube.informationsystem.model.embedded.RelationProperty;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class RelationPropertyImpl implements RelationProperty {
protected ReferentiaIntegrity referentiaIntegrity;
protected AccessPolicy accessPolicy;
@Override
public ReferentiaIntegrity getReferentialIntegrity() {
return this.referentiaIntegrity;
}
@Override
public void setReferentialIntegrity(ReferentiaIntegrity referentialIntegrity) {
this.referentiaIntegrity = referentialIntegrity;
}
@Override
public AccessPolicy getPolicy() {
return this.accessPolicy;
}
@Override
public void setPolicy(AccessPolicy accessPolicy) {
this.accessPolicy = accessPolicy;
}
}

View File

@ -1,39 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.impl.embedded;
import java.net.URI;
import org.gcube.informationsystem.model.embedded.ValueSchema;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public class ValueSchemaImpl implements ValueSchema {
protected String value;
protected URI schema;
@Override
public String getValue() {
return this.value;
}
@Override
public void setValue(String value) {
this.value = value;
}
@Override
public URI getSchema() {
return this.schema;
}
@Override
public void setSchema(URI schema) {
this.schema = schema;
}
}

View File

@ -1,27 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.impl.entity;
import org.gcube.informationsystem.model.entity.Context;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class ContextImpl extends EntityImpl implements Context {
protected String name;
@Override
public String getName() {
return this.name;
}
@Override
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,25 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.impl.entity;
import org.gcube.informationsystem.model.embedded.Header;
import org.gcube.informationsystem.model.entity.Entity;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public abstract class EntityImpl implements Entity {
protected Header header;
protected EntityImpl(){
this.header = new HeaderImpl();
}
@Override
public Header getHeader() {
return this.header;
}
}

View File

@ -1,14 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.impl.entity;
import org.gcube.informationsystem.model.entity.Facet;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public abstract class FacetImpl extends EntityImpl implements Facet {
}

View File

@ -1,60 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.impl.entity;
import java.util.UUID;
import org.gcube.informationsystem.model.embedded.Header;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class HeaderImpl implements Header {
protected UUID uuid;
protected String creator;
protected Long creationTime;
protected Long lastUpdateTime;
@Override
public UUID getUUID() {
return this.uuid;
}
protected void setUUID(UUID uuid){
this.uuid = uuid;
}
@Override
public String getCreator() {
return this.creator;
}
protected void setCreator(String creator){
this.creator = creator;
}
@Override
public Long getCreationTime() {
return creationTime;
}
protected void setCreationTime(Long creationTime){
this.creationTime = creationTime;
}
@Override
public Long getLastUpdateTime() {
return lastUpdateTime;
}
protected void setLastUpdateTime(Long lastUpdateTime){
this.lastUpdateTime = lastUpdateTime;
}
}

View File

@ -1,74 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.impl.entity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.informationsystem.model.embedded.RelationProperty;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public abstract class ResourceImpl extends EntityImpl implements Resource {
protected Map<Facet, RelationProperty> addedFacets;
protected Map<String, RelationProperty> attachedFacets;
protected List<Facet> detachedFacets;
protected Map<Resource, RelationProperty> attachedResourceProfiles;
protected List<Resource> detachedResourceProfiles;
/**
* @param name
* @param description
* @param version
*/
protected ResourceImpl() {
addedFacets = new HashMap<Facet, RelationProperty>();
attachedFacets = new HashMap<String, RelationProperty>();
detachedFacets = new ArrayList<>();
}
@Override
public void addFacet(Facet facet) {
addedFacets.put(facet, null);
}
@Override
public void addFacet(Facet facet, RelationProperty relationProperty) {
addedFacets.put(facet, relationProperty);
}
@Override
public void attachFacet(String uuid) {
attachedFacets.put(uuid, null);
}
@Override
public void attachFacet(String uuid, RelationProperty relationProperty) {
attachedFacets.put(uuid, relationProperty);
}
@Override
public void attachResource(String uuid) {
}
@Override
public void attachResource(String uuid,
RelationProperty relationProperty) {
}
}

View File

@ -1,28 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.impl.relation;
import org.gcube.informationsystem.model.embedded.RelationProperty;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.relation.ConsistOf;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class ConsistOfImpl<Out extends Resource, In extends Facet> extends
RelationImpl<Out, In> implements ConsistOf<Out, In> {
/**
* @param source
* @param target
* @param relationProperty
*/
public ConsistOfImpl(Out source, In target,
RelationProperty relationProperty) {
super(source, target, relationProperty);
}
}

View File

@ -1,27 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.impl.relation;
import org.gcube.informationsystem.model.embedded.RelationProperty;
import org.gcube.informationsystem.model.entity.Context;
import org.gcube.informationsystem.model.relation.ParentOf;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class ParentOfImpl<Out extends Context, In extends Context> extends
RelationImpl<Out, In> implements ParentOf<Out, In> {
/**
* @param source
* @param target
* @param relationProperty
*/
public ParentOfImpl(Out source, In target,
RelationProperty relationProperty) {
super(source, target, relationProperty);
}
}

View File

@ -1,26 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.impl.relation;
import org.gcube.informationsystem.model.embedded.RelationProperty;
import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.relation.RelatedTo;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public class RelatedToImpl<Out extends Resource, In extends Resource> extends
RelationImpl<Out, In> implements RelatedTo<Out, In> {
/**
* @param source
* @param target
* @param relationProperty
*/
public RelatedToImpl(Out source, In target,
RelationProperty relationProperty) {
super(source, target, relationProperty);
}
}

View File

@ -1,50 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.impl.relation;
import org.gcube.informationsystem.model.embedded.Header;
import org.gcube.informationsystem.model.embedded.RelationProperty;
import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.relation.Relation;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public class RelationImpl<Out extends Entity, In extends Entity> implements Relation<Out, In> {
protected Header header;
protected Out source;
protected In target;
protected RelationProperty relationProperty;
protected RelationImpl(Out source, In target, RelationProperty relationProperty){
this.source = source;
this.target = target;
this.relationProperty = relationProperty;
}
@Override
public Header getHeader() {
return header;
}
@Override
public Out getSource() {
return null;
}
@Override
public In getTarget() {
return null;
}
@Override
public RelationProperty getRelationProperty() {
return this.relationProperty;
}
}

View File

@ -1,81 +0,0 @@
package org.gcube.informationsystem.impl.utils;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public class Entities {
protected static final ObjectMapper mapper = new ObjectMapper();
/**
* Write the serialization of a given resource to a given
* {@link OutputStream} .
*
* @param resource the resource
* @param stream the stream in input
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
public static <T extends OutputStream> T marshal(Object resource, T stream)
throws JsonGenerationException, JsonMappingException, IOException {
mapper.writeValue(stream, resource);
return stream;
}
/**
* Write the serialization of a given resource to a given {@link Writer} .
* @param resource the resource
* @param writer the writer in input
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
public static <T extends Writer> T marshal(Object resource, T writer)
throws JsonGenerationException, JsonMappingException, IOException {
mapper.writeValue(writer, resource);
return writer;
}
/**
* Creates a resource of given class from its serialization in a given
* {@link Reader}.
* @param resourceClass the class of the resource
* @param reader the reader
* @return the resource
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
*/
public static <T> T unmarshal(Class<T> resourceClass, Reader reader)
throws JsonParseException, JsonMappingException, IOException {
return mapper.readValue(reader, resourceClass);
}
/**
* Creates a resource of given class from its serialization in a given
* {@link InputStream}.
* @param resourceClass the class of the resource
* @param stream the stream
* @return the resource
* @throws IOException
* @throws JsonMappingException
* @throws JsonParseException
*/
public static <T> T unmarshal(Class<T> resourceClass, InputStream stream)
throws JsonParseException, JsonMappingException, IOException {
return mapper.readValue(stream, resourceClass);
}
}

View File

@ -1,13 +0,0 @@
package org.gcube.informationsystem.model.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Abstract {
}

View File

@ -1,21 +0,0 @@
package org.gcube.informationsystem.model.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ISProperty {
String name() default "";
String description() default "";
boolean mandatory() default false;
boolean readonly() default false;
boolean nullable() default true;
int min() default -1;
int max() default -1;
String regexpr() default "";
}

View File

@ -1,21 +0,0 @@
package org.gcube.informationsystem.model.embedded;
import org.gcube.informationsystem.model.annotations.ISProperty;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public interface AccessPolicy extends Embedded {
public static final String NAME = AccessPolicy.class.getSimpleName();
@ISProperty
public ValueSchema getPolicy();
public void setPolicy(ValueSchema policy);
@ISProperty
public String getNote();
public void setNote(String note);
}

View File

@ -1,14 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.embedded;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public interface Embedded {
public static final String NAME = Embedded.class.getSimpleName();
}

View File

@ -1,42 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.embedded;
import java.util.UUID;
import org.gcube.informationsystem.model.annotations.ISProperty;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* https://redmine.d4science.org/projects/bluebridge/wiki/Facets#Facet-Header
*/
public interface Header extends Embedded {
public static final String NAME = Header.class.getSimpleName();
/**
* Used to set Creator when the user is not known
*/
public static final String UNKNOWN_USER = "UNKNOWN_USER";
public static final String UUID_PROPERTY = "uuid";
public static final String CREATOR_PROPERTY = "creator";
public static final String CREATION_TIME_PROPERTY = "creationTime";
public static final String LAST_UPDATE_TIME_PROPERTY = "lastUpdateTime";
@ISProperty(name=UUID_PROPERTY, readonly=true, mandatory=true, nullable=false)
public UUID getUUID();
@ISProperty(name=CREATOR_PROPERTY, readonly=true, mandatory=true, nullable=false)
public String getCreator();
@ISProperty(name=CREATION_TIME_PROPERTY, readonly=true, mandatory=true, nullable=false)
public Long getCreationTime();
@ISProperty(name=LAST_UPDATE_TIME_PROPERTY, mandatory=true, nullable=false)
public Long getLastUpdateTime();
}

View File

@ -1,50 +0,0 @@
package org.gcube.informationsystem.model.embedded;
import org.gcube.informationsystem.model.annotations.ISProperty;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public interface RelationProperty extends Embedded {
public static final String NAME = RelationProperty.class.getSimpleName();
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* The referential integrity value have their meaning taking in account the
* Edge direction. So that is the action to be made when an action occurs on
* source Vertex.
*/
public enum ReferentiaIntegrity {
/**
* When the source Vertex is deleted also the target Vertex is deleted if
* there are no other incoming edge.
*/
onDeleteCascadeWhenOrphan,
/**
* When the source Vertex is deleted also the target Vertex is always
* deleted
*/
onDeleteCascade,
/**
* When the source Vertex is deleted also the target Vertex is keep.
* This is the standard behavior also if no integrity is declared.
*/
onDeleteKeep
}
@ISProperty
public ReferentiaIntegrity getReferentialIntegrity();
public void setReferentialIntegrity(ReferentiaIntegrity referentialIntegrity);
@ISProperty
public AccessPolicy getPolicy();
public void setPolicy(AccessPolicy accessPolicy);
}

View File

@ -1,29 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.embedded;
import java.net.URI;
import org.gcube.informationsystem.model.annotations.ISProperty;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* Base Interface for all type described by a value and a schema retrieved
* from a URI.
*/
public interface ValueSchema extends Embedded {
public static final String NAME = ValueSchema.class.getSimpleName();
@ISProperty
public String getValue();
public void setValue(String value);
@ISProperty
public URI getSchema();
public void setSchema(URI schema);
}

View File

@ -1,23 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.entity;
import org.gcube.informationsystem.model.annotations.ISProperty;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public interface Context extends Entity {
public static final String NAME = Context.class.getSimpleName();
public static final String NAME_PROPERTY = "name";
@ISProperty(name=NAME_PROPERTY, mandatory=true, nullable=false)
public String getName();
public void setName(String name);
}

View File

@ -1,24 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.entity;
import org.gcube.informationsystem.model.annotations.Abstract;
import org.gcube.informationsystem.model.annotations.ISProperty;
import org.gcube.informationsystem.model.embedded.Header;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
@Abstract
public interface Entity {
public static final String NAME = Entity.class.getSimpleName();
public static final String HEADER_PROPERTY = "header";
@ISProperty(name=HEADER_PROPERTY, mandatory=true, nullable=false)
public Header getHeader();
}

View File

@ -1,17 +0,0 @@
package org.gcube.informationsystem.model.entity;
import org.gcube.informationsystem.model.annotations.Abstract;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* https://redmine.d4science.org/projects/bluebridge/wiki/Facets
*/
@Abstract
public abstract interface Facet extends Entity {
public static final String NAME = Facet.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Facet";
public static final String VERSION = "1.0.0";
}

View File

@ -1,35 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.entity;
import org.gcube.informationsystem.model.annotations.Abstract;
import org.gcube.informationsystem.model.embedded.RelationProperty;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
@Abstract
public interface Resource extends Entity {
public static final String NAME = Resource.class.getSimpleName();
public void addFacet(Facet facet);
public void addFacet(Facet facet, RelationProperty relationProperty);
public void attachFacet(String uuid);
public void attachFacet(String uuid, RelationProperty relationProperty);
public void attachResource(String uuid);
public void attachResource(String uuid, RelationProperty relationProperty);
}

View File

@ -0,0 +1,32 @@
/**
*
*/
package org.gcube.informationsystem.model.impl;
import org.gcube.informationsystem.model.reference.ER;
import org.gcube.informationsystem.model.reference.properties.Header;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=ER.NAME)
public abstract class ERImpl extends ISManageableImpl implements ER {
protected Header header;
public ERImpl(){
super();
}
@Override
public Header getHeader() {
return header;
}
@Override
public void setHeader(Header header){
this.header = header;
}
}

View File

@ -0,0 +1,17 @@
/**
*
*/
package org.gcube.informationsystem.model.impl;
import org.gcube.informationsystem.model.reference.ISManageable;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class ISManageableImpl implements ISManageable {
public ISManageableImpl(){
}
}

View File

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

View File

@ -0,0 +1,30 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.entities;
import java.util.UUID;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class DummyFacet extends FacetImpl implements Facet {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -1527529288324120341L;
public DummyFacet(UUID uuid) {
super();
this.header = new HeaderImpl(uuid);
}
public DummyFacet(){
super();
}
}

View File

@ -0,0 +1,30 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.entities;
import java.util.UUID;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.reference.entities.Resource;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class DummyResource extends ResourceImpl implements Resource {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -8522083786087905215L;
public DummyResource(UUID uuid){
super();
this.header = new HeaderImpl(uuid);
}
public DummyResource(){
super();
}
}

View File

@ -0,0 +1,46 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.entities;
import java.io.StringWriter;
import org.gcube.informationsystem.model.impl.ERImpl;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.utils.ISMapper;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=Entity.NAME)
public abstract class EntityImpl extends ERImpl implements Entity {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -4488771434017342703L;
protected EntityImpl(){
super();
this.header = null;
}
@Override
public String toString(){
StringWriter stringWriter = new StringWriter();
try {
ISMapper.marshal(this, stringWriter);
return stringWriter.toString();
}catch(Exception e){
try {
ISMapper.marshal(this.header, stringWriter);
return stringWriter.toString();
} catch(Exception e1){
return super.toString();
}
}
}
}

View File

@ -0,0 +1,100 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.entities;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.gcube.informationsystem.model.reference.ISManageable;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.utils.ISMapper;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=Facet.NAME)
public abstract class FacetImpl extends EntityImpl implements Facet {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 6075565284892615813L;
@JsonIgnore
protected Map<String, Object> additionalProperties;
@JsonIgnore
/**
* Used to allow to have an additional property starting with '_' or '@'
*/
protected final Set<String> allowedAdditionalKeys;
protected FacetImpl(){
super();
this.additionalProperties = new HashMap<>();
this.allowedAdditionalKeys = new HashSet<>();
this.allowedAdditionalKeys.add(SUPERCLASSES_PROPERTY);
}
@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(ISManageable.CLASS_PROPERTY)) {
String reserialized = ISMapper.getObjectMapper().writeValueAsString(map);
Property property = ISMapper.unmarshal(Property.class, reserialized);
value = property;
}
}
}catch (Throwable e) {
e.getMessage();
// Any type of error/exception must be catched
}
/* END of fix to properly deserialize Property types*/
this.additionalProperties.put(key, value);
}
public void addAllowedAdditionalKey(String allowedAdditionalKey){
this.allowedAdditionalKeys.add(allowedAdditionalKey);
}
}

View File

@ -0,0 +1,301 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.entities;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.impl.relations.IsRelatedToImpl;
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.IsIdentifiedBy;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=Resource.NAME)
public abstract class ResourceImpl extends EntityImpl implements Resource {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -3117918737458706846L;
private static Logger logger = LoggerFactory.getLogger(ResourceImpl.class);
protected List<ConsistsOf<? extends Resource, ? extends Facet>> consistsOfList;
protected List<IsRelatedTo<? extends Resource, ? extends Resource>> isRelatedToList;
/*
private List<Facet> facets;
@SuppressWarnings("rawtypes")
private Map<Class<Relation>, List<Relation>> relationByClass;
@SuppressWarnings("rawtypes")
private Map<Entry<Class<Relation>, Class<Entity>>, List<Relation>> relationByClassAndTarget;
private Map<Class<Entity>, List<Entity>> entityByClass;
@SuppressWarnings("rawtypes")
private Map<Entry<Class<Relation>, Class<Entity>>, List<Entity>> entityByClassAndTarget;
*/
protected ResourceImpl() {
super();
consistsOfList = new ArrayList<>();
isRelatedToList = new ArrayList<>();
/*
facets = new ArrayList<>();
relationByClass = new HashMap<>();
relationByClassAndTarget = new HashMap<>();
entityByClass = new HashMap<>();
entityByClassAndTarget = new HashMap<>();
*/
}
/*
@SuppressWarnings({ "rawtypes"})
private void addRelationByClassAndTarget(Entry<Class<Relation>, Class<Entity>> entry, Relation relation){
List<Relation> relations = relationByClassAndTarget.get(entry);
if(relations==null){
relations = new ArrayList<>();
relationByClassAndTarget.put(entry, relations);
}
relations.add(relation);
addRelationByClass(entry.getKey(), relation);
}
@SuppressWarnings({ "rawtypes"})
private void addRelationByClass(Class<Relation> relationClass, Relation r){
List<Relation> relations = (List<Relation>) relationByClass.get(relationClass);
if(relations==null){
relations = new ArrayList<>();
relationByClass.put(relationClass, relations);
}
relations.add(r);
}
@SuppressWarnings({ "rawtypes"})
private void addEntityByClassAndTarget(Entry<Class<Relation>, Class<Entity>> entry, Entity entity){
List<Entity> entities = entityByClassAndTarget.get(entry);
if(entities==null){
entities = new ArrayList<>();
entityByClassAndTarget.put(entry, entities);
}
entities.add(entity);
addEntityByClass(entry.getValue(), entity);
}
private void addEntityByClass(Class<Entity> entityClass, Entity entity){
List<Entity> entities = entityByClass.get(entityClass);
if(entities==null){
entities = new ArrayList<>();
entityByClass.put(entityClass, entities);
}
entities.add(entity);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private Entry<Class<Relation>, Class<Entity>> getEntry(Class<Relation> realtionClass, Class<Entity> entityClass){
Map<Class<Relation>, Class<Entity>> mapForEntry = new HashMap<>();
mapForEntry.put(realtionClass, entityClass);
return (Entry<Class<Relation>, Class<Entity>>) mapForEntry.entrySet().toArray()[0];
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private void addRelation(Relation relation){
Entity entity = (Entity) relation.getTarget();
Entry<Class<Relation>, Class<Entity>> entry = getEntry((Class<Relation>) relation.getClass(), (Class<Entity>) entity.getClass());
addRelationByClassAndTarget(entry, relation);
addEntityByClassAndTarget(entry, entity);
}
*/
@Override
public void addFacet(UUID uuid) {
Facet facet = new DummyFacet(uuid);
addFacet(facet);
}
@Override
public <F extends Facet > void addFacet(F facet) {
ConsistsOf<Resource, Facet> consistsOf = new ConsistsOfImpl<Resource, Facet>(this, facet, null);
addFacet(consistsOf);
}
@Override
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> void addFacet(C relation) {
if (relation.getSource() != this) {
String message = String.format(
"%s Source %s is not this. %s != %s", ConsistsOf.NAME,
Resource.NAME, relation.getSource().toString(),
this.toString());
logger.error(message);
throw new RuntimeException(message);
}
consistsOfList.add(relation);
/*
addRelation(relation);
facets.add(relation.getTarget());
*/
}
@Override
public void attachResource(UUID uuid) {
Resource resource = new DummyResource(uuid);
attachResource(resource);
}
@Override
public <R extends Resource> void attachResource(R resource) {
IsRelatedTo<Resource, Resource> isRelatedTo = new IsRelatedToImpl<Resource, Resource>(this, resource, null);
attachResource(isRelatedTo);
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void attachResource(IsRelatedTo relation) {
String message = String.format(
"%s Source %s is not this. %s != %s", IsRelatedTo.NAME,
Resource.NAME, relation.getSource(),
this.toString());
if (relation.getSource()==null){
throw new RuntimeException(message);
}
if (relation.getSource().getHeader()!= null &&
relation.getSource().getHeader().getUUID() != null &&
this.header !=null &&
this.header.getUUID() != null &&
relation.getSource().getHeader().getUUID().compareTo(this.header.getUUID())!=0) {
throw new RuntimeException(message);
}
if(relation.getSource()!=this){
relation.setSource(this);
}
isRelatedToList.add(relation);
/*
addRelation(relation);
*/
}
@Override
public List<? extends Facet> getIdentificationFacets() {
List<Facet> identificationFacets = new ArrayList<>();
for(ConsistsOf<? extends Resource, ? extends Facet> consistsOfInstance : consistsOfList){
if (IsIdentifiedBy.class.isAssignableFrom(consistsOfInstance.getClass())) {
identificationFacets.add(consistsOfInstance.getTarget());
}
}
return identificationFacets;
}
@Override
public List<ConsistsOf<? extends Resource, ? extends Facet>> getConsistsOf() {
return consistsOfList;
}
@Override
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> List<C> getConsistsOf(Class<C> clz) {
List<C> list = new ArrayList<>();
for(ConsistsOf<? extends Resource, ? extends Facet> consistsOf : consistsOfList){
if(clz.isInstance(consistsOf)){
@SuppressWarnings("unchecked")
C c = (C) consistsOf;
list.add(c);
}
}
return list;
}
@Override
public List<IsRelatedTo<? extends Resource, ? extends Resource>> getIsRelatedTo() {
return isRelatedToList;
}
@Override
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> List<I> getIsRelatedTo(Class<I> clz) {
List<I> list = new ArrayList<>();
for(IsRelatedTo<? extends Resource, ? extends Resource> isRelatedTo : isRelatedToList){
if(clz.isInstance(isRelatedTo)){
@SuppressWarnings("unchecked")
I i = (I) isRelatedTo;
list.add(i);
}
}
return list;
}
@Override
public List<? extends Facet> getFacets() {
List<Facet> list = new ArrayList<>();
for(ConsistsOf<? extends Resource, ? extends Facet> consistsOf : consistsOfList){
list.add(consistsOf.getTarget());
}
return list;
}
@Override
public <F extends Facet> List<F> getFacets(Class<F> clz) {
List<F> list = new ArrayList<>();
for(ConsistsOf<? extends Resource, ? extends Facet> consistsOf : consistsOfList){
if(clz.isInstance(consistsOf.getTarget())){
@SuppressWarnings("unchecked")
F f = (F) consistsOf.getTarget();
list.add(f);
}
}
return list;
}
@Override
public <F extends Facet, C extends ConsistsOf<? extends Resource, F>> List<C> getConsistsOf(Class<C> clz, Class<F> facetClz) {
List<C> list = new ArrayList<>();
for(ConsistsOf<? extends Resource, ? extends Facet> consistsOf : consistsOfList){
if(clz.isInstance(consistsOf)){
if(facetClz.isInstance(consistsOf.getTarget())){
@SuppressWarnings("unchecked")
C c = (C) consistsOf;
list.add(c);
}
}
}
return list;
}
@Override
public <F extends Facet, C extends ConsistsOf<? extends Resource, F>> List<F> getFacets(Class<C> clz, Class<F> facetClz) {
List<F> list = new ArrayList<>();
for(ConsistsOf<? extends Resource, ? extends Facet> consistsOf : consistsOfList){
if(clz.isInstance(consistsOf)){
if(facetClz.isInstance(consistsOf.getTarget())){
@SuppressWarnings("unchecked")
F f = (F) consistsOf.getTarget();
list.add(f);
}
}
}
return list;
}
}

View File

@ -0,0 +1,23 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.properties;
import org.gcube.informationsystem.model.reference.properties.Property;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class DummyProperty extends PropertyImpl implements Property {
/**
* Generated Serial version UID
*/
private static final long serialVersionUID = 2458531826742344451L;
public DummyProperty(){
super();
}
}

View File

@ -0,0 +1,58 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.properties;
import java.security.Key;
import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value = Encrypted.NAME)
public class EncryptedImpl extends PropertyImpl implements Encrypted {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 7823031209294161865L;
@JsonIgnore
protected String encryptedValue;
public EncryptedImpl() {
super();
}
@Override
public String getEncryptedValue() {
return encryptedValue;
}
@Override
public void setEncryptedValue(String encryptedValue) {
this.encryptedValue = encryptedValue;
}
public static String encrypt(String value) throws Exception {
return StringEncrypter.getEncrypter().encrypt(value);
}
public static String decrypt(String value) throws Exception {
return StringEncrypter.getEncrypter().decrypt(value);
}
public static String encrypt(String value, Key key) throws Exception {
return StringEncrypter.getEncrypter().encrypt(value, key);
}
public static String decrypt(String value, Key key) throws Exception {
return StringEncrypter.getEncrypter().decrypt(value, key);
}
}

View File

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

View File

@ -0,0 +1,55 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.properties;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=PropagationConstraint.NAME)
public class PropagationConstraintImpl extends PropertyImpl implements PropagationConstraint {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = -4708881022038107688L;
@JsonFormat(shape=JsonFormat.Shape.STRING)
@JsonProperty(value=REMOVE_PROPERTY)
protected RemoveConstraint removeConstraint;
@JsonFormat(shape=JsonFormat.Shape.STRING)
@JsonProperty(value=ADD_PROPERTY)
protected AddConstraint addConstraint;
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;
}
@Override
public void setAddConstraint(AddConstraint addConstraint) {
this.addConstraint = addConstraint;
}
}

View File

@ -0,0 +1,26 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.properties;
import org.gcube.informationsystem.model.impl.ISManageableImpl;
import org.gcube.informationsystem.model.reference.properties.Property;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
@JsonTypeName(value=Property.NAME)
public class PropertyImpl extends ISManageableImpl implements Property {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 1396998430221747445L;
public PropertyImpl() {
super();
}
}

View File

@ -0,0 +1,28 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.relations;
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.relations.ConsistsOf;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=ConsistsOf.NAME)
public class ConsistsOfImpl<Out extends Resource, In extends Facet> extends
RelationImpl<Out, In> implements ConsistsOf<Out, In> {
protected ConsistsOfImpl(){
super();
}
public ConsistsOfImpl(Out source, In target,
PropagationConstraint propagationConstraint) {
super(source, target, propagationConstraint);
}
}

View File

@ -0,0 +1,29 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.relations;
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.relations.ConsistsOf;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=ConsistsOf.NAME)
public class DummyConsistsOf<Out extends Resource, In extends Facet> extends
ConsistsOfImpl<Out, In> implements ConsistsOf<Out, In> {
public DummyConsistsOf(){
super();
}
public DummyConsistsOf(Out source, In target,
PropagationConstraint propagationConstraint) {
super(source, target, propagationConstraint);
}
}

View File

@ -0,0 +1,27 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.relations;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=IsRelatedTo.NAME)
public class DummyIsRelatedTo<Out extends Resource, In extends Resource>
extends IsRelatedToImpl<Out, In> implements IsRelatedTo<Out, In>{
public DummyIsRelatedTo(){
super();
}
public DummyIsRelatedTo(Out source, In target,
PropagationConstraint propagationConstraint) {
super(source, target, propagationConstraint);
}
}

View File

@ -0,0 +1,29 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.relations;
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.relations.IsIdentifiedBy;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=IsIdentifiedBy.NAME)
public class IsIdentifiedByImpl<Out extends Resource, In extends Facet> extends
ConsistsOfImpl<Out, In> implements IsIdentifiedBy<Out, In> {
protected IsIdentifiedByImpl(){
super();
}
public IsIdentifiedByImpl(Out source, In target,
PropagationConstraint propagationConstraint) {
super(source, target, propagationConstraint);
}
}

View File

@ -0,0 +1,28 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.relations;
import org.gcube.informationsystem.model.reference.entities.Context;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.relations.IsParentOf;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=IsParentOf.NAME)
public class IsParentOfImpl<Out extends Context, In extends Context> extends
RelationImpl<Out, In> implements IsParentOf<Out, In> {
protected IsParentOfImpl(){
super();
}
public IsParentOfImpl(Out source, In target,
PropagationConstraint propagationConstraint) {
super(source, target, propagationConstraint);
}
}

View File

@ -0,0 +1,27 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.relations;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value=IsRelatedTo.NAME)
public class IsRelatedToImpl<Out extends Resource, In extends Resource> extends
RelationImpl<Out, In> implements IsRelatedTo<Out, In> {
protected IsRelatedToImpl(){
super();
}
public IsRelatedToImpl(Out source, In target,
PropagationConstraint propagationConstraint) {
super(source, target, propagationConstraint);
}
}

View File

@ -0,0 +1,157 @@
/**
*
*/
package org.gcube.informationsystem.model.impl.relations;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.gcube.informationsystem.model.impl.ERImpl;
import org.gcube.informationsystem.model.reference.ISManageable;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.utils.ISMapper;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonTypeName(value = Relation.NAME)
public abstract class RelationImpl<Out extends Entity, In extends Entity>
extends ERImpl implements Relation<Out, In> {
protected Out source;
protected In target;
protected PropagationConstraint propagationConstraint;
@JsonIgnore
protected Map<String, Object> additionalProperties;
/**
* Used to allow to have an additional property starting with '_' or '@'
*/
protected final Set<String> allowedAdditionalKeys;
protected RelationImpl() {
super();
this.additionalProperties = new HashMap<>();
this.allowedAdditionalKeys = new HashSet<>();
this.allowedAdditionalKeys.add(SUPERCLASSES_PROPERTY);
}
protected RelationImpl(Out source, In target,
PropagationConstraint propagationConstraint) {
this();
this.source = source;
this.target = target;
this.propagationConstraint = propagationConstraint;
}
@Override
public Out getSource() {
return source;
}
@Override
public void setSource(Out source) {
this.source = source;
}
@Override
public In getTarget() {
return target;
}
@Override
public void setTarget(In target) {
this.target = target;
}
@Override
public PropagationConstraint getPropagationConstraint() {
return this.propagationConstraint;
}
@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;
}
if (key.compareTo(PROPAGATION_CONSTRAINT) == 0) {
return;
}
if (key.compareTo(TARGET_PROPERTY) == 0) {
return;
}
if (key.compareTo(SOURCE_PROPERTY) == 0) {
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(ISManageable.CLASS_PROPERTY)) {
String reserialized = ISMapper.getObjectMapper().writeValueAsString(map);
Property property = ISMapper.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);
}
@Override
public String toString() {
StringWriter stringWriter = new StringWriter();
try {
ISMapper.marshal(this, stringWriter);
return stringWriter.toString();
} catch (Exception e) {
try {
ISMapper.marshal(this.header, stringWriter);
return stringWriter.toString();
} catch (Exception e1) {
return super.toString();
}
}
}
}

View File

@ -0,0 +1,123 @@
/**
*
*/
package org.gcube.informationsystem.model.reference;
import java.util.Arrays;
import org.gcube.informationsystem.model.impl.entities.ContextImpl;
import org.gcube.informationsystem.model.impl.entities.DummyFacet;
import org.gcube.informationsystem.model.impl.entities.DummyResource;
import org.gcube.informationsystem.model.impl.entities.EntityImpl;
import org.gcube.informationsystem.model.impl.entities.FacetImpl;
import org.gcube.informationsystem.model.impl.entities.ResourceImpl;
import org.gcube.informationsystem.model.impl.properties.DummyProperty;
import org.gcube.informationsystem.model.impl.properties.PropertyImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.impl.relations.DummyConsistsOf;
import org.gcube.informationsystem.model.impl.relations.DummyIsRelatedTo;
import org.gcube.informationsystem.model.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.model.impl.relations.IsRelatedToImpl;
import org.gcube.informationsystem.model.impl.relations.RelationImpl;
import org.gcube.informationsystem.model.reference.entities.Context;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsParentOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
* Enumerates the basic type names.
*/
public enum AccessType {
PROPERTY(Property.class, Property.NAME, PropertyImpl.class, DummyProperty.class),
CONTEXT(Context.class, Context.NAME, ContextImpl.class, null),
IS_PARENT_OF(IsParentOf.class, IsParentOf.NAME, IsParentOfImpl.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(Relation.class, Relation.NAME, RelationImpl.class, null),
IS_RELATED_TO(IsRelatedTo.class, IsRelatedTo.NAME, IsRelatedToImpl.class, DummyIsRelatedTo.class),
CONSISTS_OF(ConsistsOf.class, ConsistsOf.NAME, ConsistsOfImpl.class, DummyConsistsOf.class);
private static Logger logger = LoggerFactory.getLogger(AccessType.class);
private final Class<? extends ISManageable> clz;
private final Class<? extends ISManageable> implementationClass;
private final Class<? extends ISManageable> dummyImplementationClass;
private final String name;
private final String lowerCaseFirstCharacter;
<ISM extends ISManageable, ISMC extends ISM, ISMD extends ISMC>
AccessType(Class<ISM> clz, String name, Class<ISMC> implementationClass, Class<ISMD> dummyImplementationClass){
this.clz = clz;
this.implementationClass = implementationClass;
this.dummyImplementationClass = dummyImplementationClass;
this.name = name;
this.lowerCaseFirstCharacter = name.substring(0, 1).toLowerCase() + name.substring(1);
}
@SuppressWarnings("unchecked")
public <ISM extends ISManageable> Class<ISM> getTypeClass(){
return (Class<ISM>) clz;
}
@SuppressWarnings("unchecked")
public <ISM extends ISManageable, ISMC extends ISM> Class<ISMC> getImplementationClass() {
return (Class<ISMC>) implementationClass;
}
@SuppressWarnings("unchecked")
public <ISM extends ISManageable, ISMC extends ISM, ISMD extends ISMC> Class<ISMD> getDummyImplementationClass() {
return (Class<ISMD>) dummyImplementationClass;
}
public String getName(){
return name;
}
public String lowerCaseFirstCharacter() {
return lowerCaseFirstCharacter;
}
@Override
public String toString(){
return name;
}
public static AccessType getAccessType(Class<?> clz) {
AccessType ret =null;
AccessType[] accessTypes = AccessType.values();
for (AccessType accessType : accessTypes) {
Class<? extends ISManageable> typeClass = accessType.getTypeClass();
if (typeClass.isAssignableFrom(clz)) {
if(ret==null || ret.getTypeClass().isAssignableFrom(typeClass)){
ret = accessType;
}
}
}
if(ret !=null){
return ret;
}else{
String error = String
.format("The provided class %s does not belong to any of defined AccessTypes %s",
clz.getSimpleName(), Arrays.toString(accessTypes));
logger.trace(error);
throw new RuntimeException(error);
}
}
}

View File

@ -0,0 +1,23 @@
/**
*
*/
package org.gcube.informationsystem.model.reference;
import org.gcube.informationsystem.model.reference.properties.Header;
/**
* @author Luca Frosini (ISTI - CNR)
* Basic Interface for all Entity and Relations
*/
// @JsonDeserialize(as=ERImpl.class) Do not uncomment to manage subclasses
// @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = ER.HEADER_PROPERTY)
public interface ER extends ISManageable {
public static final String NAME = "ER"; //ER.class.getSimpleName();
public static final String HEADER_PROPERTY = "header";
public Header getHeader();
public void setHeader(Header header);
}

View File

@ -0,0 +1,7 @@
package org.gcube.informationsystem.model.reference;
public interface ISConstants {
String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS Z";
}

View File

@ -0,0 +1,23 @@
/**
*
*/
package org.gcube.informationsystem.model.reference;
import org.gcube.informationsystem.types.annotations.Abstract;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Abstract
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = ISManageable.CLASS_PROPERTY)
public interface ISManageable {
public static final String NAME = "ISManageable"; //ISManageable.class.getSimpleName();
public static final String CLASS_PROPERTY = "@class";
public static final String SUPERCLASSES_PROPERTY = "@superClasses";
}

View File

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

View File

@ -0,0 +1,32 @@
/**
*
*/
package org.gcube.informationsystem.model.reference.entities;
import java.io.Serializable;
import org.gcube.informationsystem.model.reference.ER;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.ISProperty;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Basic_Concepts
*/
@Abstract
@JsonIgnoreProperties(ignoreUnknown=true)
//@JsonDeserialize(as=EntityImpl.class) Do not uncomment to manage subclasses
public interface Entity extends ER, Serializable {
public static final String NAME = "Entity"; //Entity.class.getSimpleName();
/* Overriding getHeader method to create Header property in type */
@ISProperty(name=HEADER_PROPERTY, mandatory=true, nullable=false)
@Override
public Header getHeader();
}

View File

@ -0,0 +1,54 @@
package org.gcube.informationsystem.model.reference.entities;
import java.util.Map;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Facets
*/
@Abstract
// @JsonDeserialize(as=FacetImpl.class) Do not uncomment to manage subclasses
public interface Facet extends Entity {
public static final String NAME = "Facet"; //Facet.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Facet";
public static final String VERSION = "1.0.0";
/**
* Return all properties. The returned Map is a copy of
* the internal representation. Any modification to the returned Map MUST
* not affect the object
* @return a Map containing the properties
*/
@JsonAnyGetter
@JsonSerialize(using = AdditionalPropertiesSerializer.class)
public Map<String,Object> getAdditionalProperties();
/**
* Set all properties, replacing existing ones
*/
public void setAdditionalProperties(Map<String,Object> additionalProperties);
/**
* Return the value of the given property.
* @param key the key of the requested property
* @return the value of the given property
*/
public Object getAdditionalProperty(String key);
/**
* Set the value of the given property.
* @param key the key of the requested property
* @param value the value of the given resource property
*/
@JsonAnySetter
public void setAdditionalProperty(String key, Object value);
}

View File

@ -0,0 +1,72 @@
/**
*
*/
package org.gcube.informationsystem.model.reference.entities;
import java.util.List;
import java.util.UUID;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.types.annotations.Abstract;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Resources
*/
@Abstract
// @JsonDeserialize(as=ResourceImpl.class) Do not uncomment to manage subclasses
public interface Resource extends Entity {
public static final String NAME = "Resource"; //Resource.class.getSimpleName();
public static final String CONSISTS_OF_PROPERTY = "consistsOf";
public static final String IS_RELATED_TO_PROPERTY = "isRelatedTo";
@JsonIgnore
public List<? extends Facet> getIdentificationFacets();
// @JsonManagedReference
public List<ConsistsOf<? extends Resource, ? extends Facet>> getConsistsOf();
@JsonIgnore
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> List<C> getConsistsOf(Class<C> clz);
@JsonIgnore
public <F extends Facet, C extends ConsistsOf<? extends Resource, F>> List<C> getConsistsOf(Class<C> clz, Class<F> target);
// @JsonManagedReference
public List<IsRelatedTo<? extends Resource, ? extends Resource>> getIsRelatedTo();
@JsonIgnore
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> List<I> getIsRelatedTo(Class<I> clz);
@JsonIgnore
public List<? extends Facet> getFacets();
@JsonIgnore
public <F extends Facet> List<F> getFacets(Class<F> clz);
@JsonIgnore
public <F extends Facet, C extends ConsistsOf<? extends Resource, F>> List<F> getFacets(Class<C> clz, Class<F> target);
public void addFacet(UUID uuid);
public <F extends Facet> void addFacet(F facet);
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> void addFacet(C relation);
public void attachResource(UUID uuid);
public <R extends Resource> void attachResource(R resource);
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> void attachResource(I relation);
}

View File

@ -0,0 +1,29 @@
package org.gcube.informationsystem.model.reference.properties;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.types.annotations.ISProperty;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@JsonDeserialize(as=EncryptedImpl.class)
public interface Encrypted extends Property {
public static final String NAME = "Encrypted"; //Encrypted.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Encrypted values";
public static final String VERSION = "1.0.0";
public static final String VALUE = "value";
@ISProperty(name=VALUE, readonly=false, mandatory=true, nullable=false)
@JsonGetter(value=VALUE)
public String getEncryptedValue();
@JsonSetter(value=VALUE)
public void setEncryptedValue(String encryptedValue);
}

View File

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

View File

@ -0,0 +1,67 @@
/**
*
*/
package org.gcube.informationsystem.model.reference.properties;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.types.annotations.ISProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Propagation_Constraint
*/
@JsonDeserialize(as=PropagationConstraintImpl.class)
public interface PropagationConstraint extends Property {
public static final String NAME = "PropagationConstraint"; //RelationProperty.class.getSimpleName();
public static final String REMOVE_PROPERTY = "remove";
public static final String ADD_PROPERTY = "add";
public enum RemoveConstraint {
/**
* When the source Entity is removed also the target
* Entity is removed but if and only if the latter has no other
* incoming Relation.
*/
cascadeWhenOrphan,
/**
* When the source Entity is removed also the target
* Entity is removed.
*/
cascade,
/**
* When the source Entity is removed the target Entity
* is keep.
*/
keep
}
public enum AddConstraint {
propagate,
unpropagate
}
@ISProperty(name=REMOVE_PROPERTY)
public RemoveConstraint getRemoveConstraint();
public void setRemoveConstraint(RemoveConstraint removeConstraint);
@ISProperty(name=ADD_PROPERTY)
public AddConstraint getAddConstraint();
public void setAddConstraint(AddConstraint addConstraint);
}

View File

@ -0,0 +1,24 @@
/**
*
*/
package org.gcube.informationsystem.model.reference.properties;
import java.io.Serializable;
import org.gcube.informationsystem.model.reference.ISManageable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* @author Luca Frosini (ISTI - CNR)
* Root Class for Property types. It creates a base common type, which is useful
* for management purpose.
*/
// @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = ISManageable.CLASS_PROPERTY)
@JsonIgnoreProperties(ignoreUnknown=true)
public interface Property extends ISManageable, Serializable {
public static final String NAME = "Property"; //Property.class.getSimpleName();
public static final String DESCRIPTION = "This is the base class for Property";
public static final String VERSION = "1.0.0";
}

View File

@ -0,0 +1,19 @@
/**
*
*/
package org.gcube.informationsystem.model.reference.relations;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#consistsOf
*/
// @JsonDeserialize(as=ConsistsOfImpl.class) Do not uncomment to manage subclasses
public interface ConsistsOf<Out extends Resource, In extends Facet>
extends Relation<Out, In> {
public static final String NAME = "ConsistsOf"; //ConsistsOf.class.getSimpleName();
}

View File

@ -0,0 +1,22 @@
/**
*
*/
package org.gcube.informationsystem.model.reference.relations;
import org.gcube.informationsystem.model.impl.relations.IsIdentifiedByImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isIdentifiedBy
*/
@JsonDeserialize(as=IsIdentifiedByImpl.class)
public interface IsIdentifiedBy<Out extends Resource, In extends Facet>
extends ConsistsOf<Out, In> {
public static final String NAME = "IsIdentifiedBy"; //IsIdentifiedBy.class.getSimpleName();
}

View File

@ -0,0 +1,21 @@
/**
*
*/
package org.gcube.informationsystem.model.reference.relations;
import org.gcube.informationsystem.model.impl.relations.IsParentOfImpl;
import org.gcube.informationsystem.model.reference.entities.Context;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isParentOf
*/
@JsonDeserialize(as=IsParentOfImpl.class)
public interface IsParentOf<Out extends Context, In extends Context>
extends Relation<Out, In> {
public static final String NAME = "IsParentOf"; //IsParentOf.class.getSimpleName();
}

View File

@ -0,0 +1,19 @@
/**
*
*/
package org.gcube.informationsystem.model.reference.relations;
import org.gcube.informationsystem.model.reference.entities.Resource;
/**
* @author Luca Frosini (ISTI - CNR)
* This Relation is for internal use only
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#isRelatedTo
*/
// @JsonDeserialize(as=IsRelatedToImpl.class) Do not uncomment to manage subclasses
public interface IsRelatedTo<Out extends Resource, In extends Resource>
extends Relation<Out, In> {
public static final String NAME = "IsRelatedTo"; //IsRelatedTo.class.getSimpleName();
}

View File

@ -0,0 +1,96 @@
/**
*
*/
package org.gcube.informationsystem.model.reference.relations;
import java.util.Map;
import org.gcube.informationsystem.model.reference.ER;
import org.gcube.informationsystem.model.reference.entities.Context;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.gcube.informationsystem.utils.AdditionalPropertiesSerializer;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* @author Luca Frosini (ISTI - CNR)
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Relations
*/
// @JsonDeserialize(as=RelationImpl.class) Do not uncomment to manage subclasses
public interface Relation<Out extends Entity, In extends Entity> extends ER {
public static final String NAME = "Relation"; //Relation.class.getSimpleName();
public static final String SOURCE_PROPERTY = "source";
public static final String TARGET_PROPERTY = "target";
public static final String PROPAGATION_CONSTRAINT = "propagationConstraint";
/* Overriding getHeader method to create Header property in type */
@ISProperty(name=HEADER_PROPERTY, mandatory=true, nullable=false)
@Override
public Header getHeader();
// @JsonBackReference
// @JsonIgnore
@JsonIgnoreProperties({
Resource.CONSISTS_OF_PROPERTY, Resource.IS_RELATED_TO_PROPERTY,
Context.PARENT_PROPERTY, Context.CHILDREN_PROPERTY
})
@JsonGetter(value=SOURCE_PROPERTY)
public Out getSource();
@JsonIgnore
public void setSource(Out source);
@JsonIgnoreProperties({ Context.PARENT_PROPERTY, Context.CHILDREN_PROPERTY })
@JsonGetter(value=TARGET_PROPERTY)
public In getTarget();
@JsonIgnore
public void setTarget(In target);
@ISProperty(name=PROPAGATION_CONSTRAINT)
public PropagationConstraint getPropagationConstraint();
/**
* Return all properties. The returned Map is a copy of
* the internal representation. Any modification to the returned Map MUST
* not affect the object
* @return a Map containing the properties
*/
@JsonAnyGetter
@JsonSerialize(using = AdditionalPropertiesSerializer.class)
public Map<String, Object> getAdditionalProperties();
/**
* Set all properties, replacing existing ones
*/
public void setAdditionalProperties(Map<String, Object> additionalProperties);
/**
* Return the value of the given property.
* @param key the key of the requested property
* @return the value of the given property
*/
public Object getAdditionalProperty(String key);
/**
* Set the value of the given property.
* @param key the key of the requested property
* @param value the value of the given resource property
*/
@JsonAnySetter
public void setAdditionalProperty(String key, Object value);
}

View File

@ -1,17 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.relation;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public interface ConsistOf<Out extends Resource, In extends Facet>
extends Relation<Out, In> {
public static final String NAME = ConsistOf.class.getSimpleName();
}

View File

@ -1,16 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.relation;
import org.gcube.informationsystem.model.entity.Context;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public interface ParentOf<Out extends Context, In extends Context>
extends Relation<Out, In> {
public static final String NAME = ParentOf.class.getSimpleName();
}

View File

@ -1,19 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.relation;
import org.gcube.informationsystem.model.entity.Resource;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* https://redmine.d4science.org/projects/bluebridge/wiki/Facets#Relation-Facet
* Please note that targetResource described in the wiki is implicit. The
* {@link OutVertex} of this Edge. Look at {@link RelatedTo#getTargetResource()}
*/
public interface RelatedTo<Out extends Resource, In extends Resource>
extends Relation<Out, In> {
public static final String NAME = RelatedTo.class.getSimpleName();
}

View File

@ -1,32 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.model.relation;
import org.gcube.informationsystem.model.annotations.ISProperty;
import org.gcube.informationsystem.model.embedded.Header;
import org.gcube.informationsystem.model.embedded.RelationProperty;
import org.gcube.informationsystem.model.entity.Entity;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
public interface Relation<Out extends Entity, In extends Entity> {
public static final String NAME = Relation.class.getSimpleName();
public static final String RELATION_PROPERTY = "relationProperty";
public static final String HEADER_PROPERTY = Entity.HEADER_PROPERTY;
@ISProperty(name=HEADER_PROPERTY, mandatory=true, nullable=false)
public Header getHeader();
public Out getSource();
public In getTarget();
@ISProperty(name=RELATION_PROPERTY)
public RelationProperty getRelationProperty();
}

View File

@ -22,6 +22,7 @@ package org.gcube.informationsystem.types;
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -29,15 +30,22 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
public class Type{
import org.gcube.informationsystem.model.reference.properties.Property;
/**
* @author Lucio Lelii (ISTI - CNR)
* @author Luca Frosini (ISTI - CNR)
* Create a mapping with OrientDB Types
* https://orientdb.gitbooks.io/orientdb-manual/content/orientdb.wiki/Types.html
* and gCube IS Types
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Property
* The code is copied from OrientDB source Code
* https://github.com/orientechnologies/orientdb/blob/master/core/src/main/java/com/orientechnologies/orient/core/metadata/schema/OType.java
* and adapted for gCube purpose.
*/
public class Type {
/**
* Generic representation of a type.<br>
* allowAssignmentFrom accepts any class, but Array.class means that the type accepts generic Arrays.
*
* @author Luca Garulli
*
*/
public enum OType {
BOOLEAN("Boolean", 0),
@ -59,11 +67,15 @@ public class Type{
EMBEDDED("Embedded", 9),
EMBEDDEDLIST("Embedded list", 10),
EMBEDDEDLIST("Embedded List", 10),
EMBEDDEDSET("Embedded set", 11),
EMBEDDEDSET("Embedded Set", 11),
EMBEDDEDMAP("Embedded map", 12);
EMBEDDEDMAP("Embedded Map", 12),
BYTE("Byte", 17),
BINARY("Binary", 8);
private String stringValue;
private int intValue;
@ -88,27 +100,48 @@ public class Type{
static{
// This is made by hand because not all types should be add.
TYPES_BY_CLASS.put(Boolean.class, OType.BOOLEAN);
TYPES_BY_CLASS.put(Boolean.TYPE, OType.BOOLEAN);
TYPES_BY_CLASS.put(Boolean.class, OType.BOOLEAN);
TYPES_BY_CLASS.put(Integer.TYPE, OType.INTEGER);
TYPES_BY_CLASS.put(Integer.class, OType.INTEGER);
TYPES_BY_CLASS.put(BigInteger.class, OType.INTEGER);
TYPES_BY_CLASS.put(Short.class, OType.SHORT);
TYPES_BY_CLASS.put(Short.TYPE, OType.SHORT);
TYPES_BY_CLASS.put(Long.class, OType.LONG);
TYPES_BY_CLASS.put(Short.class, OType.SHORT);
TYPES_BY_CLASS.put(Long.TYPE, OType.LONG);
TYPES_BY_CLASS.put(Long.class, OType.LONG);
TYPES_BY_CLASS.put(Float.TYPE, OType.FLOAT);
TYPES_BY_CLASS.put(Float.class, OType.FLOAT);
TYPES_BY_CLASS.put(Double.TYPE, OType.DOUBLE);
TYPES_BY_CLASS.put(Double.class, OType.DOUBLE);
TYPES_BY_CLASS.put(Date.class, OType.DATETIME);
TYPES_BY_CLASS.put(Calendar.class, OType.DATETIME);
TYPES_BY_CLASS.put(String.class, OType.STRING);
TYPES_BY_CLASS.put(Enum.class, OType.STRING);
TYPES_BY_CLASS.put(Character.class, OType.STRING);
TYPES_BY_CLASS.put(Character.TYPE, OType.STRING);
TYPES_BY_CLASS.put(Property.class, OType.EMBEDDED);
TYPES_BY_CLASS.put(List.class, OType.EMBEDDEDLIST);
TYPES_BY_CLASS.put(Set.class, OType.EMBEDDEDSET);
TYPES_BY_CLASS.put(Map.class, OType.EMBEDDEDMAP);
TYPES_BY_CLASS.put(Byte.TYPE, OType.BYTE);
TYPES_BY_CLASS.put(Byte.class, OType.BYTE);
TYPES_BY_CLASS.put(byte[].class, OType.BYNARY);
TYPES_BY_CLASS.put(Byte[].class, OType.BYNARY);
TYPES_BY_CLASS.put(Enum.class, OType.STRING);
TYPES_BY_CLASS.put(URI.class, OType.STRING);
TYPES_BY_CLASS.put(URL.class, OType.STRING);
TYPES_BY_CLASS.put(UUID.class, OType.STRING);
@ -116,10 +149,10 @@ public class Type{
}
/**
* Return the correspondent type by checking the "assignability" of the class received as parameter.
* Return the correspondent type by checking the "assignability" of the
* class received as parameter.
*
* @param iClass
* Class to check
* @param iClass Class to check
* @return OType instance if found, otherwise null
*/
public static OType getTypeByClass(final Class<?> iClass) {
@ -127,12 +160,9 @@ public class Type{
return null;
}
OType type = TYPES_BY_CLASS.get(iClass);
if (type != null) {
return type;
}
OType type = TYPES_BY_CLASS.get(iClass);
if(Enum.class.isAssignableFrom(iClass)){
if(type==null && Enum.class.isAssignableFrom(iClass)){
type = TYPES_BY_CLASS.get(Enum.class);
}

View File

@ -3,25 +3,40 @@ package org.gcube.informationsystem.types;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.TypeVariable;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.gcube.informationsystem.model.annotations.Abstract;
import org.gcube.informationsystem.model.annotations.ISProperty;
import org.gcube.informationsystem.model.embedded.Embedded;
import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.relation.ConsistOf;
import org.gcube.informationsystem.model.relation.RelatedTo;
import org.gcube.informationsystem.model.relation.Relation;
import org.gcube.informationsystem.model.reference.ISManageable;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.types.Type.OType;
import org.gcube.informationsystem.types.annotations.Abstract;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class TypeBinder {
private static Logger logger = LoggerFactory.getLogger(TypeBinder.class);
@ -29,77 +44,126 @@ public class TypeBinder {
private static final String EDGE_CLASS_NAME = "E";
private static final String VERTEX_CLASS_NAME = "V";
private final static String NAME = "NAME";
private final static String DESCRIPTION = "DESCRIPTION";
public final static String NAME = "NAME";
public final static String DESCRIPTION = "DESCRIPTION";
public final static String UUID_PATTERN = "^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}$";
public final static String URI_PATTERN = null;
public final static String URL_PATTERN = null;
private static String getStaticStringFieldByName(Class<?> type, String fieldName, String defaultValue){
public static String getType(Class<? extends ISManageable> clz){
return getStaticStringFieldByName(clz, NAME, clz.getSimpleName());
}
private static String getStaticStringFieldByName(Class<? extends ISManageable> type, String fieldName, String defaultValue){
Field field;
try {
field = type.getDeclaredField(fieldName);
field.setAccessible(true);
return (String) field.get(null);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
return defaultValue;
}
}
public static String serializeType(Class<?> type) throws Exception{
TypeDefinition def = createTypeDefinition(type);
public static String serializeTypeDefinition(TypeDefinition typeDefinition) throws Exception{
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(def);
String json = mapper.writeValueAsString(typeDefinition);
return json;
}
protected static TypeDefinition createTypeDefinition(Class<?> type) {
public static String serializeType(Class<? extends ISManageable> type) throws Exception{
TypeDefinition typeDefinition = createTypeDefinition(type);
return serializeTypeDefinition(typeDefinition);
}
public static TypeDefinition deserializeTypeDefinition(String json) throws Exception{
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, TypeDefinition.class);
}
public static String serializeTypeDefinitions(List<TypeDefinition> typeDefinitions) throws Exception{
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(typeDefinitions);
return json;
}
public static List<TypeDefinition> deserializeTypeDefinitions(String json) throws Exception{
ObjectMapper mapper = new ObjectMapper();
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, TypeDefinition.class) ;
return mapper.readValue(json, type);
}
private static Class<?> getGenericClass(java.lang.reflect.Type type){
TypeVariable<?> typeVariable = (TypeVariable<?>) type;
java.lang.reflect.Type[] bounds = typeVariable.getBounds();
java.lang.reflect.Type t = bounds[0];
return (Class<?>) t;
}
public static TypeDefinition createTypeDefinition(Class<? extends ISManageable> clz) {
TypeDefinition typeDefinition = new TypeDefinition();
typeDefinition.name = getStaticStringFieldByName(type, NAME, type.getSimpleName());
typeDefinition.description = getStaticStringFieldByName(type, DESCRIPTION, "");
typeDefinition.name = getType(clz);
typeDefinition.description = getStaticStringFieldByName(clz, DESCRIPTION, "");
typeDefinition.abstractType = false;
if(type.isAnnotationPresent(Abstract.class)){
if(clz.isAnnotationPresent(Abstract.class)){
typeDefinition.abstractType = true;
}
if(Entity.class.isAssignableFrom(type)) {
if(Resource.class.isAssignableFrom(type)){
typeDefinition.superclasses = retrieveSuperClasses(type, Resource.class, Entity.class.getSimpleName());
if(Entity.class.isAssignableFrom(clz)) {
if(Resource.class.isAssignableFrom(clz)){
typeDefinition.superClasses = retrieveSuperClasses(clz, Resource.class, Entity.NAME);
}else{
if(Facet.class.isAssignableFrom(type)){
typeDefinition.superclasses = retrieveSuperClasses(type, Facet.class, Entity.class.getSimpleName());
if(Facet.class.isAssignableFrom(clz)){
typeDefinition.superClasses = retrieveSuperClasses(clz, Facet.class, Entity.NAME);
} else {
typeDefinition.superclasses = retrieveSuperClasses(type, Entity.class, VERTEX_CLASS_NAME);
typeDefinition.superClasses = retrieveSuperClasses(clz, Entity.class, VERTEX_CLASS_NAME);
}
}
} else if(Relation.class.isAssignableFrom(type)){
if(RelatedTo.class.isAssignableFrom(type)){
typeDefinition.superclasses = retrieveSuperClasses(type, RelatedTo.class, Relation.class.getSimpleName());
} else if(ConsistOf.class.isAssignableFrom(type)) {
typeDefinition.superclasses = retrieveSuperClasses(type, ConsistOf.class, Relation.class.getSimpleName());
} else if(Relation.class.isAssignableFrom(clz)){
if(IsRelatedTo.class.isAssignableFrom(clz)){
typeDefinition.superClasses = retrieveSuperClasses(clz, IsRelatedTo.class, Relation.NAME);
} else if(ConsistsOf.class.isAssignableFrom(clz)) {
typeDefinition.superClasses = retrieveSuperClasses(clz, ConsistsOf.class, Relation.NAME);
} else {
typeDefinition.superclasses = retrieveSuperClasses(type, Relation.class, EDGE_CLASS_NAME);
typeDefinition.superClasses = retrieveSuperClasses(clz, Relation.class, EDGE_CLASS_NAME);
}
} else if(Embedded.class.isAssignableFrom(type)){
typeDefinition.superclasses = retrieveSuperClasses(type, Embedded.class, null);
java.lang.reflect.Type[] typeParameters = clz.getTypeParameters();
@SuppressWarnings("unchecked")
Class<? extends ISManageable> sourceClass = (Class<? extends ISManageable>) getGenericClass(typeParameters[0]);
@SuppressWarnings("unchecked")
Class<? extends ISManageable> targetClass = (Class<? extends ISManageable>) getGenericClass(typeParameters[1]);
typeDefinition.sourceType = getType(sourceClass);
typeDefinition.targetType = getType(targetClass);
} else if(Property.class.isAssignableFrom(clz)){
typeDefinition.superClasses = retrieveSuperClasses(clz, Property.class, clz == Property.class ? null : Property.NAME);
} else {
throw new RuntimeException("Serialization required");
}
if(!Resource.class.isAssignableFrom(type)){
typeDefinition.properties = retrieveListOfProperties(type);
if(!Resource.class.isAssignableFrom(clz)){
typeDefinition.properties = retrieveListOfProperties(clz);
}
logger.trace("{} TypeDefinition {} ", type, typeDefinition);
logger.trace("{} : {} ", clz, typeDefinition);
return typeDefinition;
}
protected static Set<Property> retrieveListOfProperties(Class<?> type){
Set<Property> properties = new HashSet<>();
private static 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()) {
continue;
}
ISProperty propAnnotation = m.getAnnotation(ISProperty.class);
Property prop = getProperty(propAnnotation, m);
PropertyDefinition prop = getProperty(propAnnotation, m);
properties.add(prop);
logger.trace("Property {} retrieved in type {} ", prop, type.getSimpleName());
}
@ -108,7 +172,7 @@ public class TypeBinder {
return properties;
}
protected static String getPropertyNameFromMethodName(Method method){
private static String getPropertyNameFromMethodName(Method method){
String name = method.getName();
if(name.startsWith("get")){
name = name.replace("get", "");
@ -125,28 +189,30 @@ public class TypeBinder {
return name;
}
protected static Property getProperty(ISProperty propertyAnnotation, Method method){
private static PropertyDefinition getProperty(ISProperty propertyAnnotation, Method method){
String name = propertyAnnotation.name().isEmpty()?getPropertyNameFromMethodName(method):propertyAnnotation.name();
Property property = new Property();
property.name = name;
property.description = propertyAnnotation.description();
property.mandatory= propertyAnnotation.mandatory();
property.notnull = !propertyAnnotation.nullable();
property.readonly = propertyAnnotation.readonly();
if(propertyAnnotation.max()>0) property.max = propertyAnnotation.max();
if(propertyAnnotation.max()>=propertyAnnotation.min() && propertyAnnotation.min()>0) property.min = propertyAnnotation.min();
if(!propertyAnnotation.regexpr().isEmpty()) property.regexpr = propertyAnnotation.regexpr();
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.name = name;
propertyDefinition.description = propertyAnnotation.description();
propertyDefinition.mandatory= propertyAnnotation.mandatory();
propertyDefinition.notnull = !propertyAnnotation.nullable();
propertyDefinition.readonly = propertyAnnotation.readonly();
if(propertyAnnotation.max()>0) propertyDefinition.max = propertyAnnotation.max();
if(propertyAnnotation.max()>=propertyAnnotation.min() && propertyAnnotation.min()>0) propertyDefinition.min = propertyAnnotation.min();
if(!propertyAnnotation.regexpr().isEmpty()) propertyDefinition.regexp = propertyAnnotation.regexpr();
logger.trace("Looking for property type {}", method.getReturnType());
Class<?> type = method.getReturnType();
property.type = OType.EMBEDDED.getIntValue();
@SuppressWarnings("unchecked")
Class<? extends ISManageable> type = (Class<? extends ISManageable>) method.getReturnType();
propertyDefinition.type = OType.EMBEDDED.getIntValue();
if(Embedded.class.isAssignableFrom(type)){
property.linkedClass = getStaticStringFieldByName(type, NAME, type.getSimpleName());
property.type = OType.EMBEDDED.getIntValue();
if(Property.class.isAssignableFrom(type)){
if(type != Property.class){
propertyDefinition.linkedClass = getType(type);
}
}else if (Type.getTypeByClass(type)!=null) {
property.type = Type.getTypeByClass(type).getIntValue();
if(property.type > 9 && property.type <= 12){
propertyDefinition.type = Type.getTypeByClass(type).getIntValue();
if(propertyDefinition.type > 9 && propertyDefinition.type <= 12){
java.lang.reflect.Type genericReturnType = method.getGenericReturnType();
logger.trace("Generic Return Type {} for method {}", genericReturnType, method);
@ -158,24 +224,53 @@ public class TypeBinder {
genericType = t;
}
Class<?> genericClass = (Class<?>) genericType;
@SuppressWarnings("unchecked")
Class<? extends ISManageable> genericClass = (Class<? extends ISManageable>) genericType;
OType linkedOType = Type.getTypeByClass(genericClass);
if(linkedOType!=null){
property.linkedType = linkedOType.getIntValue();
propertyDefinition.linkedType = linkedOType.getIntValue();
}else{
property.linkedClass = getStaticStringFieldByName(genericClass, NAME, genericClass.getSimpleName());
propertyDefinition.linkedClass = getType(genericClass);
}
}
if((propertyDefinition.regexp==null || propertyDefinition.regexp.compareTo("")==0 )&& propertyDefinition.type==OType.STRING.getIntValue()){
if(Enum.class.isAssignableFrom(type)){
Object[] constants = type.getEnumConstants();
StringBuilder stringBuilder = new StringBuilder("^(");
for(int i=0; i<constants.length; i++){
stringBuilder.append(constants[i].toString());
if(i<constants.length-1){
stringBuilder.append("|");
}
}
stringBuilder.append(")$");
propertyDefinition.regexp = stringBuilder.toString();
}
if(UUID.class.isAssignableFrom(type)){
propertyDefinition.regexp = UUID_PATTERN;
}
if(URI.class.isAssignableFrom(type)){
propertyDefinition.regexp = URI_PATTERN;
}
if(URL.class.isAssignableFrom(type)){
propertyDefinition.regexp = URL_PATTERN;
}
}
if(propertyDefinition.regexp!=null && propertyDefinition.regexp.compareTo("")==0){
propertyDefinition.regexp = null;
}
} else {
throw new RuntimeException("Type " + type.getSimpleName() + " not reconized");
}
return property;
return propertyDefinition;
}
private static Set<String> retrieveSuperClasses(Class<?> type, Class<?> baseClass, String topSuperClass){
private static Set<String> retrieveSuperClasses(Class<? extends ISManageable> type, Class<? extends ISManageable> baseClass, String topSuperClass){
Set<String> interfaceList = new HashSet<>();
if(type==baseClass){
@ -186,35 +281,45 @@ public class TypeBinder {
Class<?>[] interfaces = type.getInterfaces();
for (Class<?> interfaceClass : interfaces) {
if(interfaceClass==Embedded.class){
continue;
}
if(!baseClass.isAssignableFrom(interfaceClass)){
continue;
}
interfaceList.add(getStaticStringFieldByName(interfaceClass, NAME, interfaceClass.getSimpleName()));
@SuppressWarnings("unchecked")
Class<? extends ISManageable> clz = (Class<? extends ISManageable>) interfaceClass;
interfaceList.add(getType(clz));
}
return interfaceList;
}
@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
public static class TypeDefinition{
@JsonIgnoreProperties(ignoreUnknown=true)
public static class TypeDefinition {
protected String name;
protected String description;
@JsonProperty(value="abstract")
protected boolean abstractType;
protected Set<String> superclasses;
protected Set<Property> properties;
protected Set<String> superClasses;
protected Set<PropertyDefinition> properties;
@JsonInclude(JsonInclude.Include.NON_NULL)
protected String sourceType;
@JsonInclude(JsonInclude.Include.NON_NULL)
protected String targetType;
@Override
public String toString() {
return "TypeDefinition [name=" + name +", description="
+ description + ", superclasses="
+ superclasses + ", properties=" + properties + "]";
return "TypeDefinition ["
+ "name=" + name
+ (sourceType==null ? "" : "(" + sourceType + "->" + targetType + ")")
+ ", description=" + description
+ ", abstract=" + abstractType
+ ", superClasses=" + superClasses
+ ", properties=" + properties
+ "]";
}
public String getName() {
@ -225,22 +330,31 @@ public class TypeBinder {
return description;
}
public boolean isAbstractType() {
public boolean isAbstract() {
return abstractType;
}
public Set<String> getSuperclasses() {
return superclasses;
public Set<String> getSuperClasses() {
return superClasses;
}
public Set<Property> getProperties() {
public Set<PropertyDefinition> getProperties() {
return properties;
}
public String getSourceType() {
return sourceType;
}
public String getTargetType() {
return targetType;
}
}
@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
public static class Property {
@JsonIgnoreProperties(ignoreUnknown=true)
public static class PropertyDefinition {
private String name= "";
private String description= "";
@ -249,7 +363,7 @@ public class TypeBinder {
private boolean notnull = false;
private Integer max= null;
private Integer min= null;
private String regexpr= null;
private String regexp= null;
private Integer linkedType = null;
private String linkedClass = null;
private Integer type=null;
@ -282,8 +396,8 @@ public class TypeBinder {
return min;
}
public String getRegexpr() {
return regexpr;
public String getRegexp() {
return regexp;
}
public Integer getLinkedType() {
@ -298,18 +412,25 @@ public class TypeBinder {
return type;
}
@JsonIgnore
public String getTypeStringValue() {
if(type==null){
return null;
}
return OType.values()[type].getStringValue();
}
@Override
public String toString() {
return "Property [name=" + name + ", description=" + description
+ ", mandatory=" + mandatory + ", readonly=" + readonly
+ ", notnull=" + notnull + ", max=" + max + ", min="
+ min + ", regexpr=" + regexpr + ", type = " + type
+ ", linkedType = " + linkedType + ", linkedClass = "
+ min + ", regexpr=" + regexp + ", type = " + type
+ " (" + getTypeStringValue() + "), linkedType = " + linkedType + ", linkedClass = "
+ linkedClass + "]";
}
}
}

View File

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

View File

@ -0,0 +1,32 @@
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.model.reference.entities.Entity;
import org.gcube.informationsystem.types.TypeBinder;
import org.gcube.informationsystem.types.TypeBinder.PropertyDefinition;
/**
* @author Luca Frosini (ISTI - CNR)
* It is used by {@link TypeBinder} to identify which getter method are
* related to and {@link Entity} {@link PropertyDefinition}.
* The name of the property is obtained by removing "get" or "is" from method
* name and lower casing the first letter.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ISProperty {
String name() default "";
String description() default "";
boolean mandatory() default false;
boolean readonly() default false;
boolean nullable() default true;
int min() default -1;
int max() default -1;
String regexpr() default "";
}

View File

@ -0,0 +1,23 @@
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.model.reference.entities.Facet;
/**
* @author Luca Frosini (ISTI - CNR)
* Provide a way to identify a Key for a
* {@link Facet}
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Key {
String name() default "";
String[] fields() default {};
}

View File

@ -0,0 +1,41 @@
package org.gcube.informationsystem.utils;
import java.io.IOException;
import java.util.Map;
import org.gcube.informationsystem.model.reference.properties.Property;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
public class AdditionalPropertiesSerializer extends StdSerializer<Object>{
public AdditionalPropertiesSerializer() {
super(null, true);
}
public AdditionalPropertiesSerializer(StdSerializer<Object> stdSerializer) {
super(stdSerializer);
}
/**
* Generated Serial verison UID
*/
private static final long serialVersionUID = -3198778268947046277L;
@Override
public void serialize(Object obj, JsonGenerator generator, SerializerProvider provider) throws IOException {
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String,Object>) obj;
for(String key : map.keySet()) {
Object object = map.get(key);
if(object instanceof Property) {
generator.writeObjectField(key, (Property) object);
}else {
generator.writeObjectField(key, object);
}
}
}
}

View File

@ -0,0 +1,138 @@
/**
*
*/
package org.gcube.informationsystem.utils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.gcube.informationsystem.model.reference.AccessType;
import org.gcube.informationsystem.model.reference.ISManageable;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class ERDeserializer<ISM extends ISManageable> extends StdDeserializer<ISM> {
private static final long serialVersionUID = -2551569658316955137L;
protected final ObjectMapper mapper;
public ERDeserializer(Class<ISM> clz, ObjectMapper mapper) {
super(clz);
this.mapper = mapper;
}
@Override
public Object deserializeWithType(JsonParser jp,
DeserializationContext ctxt, TypeDeserializer typeDeserializer)
throws IOException {
TreeNode treeNode = jp.readValueAsTree();
JsonFactory jsonFactory = mapper.getFactory();
JsonParser clonedJP = jsonFactory.createParser(treeNode.toString());
clonedJP.nextToken();
try {
return typeDeserializer.deserializeTypedFromAny(clonedJP, ctxt);
} catch (Exception e) {
Class<?> candidatedSuperClass = _valueClass;
List<TextNode> toBeKeepSuperClasses = new ArrayList<>();
ObjectNode objectNode = (ObjectNode) treeNode;
try {
JsonNode superClassesTreeNode = objectNode
.get(ISManageable.SUPERCLASSES_PROPERTY);
if (superClassesTreeNode != null
&& superClassesTreeNode.isArray()) {
ArrayNode arrayNode = (ArrayNode) superClassesTreeNode;
for (int i = 0; i < arrayNode.size(); i++) {
try {
JsonNode jsonNode = arrayNode.get(i);
JsonNodeType jsonNodeType = jsonNode.getNodeType();
switch (jsonNodeType) {
case STRING:
String superClass = jsonNode.asText();
try {
Enum.valueOf(AccessType.class,
superClass.toUpperCase());
// It is one of the BaseType. Looking for
// another type because the base one
continue;
} catch (Exception ex) {
// can continue discovery
}
JavaType javaType = typeDeserializer
.getTypeIdResolver().typeFromId(ctxt,
superClass);
if (javaType == null) {
TextNode textNode = new TextNode(superClass);
toBeKeepSuperClasses.add(textNode);
continue;
}
Class<?> clz = javaType.getRawClass();
if (candidatedSuperClass.isAssignableFrom(clz)) {
// clz is a subClass so that is a candidate
candidatedSuperClass = clz;
}
break;
default:
break;
}
} catch (Exception ex) {
// Trying the next one
}
}
arrayNode.removeAll();
arrayNode.addAll(toBeKeepSuperClasses);
}
} catch (Exception ex) {
// Using already known candidatedSuperClass
}
if(candidatedSuperClass == _valueClass){
// No suitable class found Using Dummy Implementation
candidatedSuperClass = AccessType.getAccessType(_valueClass).getDummyImplementationClass();
}
objectNode.set(ISManageable.CLASS_PROPERTY,
new TextNode(candidatedSuperClass.getSimpleName()));
JsonParser jsonParser = jsonFactory.createParser(objectNode
.toString());
jsonParser.nextToken();
return typeDeserializer.deserializeTypedFromAny(jsonParser, ctxt);
}
}
@SuppressWarnings("unchecked")
@Override
public ISM deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
return (ISM) deserializeWithType(jp, ctxt, null);
}
}

View File

@ -0,0 +1,234 @@
package org.gcube.informationsystem.utils;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import org.gcube.informationsystem.model.reference.AccessType;
import org.gcube.informationsystem.model.reference.ISManageable;
import org.gcube.informationsystem.utils.discovery.ISMDiscovery;
import org.gcube.informationsystem.utils.discovery.RegistrationProvider;
import org.gcube.informationsystem.utils.discovery.SchemaAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@SuppressWarnings("unchecked")
public abstract class ISMapper {
private static Logger logger = LoggerFactory.getLogger(ISMapper.class);
protected static final ObjectMapper mapper;
/**
* @return the ObjectMapper
*/
public static ObjectMapper getObjectMapper() {
return mapper;
}
static {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
AccessType[] accessTypes = AccessType.values();
for(AccessType accessType : accessTypes) {
@SuppressWarnings("rawtypes")
Class clz = accessType.getTypeClass();
Class<?> dummyClz = accessType.getDummyImplementationClass();
if(dummyClz != null) {
SimpleModule isModule = new SimpleModule(accessType.getName());
isModule.addDeserializer(clz, new ERDeserializer<>(clz, mapper));
mapper.registerModule(isModule);
mapper.registerSubtypes(dummyClz);
}
}
SchemaAction schemaAction = new ObjectMappingERAction(mapper);
try {
ISMDiscovery.manageISM(schemaAction);
} catch(Exception e) {
logger.error("Error registering types", e);
}
ServiceLoader<? extends RegistrationProvider> regsitrationProviders = ServiceLoader.load(RegistrationProvider.class);
for (RegistrationProvider registrationProvider : regsitrationProviders) {
registerPackages(registrationProvider.getPackagesToRegister());
}
}
public static void registerPackages(List<Package> packages) {
SchemaAction schemaAction = new ObjectMappingERAction(mapper);
try {
ISMDiscovery.manageISM(schemaAction, packages);
} catch(Exception e) {
logger.error("Error registering types", e);
}
}
public static void registerPackages(Package... packages) {
SchemaAction schemaAction = new ObjectMappingERAction(mapper);
try {
ISMDiscovery.manageISM(schemaAction, packages);
} catch(Exception e) {
logger.error("Error registering types", e);
}
}
public static <ISM extends ISManageable> void registerSubtypes(Class<ISM>... classes) {
mapper.registerSubtypes(classes);
}
/**
* Write the serialization of a given resource to a given
* {@link OutputStream} .
*
* @param object the resource
* @param stream the stream in input
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
public static <T extends OutputStream, ISM extends ISManageable> T marshal(ISM object, T stream)
throws JsonGenerationException, JsonMappingException, IOException {
mapper.writeValue(stream, object);
return stream;
}
/**
* Write the serialization of a given resource to a given {@link Writer} .
* @param object the resource
* @param writer the writer in input
* @throws IOException
* @throws JsonMappingException
* @throws JsonGenerationException
*/
public static <T extends Writer, ISM extends ISManageable> T marshal(ISM object, T writer)
throws JsonGenerationException, JsonMappingException, IOException {
mapper.writeValue(writer, object);
return writer;
}
/**
* Return the String serialization of a given object
* @param object the object to marshal
* @return the String serialization of a given resource
* @throws JsonProcessingException
*/
public static <ISM extends ISManageable> String marshal(ISM object) throws JsonProcessingException {
return mapper.writeValueAsString(object);
}
/**
* Return the String serialization of a given list
* @param list the list to marshal
* @return the String serialization of a given list
* @throws JsonProcessingException
*/
public static <ISM extends ISManageable> String marshal(List<ISM> list) throws JsonProcessingException {
JavaType type = mapper.getTypeFactory().constructCollectionType(List.class, ISManageable.class);
return mapper.writerFor(type).writeValueAsString(list);
}
/**
* Return the String serialization of a given array
* @param array the array to marshal
* @return the String serialization of a given array
* @throws JsonProcessingException
*/
public static <ISM extends ISManageable> String marshal(ISM[] array) throws JsonProcessingException {
return mapper.writeValueAsString(array);
}
/**
* Creates a resource of given class from its serialization in a given
* {@link Reader}.
* @param clz the class of the resource
* @param reader the reader
* @return the resource
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
*/
public static <ISM extends ISManageable> ISM unmarshal(Class<ISM> clz, Reader reader)
throws JsonParseException, JsonMappingException, IOException {
return mapper.readValue(reader, clz);
}
/**
* Creates a resource of given class from its serialization in a given
* {@link InputStream}.
* @param clz the class of the resource
* @param stream the stream
* @return the resource
* @throws IOException
* @throws JsonMappingException
* @throws JsonParseException
*/
public static <ISM extends ISManageable> ISM unmarshal(Class<ISM> clz, InputStream stream)
throws JsonParseException, JsonMappingException, IOException {
return mapper.readValue(stream, clz);
}
/**
* Creates a resource of given class from its serialization in a given String
* @param clz the class of the resource
* @param string
* @return the resource
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
*/
public static <ISM extends ISManageable> ISM unmarshal(Class<ISM> clz, String string)
throws JsonParseException, JsonMappingException, IOException {
return mapper.readValue(string, clz);
}
/**
* Creates a resource of given class from its serialization in a given String
* @param clz the class of the resource
* @param string
* @return the resource
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
*/
public static <ISM extends ISManageable> ISM unmarshalWithReader(Class<ISM> reader, String string)
throws JsonParseException, JsonMappingException, IOException {
return mapper.readerFor(reader).readValue(string);
}
public static <ISM extends ISManageable> List<ISM> unmarshalList(Class<ISM> clz, String string)
throws JsonParseException, JsonMappingException, IOException {
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, clz);
return mapper.readValue(string, type);
}
public static <ISM extends ISManageable> List<ISM> unmarshalList(String string)
throws JsonParseException, JsonMappingException, IOException {
JavaType type = mapper.getTypeFactory().constructCollectionType(ArrayList.class, ISManageable.class);
return mapper.readValue(string, type);
}
}

View File

@ -0,0 +1,42 @@
/**
*
*/
package org.gcube.informationsystem.utils;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.utils.discovery.SchemaAction;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @author Luca Frosini (ISTI - CNR)
*/
class ObjectMappingERAction implements SchemaAction {
protected ObjectMapper objectMapper;
public ObjectMappingERAction(ObjectMapper objectMapper){
this.objectMapper = objectMapper;
}
@Override
public <E extends Property> void managePropertyClass(Class<E> e)
throws Exception {
objectMapper.registerSubtypes(e);
}
@Override
public <E extends Entity> void manageEntityClass(Class<E> e)
throws Exception {
objectMapper.registerSubtypes(e);
}
@Override
public <R extends Relation<? extends Entity, ? extends Entity>> void manageRelationClass(
Class<R> r) throws Exception {
objectMapper.registerSubtypes(r);
}
}

View File

@ -1,12 +1,13 @@
/**
*
*/
package org.gcube.informationsystem.impl.utils;
package org.gcube.informationsystem.utils;
import java.io.IOException;
import java.util.UUID;
import org.gcube.informationsystem.model.embedded.Header;
import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -15,20 +16,24 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* @author Luca Frosini (ISTI - CNR)
*
*/
public class Utility {
private static Logger logger = LoggerFactory.getLogger(Utility.class);
public static String getUUIDFromJSONString(String json) throws JsonProcessingException, IOException {
public static UUID getUUIDFromJsonNode(JsonNode jsonNode){
JsonNode header = jsonNode.get(Entity.HEADER_PROPERTY);
UUID uuid = UUID.fromString(header.get(Header.UUID_PROPERTY).asText());
logger.trace("UUID got from {} is : {} ", jsonNode.toString(), uuid);
return uuid;
}
public static UUID getUUIDFromJSONString(String json) throws JsonProcessingException, IOException {
logger.trace("Trying to get UUID from {} of {} ", Header.class.getSimpleName(), json);
JsonNode jsonNode = getJSONNode(json);
JsonNode header = jsonNode.get(Entity.HEADER_PROPERTY);
String uuid = header.get(Header.UUID_PROPERTY).asText();
logger.trace("UUID got from {} is : {} ", json, uuid);
return uuid;
return getUUIDFromJsonNode(jsonNode);
}
public static JsonNode getJSONNode(String json) throws JsonProcessingException, IOException {
@ -41,6 +46,4 @@ public class Utility {
return jsonNode;
}
}

View File

@ -0,0 +1,149 @@
/**
*
*/
package org.gcube.informationsystem.utils.discovery;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import org.gcube.informationsystem.model.reference.ISManageable;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.types.annotations.ISProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ISMDiscovery<ISM extends ISManageable> {
private static Logger logger = LoggerFactory.getLogger(ISMDiscovery.class);
protected final Class<ISM> root;
protected final List<Package> packages;
protected final List<Class<ISM>> discovered;
public List<Class<ISM>> getDiscovered() {
return discovered;
}
public ISMDiscovery(Class<ISM> root) {
this.root = root;
this.packages = new ArrayList<>();
addPackage(root.getPackage());
this.discovered = new ArrayList<>();
add(root);
}
public void addPackage(Package p) {
packages.add(p);
}
protected void add(Class<ISM> clz) {
discovered.add(clz);
logger.trace("+ Added {}.", clz);
}
protected void analizeISM(Class<ISM> clz) {
logger.trace("Analizyng {}", clz);
if (!clz.isInterface()) {
logger.trace("- Discarding {} that is not an interface", clz);
return;
}
if (!root.isAssignableFrom(clz)) {
logger.trace("- Discarding {} because is not a {}", clz, root.getSimpleName());
return;
}
if (discovered.contains(clz)) {
logger.trace("- Discarding {} because was already managed", clz);
return;
}
Class<?>[] interfaces = clz.getInterfaces();
for (Class<?> interfaceClass : interfaces) {
@SuppressWarnings("unchecked")
Class<ISM> parent = (Class<ISM>) interfaceClass;
analizeISM(parent);
}
if (root == Property.class) {
for (Method m : clz.getDeclaredMethods()) {
m.setAccessible(true);
if (m.isAnnotationPresent(ISProperty.class)) {
if (root.isAssignableFrom(m.getReturnType())) {
@SuppressWarnings("unchecked")
Class<ISM> type = (Class<ISM>) m.getReturnType();
analizeISM(type);
}
}
}
}
add(clz);
}
public void discover() throws Exception {
for (Package p : packages) {
List<Class<?>> classes = ReflectionUtility.getClassesForPackage(p);
for (Class<?> clz : classes) {
@SuppressWarnings("unchecked")
Class<ISM> ism = (Class<ISM>) clz;
analizeISM(ism);
}
}
}
public static void manageISM(SchemaAction schemaAction, List<Package> packages) throws Exception {
if (Objects.nonNull(packages) && packages.size() > 0) {
manageISM(schemaAction, packages.stream().toArray(Package[]::new));
} else {
manageISM(schemaAction);
}
}
@SuppressWarnings("unchecked")
public static void manageISM(SchemaAction schemaAction, Package... packages) throws Exception {
ISMDiscovery<Property> propertyDiscovery = new ISMDiscovery<>(Property.class);
if (Objects.nonNull(packages))
Arrays.stream(packages).forEach(p -> propertyDiscovery.addPackage(p));
propertyDiscovery.discover();
for (Class<Property> property : propertyDiscovery.getDiscovered()) {
logger.trace("Going to manage : {}", property);
schemaAction.managePropertyClass(property);
}
ISMDiscovery<Entity> entityDiscovery = new ISMDiscovery<>(Entity.class);
if (Objects.nonNull(packages))
Arrays.stream(packages).forEach(p -> entityDiscovery.addPackage(p));
entityDiscovery.discover();
for (Class<Entity> entity : entityDiscovery.getDiscovered()) {
logger.trace("Going to manage : {}", entity);
schemaAction.manageEntityClass(entity);
}
@SuppressWarnings("rawtypes")
ISMDiscovery<Relation> relationDiscovery = new ISMDiscovery<>(Relation.class);
if (Objects.nonNull(packages))
Arrays.stream(packages).forEach(p -> relationDiscovery.addPackage(p));
relationDiscovery.discover();
for (@SuppressWarnings("rawtypes")
Class<Relation> relation : relationDiscovery.getDiscovered()) {
logger.trace("Going to manage : {}", relation);
schemaAction.manageRelationClass(relation);
}
}
}

View File

@ -0,0 +1,201 @@
/**
*
*/
package org.gcube.informationsystem.utils.discovery;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
/**
* Got from
* http://stackoverflow.com/questions/520328/can-you-find-all-classes-in-a-package-using-reflection#answer-22462785
*
* The method first gets the current ClassLoader. It then fetches all resources
* that contain said package and iterates of these URLs. It then creates a
* URLConnection and determines what type of URL we have. It can either be a
* directory (FileURLConnection) or a directory inside a jar or zip file
* (JarURLConnection). Depending on what type of connection we have two
* different methods will be called.
*
* First lets see what happens if it is a FileURLConnection.
*
* It first checks if the passed File exists and is a directory. If that's the
* case it checks if it is a class file. If so a Class object will be created
* and put in the List. If it is not a class file but is a directory, we
* simply iterate into it and do the same thing. All other cases/files will be
* ignored.
*
* If the URLConnection is a JarURLConnection the other private helper method
* will be called. This method iterates over all Entries in the zip/jar
* archive. If one entry is a class file and is inside of the package a Class
* object will be created and stored in the ArrayList.
*
* After all resources have been parsed it (the main method) returns the
* ArrayList containing all classes in the given package, that the current
* ClassLoader knows about.
*
* If the process fails at any point a ClassNotFoundException will be thrown
* containing detailed information about the exact cause.
*
*/
public class ReflectionUtility {
/**
* Private helper method
*
* @param directory
* The directory to start with
* @param pckgname
* The package name to search for. Will be needed for getting the
* Class object.
* @param classes
* if a file isn't loaded but still is in the directory
* @throws ClassNotFoundException
*/
private static void checkDirectory(File directory, String pckgname,
List<Class<?>> classes) throws ClassNotFoundException {
File tmpDirectory;
if (directory.exists() && directory.isDirectory()) {
final String[] files = directory.list();
if(files!=null){
for (final String file : files) {
if (file.endsWith(".class")) {
try {
classes.add(Class.forName(pckgname + '.'
+ file.substring(0, file.length() - 6)));
} catch (final NoClassDefFoundError e) {
// do nothing. this class hasn't been found by the
// loader, and we don't care.
}
} else if ((tmpDirectory = new File(directory, file))
.isDirectory()) {
checkDirectory(tmpDirectory, pckgname + "." + file, classes);
}
}
}
}
}
/**
* Private helper method.
*
* @param connection
* the connection to the jar
* @param pckgname
* the package name to search for
* @param classes
* the current ArrayList of all classes. This method will simply
* add new classes.
* @throws ClassNotFoundException
* if a file isn't loaded but still is in the jar file
* @throws IOException
* if it can't correctly read from the jar file.
*/
private static void checkJarFile(JarURLConnection connection,
String pckgname, List<Class<?>> classes)
throws ClassNotFoundException, IOException {
final JarFile jarFile = connection.getJarFile();
final Enumeration<JarEntry> entries = jarFile.entries();
String name;
for (JarEntry jarEntry = null; entries.hasMoreElements()
&& ((jarEntry = entries.nextElement()) != null);) {
name = jarEntry.getName();
if (name.contains(".class")) {
name = name.substring(0, name.length() - 6).replace('/', '.');
if (name.contains(pckgname)) {
classes.add(Class.forName(name));
}
}
}
}
public static List<Class<?>> getClassesForPackage(Package packageObject)
throws ClassNotFoundException {
return getClassesForPackage(packageObject.getName());
}
/**
* Attempts to list all the classes in the specified package as determined
* by the context class loader
*
* @param pckgname
* the package name to search
* @return a list of classes that exist within that package
* @throws ClassNotFoundException
* if something went wrong
*/
@SuppressWarnings("restriction")
public static List<Class<?>> getClassesForPackage(String pckgname)
throws ClassNotFoundException {
final List<Class<?>> classes = new ArrayList<Class<?>>();
try {
final ClassLoader cld = Thread.currentThread()
.getContextClassLoader();
if (cld == null)
throw new ClassNotFoundException("Can't get class loader.");
final Enumeration<URL> resources = cld.getResources(pckgname
.replace('.', '/'));
URLConnection connection;
for (URL url = null; resources.hasMoreElements()
&& ((url = resources.nextElement()) != null);) {
try {
connection = url.openConnection();
if (connection instanceof JarURLConnection) {
checkJarFile((JarURLConnection) connection, pckgname,
classes);
} else if (connection instanceof sun.net.www.protocol.file.FileURLConnection) {
try {
checkDirectory(
new File(URLDecoder.decode(url.getPath(),
"UTF-8")), pckgname, classes);
} catch (final UnsupportedEncodingException ex) {
throw new ClassNotFoundException(
pckgname
+ " does not appear to be a valid package (Unsupported encoding)",
ex);
}
} else
throw new ClassNotFoundException(pckgname + " ("
+ url.getPath()
+ ") does not appear to be a valid package");
} catch (final IOException ioex) {
throw new ClassNotFoundException(
"IOException was thrown when trying to get all resources for "
+ pckgname, ioex);
}
}
} catch (final NullPointerException ex) {
throw new ClassNotFoundException(
pckgname
+ " does not appear to be a valid package (Null pointer exception)",
ex);
} catch (final IOException ioex) {
throw new ClassNotFoundException(
"IOException was thrown when trying to get all resources for "
+ pckgname, ioex);
}
return classes;
}
}

View File

@ -0,0 +1,19 @@
package org.gcube.informationsystem.utils.discovery;
import java.util.List;
/**
* @author Luca Frosini (ISTI - CNR)
* Any model which requires to register the defined types from marshalling and unmarshalling
* must implement this interface returning the list of packages containing the interfaces
* representing the model.
*/
public interface RegistrationProvider {
/**
* This method must return the list of packages to be registered from marshalling/unmarshalling
* @return the list of packages to register
*/
public List<Package> getPackagesToRegister();
}

View File

@ -0,0 +1,22 @@
/**
*
*/
package org.gcube.informationsystem.utils.discovery;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.Relation;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public interface SchemaAction {
public <E extends Property> void managePropertyClass(Class<E> e) throws Exception;
public <E extends Entity> void manageEntityClass(Class<E> e) throws Exception;
public <R extends Relation<? extends Entity, ? extends Entity>> void manageRelationClass(Class<R> r) throws Exception;
}

11
src/main/main.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,76 +0,0 @@
{
"orientdb" : {
"@type":"d",
"@version":0,
"name":"MyVertex",
"shortName":null,
"description":null,
"defaultClusterId":29,
"clusterIds":[29,30,31,32],
"clusterSelection":"round-robin",
"overSize":0.0,
"strictMode":false,
"abstract":false,
"properties":[
{
"@type":"d",
"@version":0,
"name":"name",
"type":7,
"globalId":0,
"mandatory":false,
"readonly":false,
"notNull":false,
"defaultValue":null,
"min":null,
"max":null,
"regexp":null,
"customFields":null,
"collate":"default",
"description":null
},
{
"@type":"d",
"@version":0,
"name":"luca",
"type":9,
"globalId":25,
"mandatory":false,
"readonly":false,
"notNull":false,
"defaultValue":null,
"min":null,
"max":null,
"regexp":null,
"linkedClass":"Lucio",
"customFields":null,
"collate":"default",
"description":null
}
],
"superClass":"Facet, Resource",
"superClasses":["V"],
"customFields":null,
"@fieldTypes":"overSize=f,properties=e"
},
"gcube" : {
"name":"MyVertex",
"abstract":false,
"superClasses":["V"],
"properties":[
{
"name":"name",
"type":7,
"mandatory":false,
"readonly":false,
"notNull":false,
"defaultValue":null,
"min":null,
"max":null,
"regexp":null,
"description": null, // "any string"
"collate":"default", // default - ci
}
]
}
}

View File

@ -0,0 +1,115 @@
/**
*
*/
package org.gcube.informationsystem.model;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ContextTest {
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
protected static final String PROPERTIES_FILENAME = "token.properties";
private static final String GCUBE_VARNAME = "GCUBE";
public static final String GCUBE;
private static final String GCUBE_DEVNEXT_VARNAME = "GCUBE_DEVNEXT";
public static final String GCUBE_DEVNEXT;
private static final String GCUBE_DEVNEXT_NEXTNEXT_VARNAME = "GCUBE_DEVNEXT_NEXTNEXT";
public static final String GCUBE_DEVNEXT_NEXTNEXT;
public static final String GCUBE_DEVSEC_VARNAME = "GCUBE_DEVSEC";
public static final String GCUBE_DEVSEC;
public static final String GCUBE_DEVSEC_DEVVRE_VARNAME = "GCUBE_DEVSEC_DEVVRE";
public static final String GCUBE_DEVSEC_DEVVRE;
private static final String GCUBE_DEVNEXT_ANOTHER_USER_VARNAME = "GCUBE_DEVNEXT_ANOTHER_USER";
public static final String GCUBE_DEVNEXT_ANOTHER_USER;
public static final String DEFAULT_TEST_SCOPE;
public static final String PARENT_DEFAULT_TEST_SCOPE;
public static final String DEFAULT_TEST_SCOPE_ANOTHER_USER;
public static final String ALTERNATIVE_TEST_SCOPE;
static {
Properties properties = new Properties();
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
try {
// load the properties file
properties.load(input);
} catch (IOException e) {
throw new RuntimeException(e);
}
GCUBE = properties.getProperty(GCUBE_VARNAME);
GCUBE_DEVNEXT = properties.getProperty(GCUBE_DEVNEXT_VARNAME);
GCUBE_DEVNEXT_NEXTNEXT = properties.getProperty(GCUBE_DEVNEXT_NEXTNEXT_VARNAME);
GCUBE_DEVSEC = properties.getProperty(GCUBE_DEVSEC_VARNAME);
GCUBE_DEVSEC_DEVVRE = properties.getProperty(GCUBE_DEVSEC_DEVVRE_VARNAME);
GCUBE_DEVNEXT_ANOTHER_USER = properties.getProperty(GCUBE_DEVNEXT_ANOTHER_USER_VARNAME);
DEFAULT_TEST_SCOPE = GCUBE_DEVNEXT;
PARENT_DEFAULT_TEST_SCOPE = GCUBE;
DEFAULT_TEST_SCOPE_ANOTHER_USER = GCUBE_DEVNEXT_ANOTHER_USER;
ALTERNATIVE_TEST_SCOPE = GCUBE_DEVNEXT_NEXTNEXT;
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception{
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
logger.info("Context of token {} is {}", token, context);
return context;
}
public static void setContext(String token) throws ObjectNotFound, Exception{
SecurityTokenProvider.instance.set(token);
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
ClientInfo clientInfo = authorizationEntry.getClientInfo();
String qualifier = authorizationEntry.getQualifier();
Caller caller = new Caller(clientInfo, qualifier);
AuthorizationProvider.instance.set(caller);
ScopeProvider.instance.set(getCurrentScope(token));
}
@BeforeClass
public static void beforeClass() throws Exception{
setContext(DEFAULT_TEST_SCOPE);
}
@AfterClass
public static void afterClass() throws Exception{
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
}
}

View File

@ -0,0 +1,43 @@
package org.gcube.informationsystem.model.impl.entities;
import org.gcube.informationsystem.model.impl.entities.ContextImpl;
import org.gcube.informationsystem.model.reference.entities.Context;
import org.gcube.informationsystem.utils.ISMapper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ISContextTest {
private static final Logger logger = LoggerFactory.getLogger(ISContextTest.class);
@Test
public void testMarshalling() throws Exception {
Context gcube = new ContextImpl("gcube");
logger.debug("gcube : {}", ISMapper.marshal(ISMapper.unmarshal(Context.class, ISMapper.marshal(gcube))));
Context devsec = new ContextImpl("devsec");
gcube.addChild(devsec);
logger.debug("devsec : {}", ISMapper.marshal(ISMapper.unmarshal(Context.class, ISMapper.marshal(devsec))));
Context devVRE = new ContextImpl("devVRE");
devsec.addChild(devVRE);
logger.debug("devVRE : {}", ISMapper.marshal(ISMapper.unmarshal(Context.class, ISMapper.marshal(devVRE))));
Context devNext = new ContextImpl("devNext");
gcube.addChild(devNext);
logger.debug("devNext : {}", ISMapper.marshal(ISMapper.unmarshal(Context.class, ISMapper.marshal(devNext))));
Context NextNext = new ContextImpl("NextNext");
devNext.addChild(NextNext);
logger.debug("NextNext : {}", ISMapper.marshal(ISMapper.unmarshal(Context.class, ISMapper.marshal(NextNext))));
logger.debug("------------------------------------");
logger.debug("gcube : {}", ISMapper.marshal(gcube));
logger.debug("devsec : {}", ISMapper.marshal(devsec));
logger.debug("devVRE : {}", ISMapper.marshal(devVRE));
logger.debug("devNext : {}", ISMapper.marshal(devNext));
logger.debug("NextNext : {}", ISMapper.marshal(NextNext));
}
}

View File

@ -0,0 +1,99 @@
package org.gcube.informationsystem.model.impl.properties;
import java.security.Key;
import java.security.SecureRandom;
import javax.crypto.KeyGenerator;
import org.gcube.informationsystem.model.ContextTest;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.types.TypeBinder;
import org.gcube.informationsystem.utils.ISMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class EncryptedTest extends ContextTest {
private static final Logger logger = LoggerFactory.getLogger(EncryptedTest.class);
@Test
public void testEncryptDecrypt() throws Exception {
String value = "myValue";
logger.debug("Original Value {}", value);
String encrypted = EncryptedImpl.encrypt(value);
logger.debug("Encrypted Value {}", encrypted);
String decrypted = EncryptedImpl.decrypt(encrypted);
logger.debug("Decrypted Value {}", decrypted);
Assert.assertTrue(decrypted.compareTo(value)==0);
}
@Test
public void testEncryptDecryptWithSpecificKey() throws Exception {
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
SecureRandom rand = new SecureRandom();
keyGen.init(256, rand);
Key key = keyGen.generateKey();
String value = "myValue";
logger.debug("Original Value {}", value);
String encrypted = EncryptedImpl.encrypt(value, key);
logger.debug("Encrypted Value {}", encrypted);
String decrypted = EncryptedImpl.decrypt(encrypted, key);
logger.debug("Decrypted Value {}", decrypted);
Assert.assertTrue(decrypted.compareTo(value)==0);
}
@Test
public void testEncryptedClass() throws Exception {
String value = "myValue";
Encrypted encrypted = new EncryptedImpl();
encrypted.setEncryptedValue(EncryptedImpl.encrypt(value));
String json = ISMapper.marshal(encrypted);
logger.debug(json);
Encrypted unmarshalled = ISMapper.unmarshal(Encrypted.class, json);
String decrypted = EncryptedImpl.decrypt(unmarshalled.getEncryptedValue());
Assert.assertTrue(decrypted.compareTo(value)==0);
}
@Test
public void testClassDefinition() throws Exception {
Class<? extends Property> clz = Encrypted.class;
String json = TypeBinder.serializeType(clz);
logger.trace(json);
}
@Test
public void testEncryptedSpecilization() throws Exception {
String marshalled = "{\"@class\":\"MyEncrypted\",\"@superClasses\":[\"Encrypted\", \"Property\"],\"value\":\"Encrypted\"}";
Property property = ISMapper.unmarshal(Property.class, marshalled);
logger.debug(ISMapper.marshal(property));
}
@Test
public void decryptTest() throws Exception {
ContextTest.setContext(GCUBE_DEVSEC);
String encryptedValue = "yFdK2wXAOLkNoKKx+gopzA==";
String decryptedValue = EncryptedImpl.decrypt(encryptedValue);
logger.debug("Encrypted Value is : '{}' which decrypted is : '{}'", encryptedValue, decryptedValue);
String reEncryptedValue = EncryptedImpl.encrypt(decryptedValue);
Assert.assertTrue(encryptedValue.compareTo(reEncryptedValue)==0);
}
}

View File

@ -0,0 +1,37 @@
package org.gcube.informationsystem.model.impl.properties;
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.utils.ISMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HeaderTest {
private static Logger logger = LoggerFactory.getLogger(HeaderTest.class);
@Test
public void headerTest() throws Exception {
HeaderImpl header = new HeaderImpl(UUID.randomUUID());
Date date = Calendar.getInstance().getTime();
header.creationTime = date;
header.lastUpdateTime = date;
header.creator = Header.UNKNOWN_USER;
String json = ISMapper.marshal(header);
logger.debug(json);
Header h = ISMapper.unmarshal(Header.class, json);
Assert.assertTrue(h.getCreationTime().compareTo(date)==0);
Assert.assertTrue(h.getLastUpdateTime().compareTo(date)==0);
}
}

View File

@ -1,13 +0,0 @@
package org.gcube.informationsystem.type;
import org.gcube.informationsystem.model.annotations.ISProperty;
import org.gcube.informationsystem.model.entity.Facet;
public interface EntityParentParent extends Facet {
@ISProperty(name="asd", description="desc")
public String getAs();
}

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