[portal-commits] JBoss Portal SVN: r5898 - in trunk/wsrp/src/main/org/jboss/portal: test/wsrp/v1/producer wsrp wsrp/producer

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Mon Dec 18 23:24:12 EST 2006


Author: chris.laprun at jboss.com
Date: 2006-12-18 23:24:10 -0500 (Mon, 18 Dec 2006)
New Revision: 5898

Modified:
   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/WSRPUtils.java
   trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
Log:
- Implemented clonePortlet, destroyPortlets and setPortletProperties on Producer.
- Added associated test cases (don't currently pass because some behavior need to be fixed wrt POPs).
- Added creation methods in WSRPTypeFactory.

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-12-19 00:58:22 UTC (rev 5897)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/PortletManagementTestCase.java	2006-12-19 04:24:10 UTC (rev 5898)
@@ -26,15 +26,23 @@
 import org.jboss.portal.common.junit.ExtendedAssert;
 import org.jboss.portal.wsrp.WSRPConstants;
 import org.jboss.portal.wsrp.WSRPTypeFactory;
+import org.jboss.portal.wsrp.core.ClonePortlet;
+import org.jboss.portal.wsrp.core.DestroyFailed;
+import org.jboss.portal.wsrp.core.DestroyPortlets;
+import org.jboss.portal.wsrp.core.DestroyPortletsResponse;
 import org.jboss.portal.wsrp.core.GetPortletDescription;
 import org.jboss.portal.wsrp.core.GetPortletProperties;
 import org.jboss.portal.wsrp.core.GetPortletPropertyDescription;
+import org.jboss.portal.wsrp.core.GetServiceDescription;
 import org.jboss.portal.wsrp.core.ModelDescription;
+import org.jboss.portal.wsrp.core.OperationFailedFault;
+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.PropertyDescription;
 import org.jboss.portal.wsrp.core.PropertyList;
+import org.jboss.portal.wsrp.core.SetPortletProperties;
 
 import javax.xml.soap.SOAPElement;
 import java.util.Arrays;
@@ -54,16 +62,57 @@
       super("PortletManagementTestCase", TEST_BASIC_PORTLET_WAR);
    }
 
-   public void testClonePortlet()
+   public void testClonePortlet() throws Exception
    {
-      // todo: implement
+      String handle = getDefaultHandle();
+      // first check that we get a new PortletContext
+      PortletContext portletContext = clonePortlet(handle);
+      ExtendedAssert.assertNotNull(portletContext);
+      ExtendedAssert.assertFalse(WSRPTypeFactory.createPortletContext(handle).equals(portletContext));
+
+      // then check that the initial state is identical
+      GetPortletProperties getPortletProperties = WSRPTypeFactory.createGetPortletProperties(null, portletContext.getPortletHandle());
+      Property[] result = portletManagementService.getPortletProperties(getPortletProperties).getProperties();
+      getPortletProperties = WSRPTypeFactory.createGetPortletProperties(null, handle);
+      checkGetPropertiesResponse(portletManagementService.getPortletProperties(getPortletProperties), result);
+
+      // check that new clone is not listed in service description
+      GetServiceDescription gs = getNoRegistrationServiceDescriptionRequest();
+      checkServiceDescriptionWithOnlyBasicPortlet(gs);
    }
 
-   public void testDestroyPortlets()
+   public void testDestroyPortlets() throws Exception
    {
-      // todo: implement
+      // first try to destroy POP, should fail
+      String handle = getDefaultHandle();
+      DestroyPortlets destroyPortlets = WSRPTypeFactory.createDestroyPortlets(null, new String[]{handle});
+      DestroyPortletsResponse response = portletManagementService.destroyPortlets(destroyPortlets);
+      ExtendedAssert.assertNotNull(response);
+      DestroyFailed[] failures = response.getDestroyFailed();
+      ExtendedAssert.assertNotNull(failures);
+      ExtendedAssert.assertEquals(1, failures.length);
+      DestroyFailed failure = failures[0];
+      ExtendedAssert.assertNotNull(failure);
+      ExtendedAssert.assertEquals(handle, failure.getPortletHandle());
+      ExtendedAssert.assertNotNull(failure.getReason());
+
+      // clone portlet and try to destroy it
+      PortletContext portletContext = clonePortlet(handle);
+      destroyPortlets = WSRPTypeFactory.createDestroyPortlets(null, new String[]{portletContext.getPortletHandle()});
+      response = portletManagementService.destroyPortlets(destroyPortlets);
+      ExtendedAssert.assertNotNull(response);
+      failures = response.getDestroyFailed();
+      ExtendedAssert.assertNull(failures);
    }
 
