Update of 
/var/cvs/contributions/CMSContainer_Modules/luceus/src/java/com/finalist/cmsc/module/luceusmodule
In directory 
james.mmbase.org:/tmp/cvs-serv19299/luceus/src/java/com/finalist/cmsc/module/luceusmodule

Modified Files:
        IndexUpdateTask.java QueuedUpdate.java LuceusModule.java 
        CustomContentHandler.java 
Added Files:
        CustomObjectHandler.java 
Log Message:
CMSC-1346 Indexing custom objects


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Modules/luceus/src/java/com/finalist/cmsc/module/luceusmodule
See also: http://www.mmbase.org/jira/browse/CMSC-1346




Index: IndexUpdateTask.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/luceus/src/java/com/finalist/cmsc/module/luceusmodule/IndexUpdateTask.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- IndexUpdateTask.java        29 Dec 2008 13:48:54 -0000      1.12
+++ IndexUpdateTask.java        25 Mar 2009 09:44:39 -0000      1.13
@@ -53,12 +53,15 @@
 
    private CustomContentHandler cch;
 
+   private CustomObjectHandler coh;
+
 
    public IndexUpdateTask(LuceusModule module, 
LinkedBlockingQueue<QueuedUpdate> queue, int id) {
       this.module = module;
       this.in = queue;
       this.id = id;
       this.cch = module.getCustomContentHandler();
+      this.coh = module.getCustomObjectHandler();
    }
 
 
@@ -97,6 +100,15 @@
                   case QueuedUpdate.METHOD_CREATE_CONTENT_INDEX:
                      executeCreateContentIndex(update.getNodeNumber());
                      break;
+                  case QueuedUpdate.METHOD_UPDATE_CUSTOMOBJECT_INDEX:
+                      executeUpdateCustomObjectIndex(update.getNodeNumber());
+                      break;
+                  case QueuedUpdate.METHOD_DELETE_CUSTOMOBJECT_INDEX:
+                      executeDeleteCustomObjectIndex(update.getNodeNumber());
+                      break;                           
+                  case QueuedUpdate.METHOD_CREATE_CUSTOMOBJECT_INDEX:
+                      executeCreateCustomObjectIndex(update.getNodeNumber());
+                      break;
                   case QueuedUpdate.METHOD_ERASE_INDEX:
                      executeEraseIndex();
                      break;
@@ -151,18 +163,48 @@
    private void executeDeletePageContentIndex(int page, int contentElement) {
       log.debug(id + " Delete page: " + page + " with content: " + 
contentElement);
       delete(String.valueOf(page), String.valueOf(contentElement));
+
+      // find and delete custom object related to the page
+      Node node = fetchNode(page);
+      Set<Node> elementen = Collections.emptySet();
+      if (node != null && coh != null) {
+         elementen = coh.findLinkedContent(node);
+      }
+      for (Node element : elementen) {
+          executeDeleteCustomObjectIndex(element.getNumber()); 
+      }            
    }
 
 
    private void executeDeletePageIndex(int pageNumber) {
       log.debug(id + " Delete page: " + pageNumber);
       delete(String.valueOf(pageNumber), null);
+
+      // find and delete custom object related to the page
+      Node node = fetchNode(pageNumber);
+      Set<Node> elementen = Collections.emptySet();
+      if (node != null && coh != null) {
+         elementen = coh.findLinkedContent(node);
+      }
+      for (Node element : elementen) {
+          executeDeleteCustomObjectIndex(element.getNumber()); 
+      }            
    }
 
 
    private void executeDeleteContentIndex(int ceNumber) {
       log.debug(id + " Delete content: " + ceNumber);
       delete(null, String.valueOf(ceNumber));
+ 
+      // find and delete custom object related to content
+      Node node = fetchNode(ceNumber);
+      Set<Node> elementen = Collections.emptySet();
+      if (node != null && coh != null) {
+         elementen = coh.findLinkedContent(node);
+      }
+      for (Node element : elementen) {
+          executeDeleteCustomObjectIndex(element.getNumber()); 
+      }           
    }
 
 
@@ -181,6 +223,15 @@
          int pageId = info.getPageNumber();
          create(String.valueOf(pageId), node);
       }
+
+      // find and create custom object related to content
+      Set<Node> elementen = Collections.emptySet();
+      if (coh != null) {
+         elementen = coh.findLinkedContent(node);
+      }
+      for (Node element : elementen) {
+          executeCreateCustomObjectIndex(element);
+      }          
    }
 
 
@@ -195,6 +246,15 @@
          int pageId = info.getPageNumber();
          update(String.valueOf(pageId), node, triggeredByPrimary);
       }
+
+      // find and update custom object related to content
+      Set<Node> elementen = Collections.emptySet();
+      if (coh != null) {
+         elementen = coh.findLinkedContent(node);
+      }
+      for (Node element : elementen) {
+          executeUpdateCustomObjectIndex(element);
+      }            
    }
 
 
