head	1.19;
access;
symbols
	TIGRIS_1_1_0RC2:1.8.6.2
	TIGRIS_1_1_0RC1:1.8.6.2
	TIGRIS_1_1:1.8.6.2.0.2
	TIGRIS_1_0_8:1.8.6.2
	TIGRIS_1_0_8RC3:1.8.6.2
	TIGRIS_1_0_8RC2:1.8.6.2
	TIGRIS_1_0_8RC1:1.8.6.2
	TIGRIS_1_0_7:1.8.6.2
	TIGRIS_1_0_7RC3:1.8.6.2
	TIGRIS_1_0_7RC2:1.8.6.2
	TIGRIS_1_0_7RC1:1.8.6.2
	TIGRIS_1_0_6:1.8.6.2
	TIGRIS_1_0_6RC5:1.8.6.2
	TIGRIS_1_0_6RC4:1.8.6.2
	TIGRIS_1_0_6RC3:1.8.6.2
	TIGRIS_1_0_6RC2:1.8.6.2
	TIGRIS_1_0_6RC1:1.8.6.2
	TIGRIS_1_0_5:1.8.6.1
	TIGRIS_1_0_5RC6:1.8.6.1
	TIGRIS_1_0_5RC5:1.8.6.1
	TIGRIS_1_0_5RC4:1.8.6.1
	TIGRIS_1_0_5RC3:1.8.6.1
	TIGRIS_1_0_5RC2:1.8.6.1
	TIGRIS_1_0_5RC1:1.8.6.1
	TIGRIS_1_0_4:1.8.6.1
	TIGRIS_1_0_3:1.8
	TIGRIS_1_0_2:1.8
	TIGRIS_1_0_1:1.8
	TIGRIS_1_0:1.8.0.6
	TIGRIS_1_0_0:1.8
	TIGRIS_1_0_0_RC1:1.8.0.2
	dlr:1.1.1
	HELM_PEER_PORT_BRANCH:1.1.1.1;
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.12.20.00.16;	author leonardr;	state Exp;
branches;
next	1.17;

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

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

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

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

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

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

1.11
date	2001.05.08.01.31.36;	author leonardr;	state Exp;
branches;
next	1.10;

1.10
date	2001.05.02.08.11.04;	author dlr;	state Exp;
branches;
next	1.9;

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

1.8
date	2001.03.13.20.01.39;	author leonardr;	state Exp;
branches
	1.8.6.1;
next	1.7;

1.7
date	2001.03.13.19.08.00;	author leonardr;	state Exp;
branches;
next	1.6;

1.6
date	2001.03.08.19.05.38;	author leonardr;	state Exp;
branches;
next	1.5;

1.5
date	2001.03.07.01.53.22;	author lucas;	state Exp;
branches;
next	1.4;

1.4
date	2001.02.24.03.59.53;	author dlr;	state Exp;
branches;
next	1.3;

1.3
date	2001.02.23.23.34.20;	author elicia;	state Exp;
branches;
next	1.2;

1.2
date	2001.02.21.03.02.22;	author edk;	state Exp;
branches;
next	1.1;

1.1
date	2001.01.30.01.21.05;	author leonardr;	state dead;
branches
	1.1.1.1
	1.1.2.1;
next	;

1.1.1.1
date	2001.02.21.00.33.05;	author dlr;	state Exp;
branches;
next	;

1.1.2.1
date	2001.01.30.01.21.05;	author leonardr;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	2001.01.30.07.35.39;	author dlr;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	2001.01.30.19.48.03;	author leonardr;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2001.01.31.01.00.54;	author dlr;	state Exp;
branches;
next	1.1.2.5;

1.1.2.5
date	2001.02.05.17.04.46;	author leonardr;	state Exp;
branches;
next	1.1.2.6;

1.1.2.6
date	2001.02.12.16.24.32;	author leonardr;	state Exp;
branches;
next	1.1.2.7;

1.1.2.7
date	2001.02.13.03.03.02;	author dlr;	state Exp;
branches;
next	1.1.2.8;

1.1.2.8
date	2001.02.13.03.12.17;	author dlr;	state Exp;
branches;
next	1.1.2.9;

1.1.2.9
date	2001.02.13.03.35.34;	author leonardr;	state Exp;
branches;
next	1.1.2.10;

1.1.2.10
date	2001.02.14.00.34.10;	author leonardr;	state Exp;
branches;
next	1.1.2.11;

1.1.2.11
date	2001.02.14.23.20.29;	author leonardr;	state Exp;
branches;
next	1.1.2.12;

1.1.2.12
date	2001.02.15.20.06.24;	author leonardr;	state Exp;
branches;
next	1.1.2.13;

1.1.2.13
date	2001.02.15.20.50.38;	author leonardr;	state Exp;
branches;
next	1.1.2.14;

1.1.2.14
date	2001.02.16.03.01.27;	author dlr;	state Exp;
branches;
next	1.1.2.15;

1.1.2.15
date	2001.02.16.16.09.07;	author leonardr;	state Exp;
branches;
next	1.1.2.16;

1.1.2.16
date	2001.02.16.16.26.36;	author leonardr;	state Exp;
branches;
next	;

1.8.6.1
date	2001.05.02.23.07.10;	author leonardr;	state Exp;
branches;
next	1.8.6.2;

1.8.6.2
date	2001.05.24.23.31.09;	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.sql.*;

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

import org.tigris.helm.security.AccessControlList;
import org.tigris.helm.security.ACLException;

import org.tigris.helm.AlreadyExists;
import org.tigris.helm.om.*;
import org.tigris.helm.om.profile.GroupProfile;
import org.tigris.helm.tool.DBFlag;
import org.tigris.helm.tool.paginate.PeerBackedList;

/** 
 * Project group business object.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 */
public class ProjectGroup extends AssociationTargetProject
{
    /**
     * List of valid subproject types.
     */
    protected static String[] VALID_SUBPROJECT_TYPES = {GROUP_TYPE};


    /**
     * List of valid superproject types.
     */
    protected static String[] VALID_SUPERPROJECT_TYPES = 
    {
        DOMAIN_TYPE, 
        GROUP_TYPE
    };

    /**
     * List of valid types of projects which can be associated with this.
     * project.
     */
    protected static String[] VALID_ASSOCIATION_TYPES = 
    {
        REGULAR_TYPE,
        CATEGORY_TYPE
    };

    /**
     * Description of the audit log entry created when a project of this
     * type is added.  
     */
    private static final String AUDIT_LOG_ON_ADD = "Project group added: ";

    /**
     * Description of the audit log entry created when a project of this
     * type is deleted.
     */
    private static final String AUDIT_LOG_ON_DELETE = "Project group deleted: ";

    /**
     * Description of the audit log entry created when a project of this
     * type is edited.
     */
    private static final String AUDIT_LOG_ON_EDIT = "Project group edited: ";

