head	1.19;
access;
symbols
	TIGRIS_1_1_0RC2:1.1.6.1
	TIGRIS_1_1_0RC1:1.1.6.1
	TIGRIS_1_1:1.1.6.1.0.2
	TIGRIS_1_0_8:1.1.6.1
	TIGRIS_1_0_8RC3:1.1.6.1
	TIGRIS_1_0_8RC2:1.1.6.1
	TIGRIS_1_0_8RC1:1.1.6.1
	TIGRIS_1_0_7:1.1.6.1
	TIGRIS_1_0_7RC3:1.1.6.1
	TIGRIS_1_0_7RC2:1.1.6.1
	TIGRIS_1_0_7RC1:1.1.6.1
	TIGRIS_1_0_6:1.1.6.1
	TIGRIS_1_0_6RC5:1.1.6.1
	TIGRIS_1_0_6RC4:1.1.6.1
	TIGRIS_1_0_6RC3:1.1.6.1
	TIGRIS_1_0_6RC2:1.1.6.1
	TIGRIS_1_0_6RC1:1.1.6.1
	TIGRIS_1_0_5:1.1.6.1
	TIGRIS_1_0_5RC6:1.1.6.1
	TIGRIS_1_0_5RC5:1.1.6.1
	TIGRIS_1_0_5RC4:1.1.6.1
	TIGRIS_1_0_5RC3:1.1.6.1
	TIGRIS_1_0_5RC2:1.1.6.1
	TIGRIS_1_0_5RC1:1.1.6.1
	TIGRIS_1_0_4:1.1
	TIGRIS_1_0_3:1.1
	TIGRIS_1_0_2:1.1
	TIGRIS_1_0_1:1.1
	TIGRIS_1_0:1.1.0.6
	TIGRIS_1_0_0:1.1
	TIGRIS_1_0_0_RC1:1.1.0.2;
locks; strict;
comment	@# @;


1.19
date	2001.08.11.09.08.03;	author dlr;	state Exp;
branches;
next	1.18;

1.18
date	2001.07.02.18.56.42;	author leonardr;	state Exp;
branches;
next	1.17;

1.17
date	2001.06.15.20.23.08;	author leonardr;	state Exp;
branches;
next	1.16;

1.16
date	2001.06.13.17.30.16;	author leonardr;	state Exp;
branches;
next	1.15;

1.15
date	2001.06.09.00.24.07;	author leonardr;	state Exp;
branches;
next	1.14;

1.14
date	2001.06.07.22.47.06;	author leonardr;	state Exp;
branches;
next	1.13;

1.13
date	2001.05.30.15.41.37;	author leonardr;	state Exp;
branches;
next	1.12;

1.12
date	2001.05.25.01.45.28;	author leonardr;	state Exp;
branches;
next	1.11;

1.11
date	2001.05.23.01.50.13;	author dlr;	state Exp;
branches;
next	1.10;

1.10
date	2001.05.23.00.35.00;	author leonardr;	state Exp;
branches;
next	1.9;

1.9
date	2001.05.11.19.38.55;	author leonardr;	state Exp;
branches;
next	1.8;

1.8
date	2001.05.09.01.59.49;	author leonardr;	state Exp;
branches;
next	1.7;

1.7
date	2001.05.02.07.54.49;	author dlr;	state Exp;
branches;
next	1.6;

1.6
date	2001.05.02.07.26.05;	author dlr;	state Exp;
branches;
next	1.5;

1.5
date	2001.05.02.07.06.23;	author dlr;	state Exp;
branches;
next	1.4;

1.4
date	2001.05.01.21.47.21;	author leonardr;	state Exp;
branches;
next	1.3;

1.3
date	2001.04.20.21.19.40;	author leonardr;	state Exp;
branches;
next	1.2;

1.2
date	2001.04.20.15.30.21;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2001.03.07.01.13.15;	author lucas;	state Exp;
branches
	1.1.6.1;
next	;

1.1.6.1
date	2001.05.10.22.15.21;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.19
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@/* ================================================================
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */

package org.tigris.helm.om;

import java.util.*;
import java.rmi.RemoteException;

import org.apache.torque.util.Criteria;
import org.apache.turbine.util.Log;
import org.apache.commons.util.exception.NestableException;
import org.apache.commons.util.exception.NestableException;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.*;
import org.tigris.helm.tool.DBFlag;
import org.tigris.helm.tool.PeerTool;
import org.tigris.helm.tool.cache.SimpleRegisterableCache;

/**
 * Extension of generated Peer BaseRolePeer.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: RolePeer.java,v 1.18 2001/07/02 18:56:42 leonardr Exp $
 */
public class RolePeer extends BaseRolePeer
{

