diff --git a/pom.xml b/pom.xml
index 310b75d..889d30a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,11 +34,6 @@
org.gcube.information-system
information-system-model
-
- org.gcube.information-system
- information-system-model-orientdb-binding
- [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)
-
diff --git a/src/main/java/org/gcube/informationsystem/orientdb/hooks/HeaderHook.java b/src/main/java/org/gcube/informationsystem/orientdb/hooks/HeaderHook.java
index c5701f6..38d0507 100644
--- a/src/main/java/org/gcube/informationsystem/orientdb/hooks/HeaderHook.java
+++ b/src/main/java/org/gcube/informationsystem/orientdb/hooks/HeaderHook.java
@@ -3,16 +3,15 @@
*/
package org.gcube.informationsystem.orientdb.hooks;
-import java.text.SimpleDateFormat;
import java.util.Calendar;
-import java.util.Date;
import java.util.UUID;
+import org.gcube.informationsystem.model.embedded.Header;
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.common.log.OLogManager;
import com.orientechnologies.orient.core.db.ODatabaseInternal;
import com.orientechnologies.orient.core.db.ODatabaseLifecycleListener;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
@@ -29,20 +28,20 @@ import com.orientechnologies.orient.core.record.impl.ODocument;
public class HeaderHook extends ODocumentHookAbstract
implements ODatabaseLifecycleListener {
- protected void init(){
+ protected void init() {
setIncludeClasses(Entity.NAME, Relation.NAME);
}
-
+
@SuppressWarnings("deprecation")
public HeaderHook() {
super();
- //System.out.println("HeaderHook()");
+ // System.out.println("HeaderHook()");
init();
}
-
+
public HeaderHook(ODatabaseDocument database) {
super(database);
- //System.out.println("HeaderHook(ODatabaseDocument database)");
+ // System.out.println("HeaderHook(ODatabaseDocument database)");
init();
}
@@ -53,67 +52,75 @@ public class HeaderHook extends ODocumentHookAbstract
@Override
public RESULT onRecordBeforeCreate(final ODocument iDocument) {
- System.out.println("\n\n--------------\n" + iDocument);
-
+ OLogManager.instance().debug(this, "Checking %s on %s",
+ Header.NAME, iDocument.toJSON());
+
ODocument oDocument = iDocument.field(Entity.HEADER_PROPERTY);
- if(oDocument==null){
- System.out.println("Header not present. Going to create it");
- Header header = new Header();
+ if (oDocument == null) {
+ OLogManager.instance().info(this,
+ "%s not present. Going to create it on %s",
+ Header.NAME, iDocument.toJSON());
+ oDocument = new ODocument(Header.NAME);
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);
-
- Date date = Calendar.getInstance().getTime();
- SimpleDateFormat ft = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
- System.out.println("Setting Last Update and Creation Time to " + ft.format(date));
- header.setCreationTime(date);
- header.setLastUpdateTime(date);
-
- System.out.println("Setting newly create header " + header);
- iDocument.field(Entity.HEADER_PROPERTY, header);
+ oDocument.field(Header.UUID_PROPERTY, uuid.toString());
+
+ OLogManager.instance().debug(this,
+ "Creator is unknown setting as %s", Header.UNKNOWN_USER);
+ oDocument.field(Header.CREATOR_PROPERTY, Header.UNKNOWN_USER);
+
+ long timestamp = Calendar.getInstance().getTimeInMillis();
+ oDocument.field(Header.CREATION_TIME_PROPERTY, timestamp);
+ oDocument.field(Header.LAST_UPDATE_TIME_PROPERTY, timestamp);
+
+ iDocument.field(Entity.HEADER_PROPERTY, oDocument);
+ OLogManager.instance().info(this,
+ "%s has now an %s", iDocument.toJSON(), Header.NAME);
return RESULT.RECORD_CHANGED;
- }else{
- System.out.println("Header already present : " + oDocument);
+ } else {
+ OLogManager.instance().info(this, "%s already present on %s",
+ Header.NAME, iDocument.toJSON());
return RESULT.RECORD_NOT_CHANGED;
}
}
-
+
@Override
public RESULT onRecordBeforeUpdate(final ODocument iDocument) {
- System.out.println("\n\n--------------\nUpdating Last Update Time");
+ OLogManager.instance().debug(this, "Updating Last Update Time on %s of %s",
+ Header.NAME, iDocument.toJSON());
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(org.gcube.informationsystem.model.embedded.Header.LAST_UPDATE_TIME_PROPERTY, timestamp);
-
- System.out.println("Updated Document is " + iDocument);
-
+ Calendar calendar = Calendar.getInstance();
+ long timestamp = calendar.getTimeInMillis();
+ oDocument.field(Header.LAST_UPDATE_TIME_PROPERTY, timestamp);
+
+ OLogManager.instance().info(this, "Updated Document is %s", 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
+
+ if (oClass.isSubClassOf(Facet.NAME)) {
+ OLogManager.instance().warn(this,
+ "TODO : Also Last Update Time of Resources pointing to this Facet MUST be updated to %T",
+ calendar);
+ // 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) {
+ public PRIORITY getPriority() {
+ return PRIORITY.REGULAR;
+ }
+
+ @Override
+ public void onCreate(
+ @SuppressWarnings("rawtypes") ODatabaseInternal iDatabase) {
// REGISTER THE HOOK
iDatabase.registerHook(this);
}
@@ -125,25 +132,31 @@ public class HeaderHook extends ODocumentHookAbstract
}
@Override
- public void onClose(@SuppressWarnings("rawtypes") ODatabaseInternal iDatabase) {
+ public void onClose(
+ @SuppressWarnings("rawtypes") ODatabaseInternal iDatabase) {
// REGISTER THE HOOK
- iDatabase.unregisterHook(this);
+ iDatabase.unregisterHook(this);
}
@Override
public void onDrop(@SuppressWarnings("rawtypes") ODatabaseInternal iDatabase) {
+ iDatabase.unregisterHook(this);
}
@Override
- public void onCreateClass(@SuppressWarnings("rawtypes") ODatabaseInternal iDatabase, OClass iClass) {
+ public void onCreateClass(
+ @SuppressWarnings("rawtypes") ODatabaseInternal iDatabase,
+ OClass iClass) {
}
@Override
- public void onDropClass(@SuppressWarnings("rawtypes") ODatabaseInternal iDatabase, OClass iClass) {
+ public void onDropClass(
+ @SuppressWarnings("rawtypes") ODatabaseInternal iDatabase,
+ OClass iClass) {
}
@Override
public void onLocalNodeConfigurationRequest(ODocument iConfiguration) {
}
-
+
}
\ No newline at end of file