head	1.6;
access;
symbols
	dlr:1.1.1
	HELM_PEER_PORT_BRANCH:1.1.1.1;
locks; strict;
comment	@# @;


1.6
date	2001.03.07.01.14.51;	author lucas;	state dead;
branches;
next	1.5;

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

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

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

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

1.1
date	2001.01.28.01.18.25;	author dlr;	state dead;
branches
	1.1.1.1
	1.1.2.1;
next	;

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

1.1.2.1
date	2001.01.28.01.18.25;	author dlr;	state Exp;
branches;
next	1.1.2.2;

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

1.1.2.3
date	2001.01.29.22.06.36;	author dlr;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2001.01.30.01.21.06;	author leonardr;	state Exp;
branches;
next	1.1.2.5;

1.1.2.5
date	2001.01.30.06.29.06;	author dlr;	state Exp;
branches;
next	1.1.2.6;

1.1.2.6
date	2001.01.30.06.54.09;	author dlr;	state Exp;
branches;
next	1.1.2.7;

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

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

1.1.2.9
date	2001.01.31.02.45.18;	author dlr;	state Exp;
branches;
next	1.1.2.10;

1.1.2.10
date	2001.01.31.03.11.05;	author dlr;	state Exp;
branches;
next	1.1.2.11;

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

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

1.1.2.13
date	2001.02.01.21.02.07;	author dlr;	state Exp;
branches;
next	1.1.2.14;

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

1.1.2.15
date	2001.02.08.01.29.08;	author elicia;	state Exp;
branches;
next	1.1.2.16;

1.1.2.16
date	2001.02.08.15.15.03;	author leonardr;	state Exp;
branches;
next	1.1.2.17;

1.1.2.17
date	2001.02.08.18.19.12;	author leonardr;	state Exp;
branches;
next	1.1.2.18;

1.1.2.18
date	2001.02.08.19.51.45;	author dlr;	state Exp;
branches;
next	1.1.2.19;

1.1.2.19
date	2001.02.09.22.05.51;	author dlr;	state Exp;
branches;
next	1.1.2.20;

1.1.2.20
date	2001.02.09.22.21.25;	author dlr;	state Exp;
branches;
next	1.1.2.21;

1.1.2.21
date	2001.02.09.23.12.08;	author dlr;	state Exp;
branches;
next	1.1.2.22;

1.1.2.22
date	2001.02.09.23.14.34;	author dlr;	state Exp;
branches;
next	1.1.2.23;

1.1.2.23
date	2001.02.09.23.19.37;	author dlr;	state Exp;
branches;
next	1.1.2.24;

1.1.2.24
date	2001.02.13.00.55.54;	author dlr;	state Exp;
branches;
next	1.1.2.25;

1.1.2.25
date	2001.02.13.03.35.34;	author leonardr;	state Exp;
branches;
next	1.1.2.26;

1.1.2.26
date	2001.02.14.00.34.10;	author leonardr;	state Exp;
branches;
next	1.1.2.27;

1.1.2.27
date	2001.02.14.00.49.53;	author leonardr;	state Exp;
branches;
next	1.1.2.28;

1.1.2.28
date	2001.02.15.20.50.39;	author leonardr;	state Exp;
branches;
next	1.1.2.29;

1.1.2.29
date	2001.02.16.03.01.32;	author dlr;	state Exp;
branches;
next	1.1.2.30;

1.1.2.30
date	2001.02.17.00.05.38;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.6
log
@Deprecated by Torque changes. -dlr
@
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.peer;

import java.util.*;

import org.apache.turbine.om.*;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.Log;

import org.tigris.helm.om.base.*;
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.AlreadyExists;
import org.tigris.helm.om.Domain;
import org.tigris.helm.om.Project;
import org.tigris.helm.om.ProjectGroup;
import org.tigris.helm.om.ProjectType;
import org.tigris.helm.om.profile.*;
import org.tigris.helm.tool.PeerTool;

import org.tigris.helm.tool.paginate.PeerBackedList;
import org.tigris.helm.security.AccessControlList;

/**
 * Extension of generated Peer BaseProjectPeer.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 */
public class ProjectPeer extends BaseProjectPeer
{

    //
    // Special data structures and methods for paginating lists of projects.
    //     

    public static Map filterableFields = new HashMap();
    
    /**
     * How objects of this type should be ordered in lists.
     */
    public static final String DEFAULT_ORDER_BY = NAME;

    /**
     * Static initializer; initializes the filterableFields data structure.
     */
    static
    { 
        filterableFields.put("Project Name", ProjectPeer.NAME);
        filterableFields.put("Summary", ProjectPeer.SHORT_DESCRIPTION);
        filterableFields.put("Description", ProjectPeer.LONG_DESCRIPTION);
    };

    //
    // Constants and methods used in dealing with special host and
    // domain projects.
    //

    /**
     * The special name of projects which represent all public
     * projects in a domain.  
     */
    public static final String DOMAIN_PUBLIC_PROJECT_NAME = 
        "*All public projects in domain";

    /**
     * The special name of projects which represent all projects in a
     * domain.
     */
    public static final String DOMAIN_PROJECT_NAME =
        "*All projects in domain";

    /**
     * The special name of the project representing all projects on
     * the host.  
     */
    public static final String HOST_PROJECT_NAME = 
        "**All projects on host";

    /**
     * The default project name.
     */
    public static final String DEFAULT_PROJECT_NAME = "www";

    /**
     * The descrition of the default project.
     */
    public static final String DEFAULT_PROJECT_DESCRIP =
        "Web publishing module";
    
    //
    // Special projects
    //

    public static ProjectGroup getHostProject()
        throws Exception
    {
        Criteria c = new Criteria().add(TYPE, Project.HOST_TYPE);
        try {
            ProjectGroup host =
                (ProjectGroup)PeerTool.getFirstBO(ProjectPeer.doSelect(c), "");
            return host;
        }
        catch (DoesNotExist e) {
            throw new Error("Could not locate host project!");
        }
    }
    
    /**
     * Get the project group for all projects in the specified domain.
     */
    public static ProjectGroup getDomainProject(Domain domain)
        throws Exception
    {
        ProjectGroup p = null;
        if (domain.isHost()) {
            p = getHostProject();
        }
        else {
            try {
                p = getGroupInstanceByName(domain, DOMAIN_PROJECT_NAME);
            }
            catch (DoesNotExist e) {
                throw new Error("Could not locate special project group for " +
                                domain.getName());
            }
        }
        return p;
    }

    public static ProjectGroup getPublicDomainProject(Domain domain)
        throws Exception
    {
        if (domain.isHost())
        {
            return getHostProject();
        }
        ProjectGroup p = null;
        try {
            p = getGroupInstanceByName(domain, DOMAIN_PUBLIC_PROJECT_NAME);
        }
        catch (DoesNotExist e) {
            throw new Error
                ("Could not locate special public project group for " +
                 domain.getName());
        }
        return p;
    }

    //
    // Ways of retrieving Project objects.
    //

    public static Project getInstance(String projectID)
        throws Exception
    {
        return ProjectPeer.retrieveByPK(new NumberKey(projectID));
    }

    public static Project getInstanceByName(Domain domain, String name)
        throws DoesNotExist, Exception
    {
        Criteria c = new Criteria()
            .add(NAME, name)
            .add(DOMAIN_ID, domain.getID());
        List p = ProjectPeer.doSelect(c);
        return (Project)PeerTool.getFirstBO(p, "Project named " + name, domain);
    }

    public static Project getInstanceByAliasURL(Domain domain, String aliasURL)
        throws DoesNotExist, Exception
    {
        Criteria c = new Criteria()
            .add(ALIAS_URL, aliasURL)
            .add(DOMAIN_ID, domain.getID());
        List p = ProjectPeer.doSelect(c);
        return (Project)PeerTool.getFirstBO(p, "Project with alias URL " +
                                            aliasURL, domain);
    }