+   private PortletContext clonePortlet(String handle)
+      throws org.jboss.portal.wsrp.core.InvalidUserCategoryFault, org.jboss.portal.wsrp.core.AccessDeniedFault, org.jboss.portal.wsrp.core.OperationFailedFault, org.jboss.portal.wsrp.core.InvalidHandleFault, org.jboss.portal.wsrp.core.InvalidRegistrationFault, org.jboss.portal.wsrp.core.InconsistentParametersFault, org.jboss.portal.wsrp.core.MissingParametersFault, java.rmi.RemoteException
+   {
+      ClonePortlet clonePortlet = WSRPTypeFactory.createSimpleClonePortlet(handle);
+      PortletContext portletContext = portletManagementService.clonePortlet(clonePortlet);
+      return portletContext;
+   }
+
    public void testGetPortletDescription() throws Exception
    {
       String handle = getDefaultHandle();
@@ -98,14 +147,6 @@
       checkGetPropertiesResponse(response, expected);
    }
 
-   private Property[] checkGetPropertiesResponse(PropertyList response, Property[] expected)
-   {
-      ExtendedAssert.assertNotNull(response);
-      Property[] properties = response.getProperties();
-      ExtendedAssert.assertEquals(expected, properties, false, "Didn't receive expected properties!", new PropertyDecorator());
-      return properties;
-   }
-
    public void testGetPortletPropertyDescription() throws Exception
    {
       String handle = getDefaultHandle();
@@ -126,7 +167,48 @@
       expected[1].setHint(WSRPTypeFactory.createLocalizedString("prefName2"));
       expected[1].setLabel(WSRPTypeFactory.createLocalizedString("prefName2"));
 
-      ExtendedAssert.assertEquals(2, propertyDescriptions.length);
+      checkPropertyDescriptions(expected, propertyDescriptions);
+   }
+
+   public void testSetPortletProperties() throws Exception
+   {
+      String handle = getDefaultHandle();
+
+      PortletContext portletContext = clonePortlet(handle);
+      PropertyList propertyList = WSRPTypeFactory.createPropertyList();
+      Property[] properties = new Property[]{
+         WSRPTypeFactory.createProperty("prefName1", "en", "newPrefValue1"),
+         WSRPTypeFactory.createProperty("prefName2", "en", "newPrefValue2")
+      };
+      propertyList.setProperties(properties);
+      SetPortletProperties setPortletProperties = WSRPTypeFactory.createSetPortletProperties(portletContext, propertyList);
+
+      PortletContext response = portletManagementService.setPortletProperties(setPortletProperties);
+      GetPortletProperties getPortletProperties = WSRPTypeFactory.createGetPortletProperties(null, portletContext.getPortletHandle());
+      checkGetPropertiesResponse(portletManagementService.getPortletProperties(getPortletProperties), properties);
+
+      portletContext = WSRPTypeFactory.createPortletContext(handle);
+      try
+      {
+         response = portletManagementService.setPortletProperties(setPortletProperties);
+         ExtendedAssert.fail("Setting properties on Producer-Offered Portlet should fail...");
+      }
+      catch (OperationFailedFault expected)
+      {
+      }
+   }
+
+   private Property[] checkGetPropertiesResponse(PropertyList response, Property[] expected)
+   {
+      ExtendedAssert.assertNotNull(response);
+      Property[] properties = response.getProperties();
+      ExtendedAssert.assertEquals(expected, properties, false, "Didn't receive expected properties!", new PropertyDecorator());
+      return properties;
+   }
+
+   private void checkPropertyDescriptions(PropertyDescription[] expected, PropertyDescription[] propertyDescriptions)
+   {
+      ExtendedAssert.assertEquals(expected.length, propertyDescriptions.length);
       PropertyDescription propDesc = propertyDescriptions[0];
       ExtendedAssert.assertNotNull(propDesc);
       String name = propDesc.getName();
@@ -146,11 +228,6 @@
       }
    }
 