@@ -205,6 +265,15 @@
       }
       else {
          delete(null, "" + nodeNumber);
+
+         // find and delete custom object related to content
+         Set<Node> elementen = Collections.emptySet();
+         if (node != null && coh != null) {
+            elementen = coh.findLinkedContent(node);
+         }
+         for (Node element : elementen) {
+             executeDeleteCustomObjectIndex(element.getNumber()); 
+         }         
       }
    }
 
@@ -260,12 +329,82 @@
          for (Node element : elementen) {
             update(pageNode, element, true);
          }
+
+         // find and update custom object related to page
+         elementen = Collections.emptySet();
+         if (coh != null) {
+            elementen = coh.findLinkedContent(pageNode);
+         }
+         for (Node element : elementen) {
+             executeUpdateCustomObjectIndex(element);
+         }         
       }
       else {
          delete("" + pageNumber, null);
+
+         // find and delete custom object related to the page
+         Node node = fetchNode(pageNumber);
+         Set<Node> elementen = Collections.emptySet();
+         if (node != null && coh != null) {
+            elementen = coh.findLinkedContent(node);
+         }
+         for (Node element : elementen) {
+             executeDeleteCustomObjectIndex(element.getNumber()); 
+         }       
+      }
+   }
+   
+   private void executeUpdateCustomObjectIndex(int nodeNumber) {
+       Node node = fetchNode(nodeNumber);
+       if (node != null) {
+          executeUpdateCustomObjectIndex(node);
+       }
+       else {
+          delete(null, "" + nodeNumber);
       }
    }
 
+   private void executeUpdateCustomObjectIndex(Node node) {
+       log.debug(id + " Update custom object index: " + node.getNumber());
+       
+       Set<PageInfo> pages = Collections.emptySet();
+       if (coh != null) {
+          pages = coh.findAllPagesForCustomObject(node);
+       }       
+       if (pages.size() == 0) {
+          log.debug(id + " Unable to find page(s) for update of custom object: 
" + node.getNumber());
+          delete(null, String.valueOf(node.getNumber()));
+       }   
+       for (PageInfo info : pages) {
+          int pageId = info.getPageNumber();
+          update(String.valueOf(pageId), node, false);
+       }
+    }   
+   
+   private void executeDeleteCustomObjectIndex(int nodeNumber) {
+       log.debug(id + " Delete custom object: " + nodeNumber);
+       delete(null, String.valueOf(nodeNumber));
+    }
+
+   private void executeCreateCustomObjectIndex(int nodeNumber) {
+       Node node = fetchNode(nodeNumber);
+       if (node != null) {
+           executeCreateCustomObjectIndex(node);
+       }
+    }      
+   
+   private void executeCreateCustomObjectIndex(Node node) {
+       log.debug(id + " Create custom object index: " + node.getNumber());
+       
+       Set<PageInfo> pages = Collections.emptySet();
+       if (coh != null) {
+          pages = coh.findAllPagesForCustomObject(node);
+       }
+       for (PageInfo info : pages) {
+          int pageId = info.getPageNumber();
+          create(String.valueOf(pageId), node);
+       }
+    }
 
    private void create(String pageId, Node contentElement) {
       Node pageNode = contentElement.getCloud().getNode(pageId);
@@ -381,6 +520,15 @@
          }
       }
 
+      if (coh != null) {
+          custom = coh.findLinkedContent(contentElement);
+
+           // Finally fields of the custom object to the document
+           for (Node customNode : custom) {
+              LuceusUtil.nodeFields(customNode, doc);
+           }      
+      }
+      
       Indexer idx = module.getIndexer();
       if (idx != null) {
          idx.write(doc);


Index: QueuedUpdate.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/luceus/src/java/com/finalist/cmsc/module/luceusmodule/QueuedUpdate.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- QueuedUpdate.java   4 Nov 2008 10:04:09 -0000       1.3
+++ QueuedUpdate.java   25 Mar 2009 09:44:39 -0000      1.4
@@ -37,6 +37,12 @@
 
    public final static int METHOD_CREATE_CONTENT_INDEX = 11;
 
+   public final static int METHOD_UPDATE_CUSTOMOBJECT_INDEX = 12;   
+   
+   public final static int METHOD_DELETE_CUSTOMOBJECT_INDEX = 13;
+   
+   public final static int METHOD_CREATE_CUSTOMOBJECT_INDEX = 14;
+   
    public static final int METHOD_ERASE_INDEX = 666;
 
    private int method;


Index: LuceusModule.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/luceus/src/java/com/finalist/cmsc/module/luceusmodule/LuceusModule.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- LuceusModule.java   4 Nov 2008 10:04:09 -0000       1.7
+++ LuceusModule.java   25 Mar 2009 09:44:39 -0000      1.8
@@ -71,6 +71,8 @@
 
    private CustomContentHandler customContentHandler;
 
+   private CustomObjectHandler customObjectHandler;
+
    private Set<String> secondaryCache = Collections.synchronizedSet(new 
HashSet<String>());
 
 
@@ -209,7 +211,7 @@
          }
       }
 