    /**
     * Description of the audit log entry created when a project is added
     * to this group.
     */
    private static final String AUDIT_LOG_ON_ASSOCIATE = 
        "Project associated with project group: ";

    /**
     * Description of the audit log entry created when a project is removed
     * from this group.
     */
    private static final String AUDIT_LOG_ON_DISASSOCIATE = 
        "Project disassociated from project group: ";

    /**
     * Constructor; make nice with Torque.
     */
    public ProjectGroup()
    {
        setType(ProjectPeer.CLASSKEY_GROUP);
    }

    /**
     * Returns the types of projects which can be subprojects of this type
     * of project.
     */
    protected String[] getValidSubprojectTypes()
    {
        return this.VALID_SUBPROJECT_TYPES;
    }

    /**
     * Returns the types of projects which can be superprojects of this type
     * of project.
     */
    protected String[] getValidSuperprojectTypes()
    {
        return this.VALID_SUPERPROJECT_TYPES;
    }

    /**
     * Returns the types of projects which can be associated with this
     * type of project.
     */
    protected String[] getValidAssociationTypes()
    {
        return VALID_ASSOCIATION_TYPES;
    }

    //
    // Mutator methods
    //

    /**
     * Add a new project group with some initial elements.
     */
    public static ProjectGroup add (AccessControlList acl, Project parent,
                                    String name, String shortDescription, 
                                    String longDescription, 
                                    List initialElements)
        throws AlreadyExists, ACLException, Exception
    {
        return (ProjectGroup)AssociationTargetProject.add
            (acl, new GroupProfile(), parent, name, DBFlag.OFF, 
             shortDescription, longDescription, initialElements);
    }         
}
@


1.18
log
@The last vestiges of the old Proprietary==Private Republic have been swept away.
@
text
@d52 2
a53 2
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.TurbineException;
@


1.17
log
@Implemented project-scoped roles.
@
text
@a177 1
        Log.debug("~~");
@


1.16
log
@Implemented basic project group and category nesting.
@
text
@d54 1
d178 1
@


1.15
log
@Huge patch of the day: Got rid of redundant HELM_DOMAIN table. The project representation of the domain and the host is now the canonical one. Host and Domain now subclass ProjectGroup. The canonical representation of a project's membership in a domain group is now the corresponding mapping in HELM_PROJECT_PROJECTGROUP. Schema changes: No more HELM_DOMAIN table (obviously); no more DOMAIN_ID in HELM_PROJECT; HELM_USER and HELM_VC_VIEW now have foreign keys in HELM_PROJECT instead of HELM_DOMAIN.
@
text
@d58 1
a58 1
import org.tigris.helm.*;
d60 2
a61 4
import org.tigris.helm.om.profile.*;
import org.tigris.helm.om.*;
import org.tigris.helm.tool.PeerTool;
import org.tigris.helm.tool.audit.AuditLog;
d64 7
a70 1
public class ProjectGroup extends Project
d73 25
d119 2
a120 2
    private static final String AUDIT_LOG_ON_PROJECT_ADD = 
        "Project added to project group: ";
d126 2
a127 2
    private static final String AUDIT_LOG_ON_PROJECT_REMOVE = 
        "Project removed from project group: ";
d129 3
a136 4
    //
    // Mutator methods
    //

d138 2
a139 1
     * Add a new project group.
d141 1
a141 5
    public static ProjectGroup add(AccessControlList acl, Domain domain,
                                   boolean isCategory, String name, 
                                   String shortDescription, 
                                   String longDescription)
        throws AlreadyExists, Exception
d143 1
a143 2
        return add(acl, domain, isCategory, name, shortDescription,
                   longDescription, null);
d147 2
a148 1
     * Add a new project group with some initial elements.
d150 1
a150 6
    public static ProjectGroup add (AccessControlList acl, Domain domain,
                                    boolean isCategory, String name, 
                                    String shortDescription, 
                                    String longDescription, 
                                    List initialElements)
        throws AlreadyExists, Exception
d152 1
a152 30
        acl.assertPermission("ProjectGroup - Add", domain);
        //Get profile and license. (?)        
        ProjectProfile profile = null;
        String isPublic = "Y";
        if (isCategory)
        {
            profile = new CategoryProfile();             
        } 
        else 
        {
            isPublic = "N";
            profile = new GroupProfile(); 
        }
        String license = null;
        
        ProjectGroup p = (ProjectGroup)Project.add
            (acl, profile, domain, name, license, isPublic,
             shortDescription, longDescription, "N", 
             "", "", acl.getUser(), acl.getUser());

        //Add the initial elements.
        if (initialElements != null)
        {
            for (Iterator i = initialElements.iterator(); i.hasNext();)
            {
                Project p2= (Project)i.next();
                p.addProject(acl, p2);
            }        
        }
        return p;
d156 2
a157 1
     * Add a project to the group.
d159 1
a159 2
    public void addProject(AccessControlList acl, Project project)
        throws ACLException, Exception
d161 1
a161 11
        //Do nothing if the project is already in the group.
        if (!containsProject(project))
        {
            acl.assertPermission("ProjectGroup Element - Add", 
                                 getDomain());
            addProject(project);

            AuditLog.logEvent
                (acl.getUser(), this, this.AUDIT_LOG_ON_PROJECT_ADD
                 + getName() + " <- " + project.getName());
        }
a163 85
    /**
     * Add a project to the group. Does no permission checking.
     */
    protected void addProject(Project project)
        throws Exception    
    {
        if (!containsProject(project))
        {
            ProjectProjectgroup mapping = new ProjectProjectgroup();
            mapping.setProjectRelatedByProjectId(project);
            mapping.setProjectRelatedByProjectGroupId(this);
            mapping.save();
            project.rebuildIssueTracking();
        }
    }

    /**
     * Remove a project from the group.
     */
    public void removeProject(AccessControlList acl, Project project)
        throws ACLException, Exception
    {
        if (containsProject(project))
        {
            acl.assertPermission("ProjectGroup Element - Delete", 
                                 getDomain());
            removeProject(project);

            AuditLog.logEvent
                (acl.getUser(), this, this.AUDIT_LOG_ON_PROJECT_REMOVE 
                 + getName() + " -> " + project.getName());
        }
    }

    /**
     * Remove a project from the group. Does no permission checking.
     */
    protected void removeProject(Project project)
        throws Exception    
    {
        if (containsProject(project))
        {
            Criteria c = new Criteria()
                .add(ProjectProjectgroupPeer.PROJECT_ID,
                     PeerTool.getKey(project))
                .add(ProjectProjectgroupPeer.PROJECT_GROUP_ID,
                     PeerTool.getKey(this));
            ProjectProjectgroupPeer.doDelete(c);
            project.rebuildIssueTracking();
        }
    }
    

    /**
     * Delete the project group completely.
     */
    public void delete(AccessControlList acl)
        throws Exception
    {
        acl.assertPermission("ProjectGroup - Delete", getDomain());
        //Remove all elements of the group.
        for (Iterator i = getProjects().iterator(); i.hasNext();)
        {
            Project p = (Project)i.next();
            removeProject(p);
        }

        //Delete the project like any other project.
        super.delete(acl);
    }
        
    /**
     * Change the descriptions of a project group.
     */
    public void updateInfo(AccessControlList acl, String shortDescription,
                           String longDescription, String type)
        throws ACLException, Exception
    {
        assertEditPermission(acl);
        setShortDescription(shortDescription);
        setLongDescription(longDescription);
        setType(type);
        save();
    }
    