    //
    // Ways of retrieving ProjectGroup objects.
    //
    public static ProjectGroup getGroupInstance(String projectID)
        throws Exception
    {
        Criteria c = new Criteria().add(PROJECT_ID, projectID);
        List p = doSelect(c);
        return (ProjectGroup)PeerTool.getFirstBO
            (p, "Project group with ID " + projectID);
    }

    public static ProjectGroup getGroupInstanceByName(Domain domain,
                                                      String name)
        throws Exception
    {
        Criteria c = new Criteria()
            .add(NAME, name)
            .add(DOMAIN_ID, domain.getID());
        List p = doSelect(c);
        return (ProjectGroup)PeerTool.getFirstBO
            (p, "Project group named " + name, domain);
    }

    /**
     * Get a list of projects matching a base Criteria and a filter
     * criteria, filtering the list further by removing projects
     * that cannot be viewed by the user whose ACL is passed in.
     */
    public static PeerBackedList getProjects
        (Integer itemsPerPage, Criteria base, Criteria filter, 
         AccessControlList acl)
        throws Exception
    {
        if (base == null) base = new Criteria();

        PeerBackedList l = new PeerBackedList(ProjectPeer.class, 
                                              itemsPerPage, base, filter);
        List toRemove = new ArrayList();
        for (Iterator i = l.iterator(); i.hasNext();)
        {
            Project p = (Project)i.next();
            if (!p.isViewableBy(acl))
            {
                toRemove.add(p);
            }           
        }
        l.removeAll(toRemove);
        return l;
    }

    //
    // Utility methods.
    // 

     /**
      * Throws an exception if a project with the given name exists
      * in the given domain.
      */
     public static void assertProjectNonexistance(Domain domain, String name)
         throws AlreadyExists, Exception
     {
         try {
             Project ignore = ProjectPeer.getInstanceByName(domain, name);
         }
         catch (DoesNotExist good) {
             return;
         }
         throw new AlreadyExists("A project called " + name,
                                 "domain named " + domain.getName());
     }


    ////////////////////////////////////////////////////////////////
    // Project retrieval
    ////////////////////////////////////////////////////////////////

    /**
     * Gets a project name for a project ID.
     *
     * @@param projectID The database key to obtain the name for.
     * @@return          The project name.
     *
     * @@exception DoesNotExist If the projectID is invalid.
     * @@exception Exception    If a database error occurs.
     *
     * @@deprecated You'd have to be a total retard to need this method.
     */
    public static final String getProjectName(String projectID)
        throws DoesNotExist, Exception
    {
        return getInstance(projectID).getName();
    }

    /**
     * Gets a project ID for a project name.
     *
     * @@param projectID The project name to obtain the name for.
     * @@return          The project ID.
     *
     * @@exception DoesNotExist If the domain or name are invalid.
     * @@exception Exception    If a database error occurs.
     *
     * @@deprecated You'd have to be a total retard to need this method.
     */
    public static final String getProjectID(Domain domain, String name)
        throws DoesNotExist, Exception
    {
        return getInstanceByName(domain, name).getID();
    }


     /**
      * Retrieves a List containing all regular projects for a domain.
      *
      * @@param  domainID      The domain for which to get projects.
      * @@return a List
      *
      */
     public List getProjectsForDomain (String domainID)
         throws Exception
     {
         return getProjectsForDomainType(domainID, Project.REGULAR_TYPE);
     }

     /**
      * Retrieves a List containing all category projects for a domain.
      *
      * @@param  domainID      The domain for which to get categories.
      * @@return a List
      */
     public List getCategoriesForDomain (String domainID)
         throws Exception
     {
         return getProjectsForDomainType(domainID, Project.CATEGORY_TYPE);
     }

     /**
      * Retrieves a List containing all projects for a domain and
      * a given type.
      *
      * @@param  domainID      The domain for which to get projects.
      * @@param  type          The type of project to get.
      * @@return a List
      */
     public List getProjectsForDomainType (String domainID, String type)
         throws Exception
     {
         Criteria c = new Criteria().add(DOMAIN_ID, domainID).add(TYPE, type);
         return doSelect(c);
     }        

}
@


1.5
log
@Changes to keep in step with the latest Torque-generated code.
@
text
@@


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
@d201 1
a201 1
        return ProjectPeer.retrieveByPK(new SimpleKey(projectID));
@


1.3
log
@Added filter information to ProjectPeer.
@
text
@d51 1
d201 1
a201 1
        return ProjectPeer.retrieveByPK(Integer.parseInt(projectID));
@


1.2
log
@adding files from the branch to the head
@
text
@d77 21
a132 12

    /**
     * How objects of this type should be ordered in lists.
     */
    public static final String DEFAULT_ORDER_BY = NAME;


    //
    // Special data structures and methods for paginating lists of projects.
    //     

    public static Map filterableFields = new HashMap();
@


1.1
log
@file ProjectPeer.java was initially added on branch HELM_PEER_PORT_BRANCH.
@
text
@d1 367
@


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

import java.util.*;

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

import org.tigris.helm.om.base.*;
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.AlreadyExists;
import org.tigris.helm.om.Domain;
import org.tigris.helm.om.Project;
import org.tigris.helm.om.ProjectGroup;
import org.tigris.helm.om.ProjectType;
import org.tigris.helm.om.profile.*;
import org.tigris.helm.tool.PeerTool;

import org.tigris.helm.tool.paginate.PeerBackedList;
import org.tigris.helm.security.AccessControlList;

/**
 * Extension of generated Peer BaseProjectPeer.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 */
public class ProjectPeer extends BaseProjectPeer
{

    //
    // Constants and methods used in dealing with special host and
    // domain projects.
    //

    /**
     * The special name of projects which represent all public
     * projects in a domain.  
     */
    public static final String DOMAIN_PUBLIC_PROJECT_NAME = 
        "*All public projects in domain";

    /**
     * The special name of projects which represent all projects in a
     * domain.
     */
    public static final String DOMAIN_PROJECT_NAME =
        "*All projects in domain";

    /**
     * The special name of the project representing all projects on
     * the host.  
     */
    public static final String HOST_PROJECT_NAME = 
        "**All projects on host";

    /**
     * The default project name.
     */
    public static final String DEFAULT_PROJECT_NAME = "www";

    /**
     * The descrition of the default project.
     */
    public static final String DEFAULT_PROJECT_DESCRIP =
        "Web publishing module";

    /**
     * How objects of this type should be ordered in lists.
     */
    public static final String DEFAULT_ORDER_BY = NAME;


    //
    // Special data structures and methods for paginating lists of projects.
    //     

    public static Map filterableFields = new HashMap();
    
    //
    // Special projects
    //

    public static ProjectGroup getHostProject()
        throws Exception
    {
        Criteria c = new Criteria().add(TYPE, Project.HOST_TYPE);
        try {
            ProjectGroup host =
                (ProjectGroup)PeerTool.getFirstBO(ProjectPeer.doSelect(c), "");
            return host;
        }
        catch (DoesNotExist e) {
            throw new Error("Could not locate host project!");
        }
    }
    
    /**
     * Get the project group for all projects in the specified domain.
     */
    public static ProjectGroup getDomainProject(Domain domain)
        throws Exception
    {
        ProjectGroup p = null;
        if (domain.isHost()) {
            p = getHostProject();
        }
        else {
            try {
                p = getGroupInstanceByName(domain, DOMAIN_PROJECT_NAME);
            }
            catch (DoesNotExist e) {
                throw new Error("Could not locate special project group for " +
                                domain.getName());
            }
        }
        return p;
    }