-      // read customhandlerclass and create instance
+      // read customContentHandlerClass and create instance
       String customContentHandlerClassname = 
getInitParameter("custom-content-handler-classname");
       if (customContentHandlerClassname != null) {
          try {
@@ -220,6 +222,17 @@
          }
       }
 
+      // read customObjectHandlerClass and create instance
+      String customObjectHandlerClassname = 
getInitParameter("custom-object-handler-classname");
+      if (customObjectHandlerClassname != null) {
+         try {
+            customObjectHandler = (CustomObjectHandler) 
Class.forName(customObjectHandlerClassname).newInstance();
+         }
+         catch (Exception e) {
+            log.warn("Unable to create CustomObjectHandler! (" + 
e.getMessage() + ")");
+         }
+      }      
+      
       in = new LinkedBlockingQueue<QueuedUpdate>(updateQueueSize);
 
       if (doListeners) {
@@ -230,6 +243,9 @@
          if (customContentHandler != null) {
             customContentHandler.registerListeners(this);
          }
+         if (customObjectHandler != null) {
+             customObjectHandler.registerListeners(this);
+          }
       }
 
       ScheduledThreadPoolExecutor exec = new 
ScheduledThreadPoolExecutor(execs);
@@ -298,18 +314,24 @@
       addToQueue(new QueuedUpdate(QueuedUpdate.METHOD_DELETE_PAGE_INDEX, 
nodeNumber));
    }
 
+   public void deleteCustomObjectIndex(int nodeNumber) {
+       addToQueue(new 
QueuedUpdate(QueuedUpdate.METHOD_DELETE_CUSTOMOBJECT_INDEX, nodeNumber));
+    }
+   
 
    // aka fullindex
    public void createContentIndex(Node node) {
       addToQueue(new QueuedUpdate(QueuedUpdate.METHOD_CREATE_CONTENT_INDEX, 
node.getNumber()));
    }
 
+   public void createCustomObjectIndex(Node node) {
+       addToQueue(new 
QueuedUpdate(QueuedUpdate.METHOD_CREATE_CUSTOMOBJECT_INDEX, node.getNumber()));
+    }
 
    public void updateContentIndex(Node node) {
       updateContentIndex(node.getNumber());
    }
 
-
    public void updateContentIndex(int nodeNumber) {
       addToQueue(new QueuedUpdate(QueuedUpdate.METHOD_UPDATE_CONTENT_INDEX, 
nodeNumber));
    }
@@ -329,6 +351,13 @@
       addToQueue(new 
QueuedUpdate(QueuedUpdate.METHOD_UPDATE_SECONDARYCONTENT_INDEX, nodeNumber));
    }
 
+   public void updateCustomObjectIndex(Node node) {
+       updateCustomObjectIndex(node.getNumber());
+    }   
+   
+   public void updateCustomObjectIndex(int nodeNumber) {
+       addToQueue(new 
QueuedUpdate(QueuedUpdate.METHOD_UPDATE_CUSTOMOBJECT_INDEX, nodeNumber));
+   }
 
    public Cloud getAnonymousCloud() {
       return CloudProviderFactory.getCloudProvider().getAnonymousCloud();
@@ -388,6 +417,10 @@
             }
          }
 
+         //if (customObjectHandler != null) {
+         //    customObjectHandler.fullIndex(erase);
+         //}
+
          log.info("===>fullIndex done<==");
       }
    }
@@ -454,6 +487,9 @@
       return customContentHandler;
    }
 
+   public CustomObjectHandler getCustomObjectHandler() {
+       return customObjectHandler;
+    }
 
    public boolean hasProcessedSecondary(String scId) {
       return secondaryCache.contains(scId);


Index: CustomContentHandler.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/luceus/src/java/com/finalist/cmsc/module/luceusmodule/CustomContentHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- CustomContentHandler.java   26 Nov 2007 11:42:13 -0000      1.2
+++ CustomContentHandler.java   25 Mar 2009 09:44:39 -0000      1.3
@@ -21,9 +21,8 @@
  */
 public interface CustomContentHandler {
 
-   public abstract Set<Node> findLinkedContent(Node contentElement);
+   Set<Node> findLinkedContent(Node contentElement);
 
-
-   public abstract void registerListeners(LuceusModule module);
+   void registerListeners(LuceusModule module);
 
 }
\ No newline at end of file
_______________________________________________
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to