d165 1
a165 1
    // Accessor methods
d169 1
a169 1
     * Get a big list of all the viewable projects in this group.
d171 5
a175 40
    public List getProjects(AccessControlList acl)
        throws Exception
    {
        return getProjects(new Integer(0), HelmPeer.NO_CRITERIA, acl);
    }

    /**
     * Get a paginatable list of the viewable projects in this group.
     */
    public PeerBackedList getProjects(Integer itemsPerPage, Criteria filter, 
                                      AccessControlList acl)
        throws Exception
    {
        return ProjectPeer.getProjects(itemsPerPage, null, filter, acl);
    }

    /**
     * Get a paginatable list of the viewable projects in this group.
     */
    public PeerBackedList getProjects(Integer itemsPerPage, 
                                      Criteria base, Criteria filter, 
                                      AccessControlList acl)
        throws Exception
    {
        if (base == null)
        {
            base = projectsInGroupCriteria();
        }
        else
        {
            base.putAll(projectsInGroupCriteria());
        }
        return ProjectPeer.getProjects(itemsPerPage, base, filter, acl);
    }

    /**
     * Get the count of the viewable projects in this group.
     */    
    public final int getNumberOfProjects(AccessControlList acl)
        throws Exception
d177 4
a180 44
        return getProjects(acl).size();
    }

    /**
     * Returns the list of projects to which this project is equivalent.
     */
    public List expand()
        throws Exception
    {
        return getProjects();
    }

    /**
     * Returns true iff this group contains the given project.
     */
    public boolean containsProject(Project p)
        throws Exception
    {
        Criteria c = new Criteria()
            .add(ProjectProjectgroupPeer.PROJECT_ID, p.getID())
            .add(ProjectProjectgroupPeer.PROJECT_GROUP_ID, getID());
        return !ProjectProjectgroupPeer.doSelect(c).isEmpty();
    }

    /**
     * Returns the criteria to be used when selecting projects that are
     * in this project group.
     */
    private Criteria projectsInGroupCriteria()
    {
        return new Criteria()
            .addJoin(ProjectProjectgroupPeer.PROJECT_ID, 
                     ProjectPeer.PROJECT_ID)
            .add(ProjectProjectgroupPeer.PROJECT_GROUP_ID, getProjectId());
    }

    /**
     * Get a big list of all the projects in this group.
     */
    protected List getProjects()
        throws Exception
    {
        return ProjectPeer.doSelect(projectsInGroupCriteria());
    }
@


1.14
log
@Got rid of the ugly and unneccessary asGroup() and getGroupInstance() methods.
@
text
@d288 19
a306 1
        Criteria base = projectsInGroupCriteria();
@


1.13
log
@Refactored a lot of code to get rid of the good-looking but very slow IssueTrackingAccount{Descriptor,Map} classes. Also cleaned up the script-running interface quite a bit.
@
text
@d146 2
a147 1
        ProjectGroup p = Project.add
d150 1
a150 1
             "", "", acl.getUser(), acl.getUser()).asGroup();
@


1.12
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
@d194 1
a194 1
            HelmTask.rebuildIssueTracking(project);
d230 1
a230 1
            HelmTask.rebuildIssueTracking(project);
@


1.11
log
@Shunt off issue tracking rebuild time to non-user-visible time.
@
text
@a64 1
import org.tigris.helm.tool.task.IssueTrackingAccountDescriptor;
a187 6
        if (!project.isBase() && !(isHost() || isDomain()))
        {
            throw new TurbineException
                ("User-created project groups cannot themselves contain project groups.");
        }

d230 1
a230 1
            HelmTask.rebuildIssueTracking(project);            
@


1.10
log
@Corrected getAttributes() call in Role and made use of HelmPeer's new NO_CRITERIA constant.
@
text
@a200 1
            //rebuildProjectGroups();
a230 2
            IssueTrackingAccountDescriptor before = 
                new IssueTrackingAccountDescriptor(project);
d237 1
a237 4
            //rebuildProjectGroups();
            IssueTrackingAccountDescriptor after = 
                new IssueTrackingAccountDescriptor(project);
            before.syncTo(after);
@


1.9
log
@Patches I forgot to commit before, for decoupling privateness from proprietariness.
@
text
@d290 1
a290 1
        return getProjects(new Integer(0), new Criteria(0), acl);
@