    public static ProjectGroup getPublicDomainProject(Domain domain)
        throws Exception
    {
        if (domain.isHost())
        {
            return getHostProject();
        }
        ProjectGroup p = null;
        try {
            p = getGroupInstanceByName(domain, DOMAIN_PUBLIC_PROJECT_NAME);
        }
        catch (DoesNotExist e) {
            throw new Error
                ("Could not locate special public project group for " +
                 domain.getName());
        }
        return p;
    }

    //
    // Ways of retrieving Project objects.
    //

    public static Project getInstance(String projectID)
        throws Exception
    {
        return ProjectPeer.retrieveByPK(Integer.parseInt(projectID));
    }

    public static Project getInstanceByName(Domain domain, String name)
        throws DoesNotExist, Exception
    {
        Criteria c = new Criteria()
            .add(NAME, name)
            .add(DOMAIN_ID, domain.getID());
        List p = ProjectPeer.doSelect(c);
        return (Project)PeerTool.getFirstBO(p, "Project named " + name, domain);
    }

    public static Project getInstanceByAliasURL(Domain domain, String aliasURL)
        throws DoesNotExist, Exception
    {
        Criteria c = new Criteria()
            .add(ALIAS_URL, aliasURL)
            .add(DOMAIN_ID, domain.getID());
        List p = ProjectPeer.doSelect(c);
        return (Project)PeerTool.getFirstBO(p, "Project with alias URL " +
                                            aliasURL, domain);
    }

    //
    // Ways of retrieving ProjectGroup objects.
    //
    public static ProjectGroup getGroupInstance(String projectID)
        throws Exception
    {
        Criteria c = new Criteria().add(PROJECT_ID, projectID);
        List p = doSelect(c);
        return (ProjectGroup)PeerTool.getFirstBO
            (p, "Project group with ID " + projectID);
    }

    public static ProjectGroup getGroupInstanceByName(Domain domain,
                                                      String name)
        throws Exception
    {
        Criteria c = new Criteria()
            .add(NAME, name)
            .add(DOMAIN_ID, domain.getID());
        List p = doSelect(c);
        return (ProjectGroup)PeerTool.getFirstBO
            (p, "Project group named " + name, domain);
    }

    /**
     * Get a list of projects matching a base Criteria and a filter
     * criteria, filtering the list further by removing projects
     * that cannot be viewed by the user whose ACL is passed in.
     */
    public static PeerBackedList getProjects
        (Integer itemsPerPage, Criteria base, Criteria filter, 
         AccessControlList acl)
        throws Exception
    {
        if (base == null) base = new Criteria();

        PeerBackedList l = new PeerBackedList(ProjectPeer.class, 
                                              itemsPerPage, base, filter);
        List toRemove = new ArrayList();
        for (Iterator i = l.iterator(); i.hasNext();)
        {
            Project p = (Project)i.next();
            if (!p.isViewableBy(acl))
            {
                toRemove.add(p);
            }           
        }
        l.removeAll(toRemove);
        return l;
    }

    //
    // Utility methods.
    // 

     /**
      * Throws an exception if a project with the given name exists
      * in the given domain.
      */
     public static void assertProjectNonexistance(Domain domain, String name)
         throws AlreadyExists, Exception
     {
         try {
             Project ignore = ProjectPeer.getInstanceByName(domain, name);
         }
         catch (DoesNotExist good) {
             return;
         }
         throw new AlreadyExists("A project called " + name,
                                 "domain named " + domain.getName());
     }


    ////////////////////////////////////////////////////////////////
    // Project retrieval
    ////////////////////////////////////////////////////////////////

    /**
     * Gets a project name for a project ID.
     *
     * @@param projectID The database key to obtain the name for.
     * @@return          The project name.
     *
     * @@exception DoesNotExist If the projectID is invalid.
     * @@exception Exception    If a database error occurs.
     *
     * @@deprecated You'd have to be a total retard to need this method.
     */
    public static final String getProjectName(String projectID)
        throws DoesNotExist, Exception
    {
        return getInstance(projectID).getName();
    }

    /**
     * Gets a project ID for a project name.
     *
     * @@param projectID The project name to obtain the name for.
     * @@return          The project ID.
     *
     * @@exception DoesNotExist If the domain or name are invalid.
     * @@exception Exception    If a database error occurs.
     *
     * @@deprecated You'd have to be a total retard to need this method.
     */
    public static final String getProjectID(Domain domain, String name)
        throws DoesNotExist, Exception
    {
        return getInstanceByName(domain, name).getID();
    }


     /**
      * Retrieves a List containing all regular projects for a domain.
      *
      * @@param  domainID      The domain for which to get projects.
      * @@return a List
      *
      */
     public List getProjectsForDomain (String domainID)
         throws Exception
     {
         return getProjectsForDomainType(domainID, Project.REGULAR_TYPE);
     }

     /**
      * Retrieves a List containing all category projects for a domain.
      *
      * @@param  domainID      The domain for which to get categories.
      * @@return a List
      */
     public List getCategoriesForDomain (String domainID)
         throws Exception
     {
         return getProjectsForDomainType(domainID, Project.CATEGORY_TYPE);
     }

     /**
      * Retrieves a List containing all projects for a domain and
      * a given type.
      *
      * @@param  domainID      The domain for which to get projects.
      * @@param  type          The type of project to get.
      * @@return a List
      */
     public List getProjectsForDomainType (String domainID, String type)
         throws Exception
     {
         Criteria c = new Criteria().add(DOMAIN_ID, domainID).add(TYPE, type);
         return doSelect(c);
     }        

}
@


1.1.2.1
log
@Classes ported to the Turbine Peer system. -dlr and leonardr
@
text
@a0 926
/* ================================================================
 * Copyright (c) 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.peer;

import java.util.*;

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

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.Domain;
import org.tigris.helm.om.Project;
import org.tigris.helm.om.ProjectType;
import org.tigris.helm.tool.PeerTool;

/**
 * Extension of generated Peer BaseProjectPeer.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 */
public class ProjectPeer extends BaseProjectPeer
{
    //
    // Constants and methods used in dealing with special host and
    // domain projects.
    //

    /**
     * The special name of projects which represent all public
     * projects in a domain.  
     */
    public static final String DOMAIN_PUBLIC_PROJECT_NAME = 
        "*All public projects in domain";

    /**
     * The special name of projects which represent all projects in a
     * domain.
     */
    public static final String DOMAIN_PROJECT_NAME =
        "*All projects in domain";

    /**
     * The special name of the project representing all projects on
     * the host.  
     */
    public static final String HOST_PROJECT_NAME = 
        "**All projects on host";

    /**
     * The keyword designating a domain project in the type field.
     */
    public static final String DOMAIN_PROJECT_TYPE = "domain";

    /**
     * The keyword designating the host project in the type field.
     */
    public static final String HOST_PROJECT_TYPE = "host";

    /**
     * The keyword designating a base project in the type field.
     */
    public static final String BASE_PROJECT_TYPE = "base";

    /**
     * The keyword designating a category project in the type field.
     */
    public static final String CATEGORY_PROJECT_TYPE = "category";

    //
    // Special projects
    //

    public static Project getHostProject()
        throws Exception
    {
        Criteria c = new Criteria().add(TYPE, ProjectType.HOST);
        Project p = null;
        try {
            p = (Project)PeerTool.getFirstBO(ProjectPeer.doSelect(c), "");
        } catch (Exception e) {
            throw new Exception("ERROR: Could not locate host project!");
        }
        return p;
    }
    
    public static Project getDomainProject(Domain domain)
        throws Exception
    {
        Project p = null;
        try {
            p = getInstanceByName(domain, DOMAIN_PROJECT_NAME);
        } catch (DoesNotExist e) {
            throw new Exception
                ("ERROR: Could not locate special project group for " + 
                 domain.getName() + ": " + e.getMessage());
        }
        return p;
    }

