portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r772283 - in /portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src: main/java/org/apache/jetspeed/components/portletregistry/ test/java/org/apache/jetspeed/components/portletregistry/
Date Wed, 06 May 2009 14:41:14 GMT
Author: woonsan
Date: Wed May  6 14:41:14 2009
New Revision: 772283

URL: http://svn.apache.org/viewvc?rev=772283&view=rev
Log:
JS2-990: Fixing portlet definition cloning problem. Now all collections are copied correctly.
One thing to note: portlet name and display name(s) are not copied to a cloned one
because portlet name or display name(s) are to be used in UI to represent the portlet definition.
Also, adds a simple unit test.

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletregistry/PersistenceBrokerPortletRegistry.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestPortletRegistryDAO.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletregistry/PersistenceBrokerPortletRegistry.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletregistry/PersistenceBrokerPortletRegistry.java?rev=772283&r1=772282&r2=772283&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletregistry/PersistenceBrokerPortletRegistry.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletregistry/PersistenceBrokerPortletRegistry.java
Wed May  6 14:41:14 2009
@@ -27,13 +27,21 @@
 import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport;
 import org.apache.jetspeed.components.portletpreferences.PortletPreferencesProvider;
 import org.apache.jetspeed.om.common.Support;
+import org.apache.jetspeed.om.portlet.ContainerRuntimeOption;
+import org.apache.jetspeed.om.portlet.Description;
+import org.apache.jetspeed.om.portlet.DisplayName;
+import org.apache.jetspeed.om.portlet.EventDefinitionReference;
+import org.apache.jetspeed.om.portlet.InitParam;
+import org.apache.jetspeed.om.portlet.Language;
 import org.apache.jetspeed.om.portlet.LocalizedField;
 import org.apache.jetspeed.om.portlet.PortletApplication;
 import org.apache.jetspeed.om.portlet.PortletDefinition;
 import org.apache.jetspeed.om.portlet.Preference;
-import org.apache.jetspeed.om.portlet.Preferences;
+import org.apache.jetspeed.om.portlet.SecurityRoleRef;
+import org.apache.jetspeed.om.portlet.Supports;
 import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl;
 import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
+import org.apache.jetspeed.util.JetspeedLocale;
 import org.apache.ojb.broker.query.Criteria;
 import org.apache.ojb.broker.query.QueryFactory;
 import org.springframework.dao.DataAccessException;
@@ -341,30 +349,107 @@
         {
             throw new FailedToStorePortletDefinitionException("Cannot clone to portlet named
" + newPortletName + ", name already exists"); 
         }
+        
         PortletDefinitionImpl copy = new PortletDefinitionImpl();
-        copy.setApplication(source.getApplication());
+        
+        // First set the name and display name
+        
         copy.setPortletName(newPortletName);
+        DisplayName displayName = copy.addDisplayName(JetspeedLocale.getDefaultLocale().getLanguage());
+        displayName.setDisplayName(newPortletName);
+        
+        // And, then, copy all attributes
+        
+        copy.setApplication(source.getApplication());
         copy.setPortletClass(source.getPortletClass());
         copy.setResourceBundle(source.getResourceBundle());
         copy.setPreferenceValidatorClassname(source.getPreferenceValidatorClassname());
         copy.setExpirationCache(source.getExpirationCache());
         copy.setCacheScope(source.getCacheScope());
-        Collection<LocalizedField> fields = source.getMetadata().getFields();
-        for (LocalizedField field : fields)
+        
+        for (LocalizedField field : source.getMetadata().getFields())
         {
-            copy.getMetadata().addField(field);            
-        }        
+            copy.getMetadata().addField(field.getLocale(), field.getName(), field.getValue());
+        }
+        
         copy.setJetspeedSecurityConstraint(source.getJetspeedSecurityConstraint());
