incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmatth...@apache.org
Subject svn commit: r1103224 - in /incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src: main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/ main/java/org/apache/isis/runtimes/dflt/o...
Date Sat, 14 May 2011 20:58:28 GMT
Author: rmatthews
Date: Sat May 14 20:58:27 2011
New Revision: 1103224

URL: http://svn.apache.org/viewvc?rev=1103224&view=rev
Log:
introduced encryption of values in NOSQL store (only provides a very simple method at the moment (rot13) but the interface allows for proper schemes to be introduced).

Added:
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/DataEncrypter.java   (with props)
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoEncryption.java   (with props)
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/Rot13Encryption.java   (with props)
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateReaderTest.java   (with props)
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateWriterTest.java   (with props)
Modified:
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCreateObjectCommand.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStore.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlPersistorMechanismInstaller.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlSaveObjectCommand.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReader.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/StateReader.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/StateWriter.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateReader.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateWriter.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateReader.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateWriter.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReaderTest.java
    incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java

Added: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/DataEncrypter.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/DataEncrypter.java?rev=1103224&view=auto
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/DataEncrypter.java (added)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/DataEncrypter.java Sat May 14 20:58:27 2011
@@ -0,0 +1,30 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.runtimes.dflt.objectstores.nosql;
+
+public interface DataEncrypter {
+    
+    String getType();
+    
+    String encrypt(String plainText);
+    
+    String decrypt(String encryptedText);
+
+}
+

Propchange: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/DataEncrypter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoEncryption.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoEncryption.java?rev=1103224&view=auto
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoEncryption.java (added)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoEncryption.java Sat May 14 20:58:27 2011
@@ -0,0 +1,35 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.runtimes.dflt.objectstores.nosql;
+
+public class NoEncryption implements DataEncrypter {
+
+    public String getType() {
+        return "none";
+    }
+
+    public String encrypt(String plainText) {
+        return plainText;
+    }
+
+    public String decrypt(String encryptedText) {
+        return encryptedText;
+    }
+
+}

