Creating Trunk Branch
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-orientdb-hooks@130464 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
commit
c7c2ca2d2a
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<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">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>resource-registry-orientdb-hooks</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,6 @@
|
|||
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
|
|
@ -0,0 +1,5 @@
|
|||
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
|
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
mvn -U clean package -DskipTests=true
|
||||
cp ~/workspace/information-system-orientdb-hooks/target/resource-registry-orientdb-hooks--SNAPSHOT.jar ~/workspace/orientdb-community-2.2.0/lib/
|
|
@ -0,0 +1,56 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>resource-registry-orientdb-hooks</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>Resource Registry OrientDB Hooks</name>
|
||||
<description>Resource Registry OrientDB Hooks</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.orientechnologies</groupId>
|
||||
<artifactId>orientdb-core</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>information-system-model</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>information-system-model-orientdb-binding</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,145 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.orientdb.hooks;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.model.entity.Entity;
|
||||
import org.gcube.informationsystem.model.entity.Facet;
|
||||
import org.gcube.informationsystem.model.orientdb.impl.embedded.Header;
|
||||
import org.gcube.informationsystem.model.relation.Relation;
|
||||
|
||||
import com.orientechnologies.orient.core.db.ODatabaseInternal;
|
||||
import com.orientechnologies.orient.core.db.ODatabaseLifecycleListener;
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.hook.ODocumentHookAbstract;
|
||||
import com.orientechnologies.orient.core.metadata.OMetadata;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OClass;
|
||||
import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
||||
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
* @param <OrientGraphNoTx>
|
||||
*/
|
||||
public class HeaderHook<OrientGraphNoTx> extends ODocumentHookAbstract
|
||||
implements ODatabaseLifecycleListener {
|
||||
|
||||
protected void init(){
|
||||
setIncludeClasses(Entity.NAME, Relation.NAME);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public HeaderHook() {
|
||||
super();
|
||||
//System.out.println("HeaderHook()");
|
||||
init();
|
||||
}
|
||||
|
||||
public HeaderHook(ODatabaseDocument database) {
|
||||
super(database);
|
||||
//System.out.println("HeaderHook(ODatabaseDocument database)");
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
|
||||
return DISTRIBUTED_EXECUTION_MODE.BOTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RESULT onRecordBeforeCreate(final ODocument iDocument) {
|
||||
System.out.println("\n\n--------------\n" + iDocument);
|
||||
|
||||
ODocument oDocument = iDocument.field(Entity.HEADER_PROPERTY, Header.class);
|
||||
if(oDocument==null){
|
||||
System.out.println("Header not present. Going to create it");
|
||||
Header header = new Header();
|
||||
|
||||
UUID uuid = UUID.randomUUID();
|
||||
System.out.println("Setting generated UUID : " + uuid.toString());
|
||||
header.setUUID(uuid);
|
||||
|
||||
System.out.println("Creator is unknown setting as : " + org.gcube.informationsystem.model.embedded.Header.UNKNOWN_USER);
|
||||
header.setCreator(org.gcube.informationsystem.model.embedded.Header.UNKNOWN_USER);
|
||||
|
||||
long timestamp = System.currentTimeMillis();
|
||||
System.out.println("Setting Last Update and Creation Time to " + timestamp);
|
||||
header.setCreationTime(timestamp);
|
||||
header.setLastUpdateTime(timestamp);
|
||||
|
||||
System.out.println("Setting newly create header " + header);
|
||||
iDocument.field(Entity.HEADER_PROPERTY, header);
|
||||
return RESULT.RECORD_CHANGED;
|
||||
}else{
|
||||
System.out.println("Header already present : " + oDocument);
|
||||
return RESULT.RECORD_NOT_CHANGED;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RESULT onRecordBeforeUpdate(final ODocument iDocument) {
|
||||
System.out.println("\n\n--------------\nUpdating Last Update Time");
|
||||
|
||||
ODocument oDocument = iDocument.field(Entity.HEADER_PROPERTY);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
System.out.println("Updating Last Update Time in header of " + iDocument + " to " + timestamp);
|
||||
oDocument.field(Header.LAST_UPDATE_TIME_PROPERTY, timestamp);
|
||||
|
||||
System.out.println("Updated Document is " + iDocument);
|
||||
|
||||
String entityType = iDocument.getClassName();
|
||||
System.out.println("Document Type is " + entityType);
|
||||
|
||||
OMetadata oMetadata = database.getMetadata();
|
||||
OSchema oSchema = oMetadata.getSchema();
|
||||
OClass oClass = oSchema.getClass(entityType);
|
||||
|
||||
if(oClass.isSubClassOf(Facet.NAME)){
|
||||
System.out.println("Updating a Facet. Also Attached Resources Last Update Time MUST be updated to " + timestamp);
|
||||
// TODO
|
||||
// Get all Resources attached to this Facet and set last update time
|
||||
}
|
||||
|
||||
return RESULT.RECORD_CHANGED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PRIORITY getPriority() { return PRIORITY.REGULAR; }
|
||||
|
||||
@Override
|
||||
public void onCreate(@SuppressWarnings("rawtypes") ODatabaseInternal iDatabase) {
|
||||
// REGISTER THE HOOK
|
||||
iDatabase.registerHook(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(@SuppressWarnings("rawtypes") ODatabaseInternal iDatabase) {
|
||||
// REGISTER THE HOOK
|
||||
iDatabase.registerHook(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(@SuppressWarnings("rawtypes") ODatabaseInternal iDatabase) {
|
||||
// REGISTER THE HOOK
|
||||
iDatabase.unregisterHook(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrop(@SuppressWarnings("rawtypes") ODatabaseInternal iDatabase) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateClass(@SuppressWarnings("rawtypes") ODatabaseInternal iDatabase, OClass iClass) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDropClass(@SuppressWarnings("rawtypes") ODatabaseInternal iDatabase, OClass iClass) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocalNodeConfigurationRequest(ODocument iConfiguration) {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<logger name="org.gcube" level="TRACE" />
|
||||
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
Loading…
Reference in New Issue