-   public void testSetPortletProperties()
-   {
-      // todo: implement
-   }
-
    protected String getMostUsedPortletWARFileName()
    {
       return TEST_BASIC_PORTLET_WAR;

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java	2006-12-19 00:58:22 UTC (rev 5897)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java	2006-12-19 04:24:10 UTC (rev 5898)
@@ -35,6 +35,10 @@
 import org.jboss.portal.wsrp.core.BlockingInteractionResponse;
 import org.jboss.portal.wsrp.core.CacheControl;
 import org.jboss.portal.wsrp.core.ClientData;
+import org.jboss.portal.wsrp.core.ClonePortlet;
+import org.jboss.portal.wsrp.core.DestroyFailed;
+import org.jboss.portal.wsrp.core.DestroyPortlets;
+import org.jboss.portal.wsrp.core.DestroyPortletsResponse;
 import org.jboss.portal.wsrp.core.GetMarkup;
 import org.jboss.portal.wsrp.core.GetPortletDescription;
 import org.jboss.portal.wsrp.core.GetPortletProperties;
@@ -55,11 +59,13 @@
 import org.jboss.portal.wsrp.core.PortletPropertyDescriptionResponse;
 import org.jboss.portal.wsrp.core.Property;
 import org.jboss.portal.wsrp.core.PropertyDescription;
+import org.jboss.portal.wsrp.core.PropertyList;
 import org.jboss.portal.wsrp.core.RegistrationContext;
 import org.jboss.portal.wsrp.core.RegistrationData;
 import org.jboss.portal.wsrp.core.RuntimeContext;
 import org.jboss.portal.wsrp.core.ServiceDescription;
 import org.jboss.portal.wsrp.core.SessionContext;
+import org.jboss.portal.wsrp.core.SetPortletProperties;
 import org.jboss.portal.wsrp.core.StateChange;
 import org.jboss.portal.wsrp.core.Templates;
 import org.jboss.portal.wsrp.core.UpdateResponse;
@@ -738,4 +744,97 @@
    {
       return createGetPortletPropertyDescription(null, createPortletContext(portletHandle), null, null);
    }
+
+
+   /**
+    * portletHandle(xsd:string), reason(xsd:string)
+    *
+    * @param portletHandle
+    * @param reason
+    * @return
+    * @since 2.6
+    */
+   public static DestroyFailed createDestroyFailed(String portletHandle, String reason)
+   {
+      ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletHandle, "Portlet handle", "DestroyFailed");
+      ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(reason, "Reason for failure", "DestroyFailed");
+      // todo: check reason should be a fault code from Section 13 of spec but this is not clear... 
+      return new DestroyFailed(portletHandle, reason);
+   }
+
+   /**
+    * destroyFailed(DestroyFailed)*, extensions(Extension)*
+    *
+    * @param destroyFailed
+    * @return
+    * @since 2.6
+    */
+   public static DestroyPortletsResponse createDestroyPortletsResponse(DestroyFailed[] destroyFailed)
+   {
+      return new DestroyPortletsResponse(destroyFailed, null);
+   }
+
+   /**
+    * registrationContext(RegistrationContext)?, portletContext(PortletContext), userContext(UserContext)?,
+    * propertyList(PropertyList)
+    *
+    * @param portletContext
+    * @param propertyList
+    * @return
+    * @since 2.6
+    */
+   public static SetPortletProperties createSetPortletProperties(PortletContext portletContext, PropertyList propertyList)
+   {
+      ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "PortletContext");
+      ParameterValidation.throwIllegalArgExceptionIfNull(propertyList, "PropertyList");
+
+      return new SetPortletProperties(null, portletContext, null, propertyList);
+   }
+
+   /**
+    * same as createClonePortlet(null, createPortletContext(portletHandle), null)
+    *
+    * @param portletHandle
+    * @return
+    * @since 2.6
+    */
+   public static ClonePortlet createSimpleClonePortlet(String portletHandle)
+   {
+      return createClonePortlet(null, createPortletContext(portletHandle), null);
+   }
+
+   /**
+    * registrationContext(RegistrationContext)?, portletContext(PortletContext), userContext(UserContext)?
+    *
+    * @return
+    * @since 2.6
+    */
+   public static ClonePortlet createClonePortlet(RegistrationContext registrationContext, PortletContext portletContext, UserContext userContext)
+   {
+      ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "PortletContext");
+      return new ClonePortlet(registrationContext, portletContext, userContext);
+   }
+
+   /**
+    * registrationContext(RegistrationContext)?, portletHandles(xsd:string)+
+    *
+    * @return
+    * @since 2.6
+    */
+   public static DestroyPortlets createDestroyPortlets(RegistrationContext registrationContext, String[] portletHandles)
+   {
+      ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletHandles, "Portlet handles");
+      return new DestroyPortlets(registrationContext, portletHandles);
+   }
+
+   /**
+    * properties(Property)*, resetProperties(ResetProperty)*, extensions(Extension)*
+    *
+    * @return
+    * @since 2.6
+    */
+   public static PropertyList createPropertyList()
+   {
+      return new PropertyList();
+   }
 }

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java	2006-12-19 00:58:22 UTC (rev 5897)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java	2006-12-19 04:24:10 UTC (rev 5898)
@@ -222,7 +222,7 @@
       return desiredLocales;
    }
 