1.8
log
@User-created groups cannot themselves contain groups.
@
text
@d136 1
d139 5
a143 2
            profile = new CategoryProfile(); 
        } else {
d148 1
a148 1
            (acl, profile, domain, name, license,
@


1.8.6.1
log
@Don't build an IssueTrackingAccountDescriptor on user time.
@
text
@d197 1
d228 2
d236 4
a239 1
            HelmTask.rebuildIssueTracking(project);
@


1.8.6.2
log
@Ported task running system in from HEAD.
@
text
@d65 1
d197 1
a197 1
            project.rebuildIssueTracking();
d233 1
a233 1
            project.rebuildIssueTracking();
@


1.7
log
@Added a new type of task which redoes the issue tracking of a project. This causes some unneccessary scripts to be run (since we lose the context of how the issue tracking was before a change was made), but it lets us offload the time it takes to build an IssueTrackingAccountDescriptor onto the task-runner thread so that the user doesn't see it. The immediate performance effect (in the two places that now use the task instead of making their own ITADs) is to reduce user-visible project creation time from 10 seconds to 3 seconds (YMMV).
@
text
@d53 1
d185 6
@


1.6
log
@Political correctness strikes Tigris.org! The components of project and user groups no longer wish to be called "members", as that causes them to be confused with users who have roles in projects. The new, approved term is "elements".
@
text
@a185 2
            IssueTrackingAccountDescriptor before = 
                new IssueTrackingAccountDescriptor(project);
d191 1
a191 3
            IssueTrackingAccountDescriptor after = 
                new IssueTrackingAccountDescriptor(project);
            before.syncTo(after);
@


1.5
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d123 1
a123 1
     * Add a new project group with some initial members.
d129 1
a129 1
                                    List initialMembers)
d147 2
a148 2
        //Add the initial members.
        if (initialMembers != null)
d150 1
a150 1
            for (Iterator i = initialMembers.iterator(); i.hasNext();)
d168 1
a168 1
            acl.assertPermission("ProjectGroup Member - Add", 
d207 1
a207 1
            acl.assertPermission("ProjectGroup Member - Delete", 
d248 1
a248 1
        //Remove all members of the group.
@


1.4
log
@Sync'd with latest Turbine changes.  Mostly this consists of the use of the new SimpleKey class to handle primary database keys.
@
text
@d60 1
a60 2
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
@


1.3
log
@update method now updating type (category or group)
@
text
@d62 1
d190 2
a191 2
            mapping.setProjectId(project.getPrimaryKeyAsInt());
            mapping.setProjectGroupId(getPrimaryKeyAsInt());
d228 5
a232 3
            Criteria c = new Criteria().add(ProjectProjectgroupPeer.PROJECT_ID,
                                            project.getPrimaryKeyAsInt());
            c.add(ProjectProjectgroupPeer.PROJECT_GROUP_ID, getPrimaryKeyAsInt());
@


1.2
log
@adding files from the branch to the head
@
text
@d261 1
a261 1
                           String longDescription)
d267 1
@


1.1
log
@file ProjectGroup.java was initially added on branch HELM_PEER_PORT_BRANCH.
@
text
@d1 344
@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@a0 344
/* ================================================================
 * 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.sql.*;

import org.apache.turbine.util.db.Criteria;

import org.tigris.helm.security.AccessControlList;
import org.tigris.helm.security.ACLException;

import org.tigris.helm.*;
import org.tigris.helm.om.*;
import org.tigris.helm.om.profile.*;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
import org.tigris.helm.tool.audit.AuditLog;
import org.tigris.helm.tool.paginate.PeerBackedList;
import org.tigris.helm.tool.task.IssueTrackingAccountDescriptor;

public class ProjectGroup extends Project
{
    /**
     * Description of the audit log entry created when a project of this
     * type is added.  
     */
    private static final String AUDIT_LOG_ON_ADD = "Project group added: ";

    /**
     * Description of the audit log entry created when a project of this
     * type is deleted.
     */
    private static final String AUDIT_LOG_ON_DELETE = "Project group deleted: ";

    /**
     * Description of the audit log entry created when a project of this
     * type is edited.
     */
    private static final String AUDIT_LOG_ON_EDIT = "Project group edited: ";

    /**
     * Description of the audit log entry created when a project is added
     * to this group.
     */
    private static final String AUDIT_LOG_ON_PROJECT_ADD = 
        "Project added to project group: ";

    /**
     * Description of the audit log entry created when a project is removed
     * from this group.
     */
    private static final String AUDIT_LOG_ON_PROJECT_REMOVE = 
        "Project removed from project group: ";

    public ProjectGroup()
    {
        setType(ProjectPeer.CLASSKEY_GROUP);
    }

    //
    // Mutator methods
    //

    /**
     * Add a new project group.
     */
    public static ProjectGroup add(AccessControlList acl, Domain domain,
                                   boolean isCategory, String name, 
                                   String shortDescription, 
                                   String longDescription)
        throws AlreadyExists, Exception
    {
        return add(acl, domain, isCategory, name, shortDescription,
                   longDescription, null);
    }

    /**
     * Add a new project group with some initial members.
     */
    public static ProjectGroup add (AccessControlList acl, Domain domain,
                                    boolean isCategory, String name, 
                                    String shortDescription, 
                                    String longDescription, 
                                    List initialMembers)
        throws AlreadyExists, Exception
    {
        acl.assertPermission("ProjectGroup - Add", domain);
        //Get profile and license. (?)        
        ProjectProfile profile = null;
        if (isCategory)
        {
            profile = new CategoryProfile(); 
        } else {
            profile = new GroupProfile(); 
        }
        String license = null;
        ProjectGroup p = Project.add
            (acl, profile, domain, name, license,
             shortDescription, longDescription, "N", 
             "", "", acl.getUser(), acl.getUser()).asGroup();

        //Add the initial members.
        if (initialMembers != null)
        {
            for (Iterator i = initialMembers.iterator(); i.hasNext();)
            {
                Project p2= (Project)i.next();
                p.addProject(acl, p2);
            }        
        }
        return p;
    }

    /**
     * Add a project to the group.
     */
    public void addProject(AccessControlList acl, Project project)
        throws ACLException, Exception
    {
        //Do nothing if the project is already in the group.
        if (!containsProject(project))
        {
            acl.assertPermission("ProjectGroup Member - Add", 
                                 getDomain());
            addProject(project);

            AuditLog.logEvent
                (acl.getUser(), this, this.AUDIT_LOG_ON_PROJECT_ADD
                 + getName() + " <- " + project.getName());
        }
    }

    /**
     * Add a project to the group. Does no permission checking.
     */
    protected void addProject(Project project)
        throws Exception    
    {
        if (!containsProject(project))
        {
            IssueTrackingAccountDescriptor before = 
                new IssueTrackingAccountDescriptor(project);
            ProjectProjectgroup mapping = new ProjectProjectgroup();
            mapping.setProjectId(project.getPrimaryKeyAsInt());
            mapping.setProjectGroupId(getPrimaryKeyAsInt());
            mapping.save();
            //rebuildProjectGroups();
            IssueTrackingAccountDescriptor after = 
                new IssueTrackingAccountDescriptor(project);
            before.syncTo(after);
        }
    }

    /**
     * Remove a project from the group.
     */
    public void removeProject(AccessControlList acl, Project project)
        throws ACLException, Exception
    {
        if (containsProject(project))
        {
            acl.assertPermission("ProjectGroup Member - Delete", 
                                 getDomain());
            removeProject(project);

            AuditLog.logEvent
                (acl.getUser(), this, this.AUDIT_LOG_ON_PROJECT_REMOVE 
                 + getName() + " -> " + project.getName());
        }
    }

    /**
     * Remove a project from the group. Does no permission checking.
     */
    protected void removeProject(Project project)
        throws Exception    
    {
        if (containsProject(project))
        {
            IssueTrackingAccountDescriptor before = 
                new IssueTrackingAccountDescriptor(project);
            Criteria c = new Criteria().add(ProjectProjectgroupPeer.PROJECT_ID,
                                            project.getPrimaryKeyAsInt());
            c.add(ProjectProjectgroupPeer.PROJECT_GROUP_ID, getPrimaryKeyAsInt());
            ProjectProjectgroupPeer.doDelete(c);
            //rebuildProjectGroups();
            IssueTrackingAccountDescriptor after = 
                new IssueTrackingAccountDescriptor(project);
            before.syncTo(after);
        }
    }
    

    /**
     * Delete the project group completely.
     */
    public void delete(AccessControlList acl)
        throws Exception
    {
        acl.assertPermission("ProjectGroup - Delete", getDomain());
        //Remove all members of the group.
        for (Iterator i = getProjects().iterator(); i.hasNext();)
        {
            Project p = (Project)i.next();
            removeProject(p);
        }

        //Delete the project like any other project.
        super.delete(acl);
    }
        
    /**
     * Change the descriptions of a project group.
     */
    public void updateInfo(AccessControlList acl, String shortDescription,
                           String longDescription)
        throws ACLException, Exception
    {
        assertEditPermission(acl);
        setShortDescription(shortDescription);
        setLongDescription(longDescription);
        save();
    }
    
    //
    // Accessor methods
    //

    /**
     * Get a big list of all the viewable projects in this group.
     */
    public List getProjects(AccessControlList acl)
        throws Exception
    {
        return getProjects(new Integer(0), new Criteria(0), acl);
    }

    /**
     * Get a paginatable list of the viewable projects in this group.
     */
    public PeerBackedList getProjects(Integer itemsPerPage, Criteria filter, 
                                      AccessControlList acl)
        throws Exception
    {
        Criteria base = projectsInGroupCriteria();
        return ProjectPeer.getProjects(itemsPerPage, base, filter, acl);
    }

    /**
     * Get the count of the viewable projects in this group.
     */    
    public final int getNumberOfProjects(AccessControlList acl)
        throws Exception
    {
        return getProjects(acl).size();
    }

    /**
     * Returns the list of projects to which this project is equivalent.
     */
    public List expand()
        throws Exception
    {
        return getProjects();
    }

    /**
     * Returns true iff this group contains the given project.
     */
    public boolean containsProject(Project p)
        throws Exception
    {
        Criteria c = new Criteria()
            .add(ProjectProjectgroupPeer.PROJECT_ID, p.getID())
            .add(ProjectProjectgroupPeer.PROJECT_GROUP_ID, getID());
        return !ProjectProjectgroupPeer.doSelect(c).isEmpty();
    }

    /**
     * Returns the criteria to be used when selecting projects that are
     * in this project group.
     */
    private Criteria projectsInGroupCriteria()
    {
        return new Criteria()
            .addJoin(ProjectProjectgroupPeer.PROJECT_ID, 
                     ProjectPeer.PROJECT_ID)
            .add(ProjectProjectgroupPeer.PROJECT_GROUP_ID, getProjectId());
    }

    /**
     * Get a big list of all the projects in this group.
     */
    protected List getProjects()
        throws Exception
    {
        return ProjectPeer.doSelect(projectsInGroupCriteria());
    }
}
@


1.1.2.1
log
@Ported ProjectGroup, among other stuff.
@
text
@a0 223
/* ================================================================
 * Copyright (c) 2000 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.sql.*;

import org.webmacro.util.*;

import org.apache.turbine.util.db.Criteria;

import org.tigris.helm.security.AccessControlList;
import org.tigris.helm.security.ACLException;

import org.tigris.helm.AlreadyExists;
import org.tigris.helm.om.profile.*;
import org.tigris.helm.om.peer.ProjectProjectgroupPeer;


public class ProjectGroup extends Project
{
    private static Log log = new Log("prjGrp", "ProjectGroup");

    public static ProjectGroup add(AccessControlList acl, Domain domain,
                                   boolean isCategory, String name, 
                                   String shortDescription, 
                                   String longDescription)
        throws AlreadyExists, Exception
    {
        return add(acl, domain, isCategory, name, shortDescription,
                   longDescription, null);
    }

    public static ProjectGroup add (AccessControlList acl, Domain domain,
                                    boolean isCategory, String name, 
                                    String shortDescription, 
                                    String longDescription, 
                                    List initialMembers)
        throws AlreadyExists, Exception
    {
        acl.assertPermissionForDomain("ProjectGroup - Add", domain);
        //Get profile and license. (?)        
        ProjectProfile profile = null;
        if (isCategory)
        {
            profile = new CategoryProfile(); 
        } else {
            profile = new GroupProfile(); 
        }
        String license = null;
        ProjectGroup p = Project.add(acl, profile, domain, name, license,
                                     shortDescription, longDescription, "N", 
                                     "", "", acl.getUser(), acl.getUser()).asGroup();

        //Add the initial members.
        if (initialMembers != null)
        {
            for (Iterator i = initialMembers.iterator(); i.hasNext();)
            {
                Project p2= (Project)i.next();
                p.addProject(acl, p2);
            }        
        }
        return p;
    }

    ////////////////////////////////////////////////////////////////////
    // Read-write methods.
    ////////////////////////////////////////////////////////////////////

    public void addProject(AccessControlList acl, Project project)
        throws ACLException, Exception
    {
        acl.assertPermissionForDomain("ProjectGroup Member - Add", getDomain());
        //IssueTrackingAccountDescriptor before = 
        //new IssueTrackingAccountDescriptor(project);
        ProjectProjectgroup mapping = new ProjectProjectgroup();
        mapping.setProjectId(project.getPrimaryKeyAsInt());
        mapping.setProjectGroupId(project.getPrimaryKeyAsInt());
        //rebuildProjectGroups();
        //IssueTrackingAccountDescriptor after = 
        //new IssueTrackingAccountDescriptor(project);
        //before.syncTo(after);
    }

    protected void removeProject(AccessControlList acl, Project project)
        throws ACLException, Exception
    {
        acl.assertPermissionForDomain("ProjectGroup Member - Delete", getDomain());
        //IssueTrackingAccountDescriptor before = 
        //new IssueTrackingAccountDescriptor(project);
        Criteria c = new Criteria().add(ProjectProjectgroupPeer.PROJECT_ID,
                                        project.getPrimaryKeyAsInt());
        c.add(ProjectProjectgroupPeer.PROJECT_GROUP_ID, getPrimaryKeyAsInt());
        ProjectProjectgroupPeer.doDelete(c);
        //rebuildProjectGroups();
        //IssueTrackingAccountDescriptor after = 
        //new IssueTrackingAccountDescriptor(project);
        //before.syncTo(after);
    }

    /*
    public void delete(AccessControlList acl)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist, ACLException               
    {
        acl.assertPermissionForDomain("ProjectGroup - Delete", getDomainID());
        //Remove all members of the group.
        DataSet projectSet = prjGrpMgr.getProjectsForGroup(conn, getID());
        for (int i=0; i < projectSet.size(); i++)
        {
            String projectID = projectSet.getRecord(i)
                .getValue(ProjectProjectGroupManager.PROJECT_ID).asString();
            Project remove = new Project(conn, dMgr, projectID);
            removeProjectNoPerms(remove);
        }
        //Delete the project like any other project.
        super.delete(acl);
    }

    public void updateInfo(AccessControlList acl, String shortDescription,
                           String longDescription)
        throws ACLException, DataSetException, SQLException,
               JoistDatabaseException
    {
        acl.assertPermissionForDomain("ProjectGroup - Edit", getDomainID());
        try 
        {
            pMgr.updateProjectInfo
                (conn, getID(), null, shortDescription, longDescription, null,
                 null, null);
            setRecord(pMgr.getProjectForID(conn, getID()));
        } catch (DoesNotExist ignore) {} //Can't happen--we just used it.    
    }
    
    //
    // Accessor methods
    //

    public List getProjects(AccessControlList acl)
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        List projects = expand();

        return AccessControlledDatabaseFilter.getViewableProjects
            (acl, projects);
    }
    
    public List expand()
	throws DataSetException, SQLException
    {
        List projects = new ArrayList();        
        DataSet projectSet = prjGrpMgr.getProjectsForGroup(conn, getID());
        for (int i = 0; i < projectSet.size(); i++)
        {
            Record r = projectSet.getRecord(i);
	    String id = r.getValue(ProjectProjectGroupManager.PROJECT_ID)
                .asString();
	    try {
                Project p = new Project(conn, dMgr, id);
                if (!p.isHost() && !p.isDomain())
                {
                    projects.add(p);
                }
	    } catch (DoesNotExist ignore) {}
        }
	return projects;
    }

    public int getNumberOfProjects(AccessControlList acl)
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        return getProjects(acl).size();
    }
    */
}

