Package org.apache.jetspeed.om.common.portlet

Examples of org.apache.jetspeed.om.common.portlet.MutablePortletApplication


                }
                register = false;
            }

      // try to get the PA from database by context name
      MutablePortletApplication pa = registry.getPortletApplication(contextName);

            if (pa != null)
            {
                if (log.isDebugEnabled())
                {
                    log.debug("Portlet Application " + contextName + " found in registry.");
              }
                if ( pa.getApplicationType() != paType )
                {
                    throw new RegistryException("Cannot start portlet application "+contextName+": as Application Types don't match: " + pa.getApplicationType() + " != " + paType);
                }
                if (!monitored && changeMonitor != null)
                {
                    changeMonitor.remove(contextName);
                }
                if (log.isDebugEnabled())
                {
                    log.debug("unregistering portlet application " + contextName + "...");
                }
                portletFactory.unregisterPortletApplication(pa);                       
            }
//            if (register && (pa == null || checksum != pa.getChecksum()))
            if (register)
            {
              if (pa == null)
              {
                // new
                  try
                  {
                      if (log.isDebugEnabled())
                        {
                          log.debug("Register new portlet application " + contextName + ".");
                        }
                      pa = registerPortletApplication(paWar, pa, paType, paClassLoader, silent);
                  }
                  catch (Exception e)
                  {
                      String msg = "Error register new portlet application " + contextName + ".";
                   
                      if (log.isDebugEnabled())
                    {
                        log.debug(msg);
                    }
                      throw new RegistryException(msg);
                     
                  }
              }
              else
              {
                    if (log.isDebugEnabled())
                    {
                        log.debug("Re-register existing portlet application " + contextName + ".");
                    }
                int status = nodeManager.checkNode(new Long(pa.getId().toString()), pa.getName());
              boolean reregister = false;
              boolean deploy = false;
              switch (status)
              {
                case  NodeManager.NODE_NEW:
                {
                            if (log.isDebugEnabled())
                            {
                                log.debug("Node for Portlet application " + contextName + " is NEW.");
                            }
                    //only reason is that the file got somehow corrupted
                    // so we really do not know what is going on here...
                    // the best chance at this point is to reregister (which might be the absolute wrong choice)
                    log.warn("The portlet application " + pa.getName() + " is registered in the database but not locally .... we will reregister");
                    reregister = true;
                  if (checksum != pa.getChecksum())
                  {
                      log.warn("The provided portlet application " + pa.getName() + " is a different version than in the database (db-checksum=" + pa.getChecksum() + ", local-checksum=: " + checksum + ") .... we will redeploy (also to the database)");
                  deploy = true;
                  }
                  break;
                }
                case  NodeManager.NODE_SAVED:
                {
                            if (log.isDebugEnabled())
                            {
                                log.debug("Node for Portlet application " + contextName + " is SAVED.");
                            }
                  if (checksum != pa.getChecksum())
                        { 
                      log.warn("The provided portlet application " + pa.getName() + " is a different version than in the local node info and the database (db-checksum=" + pa.getChecksum() + ", local-checksum=: " + checksum + ") .... we will reregister AND redeploy (also to the database)");
                    //database and local node info are in synch, so we assume that this is a brand new
                    // war .... let's deploy
                    reregister = true;
                    deploy = true;
                        }
                  break;
                }
                case  NodeManager.NODE_OUTDATED:
                {
                            // new version in database, maybe changed by a different cluster node
                    if (log.isDebugEnabled())
                    {
                        log.debug("Node for Portlet application " + contextName + " is OUTDATED (local PA.id < DB PA.id).");
                    }
                    //database version is older (determined by id) than the database
                  //let's deploy and reregister
                    if (checksum != pa.getChecksum())
                    {
                      log.error("The portlet application " + pa.getName() + " provided for the upgrade IS WRONG. The database checksum= " + pa.getChecksum() + ", but the local=" + checksum + "....THIS NEEDS TO BE CORRECTED");
                      // if the checksums do not match make sure the database is updated with the new PA from file system
                      // I've observed "unavailable PA" in clustered env for the cluster node that reported OUTDATED state
                      deploy = true;
                  }
                    reregister = true;
                    break;
                }
              }
              if (deploy)
              {
                  if (log.isDebugEnabled())
                  {
                      log.debug("Register (deploy=true) Portlet application " + contextName + " in database.");
                        }
                      pa = registerPortletApplication(paWar, pa, paType, paClassLoader, silent);
              }
              else
                if (reregister)
                {
                            if (log.isDebugEnabled())
                            {
                                log.debug("Re-Register (reregister=true) Portlet application " + contextName + ".");
                            }
                  // add to search engine result
                  this.updateSearchEngine(true, pa);
                  this.updateSearchEngine(false, pa);
                 
                  // and add to the current node info
                  try
                  {
                    nodeManager.addNode(new Long(pa.getId().toString()), pa.getName());
                  } catch (Exception e)
                  {
                      log.error("Adding node for portlet application " + pa.getName() + " caused exception" , e);
                  }
                }
               
             
              }
View Full Code Here


  }

  protected void stopPA(String contextName, int paType)
    throws RegistryException
  {
    MutablePortletApplication pa = null;
       
        try
        {
            pa = registry.getPortletApplication(contextName);
        }
        catch (Exception e)
        {
            // ignore errors during portal shutdown
        }
        if  (pa != null && pa.getApplicationType() != paType)
        {
            throw new RegistryException("Cannot stop portlet application "+contextName+": as Application Types don't match: " + pa.getApplicationType() + " != " + paType);
        }
        DescriptorChangeMonitor monitor = this.monitor;
        if ( monitor != null )
        {
            monitor.remove(contextName);
View Full Code Here

        // Check if user info map is in cache.
        Collection linkedUserAttr = (List)appUserInfoAttrCache.get(oid);
       
        if (linkedUserAttr == null)
        {
            MutablePortletApplication pa = registry.getPortletApplication(oid);
            if (null == pa)
            {
                log.debug(PortletRequest.USER_INFO + " is set to null");
                return null;
            }
            Collection userAttributes = pa.getUserAttributes();
            Collection userAttributeRefs = pa.getUserAttributeRefs();
            linkedUserAttr = mapLinkedUserAttributes(userAttributes, userAttributeRefs);
            appUserInfoAttrCache.put(oid, linkedUserAttr);
        }
        return linkedUserAttr;
    }
View Full Code Here

   
    public void testLoadPortletApplicationTree() throws Exception
    {
        System.out.println("Testing loadPortletApplicationTree");
        PortletApplicationDescriptor pad = new PortletApplicationDescriptor(new FileReader("./test/testdata/deploy/portlet.xml"), "unit-test");
        MutablePortletApplication app = pad.createPortletApplication(false);           
        assertNotNull("App is null", app);
        assertNotNull("Version is null", app.getVersion());
        assertTrue("Version invalid: " + app.getVersion(), app.getVersion().equals("1.0"));
        assertNotNull("PA Identifier is null", app.getApplicationIdentifier());
        assertTrue(
                "PA Identifier invalid: " + app.getApplicationIdentifier(),
                app.getApplicationIdentifier().equals("TestRegistry"));
      
        ExtendedPortletMetadata md = new ExtendedPortletMetadata(new FileReader("./test/testdata/deploy/jetspeed-portlet.xml"), app);
        md.load();
      
        PortletDefinitionComposite def1 = (PortletDefinitionComposite)app.getPortletDefinitionByName(PORTLET_01);
        PortletDefinitionComposite def2 = (PortletDefinitionComposite)app.getPortletDefinitionByName(PORTLET_02);
        PortletDefinitionComposite def3 = (PortletDefinitionComposite)app.getPortletDefinitionByName(PORTLET_03);
        PortletDefinitionComposite def4 = (PortletDefinitionComposite)app.getPortletDefinitionByName(PORTLET_04);
       
        Collection titles = app.getMetadata().getFields("title");
        Collection def1Titles = def1.getMetadata().getFields("title");
        Collection def2Subjects = def2.getMetadata().getFields("subject");
        Collection def3Creators = def3.getMetadata().getFields("creator");
        Collection def4Field1 = def4.getMetadata().getFields("field1");
        Collection def4Fiels2 = def4.getMetadata().getFields("field2");
       
        String securityRef = app.getJetspeedSecurityConstraint();
        assertEquals(titles.size(), 3);
        assertEquals(def1Titles.size(), 4);
        assertEquals(def2Subjects.size(), 5);
        assertEquals(def3Creators.size(), 4);
        assertEquals(def4Field1.size(), 3);
        assertEquals(def4Fiels2.size(), 2);
       
        // Security Constraints tests
        assertEquals(securityRef, "admin-only");
        assertEquals(def1.getJetspeedSecurityConstraint(), "users-1");
        assertEquals(def2.getJetspeedSecurityConstraint(), "users-2");
        assertEquals(def3.getJetspeedSecurityConstraint(), "users-4");
        assertNull(def4.getJetspeedSecurityConstraint());
       
        Collection servicesCollection = app.getJetspeedServices();
        assertNotNull("Metadata services is null", servicesCollection);
        assertEquals("Expected 2 service definitions", servicesCollection.size(), 2);
        Object[] services = servicesCollection.toArray();
        JetspeedServiceReference service = (JetspeedServiceReference)services[0];
        System.out.println("**** service = " + service.getName());
View Full Code Here

    {
        System.out.println("Testing securityRoles");
        File warFile = new File("./test/testdata/deploy/webapp");
        PortletApplicationWar paWar = new PortletApplicationWar(new DirectoryHelper(warFile), "unit-test", "/" );

        MutablePortletApplication app = paWar.createPortletApp(false);
        assertNotNull("App is null", app);

        MutableWebApplication webApp = paWar.createWebApp();
        assertNotNull("WebApp is null", webApp);

        app.setWebApplicationDefinition(webApp);

        PortletDefinition portlet = app.getPortletDefinitionByName("TestPortlet");
        assertNotNull("TestPortlet is null", portlet);
        checkWebSecurityRoles(webApp);
        checkPortletSecurityRoleRefs(portlet);
        boolean validateFailed = false;
        try
        {
            paWar.validate();
        }
        catch (PortletApplicationException e)
        {
            validateFailed = true;
        }
        assertTrue("Invalid PortletDescriptor validation result", validateFailed);
        SecurityRoleImpl role = new SecurityRoleImpl();
        role.setRoleName("users.manager");
        webApp.addSecurityRole(role);
        try
        {
            paWar.validate();
            validateFailed = false;
        }
        catch (PortletApplicationException e)
        {
        }
        assertEquals("Invalid PortletDescriptor validation result", false, validateFailed);

        // persist the app
        try
        {
           
            portletRegistry.registerPortletApplication(app);
           
        }
        catch (Exception e)
        {
            String msg = "Unable to register portlet application, " + app.getName()
                    + ", through the portlet registry: " + e.toString();
           
            throw new Exception(msg, e);
        }
        // clear cache
       

        // read back in
        app = portletRegistry.getPortletApplication("unit-test");
        validateFailed = true;
        try
        {
            paWar.validate();
            validateFailed = false;
        }
        catch (PortletApplicationException e)
        {
        }
        assertEquals("Invalid loaded PortletDescriptor validation result", false, validateFailed);

        // remove the app
        try
        {
           
            portletRegistry.removeApplication(app);
           
        }
        catch (Exception e)
        {
            String msg = "Unable to remove portlet application, " + app.getName()
                    + ", through the portlet portletRegistry: " + e.toString();
            throw new Exception(msg, e);
        }

    }
View Full Code Here

    public void testLoadPortletApplicationTree() throws Exception
    {
        System.out.println("Testing loadPortletApplicationTree");
        PortletApplicationDescriptor pad = new PortletApplicationDescriptor(new FileReader("./test/testdata/deploy/portlet.xml"), "unit-test");
        MutablePortletApplication app = pad.createPortletApplication(true);
        assertNotNull("App is null", app);
        assertNotNull("Version is null", app.getVersion());
        assertTrue("Version invalid: " + app.getVersion(), app.getVersion().equals("1.0"));
        assertNotNull("PA Identifier is null", app.getApplicationIdentifier());
        assertTrue(
            "PA Identifier invalid: " + app.getApplicationIdentifier(),
            app.getApplicationIdentifier().equals("TestRegistry"));

        validateUserInfo(app);

        // portlets
        PortletDefinitionList portletsList = app.getPortletDefinitionList();
        Iterator it = portletsList.iterator();
        int count = 0;
        while (it.hasNext())
        {
            PortletDefinitionComposite portlet = (PortletDefinitionComposite) it.next();
View Full Code Here

    public void testWritingToDB() throws Exception
    {
       
       
        MutablePortletApplication app = portletRegistry.getPortletApplication("HW_App");
        if (app != null)
        {
            portletRegistry.removeApplication(app);
         
        }

        PortletApplicationDescriptor pad = new PortletApplicationDescriptor(new FileReader("./test/testdata/deploy/portlet2.xml"), "HW_App");
        app = pad.createPortletApplication(true);

        app.setName("HW_App");

        portletRegistry.registerPortletApplication(app);
 
        // store.invalidateAll();
View Full Code Here

        List list = new LinkedList();
        Iterator portlets = registry.getAllPortletDefinitions().iterator();
        while ( portlets.hasNext() )
        {
            PortletDefinitionComposite portlet = (PortletDefinitionComposite)portlets.next();
            MutablePortletApplication muta = (MutablePortletApplication)portlet.getPortletApplicationDefinition();
            String appName = muta.getName();
            if ( appName == null )
                continue;
            if ( ! appName.equals( "jetspeed-layouts" ) )
                continue;
View Full Code Here

     * @return
     */
   
    public static Preferences createPrefenceNode(PortletDefinitionComposite portlet)
    {
        MutablePortletApplication app = (MutablePortletApplication) portlet.getPortletApplicationDefinition();
        if(app == null)
        {
            throw new IllegalArgumentException("createPrefencePath() requires a PortletDefinition whose Application is not null.");
        }
        String portletDefPrefPath = MutablePortletApplication.PREFS_ROOT + "/" + app.getName() + "/"
        + PortletDefinitionComposite.PORTLETS_PREFS_ROOT + "/" + portlet.getName() + "/"
        + PrefsPreference.PORTLET_PREFERENCES_ROOT;
       
        return Preferences.systemRoot().node(portletDefPrefPath);
    }
View Full Code Here

        BaseParsedObject result = null;
       
        if(o instanceof MutablePortletApplication)
        {
            result = new BaseParsedObject();
          MutablePortletApplication pa = (MutablePortletApplication) o;
         
          result.setDescription(pa.getDescription());
          result.setTitle(pa.getName());
          result.setKey(KEY_PREFIX + pa.getName());
          result.setType(ParsedObject.OBJECT_TYPE_PORTLET_APPLICATION);
          result.setClassName(pa.getClass().getName());
         
          MultiHashMap fieldMap = new MultiHashMap();
          fieldMap.put(ID, pa.getName());
         
          Collection fields = pa.getMetadata().getFields();
          for (Iterator fieldIter = fields.iterator(); fieldIter.hasNext();)
            {
                LocalizedField field = (LocalizedField) fieldIter.next();
                fieldMap.put(field.getName(), field.getValue());
                //this.fields.add(field.getName());
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.om.common.portlet.MutablePortletApplication

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.