-        copy.getDescriptions().addAll(source.getDescriptions());
-        copy.getDisplayNames().addAll(source.getDisplayNames());
-        copy.getInitParams().addAll(source.getInitParams());
-        copy.getSupportedProcessingEvents().addAll(source.getSupportedProcessingEvents());
-        copy.getSupportedPublishingEvents().addAll(source.getSupportedPublishingEvents());
-        copy.getSecurityRoleRefs().addAll(source.getSecurityRoleRefs());
-        copy.getSupports().addAll(source.getSupports());
-        copy.getLanguages().addAll(source.getLanguages());
-        copy.getContainerRuntimeOptions().addAll(source.getContainerRuntimeOptions());
+        
+        for (Description desc : source.getDescriptions())
+        {
+            Description copyDesc = copy.addDescription(desc.getLang());
+            copyDesc.setDescription(desc.getDescription());
+        }
+
+        for (InitParam initParam : source.getInitParams())
+        {
+            InitParam copyInitParam = copy.addInitParam(initParam.getParamName());
+            copyInitParam.setParamValue(initParam.getParamValue());
+            
+            for (Description desc : initParam.getDescriptions())
+            {
+                Description copyDesc = copyInitParam.addDescription(desc.getLang());
+                copyDesc.setDescription(desc.getDescription());
+            }
+        }
+        
+        for (EventDefinitionReference eventDefRef : source.getSupportedProcessingEvents())
+        {
+            copy.addSupportedProcessingEvent(eventDefRef.getQName());
+        }
+
+        for (EventDefinitionReference eventDefRef : source.getSupportedPublishingEvents())
+        {
+            copy.addSupportedPublishingEvent(eventDefRef.getQName());
+        }
+        
+        for (SecurityRoleRef secRoleRef : source.getSecurityRoleRefs())
+        {
+            SecurityRoleRef copySecRoleRef = copy.addSecurityRoleRef(secRoleRef.getRoleName());
+            copySecRoleRef.setRoleLink(secRoleRef.getRoleLink());
+            
+            for (Description desc : secRoleRef.getDescriptions())
+            {
+                Description copyDesc = copySecRoleRef.addDescription(desc.getLang());
+                copyDesc.setDescription(desc.getDescription());
+            }
+        }
+        
+        for (Supports supports : source.getSupports())
+        {
+            Supports copySupports = copy.addSupports(supports.getMimeType());
+            
+            for (String portletMode : supports.getPortletModes())
+            {
+                copySupports.addPortletMode(portletMode);
+            }
+            
+            for (String windowState : supports.getWindowStates())
+            {
+                copySupports.addWindowState(windowState);
+            }
+        }
+        
+        for (Language language : source.getLanguages())
+        {
+            Language copyLanguage = copy.addLanguage(language.getLocale());
+            copyLanguage.setTitle(language.getTitle());
+            copyLanguage.setShortTitle(language.getShortTitle());
+            copyLanguage.setKeywords(language.getKeywords());
+            copyLanguage.setSupportedLocale(language.isSupportedLocale());
+        }
+        
+        for (ContainerRuntimeOption runtimeOption : source.getContainerRuntimeOptions())
+        {
+            ContainerRuntimeOption copyRuntimeOption = copy.addContainerRuntimeOption(runtimeOption.getName());
+            
+            for (String value : runtimeOption.getValues())
+            {
+                copyRuntimeOption.addValue(value);
+            }
+        }
+        
         copy.getSupportedPublicRenderParameters().addAll(source.getSupportedPublicRenderParameters());
+        
         //savePortletDefinition(copy);
         source.getApplication().getPortlets().add(copy);
         try

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestPortletRegistryDAO.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestPortletRegistryDAO.java?rev=772283&r1=772282&r2=772283&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestPortletRegistryDAO.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/test/java/org/apache/jetspeed/components/portletregistry/TestPortletRegistryDAO.java
Wed May  6 14:41:14 2009
@@ -18,6 +18,7 @@
 
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 
@@ -39,6 +40,7 @@
 import org.apache.jetspeed.om.portlet.InitParam;
 import org.apache.jetspeed.om.portlet.Language;
 import org.apache.jetspeed.om.portlet.Listener;
+import org.apache.jetspeed.om.portlet.LocalizedField;
 import org.apache.jetspeed.om.portlet.PortletApplication;
 import org.apache.jetspeed.om.portlet.PortletDefinition;
 import org.apache.jetspeed.om.portlet.Preference;
@@ -125,6 +127,91 @@
     {
         verifyData(false);
     }
+    
+    public void testCloningOfPortletDefinition() throws Exception
+    {
+        final String appName = "App_1";
+        final String sourcePortletName = "Portlet 1";
+        final String clonedPortletName = "ClonedPortlet 1";
+        
+        PortletApplication app = portletRegistry.getPortletApplication(appName);
+        assertNotNull("Portlet application, " + appName + ", is not found.", app);
+        
+        PortletDefinition sourcePortlet = app.getPortlet(sourcePortletName);
+        assertNotNull("Portlet definition, " + sourcePortletName + ", is not found.", sourcePortlet);
+        
+        PortletDefinition clonedPortlet = app.getPortlet(clonedPortletName);
+        assertNull("A portlet definition with cloned portlet name, " + clonedPortletName
+ ", shouldn't be there.", 
+                   clonedPortlet);
+        
+        try
+        {
+            Collection<LocalizedField> sourceFields = sourcePortlet.getMetadata().getFields();
+            portletRegistry.clonePortletDefinition(sourcePortlet, clonedPortletName);
+            clonedPortlet = app.getPortlet(clonedPortletName);
+            assertNotNull("Cloned portlet is not found after invoking cloning method.", clonedPortlet);
+
+            Collection<LocalizedField> clonedFields = clonedPortlet.getMetadata().getFields();
+            
+            assertEquals("The metadata fields count is not equals.", sourceFields.size(),
clonedFields.size());
+            
+            for (LocalizedField sourceField : sourceFields)
+            {
+                List<LocalizedField> foundClonedFields = findLocalizedFieldsByNameAndLocale(clonedFields,
sourceField.getName(), sourceField.getLocale());
+                assertFalse("There's no matching metadata field in cloned portlet definition.",
foundClonedFields.isEmpty());
+                assertNotNull("The metadata field values from the source metadata not found.",
findLocalizedFieldByValue(foundClonedFields, sourceField.getValue()));
+            }
+            
+            for (LocalizedField clonedField : clonedFields)
+            {
+                clonedField.setValue("Cloned value of " + clonedField.getValue());
+            }
+            
+            for (LocalizedField sourceField : sourceFields)
+            {
+                List<LocalizedField> foundClonedFields = findLocalizedFieldsByNameAndLocale(clonedFields,
sourceField.getName(), sourceField.getLocale());
+                assertFalse("There's no matching metadata field in cloned portlet definition.",
foundClonedFields.isEmpty());
+                assertNull("The metadata field values from the source metadata should not
be found because the ones of cloned stuff have been changed.", 
+                           findLocalizedFieldByValue(foundClonedFields, sourceField.getValue()));
+            }
+        }
+        finally
+        {
+            if (clonedPortlet != null)
+            {
+                app.getPortlets().remove(clonedPortlet);
+                portletRegistry.updatePortletApplication(app);
+            }
+        }
+    }
+    
+    private static List<LocalizedField> findLocalizedFieldsByNameAndLocale(final Collection<LocalizedField>
sourceFields, final String name, final Locale locale)
+    {
+        List<LocalizedField> localizedFields = new LinkedList<LocalizedField>();
+        
+        for (LocalizedField sourceField : sourceFields)
+        {
+            if (name.equals(sourceField.getName()) && locale.equals(sourceField.getLocale()))
+            {
+                localizedFields.add(sourceField);
+            }
+        }
+        
+        return localizedFields;
+    }
+    
+    private static LocalizedField findLocalizedFieldByValue(final Collection<LocalizedField>
sourceFields, String value)
+    {
+        for (LocalizedField sourceField : sourceFields)
+        {
+            if (value.equals(sourceField.getValue()))
+            {
+                return sourceField;
+            }
+        }
+
+        return null;
+    }
 
     private void addDublinCore(GenericMetadata metadata)
     {



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message