views:

738

answers:

1

How can I programmatically add portlet to the JBoss Portal dashboard of specific user? Is there any remote API of the JBoss Portal to do this? SOAP web service, may be MBean-based API? Of course, as a last resort I can implement such service myself and deploy it to the JBoss Portal, but ideally it should not require deploying anything to the JBoss.

I need to do this from application not deployed on the JBoss. It runs on the separate Tomcat instance. The application knows the portal address, it knows the user name and credentials, I can establish any trust relationships I need between the application and the portal.

More detailed description: I have a Google Gadget and I want to create a button in my application that will add the gadget as a portlet to my portal. So, user opens my application, presses the "Add to dashboard" button and Google gadget is added to the portal dashboard.

+1  A: 

Hope this peace of code helps:

   //container
    container = (CustomizationManager)MBeanProxy.get(CustomizationManager.class, new ObjectName("portal:service=CustomizationManager"), MBeanServerLocator.locateJBoss());

    //transaction manager
    tm = (TransactionManager) new InitialContext().lookup("java:/TransactionManager");      

    tm.begin();

    //dashboard
    dashboard = container.getDashboard(new org.jboss.portal.identity.User() {

        public boolean validatePassword(String arg0) {
            return false;
        }

        public void updatePassword(String arg0) throws IdentityException {
        }

        public String getUserName() {
            return userId;
        }

        public Object getId() {
            return null;
        }
    });     
    System.out.println("!!! Portlal: " + dashboard.toString());

    //default page
    defaultPage = dashboard.getPage("default");
    System.out.println("!!! Page: " + defaultPage.toString());

    //gets page windows
    Collection<PortalObject> objects = defaultPage.getChildren();
    if (objects != null && objects.size() > 0) {
        for (PortalObject object : objects) {
            System.out.println("!!! PageChild: " + object.getName());
            System.out.println("!!! WindowRegion: " + object.getDeclaredProperty("theme.region"));

            String windowPortletName = object.getDeclaredProperty("portletName");

            if (StringUtils.equals(object.getDeclaredProperty("theme.region"), "column1"))
            {
                column1Windows.add(object.getName());

                System.out.println("!!! Column1Window: " + object.getName());
                System.out.println("!!! Column1WindowPortletName: " + object.getDeclaredProperty("portletName"));

                //removes from portlets list if already exists
                Iterator iterator = portlets.iterator();
                while (iterator.hasNext())
                {
                    Portlet tempPortlet = (Portlet) iterator.next();
                    if (StringUtils.equals(tempPortlet.getSystemName(), windowPortletName))
                    {
                        iterator.remove();
                    }                       
                }
            }
            else if (StringUtils.equals(object.getDeclaredProperty("theme.region"), "column2"))
            {
                column2Windows.add(object.getName());
                System.out.println("!!! Column2Window: " + object.getName());

                //removes from portlets list if already exists
                Iterator iterator = portlets.iterator();
                while (iterator.hasNext())
                {
                    Portlet tempPortlet = (Portlet) iterator.next();
                    if (StringUtils.equals(tempPortlet.getSystemName(), windowPortletName))
                    {
                        iterator.remove();
                    }                       
                }

            }
        }
    }

    tm.commit();        
Genadii Ganebnyi