    /**
     * Cache of roles keyed by ID.
     */
    private static SimpleRegisterableCache rolesByID 
        = new SimpleRegisterableCache
        ("Role cache", RolePeer.class, new Hashtable());
    
    /**
     * Overridden BasePeer method to do a delete and then to send out
     * an appropriate CacheInvalidationEvent.
     */
    public static void doDelete(Criteria c)
        throws Exception
    {
        BaseRolePeer.doDelete(c);
        uncache(Role.class);
    }

    /**
     * @@param id The database key of the role.
     */
    public static Role getInstance(String id)
        throws DoesNotExist, Exception
    {
        Map cache = rolesByID.getCache();
        Role r = (Role)cache.get(id);
        if (r == null)
        {
            Criteria c = new Criteria(1).add(ROLE_ID, id);
            synchronized(cache)
            {
                r = (Role)PeerTool.getFirstBO
                        (doSelect(c), "Role with ID " + id);
                cache.put(id, r);
            }
        }
        return r;
    }

    /**
     * @@param name The name of the role.
     */
    public static Role getInstanceByName(String name)
        throws DoesNotExist, Exception
    {
        Criteria c = new Criteria()
            .add(RolePeer.NAME, name);
        return (Role)PeerTool.getFirstBO(RolePeer.doSelect(c),
                                         "Role named " + name);
    }

    /**
     * Returns all the roles on the site of the specified type.
     * @@param type The type of role to get.
     */
    public static List getRolesForType(String type)
        throws Exception
    {
        Criteria c = new Criteria().add(TYPE, type);
        return doSelect(c);
    }

    /**
     * Returns all the roles visible from the given project which have
     * the named attribute set to "Y".
     * @@param p The project in which to check visibility.
     * @@param name The name of the attribute to check.  
     */
    public static List getRolesWithBooleanAttribute(Project p, String name)
        throws Exception
    {
        return doSelect(getCriteriaForRolesWithBooleanAttribute(p, name));
    }

    /**
     * Returns all the roles which have the named attribute set to "Y".
     * @@param p The project in which to check visibility.
     * @@param name The name of the attribute to check.
     */
    public static Criteria getCriteriaForRolesWithBooleanAttribute
        (Project p, String name)
        throws Exception
    {
        Criteria c = new Criteria(7);
        if (p != null)
        {
            c.addJoin(RolePeer.PROJECT_ID, ProjectPeer.PROJECT_ID)
            .addIn(ProjectPeer.PROJECT_ID, p.getRecursiveParentIDs());
        }
        
        c.addJoin(AttributeValuePeer.ENTITY_ID, RolePeer.ROLE_ID)
            .add(AttributeValuePeer.VALUE, DBFlag.ON)
            .addJoin(AttributeValuePeer.ATTRIBUTE_ID, 
                     AttributePeer.ATTRIBUTE_ID)
            .add(AttributePeer.ENTITY_TYPE, Attribute.ROLE_TYPE)
            .add(AttributePeer.NAME, name);
        return c;
    }

    /**
     * Returns all the roles which have the given action on some resource.
     */
    public static Vector getRolesWithAction(String action)
        throws Exception
    {
        Criteria c = new Criteria(3)
            .addJoin(RolePeer.ROLE_ID, RoleActionResourcePeer.ROLE_ID)
            .addJoin(RoleActionResourcePeer.ACTION_ID, ActionPeer.ACTION_ID)
            .add(ActionPeer.NAME, action);
        c.setDistinct();       
        return doSelect(c);
    }

    /**
     * Returns the IDs of all the roles which have the given action on
     * some resource. The first vector contains all roles. The second
     * contains public-recursive roles only.
     *
     * The result of this method should be cached.
     */
    public static Vector[] getRoleIDsForAction(String action)
        throws Exception
    {
        Vector[] roleIDs = new Vector[2];

        List roles = RolePeer.getRolesWithAction(action);
        for (int i = 0; i <= 1; i++)
        {
            roleIDs[i] = new Vector(roles.size());
        }
        
        for (Iterator i = roles.iterator(); i.hasNext();)
        {
            Role r = (Role)i.next();
            String id = r.getID();
            roleIDs[0].add(id);
            if (r.canRecurseIntoPrivateProjects())
            {
                roleIDs[1].add(id);
            }
        }
        return roleIDs;
    }
}
@


1.18
log
@Implemented project-scoped roles.
@
text
@d52 1
a52 3
import org.apache.turbine.om.SimpleKey;
import org.apache.turbine.om.NumberKey;
import org.apache.turbine.util.db.Criteria;
d54 2
a55 2
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.TurbineException;
d68 1
a68 1
 * @@version $Id: RolePeer.java,v 1.17 2001/06/15 20:23:08 leonardr Exp $
@


