Author: nzamosenchuk
Date: 2009-11-09 06:17:36 -0500 (Mon, 09 Nov 2009)
New Revision: 504
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
Log:
EXOJCR-204:Observation cache loader update, test added.
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java 2009-11-09
10:52:43 UTC (rev 503)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java 2009-11-09
11:17:36 UTC (rev 504)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.core.NamespaceAccessor;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
@@ -51,21 +52,22 @@
protected ActionLauncher launcher;
-
protected SessionRegistry sessionRegistry;
protected NamespaceAccessor namespaceAccessor;
protected NodeTypeDataManager nodeTypeDataManager;
+ protected WorkspacePersistentDataManager workspaceDataManager;
+
public ObservationManagerRegistry(WorkspacePersistentDataManager
workspaceDataManager,
SessionRegistry sessionRegistry, NamespaceAccessor namespaceAccessor)
{
this.sessionRegistry = sessionRegistry;
this.listenersMap = new HashMap<EventListener, ListenerCriteria>();
- this.namespaceAccessor = namespaceAccessor;
- //this.nodeTypeDataManager = nodeTypeDataManager;
- this.launcher = new ActionLauncher(this, workspaceDataManager, nodeTypeDataManager,
sessionRegistry);
+ this.nodeTypeDataManager = nodeTypeDataManager;
+ this.workspaceDataManager = workspaceDataManager;
+ //this.launcher = new ActionLauncher(this, workspaceDataManager,
nodeTypeDataManager, sessionRegistry);
}
public ObservationManagerImpl createObservationManager(SessionImpl session)
@@ -111,11 +113,23 @@
listenersMap.remove(listener);
}
}
-
- public ActionLauncher getLauncher()
+ // TODO: remove hardcode
+ public NodeTypeDataManager getNodeTypeDataManager()
{
- return launcher;
+ return nodeTypeDataManager;
}
+
+ // TODO: remove hardcode
+ public WorkspacePersistentDataManager getWorkspaceDataManager()
+ {
+ return workspaceDataManager;
+ }
+
+ // TODO: remove hardcode
+ public LocationFactory getLocationFactory()
+ {
+ return new LocationFactory(namespaceAccessor);
+ }
}
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java 2009-11-09
10:52:43 UTC (rev 503)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java 2009-11-09
11:17:36 UTC (rev 504)
@@ -31,6 +31,7 @@
import org.exoplatform.services.log.Log;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
+import org.jboss.cache.factories.annotations.Inject;
import java.util.List;
@@ -54,7 +55,7 @@
private final Fqn propFqn = Fqn.fromString(JBossCacheStorage.PROPS);
- private ObservationManagerRegistry observationManagerRegistry=null;
+ private ObservationManagerRegistry observationManagerRegistry = null;
/**
*
@@ -63,6 +64,12 @@
{
}
+ @Inject
+ public void insertObservationRegistry(ObservationManagerRegistry
observationManagerRegistry)
+ {
+ this.observationManagerRegistry = observationManagerRegistry;
+ }
+
/**
* @see
org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader#put(java.util.List)
*/
@@ -70,6 +77,72 @@
public void put(List<Modification> modifications) throws Exception
{
+ // get SessionID from list
+ // TODO: get real user ID
+ String userId = "admin-dummy-id";
+
+ // get UserID from list
+ // TODO: get real session ID
+ String sessionId = "user-session-dummy-id";
+
+ // extract real list from list of modification
+ // real - means list with out fake modifications containing UserID & etc
+
+ // for each listener
+ // for each element from real list post and event, if filtering ok
+
+ if (observationManagerRegistry != null)
+ {
+
+ EventListenerIterator eventListeners =
observationManagerRegistry.getEventListeners();
+ while (eventListeners.hasNext())
+ {
+ EventListener listener = eventListeners.nextEventListener();
+ ListenerCriteria criteria =
observationManagerRegistry.getListenerFilter(listener);
+
+ EntityCollection events = new EntityCollection();
+
+ for (Modification m : modifications)
+ {
+
+ if (m.getFqn().isDirectChildOf(nodeFqn) ||
m.getFqn().isDirectChildOf(propFqn))
+ {
+ ItemData item = getItemData(m);
+ // TODO: remove hardcode
+ if (item == null)
+ {
+ break;
+ } // it wasn't able to retrive item's data
+ int eventType = eventType(m);
+ boolean result = true;
+ // check event type
+ result &= isTypeMatch(criteria, eventType);
+ // check Path
+ result &= isPathMatch(criteria, item);
+ // check UUID
+ result &= isIdentifierMatch(criteria, item);
+ // check NodeType
+ // TODO: FIX nodetype checks
+ //result &= isNodeTypeMatch(criteria, item, changesLog);
+ // check session
+ result &= isSessionMatch(criteria, sessionId);
+ if (result)
+ {
+ String path =
+
observationManagerRegistry.getLocationFactory().createJCRPath(item.getQPath()).getAsString(
+ false);
+ events.add(new EventImpl(eventType, path, userId));
+ }
+ }
+ }
+
+ if (events.size() > 0)
+ {
+ // no events - no onEvent() action
+ listener.onEvent(events);
+ }
+ }
+ }
}
private int eventType(Modification modification)
@@ -77,28 +150,32 @@
// TODO: REMOVE cache structure hardcode!
switch (modification.getType())
{
- case PUT_DATA :
- if (modification.getFqn().isDirectChildOf(nodeFqn))
+ case PUT_KEY_VALUE :
+ // put something to /$node/IDxxxx.ITEMDATA
+ if (modification.getKey().equals(JBossCacheStorage.ITEM_DATA))
{
- // node added
- return Event.NODE_ADDED;
- }
- else if (modification.getFqn().isDirectChildOf(propFqn))
- {
- // property added or changed
- if (modification.getOldValue() != null)
+ if (modification.getFqn().isDirectChildOf(nodeFqn))
{
- // property changed
- // TODO: possibly bad idea
- return Event.PROPERTY_CHANGED;
+ // node added
+ return Event.NODE_ADDED;
}
- else
+ else if (modification.getFqn().isDirectChildOf(propFqn))
{
- // property added
- return Event.PROPERTY_ADDED;
+ // property added or changed
+ if (modification.getOldValue() != null)
+ {
+ // property changed
+ return Event.PROPERTY_CHANGED;
+ }
+ else
+ {
+ // property added
+ return Event.PROPERTY_ADDED;
+ }
}
}
break;
+
case REMOVE_NODE :
if (modification.getFqn().isDirectChildOf(nodeFqn))
{
@@ -207,7 +284,7 @@
protected ItemData getItemData(Modification m)
{
- return (ItemData)m.getData().get(JBossCacheStorage.ITEM_DATA);
+ return (ItemData)m.getValue();
}
}
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
(rev 0)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java 2009-11-09
11:17:36 UTC (rev 504)
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jbosscache;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.services.jcr.access.AccessControlList;
+import org.exoplatform.services.jcr.core.NamespaceAccessor;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
+import org.exoplatform.services.jcr.impl.core.observation.ListenerCriteria;
+import org.exoplatform.services.jcr.impl.core.observation.ObservationManagerRegistry;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.Modification.ModificationType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.RepositoryException;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
+
+/**
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
+ * @version $Id: ObservationCacheLoaderTest.java 34360 2009-07-22 23:58:59Z aheritier $
+ *
+ */
+public class ObservationCacheLoaderTest extends TestCase
+{
+
+ private ObservationCacheLoader loader;
+
+ private ObservationManagerRegistry registry;
+
+ private LocationFactory lf;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ loader = new ObservationCacheLoader();
+ registry = new DummyObservationRegistry();
+ loader.insertObservationRegistry(registry);
+
+ final Map<String, String> ns = new HashMap<String, String>();
+
+ final Map<String, String> nss = new HashMap<String, String>();
+
+ ns.put("jcr", "http:jcr");
+ ns.put("", "");
+ nss.put("http:jcr", "jcr");
+ nss.put("", "");
+
+ this.lf = new LocationFactory(new NamespaceAccessor()
+ {
+
+ public String getNamespaceURIByPrefix(String prefix) throws NamespaceException,
RepositoryException
+ {
+ return ns.get(prefix);
+ }
+
+ public String getNamespacePrefixByURI(String uri) throws NamespaceException,
RepositoryException
+ {
+ return nss.get(uri);
+ }
+
+ public String[] getAllNamespacePrefixes() throws RepositoryException
+ {
+ return ns.keySet().toArray(new String[ns.keySet().size()]);
+ }
+ });
+ }
+
+ public void testAddNode() throws Exception
+ {
+ QPath node1path = QPath.parse("[]:1[]node:1");
+ NodeData newNode =
+ new TransientNodeData(node1path, Constants.SYSTEM_UUID, 1,
Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList());
+ DummyListener listener = new DummyListener();
+ registry.addEventListener(listener, new ListenerCriteria(Event.NODE_ADDED,
+ lf.parseAbsPath("/").getInternalPath(), true, null, null, false,
"asd"));
+
+ List<Modification> modifications = new ArrayList<Modification>();
+ modifications.add(addNode(newNode));
+ loader.put(modifications);
+ assertEquals(1, listener.eventList.size());
+ Event event = listener.eventList.get(0);
+ assertEquals(Event.NODE_ADDED, event.getType());
+ assertEquals(lf.createJCRPath(node1path).getAsString(false), event.getPath());
+ }
+
+ public Modification addNode(NodeData data)
+ {
+ // add in NODES
+ String fqn = "/" + JBossCacheStorage.NODES + "/" +
data.getIdentifier();
+ return new Modification(ModificationType.PUT_KEY_VALUE, Fqn.fromString(fqn),
(Object)JBossCacheStorage.ITEM_DATA,
+ (Object)data);
+ //node.put(ITEM_DATA, data);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ class DummyObservationRegistry extends ObservationManagerRegistry
+ {
+ public DummyObservationRegistry()
+ {
+ super(null, null, null);
+ }
+
+ // TODO: remove hardcode
+ public LocationFactory getLocationFactory()
+ {
+ return lf;
+ }
+
+ }
+
+ class DummyListener implements EventListener
+ {
+
+ public List<Event> eventList = new ArrayList<Event>();
+
+ public void onEvent(EventIterator events)
+ {
+ while (events.hasNext())
+ {
+ eventList.add(events.nextEvent());
+ }
+ }
+
+ }
+
+}
Property changes on:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain