portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbregistry PortletDbEntryPeer.java
Date Wed, 21 Jul 2004 18:55:09 GMT
taylor      2004/07/21 11:55:09

  Modified:    src/java/org/apache/jetspeed/om/dbregistry
                        PortletDbEntryPeer.java
  Log:
  Portlet registry support for database
  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.2       +176 -44   jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbregistry/PortletDbEntryPeer.java
  
  Index: PortletDbEntryPeer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/dbregistry/PortletDbEntryPeer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PortletDbEntryPeer.java	20 Jul 2004 04:08:04 -0000	1.1
  +++ PortletDbEntryPeer.java	21 Jul 2004 18:55:09 -0000	1.2
  @@ -20,9 +20,20 @@
   import java.util.Iterator;
   import java.util.List;
   
  +import org.apache.jetspeed.om.BaseSecurityReference;
  +import org.apache.jetspeed.om.SecurityReference;
  +import org.apache.jetspeed.om.registry.CachedParameter;
  +import org.apache.jetspeed.om.registry.Category;
  +import org.apache.jetspeed.om.registry.MetaInfo;
  +import org.apache.jetspeed.om.registry.Parameter;
   import org.apache.jetspeed.om.registry.PortletEntry;
   import org.apache.jetspeed.om.registry.RegistryException;
  +import org.apache.jetspeed.om.registry.SecurityAccess;
  +import org.apache.jetspeed.om.registry.base.BaseCachedParameter;
  +import org.apache.jetspeed.om.registry.base.BaseCategory;
  +import org.apache.jetspeed.om.registry.base.BaseMetaInfo;
   import org.apache.jetspeed.om.registry.base.BasePortletEntry;
  +import org.apache.jetspeed.om.registry.base.BaseSecurityAccess;
   import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
   import org.apache.jetspeed.services.logging.JetspeedLogger;
   import org.apache.torque.Torque;
  @@ -48,7 +59,10 @@
           try
           {
               PortletDbEntry pde = lookup(entryName);
  -            pe = mapDatabaseToEntry(pde);
  +            if (pde != null)
  +            {
  +                pe = mapDatabaseToEntry(pde);
  +            }
           } catch (Exception e)
           {
               logger.error("Exception retrieving Portlet Entry: " + entryName, e);
  @@ -62,14 +76,85 @@
           Criteria criteria = new Criteria();
           criteria.add(PortletDbEntryPeer.NAME, entryName);
           List result = PortletDbEntryPeer.doSelect(criteria);
  -        if (null == result || result.isEmpty()) { return null; }
  +        if (null == result || result.isEmpty()) 
  +        { 
  +            return null; 
  +        }
           return (PortletDbEntry) result.get(0);
       }
   
  -    public static PortletEntry mapDatabaseToEntry(PortletDbEntry sde)
  +    public static PortletEntry mapDatabaseToEntry(PortletDbEntry pde)
               throws TorqueException
       {
  -        PortletEntry pe = new BasePortletEntry(sde.getId());
  +        PortletEntry pe = new BasePortletEntry(pde.getId());
  +        pe.setApplication(pde.getApplication());
  +        pe.setCachedOnURL(pde.getCachedOnUrl());
  +        pe.setClassname(pde.getClassname());
  +        pe.setDescription(pde.getDescription());
  +        pe.setHidden(pde.getHidden());
  +        MetaInfo meta = new BaseMetaInfo();
  +        meta.setImage(pde.getImage());
  +        meta.setDescription(pde.getDescription());
  +        meta.setTitle(pde.getTitle());
  +        pe.setMetaInfo(meta);                
  +        pe.setName(pde.getName());            
  +        pe.setParent(pde.getParent());
  +        SecurityReference ref = new BaseSecurityReference();
  +        ref.setParent(pde.getSecurityRef());
  +        pe.setSecurityRef(ref);
  +        pe.setTitle(pde.getTitle());
  +        pe.setType(pde.getType());
  +        pe.setURL(pde.getURL());
  +        
  +        // parameters
  +        Iterator params = pde.getPortletParameters().iterator();
  +        while (params.hasNext())
  +        {
  +            PortletParameter pp = (PortletParameter)params.next();
  +            CachedParameter cp = new BaseCachedParameter(pp.getId());
  +            cp.setCachedOnName(pp.getCachedOnName());
  +            cp.setCachedOnValue(pp.getCachedOnValue());
  +            cp.setDescription(pp.getDescription());
  +            cp.setHidden(pp.getHidden());
  +            cp.setName(pp.getName());
  +            cp.setType(pp.getType());
  +            cp.setValue(pp.getValue());
  +
  +            
  +            cp.setTitle(pp.getTitle());
  +            if (pp.getDescription() != null || pp.getTitle() != null || pp.getImage() !=
null)
  +            {
  +                MetaInfo meta2 = new BaseMetaInfo();
  +                meta2.setImage(pp.getImage());
  +                meta2.setDescription(pp.getDescription());
  +                meta2.setTitle(pp.getTitle());
  +                cp.setMetaInfo(meta2);
  +            }
  +            if (pp.getSecurityRef() != null)
  +            {
  +                SecurityReference ref2 = new BaseSecurityReference();
  +                ref2.setParent(pp.getSecurityRef());
  +                cp.setSecurityRef(ref2);
  +            }            
  +            pe.addParameter(cp);
  +        }
  +        
  +        // media types
  +        Iterator mtypes = pde.getPortletMediatypes().iterator();
  +        while (mtypes.hasNext())
  +        {
  +            PortletMediatype pm = (PortletMediatype)mtypes.next();
  +            pe.addMediaType(pm.getName());
  +        }
  +
  +        // categories
  +        Iterator categories = pde.getPortletCategorys().iterator();
  +        while (categories.hasNext())
  +        {
  +            PortletCategory pc = (PortletCategory)categories.next();            
  +            pe.addCategory(pc.getName(), pc.getGroup());
  +        }
  +        
           return pe;
       }
   
  @@ -81,16 +166,16 @@
               Criteria criteria = new Criteria();
               criteria.add(PortletParameterPeer.PORTLET_ID, id);
               PortletParameterPeer.doDelete(criteria);
  -            /*
  -             * criteria = new Criteria();
  -             * criteria.add(PortletParameterPeer.PORTLET_ID, id);
  -             * PortletParameterPeer.doDelete(criteria);
  -             * 
  -             * criteria = new Criteria(); criteria.add(PortletMediatypePeer.,
  -             * id); PortletParameterPeer.doDelete(criteria);
  -             */
   
  -        } catch (TorqueException e)
  +            criteria = new Criteria();
  +            criteria.add(PortletMediatypePeer.PORTLET_ID, id);
  +            PortletMediatypePeer.doDelete(criteria);
  +
  +            criteria = new Criteria();
  +            criteria.add(PortletCategoryPeer.PORTLET_ID, id);
  +            PortletCategoryPeer.doDelete(criteria);            
  +        } 
  +        catch (TorqueException e)
           {
               logger.error("Exception Removing Portlet Entry Accesses: " + id, e);
               throw new RegistryException("Exception Removing Portlet Entry: "
  @@ -107,8 +192,8 @@
                       .iterator();
               while (result.hasNext())
               {
  -                PortletEntry se = mapDatabaseToEntry((PortletDbEntry) result
  -                        .next());
  +                PortletEntry se = 
  +                    mapDatabaseToEntry((PortletDbEntry) result.next());
                   extent.add(se);
               }
           } catch (TorqueException e)
  @@ -127,6 +212,7 @@
           boolean autoCommit = false;
           try
           {
  +            
               // get fresh copy in case its changed on another node
               PortletDbEntry pde = lookup(pe.getName());
               if (null != pde)
  @@ -140,41 +226,86 @@
               autoCommit = conn.getAutoCommit();
               conn.setAutoCommit(false);
   
  -            pde.setName(pe.getName());
  -            pde.setTitle(pe.getTitle());
  +            pde.setApplication(pe.isApplication());
  +            pde.setCachedOnUrl(pe.isCachedOnURL());
  +            pde.setClassname(pe.getClassname());
               pde.setDescription(pe.getDescription());
  -            // TODO: LEFT OFF here
  +            pde.setHidden(pe.isHidden());
  +            if (pe.getMetaInfo() != null)
  +            {
  +                pde.setImage(pe.getMetaInfo().getImage());
  +            }
  +            pde.setName(pe.getName());            
  +            pde.setParent(pe.getParent());
  +            if (pe.getSecurityRef() != null)
  +            {
  +                pde.setSecurityRef(pe.getSecurityRef().getParent());
  +            }
  +            pde.setTitle(pe.getTitle());
  +            pde.setType(pe.getType());
  +            pde.setURL(pe.getURL());
  +            
               pde.save(conn);
   
  -            Iterator parameters = pe.getParameterNames();
  +            // parameters
  +            Iterator parameters = pe.getParameterNames();            
               while (parameters.hasNext())
               {
  -                /*
  -                 * PortletAccess access = (SecurityAccess)accesses.next();
  -                 * SecurityAccessDbEntry sade = new SecurityAccessDbEntry();
  -                 * sade.setAction(access.getAction());
  -                 * sade.setEntryId(sde.getId()); sade.save(conn);
  -                 * 
  -                 * Iterator allows = access.getAllAllows().iterator(); while
  -                 * (allows.hasNext()) { SecurityAllow allow =
  -                 * (SecurityAllow)allows.next(); SecurityAllowDbEntry sa = new
  -                 * SecurityAllowDbEntry(); if (allow.isOwner()) {
  -                 * sa.setAllowType(ALLOW_OWNER); sa.setAllowValue(ALLOW_OWNER); }
  -                 * else if (allow.getRole() != null && allow.getGroup() != null)
{
  -                 * sa.setAllowType(ALLOW_BOTH);
  -                 * sa.setAllowValue(allow.getRole());
  -                 * sa.setAllowGroup(allow.getGroup()); } else if
  -                 * (allow.getRole() != null) { sa.setAllowType(ALLOW_ROLE);
  -                 * sa.setAllowValue(allow.getRole()); } else if
  -                 * (allow.getGroup() != null) { sa.setAllowType(ALLOW_GROUP);
  -                 * sa.setAllowValue(allow.getGroup()); } else {
  -                 * sa.setAllowType(ALLOW_USER);
  -                 * sa.setAllowValue(allow.getUser()); }
  -                 * sa.setAccessId(sade.getId()); sa.save(conn); }
  -                 */
  +                String name = (String)parameters.next();
  +                CachedParameter cp = (CachedParameter)pe.getParameter(name);
  +
  +                PortletParameter pp = new PortletParameter();
  +                pp.setCachedOnName(cp.isCachedOnName());
  +                pp.setCachedOnValue(cp.isCachedOnValue());
  +                pp.setDescription(cp.getDescription());
  +                pp.setHidden(cp.isHidden());
  +                pp.setName(cp.getName());
  +                pp.setPortletId(pde.getId());
  +                pp.setTitle(cp.getTitle());
  +                pp.setType(cp.getType());
  +                pp.setValue(cp.getValue());
  +                
  +                MetaInfo meta = cp.getMetaInfo();
  +                if (meta != null)
  +                {
  +                    pp.setImage(meta.getImage());
  +                    pp.setDescription(meta.getDescription());
  +                    pp.setTitle(meta.getTitle());
  +                }
  +                SecurityReference ref = cp.getSecurityRef();
  +                if (ref != null)
  +                {
  +                    pp.setSecurityRef(ref.getParent());
  +                }
  +                pp.save(conn);
               }
  +            
  +            // media types
  +            Iterator mtypes = pe.listMediaTypes();            
  +            while (mtypes.hasNext())
  +            {
  +                String name = (String)mtypes.next();
   
  -        } catch (Exception e)
  +                PortletMediatype pm = new PortletMediatype();
  +                pm.setName(name);
  +                pm.setPortletId(pde.getId());                
  +                pm.save(conn);
  +            }
  +
  +            // categories
  +            Iterator categories = pe.listCategories();                        
  +            while (categories.hasNext())
  +            {
  +                Category category = (Category)categories.next();
  +
  +                PortletCategory pc = new PortletCategory();
  +                pc.setName(category.getName());
  +                pc.setGroup(category.getGroup());
  +                pc.setPortletId(pde.getId());                
  +                pc.save(conn);
  +            }                        
  +        } 
  +        catch (Exception e)
           {
               try
               {
  @@ -183,6 +314,7 @@
               {
                   logger.error("Failed to rollback", e2);
               }
  +            e.printStackTrace();
               logger.error("Exception storing Portlet Entry: " + pe.getName(), e);
               throw new RegistryException("Exception storing Portlet Entry: "
                       + pe.getName() + ", " + e.toString());
  
  
  

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


Mime
View raw message