-   public static PortletContext convertWSRPPortletContextToPortalPortletContext(org.jboss.portal.wsrp.core.PortletContext portletContext)
+   public static PortletContext convertToPortalPortletContext(org.jboss.portal.wsrp.core.PortletContext portletContext)
    {
       ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "PortletContext");
       String handle = portletContext.getPortletHandle();
@@ -236,6 +236,21 @@
    }
 
    /**
+    * @param portletContext
+    * @return Since 2.6
+    */
+   public static org.jboss.portal.wsrp.core.PortletContext convertToWSRPPortletContext(PortletContext portletContext)
+   {
+      ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "PortletContext");
+      String id = portletContext.getId();
+      ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "portlet id", "PortletContext");
+
+      org.jboss.portal.wsrp.core.PortletContext result = WSRPTypeFactory.createPortletContext(id);
+      result.setPortletState(portletContext.getState());
+      return result;
+   }
+
+   /**
     * Create a new OperationFailedFault based on the specified cause.
     *
     * @param cause the cause why the operation failed

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java	2006-12-19 00:58:22 UTC (rev 5897)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/PortletManagementHandler.java	2006-12-19 04:24:10 UTC (rev 5898)
@@ -27,18 +27,24 @@
 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.StringValue;
 import org.jboss.portal.common.value.Value;
+import org.jboss.portal.portlet.InvalidPortletIdException;
+import org.jboss.portal.portlet.NoSuchPortletException;
 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.info.PreferencesInfo;
+import org.jboss.portal.portlet.state.DestroyCloneFailure;
+import org.jboss.portal.portlet.state.PropertyChange;
 import org.jboss.portal.portlet.state.PropertyMap;
 import org.jboss.portal.wsrp.WSRPConstants;
 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.DestroyFailed;
 import org.jboss.portal.wsrp.core.DestroyPortlets;
 import org.jboss.portal.wsrp.core.DestroyPortletsResponse;
 import org.jboss.portal.wsrp.core.GetPortletDescription;
@@ -56,13 +62,17 @@
 import org.jboss.portal.wsrp.core.Property;
 import org.jboss.portal.wsrp.core.PropertyDescription;
 import org.jboss.portal.wsrp.core.PropertyList;
+import org.jboss.portal.wsrp.core.ResetProperty;
 import org.jboss.portal.wsrp.core.SetPortletProperties;
 import org.jboss.portal.wsrp.core.UserContext;
 import org.jboss.portal.wsrp.core.WSRP_v1_PortletManagement_PortType;
 
+import javax.xml.soap.SOAPElement;
 import java.rmi.RemoteException;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -136,6 +146,7 @@
             if (!prefInfo.isReadOnly().booleanValue())
             {
                //todo: check what we should use key
+               //todo: right now we only support String properties
                PropertyDescription desc = WSRPTypeFactory.createPropertyDescription(prefInfo.getKey(), WSRPConstants.XSD_STRING);
                desc.setLabel(WSRPUtils.convertToWSRPLocalizedString(prefInfo.getDisplayName(), desiredLocales));
                desc.setHint(WSRPUtils.convertToWSRPLocalizedString(prefInfo.getDescription(), desiredLocales));
@@ -147,22 +158,167 @@
       return WSRPTypeFactory.createPortletPropertyDescriptionResponse(descs);
    }
 
-   public PortletContext clonePortlet(ClonePortlet clonePortlet) throws InvalidUserCategoryFault, AccessDeniedFault, OperationFailedFault, InvalidHandleFault, InvalidRegistrationFault, InconsistentParametersFault, MissingParametersFault, RemoteException
+   public PortletContext clonePortlet(ClonePortlet clonePortlet) throws InvalidUserCategoryFault, AccessDeniedFault,
+      OperationFailedFault, InvalidHandleFault, InvalidRegistrationFault, InconsistentParametersFault,
+      MissingParametersFault, RemoteException
    {
-      return null;  // todo: implement
+      WSRPUtils.throwOperationFailedFaultIfValueIsMissing(clonePortlet, "ClonePortlet");
+
+      PortletContext portletContext = clonePortlet.getPortletContext();
+      WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletContext, "PortletContext", "ClonePortlet");
+
+      producer.checkRegistration(clonePortlet.getRegistrationContext());
+
+      UserContext userContext = clonePortlet.getUserContext();
+      checkUserAuthorization(userContext);
+
+      org.jboss.portal.portlet.PortletContext portalPC = WSRPUtils.convertToPortalPortletContext(portletContext);
+      try
+      {
+         org.jboss.portal.portlet.PortletContext response = producer.getInvoker().createClone(portalPC);
+         return WSRPUtils.convertToWSRPPortletContext(response);
+      }
+      catch (InvalidPortletIdException e)
+      {
+         throw (InvalidHandleFault)WSRPUtils.createFaultFrom(InvalidHandleFault.class, e);
+      }
+      catch (NoSuchPortletException e)
+      {
+         throw (InvalidHandleFault)WSRPUtils.createFaultFrom(InvalidHandleFault.class, e);
+      }
+      catch (PortletInvokerException e)
+      {
+         throw WSRPUtils.createOperationFailedFault(e);
+      }
    }
 
-   public DestroyPortletsResponse destroyPortlets(DestroyPortlets destroyPortlets) throws InconsistentParametersFault, MissingParametersFault, InvalidRegistrationFault, OperationFailedFault, RemoteException
+   public DestroyPortletsResponse destroyPortlets(DestroyPortlets destroyPortlets) throws InconsistentParametersFault,
+      MissingParametersFault, InvalidRegistrationFault, OperationFailedFault, RemoteException
    {
-      return null;  // todo: implement
+      WSRPUtils.throwOperationFailedFaultIfValueIsMissing(destroyPortlets, "DestroyPortlets");
+
+      String[] handles = destroyPortlets.getPortletHandles();
+      WSRPUtils.throwMissingParametersFaultIfValueIsMissing(handles, "portlet handles to be destroyed", "DestroyPortlets");
+
+      producer.checkRegistration(destroyPortlets.getRegistrationContext());
+
+      List portletContexts = new ArrayList(handles.length);
+      for (int i = 0; i < handles.length; i++)
+      {
+         portletContexts.add(org.jboss.portal.portlet.PortletContext.createPortletContext(handles[i]));
+      }
+
+      try
+      {
+         List failuresList = producer.getInvoker().destroyClones(portletContexts);
+         int failuresNumber = failuresList.size();
+         DestroyFailed[] destroyFailed;
+         if (failuresNumber > 0)
+         {
+            destroyFailed = new DestroyFailed[failuresNumber];
+            int i = 0;
+            for (Iterator failures = failuresList.iterator(); failures.hasNext();)
+            {
+               DestroyCloneFailure failure = (DestroyCloneFailure)failures.next();
+               destroyFailed[i++] = WSRPTypeFactory.createDestroyFailed(failure.getPortletId(), failure.getMessage());
+            }
+         }
+         else
+         {
+            destroyFailed = null;
+         }
+
+         return WSRPTypeFactory.createDestroyPortletsResponse(destroyFailed);
+      }
+      catch (PortletInvokerException e)
+      {
+         throw WSRPUtils.createOperationFailedFault(e);
+      }
    }
 
-   public PortletContext setPortletProperties(SetPortletProperties setPortletProperties) throws OperationFailedFault, InvalidHandleFault, MissingParametersFault, InconsistentParametersFault, InvalidUserCategoryFault, AccessDeniedFault, InvalidRegistrationFault, RemoteException
+   public PortletContext setPortletProperties(SetPortletProperties setPortletProperties) throws OperationFailedFault,
+      InvalidHandleFault, MissingParametersFault, InconsistentParametersFault, InvalidUserCategoryFault,
+      AccessDeniedFault, InvalidRegistrationFault, RemoteException
    {
-      return null;  // todo: implement
+      WSRPUtils.throwOperationFailedFaultIfValueIsMissing(setPortletProperties, "SetPortletProperties");
+
+      PortletContext portletContext = setPortletProperties.getPortletContext();
+      WSRPUtils.throwMissingParametersFaultIfValueIsMissing(portletContext, "PortletContext", "SetPortletProperties");
+
+      PropertyList propertyList = setPortletProperties.getPropertyList();
+      WSRPUtils.throwMissingParametersFaultIfValueIsMissing(propertyList, "PropertyList", "SetPortletProperties");
+
+      producer.checkRegistration(setPortletProperties.getRegistrationContext());
+
+      checkUserAuthorization(setPortletProperties.getUserContext());
+
+      Property[] properties = propertyList.getProperties();
+      ResetProperty[] resetProperties = propertyList.getResetProperties();
+      int changesCount = 0;
+      if (properties != null)
+      {
+         changesCount += properties.length;
+      }
+      if (resetProperties != null)
+      {
+         changesCount += resetProperties.length;
+      }
+
+      if (changesCount > 0)
+      {
+         List changes = new ArrayList(changesCount);
+
+         if (properties != null)
+         {
+            for (int i = 0; i < properties.length; i++)
+            {
+               Property property = properties[i];
+               String value = property.getStringValue();
+
+               // todo: deal with XML values...
+               SOAPElement[] values = property.get_any();
+               String lang = property.getLang(); // todo: deal with language?
+
+               changes.add(PropertyChange.newUpdate(property.getName(), new StringValue(value)));
+            }
+         }
+
+         if (resetProperties != null)
+         {
+            for (int i = 0; i < resetProperties.length; i++)
+            {
+               ResetProperty resetProperty = resetProperties[i];
+               changes.add(PropertyChange.newReset(resetProperty.getName()));
+            }
+         }
+
+         try
+         {
+            org.jboss.portal.portlet.PortletContext resultContext =
+               producer.getInvoker().setProperties(WSRPUtils.convertToPortalPortletContext(portletContext),
+                  (PropertyChange[])changes.toArray(new PropertyChange[0]));
+            return WSRPUtils.convertToWSRPPortletContext(resultContext);
+         }
+         catch (InvalidPortletIdException e)
+         {
+            throw (InvalidHandleFault)WSRPUtils.createFaultFrom(InvalidHandleFault.class, e);
+         }
+         catch (NoSuchPortletException e)
+         {
+            throw (InvalidHandleFault)WSRPUtils.createFaultFrom(InvalidHandleFault.class, e);
+         }
+         catch (PortletInvokerException e)
+         {
+            throw WSRPUtils.createOperationFailedFault(e);
+         }
+      }
+
+      return portletContext;
    }
 
-   public PropertyList getPortletProperties(GetPortletProperties getPortletProperties) throws InvalidHandleFault, MissingParametersFault, InvalidRegistrationFault, AccessDeniedFault, OperationFailedFault, InconsistentParametersFault, InvalidUserCategoryFault, RemoteException
+   public PropertyList getPortletProperties(GetPortletProperties getPortletProperties) throws InvalidHandleFault,
+      MissingParametersFault, InvalidRegistrationFault, AccessDeniedFault, OperationFailedFault,
+      InconsistentParametersFault, InvalidUserCategoryFault, RemoteException
    {
       WSRPUtils.throwOperationFailedFaultIfValueIsMissing(getPortletProperties, GET_PORTLET_PROPERTIES);
 
@@ -180,8 +336,7 @@
       try
       {
          PropertyMap properties;
-         org.jboss.portal.portlet.PortletContext jbpContext =
-            WSRPUtils.convertWSRPPortletContextToPortalPortletContext(portletContext);
+         org.jboss.portal.portlet.PortletContext jbpContext = WSRPUtils.convertToPortalPortletContext(portletContext);
 
          if (keys != null)
          {
@@ -192,10 +347,11 @@
             properties = producer.getInvoker().getProperties(jbpContext);
          }
 
+         //todo: we need to check that the user can actually modify the properties
          Portlet portlet = getPortletFrom(portletContext);
          PortletInfo info = portlet.getInfo();
 
-         PropertyList result = new PropertyList();
+         PropertyList result = WSRPTypeFactory.createPropertyList();
          int propertyNb = properties.size();
 
          if (propertyNb > 0)
@@ -273,7 +429,7 @@
       Portlet portlet;
       try
       {
-         portlet = producer.getInvoker().getPortlet(WSRPUtils.convertWSRPPortletContextToPortalPortletContext(portletContext));
+         portlet = producer.getInvoker().getPortlet(WSRPUtils.convertToPortalPortletContext(portletContext));
       }
       catch (PortletInvokerException e)
       {




More information about the portal-commits mailing list