@


1.1.2.2
log
@Ported getProjects(), expand(), and getNumberOfProjects() methods.
@
text
@d59 1
a59 1
import org.tigris.helm.*;
d62 1
a62 1
import org.tigris.helm.tool.AccessControlledDatabaseFilter;
a178 1
    */
d185 2
a186 1
        throws DoesNotExist, Exception
d188 2
d191 1
a191 1
            (acl, expand());
d195 1
a195 1
        throws Exception
d197 14
a210 7
        List projects = new ArrayList();
        List projectIDs = ProjectProjectgroupPeer.getProjectsForGroup(getID());
        for (Iterator i = projectIDs.iterator(); i.hasNext(); ) {
            Project p = Project.getInstance((String)i.next());
            if (!p.isHost() && !p.isDomain()) {
                projects.add(p);
            }
d215 3
a217 2
    public final int getNumberOfProjects(AccessControlList acl)
        throws DoesNotExist, Exception
d221 1
d223 1
@


1.1.2.3
log
@More porting for projects and user groups.
@
text
@a60 1
import org.tigris.helm.om.peer.ProjectPeer;
a67 4
    //
    // Mutator methods
    //

d111 4
d123 1
a123 2
        mapping.setProjectGroupId(getPrimaryKeyAsInt());
        mapping.save();
d185 1
a185 1
    /*    public List getProjects(AccessControlList acl)
a191 6
    public final int getNumberOfProjects(AccessControlList acl)
        throws DoesNotExist, Exception
    {
        return getProjects(acl).size();
        }*/

a194 4
        Criteria c = new Criteria().add
            (ProjectProjectgroupPeer.PROJECT_GROUP_ID, getPrimaryKeyAsInt());
        List mappings = ProjectProjectgroupPeer.doSelect(c);

d196 4
a199 5
        for (Iterator i = mappings.iterator(); i.hasNext(); ) {
            ProjectProjectgroup mapping = (ProjectProjectgroup)i.next();
            Project p = ProjectPeer.retrieveByPK(mapping.getProjectId());
            if (!p.isHost() && !p.isDomain()) 
            {
d204 6
@


1.1.2.4
log
@Removed crappy WebMacro logging in favor of the new Turbine logging system.  You can now say Log.debug("my msg") to use the Turbine system.
@
text
@d52 2
d67 2
@


1.1.2.5
log
@Put back usage of IssueTrackingAccountDescriptor in methods that should use it.
@
text
@a61 1
import org.tigris.helm.tool.task.IssueTrackingAccountDescriptor;
d115 3
a117 4
        acl.assertPermissionForDomain("ProjectGroup Member - Add", 
                                      getDomain());
        IssueTrackingAccountDescriptor before = 
            new IssueTrackingAccountDescriptor(project);
d123 3
a125 3
        IssueTrackingAccountDescriptor after = 
            new IssueTrackingAccountDescriptor(project);
        before.syncTo(after);
d131 3
a133 4
        acl.assertPermissionForDomain("ProjectGroup Member - Delete", 
                                      getDomain());
        IssueTrackingAccountDescriptor before = 
            new IssueTrackingAccountDescriptor(project);
d139 3
a141 3
        IssueTrackingAccountDescriptor after = 
            new IssueTrackingAccountDescriptor(project);
        before.syncTo(after);
d149 1
a149 1
        acl.assertPermissionForDomain("ProjectGroup - Delete", getDomain());
@


1.1.2.6
log
@Changed code to no longer use deprecated methods.
@
text
@d87 1
a87 1
        acl.assertPermission("ProjectGroup - Add", domain);
d116 1
a116 1
        acl.assertPermission("ProjectGroup Member - Add", 
d133 1
a133 1
        acl.assertPermission("ProjectGroup Member - Delete", 
d152 1
a152 1
        acl.assertPermission("ProjectGroup - Delete", getDomain());
d171 1
a171 1
        acl.assertPermission("ProjectGroup - Edit", getDomainID());
@


1.1.2.7
log
@Latest Torque-generated code to handle inheritance based on values in a database field column.
@
text
@d1 46
a48 1
// JDK classes
d50 1
a51 3
// Turbine classes
import org.apache.turbine.om.BaseObject;
import org.apache.turbine.om.peer.BasePeer;
d53 11
a63 18
import org.apache.turbine.util.ObjectUtils;
import org.apache.turbine.util.StringUtils;
import org.apache.turbine.util.ParameterParser;
import org.apache.turbine.util.Log;
import org.apache.turbine.util.db.pool.DBConnection;

import org.tigris.helm.om.peer.*;


/** 
  * The skeleton for this class was autogenerated by Torque on:
  *
  * [Mon Feb 12 19:04:35 PST 2001]
  *
  * You should add additional methods to this class to meet the
  * application requirements.  This class will only be generated as
  * long as the "firstbuild" file exists in the build directory.
  */
d66 85
a150 1
    public ProjectGroup()
d152 64
a215 1
                setType(ProjectPeer.CLASSKEY_GROUP);
@


1.1.2.8
log
@Reverting ProjectGroup and UserGroup, accidently overwritten on last commit of Torque-generated files.
@
text
@a0 46
/* ================================================================
 * Copyright (c) 2000 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.
 */

d3 1
a4 1
import java.sql.*;
d6 3
d10 18
a27 11

import org.tigris.helm.security.AccessControlList;
import org.tigris.helm.security.ACLException;

import org.tigris.helm.*;
import org.tigris.helm.om.profile.*;
import org.tigris.helm.om.peer.ProjectPeer;
import org.tigris.helm.om.peer.ProjectProjectgroupPeer;
import org.tigris.helm.tool.AccessControlledDatabaseFilter;
import org.tigris.helm.tool.task.IssueTrackingAccountDescriptor;

d30 1
a30 85
    //
    // Mutator methods
    //

    public static ProjectGroup add(AccessControlList acl, Domain domain,
                                   boolean isCategory, String name, 
                                   String shortDescription, 
                                   String longDescription)
        throws AlreadyExists, Exception
    {
        return add(acl, domain, isCategory, name, shortDescription,
                   longDescription, null);
    }

    public static ProjectGroup add (AccessControlList acl, Domain domain,
                                    boolean isCategory, String name, 
                                    String shortDescription, 
                                    String longDescription, 
                                    List initialMembers)
        throws AlreadyExists, Exception
    {
        acl.assertPermission("ProjectGroup - Add", domain);
        //Get profile and license. (?)        
        ProjectProfile profile = null;
        if (isCategory)
        {
            profile = new CategoryProfile(); 
        } else {
            profile = new GroupProfile(); 
        }
        String license = null;
        ProjectGroup p = Project.add(acl, profile, domain, name, license,
                                     shortDescription, longDescription, "N", 
                                     "", "", acl.getUser(), acl.getUser()).asGroup();

        //Add the initial members.
        if (initialMembers != null)
        {
            for (Iterator i = initialMembers.iterator(); i.hasNext();)
            {
                Project p2= (Project)i.next();
                p.addProject(acl, p2);
            }        
        }
        return p;
    }

    public void addProject(AccessControlList acl, Project project)
        throws ACLException, Exception
    {
        acl.assertPermission("ProjectGroup Member - Add", 
                                      getDomain());
        IssueTrackingAccountDescriptor before = 
            new IssueTrackingAccountDescriptor(project);
        ProjectProjectgroup mapping = new ProjectProjectgroup();
        mapping.setProjectId(project.getPrimaryKeyAsInt());
        mapping.setProjectGroupId(getPrimaryKeyAsInt());
        mapping.save();
        //rebuildProjectGroups();
        IssueTrackingAccountDescriptor after = 
            new IssueTrackingAccountDescriptor(project);
        before.syncTo(after);
    }

    protected void removeProject(AccessControlList acl, Project project)
        throws ACLException, Exception
    {
        acl.assertPermission("ProjectGroup Member - Delete", 
                                      getDomain());
        IssueTrackingAccountDescriptor before = 
            new IssueTrackingAccountDescriptor(project);
        Criteria c = new Criteria().add(ProjectProjectgroupPeer.PROJECT_ID,
                                        project.getPrimaryKeyAsInt());
        c.add(ProjectProjectgroupPeer.PROJECT_GROUP_ID, getPrimaryKeyAsInt());
        ProjectProjectgroupPeer.doDelete(c);
        //rebuildProjectGroups();
        IssueTrackingAccountDescriptor after = 
            new IssueTrackingAccountDescriptor(project);
        before.syncTo(after);
    }

    /*
    public void delete(AccessControlList acl)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist, ACLException               
d32 1
a32 64
        acl.assertPermission("ProjectGroup - Delete", getDomain());
        //Remove all members of the group.
        DataSet projectSet = prjGrpMgr.getProjectsForGroup(conn, getID());
        for (int i=0; i < projectSet.size(); i++)
        {
            String projectID = projectSet.getRecord(i)
                .getValue(ProjectProjectGroupManager.PROJECT_ID).asString();
            Project remove = new Project(conn, dMgr, projectID);
            removeProjectNoPerms(remove);
        }
        //Delete the project like any other project.
        super.delete(acl);
    }

    public void updateInfo(AccessControlList acl, String shortDescription,
                           String longDescription)
        throws ACLException, DataSetException, SQLException,
               JoistDatabaseException
    {
        acl.assertPermission("ProjectGroup - Edit", getDomainID());
        try 
        {
            pMgr.updateProjectInfo
                (conn, getID(), null, shortDescription, longDescription, null,
                 null, null);
            setRecord(pMgr.getProjectForID(conn, getID()));
        } catch (DoesNotExist ignore) {} //Can't happen--we just used it.    
    }
    */
    
    //
    // Accessor methods
    //

    /*    public List getProjects(AccessControlList acl)
        throws DoesNotExist, Exception
    {
        return AccessControlledDatabaseFilter.getViewableProjects
            (acl, expand());
    }
    
    public final int getNumberOfProjects(AccessControlList acl)
        throws DoesNotExist, Exception
    {
        return getProjects(acl).size();
        }*/

    public List expand()
        throws Exception
    {
        Criteria c = new Criteria().add
            (ProjectProjectgroupPeer.PROJECT_GROUP_ID, getPrimaryKeyAsInt());
        List mappings = ProjectProjectgroupPeer.doSelect(c);

        List projects = new ArrayList();
        for (Iterator i = mappings.iterator(); i.hasNext(); ) {
            ProjectProjectgroup mapping = (ProjectProjectgroup)i.next();
            Project p = ProjectPeer.retrieveByPK(mapping.getProjectId());
            if (!p.isHost() && !p.isDomain()) 
            {
                projects.add(p);
            }
        }
	return projects;
@


1.1.2.9
log
@Fixing compile errors.
@
text
@a65 5
    public ProjectGroup()
    {
        setType(ProjectPeer.CLASSKEY_GROUP);
    }

@


1.1.2.10
log
@Adding support for project group manipulation servlets.
@
text
@a57 1
import org.tigris.helm.om.*;
d59 3
a61 2
import org.tigris.helm.om.peer.*;
import org.tigris.helm.tool.paginate.PeerBackedList;
d102 3
a104 4
        ProjectGroup p = Project.add
            (acl, profile, domain, name, license,
             shortDescription, longDescription, "N", 
             "", "", acl.getUser(), acl.getUser()).asGroup();
d135 1
a135 4
    /**
     * Remove a project from the group.
     */
    public void removeProject(AccessControlList acl, Project project)
d139 1
a139 10
                             getDomain());
        removeProject(project);
    }

    /**
     * Remove a project from the group. Does no permission checking.
     */
    private void removeProject(Project project)
        throws Exception    
    {
a150 1
    
d152 1
a152 3
    /**
     * Delete the project group completely.
     */
d154 2
a155 1
        throws Exception
d159 2
a160 1
        for (Iterator i = getProjects().iterator(); i.hasNext();)
d162 4
a165 2
            Project p = (Project)i.next();
            removeProject(p);
a166 1

d170 1
a170 4
        
    /**
     * Change the descriptions of a project group.
     */
d173 2
a174 1
        throws ACLException, Exception
d176 8
a183 4
        assertEditPermission(acl);
        setShortDescription(shortDescription);
        setLongDescription(longDescription);
        save();
d185 1
d191 2
a192 17
    /**
     * Returns the criteria to be used when selecting projects that are
     * in this project group.
     */
    private Criteria projectsInGroupCriteria()
    {
        return new Criteria()
            .addJoin(ProjectProjectgroupPeer.PROJECT_ID, 
                     ProjectPeer.PROJECT_ID)
            .add(ProjectProjectgroupPeer.PROJECT_GROUP_ID, getProjectId());
    }

    /**
     * Get a big list of all the projects in this group.
     */
    protected List getProjects()
        throws Exception
d194 2
a195 1
        return ProjectPeer.doSelect(projectsInGroupCriteria());
d197 1
a197 24

    /**
     * Get a big list of all the viewable projects in this group.
     */
    protected List getProjects(AccessControlList acl)
        throws Exception
    {
        return getProjects(new Integer(0), new Criteria(0), acl);
    }

    /**
     * Get a paginatable list of the viewable projects in this group.
     */
    public PeerBackedList getProjects(Integer itemsPerPage, Criteria filter, 
                                      AccessControlList acl)
        throws Exception
    {
        Criteria base = projectsInGroupCriteria();
        return ProjectPeer.getProjects(itemsPerPage, base, filter, acl);
    }

    /**
     * Get the count of the viewable projects in this group.
     */    
d199 1
a199 1
        throws Exception
d202 1
a202 1
    }
a203 3
    /**
     * Returns the list of projects to which this project is equivalent.
     */
d207 14
a220 1
        return getProjects();
@


1.1.2.11
log
@Big wide-ranging patch being committed all at once due to network downness. Features of this patch include: lots of added and updated JavaDoc, conversion of emails to use TemplateInterpolator and HelmEmailer, rearrangement of methods, changing code that gets mappings and loops over them to code that just gets the appropriate objects from the peer using AddJoin.
@
text
@a74 3
    /**
     * Add a new project group.
     */
a84 3
    /**
     * Add a new project group with some initial members.
     */
a118 3
    /**
     * Add a project to the group.
     */
a123 9
        addProject(project);
    }

    /**
     * Add a project to the group. Does no permission checking.
     */
    protected void addProject(Project project)
        throws Exception    
    {
d150 1
a150 1
    protected void removeProject(Project project)
d202 21
d225 1
a225 1
    public List getProjects(AccessControlList acl)
a257 21
    }

    /**
     * Returns the criteria to be used when selecting projects that are
     * in this project group.
     */
    private Criteria projectsInGroupCriteria()
    {
        return new Criteria()
            .addJoin(ProjectProjectgroupPeer.PROJECT_ID, 
                     ProjectPeer.PROJECT_ID)
            .add(ProjectProjectgroupPeer.PROJECT_GROUP_ID, getProjectId());
    }

    /**
     * Get a big list of all the projects in this group.
     */
    protected List getProjects()
        throws Exception
    {
        return ProjectPeer.doSelect(projectsInGroupCriteria());
@


1.1.2.12
log
@Don't add a project-projectgroup mapping if it already exists--this will cause an SQLException to be thrown.
@
text
@d142 10
a151 14
        //Do nothing if the project is already in the group.
        if (!containsProject(project))
        {
            IssueTrackingAccountDescriptor before = 
                new IssueTrackingAccountDescriptor(project);
            ProjectProjectgroup mapping = new ProjectProjectgroup();
            mapping.setProjectId(project.getPrimaryKeyAsInt());
            mapping.setProjectGroupId(getPrimaryKeyAsInt());
            mapping.save();
            //rebuildProjectGroups();
            IssueTrackingAccountDescriptor after = 
                new IssueTrackingAccountDescriptor(project);
            before.syncTo(after);
        }
a254 12
    }

    /**
     * Returns true iff this group contains the given project.
     */
    public boolean containsProject(Project p)
        throws Exception
    {
        Criteria c = new Criteria()
            .add(ProjectProjectgroupPeer.PROJECT_ID, p.getID())
            .add(ProjectProjectgroupPeer.PROJECT_GROUP_ID, getID());
        return !ProjectProjectgroupPeer.doSelect(c).isEmpty();
@


1.1.2.13
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
@


1.1.2.14
log
@Added new imports necessitated by Torque.
@
text
@a60 1
import org.tigris.helm.om.base.*;
@


1.1.2.15
log
@Added audit logging in a bunch of places.
@
text
@a66 32
    /**
     * Description of the audit log entry created when a project of this
     * type is added.  
     */
    private static final String AUDIT_LOG_ON_ADD = "Project group added: ";

    /**
     * Description of the audit log entry created when a project of this
     * type is deleted.
     */
    private static final String AUDIT_LOG_ON_DELETE = "Project group deleted: ";

    /**
     * Description of the audit log entry created when a project of this
     * type is edited.
     */
    private static final String AUDIT_LOG_ON_EDIT = "Project group edited: ";

    /**
     * Description of the audit log entry created when a project is added
     * to this group.
     */
    private static final AUDIT_LOG_ON_PROJECT_ADD = 
        "Project added to project group: ";

    /**
     * Description of the audit log entry created when a project is removed
     * from this group.
     */
    private static final AUDIT_LOG_ON_PROJECT_REMOVE = 
        "Project removed from project group: ";

d132 3
a134 11
        //Do nothing if the project is already in the group.
        if (!containsProject(project))
        {
            acl.assertPermission("ProjectGroup Member - Add", 
                                 getDomain());
            addProject(project);

            AuditLog.logEvent
                (acl.getUser(), this, this.AUDIT_LOG_ON_PROJECT_ADD
                 + getName() + " <- " + project.getName());
        }
d143 1
d165 3
a167 10
        if (containsProject(project))
        {
            acl.assertPermission("ProjectGroup Member - Delete", 
                                 getDomain());
            removeProject(project);

            AuditLog.logEvent
                (acl.getUser(), this, this.AUDIT_LOG_ON_PROJECT_REMOVE 
                 + getName() + " -> " + project.getName());
        }
d176 10
a185 13
        if (containsProject(project))
        {
            IssueTrackingAccountDescriptor before = 
                new IssueTrackingAccountDescriptor(project);
            Criteria c = new Criteria().add(ProjectProjectgroupPeer.PROJECT_ID,
                                            project.getPrimaryKeyAsInt());
            c.add(ProjectProjectgroupPeer.PROJECT_GROUP_ID, getPrimaryKeyAsInt());
            ProjectProjectgroupPeer.doDelete(c);
            //rebuildProjectGroups();
            IssueTrackingAccountDescriptor after = 
                new IssueTrackingAccountDescriptor(project);
            before.syncTo(after);
        }
@


1.1.2.16
log
@Fixed compile errors introduced in audit logging patch.
@
text
@a61 1
import org.tigris.helm.tool.audit.AuditLog;
d89 1
a89 1
    private static final String AUDIT_LOG_ON_PROJECT_ADD = 
d96 1
a96 1
    private static final String AUDIT_LOG_ON_PROJECT_REMOVE = 
@