1.17
log
@Rearranged attribute constants and added generic host attribute-editing interface to AdminUtils.
@
text
@d70 1
a70 1
 * @@version $Id: RolePeer.java,v 1.16 2001/06/13 17:30:16 leonardr Exp $
d138 4
a141 2
     * Returns the roles that should be granted to a user when they 
     * create a project.
d143 1
a143 1
    public static List getRolesToGrantOnProjectCreation()
d146 1
a146 12
        return getRolesWithBooleanAttribute
            (Attribute.GRANT_ON_PROJECT_CREATION);
    }
    
    /**
     * Returns all the roles which have the named attribute set to "Y".
     * @@param name The name of the attribute to check.
     */
    public static List getRolesWithBooleanAttribute(String name)
        throws Exception
    {
        return doSelect(getCriteriaForRolesWithBooleanAttribute(name));
d151 1
d154 2
a155 1
    public static Criteria getOwnershipRoleCriteria()
d158 8
a165 13
        return getCriteriaForRolesWithBooleanAttribute
            (Attribute.DENOTES_OWNERSHIP);
    }

    /**
     * Returns all the roles which have the named attribute set to "Y".
     * @@param name The name of the attribute to check.
     */
    public static Criteria getCriteriaForRolesWithBooleanAttribute(String name)
        throws Exception
    {
        return new Criteria(5)
            .addJoin(AttributeValuePeer.ENTITY_ID, RolePeer.ROLE_ID)
d171 1
@


1.16
log
@Added more places where unapproved roles are filtered out.
@
text
@d70 1
a70 1
 * @@version $Id: RolePeer.java,v 1.15 2001/06/09 00:24:07 leonardr Exp $
d145 1
a145 1
            (AttributePeer.GRANT_ON_PROJECT_CREATION_ATTRIBUTE);
d166 1
a166 1
            (AttributePeer.DENOTES_OWNERSHIP_ATTRIBUTE);
@


1.15
log
@Synchronize cache access, and make use of PeerTool to generate DoesNotExist when appropriate.
@
text
@d70 1
a70 1
 * @@version $Id: RolePeer.java,v 1.14 2001/06/07 22:47:06 leonardr Exp $
d156 11
@


1.14
log
@Refactored mass user permission-checking code.
@
text
@d70 1
a70 1
 * @@version $Id: RolePeer.java,v 1.13 2001/05/30 15:41:37 leonardr Exp $
d97 1
a97 1
        throws Exception
d99 2
a100 1
        Role r = (Role)rolesByID.getCache().get(id);
d103 7
a109 2
            r = retrieveByPK(new NumberKey(id));
            rolesByID.getCache().put(id, r);
@


1.13
log
@Fixed role cache.
@
text
@d70 1
a70 1
 * @@version $Id: RolePeer.java,v 1.12 2001/05/25 01:45:28 leonardr Exp $
d180 31
@


1.12
log
@Finally got rid of REQUESTABLE and DENOTES_OWNER fields in HELM_ROLE.
@
text
@d70 1
a70 1
 * @@version $Id: RolePeer.java,v 1.11 2001/05/23 01:50:13 dlr Exp $
d78 3
a80 7
    private static SimpleRegisterableCache rolesByID;

    static
    {
        rolesByID = new SimpleRegisterableCache
            ("Role cache", RolePeer.class, new Hashtable());
    }
d99 7
a105 1
        return retrieveByPK(new NumberKey(id));
@


1.11
log
@Ported Helm from WebMacro to Velocity.
@
text
@d70 1
a70 1
 * @@version $Id: RolePeer.java,v 1.10 2001/05/23 00:35:00 leonardr Exp $
d147 11
a157 1
        Criteria c = new Criteria(5)
a163 2

        return doSelect(c);
@


1.10
log
@Cleanup of caching and cache invalidation.
@
text
@d56 2
d70 1
a70 1
 * @@version $Id: RolePeer.java,v 1.9 2001/05/11 19:38:55 leonardr Exp $
@


1.9
log
@A Heartbreaking Patch of Staggering Genius: adds capacity (but no interface) for deeply nested projects, categories, and project groups. As a side effect, gets rid of the hacky special 'all public projects in domain' group. There are probably bugs in this, and some of those bugs are probably security holes, so watch out.
@
text
@d68 1
a68 1
 * @@version $Id: RolePeer.java,v 1.8 2001/05/09 01:59:49 leonardr Exp $
d80 2
a81 10
        try
        {
            rolesByID = new SimpleRegisterableCache
                (RolePeer.class, new Hashtable());
        }
        catch (RemoteException e)
        {
            throw new RuntimeException("Unable to create role cache: " +
                                       e.getMessage());
        }
d83 1
a83 1
   
d92 1
a92 1
        uncache(RolePeer.class);
@


1.8
log
@Made IssueTrackingRebuild about a million times faster.
@
text
@d68 1
a68 1
 * @@version $Id: RolePeer.java,v 1.7 2001/05/02 07:54:49 dlr Exp $
d164 4
a167 1
    public static Vector getRoleIDsWithAction(String action)
d175 1
a175 12
        return roleIDs(doSelect(c));
    }

    public static Vector roleIDs(List objs)
    {
        Vector ids = new Vector(objs.size());
        for (Iterator i = objs.iterator(); i.hasNext();)
        {
            Role o = (Role)i.next();
            ids.add(o.getID());            
        }
        return ids;
@


1.7
log
@Corrected criteria for and pre-alloc'd size of getRolesWithBooleanAttribute().
@
text
@d68 1
a68 1
 * @@version $Id: RolePeer.java,v 1.6 2001/05/02 07:26:05 dlr Exp $
d162 22
@


1.6
log
@getRolesWithBooleanAttribute() now only gets Role-specific entries.
@
text
@d68 1
a68 1
 * @@version $Id: RolePeer.java,v 1.5 2001/05/02 07:06:23 dlr Exp $
d153 1
a153 1
        Criteria c = new Criteria(4)
d155 1
d158 1
a158 2
            .add(AttributePeer.ENTITY_TYPE, AttributeValue.ROLE_TYPE)
            .add(AttributeValuePeer.VALUE, DBFlag.ON)
@


1.5
log
@Migrating code to make proper use of the new generic attribute tables.  Things are still a bit rough.
@
text
@d59 1
d68 1
a68 1
 * @@version $Id: RolePeer.java,v 1.4 2001/05/01 21:47:21 leonardr Exp $
a152 1
        // TODO: Only get Role-specific entries.
d154 4
a157 2
            .addJoin(AttributeValuePeer.ROLE_ID, RolePeer.ROLE_ID)
            .add(AttributePeer.NAME, name)
d159 1
a159 2
            .addJoin(AttributePeer.ATTRIBUTE_ID, 
                     AttributeValuePeer.ATTRIBUTE_ID);
@


1.4
log
@Big architecture and schema change: booleans in the HELM_ROLE table have been replaced by entries in the HELM_ROLE_ATTRIBUTE_VALUE table. Also, a new attribute has been added which controls which roles a user gets upon creation of a project.
@
text
@d67 1
a67 1
 * @@version $Id: RolePeer.java,v 1.3 2001/04/20 21:19:40 leonardr Exp $
d142 1
a142 1
            (RoleAttributePeer.GRANT_ON_PROJECT_CREATION_ATTRIBUTE);
d152 1
d154 5
a158 5
            .addJoin(RoleAttributeValuePeer.ROLE_ID, RolePeer.ROLE_ID)
            .add(RoleAttributePeer.NAME, name)
            .add(RoleAttributeValuePeer.VALUE, "Y")
            .addJoin(RoleAttributePeer.ATTRIBUTE_ID, 
                     RoleAttributeValuePeer.ATTRIBUTE_ID);
@


1.3
log
@Send CacheInvalidationEvents on deletes, and on saves of objects which are not themselves cached but which invalidate other caches when they are changed.
@
text
@d55 1
d67 1
a67 1
 * @@version $Id: RolePeer.java,v 1.2 2001/04/20 15:30:21 dlr Exp $
d134 27
@


1.2
log
@Added semi-selective cache invalidation which invalidates particular caches on a write instead of all the caches.
@
text
@d66 1
a66 1
 * @@version $Id: RolePeer.java,v 1.1 2001/03/07 01:13:15 lucas Exp $
d88 11
@


1.1
log
@Moved in from peer package to handle Torque changes. -dlr
@
text
@d50 1
d59 1
d66 1
a66 1
 * @@version $Id: RolePeer.java,v 1.5 2001/02/26 20:21:18 dlr Exp $
d70 20
@


1.1.6.1
log
@Patched change in HEAD to speed up issue tracking rebuilds.
@
text
@d64 1
a64 1
 * @@version $Id: RolePeer.java,v 1.8 2001/05/09 01:59:49 leonardr Exp $
a97 22
    }

    public static Vector getRoleIDsWithAction(String action)
        throws Exception
    {
        Criteria c = new Criteria(3)
            .addJoin(RolePeer.ROLE_ID, RoleActionResourcePeer.ROLE_ID)
            .addJoin(RoleActionResourcePeer.ACTION_ID, ActionPeer.ACTION_ID)
            .add(ActionPeer.NAME, action);
        c.setDistinct();       
        return roleIDs(doSelect(c));
    }

    public static Vector roleIDs(List objs)
    {
        Vector ids = new Vector(objs.size());
        for (Iterator i = objs.iterator(); i.hasNext();)
        {
            Role o = (Role)i.next();
            ids.add(o.getID());            
        }
        return ids;
@


