portals-pluto-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msnickl...@apache.org
Subject [07/19] portals-pluto git commit: worked on mapper implementation
Date Tue, 27 Jan 2015 08:01:51 GMT
worked on mapper implementation


Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/79e249d2
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/79e249d2
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/79e249d2

Branch: refs/heads/PortletHub
Commit: 79e249d2406121f3009088468aeac88c18b958b2
Parents: aa65948
Author: Scott Nicklous <msnicklous@apache.org>
Authored: Tue Jan 20 17:17:57 2015 +0100
Committer: Scott Nicklous <msnicklous@apache.org>
Committed: Tue Jan 20 17:17:57 2015 +0100

----------------------------------------------------------------------
 .../driver/url/impl/RelativePortalURLImpl.java  |  18 ++-
 .../portal/PublicRenderParameterMapper.java     |  72 ++++++++---
 .../portal/PublicRenderParameterMapperImpl.java | 120 +++++++++++++------
 .../driver/url/PortalURLPublicParameter.java    |  19 ++-
 4 files changed, 166 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/79e249d2/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/url/impl/RelativePortalURLImpl.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/url/impl/RelativePortalURLImpl.java
b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/url/impl/RelativePortalURLImpl.java
index 883a5be..85378f2 100644
--- a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/url/impl/RelativePortalURLImpl.java
+++ b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/url/impl/RelativePortalURLImpl.java
@@ -21,6 +21,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -62,12 +63,10 @@ public class RelativePortalURLImpl implements PortalURL {
    private Map<String, String[]> publicParameterNew = new HashMap<String, String[]>();
    private Map<String, String[]> privateRenderParameters = new HashMap<String, String[]>();
 
-   // The public render parameters for the page currently set on the URL targeting the page
to be rendered
-   private Set<PortalURLPublicParameter> currPrps = new HashSet<PortalURLPublicParameter>();
-
    // Newly made changes to the public render parameters
    private Set<PortalURLPublicParameter> newPrps = new HashSet<PortalURLPublicParameter>();
 
+   // provides the defined public render parameters and their relationships to one another
for the current page 
    private PublicRenderParameterMapper prpMapper = null;
 
    /**
@@ -307,9 +306,11 @@ public class RelativePortalURLImpl implements PortalURL {
 
    public void addPublicParameterCurrent(String name, String[] values){
       publicParameterCurrent.put(name, values);
-      if (prpMapper != null) {
-         Set<PortalURLPublicParameter> mappedPRPs = prpMapper.getPRPsForId(name, values);
-         currPrps.addAll(mappedPRPs);
+      for (int ii = 0; ii < prpMapper.getNumberOfGroups(); ii++) {
+         List<PortalURLPublicParameter> prps = prpMapper.getPublicParameterGroup(ii);
+         if (prps.get(0).getName().equals(name)) {
+            prpMapper.setValues(ii, values);
+         }
       }
    }
 
@@ -392,10 +393,7 @@ public class RelativePortalURLImpl implements PortalURL {
    }
 
    public void addPublicRenderParameter(PortalURLPublicParameter pup) {
-      if (prpMapper != null) {
-         Set<PortalURLPublicParameter> mappedPRPs = prpMapper.getMappedPublicParameters(pup);
-         newPrps.addAll(mappedPRPs);
-      }
+      newPrps.add(pup);
    }
 
    public void setPublicRenderParameterMapper(PublicRenderParameterMapper prpm) {

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/79e249d2/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PublicRenderParameterMapper.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PublicRenderParameterMapper.java
b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PublicRenderParameterMapper.java
index f2e4a8e..c02c3cb 100644
--- a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PublicRenderParameterMapper.java
+++ b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PublicRenderParameterMapper.java
@@ -18,7 +18,7 @@
 
 package org.apache.pluto.driver.services.portal;
 
-import java.util.Set;
+import java.util.List;
 
 import javax.xml.namespace.QName;
 
@@ -43,28 +43,26 @@ import org.apache.pluto.driver.url.PortalURLPublicParameter;
  * equals() function, which determines equality of public render parameters
  * based on comparison of the window ID and the parameter name (= PRP identifier).
  * 
+ * The public render parameters contain a 'removed' flag that marks whether or not the
+ * PRP has been set. If the <code>removed</code> flag is set, the PRP is considered
to
+ * be inactive, or 'not set'. A newly-created PRP mapper will contain public render parameters
+ * whose <code>removed</code> flag is set. When a value is set, the <code>removed</code>
+ * flag is automatically reset.
+ * 
  * @author msnicklous
- * @since  16/01/2015
+ * @since  19/01/2015
  */
 public interface PublicRenderParameterMapper {
 
    /**
-    * Returns the set of public render parameters matching the input public render parameter.
-    * The returned set will include the input PRP (providing that it is used on the page
at all).
-    * 
-    * @param prp     The public render parameter to be matched
-    * @return        Set containing all matching PRPs
-    */
-   public Set<PortalURLPublicParameter> getMappedPublicParameters(PortalURLPublicParameter
prp);
-
-   /**
     * Returns the set of public render parameters specified by the input group index.
     * 
     * @param index   The group index
     * @return        Set containing all matching PRPs.
-    *                If no group matches the index, an empty set is returned
+    * 
+    * @throws        IndexOutOfBoundsException - if the index is out of range (index <
0 || index >= getNumberOfGroups())
     */
-   public Set<PortalURLPublicParameter> getMappedPublicParameters(int index);
+   public List<PortalURLPublicParameter> getPublicParameterGroup(int index);
    
    /**
     * Returns the number of distinct PRP groups available from the mapper.
@@ -105,14 +103,54 @@ public interface PublicRenderParameterMapper {
    public int getIndex(QName qname);
    
    /**
-    * Sets the values of all public render parameters within the specified group. 
+    * Sets the values of all public render parameters within the specified group.
+    * 
+    * Setting a value automatically resets the 'removed' flag so that the values are made
available
+    * to portlets using the public render parameter in question.
     * 
     * @param index      Group index
     * @param values     Values array for the public render parameters contained in the group
     */
-   public void setValue(int index, String[] values);
+   public void setValues(int index, String[] values);
 
-   // scafolding function - to be thrown away then the URL generation is complete.
-   public Set<PortalURLPublicParameter> getPRPsForId(String id, String[] vals);
+   /**
+    * Gets the string value array that is set for all the public render parameters within
 
+    * the group specified by the index.
+    * 
+    * @param index      Group index
+    * @return           String array 
+    * 
+    * @throws           IndexOutOfBoundsException - if the index is out of range (index <
0 || index >= getNumberOfGroups())
+    */
+   public String[] getValues(int index);
    
+   /**
+    * Sets the 'removed' flag for all public render parameters in the group specified by
the index.
+    * 
+    * When the 'removed' flag is set, the public render parameter is considered to be not
set.
+    * the value <code>null</code> will be returned to a portlet attempting to
read the parameter.
+    * 
+    * @param index      Group index
+    * @param removed    <code>true</code> marks the PRP as removed. <code>false</code>
resets the value to <code>null</code> and marks it as being available.
+    */
+   public void setRemoved(int index, boolean removed);
+
+   /**
+    * Gets the 'removed' flag that is set for all the public render parameters within  
+    * the group specified by the index.
+    * 
+    * @param index      Group index
+    * @return           The removed flag.  
+    * 
+    * @throws           IndexOutOfBoundsException - if the index is out of range (index <
0 || index >= getNumberOfGroups())
+    */
+   public boolean getRemoved(int index);
+   
+   /**
+    * Returns an array containing the indexes of all active PRP groups (<code>removed</code>
flag
+    * is reset).
+    * 
+    * @return   an array of indexes. If no groups are active, the array will be empty.
+    */
+   public List<Integer> getActiveIndexes();
 }

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/79e249d2/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PublicRenderParameterMapperImpl.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PublicRenderParameterMapperImpl.java
b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PublicRenderParameterMapperImpl.java
index 3f3025b..7cd9a5f 100644
--- a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PublicRenderParameterMapperImpl.java
+++ b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/PublicRenderParameterMapperImpl.java
@@ -19,10 +19,12 @@
 
 package org.apache.pluto.driver.services.portal;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Collection;
-import java.util.HashSet;
+import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Set;
+import java.util.Map;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -46,9 +48,14 @@ import org.apache.pluto.container.om.portlet.PublicRenderParameter;
  */
 public class PublicRenderParameterMapperImpl implements PublicRenderParameterMapper {
    private final Logger LOGGER = LoggerFactory.getLogger(PublicRenderParameterMapperImpl.class);
-   
+ 
    // Set of all public render parameters on the page
-   Set<PortalURLPublicParameter> prps = new HashSet<PortalURLPublicParameter>();
+   ArrayList<PortalURLPublicParameter> prpList = new ArrayList<PortalURLPublicParameter>();
+   
+   // Maps the PRP QName to a set of public render parameters
+   private final Map<QName, List<PortalURLPublicParameter>> qn2PRP =
+                     new HashMap<QName, List<PortalURLPublicParameter>>();
+   private final ArrayList<QName> qnList = new ArrayList<QName>();
    
    public PublicRenderParameterMapperImpl(PageConfig paco, PortletRegistryService pore) {
       
@@ -105,8 +112,19 @@ public class PublicRenderParameterMapperImpl implements PublicRenderParameterMap
                      LOGGER.error("Problem with PRP definition: Both QName could not be obtained.");
                   } else {
                      PortalURLPublicParameter pupp = new PortalURLPublicParameter(pid, prpId,
qn);
+                     
+                     // Add to set of all PRPs for page
+                     prpList.add(pupp);
 
-                     prps.add(pupp);
+                     // Add PRP to the QName to PRP mapping
+                     if (qn2PRP.containsKey(qn)) {
+                        qn2PRP.get(qn).add(pupp);
+                     } else {
+                        List<PortalURLPublicParameter> s = new ArrayList<PortalURLPublicParameter>();
+                        s.add(pupp);
+                        qn2PRP.put(qn, s);
+                        qnList.add(qn);
+                     }
                      
                      if (isDebug) {
                         dbgstr.append("\n      Added PRP for window = " + pid + " QName =
" + qn.toString()
@@ -129,47 +147,79 @@ public class PublicRenderParameterMapperImpl implements PublicRenderParameterMap
       }
    }
 
-   /**
-    * Returns set of related PRPs for the input PRP. The mapping is done on the basis of
the QName. 
-    * The value arrays of all PRPs in the returned set are set to the value array in the
input PRP.
-    */
-   public Set<PortalURLPublicParameter> getMappedPublicParameters(PortalURLPublicParameter
prp) {
-      Set<PortalURLPublicParameter> oprps = new HashSet<PortalURLPublicParameter>();
-      for (PortalURLPublicParameter ip : prps) {
-         if (ip.getQName().equals(prp.getQName())) {
-            PortalURLPublicParameter p = ip.clone();
+   
+   public List<PortalURLPublicParameter> getPublicParameterGroup(int index) {
+      List<PortalURLPublicParameter> oprps = new ArrayList<PortalURLPublicParameter>();
+      for (PortalURLPublicParameter prp : qn2PRP.get(qnList.get(index))) {
+         PortalURLPublicParameter p = prp.clone();
+         if (!prp.isRemoved()) {
             p.setValues(prp.getValues().clone());
             oprps.add(p);
          }
       }
       if (LOGGER.isDebugEnabled()) {
-         LOGGER.debug("getMappedPublicParameters - Returning " + oprps.size() + " for window
= " + prp.getWindowId() 
-               + " QName = " + prp.getQName().toString() + ", ID = " + prp.getName());
+         LOGGER.debug("getPublicParameterSet - Returning " + oprps.size() + " public render
parameters");
       }
       return oprps;
    }
 
-   /**
-    * Returns the set of all PRPs with the same parameter names (IDs).
-    * Scaffolding code to be thrown away when the URL gen code is complete.
-    * 
-    * @param id
-    * @param vals
-    * @return
-    */
-   public Set<PortalURLPublicParameter> getPRPsForId(String id, String[] vals) {
-      Set<PortalURLPublicParameter> oprps = new HashSet<PortalURLPublicParameter>();
-      for (PortalURLPublicParameter ip : prps) {
-         if (ip.getName().equals(id)) {
-            PortalURLPublicParameter p = ip.clone();
-            p.setValues(vals.clone());
-            oprps.add(p);
-         }
+   public int getNumberOfGroups() {
+      return qnList.size();
+   }
+
+   public int getIndex(PortalURLPublicParameter prp) {
+      return qnList.indexOf(prp.getQName());
+   }
+
+   public int getIndex(String windowId, String identifier) {
+      PortalURLPublicParameter tmpPRP = new PortalURLPublicParameter(windowId, identifier,
null);
+      int ind = prpList.indexOf(tmpPRP);
+      if (ind < 0) {
+         LOGGER.warn("Public render parameter with window ID = " + windowId + ", ID = " +
identifier + " could not be found.");
+      } else {
+         QName qn = prpList.get(ind).getQName();
+         ind = qnList.indexOf(qn);
       }
-      if (LOGGER.isDebugEnabled()) {
-         LOGGER.debug("getPRPsForId - Returning " + oprps.size() + " for ID = " + id);
+      return ind;
+   }
+
+   public int getIndex(QName qname) {
+      return qnList.indexOf(qname);
+   }
+
+   public void setValues(int index, String[] values) {
+      List<PortalURLPublicParameter> oprps = qn2PRP.get(qnList.get(index));
+      for (PortalURLPublicParameter prp : oprps) {
+         prp.setValues(values.clone());
       }
-      return oprps;
+   }
+
+   public String[] getValues(int index) {
+      List<PortalURLPublicParameter> oprps = qn2PRP.get(qnList.get(index));
+      return oprps.get(0).getValues().clone();
+   }
+
+   public void setRemoved(int index, boolean removed) {
+      List<PortalURLPublicParameter> oprps = qn2PRP.get(qnList.get(index));
+      for (PortalURLPublicParameter prp : oprps) {
+         prp.setRemoved(removed);
+      }
+   }
+
+   public boolean getRemoved(int index) {
+      List<PortalURLPublicParameter> oprps = qn2PRP.get(qnList.get(index));
+      return oprps.get(0).isRemoved();
+   }
+
+   public List<Integer> getActiveIndexes() {
+      ArrayList<Integer> inds = new ArrayList<Integer>();
+      for (QName qn : qnList) {
+         List<PortalURLPublicParameter> oprps = qn2PRP.get(qn);
+         if (!oprps.get(0).isRemoved()) {
+            inds.add(qnList.indexOf(qn));
+         }
+      }
+      return inds; 
    }
 
 }

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/79e249d2/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLPublicParameter.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLPublicParameter.java
b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLPublicParameter.java
index d90f92d..802ec7e 100644
--- a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLPublicParameter.java
+++ b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/url/PortalURLPublicParameter.java
@@ -23,6 +23,12 @@ import javax.xml.namespace.QName;
 
 /**
  * Encapsulates concrete public render parameters used with the portal URLs.
+ * 
+ * The public render parameters contain a 'removed' flag that marks whether or not the
+ * PRP has been set. If the <code>removed</code> flag is set, the PRP is considered
to
+ * be inactive, or 'not set'. A newly-created PRP have the <code>removed</code>
flag set. 
+ * When a value is set, the <code>removed</code> flag is automatically reset.
+ * 
  * @author msnicklous
  * @since  16/01/2014
  */
@@ -31,7 +37,7 @@ public class PortalURLPublicParameter extends PortalURLParameter {
    private final QName  qname;
    
    // mark if this PRP is to be removed from the current set
-   private boolean removed = false;
+   private boolean removed = true;
 
    /**
     * Constructor when no value is available
@@ -54,6 +60,7 @@ public class PortalURLPublicParameter extends PortalURLParameter {
    public PortalURLPublicParameter(String window, String name, QName qname, String value)
{
       super(window, name, value);
       this.qname = qname;
+      removed = false;
    }
 
    /**
@@ -66,6 +73,7 @@ public class PortalURLPublicParameter extends PortalURLParameter {
    public PortalURLPublicParameter(String window, String name, QName qname, String[] values)
{
       super(window, name, values);
       this.qname = qname;
+      removed = false;
    }
    
    /**
@@ -106,4 +114,13 @@ public class PortalURLPublicParameter extends PortalURLParameter {
       return pupp;
    }
    
+   /**
+    * make sure removed flag is handled properly.
+    */
+   @Override
+   public void setValues(String[] value) {
+      super.setValues(value);
+      removed = false;
+   }
+   
 }


Mime
View raw message