Propchange: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoEncryption.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCreateObjectCommand.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCreateObjectCommand.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCreateObjectCommand.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlCreateObjectCommand.java Sat May 14 20:58:27 2011
@@ -23,9 +23,12 @@ import org.apache.isis.runtimes.dflt.run
 
 final class NoSqlCreateObjectCommand extends WriteObjectCommand implements CreateObjectCommand {
 
-    public NoSqlCreateObjectCommand(final KeyCreator keyCreator, final VersionCreator versionCreator,
-        final ObjectAdapter object) {
-        super(false, keyCreator, versionCreator, object);
+    public NoSqlCreateObjectCommand(
+            final KeyCreator keyCreator,
+            final VersionCreator versionCreator,
+            final DataEncrypter dataEncrypter,
+            final ObjectAdapter object) {
+        super(false, keyCreator, versionCreator, dataEncrypter, object);
     }
 
 }

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStore.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStore.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStore.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStore.java Sat May 14 20:58:27 2011
@@ -43,6 +43,7 @@ import org.apache.isis.runtimes.dflt.run
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceQuery;
 import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
 
+
 public class NoSqlObjectStore implements ObjectStore {
     private final NoSqlDataDatabase database;
     private final Map<String, Oid> serviceCache = new HashMap<String, Oid>();
@@ -50,14 +51,23 @@ public class NoSqlObjectStore implements
     private final VersionCreator versionCreator;
     private final ObjectReader objectReader = new ObjectReader();
     private final NoSqlOidGenerator oidGenerator;
+    private final DataEncrypter wrtingDataEncrypter;
+    private final Map<String, DataEncrypter> availableDataEncrypters;
     private final boolean isDataLoaded;
 
-    public NoSqlObjectStore(final NoSqlDataDatabase db, final NoSqlOidGenerator oidGenerator,
-        final KeyCreator keyCreator, final VersionCreator versionCreator) {
+    public NoSqlObjectStore(
+            final NoSqlDataDatabase db,
+            final NoSqlOidGenerator oidGenerator,
+            final KeyCreator keyCreator,
+            final VersionCreator versionCreator,
+            final DataEncrypter writingDataEncrypter,
+            final Map<String, DataEncrypter> availableDataEncrypters) {
         this.database = db;
         this.oidGenerator = oidGenerator;
         this.keyCreator = keyCreator;
         this.versionCreator = versionCreator;
+        this.wrtingDataEncrypter = writingDataEncrypter;
+        this.availableDataEncrypters = availableDataEncrypters;
 
         db.open();
         isDataLoaded = db.containsData();
@@ -72,10 +82,11 @@ public class NoSqlObjectStore implements
     public CreateObjectCommand createCreateObjectCommand(final ObjectAdapter object) {
         // TODO should this be done at a higher level so it is applicable for all OSes
         if (object.getSpecification().isAggregated()) {
-            // throw new UnexpectedCallException("Aggregated objects should not be created outside of their owner");
+            // throw new
+            // UnexpectedCallException("Aggregated objects should not be created outside of their owner");
             return null;
         } else {
-            return new NoSqlCreateObjectCommand(keyCreator, versionCreator, object);
+            return new NoSqlCreateObjectCommand(keyCreator, versionCreator, wrtingDataEncrypter, object);
         }
     }
 
@@ -95,7 +106,7 @@ public class NoSqlObjectStore implements
         if (rootAdapter.getOid() instanceof AggregatedOid) {
             throw new NoSqlStoreException("Unexpected aggregated object to save: " + rootAdapter + " (" + adapter + ")");
         }
-        return new NoSqlSaveObjectCommand(keyCreator, versionCreator, rootAdapter);
+        return new NoSqlSaveObjectCommand(keyCreator, versionCreator, wrtingDataEncrypter, rootAdapter);
     }
 
     /**
@@ -118,13 +129,15 @@ public class NoSqlObjectStore implements
         return instances.toArray(new ObjectAdapter[instances.size()]);
     }
 
-    private void instances(final PersistenceQuery persistenceQuery, final ObjectSpecification specification,
-        final List<ObjectAdapter> instances) {
+    private void instances(
+            final PersistenceQuery persistenceQuery,
+            final ObjectSpecification specification,
+            final List<ObjectAdapter> instances) {
         String specificationName = specification.getFullIdentifier();
         final Iterator<StateReader> instanceData = database.instancesOf(specificationName);
         while (instanceData.hasNext()) {
             final StateReader reader = instanceData.next();
-            final ObjectAdapter instance = objectReader.load(reader, keyCreator, versionCreator);
+            final ObjectAdapter instance = objectReader.load(reader, keyCreator, versionCreator, availableDataEncrypters);
             // TODO deal with this natively
             if (persistenceQuery instanceof PersistenceQueryBuiltIn) {
                 if (!((PersistenceQueryBuiltIn) persistenceQuery).matches(instance)) {
@@ -143,7 +156,7 @@ public class NoSqlObjectStore implements
     public ObjectAdapter getObject(final Oid oid, final ObjectSpecification hint) {
         final String key = keyCreator.key(oid);
         final StateReader reader = database.getInstance(key, hint.getFullIdentifier());
-        return objectReader.load(reader, keyCreator, versionCreator);
+        return objectReader.load(reader, keyCreator, versionCreator, availableDataEncrypters);
     }
 
     @Override
@@ -174,14 +187,12 @@ public class NoSqlObjectStore implements
     }
 
     @Override
-    public void reset() {
-    }
+    public void reset() {}
 
     @Override
     public void resolveField(final ObjectAdapter object, final ObjectAssociation field) {
         final ObjectAdapter fieldValue = field.get(object);
-        if (fieldValue != null && !fieldValue.getResolveState().isResolved()
-            && !fieldValue.getSpecification().isAggregated()) {
+        if (fieldValue != null && !fieldValue.getResolveState().isResolved() && !fieldValue.getSpecification().isAggregated()) {
             resolveImmediately(fieldValue);
         }
     }
@@ -191,12 +202,13 @@ public class NoSqlObjectStore implements
         final Oid oid = object.getOid();
         ;
         if (oid instanceof AggregatedOid) {
-            // throw new UnexpectedCallException("Aggregated objects should not need to be resolved: " + object);
+            // throw new UnexpectedCallException("Aggregated objects should not need to be resolved: " +
+            // object);
         } else {
             final String specificationName = object.getSpecification().getFullIdentifier();
             final String key = keyCreator.key(oid);
             final StateReader reader = database.getInstance(key, specificationName);
-            objectReader.update(reader, keyCreator, versionCreator, object);
+            objectReader.update(reader, keyCreator, versionCreator, availableDataEncrypters, object);
         }
     }
 
@@ -226,16 +238,13 @@ public class NoSqlObjectStore implements
     }
 
     @Override
-    public void abortTransaction() {
-    }
+    public void abortTransaction() {}
 
     @Override
-    public void endTransaction() {
-    }
+    public void endTransaction() {}
 
     @Override
-    public void startTransaction() {
-    }
+    public void startTransaction() {}
 
     // ////////////////////////////////////////////////////////////////
     // Dependencies (from context)

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlPersistorMechanismInstaller.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlPersistorMechanismInstaller.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlPersistorMechanismInstaller.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlPersistorMechanismInstaller.java Sat May 14 20:58:27 2011
@@ -19,6 +19,9 @@
 
 package org.apache.isis.runtimes.dflt.objectstores.nosql;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.isis.core.commons.config.IsisConfiguration;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapterFactory;
 import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.ObjectStorePersistenceMechanismInstallerAbstract;
@@ -60,7 +63,14 @@ public abstract class NoSqlPersistorMech
             final VersionCreator versionCreator = createVersionCreator();
             final NoSqlDataDatabase db = createNoSqlDatabase(configuration);
             final NoSqlOidGenerator oidGenerator = createOidGenerator(db);
-            objectStore = new NoSqlObjectStore(db, oidGenerator, keyCreator, versionCreator);
+            
+            DataEncrypter writingDataEncrypter = new Rot13Encryption();
+            Map<String, DataEncrypter> availableDataEncrypters = new HashMap<String, DataEncrypter>();
+            availableDataEncrypters.put(writingDataEncrypter.getType(), writingDataEncrypter);
+            DataEncrypter passThoughEncrypter = new NoEncryption();
+            availableDataEncrypters.put(passThoughEncrypter.getType(), passThoughEncrypter);
+            
+            objectStore = new NoSqlObjectStore(db, oidGenerator, keyCreator, versionCreator, writingDataEncrypter, availableDataEncrypters);
         }
         return objectStore;
     }

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlSaveObjectCommand.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlSaveObjectCommand.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlSaveObjectCommand.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlSaveObjectCommand.java Sat May 14 20:58:27 2011
@@ -23,9 +23,12 @@ import org.apache.isis.runtimes.dflt.run
 
 final class NoSqlSaveObjectCommand extends WriteObjectCommand implements SaveObjectCommand {
 
-    public NoSqlSaveObjectCommand(final KeyCreator keyCreator, final VersionCreator versionCreator,
-        final ObjectAdapter object) {
-        super(true, keyCreator, versionCreator, object);
+    public NoSqlSaveObjectCommand(
+            final KeyCreator keyCreator,
+            final VersionCreator versionCreator,
+            final DataEncrypter dataEncrypter,
+            final ObjectAdapter object) {
+        super(true, keyCreator, versionCreator, dataEncrypter, object);
     }
 
 }

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReader.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReader.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReader.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReader.java Sat May 14 20:58:27 2011
@@ -20,6 +20,7 @@
 package org.apache.isis.runtimes.dflt.objectstores.nosql;
 
 import java.util.List;
+import java.util.Map;
 
 import org.apache.isis.core.commons.exceptions.UnexpectedCallException;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
@@ -39,7 +40,11 @@ import org.apache.isis.runtimes.dflt.run
 
 class ObjectReader {
 
-    public ObjectAdapter load(final StateReader reader, final KeyCreator keyCreator, final VersionCreator versionCreator) {
+    public ObjectAdapter load(
+            final StateReader reader,
+            final KeyCreator keyCreator,
+            final VersionCreator versionCreator,
+            final Map<String, DataEncrypter> dataEncrypters) {
         final String className = reader.readObjectType();
         final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(className);
         final String id = reader.readId();
@@ -64,18 +69,26 @@ class ObjectReader {
 
         // TODO move lock to common method
         // object.setOptimisticLock(version);
-        loadState(reader, keyCreator, versionCreator, object);
+        loadState(reader, keyCreator, versionCreator, dataEncrypters, object);
         return object;
     }
 
-    public void update(final StateReader reader, final KeyCreator keyCreator, final VersionCreator versionCreator,
-        final ObjectAdapter object) {
-        loadState(reader, keyCreator, versionCreator, object);
-    }
-
-    private void loadState(final StateReader reader, final KeyCreator keyCreator, final VersionCreator versionCreator,
-        final ObjectAdapter object) {
-        final ResolveState resolveState = ResolveState.RESOLVING;
+    public void update(
+            final StateReader reader,
+            final KeyCreator keyCreator,
+            final VersionCreator versionCreator,
+            final Map<String, DataEncrypter> dataEncrypters,
+            final ObjectAdapter object) {
+        loadState(reader, keyCreator, versionCreator, dataEncrypters, object);
+    }
+
+    private void loadState(
+            final StateReader reader,
+            final KeyCreator keyCreator,
+            final VersionCreator versionCreator,
+            final Map<String, DataEncrypter> dataEncrypters,
+            final ObjectAdapter object) {
+    final ResolveState resolveState = ResolveState.RESOLVING;
         object.changeState(resolveState);
         Version version = null;
         final String versionString = reader.readVersion();
@@ -84,12 +97,17 @@ class ObjectReader {
             final String time = reader.readTime();
             version = versionCreator.version(versionString, user, time);
         }
-        readFields(reader, object, keyCreator);
+        String encryptionType = reader.readEncrytionType();
+        readFields(reader, object, keyCreator, dataEncrypters.get(encryptionType));
         object.setOptimisticLock(version);
         object.changeState(resolveState.getEndState());
     }
 
-    private void readFields(final StateReader reader, final ObjectAdapter object, final KeyCreator keyCreator) {
+    private void readFields(
+            final StateReader reader,
+            final ObjectAdapter object,
+            final KeyCreator keyCreator,
+            final DataEncrypter dataEncrypter) {
         final ObjectAssociationContainer specification = object.getSpecification();
         final List<ObjectAssociation> associations = specification.getAssociations();
         for (final ObjectAssociation association : associations) {
@@ -97,53 +115,65 @@ class ObjectReader {
                 continue;
             }
             if (association.isOneToManyAssociation()) {
-                readCollection(reader, keyCreator, (OneToManyAssociation) association, object);
+                readCollection(reader, keyCreator, dataEncrypter, (OneToManyAssociation) association, object);
             } else if (association.getSpecification().isValue()) {
-                readValue(reader, (OneToOneAssociation) association, object);
+                readValue(reader, dataEncrypter, (OneToOneAssociation) association, object);
             } else if (association.getSpecification().isAggregated()) {
-                readAggregate(reader, keyCreator, (OneToOneAssociation) association, object);
+                readAggregate(reader, keyCreator, dataEncrypter, (OneToOneAssociation) association, object);
             } else {
                 readReference(reader, keyCreator, (OneToOneAssociation) association, object);
             }
         }
     }
 
-    private void readAggregate(final StateReader reader, final KeyCreator keyCreator,
-        final OneToOneAssociation association, final ObjectAdapter object) {
+    private void readAggregate(
+            final StateReader reader,
+            final KeyCreator keyCreator,
+            final DataEncrypter dataEncrypter,
+            final OneToOneAssociation association,
+            final ObjectAdapter object) {
         final String id = association.getId();
         final StateReader aggregateReader = reader.readAggregate(id);
         if (aggregateReader != null) {
             final String id2 = aggregateReader.readId();
             final AggregatedOid oid = new AggregatedOid(object.getOid(), id2);
-            final ObjectAdapter fieldObject = restoreAggregatedObject(aggregateReader, oid, keyCreator);
+            final ObjectAdapter fieldObject = restoreAggregatedObject(aggregateReader, oid, keyCreator, dataEncrypter);
             association.initAssociation(object, fieldObject);
         } else {
             association.initAssociation(object, null);
         }
     }
 
-    private ObjectAdapter restoreAggregatedObject(final StateReader aggregateReader, final Oid oid,
-        final KeyCreator keyCreator) {
+    private ObjectAdapter restoreAggregatedObject(
+            final StateReader aggregateReader,
+            final Oid oid,
+            final KeyCreator keyCreator,
+            final DataEncrypter dataEncrypter) {
         final String objectType = aggregateReader.readObjectType();
         final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(objectType);
         final ObjectAdapter fieldObject = getAdapter(specification, oid);
         if (fieldObject.getResolveState().isGhost()) {
             final ResolveState resolveState = ResolveState.RESOLVING;
             fieldObject.changeState(resolveState);
-            readFields(aggregateReader, fieldObject, keyCreator);
+            readFields(aggregateReader, fieldObject, keyCreator, dataEncrypter);
             fieldObject.changeState(resolveState.getEndState());
         }
         return fieldObject;
     }
 
-    private void readValue(final StateReader reader, final OneToOneAssociation association, final ObjectAdapter object) {
+    private void readValue(
+            final StateReader reader,
+            final DataEncrypter dataEncrypter,
+            final OneToOneAssociation association,
+            final ObjectAdapter object) {
         final String fieldData = reader.readField(association.getId());
         if (fieldData != null) {
             if (fieldData.equals("null")) {
                 association.initAssociation(object, null);
             } else {
                 final EncodableFacet encodeableFacet = association.getSpecification().getFacet(EncodableFacet.class);
-                final ObjectAdapter value = encodeableFacet.fromEncodedString(fieldData);
+                String decryptedData = dataEncrypter.decrypt(fieldData);
+                final ObjectAdapter value = encodeableFacet.fromEncodedString(decryptedData);
                 association.initAssociation(object, value);
             }
         }
@@ -163,8 +193,12 @@ class ObjectReader {
         association.initAssociation(object, fieldObject);
     }
 
-    private void readCollection(final StateReader reader, final KeyCreator keyCreator,
-        final OneToManyAssociation association, final ObjectAdapter object) {
+    private void readCollection(
+            final StateReader reader,
+            final KeyCreator keyCreator,
+            final DataEncrypter dataEncrypter,
+            final OneToManyAssociation association,
+            final ObjectAdapter object) {
         final ObjectAdapter collection = association.get(object);
         final CollectionFacet facet = collection.getSpecification().getFacet(CollectionFacet.class);
         if (association.getSpecification().isAggregated()) {
@@ -175,7 +209,7 @@ class ObjectReader {
             for (final StateReader elementReader : readers) {
                 final String id = elementReader.readId();
                 final AggregatedOid oid = new AggregatedOid(object.getOid(), id);
-                elements[i++] = restoreAggregatedObject(elementReader, oid, keyCreator);
+                elements[i++] = restoreAggregatedObject(elementReader, oid, keyCreator, dataEncrypter);
             }
             facet.init(collection, elements);
         } else {

Added: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/Rot13Encryption.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/Rot13Encryption.java?rev=1103224&view=auto
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/Rot13Encryption.java (added)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/Rot13Encryption.java Sat May 14 20:58:27 2011
@@ -0,0 +1,58 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.runtimes.dflt.objectstores.nosql;
+
+public class Rot13Encryption implements DataEncrypter {
+
+    public String getType() {
+        return "rot13";
+    }
+
+    public String encrypt(String plainText) {
+        return encode(plainText);
+    }
+
+    public String decrypt(String encryptedText) {
+        return encode(encryptedText);
+    }
+
+    private String encode(String plainText) {
+        if (plainText == null) {
+            return plainText;
+        }
+
+        // encode plainText
+        String encodedMessage = "";
+        for (int i = 0; i < plainText.length(); i++) {
+            char c = plainText.charAt(i);
+            if (c >= 'a' && c <= 'm') {
+                c += 13;
+            } else if (c >= 'n' && c <= 'z') {
+                c -= 13;
+            } else if (c >= 'A' && c <= 'M') {
+                c += 13;
+            } else if (c >= 'N' && c <= 'Z') {
+                c -= 13;
+            }
+            encodedMessage += c;
+        }
+        return encodedMessage;
+    }
+
+}

Propchange: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/Rot13Encryption.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/StateReader.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/StateReader.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/StateReader.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/StateReader.java Sat May 14 20:58:27 2011
@@ -29,6 +29,8 @@ public interface StateReader {
 
     String readField(String id);
 
+    String readEncrytionType();
+
     String readObjectType();
 
     String readId();

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/StateWriter.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/StateWriter.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/StateWriter.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/StateWriter.java Sat May 14 20:58:27 2011
@@ -28,6 +28,8 @@ public interface StateWriter {
     void writeId(String oid);
 
     void writeType(String type);
+    
+    void writeEncryptionType(String type);
 
     void writeField(String id, String data);
 

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommand.java Sat May 14 20:58:27 2011
@@ -38,13 +38,19 @@ class WriteObjectCommand implements Pers
     private final KeyCreator keyCreator;
     private final ObjectAdapter object;
     private final VersionCreator versionCreator;
+    private final DataEncrypter dataEncrypter;
     private final boolean isUpdate;
 
-    WriteObjectCommand(final boolean isUpdate, final KeyCreator keyCreator, final VersionCreator versionCreator,
-        final ObjectAdapter object) {
+    WriteObjectCommand(
+            final boolean isUpdate,
+            final KeyCreator keyCreator,
+            final VersionCreator versionCreator,
+            final DataEncrypter dataEncrypter,
+            final ObjectAdapter object) {
         this.isUpdate = isUpdate;
         this.keyCreator = keyCreator;
         this.versionCreator = versionCreator;
+        this.dataEncrypter = dataEncrypter;
         this.object = object;
     }
 
@@ -66,6 +72,7 @@ class WriteObjectCommand implements Pers
             writer.writeVersion(version, versionCreator.versionString(newVersion));
             writer.writeUser(newVersion.getUser());
             writer.writeTime(versionCreator.timeString(newVersion));
+            writer.writeEncryptionType(dataEncrypter.getType());
         }
 
         if (isUpdate) {
@@ -128,6 +135,7 @@ class WriteObjectCommand implements Pers
         } else {
             final EncodableFacet encodeableFacet = value.getSpecification().getFacet(EncodableFacet.class);
             data = encodeableFacet.toEncodedString(value);
+            data  = dataEncrypter.encrypt(data);
         }
         writer.writeField(association.getId(), data);
     }

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateReader.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateReader.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateReader.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateReader.java Sat May 14 20:58:27 2011
@@ -99,6 +99,21 @@ public class JsonStateReader implements 
     }
 
     @Override
+    public String readEncrytionType() {
+        try {
+            String encryptionType;
+            if (instance.has("_encrypt")) {
+                encryptionType = instance.getString("_encrypt");
+            } else {
+                encryptionType = "none";
+            }
+            return encryptionType;
+        } catch (final JSONException e) {
+            throw new NoSqlStoreException("failed to read field _encrypt", e);
+        }
+    }
+        
+    @Override
     public String readUser() {
         return readRequiredField("_user");
     }
@@ -113,7 +128,7 @@ public class JsonStateReader implements 
             final Object value = instance.get(name);
             return (String) value;
         } catch (final JSONException e) {
-            throw new NoSqlStoreException("failed to read long field value", e);
+            throw new NoSqlStoreException("failed to read field " + name, e);
         }
     }
 

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateWriter.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateWriter.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateWriter.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateWriter.java Sat May 14 20:58:27 2011
@@ -65,6 +65,11 @@ public class JsonStateWriter implements 
     }
 
     @Override
+    public void writeEncryptionType(String type) {
+        writeField("_encrypt", type);
+    }
+    
+    @Override
     public void writeVersion(final String currentVersion, final String newVersion) {
         this.currentVersion = currentVersion;
         this.newVersion = newVersion;
@@ -128,4 +133,5 @@ public class JsonStateWriter implements 
             throw new NoSqlStoreException(e);
         }
     }
+
 }

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateReader.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateReader.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateReader.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateReader.java Sat May 14 20:58:27 2011
@@ -69,6 +69,11 @@ public class MongoStateReader implements
     }
 
     @Override
+    public String readEncrytionType() {
+        return (String) instance.get("_encrypt");
+    }
+    
+    @Override
     public String readObjectType() {
         return (String) instance.get("_type");
     }

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateWriter.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateWriter.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateWriter.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/mongo/MongoStateWriter.java Sat May 14 20:58:27 2011
@@ -64,6 +64,8 @@ public class MongoStateWriter implements
         dbObject.put(id, Long.toString(l));
     }
 
+    public void writeEncryptionType(String type) {}
+    
     @Override
     public void writeVersion(final String currentVersion, final String newVersion) {
     }

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlObjectStoreTest.java Sat May 14 20:58:27 2011
@@ -19,13 +19,12 @@
 
 package org.apache.isis.runtimes.dflt.objectstores.nosql;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.isis.core.commons.exceptions.UnexpectedCallException;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.ResolveState;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
@@ -41,6 +40,10 @@ import org.jmock.Mockery;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 public class NoSqlObjectStoreTest {
 
     private Mockery context;
@@ -74,8 +77,25 @@ public class NoSqlObjectStoreTest {
         });
         keyCreator = context.mock(KeyCreator.class);
         versionCreator = context.mock(VersionCreator.class);
-        ;
-        store = new NoSqlObjectStore(db, new NoSqlOidGenerator(db), keyCreator, versionCreator);
+        
+        Map<String, DataEncrypter> dataEncrypter = new HashMap<String, DataEncrypter>();
+        DataEncrypter dataEncrypter1 = new DataEncrypter() {
+            public String getType() {
+                return "etc";
+            }
+
+            public String encrypt(String plainText) {
+                throw new UnexpectedCallException();
+            }
+
+            public String decrypt(String encryptedText) {
+                return encryptedText.substring(3);
+            }
+        };
+        dataEncrypter.put(dataEncrypter1.getType(), dataEncrypter1);
+
+        
+        store = new NoSqlObjectStore(db, new NoSqlOidGenerator(db), keyCreator, versionCreator, null, dataEncrypter);
     }
 
     @Test
@@ -113,7 +133,7 @@ public class NoSqlObjectStoreTest {
                 one(db).close();
             }
         });
-        store = new NoSqlObjectStore(db, new NoSqlOidGenerator(db), null, null);
+        store = new NoSqlObjectStore(db, new NoSqlOidGenerator(db), null, null, null, new HashMap<String, DataEncrypter>());
         assertTrue(store.isFixturesInstalled());
     }
 

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReaderTest.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReaderTest.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ObjectReaderTest.java Sat May 14 20:58:27 2011
@@ -19,11 +19,11 @@
 
 package org.apache.isis.runtimes.dflt.objectstores.nosql;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.isis.core.commons.exceptions.UnexpectedCallException;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.ResolveState;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
@@ -38,6 +38,9 @@ import org.jmock.Mockery;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
 public class ObjectReaderTest {
 
     private ObjectReader objectReader;
@@ -46,6 +49,7 @@ public class ObjectReaderTest {
     private Mockery context;
     private KeyCreator keyCreator;
     private VersionCreator versionCreator;
+    private Map<String, DataEncrypter> dataEncrypter;
 
     @Before
     public void setup() {
@@ -58,7 +62,24 @@ public class ObjectReaderTest {
         objectReader = new ObjectReader();
         keyCreator = context.mock(KeyCreator.class);
         versionCreator = context.mock(VersionCreator.class);
-        ;
+        
+        
+        dataEncrypter = new HashMap<String, DataEncrypter>();
+        DataEncrypter dataEncrypter1 = new DataEncrypter() {
+            public String getType() {
+                return "etc1";
+            }
+
+            public String encrypt(String plainText) {
+                throw new UnexpectedCallException();
+            }
+
+            public String decrypt(String encryptedText) {
+                return encryptedText.substring(3);
+            }
+        };
+        dataEncrypter.put(dataEncrypter1.getType(), dataEncrypter1);
+
     }
 
     @Test
@@ -73,6 +94,8 @@ public class ObjectReaderTest {
                 one(reader1).readId();
                 will(returnValue("3"));
 
+                one(reader1).readEncrytionType();
+                will(returnValue("etc1"));
                 one(reader1).readVersion();
                 will(returnValue("3"));
                 one(reader1).readUser();
@@ -87,7 +110,7 @@ public class ObjectReaderTest {
             }
         });
 
-        final ObjectAdapter readObject = objectReader.load(reader1, keyCreator, versionCreator);
+        final ObjectAdapter readObject = objectReader.load(reader1, keyCreator, versionCreator, dataEncrypter);
         assertEquals(SerialOid.createPersistent(3), readObject.getOid());
         assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
 
@@ -109,6 +132,8 @@ public class ObjectReaderTest {
                 one(reader2).readId();
                 will(returnValue("4"));
 
+                one(reader2).readEncrytionType();
+                will(returnValue("etc1"));
                 one(reader2).readVersion();
                 will(returnValue("3"));
                 one(reader2).readUser();
@@ -135,7 +160,7 @@ public class ObjectReaderTest {
             }
         });
 
-        final ObjectAdapter readObject = objectReader.load(reader2, keyCreator, versionCreator);
+        final ObjectAdapter readObject = objectReader.load(reader2, keyCreator, versionCreator, dataEncrypter);
         assertEquals(SerialOid.createPersistent(4), readObject.getOid());
         assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
 
@@ -159,6 +184,8 @@ public class ObjectReaderTest {
                 one(reader2).readId();
                 will(returnValue("5"));
 
+                one(reader2).readEncrytionType();
+                will(returnValue("etc1"));
                 one(reader2).readVersion();
                 will(returnValue("3"));
                 one(reader2).readUser();
@@ -187,7 +214,7 @@ public class ObjectReaderTest {
             }
         });
 
-        final ObjectAdapter readObject = objectReader.load(reader2, keyCreator, versionCreator);
+        final ObjectAdapter readObject = objectReader.load(reader2, keyCreator, versionCreator, dataEncrypter);
         assertEquals(SerialOid.createPersistent(5), readObject.getOid());
         assertEquals(ResolveState.RESOLVED, readObject.getResolveState());
 
@@ -206,6 +233,9 @@ public class ObjectReaderTest {
         setupObject1();
         context.checking(new Expectations() {
             {
+
+                one(reader1).readEncrytionType();
+                will(returnValue("etc1"));
                 one(reader1).readVersion();
                 will(returnValue("3"));
                 one(reader1).readUser();
@@ -216,12 +246,11 @@ public class ObjectReaderTest {
             }
         });
 
-        final ObjectSpecification specification =
-            IsisContext.getSpecificationLoader().loadSpecification(ExampleValuePojo.class);
-        final ObjectAdapter readObject =
-            IsisContext.getPersistenceSession().recreateAdapter(SerialOid.createPersistent(4), specification);
+        final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(ExampleValuePojo.class);
+        final ObjectAdapter readObject = IsisContext.getPersistenceSession().recreateAdapter(SerialOid.createPersistent(4),
+                specification);
 
-        objectReader.update(reader1, keyCreator, versionCreator, readObject);
+        objectReader.update(reader1, keyCreator, versionCreator, dataEncrypter, readObject);
 
         final ExampleValuePojo pojo = (ExampleValuePojo) readObject.getObject();
         assertEquals("Fred Smith", pojo.getName());
@@ -235,10 +264,10 @@ public class ObjectReaderTest {
         context.checking(new Expectations() {
             {
                 one(reader1).readField("name");
-                will(returnValue("Fred Smith"));
+                will(returnValue("ENCFred Smith"));
 
                 one(reader1).readField("size");
-                will(returnValue("34"));
+                will(returnValue("ENC34"));
 
                 one(reader1).readField("nullable");
                 will(returnValue("null"));

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java?rev=1103224&r1=1103223&r2=1103224&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/WriteObjectCommandTest.java Sat May 14 20:58:27 2011
@@ -19,6 +19,7 @@
 
 package org.apache.isis.runtimes.dflt.objectstores.nosql;
 
+import org.apache.isis.core.commons.exceptions.UnexpectedCallException;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
 import org.apache.isis.core.metamodel.adapter.version.Version;
@@ -44,6 +45,7 @@ public class WriteObjectCommandTest {
     private KeyCreator keyCreator;
     private NoSqlCommandContext commandContext;
     private Mockery context;
+    private DataEncrypter dataEncrypter;
 
     @Before
     public void setup() {
@@ -81,7 +83,6 @@ public class WriteObjectCommandTest {
         commandContext = context.mock(NoSqlCommandContext.class);
         keyCreator = context.mock(KeyCreator.class);
         versionCreator = context.mock(VersionCreator.class);
-        ;
 
         final Version version = new SerialNumberVersion(2, "username", null);
 
@@ -95,6 +96,20 @@ public class WriteObjectCommandTest {
                 will(returnValue("1057"));
             }
         });
+        
+        dataEncrypter = new DataEncrypter() {
+            public String getType() {
+                return "etc1";
+            }
+
+            public String encrypt(String plainText) {
+                return "ENC" + plainText;
+            }
+
+            public String decrypt(String encryptedText) {
+                throw new UnexpectedCallException();
+            }
+        };
 
     }
 
@@ -111,19 +126,20 @@ public class WriteObjectCommandTest {
 
                 one(writer).writeId("3");
                 one(writer).writeType(specification.getFullIdentifier());
-                one(writer).writeField("name", "Fred Smith");
-                one(writer).writeField("size", "108");
+                one(writer).writeField("name", "ENCFred Smith");
+                one(writer).writeField("size", "ENC108");
                 one(writer).writeField("nullable", null);
                 one(writer).writeVersion(null, "2");
                 one(writer).writeUser("username");
                 one(writer).writeTime("1057");
-
+                one(writer).writeEncryptionType("etc1");
+                
                 one(commandContext).insert(writer);
 
             }
         });
 
-        new WriteObjectCommand(false, keyCreator, versionCreator, object1).execute(commandContext);
+        new WriteObjectCommand(false, keyCreator, versionCreator, dataEncrypter, object1).execute(commandContext);
 
         context.assertIsSatisfied();
     }
@@ -148,12 +164,13 @@ public class WriteObjectCommandTest {
                 one(writer).writeVersion(null, "2");
                 one(writer).writeUser("username");
                 one(writer).writeTime("1057");
+                one(writer).writeEncryptionType("etc1");
 
                 one(commandContext).insert(writer);
             }
         });
 
-        new WriteObjectCommand(false, keyCreator, versionCreator, object3).execute(commandContext);
+        new WriteObjectCommand(false, keyCreator, versionCreator, dataEncrypter, object3).execute(commandContext);
 
         context.assertIsSatisfied();
     }
@@ -181,12 +198,13 @@ public class WriteObjectCommandTest {
                 one(writer).writeVersion(null, "2");
                 one(writer).writeUser("username");
                 one(writer).writeTime("1057");
+                one(writer).writeEncryptionType("etc1");
 
                 one(commandContext).insert(writer);
             }
         });
 
-        new WriteObjectCommand(false, keyCreator, versionCreator, object4).execute(commandContext);
+        new WriteObjectCommand(false, keyCreator, versionCreator, dataEncrypter, object4).execute(commandContext);
 
         context.assertIsSatisfied();
     }

Added: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateReaderTest.java?rev=1103224&view=auto
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateReaderTest.java (added)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateReaderTest.java Sat May 14 20:58:27 2011
@@ -0,0 +1,114 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.runtimes.dflt.objectstores.nosql.file;
+
+import java.util.List;
+
+import org.apache.isis.runtimes.dflt.objectstores.nosql.StateReader;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+public class JsonStateReaderTest {
+    
+    private JsonStateReader reader;
+
+    @Before
+    public void setup() {
+        reader = new JsonStateReader("{" + 
+                "\"_encrypt\": \"etc1\"," +
+                "\"_id\": \"#2\"," +
+                "\"_type\": \"com.planchaser.ClassName\"," +
+                "\"_time\": \"ddmmyy\"," +
+                "\"_user\": \"fred\"," +
+                "\"_version\": \"2\"," +
+                "\"field-1\": \"1234\"," +
+                "\"field-2\": \"data\"," +
+                "\"field-3\": null," +
+                "\"list\": [{}, {}]," +
+                "\"aggregate\": {\"_id\": \"#3\"}," +
+                "}");
+    }
+    
+    @Test
+    public void readEncryptionType() throws Exception {
+        assertEquals("etc1", reader.readEncrytionType());
+    }
+
+    @Test
+    public void readId() throws Exception {
+        assertEquals("#2", reader.readId());
+    }
+
+    @Test
+    public void readObjectType() throws Exception {
+        assertEquals("com.planchaser.ClassName", reader.readObjectType());
+    }
+    
+    @Test
+    public void readTime() throws Exception {
+        assertEquals("ddmmyy", reader.readTime());
+    }
+    
+    @Test
+    public void readUser() throws Exception {
+        assertEquals("fred", reader.readUser());
+    }
+    
+    @Test
+    public void readVersion() throws Exception {
+        assertEquals("2", reader.readVersion());
+    }
+
+    @Test
+    public void readNumberField() throws Exception {
+        assertEquals(1234L, reader.readLongField("field-1"));
+    }
+
+    @Test
+    public void readNumberFieldAsNull() throws Exception {
+        assertEquals(0L, reader.readLongField("field-4"));
+    }
+
+    @Test
+    public void readStringField() throws Exception {
+        assertEquals("data", reader.readField("field-2"));
+    }
+
+    @Test
+    public void readStringFieldAsNull() throws Exception {
+        assertEquals(null, reader.readField("field-4"));
+    }
+
+    @Test
+    public void readList() throws Exception {
+        List<StateReader> collection = reader.readCollection("list");
+        assertEquals(2, collection.size());
+//        assertEquals(null, reader.readField("field-4"));
+    }    
+
+    @Test
+    public void readAggregate() throws Exception {
+        StateReader aggregate = reader.readAggregate("aggregate");
+        assertEquals("#3", aggregate.readId());
+    }
+}
+

Propchange: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateReaderTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateWriterTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateWriterTest.java?rev=1103224&view=auto
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateWriterTest.java (added)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateWriterTest.java Sat May 14 20:58:27 2011
@@ -0,0 +1,109 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.runtimes.dflt.objectstores.nosql.file;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.isis.runtimes.dflt.objectstores.nosql.StateWriter;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+public class JsonStateWriterTest {
+
+    private JsonStateWriter writer;
+
+    @Before
+    public void setup() {
+        writer = new JsonStateWriter(null, "spec-name");
+    }
+
+    @Test
+    public void noData() throws Exception {
+        assertEquals("{}", writer.getData());
+    }
+
+    @Test
+    public void basicData() throws Exception {
+        writer.writeId("#1");
+        writer.writeTime("ddmmyy");
+        writer.writeType("com.planchase.ClassName");
+        writer.writeVersion("1", "2");
+        writer.writeUser("fred");
+        assertEquals("{\n    \"_id\": \"#1\",\n    \"_time\": \"ddmmyy\",\n    \"_type\": \"com.planchase.ClassName\",\n    \"_user\": \"fred\",\n    \"_version\": \"2\"\n}", writer.getData());
+    }
+
+    @Test
+    public void encrytionVersion() throws Exception {
+        writer.writeEncryptionType("etc1");
+        assertEquals("{\"_encrypt\": \"etc1\"}", writer.getData());
+    }
+
+    @Test
+    public void numberData() throws Exception {
+        writer.writeField("number", 1239912);
+        assertEquals("{\"number\": \"1239912\"}", writer.getData());
+    }
+
+    @Test
+    public void stringData() throws Exception {
+        writer.writeField("number", "string-data");
+        assertEquals("{\"number\": \"string-data\"}", writer.getData());
+    }
+
+    @Test
+    public void nullData() throws Exception {
+        writer.writeField("number", null);
+        assertEquals("{\"number\": null}", writer.getData());
+    }
+
+    @Test
+    public void addAggregate() throws Exception {
+        StateWriter aggregate = writer.addAggregate("#4");
+        aggregate.writeField("number", "string-data");
+        assertEquals("{\"#4\": {\"number\": \"string-data\"}}", writer.getData());
+    }
+
+    @Test
+    public void elementData() throws Exception {
+        List<StateWriter> elements = new ArrayList<StateWriter>();
+        StateWriter elementWriter1 = writer.createElementWriter();
+        elementWriter1.writeField("number", "1");
+        elements.add(elementWriter1);
+        StateWriter elementWriter2 = writer.createElementWriter();
+        elementWriter2.writeField("number", "4");
+        elements.add(elementWriter2);
+        
+        writer.writeCollection("coll", elements);
+        
+        assertEquals("{\"coll\": [\n    {\"number\": \"1\"},\n    {\"number\": \"4\"}\n]}", writer.getData());
+    }
+    
+    @Test
+    public void requestData() throws Exception {
+        writer.writeType("com.planchase.ClassName");
+        writer.writeId("#8");
+        writer.writeVersion("1", "2");
+        assertEquals("com.planchase.ClassName #8 1 2", writer.getRequest());
+    }
+
+}

Propchange: incubator/isis/trunk/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/file/JsonStateWriterTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message