    public static Project getPublicDomainProject(Domain domain)
        throws Exception
    {
        Project p = null;
        try {
            p = getInstanceByName(domain, DOMAIN_PROJECT_NAME);
        } catch (DoesNotExist e) {
            throw new Exception
                ("ERROR: Could not locate special public project group for " +
                 domain.getName() + ": " + e.getMessage());
        }
        return p;
    }

    //
    // Ways of retrieving Project objects.
    //

    public static Project getInstance(String projectID)
        throws Exception
    {
        return ProjectPeer.retrieveByPK(Integer.parseInt(projectID));
    }

    public static Project getInstanceByName(Domain domain, String name)
        throws DoesNotExist, Exception
    {
        Criteria c = new Criteria()
            .add(ProjectPeer.NAME,name)
            .add(ProjectPeer.DOMAIN_ID, domain.getID());
        List p = ProjectPeer.doSelect(c);
        return (Project)PeerTool.getFirstBO
            (p, "Project named " + name + " in domain " + domain.getName());
    }

//     /**
//      * Checks whether a project name already exists in the given domain.
//      */
//     public void assertProjectNonexistance(String domainID, String name)
//         throws AlreadyExists, DBException
//     {
//         Record project = getProjectForName(domainID, name);
//         if (project != null)
//         {
//            throw new AlreadyExists("Project in domain + " domainID 
//                                    + " with name " + name);
//         }
//     }


//     ////////////////////////////////////////////////////////////////
//     // Project addition
//     ////////////////////////////////////////////////////////////////

//     /**
//      * Adds a project.
//      *
//      * @@param domainID          ID of Domain in which the project resides.
//      * @@param name              Name of the project.
//      * @@param license           License of the project.
//      * @@param shortDescription  A short description of the project.
//      * @@param longDescription   A long description of the project.
//      * @@param useIndex          Whether to use the index file contents for the
//      *                          long description.
//      * @@param aliasURL          URL to use as alias, if any.
//      * @@param proposedBy        User who proposed the project.
//      * @@param approvedBy        User who approved the project, if any.
//      * @@return                  The database record for the project.
//      *
//      * @@exception AlreadyExists if a project in this domain with this name exists.
//      */
//     public Record addProject (ProjectProfile profile,
//                               String domainID,
//                               String name, 
//                               String license,
//                               String shortDescription,
//                               String longDescription,
//                               String useIndex,
//                               String status,
//                               String aliasURL,
//                               String proposedBy,
//                               String approvedBy)
//         throws AlreadyExists, DBException
//     {        
//         Record p = null;
//         assertProjectNonexistance(domainID, name);
//         try {
//             p = updateProject(null,             //projectID
//                               profile,          //profile
//                               domainID,         //domainID
//                               name,             //name
//                               license,          //license
//                               shortDescription, //shortDescription
//                               longDescription,  //longDescription
//                               useIndex,         //useIndex
//                               status,           //status
//                               aliasURL,         //aliasURL
//                               proposedBy,       //proposedBy
//                               approvedBy        //approvedBy
//                               );
//         } catch (DoesNotExist ignore) {}
//         return p;
//     }


//     ////////////////////////////////////////////////////////////////
//     // Project manipulation
//     ////////////////////////////////////////////////////////////////

//     /**
//      * Approves the project in the name of the given userID.
//      *
//      * @@param projectID   The project to approve.
//      * @@param userID      The user approving the project.
//      * @@return  The system-assigned project ID for the project.
//      *
//      * @@exception DBException if a database error occurs.
//      * @@exception DoesNotExist if the specified project is invalid.
//      */
//     public void approveProject(String projectID, String userID)
//         throws DBException, DoesNotExist
//     {
//         Record project = getProjectForID(projectID);
//         try {
//             project.setValue(PROJECT_APPROVED_BY, userID);
//             project.save();
//         } catch (DataSetException e) {
//             throw new DBException
//         }
//     }

//     /**
//      * Updates a project's info.
//      * This is public version of the private updateProject.  Used
//      * by, eg., ProjectEdit  to update project info.
//      * <p>
//      * Pass nulls for all args you do not want to change.
//      *
//      * @@param projectID         The database key of the project to update.
//      * @@param license           License of the project.
//      * @@param shortDescription  A short description of the project.
//      * @@param longDescription   A long description of the project.
//      * @@param useIndex          Whether to use the index file contents for the
//      *                          long description.
//      * @@param status            Status of the project.
//      * @@param aliasURL          Project URL
//      *
//      * @@exception DBException if a database error occurs.
//      * @@exception DoesNotExist if the specified project is invalid.
//      */
//     public void updateProjectInfo(String projectID,
//                                   String license,
//                                   String shortDescription,
//                                   String longDescription,
//                                   String useIndex,
//                                   String status, 
//                                   String aliasURL
//                                   )
//         throws DoesNotExist, DBException
//     {
//         updateProject(projectID,        //projectID
//                       null,             //profile
//                       null,             //domainID
//                       null,             //name
//                       license,          //license
//                       shortDescription, //shortDescription
//                       longDescription,  //longDescription
//                       useIndex,         //useIndex
//                       status,           //status
//                       aliasURL,         //aliasURL
//                       null,             //proposedBy
//                       null              //approvedBy
//                       );
//     }
   
//     /**
//      * Updates an existing project or adds a new project to the database 
//      * (depending on whether given a <code>projectID</code> or not).
//      *
//      * Note: This method only changes the database. It does not
//      * run scripts.
//      *
//      * @@param projectID         The database key of the project to update 
//      *                            (or null, in which case a new project is 
//      *                            created).
//      * @@param profile           Profile of a new project (immutable).
//      * @@param domainID          ID of domain in which the project resides.
//      * @@param name              Name of the project.
//      * @@param license           License of the project.
//      * @@param shortDescription  A short description of the project.
//      * @@param longDescription   A longer description of the project.
//      * @@param useIndex          Whether to use the index file contents for the
//      *                          long description.
//      * @@param status            Status of the project.
//      * @@param aliasURL          Project URL
//      * @@param proposedBy        ID of user who proposed project.
//      * @@param approvedBy        ID of user who approved project.
//      *
//      * @@return  The system-assigned project ID for the project.
//      *
//      * @@exception SQLException
//      * @@exception DataSetException 
//      */
//     private Record updateProject (String projectID, 
//                                   ProjectProfile profile,
//                                   String domainID,
//                                   String name, 
//                                   String license,
//                                   String shortDescription,
//                                   String longDescription,
//                                   String useIndex,
//                                   String status,
//                                   String aliasURL,
//                                   String proposedBy,
//                                   String approvedBy)
//         throws DoesNotExist, DBException
//     {

//         DBConnection dbConn = null;
//         Record project = null;
//         TableDataSet projects = null;

//         try {
//             dbConn = TurbineDB.getConnection();
//         } catch (Exception e) {
//             throw new DBException(e);
//         }
        
//         if (projectID == null)
//         {
//             action = "Adding Project";
//             projects = new TableDataSet(dbconn.getConnection(), 
//                                         TABLE_NAME, keydef);
//             project = downloads.addRecord();

//         } else {
//             action = "Updating Project";
//             profile = null; //Profile is immutable.
//             project = getProjectForID(projectID);
//         }

//         try {
//             // Do update.
//             if (domainID != null) project.setValue(PROJECT_DOMAIN_ID, 
//                                                    domainID);
            
//             if (name != null) project.setValue(PROJECT_NAME, name);
            
//             if (profile != null) 
//             {
//                 project.setValue(PROJECT_PROFILE, profile.getKey());
//                 project.setValue(PROJECT_TYPE, profile.getType());
//             }
            
//             if (shortDescription != null) 
//                 project.setValue(PROJECT_SHORT_DESCRIPTION, shortDescription);
            
//             if (longDescription != null) 
//                 project.setValue(PROJECT_LONG_DESCRIPTION, longDescription);
            
//             if (useIndex != null)
//                 project.setValue(USE_INDEX, useIndex);
            
//             if (status != null) 
//                 project.setValue(PROJECT_STATUS, status);
            
//             if (aliasURL != null)
//                 project.setValue(PROJECT_ALIAS_URL, aliasURL);

//             if (proposedBy != null)
//                 project.setValue(PROJECT_PROPOSED_BY, proposedBy);

//             if (approvedBy != null)
//                 project.setValue(PROJECT_APPROVED_BY, approvedBy);

//             project.save();

//             if (projectID == null)
//             {
//                 // NOTE: There is no way to refresh a Village Record which has
//                 // been created using TableDataSet.addRecord().
//                 projectID = getLastInsertedID(connection).toString();
//                 project.setValue(PROJECT_ID, projectID);
//             }

//             if (license != null) 
//             { 
//                 project = setLicense(connection, projectID,  license);
//             }
//         } catch (DataSetException e) {
//             throw new DBException(e);
//         } catch (SQLException e) {
//             throw new DBException(e);
//         } finally {
//             registerToClose(projects);
//             try {
//                 TurbineDB.releaseConnection(dbConn);
//             } catch (Exception e) {
//                 throw new DBException(e);
//             }
//         }
        
//         return project;
//     }

//     public Record setLicense (String projectID, String license)
//         throws DoesNotExist, DBException
//     {
//         //Get the project.
//         Record project = getProjectForID(projectID);

//         //Get the old license--see if it's proprietary.
//         String oldLicense = null;
//         try {
//             oldLicense = project.getValue(PROJECT_LICENSE).asString();
//         } catch (DataSetException e) {
//             throw new DBException(e);
//         }
//         if (oldLicense != null && oldLicense.equals(license))
//         {
//             return project;
//         }

//         boolean wasProprietary = Licenses.isProprietary(oldLicense);
//         boolean isProprietary = Licenses.isProprietary(license);
            
//         boolean approved = isApproved(connection, projectID);

//         /**
//          * Approved non-proprietary projects can't go proprietary.
//          */
//         if (approved && isProprietary && !wasProprietary)
//         {
//             return project;
//         }

//         //Set the new license.
//         try {
//             project.setValue(PROJECT_LICENSE, license);
//             project.save();
//         } catch (DataSetException e) {
//             throw new DBException(e);
//         } catch (SQLException e) {
//             throw new DBException(e);
//         }

//         //If we are approved, change appropriate groups.
//         if (approved)
//         {
//             ProjectProjectGroupManager prjGrpMgr = (ProjectProjectGroupManager)
//                 dMgr.getManager
//                 ("org.tigris.helm.database.ProjectProjectGroupManager");
            
//             String domainID = null;
//             try {
//                 domainID = project.getValue(PROJECT_DOMAIN_ID).asString();
//             } catch (DataSetException e) {
//                 throw new DBException(e);
//             }
            
//             Project p = new Project(dMgr, projectID);

//             //If we used not to be proprietary and now we are, remove
//             //this project from the public projects list.
//             if ((!wasProprietary || oldLicense == null) && isProprietary)
//             {
//                 log.info("Removing project from public group.");
//                 ProjectGroup.removeFromPublicGroup(dMgr, p, domainID);
//             }
            
//             //If we used to be proprietary and now we're not, add this project
//             //to the public projects list.
//             if ((wasProprietary || oldLicense == null) && !isProprietary)
//             {
//                 log.info("Adding project to public group.");
//                 ProjectGroup.addToPublicGroup(dMgr, p, domainID);
//             }
//         }

//         return project;
//     }

//     ////////////////////////////////////////////////////////////////
//     // Project deletion
//     ////////////////////////////////////////////////////////////////

//     /**
//      * Deletes an existing project from the database
//      *
//      * @@param      projectID       the ID of the project to delete
//      * @@exception DBException if a database error occurs.
//      */
//     public void  deleteProject (String projectID)
//         throws DBException
//     {
//         Record project = getProjectForID(projectID);
//         if (project != null)
//         {
//             project.markToBeDeleted();
//             project.save();
//         }
//     }

//     ////////////////////////////////////////////////////////////////
//     // Project retrieval
//     ////////////////////////////////////////////////////////////////

//     /**
//      * Gets a project name for a project ID.
//      *
//      * @@param    projectID       The projectID to obtain the name for
//      * @@return     a String
//      * @@exception    DBException if a database error occurs.
//      * @@exception    DoesNotExist if the projectID is invalid.
//      */
//     public String getProjectName (String projectID)
//         throws DBException, DoesNotExist
//     {
//         Record project = getProjectForID(projectID);
//         String name = null;
//         try {
//             name = project.getValue(PROJECT_NAME).asString();
//         } catch (DataSetException e) {
//             throw new DBException(e);
//         }
//         return name;
//     }

//     /**
//      * Retrieves the ID for a project with known name and domain
//      *
//      * @@param    connection    A JDBC database connection
//      * @@param    domainId      Domain in which the project resides
//      * @@param    projectName   The project name to identify
//      * @@return     a String
//      *
//      * @@exception    DBException if a database error occurs.
//      * @@exception    DoesNotExist if the projectID is invalid.
//      */
//     public String getProjectID (String domainID, String name)
//         throws DBException, DoesNotExist
//     {
//         Record project = getProjectForName(domainID, name);
//         String name = null;
//         try {
//             name = project.getValue(PROJECT_NAME).asString();
//         } catch (DataSetException e) {
//             throw new DBException(e);
//         }
//         return name;
//     }
    
//     /**
//      * Given a projectID, find the associated domain name.
//      *
//      * @@param projectID    The projectID whose domain will be found
//      * @@return a String
//      *
//      * @@exception    DBException if a database error occurs.
//      * @@exception    DoesNotExist if the projectID is invalid.
//      */
//         public String getProjectDomain (String projectID)
//         throws DBException, DoesNotExist
//         {
//             String domainName = null;
//         String domainID = null;
//         Record project = getProjectForID(projectID);

//         try {            
//             domainID = project.getValue(PROJECT_DOMAIN_ID).asString();
//         } catch (DataSetException e) {
//             throw new DBException(e);
//         }

//         DomainManager domMgr = (DomainManager)dMgr
//             .getManager("org.tigris.helm.database.DomainManager");
//         domainName = domMgr.getDomainName(domainID);
//         return domainName;
//     }

//     /**
//      * Retrieves a DataSet containing the project specified by ID
//      *
//      * @@param  connection    A JDBC database connection
//      * @@param  domainID      ID of the project to be retrieved
//      * @@return The requested project's record.
//      *
//      * @@exception    DBException if a database error occurs.
//      * @@exception    DoesNotExist if there is no such proejct.
//      */
//     public Record getProjectForID(Connection connection, String projectID)
//             throws DBException, DoesNotExist
//     {
//         Criterion c = new Criterion (PROJECT_ID, domainID);
//         c.and(new Criterion(PROJECT_NAME, name);
//         Record project = getFirstMatchingRecord(c);
//         if (project == null)
//         {
//             throw new DoesNotExist("Project with id " + projectID));
//         }
//         return project;
//     }
    
//     /**
//      * Retrieves a Record containing the project specified by domain and name.
//      *
//      * @@param  domainID      Domain of the project to be retrieved
//      * @@param  name          Name of the project to be retrieved
//      * @@return The requested project's record.
//      * @@exception    DBException if a database error occurs.
//      * @@exception    DoesNotExist if there is no such proejct.
//      */
//     public Record getProjectForName(String domainID, String name)
//         throws DBException, DoesNotExist
//     {
//         Criterion c = new Criterion (PROJECT_DOMAIN_ID, domainID);
//         c.and(new Criterion(PROJECT_NAME, name));
//         Record project = getFirstMatchingRecord(c);
//         if (project == null)
//         {
//             throw new DoesNotExist("Project with name " + name 
//                                    + " in domain " + domainID);
//         }
//         return project;
//     }
    
//     /**
//      * Retrieves a project from alias URL.
//      *
//      * @@param    domainID The ID of the domain (or <code>null</code>).
//      * @@param    aliasURL The project alias URL.
//      * @@return            The project for an alias URL.
//      *
//      * @@exception    DBException if a database error occurs.
//      * @@exception    DoesNotExist if there is no such proejct.
//      */
//     public Record getProjectForAliasURL (String aliasURL)
//             throws DBException, DoesNotExist
//     {
//         Record project = null;
//         if (aliasURL != null && aliasURL.length() > 0)
//         {
//             DataSet projects = getRecords(c);
//             if (projects.size() > 1)
//             {
//                 throw new DBException("Duplicate alias URL: " + aliasURL);
//             } else {
//                 try {
//                     project = projects.getRecord(0);
//                 } catch (DataSetException e) {
//                     throw new DBException(e);
//                 }
//             }
//         }
//         return project;
//     }

