[jboss-svn-commits] JBoss Portal SVN: r5439 - in trunk/wsrp/src: main/org/jboss/portal/test/wsrp/v1/producer main/org/jboss/portal/wsrp main/org/jboss/portal/wsrp/producer resources/test-basic-portlet-war/WEB-INF

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Oct 13 12:30:16 EDT 2006


Author: chris.laprun at jboss.com
Date: 2006-10-13 12:30:12 -0400 (Fri, 13 Oct 2006)
New Revision: 5439

Modified:
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java
   trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
   trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
   trunk/wsrp/src/resources/test-basic-portlet-war/WEB-INF/portlet.xml
Log:
- Implemented getPortletProperties.
- Added test case and related changes.

Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java	2006-10-13 16:28:41 UTC (rev 5438)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/MarkupTestCase.java	2006-10-13 16:30:12 UTC (rev 5439)
@@ -49,7 +49,7 @@
  * @version $Revision$
  * @since 2.4
  */
-public class MarkupTestCase extends org.jboss.portal.test.wsrp.v1.producer.NeedPortletHandleTest
+public class MarkupTestCase extends NeedPortletHandleTest
 {
    private static final String DEFAULT_VIEW_MARKUP = "<p>symbol unset stock value: value unset</p>";
    private static final String DEFAULT_MARKUP_PORTLET_WAR = "test-markup-portlet.war";

Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java	2006-10-13 16:28:41 UTC (rev 5438)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java	2006-10-13 16:30:12 UTC (rev 5439)
@@ -22,10 +22,16 @@
 
 package org.jboss.portal.test.wsrp.v1.producer;
 
+import org.jboss.portal.wsrp.WSRPTypeFactory;
 import org.jboss.portal.wsrp.core.GetPortletDescription;
-import org.jboss.portal.wsrp.core.PortletContext;
+import org.jboss.portal.wsrp.core.GetPortletProperties;
 import org.jboss.portal.wsrp.core.PortletDescriptionResponse;
+import org.jboss.portal.wsrp.core.Property;
+import org.jboss.portal.wsrp.core.PropertyList;
 
+import javax.xml.soap.SOAPElement;
+import java.util.Arrays;
+
 /**
  * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
  * @version $Revision$
@@ -52,7 +58,7 @@
    public void testGetPortletDescription() throws Exception
    {
       String handle = getDefaultHandle();
-      GetPortletDescription gpd = new GetPortletDescription(null, new PortletContext(handle, null, null), null, null);
+      GetPortletDescription gpd = WSRPTypeFactory.createGetPortletDescription(null, handle);
 
       PortletDescriptionResponse response = portletManagementService.getPortletDescription(gpd);
       assertNotNull(response);
@@ -60,11 +66,37 @@
       checkBasicPortletDescription(response.getPortletDescription(), handle);
    }
 
-   public void testGetPortletProperties()
+   public void testGetPortletPropertiesNoRegistration() throws Exception
    {
-      // todo: implement
+      String handle = getDefaultHandle();
+      GetPortletProperties getPortletProperties = WSRPTypeFactory.createGetPortletProperties(null, handle);
+      getPortletProperties.setNames(new String[]{"prefName1", "prefName2"});
+
+      PropertyList response = portletManagementService.getPortletProperties(getPortletProperties);
+      Property[] expected = new Property[]{
+         new Property("prefName1", "en", "prefValue1", null),
+         new Property("prefName2", "en", "prefValue2", null)
+      };
+      checkGetPropertiesResponse(response, expected);
+
+      getPortletProperties.setNames(null);
+      response = portletManagementService.getPortletProperties(getPortletProperties);
+      checkGetPropertiesResponse(response, expected);
+
+      getPortletProperties.setNames(new String[]{"prefName2"});
+      response = portletManagementService.getPortletProperties(getPortletProperties);
+      expected = new Property[]{new Property("prefName2", "en", "prefValue2", null)};
+      checkGetPropertiesResponse(response, expected);
    }
 
+   private Property[] checkGetPropertiesResponse(PropertyList response, Property[] expected)
+   {
+      assertNotNull(response);
+      Property[] properties = response.getProperties();
+      assertEquals(expected, properties, false, "Didn't receive expected properties!", new PropertyDecorator());
+      return properties;
+   }
+
    public void testGetPortletPropertyDescription()
    {
       // todo: implement
@@ -74,4 +106,56 @@
    {
       // todo: implement
    }
+
+   private static class PropertyDecorator implements Decorator
+   {
+      private Property prop;
+
+      public void decorate(Object decorated)
+      {
+         prop = (Property)decorated;
+      }
+
+      public boolean equals(Object o)
+      {
+         if (o instanceof DecoratedObject)
+         {
+            DecoratedObject decoratedObject = (DecoratedObject)o;
+            Property that = (Property)decoratedObject.getDecorated();
+
+            String name = prop.getName();
+            if (name != null ? !name.equals(that.getName()) : that.getName() != null)
+            {
+               return false;
+            }
+
+            String value = prop.getStringValue();
+            if (value != null ? !value.equals(that.getStringValue()) : that.getStringValue() != null)
+            {
+               return false;
+            }
+
+            String lang = prop.getLang();
+            if (lang != null ? !lang.equals(that.getLang()) : that.getLang() != null)
+            {
+               return false;
+            }
+
+            SOAPElement[] any = prop.get_any();
+            return !(any != null ? !Arrays.equals(any, that.get_any()) : that.get_any() != null);
+
+         }
+         else
+         {
+            return false;
+         }
+      }
+
+
+      public String toString()
+      {
+         return new StringBuffer().append("Property: ").append(prop.getName()).append("=")
+            .append(prop.getStringValue()).append(" (").append(prop.getLang()).append(")").toString();
+      }
+   }
 }
\ No newline at end of file

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java	2006-10-13 16:28:41 UTC (rev 5438)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java	2006-10-13 16:30:12 UTC (rev 5439)
@@ -36,6 +36,7 @@
 import org.jboss.portal.wsrp.core.ClientData;
 import org.jboss.portal.wsrp.core.GetMarkup;
 import org.jboss.portal.wsrp.core.GetPortletDescription;
+import org.jboss.portal.wsrp.core.GetPortletProperties;
 import org.jboss.portal.wsrp.core.GetServiceDescription;
 import org.jboss.portal.wsrp.core.InitCookie;
 import org.jboss.portal.wsrp.core.InteractionParams;
@@ -159,6 +160,20 @@
       return new GetPortletDescription(registrationContext, createPortletContext(portletHandle), null, null);
    }
 
+   /**
+    * registrationContext(RegistrationContext)?, portletContext(PortletContext), userContext(UserContext)?,
+    * desiredLocales(xsd:string)*
+    *
+    * @param registrationContext
+    * @param portletHandle
+    * @return
+    * @since 2.6
+    */
+   public static GetPortletProperties createGetPortletProperties(RegistrationContext registrationContext, String portletHandle)
+   {
+      return new GetPortletProperties(registrationContext, createPortletContext(portletHandle), null, null);
+   }
+
    /** ====== WSRP Response objects ====== **/
 
    /**

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java	2006-10-13 16:28:41 UTC (rev 5438)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java	2006-10-13 16:30:12 UTC (rev 5439)
@@ -22,6 +22,18 @@
 
 package org.jboss.portal.wsrp.producer;
 
+import org.jboss.logging.Logger;
+import org.jboss.portal.common.util.LocaleInfo;
+import org.jboss.portal.common.util.LocalizedString;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.value.Value;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.info.PortletInfo;
+import org.jboss.portal.portlet.info.PreferenceInfo;
+import org.jboss.portal.portlet.state.PropertyMap;
+import org.jboss.portal.wsrp.WSRPTypeFactory;
+import org.jboss.portal.wsrp.WSRPUtils;
 import org.jboss.portal.wsrp.core.AccessDeniedFault;
 import org.jboss.portal.wsrp.core.ClonePortlet;
 import org.jboss.portal.wsrp.core.DestroyPortlets;
@@ -38,12 +50,16 @@
 import org.jboss.portal.wsrp.core.PortletContext;
 import org.jboss.portal.wsrp.core.PortletDescriptionResponse;
 import org.jboss.portal.wsrp.core.PortletPropertyDescriptionResponse;
+import org.jboss.portal.wsrp.core.Property;
 import org.jboss.portal.wsrp.core.PropertyList;
 import org.jboss.portal.wsrp.core.SetPortletProperties;
 import org.jboss.portal.wsrp.core.WSRP_v1_PortletManagement_PortType;
-import org.apache.log4j.Logger;
 
 import java.rmi.RemoteException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
@@ -53,6 +69,9 @@
 class PortletManagementHandler extends ServiceHandler implements WSRP_v1_PortletManagement_PortType
 {
    private final Logger log = Logger.getLogger(getClass());
+   private static final String GET_PORTLET_PROPERTY_DESCRIPTION = "GetPortletPropertyDescription";
+   private static final String GET_PORTLET_PROPERTIES = "GetPortletProperties";
+   private static final String PORTLET_CONTEXT = "PortletContext";
 
    PortletManagementHandler(WSRPProducerImpl producer)
    {
@@ -63,18 +82,16 @@
       throws AccessDeniedFault, InvalidHandleFault, InvalidUserCategoryFault, InconsistentParametersFault,
       MissingParametersFault, InvalidRegistrationFault, OperationFailedFault, RemoteException
    {
-      // todo: could do user filtering
-      if (getPortletDescription != null)
+      WSRPUtils.throwOperationFailedFaultIfValueIsMissing(getPortletDescription, "getPortletDescription");
+
+      if (producer.isRegistrationValid(getPortletDescription.getRegistrationContext()))
       {
-         if (producer.isRegistrationValid(getPortletDescription.getRegistrationContext()))
-         {
-            String handle = getPortletDescription.getPortletContext().getPortletHandle();
-            return new PortletDescriptionResponse(
-               producer.getPortletDescription(handle, getPortletDescription.getDesiredLocales()),
-               null, null);
-         }
+         String handle = getPortletDescription.getPortletContext().getPortletHandle();
+         return new PortletDescriptionResponse(
+            producer.getPortletDescription(handle, getPortletDescription.getDesiredLocales()),
+            null, null);
       }
-      return null;
+      return null; // shouldn't happen
    }
 
    public PortletContext clonePortlet(ClonePortlet clonePortlet) throws InvalidUserCategoryFault, AccessDeniedFault, OperationFailedFault, InvalidHandleFault, InvalidRegistrationFault, InconsistentParametersFault, MissingParametersFault, RemoteException
@@ -94,11 +111,128 @@
 
    public PropertyList getPortletProperties(GetPortletProperties getPortletProperties) throws InvalidHandleFault, MissingParametersFault, InvalidRegistrationFault, AccessDeniedFault, OperationFailedFault, InconsistentParametersFault, InvalidUserCategoryFault, RemoteException
    {
-      return null;  // todo: implement
+      WSRPUtils.throwOperationFailedFaultIfValueIsMissing(getPortletProperties, GET_PORTLET_PROPERTIES);
+
+      PortletContext portletContext = getPortletProperties.getPortletContext();
+      WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletContext, PORTLET_CONTEXT, GET_PORTLET_PROPERTIES);
+
+      if (producer.isRegistrationValid(getPortletProperties.getRegistrationContext()))
+      {
+         String[] names = getPortletProperties.getNames();
+         Set keys = getKeysFromNames(names);
+
+         try
+         {
+            PropertyMap properties;
+            org.jboss.portal.portlet.PortletContext jbpContext =
+               WSRPUtils.convertWSRPPortletContextToPortalPortletContext(portletContext);
+
+            if (keys != null)
+            {
+               properties = producer.getInvoker().getProperties(jbpContext, keys);
+            }
+            else
+            {
+               properties = producer.getInvoker().getProperties(jbpContext);
+            }
+
+            Portlet portlet = getPortletFrom(portletContext);
+            PortletInfo info = portlet.getInfo();
+
+            PropertyList result = new PropertyList();
+            int propertyNb = properties.size();
+
+            if (propertyNb > 0)
+            {
+               Property[] resProperties = new Property[propertyNb];
+               int i = 0;
+               PreferenceInfo prefInfo;
+               String key;
+               Value value;
+               LocalizedString displayName;
+
+               for (Iterator entries = properties.entrySet().iterator(); entries.hasNext(); i++)
+               {
+                  Map.Entry entry = (Map.Entry)entries.next();
+                  key = (String)entry.getKey();
+                  value = (Value)entry.getValue();
+                  prefInfo = info.getPreferences().getPreference(key);
+                  displayName = prefInfo.getDisplayName();
+                  String lang = LocaleInfo.getRFC3066LanguageTagFor(displayName.getDefaultLocale());
+                  resProperties[i] = WSRPTypeFactory.createProperty(displayName.getDefaultString(), lang, value.asString());
+               }
+
+               result.setProperties(resProperties);
+            }
+
+            return result;
+         }
+         catch (PortletInvokerException e)
+         {
+            throw(InvalidHandleFault)WSRPUtils.createFaultFrom(InvalidHandleFault.class, e);
+         }
+
+      }
+
+      return null; // shouldn't happen
    }
 
+   private Set getKeysFromNames(String[] names)
+   {
+      Set keys = null;
+      if (names != null)
+      {
+         if (names.length == 0)
+         {
+            keys = Collections.EMPTY_SET;
+         }
+         else
+         {
+            // todo fix-me we need to work around http://jira.jboss.com/jira/browse/JBWS-1300 for now:
+            boolean allNamesNull = true;
+            for (int i = 0; i < names.length && allNamesNull; i++)
+            {
+               allNamesNull = (names[i] == null);
+            }
+            if (allNamesNull)
+            {
+               keys = null;
+            }
+            else
+            {
+               keys = Tools.toSet(names);
+            }
+         }
+      }
+      return keys;
+   }
+
    public PortletPropertyDescriptionResponse getPortletPropertyDescription(GetPortletPropertyDescription getPortletPropertyDescription) throws MissingParametersFault, InconsistentParametersFault, InvalidUserCategoryFault, InvalidRegistrationFault, AccessDeniedFault, InvalidHandleFault, OperationFailedFault, RemoteException
    {
-      return null;  // todo: implement
+      WSRPUtils.throwOperationFailedFaultIfValueIsMissing(getPortletPropertyDescription, GET_PORTLET_PROPERTY_DESCRIPTION);
+
+      PortletContext portletContext = getPortletPropertyDescription.getPortletContext();
+      WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletContext, PORTLET_CONTEXT, GET_PORTLET_PROPERTY_DESCRIPTION);
+
+      if (producer.isRegistrationValid(getPortletPropertyDescription.getRegistrationContext()))
+      {
+         Portlet portlet = getPortletFrom(portletContext);
+         PortletInfo info = portlet.getInfo();
+      }
+      return null; // shouldn't happen
    }
+
+   private Portlet getPortletFrom(PortletContext portletContext) throws InvalidHandleFault
+   {
+      Portlet portlet;
+      try
+      {
+         portlet = producer.getInvoker().getPortlet(WSRPUtils.convertWSRPPortletContextToPortalPortletContext(portletContext));
+      }
+      catch (PortletInvokerException e)
+      {
+         throw(InvalidHandleFault)WSRPUtils.createFaultFrom(InvalidHandleFault.class, e);
+      }
+      return portlet;
+   }
 }

Modified: trunk/wsrp/src/resources/test-basic-portlet-war/WEB-INF/portlet.xml
===================================================================
--- trunk/wsrp/src/resources/test-basic-portlet-war/WEB-INF/portlet.xml	2006-10-13 16:28:41 UTC (rev 5438)
+++ trunk/wsrp/src/resources/test-basic-portlet-war/WEB-INF/portlet.xml	2006-10-13 16:30:12 UTC (rev 5439)
@@ -17,9 +17,13 @@
 
       <portlet-preferences>
          <preference>
-            <name>prefName</name>
-            <value>prefValue</value>
+            <name>prefName1</name>
+            <value>prefValue1</value>
          </preference>
+         <preference>
+            <name>prefName2</name>
+            <value>prefValue2</value>
+         </preference>
       </portlet-preferences>
    </portlet>
 




More information about the jboss-svn-commits mailing list