     /**
      * Retrieves a List containing all regular projects for a domain.
      *
      * @@param  domainID      The domain for which to get projects.
      * @@return a List
      *
      */
     public List getProjectsForDomain (String domainID)
         throws Exception
     {
         return getProjectsForDomainType(domainID, ProjectType.REGULAR);
     }

     /**
      * Retrieves a List containing all category projects for a domain.
      *
      * @@param  domainID      The domain for which to get categories.
      * @@return a List
      */
     public List getCategoriesForDomain (String domainID)
         throws Exception
     {
         return getProjectsForDomainType(domainID, ProjectType.CATEGORY);
     }

     /**
      * Retrieves a List containing all projects for a domain and
      * a given type.
      *
      * @@param  domainID      The domain for which to get projects.
      * @@param  type          The type of project to get.
      * @@return a List
      */
     public List getProjectsForDomainType (String domainID, String type)
         throws Exception
     {
         Criteria c = new Criteria().add(DOMAIN_ID, domainID).add(TYPE, type);
         return doSelect(c);
     }        

//     /**
//      * Retrieves a DataSet containing unapproved projects for a domain.
//      *
//      * @@param  domainID      The domain for which to get projects.
//      * @@return a DataSet
//      * @@exception    DBException if a database error occurs.
//      */
//     public DataSet getUnapprovedProjectsForDomain (String domainID)
//         throws DBException
//     {
// 	// Get the userID for user "**Nobody"
// 	UserManager uMgr =(UserManager) getDataManager().getManager
//             ("org.tigris.helm.database.UserManager");
// 	String nobodyUserID  = uMgr.getNobodyUserID();
        
// 	// Now look up the unapproved projects (i.e., APPROVED_BY "**Nobody")
//         return getProjectsInDomainApprovedByUser (domainID, nobodyUserID);
//     }        

//     /**
//      * Retrieves a DataSet containing projects approved by a particular
//      * user.
//      *
//      * @@param  domainID      The domain for which to get projects.
//      * @@return a DataSet
//      * @@exception    DBException if a database error occurs.
//      */
//     public DataSet getProjectsInDomainApprovedByUser 
//         (String domainID, String userID)
//         throws DBException
//     {        
//         Criterion c = new Criterion(PROJECT_DOMAIN_ID, domainID);
//         c.add(new Criterion(PROJECT_APPROVED_BY, userID));
//         return getRecords(c);
//     }

    
//     /**
//      * Returns the first record matching a given Criterion. 
//      *
//      * @@param criterion Criterion to use in select.
//      *
//      * @@exception DBException if a database error occurs.
//      *
//      * @@return Null if no matching record, first record in recordset
//      * otherwise.  
//      */
//     private Record getFirstMatchingRecord(Criterion criterion)
//         throws DBException
//     {
//         Record r = null;
//         try {
//             DataSet s = getRecords(criterion);
//             if (s != null && s.containsRecord(0))
//             {
//                 r = s.getRecord(0);
//             }
//         } catch (DataSetException e) {
//             throw new DBException(e);
//         }

//         return r;
//     }

//     /**
//      * Returns records matching a given Criterion.
//      *
//      * @@param criterion Criterion to use in select.
//      *
//      * @@exception DBException if a database error occurs.
//      */
//     public DataSet getRecords(Criterion criterion)
//     throws DBException
//     {
//         DataSet s = null;
//         try {
//             s = runSelect(tableName, criterion, PROJECT_NAME);
//         } catch (Exception e) {
//             throw new DBException(e);
//         }
//         return s;
//     }

//     /**
//      * Retrieves a DataSet containing all projects belonging to a
//      * given category.
//      *
//      * @@param  categoryID    The ID of the category to filter.
//      * @@return a DataSet
//      * @@exception    DBException if a database error occurs.
//      */
//     public DataSet getProjectsForCategory (String categoryID)
//         throws DBException
//     {
//         String action = "Getting Projects for Domain Category: ";
//         QueryDataSet projects = null;

//         ProjectProjectGroupManager prjGrpMgr = (ProjectProjectGroupManager)
//             dMgr.getManager("org.tigris.helm.database.ProjectProjectGroupManager");

//         try
//         {
//             String otherTable = prjGrpMgr.TABLE_NAME;
//             String otherProjectID = otherTable + "." + prjGrpMgr.joinBaseField;
//             String otherCategoryID = otherTable + "." + prjGrpMgr.joinCompositeField;
//             String projectID = TABLE_NAME + "." + PROJECT_ID;

//             StringBuffer q = new StringBuffer();
//             q.append("select ").append(TABLE_NAME).append(".* from ")
//                 .append(TABLE_NAME).append(", ").append(otherTable);
//             q.append(" where ").append(projectID)
//                 .append("=").append(otherProjectID);
//             q.append(" and ").append(otherCategoryID)
//                 .append("=").append(categoryID);

//             projects = new QueryDataSet(connection, q.toString());

//             projects.fetchRecords();
            
//         } catch (DataSetException e) {
//             throw new DBException(e);
//         } catch (SQLException e) {
//             throw new DBException(e);
//         } finally {
//             registerToClose(projects);
//         }
//         return projects;        
//     }        

//     /**
//      * Retrieves a DataSet containing all categories in which a
//      * given project resides.
//      *
//      * @@param  projectID    The ID of the project for which to 
//      *                       obtain categories.
//      * @@exception    DBException if a database error occurs.
//      * @@return a DataSet
//      */
//     public DataSet getCategoriesForProject (String projectID)
//         throws DBException
//     {
//         String action = "Getting Categories for Project: ";
//         QueryDataSet categories = null;
        
//         ProjectProjectGroupManager prjGrpMgr = (ProjectProjectGroupManager)
//             dMgr.getManager("org.tigris.helm.database.ProjectProjectGroupManager");

// 	PreparedStatement stmt = null;        
//         try
//         {
//             String groupTable = prjGrpMgr.TABLE_NAME;
//             String groupProjectIDField = groupTable + "." + 
//                 prjGrpMgr.joinBaseField;
//             String groupCategoryIDField = groupTable + "." + 
//                 prjGrpMgr.joinCompositeField;
//             String projectIDField = TABLE_NAME + "." + 
//                 PROJECT_ID;
//             String projectTypeField = TABLE_NAME + "." + 
//                 PROJECT_TYPE;

//             StringBuffer q = new StringBuffer();
//             q.append("select ").append(TABLE_NAME).append(".* from ")
//                 .append(TABLE_NAME).append(", ").append(groupTable);
//             q.append(" where ").append(projectTypeField).append("='")
//                 .append(ProjectType.CATEGORY).append("'");
//             q.append(" and ").append(groupProjectIDField).append("=")
//                 .append(projectID);
//             q.append(" and ").append(projectIDField).append("=")
//                 .append(groupCategoryIDField);

//             categories = new QueryDataSet(connection, q.toString());

//             categories.fetchRecords();
            
//         } catch (DataSetException e) {
//             throw new DBException(e);
//         } catch (SQLException e) {
//             throw new DBException(e);
//         } finally {
//             registerToClose(categories);
//         }
//         return categories;        
//     }                   //


}
@


1.1.2.2
log
@Made use of getFirstBO() overload which takes a Domain as there
"where" parameter.
@
text
@d175 2
a176 1
        return (Project)PeerTool.getFirstBO(p, "Project named " + name, domain);
@


1.1.2.3
log
@* Removed redundant constants also supplied by ProjectType interface.
* Made use of Project's implementation of the ProjectType interface.
@
text
@d93 20
d120 1
a120 1
        Criteria c = new Criteria().add(TYPE, Project.HOST_TYPE);
d394 1
a394 1
//                 project.setValue(Project.PROJECT_TYPE, profile.getType());
d710 1
a710 1
         return getProjectsForDomainType(domainID, Project.REGULAR_TYPE);
d722 1
a722 1
         return getProjectsForDomainType(domainID, Project.CATEGORY_TYPE);
d898 1
a898 1
//                 Project.PROJECT_TYPE;
d904 1
a904 1
//                 .append(Project.CATEGORY_TYPE).append("'");
d923 2
@


1.1.2.4
log
@Ported ProjectGroup, among other stuff.
@
text
@a53 1
import org.tigris.helm.AlreadyExists;
a55 1
import org.tigris.helm.om.ProjectGroup;
d97 1
a97 1
    public static ProjectGroup getHostProject()
d101 1
a101 1
        ProjectGroup p = null;
d103 1
a103 1
            p = ((Project)PeerTool.getFirstBO(ProjectPeer.doSelect(c), "")).asGroup();
d110 1
a110 1
    public static ProjectGroup getDomainProject(Domain domain)
d113 1
a113 1
        ProjectGroup p = null;
d115 1
a115 1
            p = getGroupInstanceByName(domain, DOMAIN_PROJECT_NAME);
d124 1
a124 1
    public static ProjectGroup getPublicDomainProject(Domain domain)
d127 1
a127 1
        ProjectGroup p = null;
d129 1
a129 1
            p = getGroupInstanceByName(domain, DOMAIN_PROJECT_NAME);
d158 13
a170 34
    //
    // Ways of retrieving ProjectGroup objects.
    //
    public static ProjectGroup getGroupInstance(String projectID)
        throws Exception
    {
        return ProjectPeer.retrieveByPK(Integer.parseInt(projectID)).asGroup();
    }

    public static ProjectGroup getGroupInstanceByName(Domain domain, String name)
        throws Exception
    {
        return getInstanceByName(domain, name).asGroup();
    }

    //
    // Utility methods.
    //

     /**
      * Throws an exception if a project with the given name exists
      * in the given domain.
      */
     public static void assertProjectNonexistance(Domain domain, String name)
         throws AlreadyExists, Exception
     {
         try {
             Project ignore = getInstanceByName(domain, name);
         } catch (DoesNotExist good) {
             return;
         }
         throw new AlreadyExists("A project called " + name + " in " 
                                 + domain.getName());
     }
@


1.1.2.5
log
@Changed from Exception to Error for critical problems.
@
text
@d106 2
a107 3
        }
        catch (DoesNotExist e) {
            throw new Error("Could not locate host project!");
d118 4
a121 4
        }
        catch (DoesNotExist e) {
            throw new Error("Could not locate special project group for " + 
                            domain.getName() + ": " + e.getMessage());
d132 3
a134 3
        }
        catch (DoesNotExist e) {
            throw new Error("Could not locate special public project group for " +
@


1.1.2.6
log
@Moved factory methods back into Project.  By decree of Leonard,
Daniel, and John, factory methods shalt dwell in thy business objects!
@
text
@d103 1
d105 1
a105 3
            Project host =
                (Project)PeerTool.getFirstBO(ProjectPeer.doSelect(c), "");
            return host.asGroup();
d110 1
d122 1
a122 1
                            domain.getName());
d135 2
a136 3
            throw new Error
                ("Could not locate special public project group for " +
                 domain.getName());
d142 20
d170 1
a170 2
    public static ProjectGroup getGroupInstanceByName(Domain domain,
                                                      String name)
d173 1
a173 1
        return Project.getInstanceByName(domain, name).asGroup();
d188 1
a188 1
             Project ignore = Project.getInstanceByName(domain, name);
d192 2
a193 2
         throw new AlreadyExists("A project called " + name,
                                 "domain named " + domain.getName());
@


1.1.2.7
log
@Moved Project factory methods back into ProjectPeer.  Ping pong.
@
text
@a142 20
    // Ways of retrieving Project objects.
    //

    public static Project getInstance(String projectID)
        throws Exception
    {
        return ProjectPeer.retrieveByPK(Integer.parseInt(projectID));
    }

    public static Project getInstanceByName(Domain domain, String name)
        throws DoesNotExist, Exception
    {
        Criteria c = new Criteria()
            .add(NAME,name)
            .add(DOMAIN_ID, domain.getID());
        List p = ProjectPeer.doSelect(c);
        return (Project)PeerTool.getFirstBO(p, "Project named " + name, domain);
    }

    //
d155 1
a155 1
        return ProjectPeer.getInstanceByName(domain, name).asGroup();
d170 2
a171 3
             Project ignore = ProjectPeer.getInstanceByName(domain, name);
         }
         catch (DoesNotExist good) {
@


1.1.2.8
log
@In superclass.
@
text
@d168 1
a168 1
        return retrieveByPK(Integer.parseInt(projectID)).asGroup();
d175 1
a175 1
        return getInstanceByName(domain, name).asGroup();
@


1.1.2.9
log
@Added default project name constant.
@
text
@a94 5
    /**
     * The default project name.
     */
    public static final String DEFAULT_PROJECT_NAME = "www";

@


1.1.2.10
log
@Added getInstanceByAliasURL() factory method.
@
text
@d161 1
a161 1
            .add(NAME, name)
a164 11
    }

    public static Project getInstanceByAliasURL(Domain domain, String aliasURL)
        throws DoesNotExist, Exception
    {
        Criteria c = new Criteria()
            .add(ALIAS_URL, aliasURL)
            .add(DOMAIN_ID, domain.getID());
        List p = ProjectPeer.doSelect(c);
        return (Project)PeerTool.getFirstBO(p, "Project with alias URL " +
                                            aliasURL, domain);
@


1.1.2.11
log
@Big patch to make access control work.
@
text
@a51 1
import org.apache.turbine.util.Log;
a108 1
            Log.debug("Doing select.");
a110 1
            Log.debug("Got host, turning it into group.");
a150 6
    public static List doGroupSelect( Criteria criteria ) throws Exception
    {
        criteria.setDbName(getMapBuilder().getDatabaseMap().getName());
        return doSelect (criteria,"org.tigris.helm.om.ProjectGroup", null);
    }

d164 1
a164 1
        return (Project)PeerTool.getFirstBO(p, "Project named " + name + " in " + domain);
d184 1
a184 3
        Criteria c = new Criteria().add(PROJECT_ID, projectID);
        List p = doGroupSelect(c);
        return (ProjectGroup)PeerTool.getFirstBO(p, "Project group with ID " + projectID);
d191 1
a191 5
        Criteria c = new Criteria()
            .add(NAME, name)
            .add(DOMAIN_ID, domain.getID());
        List p = doGroupSelect(c);
        return (ProjectGroup)PeerTool.getFirstBO(p, "Project group named " + name + " in " + domain);
@


1.1.2.12
log
@Get the public domain project correctly.
@
text
@d140 1
a140 1
            p = getGroupInstanceByName(domain, DOMAIN_PUBLIC_PROJECT_NAME);
@


1.1.2.13
log
@Debug trace cleanup.
@
text
@d110 1
d113 1
a113 1
            //Log.debug("Got host project, turning it into group.");
@


1.1.2.14
log
@Use getFirstBO(BusinessObject, String, Domain).
@
text
@d172 1
a172 1
        return (Project)PeerTool.getFirstBO(p, "Project named " + name, domain);
d194 1
a194 2
        return (ProjectGroup)PeerTool.getFirstBO
            (p, "Project group with ID " + projectID);
d205 1
a205 2
        return (ProjectGroup)PeerTool.getFirstBO
            (p, "Project group named " + name, domain);
@


1.1.2.15
log
@Return the host project if getDomainProject is called on the host domain.
@
text
@a122 4
        if (domain.isHost())
        {
            return getHostProject();
        }
@


1.1.2.16
log
@Hack--return the host project if the "all public projects" project for the host domain is requested.
@
text
@a140 4
        if (domain.isHost())
        {
            return getHostProject();
        }
@


1.1.2.17
log
@New support for properly filtered paginated lists.
@
text
@a69 1

a99 24


    //
    // Special data structures and methods for paginating lists of projects.
    //     

    public static Map filterableFields = new HashMap();

    /**
     * Gets the first letter of the ordered-by field. With the new
     * thing which gets an object by its field name, this might be movable
     * out of the peer so long as DEFAULT_ORDER_BY is here.
     */
    public static String pageGuide(Object o)
    {
        Project p = (Project)o;
        String relevantString = p.getName();
        return relevantString.substring(0,1).toUpperCase();
    }
    
    /**
     * How objects of this type should be ordered in lists.
     */
    public static final String DEFAULT_ORDER_BY = NAME;
@


1.1.2.18
log
@Added JavaDoc and removed early return from getDomainProject(Domain
domain).
@
text
@a144 3
    /**
     * Get the project group for all projects in the specified domain.
     */
d148 4
d153 2
a154 2
        if (domain.isHost()) {
            p = getHostProject();
d156 3
a158 8
        else {
            try {
                p = getGroupInstanceByName(domain, DOMAIN_PROJECT_NAME);
            }
            catch (DoesNotExist e) {
                throw new Error("Could not locate special project group for " +
                                domain.getName());
            }
@


1.1.2.19
log
@Ported and deprecated a couple of retar--cough--I mean, "helper"
methods.
@
text
@d626 20
a645 33
    /**
     * Gets a project name for a project ID.
     *
     * @@param projectID The database key to obtain the name for.
     * @@return          The project name.
     *
     * @@exception DoesNotExist If the projectID is invalid.
     * @@exception Exception    If a database error occurs.
     *
     * @@deprecated You'd have to be a total retard to need this method.
     */
    public static final String getProjectName(String projectID)
        throws DoesNotExist, Exception
    {
        return getInstance(projectID).getName();
    }

    /**
     * Gets a project ID for a project name.
     *
     * @@param projectID The project name to obtain the name for.
     * @@return          The project ID.
     *
     * @@exception DoesNotExist If the domain or name are invalid.
     * @@exception Exception    If a database error occurs.
     *
     * @@deprecated You'd have to be a total retard to need this method.
     */
    public static final String getProjectID(Domain domain, String name)
        throws DoesNotExist, Exception
    {
        return getInstanceByName(domain, name).getID();
    }
d647 24
@


1.1.2.20
log
@Moved approveProject() to Project class.
@
text
@a59 1
import org.tigris.helm.om.profile.*;
d269 36
a304 36
    //
    // Project addition
    //

    /**
     * Adds a project.
     *
     * @@param domain            Domain in which the project resides.
     * @@param name              Name of the project.
     * @@param license           License of the project.
     * @@param shortDescription  A short description of the project.
     * @@param longDescription   A long description of the project.
     * @@param useIndex          Whether to use the index file contents for the
     *                          long description.
     * @@param aliasURL          URL to use as alias, if any.
     * @@param proposedBy        User who proposed the project.
     * @@param approvedBy        User who approved the project, if any.
     * @@return                  The database record for the project.
     *
     * @@exception AlreadyExists if a project in this domain with this name exists.
     */
    public Project add(Domain domain,
                       ProjectProfile profile,
                       String name, 
                       String license,
                       String shortDescription,
                       String longDescription,
                       String useIndex,
                       String status,
                       String aliasURL,
                       String proposedBy,
                       String approvedBy)
        throws AlreadyExists, Exception
    {        
        Project p = null;
//         assertProjectNonexistance(domain, name);
a306 1
//                               domain,           //domain
d308 1
d319 28
d348 1
a348 8
//         catch (DoesNotExist ignored) {}
        return p;
    }


    //
    // Project manipulation
    //
@


1.1.2.21
log
@Removed project addition code duplicated in the Project class.
@
text
@d274 52
@


1.1.2.22
log
@Removed unneeded methods.
@
text
@d271 4
d277 174
@


1.1.2.23
log
@Added new constants for the default module.
@
text
@a102 11
    /**
     * The descrition of the default project.
     */
    public static final String DEFAULT_PROJECT_DESCRIP =
        "Web publishing module";

    /**
     * How objects of this type should be ordered in lists.
     */
    public static final String DEFAULT_ORDER_BY = NAME;

d122 5
@


1.1.2.24
log
@New Torque-generated classes.
@
text
@d200 1
a200 1
        return doSelect(criteria, "org.tigris.helm.om.ProjectGroup", null);
@


1.1.2.25
log
@Fixing compile errors.
@
text
@d197 6
d237 1
a237 1
        List p = doSelect(c);
d249 1
a249 1
        List p = doSelect(c);
d256 1
a256 1
    // 
@


1.1.2.26
log
@Adding support for project group manipulation servlets.
@
text
@a62 3
import org.tigris.helm.tool.paginate.PeerBackedList;
import org.tigris.helm.security.AccessControlList;

a247 27
    /**
     * Get a list of projects matching a base Criteria and a filter
     * criteria, filtering the list further by removing projects
     * that cannot be viewed by the user whose ACL is passed in.
     */
    public static PeerBackedList getProjects
        (Integer itemsPerPage, Criteria base, Criteria filter, 
         AccessControlList acl)
        throws Exception
    {
        if (base == null) base = new Criteria();

        PeerBackedList l = new PeerBackedList(ProjectPeer.class, 
                                              itemsPerPage, base, filter);
        List toRemove = new ArrayList();
        for (Iterator i = l.iterator(); i.hasNext();)
        {
            Project p = (Project)i.next();
            if (!p.isViewableBy(acl))
            {
                toRemove.add(p);
            }           
        }
        l.removeAll(toRemove);
        return l;
    }

d270 105
a374 3
    ////////////////////////////////////////////////////////////////
    // Project retrieval
    ////////////////////////////////////////////////////////////////
d410 104
d555 183
@


1.1.2.27
log
@The fewer calls to asGroup(), the better.
@
text
@d145 4
a148 3
            ProjectGroup host =
                (ProjectGroup)PeerTool.getFirstBO(ProjectPeer.doSelect(c), "");
            return host;
@


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


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


1.1.2.30
log
@Got rid of now-superfluous page guide method.
@
text
@d124 12
@


