head	1.47;
access;
symbols
	TIGRIS_0_9_2_4:1.42.2.1
	TIGRIS_0_9_2_3:1.42.2.1
	HELM_PEER_PORT_BRANCH:1.46.0.2
	TURBINE_PEER:1.46
	TIGRIS_0_9_2_1:1.46
	TIGRIS_0_9_2:1.42.0.2
	TIGRIS_0_9_0:1.36.0.2
	TIGRIS_0_8_4:1.30.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1
	OLDHELM:1.9.0.2
	TIGRIS_NOV_11_2000:1.9
	TIGRIS_SEP_13_2000:1.7.0.2
	TIGRIS_BASELINE:1.8;
locks; strict;
comment	@# @;


1.47
date	2001.02.21.03.23.57;	author edk;	state dead;
branches;
next	1.46;

1.46
date	2001.01.26.18.29.09;	author edk;	state Exp;
branches
	1.46.2.1;
next	1.45;

1.45
date	2001.01.26.05.24.08;	author edk;	state dead;
branches;
next	1.44;

1.44
date	2001.01.25.02.42.47;	author edk;	state Exp;
branches;
next	1.43;

1.43
date	2001.01.24.20.42.49;	author dlr;	state Exp;
branches;
next	1.42;

1.42
date	2001.01.09.17.15.10;	author leonardr;	state Exp;
branches
	1.42.2.1;
next	1.41;

1.41
date	2001.01.06.01.23.00;	author leonardr;	state Exp;
branches;
next	1.40;

1.40
date	2001.01.05.21.42.39;	author leonardr;	state Exp;
branches;
next	1.39;

1.39
date	2001.01.04.16.56.27;	author leonardr;	state Exp;
branches;
next	1.38;

1.38
date	2001.01.03.00.15.30;	author kmaples;	state Exp;
branches;
next	1.37;

1.37
date	2000.12.23.00.48.19;	author dlr;	state Exp;
branches;
next	1.36;

1.36
date	2000.12.20.20.43.56;	author kmaples;	state Exp;
branches;
next	1.35;

1.35
date	2000.12.16.01.32.41;	author leonardr;	state Exp;
branches;
next	1.34;

1.34
date	2000.12.16.00.13.52;	author leonardr;	state Exp;
branches;
next	1.33;

1.33
date	2000.12.15.22.15.18;	author leonardr;	state Exp;
branches;
next	1.32;

1.32
date	2000.12.15.20.48.53;	author leonardr;	state Exp;
branches;
next	1.31;

1.31
date	2000.12.15.18.58.40;	author leonardr;	state Exp;
branches;
next	1.30;

1.30
date	2000.12.02.02.04.47;	author leonardr;	state Exp;
branches;
next	1.29;

1.29
date	2000.12.02.01.45.41;	author leonardr;	state Exp;
branches;
next	1.28;

1.28
date	2000.12.01.22.06.04;	author leonardr;	state Exp;
branches;
next	1.27;

1.27
date	2000.12.01.19.46.19;	author leonardr;	state Exp;
branches;
next	1.26;

1.26
date	2000.12.01.19.05.21;	author leonardr;	state Exp;
branches;
next	1.25;

1.25
date	2000.12.01.18.46.46;	author edk;	state Exp;
branches;
next	1.24;

1.24
date	2000.12.01.18.01.49;	author edk;	state Exp;
branches;
next	1.23;

1.23
date	2000.12.01.16.25.01;	author edk;	state Exp;
branches;
next	1.22;

1.22
date	2000.12.01.13.21.51;	author edk;	state Exp;
branches;
next	1.21;

1.21
date	2000.11.30.23.56.41;	author leonardr;	state Exp;
branches;
next	1.20;

1.20
date	2000.11.28.23.29.19;	author leonardr;	state Exp;
branches;
next	1.19;

1.19
date	2000.11.17.02.20.19;	author leonardr;	state Exp;
branches;
next	1.18;

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

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

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

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

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

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

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

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

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

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

1.8
date	2000.09.21.19.44.07;	author kmaples;	state Exp;
branches;
next	1.7;

1.7
date	2000.09.20.03.13.17;	author brian;	state Exp;
branches;
next	1.6;

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

1.5
date	2000.08.30.01.00.01;	author leonardr;	state Exp;
branches;
next	1.4;

1.4
date	2000.05.30.23.01.43;	author manoj;	state Exp;
branches;
next	1.3;

1.3
date	2000.02.03.04.21.33;	author jrobbins;	state Exp;
branches;
next	1.2;

1.2
date	2000.01.31.02.41.54;	author jrobbins;	state Exp;
branches;
next	1.1;

1.1
date	2000.01.30.01.59.39;	author jrobbins;	state Exp;
branches
	1.1.1.1;
next	;

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

1.42.2.1
date	2001.01.30.00.36.21;	author leonardr;	state Exp;
branches;
next	;

1.46.2.1
date	2001.01.28.01.02.19;	author dlr;	state dead;
branches;
next	;


desc
@@


1.47
log
@delete stuff from the head which is obsolete in the branch (more changes
are still needed for a clean compile)
@
text
@
/* ================================================================
 * 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.tool;

import java.io.*;
import java.net.*;
import java.sql.*;

import java.util.*;

import org.webmacro.util.Log;

import com.workingdogs.village.*;

import org.joist.util.JoistProperties;
import org.joist.database.*;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.project.Project;
import org.tigris.helm.domain.User;
import org.tigris.helm.domain.Domain;
import org.tigris.helm.business.*;

import org.tigris.helm.database.*;
import org.tigris.helm.security.*;
import org.tigris.helm.tool.TigrisTask;

/**
 * TigrisUpdate provides access for executing the database update methods
 * that propogate database changes to flat files and other non-db
 * configuration.
 *
 * <p>All the methods in this class are static; there should be no need
 * to instantiate a TigrisUpdate object.
 *
 * <p>Access to the program is synchronized, so only one access at a
 * time. Hopefully this will prevent data corruption. 
 */
public class TigrisUpdate 
{

    static public Log log = new Log("TUpdat", "Tigris Update");
    static private boolean debug = true;

    static List queue = Collections.synchronizedList(new LinkedList());

    ////////////////////////////////////////////////////////////////
    // Static initializer   
    ////////////////////////////////////////////////////////////////
    static 
    {
        if (TigrisTaskRunner.numberOfInstances()==0)
        {
            TigrisTaskRunner tr = new TigrisTaskRunner();
            tr.start();
        }
    }
    
    ////////////////////////////////////////////////////////////////
    // Project scripts.
    ////////////////////////////////////////////////////////////////

    /**
     * Add a new project to CVS, Issuezilla, etc.
     */
    public static void addProject(Connection connection,
                                  DataManager dMgr,
                                  String onBehalfOf,
                                  Project project)
	throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        TigrisUpdate.addProject(connection, dMgr, onBehalfOf,
                                project.getDomainName(),
                                project.getName(),
                                project.getID(),
                                project.getBrand(),
                                project.getShortDescription());
    }

    /**
     * Add a new project to CVS, Issuezilla, etc.
     */
    public static void addProject(Connection connection,
                                  DataManager dMgr,
                                  String onBehalfOf,
                                  String domainName, 
                                  String projectName, 
                                  String projectID, 
                                  String brandName,
                                  String description)
    {
	String cmd = "ProjectAdd";
	String[] args = makeProjectArgs(domainName, 
                                        projectName,
                                        projectID,  
                                        brandName,       
                                        description 
                                        );

        addTask(connection, dMgr, onBehalfOf, projectID, cmd, args);
    }

    /**
     * Edit an existing project in place.
     */
    public static void editProject(Connection connection,
                                   DataManager dMgr,
                                   String onBehalfOf,
                                   String domainName, 
                                   String projectName, 
                                   String projectID, 
                                   String brandName,
                                   String description)
    {
	String cmd = "ProjectEdit";
	String[] args = makeProjectArgs(domainName, 
                                        projectName,
                                        projectID,  
                                        brandName,       
                                        description 
                                        );
        addTask(connection, dMgr, onBehalfOf, projectID, cmd, args);
    }

    /**
     * Remove a project from CVS, Issuezilla, etc.
     */
    public static void deleteProject(Connection connection,
                                     DataManager dMgr,
                                     String onBehalfOf,
                                     Project project)
	throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        deleteProject(connection, dMgr, onBehalfOf, 
                      project.getDomainName(),
                      project.getName(),
                      project.getID(),
                      project.getBrand());
    }

    /**
     * Remove a project from CVS, Issuezilla, etc.
     */
    public static void deleteProject(Connection connection,
                                     DataManager dMgr,
                                     String onBehalfOf,
                                     String domainName,
                                     String projectName,
                                     String projectID,
                                     String brandName)
    {
     
        String cmd = "ProjectDelete";
        String[] args = makeProjectArgs(domainName,
                                        projectName,
                                        projectID,
                                        brandName,
                                        null
                                        );
        addTask(connection, dMgr, onBehalfOf, projectID, cmd, args);
    }

    ////////////////////////////////////////////////////////////////
    // Module scripts.
    ////////////////////////////////////////////////////////////////

    /**
     * Add a new module to Issuezilla.
     */
    public static void addModule(Connection connection,
                                 DataManager dMgr,
                                 User onBehalfOf,
                                 Project project,
                                 String moduleName,
                                 String moduleDescription,
                                 String isWeb)
	throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        String oboID=null;
        if (onBehalfOf != null)
        {
            oboID = onBehalfOf.getID();
        }

        TigrisUpdate.addModule(connection, dMgr, oboID,
                               project.getDomainName(),
                               project.getName(),
                               project.getID(), 
                               project.getBrand(),
                               moduleName,
                               moduleDescription,
                               isWeb
                               );
    }

    /**
     * Add a new module to Issuezilla.
     */
    public static void addModule(Connection connection, DataManager dMgr, 
                                 String onBehalfOf,
                                 String domainName, String projectName, 
                                 String projectID, String brandName,
                                 String moduleName, String moduleDescription, 
                                 String isWeb)
    {
	
	String cmd = "ModuleAdd";
	String[] args = makeModuleArgs(domainName,
                                       projectName,
                                       projectID,
                                       brandName,
                                       moduleName,
                                       moduleDescription,
                                       isWeb
                                       );
        addTask(connection, dMgr, onBehalfOf, projectID, cmd, args);
    }

    /**
     * Remove a module from Issuezilla.
     */
    public static void deleteModule(Connection connection,
                                    DataManager dMgr,
                                    String onBehalfOf,
                                    Project project,
                                    String moduleName)
	throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        TigrisUpdate.deleteModule(connection, dMgr, onBehalfOf,
                                  project.getDomainName(),
                                  project.getName(),
                                  project.getID(), 
                                  project.getBrand(),
                                  moduleName
                                  );
    }
    
    /**
     * Remove a module from Issuezilla.
     */
    public static void deleteModule(Connection connection, DataManager dMgr,
                                    String onBehalfOf,
                                    String domainName, String projectName, 
                                    String projectID, String brandName,
                                    String moduleName)
    {	
	String cmd = "ModuleDelete";
	String[] args = makeModuleArgs(domainName,
                                       projectName,
                                       projectID,
                                       brandName,
                                       moduleName,
                                       null,
                                       null
                                       );
        addTask(connection, dMgr, onBehalfOf, projectID, cmd, args);
    }

    ////////////////////////////////////////////////////////////////
    // User scripts
    ////////////////////////////////////////////////////////////////

    /**
     * Add a new user to Issuezilla.
     */
    public static void addMember(Connection connection, DataManager dMgr,
                                 User onBehalfOf, Project project, User user, 
                                 String userRole)
        throws SQLException, DataSetException, JoistDatabaseException
    {        
        ArrayList users = new ArrayList();
        users.add(user);
        addMembers(connection, dMgr, onBehalfOf, project, users, userRole);
    }

    /**
     * Add a new user to Issuezilla.
     */
    public static void addMembers(Connection connection, DataManager dMgr,
                                  User onBehalfOf, Project project, 
                                  ArrayList users, String userRole)
        throws SQLException, DataSetException, JoistDatabaseException
    {	
        String userRealNames = "";
        for (Iterator i = users.iterator(); i.hasNext();)
        {
            User user = (User)i.next();
            userRealNames += user.getName();
            if (i.hasNext())
            {
                userRealNames += ":";
            }
        }

        String userUsernames = "";
        for (Iterator i = users.iterator(); i.hasNext();)
        {
            User user = (User)i.next();
            userUsernames += user.getLoginID();
            if (i.hasNext())
            {
                userUsernames += ":";
            }
        }

        String oboID=null;
        if (onBehalfOf != null)
        {
            oboID = onBehalfOf.getID();
        }

	String cmd = "MemberAdd";
	String[] args = makeUserArgs(project.getDomainName(),
                                     project.getName(),
                                     project.getID(),
                                     project.getBrand(),
                                     userRealNames,
                                     userUsernames,
                                     userRole
                                     );
        addTask(connection, dMgr, oboID, project.getID(), 
                cmd, args);
    }

    /**
     * Disable all Issuezilla accounts for a project.
     */
    public static void disableAllAccounts
        (Connection connection, DataManager dMgr, User onBehalfOf, 
         Project project)
        throws DataSetException, SQLException, JoistDatabaseException
    {
        String oboID=null;
        if (onBehalfOf != null)
        {
            oboID = onBehalfOf.getID();
        }

	String cmd = "MemberDisableAll";
	String[] args = makeProjectArgs(project.getDomainName(),
                                        project.getName(),
                                        project.getID(),
                                        project.getBrand(),
                                        project.getShortDescription()
                                     );
        addTask(connection, dMgr, oboID, project.getID(), 
                cmd, args);
    }    

    /**
     * Remove a user from Issuezilla.
     */
    public static void deleteMember(Connection connection, DataManager dMgr,
                                    User onBehalfOf, Project project, 
                                    User user)
        throws DataSetException, SQLException, JoistDatabaseException
    {
        ArrayList users = new ArrayList();
        users.add(user);
        deleteMembers(connection, dMgr, onBehalfOf, project, users);
    }

    /**
     * Remove a user from Issuezilla.
     */
    public static void deleteMembers(Connection connection, DataManager dMgr,
                                     User onBehalfOf, Project project, 
                                     ArrayList users)
        throws DataSetException, SQLException, JoistDatabaseException
    {	
        String userUsernames = "";
        for (Iterator i = users.iterator(); i.hasNext();)
        {
            User user = (User)i.next();
            userUsernames += user.getLoginID();
            if (i.hasNext())
            {
                userUsernames += ":";
            }
        }

        String oboID=null;
        if (onBehalfOf != null)
        {
            oboID = onBehalfOf.getID();
        }

	String cmd = "MemberDelete";
	String[] args = makeUserArgs(project.getDomainName(), //domainName
                                     project.getName(),       //projectName
                                     project.getID(),         //projectID
                                     project.getBrand(),      //brandName
                                     null,                    //userRealName
                                     userUsernames,           //userUsername
                                     null                     //userRole
                                     );
        addTask(connection, dMgr, oboID, project.getID(), 
                cmd, args);
    }

   /**
    * Remove user from all projects in domain from issuezilla
    */
    public static void deleteUser(Connection connection, DataManager dMgr,
                                    User onBehalfOf, Domain domain,
                                    User user)
        throws DataSetException, SQLException, JoistDatabaseException
    {
        // Get a special project from the domain representing 
        // 'all projects in domain', and run MemberDelete script
        // against that project a final time when deleting the 
        // user alltogether:

        Project domainProject = domain.getSpecialProject();
        deleteMember(connection, dMgr, onBehalfOf, domainProject, user);
    }


    ////////////////////////////////////////////////////////////////
    // Argument builders.
    ////////////////////////////////////////////////////////////////

    /**
     * Convenience function to take only the arguments neccessary
     * for scripts that deal with projects.
     */
    public static String[] makeProjectArgs(String domainName, 
                                           String projectName, 
                                           String projectID, 
                                           String brandName,
                                           String projectDescription)
    {
        return makeArgs(domainName,
                        projectName,
                        projectID,
                        brandName,
                        projectDescription,
                        null,        //moduleName
                        null,        //moduleDescription
                        null,        //isWeb
                        null,        //userRealName
                        null,        //userUsername
                        null         //userRole
                        );
    }

    /**
     * Convenience function to take only the arguments neccessary
     * for scripts that deal with modules.
     */
    public static String[] makeModuleArgs(String domainName, 
                                          String projectName, 
                                          String projectID, 
                                          String brandName,
                                          String moduleName,
                                          String moduleDescription,
                                          String moduleIsWeb)
    {
        return makeArgs(domainName,        //domainName
                        projectName,       //projectName
                        projectID,         //projectID
                        brandName,         //brandName
                        null,              //projectDescription
                        moduleName,        //moduleName
                        moduleDescription, //moduleDescription
                        moduleIsWeb,       //isWeb
                        null,              //userRealName
                        null,              //userUsername
                        null               //userRole
                        );
    }

    /**
     * Convenience function to take only the arguments neccessary
     * for scripts that deal with users.
     */
    public static String[] makeUserArgs(String domainName, 
                                        String projectName, 
                                        String projectID, 
                                        String brandName,
                                        String userRealName,
                                        String userUsername,
                                        String userRole)
    {
        return makeArgs(domainName,   //domainName
                        projectName,  //projectName
                        projectID,    //projectID
                        brandName,    //brandName
                        null,         //projectDescription
                        null,         //moduleName
                        null,         //moduleDescription
                        null,         //isWeb
                        userRealName, //userRealName
                        userUsername, //userUsername
                        userRole      //userRole
                        );
    }

    /**
     * Takes a script name and a bunch of arguments and makes a String
     * array.  
     */
    private static String[] makeArgs(String domainName, 
                                     String projectName, 
                                     String projectID, 
                                     String brandName,
                                     String projectDescription, 
                                     String moduleName, 
                                     String moduleDescription,
                                     String isWeb, 
                                     String userRealName,
                                     String userName,
                                     String userRole)
    {
        String[] args =
        { 
            // Now with minty-fresh posix-style named arguments:  
            domainName==null?"":"--domain_name="+domainName,
            projectName==null?"":"--project_name="+projectName, 
            projectID==null?"":"--project_id="+projectID,
            brandName==null?"":"--brand_name="+brandName,
            projectDescription==null?"":"--description="+projectDescription, 
            moduleName==null?"":"--module_name="+moduleName,  
            moduleDescription==null?"":"--module_description="+moduleDescription, 
            isWeb==null?"":"--is_web="+isWeb,
            userRealName==null?"":"--issues_realname="+userRealName,
            userName==null?"":"--issues_username="+userName,
            userRole==null?"":"--issues_role="+userRole
        };
        return args;
    }

    ///////////////////////////////////////////////////////////////////
    // Task manager.
    ///////////////////////////////////////////////////////////////////

    private static TigrisTask addTask
        (Connection conn, DataManager dMgr, String onBehalfOf, 
         String affectedObjectID, String command, String[] arguments)
    {
        ArrayList args = new ArrayList();
        for (int i=0; i < arguments.length; i++)
        {
            args.add(arguments[i]);
        }
        
        TigrisTask t = null;
        try 
        {
            t = new HelmTigrisTask(conn, dMgr, onBehalfOf,
                                   affectedObjectID, 
                                   command, args);
        //TODO: This is bad. Email should be sent if this fails.
        } catch (DataSetException e) {
            log.exception(e);
        } catch (SQLException e ) {
            log.exception(e);
        } catch (Exception e) {
            log.exception(e);
        }
        return t;
    }
}
@


1.46
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@@


1.46.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@@


1.45
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@d112 2
a113 1
    public static void addProject(DataManager dMgr,
d116 2
a117 1
	throws DoesNotExist, DBException
d119 1
a119 1
        TigrisUpdate.addProject(dMgr, onBehalfOf,
d130 2
a131 1
    public static void addProject(DataManager dMgr,
d147 1
a147 1
        addTask(dMgr, onBehalfOf, projectID, cmd, args);
d153 2
a154 1
    public static void editProject(DataManager dMgr,
d169 1
a169 1
        addTask(dMgr, onBehalfOf, projectID, cmd, args);
d175 2
a176 1
    public static void deleteProject(DataManager dMgr,
d179 2
a180 1
	throws DoesNotExist, DBException
d182 1
a182 1
        deleteProject(dMgr, onBehalfOf, 
d192 2
a193 1
    public static void deleteProject(DataManager dMgr,
d208 1
a208 1
        addTask(dMgr, onBehalfOf, projectID, cmd, args);
d218 2
a219 1
    public static void addModule(DataManager dMgr,
d225 2
a226 1
	throws DoesNotExist, DBException
d234 1
a234 1
        TigrisUpdate.addModule(dMgr, oboID,
d248 1
a248 1
    public static void addModule(DataManager dMgr, 
d265 1
a265 1
        addTask(dMgr, onBehalfOf, projectID, cmd, args);
d271 2
a272 1
    public static void deleteModule(DataManager dMgr,
d276 2
a277 1
	throws DoesNotExist, DBException
d279 1
a279 1
        TigrisUpdate.deleteModule(dMgr, onBehalfOf,
d291 1
a291 1
    public static void deleteModule(DataManager dMgr,
d306 1
a306 1
        addTask(dMgr, onBehalfOf, projectID, cmd, args);
d316 1
a316 1
    public static void addMember(DataManager dMgr,
d319 1
a319 1
        throws DBException
d323 1
a323 1
        addMembers(dMgr, onBehalfOf, project, users, userRole);
d329 1
a329 1
    public static void addMembers(DataManager dMgr,
d332 1
a332 1
        throws DBException
d371 1
a371 1
        addTask(dMgr, oboID, project.getID(), 
d379 3
a381 2
        (DataManager dMgr, User onBehalfOf, Project project)
        throws DBException
d396 1
a396 1
        addTask(dMgr, oboID, project.getID(), 
d403 1
a403 1
    public static void deleteMember(DataManager dMgr,
d406 1
a406 1
        throws DBException
d410 1
a410 1
        deleteMembers(dMgr, onBehalfOf, project, users);
d416 1
a416 1
    public static void deleteMembers(DataManager dMgr,
d419 1
a419 1
        throws DBException
d447 2
a448 1
        addTask(dMgr, oboID, project.getID(), cmd, args);
d454 4
a457 4
    public static void deleteUser(DataManager dMgr,
                                  User onBehalfOf, Domain domain,
                                  User user)
        throws DBException
d465 1
a465 1
        deleteMember(dMgr, onBehalfOf, domainProject, user);
d588 1
a588 1
        (DataManager dMgr, String onBehalfOf, 
d600 1
a600 1
            t = new HelmTigrisTask(dMgr, onBehalfOf,
@


1.44
log
@more changes to match the new pattern
@
text
@@


1.43
log
@Making use of DBException.
@
text
@d112 1
a112 2
    public static void addProject(Connection connection,
                                  DataManager dMgr,
d117 1
a117 1
        TigrisUpdate.addProject(connection, dMgr, onBehalfOf,
d128 1
a128 2
    public static void addProject(Connection connection,
                                  DataManager dMgr,
d144 1
a144 1
        addTask(connection, dMgr, onBehalfOf, projectID, cmd, args);
d150 1
a150 2
    public static void editProject(Connection connection,
                                   DataManager dMgr,
d165 1
a165 1
        addTask(connection, dMgr, onBehalfOf, projectID, cmd, args);
d171 1
a171 2
    public static void deleteProject(Connection connection,
                                     DataManager dMgr,
d176 1
a176 1
        deleteProject(connection, dMgr, onBehalfOf, 
d186 1
a186 2
    public static void deleteProject(Connection connection,
                                     DataManager dMgr,
d201 1
a201 1
        addTask(connection, dMgr, onBehalfOf, projectID, cmd, args);
d211 1
a211 2
    public static void addModule(Connection connection,
                                 DataManager dMgr,
d225 1
a225 1
        TigrisUpdate.addModule(connection, dMgr, oboID,
d239 1
a239 1
    public static void addModule(Connection connection, DataManager dMgr, 
d256 1
a256 1
        addTask(connection, dMgr, onBehalfOf, projectID, cmd, args);
d262 1
a262 2
    public static void deleteModule(Connection connection,
                                    DataManager dMgr,
d268 1
a268 1
        TigrisUpdate.deleteModule(connection, dMgr, onBehalfOf,
d280 1
a280 1
    public static void deleteModule(Connection connection, DataManager dMgr,
d295 1
a295 1
        addTask(connection, dMgr, onBehalfOf, projectID, cmd, args);
d305 1
a305 1
    public static void addMember(Connection connection, DataManager dMgr,
d312 1
a312 1
        addMembers(connection, dMgr, onBehalfOf, project, users, userRole);
d318 1
a318 1
    public static void addMembers(Connection connection, DataManager dMgr,
d360 1
a360 1
        addTask(connection, dMgr, oboID, project.getID(), 
d368 1
a368 2
        (Connection connection, DataManager dMgr, User onBehalfOf, 
         Project project)
d384 1
a384 1
        addTask(connection, dMgr, oboID, project.getID(), 
d391 1
a391 1
    public static void deleteMember(Connection connection, DataManager dMgr,
d398 1
a398 1
        deleteMembers(connection, dMgr, onBehalfOf, project, users);
d404 1
a404 1
    public static void deleteMembers(Connection connection, DataManager dMgr,
d435 1
a435 1
        addTask(connection, dMgr, oboID, project.getID(), cmd, args);
d441 3
a443 3
    public static void deleteUser(Connection connection, DataManager dMgr,
                                    User onBehalfOf, Domain domain,
                                    User user)
d452 1
a452 1
        deleteMember(connection, dMgr, onBehalfOf, domainProject, user);
d575 1
a575 1
        (Connection conn, DataManager dMgr, String onBehalfOf, 
d587 1
a587 1
            t = new HelmTigrisTask(conn, dMgr, onBehalfOf,
@


1.42
log
@New servlet and support for same: IssueTrackingRebuild
@
text
@d116 1
a116 2
	throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
d178 1
a178 2
	throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
d223 1
a223 2
	throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
d273 1
a273 2
	throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
d315 1
a315 1
        throws SQLException, DataSetException, JoistDatabaseException
d328 1
a328 1
        throws SQLException, DataSetException, JoistDatabaseException
d377 1
a377 1
        throws DataSetException, SQLException, JoistDatabaseException
d402 1
a402 1
        throws DataSetException, SQLException, JoistDatabaseException
d415 1
a415 1
        throws DataSetException, SQLException, JoistDatabaseException
d443 1
a443 2
        addTask(connection, dMgr, oboID, project.getID(), 
                cmd, args);
d452 1
a452 1
        throws DataSetException, SQLException, JoistDatabaseException
@


1.42.2.1
log
@Porting changes from HEAD into branch.
@
text
@a599 1
            log.info("Adding task: " + command + "/" + affectedObjectID);
@


1.41
log
@You can now stop and restart the TigrisTaskRunner thread from the StaticUtils servlet.
@
text
@d376 25
d568 11
a578 11
            domainName==null?null:"--domain_name="+domainName,
            projectName==null?null:"--project_name="+projectName, 
            projectID==null?null:"--project_id="+projectID,
            brandName==null?null:"--brand_name="+brandName,
            projectDescription==null?null:"--description="+projectDescription, 
            moduleName==null?null:"--module_name="+moduleName,  
            moduleDescription==null?null:"--module_description="+moduleDescription, 
            isWeb==null?null:"--is_web="+isWeb,
            userRealName==null?null:"--issues_realname="+userRealName,
            userName==null?null:"--issues_username="+userName,
            userRole==null?null:"--issues_role="+userRole
@


1.40
log
@Big patch bringing the smart script runner online.
@
text
@d1 1
a92 2
    static TigrisTaskRunner tr = new TigrisTaskRunner();

d98 5
a102 2
        log.info("!!!!!!!!!!----------Starting thread.--------------!!!!!!!!!!");
        tr.start();
@


1.39
log
@Moved functionality out of TigrisUpdate into new classes.
@
text
@d541 11
a551 11
            "--domain_name="        + domainName,
            "--project_name="       + projectName, 
            "--project_id="         + projectID,
            "--brand_name="         + brandName,
            "--description="        + projectDescription, 
            "--module_name="        + moduleName,  
            "--module_description=" + moduleDescription, 
            "--is_web="             + isWeb,
            "--issues_realname="    + userRealName,
            "--issues_username="    + userName,
            "--issues_role="        + userRole
a585 272

    //////////////////////////////////////////////////////////////////
    // Issuezilla synchronization.
    //////////////////////////////////////////////////////////////////

    /**
     * Reflects the effects of a grant on a projectID to a userID.
     */
    public static void reflectGrant(Connection connection, DataManager dMgr,
                                    String onBehalfOf,
                                    String userID,
                                    String projectID)
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        ArrayList affectedUsers = TigrisUpdate
            .expandUser(dMgr, connection, userID);
        ArrayList affectedProjects = TigrisUpdate
            .expandProject(dMgr, connection, projectID);
        User user = null;
        if (onBehalfOf != null)
        {
            user = User.getInstance(connection, dMgr, onBehalfOf);
        }
        TigrisUpdate.findNewMembers(connection, dMgr, user,
                                    affectedUsers, affectedProjects);
    }

    /**
     * Runs addMember on users who have permissions in the given
     * projects.
     */
    public static void findNewMembers(Connection connection, DataManager dMgr,
                                      User onBehalfOf, ArrayList affectedUsers,
                                      ArrayList affectedProjects)
        throws DataSetException, SQLException, JoistDatabaseException
    {        
        if (debug) log.info(" FindNewMembers.");
        //For each project...
        for (Iterator j = affectedProjects.iterator(); j.hasNext();)
        {
            //We're going to build two lists of users: one of users with
            //regular access and one of users with admin access.
            
            //Get the project information.
            Project project = (Project)j.next();
            
            if (debug) log.info("Processing project " + project.getName());
            ArrayList adminUsers = new ArrayList();
            ArrayList developerUsers = new ArrayList();
            ArrayList observerUsers = new ArrayList();            

            //For each user...
            for (Iterator i = affectedUsers.iterator(); i.hasNext();)
            {
                //Get their ACL and user information.
                User user = (User)i.next();
                AccessControlList currentACL = user.getACL();
                if (debug) log.info(" Processing user " + user.getLoginID());
                
                //Figure out which role they have on the issue tracker
                //for this project, and put them in the appropriate list.
                String pID = project.getID();
                String pName = project.getName();
                String lID = user.getLoginID();
                if (currentACL.hasPermissionForProject
                    ("Project Issue Tracking - Configure", project.getID()))
                {
                    if (debug) log.info(" " + lID + " is an administrator of "
                                        + pName);
                    adminUsers.add(user);
                    
                } else if (currentACL.hasPermissionForProject
                           ("Project Issue Tracking - Change", 
                            project.getID())) {
                    if (debug) log.info(" " + lID + " is a developer on " 
                                        + pName); 
                    developerUsers.add(user);
                } else if (currentACL.hasPermissionForProject
                           ("Project Issue Tracking - Submit", 
                            project.getID())) {
                    if (debug) log.info(" " + lID + " is an observer on " 
                                        + pName); 
                    observerUsers.add(user);
                } else {
                    if (debug) log.info(" " + lID + " has no role in " 
                                        + pName);
                }
            }
            
            if (observerUsers.size() > 0)
            {
                TigrisUpdate.addMembers(connection, dMgr, onBehalfOf, 
                                        project, observerUsers, "observer");
            }

            if (developerUsers.size() > 0)
            {
                TigrisUpdate.addMembers(connection, dMgr, onBehalfOf,
                                        project, developerUsers, "developer");
            }
            
            if (adminUsers.size() > 0)
            {            
                TigrisUpdate.addMembers(connection, dMgr, onBehalfOf,
                                        project, adminUsers, "admin");
            }
        }
    }

    /**
     * Reflects the effects of a revoke on a projectID from a userID.
     */
    public static void reflectRevoke(Connection connection, 
                                     DataManager dMgr,
                                     String onBehalfOf,
                                     String userID,
                                     String projectID)
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        if (debug) log.info(" Reflecting revoke.");
        ArrayList affectedUsers = expandUser(dMgr, connection, userID);
        ArrayList affectedProjects = 
            expandProject(dMgr, connection, projectID);
        User user = null;
        if (onBehalfOf != null)
        {
            user = User.getInstance(connection, dMgr, onBehalfOf);
        }

        TigrisUpdate.findExMembers(connection, dMgr, user, affectedUsers,
                                   affectedProjects);
        //A ham-handed way to find people who had one Issuezilla role
        //before and who have a different one now.
        TigrisUpdate.findNewMembers(connection, dMgr, user, affectedUsers,
                                    affectedProjects);
        if (debug) log.info(" Done reflecting revoke.");
    }


    /**
     * Runs deleteMember for users who don't have permissions in
     * the given projects.
     */
    public static void findExMembers(Connection connection, DataManager dMgr,
                                     User onBehalfOf, ArrayList affectedUsers,
                                     ArrayList affectedProjects)
        throws DataSetException, SQLException, JoistDatabaseException
    {
        if (debug) log.info(" FindExMembers.");
        //For each project...
        for (Iterator j = affectedProjects.iterator(); j.hasNext();)
        {
            //We're going to make a list of users who no longer have any
            //relevant permissions in this project.
            ArrayList deletedUsers = new ArrayList();
            
            Project project = (Project)j.next();
            //For each user...
            for (Iterator i = affectedUsers.iterator(); i.hasNext();)
            {
                User user = (User)i.next();
                AccessControlList currentACL = user.getACL();
                if (debug) log.info("Checking " + user.getLoginID());
                
                //Figure out which role they have on the issue tracker
                //for this project, and put them in the appropriate list.
                if (!(currentACL.hasPermissionForProject
                      ("Project Issue Tracking - Configure", project.getID())
                      || currentACL.hasPermissionForProject
                      ("Project Issue Tracking - Change", project.getID())
                      || currentACL.hasPermissionForProject
                      ("Project Issue Tracking - Submit", project.getID())))
                {
                    if (debug) log.info("Adding " + user.getLoginID());
                    deletedUsers.add(user);
                }
            }
            
            if (deletedUsers.size() > 0)
            {
                TigrisUpdate.deleteMembers(connection, dMgr, onBehalfOf,
                        project, deletedUsers);
            }
        }
        if (debug) log.info("Done deleting members.");
    }

    /**
     * Get the User object for every user corresponding to the
     * given userID.
     */    
    public static ArrayList expandUser(DataManager dMgr,
                                       Connection connection, 
                                       String userID)
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {        
        if (debug) log.info("Expanding user.");
        UserUserGroupManager usrGrpMgr = (UserUserGroupManager) dMgr.getManager
            ("org.tigris.helm.database.UserUserGroupManager");
        DataSet usersForUserID = usrGrpMgr
            .getBasesForComposite(connection, userID);
        
        ArrayList affectedUsers = new ArrayList();     
        if (usersForUserID.size() == 0)
        {
            User user = User.getInstance(connection, dMgr, userID);
            if (debug) log.info("Expand user: " + user.getLoginID() +
                    " is affected.");
            affectedUsers.add(user);
        } else {
            for (int i = 0; i < usersForUserID.size(); i++)
            {
                String effectiveID = 
                    usersForUserID.getRecord(i)
                    .getValue(UserUserGroupManager.USER_ID).asString();
                User user = User.getInstance(connection, dMgr, effectiveID);
                affectedUsers.add(user);
                if (debug) log.info("Expand user: " + user.getLoginID() 
                         + " is affected.");
            }
        }
        return affectedUsers;
    }
    
    /**
     * Get a Project object for every project corresponding to the
     * given projectID.
     */    
    public static ArrayList expandProject(DataManager dMgr,
                                          Connection connection, 
                                          String projectID)
        throws DataSetException, SQLException, JoistDatabaseException,
               DoesNotExist
    {
        if (debug) log.info("Expanding project.");
        ArrayList affectedProjects = new ArrayList();

        ProjectProjectGroupManager prjGrpMgr = (ProjectProjectGroupManager) 
            dMgr.getManager
            ("org.tigris.helm.database.ProjectProjectGroupManager");
        DataSet projectsForProjectID = prjGrpMgr
            .getBasesForComposite(connection, projectID);
        
        ArrayList projectInfo = new ArrayList();
        if (projectsForProjectID.size() == 0)
        {
            Project project = new Project(connection, dMgr, projectID);
            affectedProjects.add(project);
                if (debug) log.info("Expand project: " + project.getName() 
                         + " is affected.");

        } else {
            for (int i = 0; i < projectsForProjectID.size(); i++)
            {
                String pID = 
                    projectsForProjectID.getRecord(i)
                    .getValue(ProjectProjectGroupManager.PROJECT_ID)
                    .asString();
                Project project = new Project(connection, dMgr, pID);
                if (project.isBase())
                {
                    affectedProjects.add(project);
                    if (debug) log.info("Expand project: " + project.getName() 
                             + " is affected.");
                }
            }
        }
        return affectedProjects;
    }    
@


1.38
log
@Worked with Leonard to add call to 'deleteUser()' after deleting user from
specific projects.  This helps to address #1623 - removing users from IZ
when in single-db mode.
@
text
@d17 1
a17 1
 * software developed by CollabNet (http://www.Collab.Net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d857 1
a857 196
    }

    //////////////////////////////////////////////////////////////////////
    // Methods which run the appropriate scripts to bring Issuezilla
    // in sync with the database.
    //////////////////////////////////////////////////////////////////////
    
    public static void mapDump(Map map)
        throws DataSetException
    {
        log.info("Beginning mapDump.");
        for (Iterator i = map.keySet().iterator(); i.hasNext();)
        {
            Project p = (Project)i.next();
            log.info(" Project: " + p.getName());
            Map accts = (Map)map.get(p);
            for (Iterator j = accts.keySet().iterator(); j.hasNext();)
            {
                String acctType = (String)j.next();
                List users = (List)accts.get(acctType);
                if (users.size() > 0)
                {
                    log.info("  Account type: " + acctType);
                    for (Iterator k = users.iterator(); k.hasNext();)
                    {
                        User u = (User)k.next();
                        log.info("   User: " + u.getName());
                    }
                }
            }
        }
    }

    /**
     * Returns a mapping of Issuezilla roles in projects to Users. 
     */
    public static Map getIssueTrackingAccountMap
        (Connection connection, DataManager dMgr, List users, List projects)
        throws DataSetException, SQLException, JoistDatabaseException
    {
        Map m = new HashMap();

        //Build the data structure.
        for (Iterator i = users.iterator(); i.hasNext();)
        {
            User u = (User)i.next();
            for (Iterator j = projects.iterator(); j.hasNext();)
            {
                Project p = (Project)j.next();
                String acct = u.issueTrackingAccountType(p);
                if (!acct.equals(""))
                {
                    Map accountsForProject = (HashMap)m.get(p.getID());
                    if (accountsForProject == null)
                    {
                        accountsForProject = new HashMap();
                    }
                    List accountsOfTypeForProject =
                        (ArrayList)accountsForProject.get(acct);
                    if (accountsOfTypeForProject == null)
                    {
                        accountsOfTypeForProject = new ArrayList();
                    }
                    accountsOfTypeForProject.add(u);
                    accountsForProject.put(acct, accountsOfTypeForProject);
                    m.put(p, accountsForProject);
                }
            }
        }
        return m;
    }


    /**
     * Runs whatever scripts are neccessary to the difference between two Maps
     * obtained by calls to getIssueTrackingRoles.
     */
    public static void syncIssueTrackingAccounts(Map oldAccounts, 
                                                 Map newAccounts)
        throws SQLException, DataSetException
    {
        //For each project, sync that project's issue tracking.
        for (Iterator i = oldAccounts.keySet().iterator(); i.hasNext();)
        {
            Project project = (Project)i.next();
            Map oldAccountsForProject = (Map)oldAccounts.get(project);
            Map newAccountsForProject = (Map)newAccounts.get(project);
            syncIssueTrackingAccountsForProject(oldAccountsForProject,
                                             newAccountsForProject,
                                             project);
        }
    }

    /**
     * Issuezilla Account A -> User I       Issuezilla Account A -> User I
     *                      -> User II      Issuezilla Account B -> User II
     * Issuezilla Account B -> User III                          -> User III 
     * Issuezilla Account C -> User IV     
     */
    private static void syncIssueTrackingAccountsForProject(Map oldAccounts, 
                                                         Map newAccounts,
                                                         Project project)
        throws SQLException, DataSetException
    {
        if (oldAccounts == null) oldAccounts = new HashMap();
        if (newAccounts == null) newAccounts = new HashMap();
        Map scriptsToRun = new HashMap();
        List usersToDelete = new ArrayList();

        //Find people who have an account in oldAccounts and don't have
        //the same account (different type, or no account) in
        //newAccounts.
        for (Iterator i = oldAccounts.keySet().iterator(); i.hasNext();)
        {
            String type = (String)i.next();
            List oldUsersWithAccount = (List)oldAccounts.get(type);
            for (Iterator j = oldUsersWithAccount.iterator(); i.hasNext();)
            {
                User u = (User)i.next();
                String newAcctType = userAccountTypeInProject(u, newAccounts);
                if (newAcctType.equals(""))
                {
                    //They no longer have any account in this project.
                    usersToDelete.add(u);
                } 
            }
        }

        //Find people who have roles in newAccounts and no role in
        //oldAccounts.
        for (Iterator i = newAccounts.keySet().iterator(); i.hasNext();)
        {
            String type = (String)i.next();
            List oldUsersWithAccount = (List)oldAccounts.get(type);
            for (Iterator j = oldUsersWithAccount.iterator(); i.hasNext();)
            {
                User u = (User)i.next();
                String oldAcctType = userAccountTypeInProject(u, oldAccounts);
                if (!oldAcctType.equals(type)) {
                    //They have a different account in this project
                    //than they used to (inc. no previous account).
                    List list = (List)scriptsToRun.get(type);
                    if (list == null) list = new ArrayList();
                    list.add(u);
                    scriptsToRun.put(type, list);
                }
            }
        }

        //Don't run the scripts yet; just print out which scripts would
        //have been run.
        for (Iterator i = scriptsToRun.keySet().iterator(); i.hasNext();)
        {
            String type = (String)i.next();
            log.info("Considering users with role type " + type);
            List list = (List)scriptsToRun.get(type);
            if (list.size() > 0)
            {
                log.info("Running MemberAdd " + project.getName() + " " + type 
                         + " for the following users: ");                     
                for (Iterator j = list.iterator(); j.hasNext();)
                {
                    User u = (User)j.next();
                    log.info(" " + u.getName());
                }
            }
        }

        if (usersToDelete.size() > 0)
        {
            log.info("Running MemberDelete " + project.getName()
                     + " for the following users: ");
            for (Iterator i = usersToDelete.iterator(); i.hasNext();)
            {
                User u = (User)i.next();
                log.info(" " + u.getName());
            }
        }

    }

    public static String userAccountTypeInProject(User user, Map accounts)
    {
        String accountType = "";
        for (Iterator i = accounts.keySet().iterator(); i.hasNext();)
        {
            String type = (String)i.next();
            List usersWithAccountType = (List)accounts.get(type);
            if (usersWithAccountType.contains(user))
            {
                accountType = type;
            }
        }        
        return accountType;
    }
    
@


1.37
log
@Removed unnecessary getCache() implementations in BusinessObject subclasses and migrated to a factory method for User's primary database key ctor.
@
text
@d424 18
@


1.36
log
@I told edk I would, and so I did; the perl project creation scripts now use
posix-style named args.
@
text
@d587 1
a587 1
        User o = null;
d590 1
a590 1
            o = new User(connection, dMgr, onBehalfOf);
d592 1
a592 1
        TigrisUpdate.findNewMembers(connection, dMgr, o,
d693 1
a693 1
        User o = null;
d696 1
a696 1
            o = new User(connection, dMgr, onBehalfOf);
d699 2
a700 1
        TigrisUpdate.findExMembers(connection, dMgr, o, affectedUsers, affectedProjects);
d703 2
a704 1
        TigrisUpdate.findNewMembers(connection, dMgr, o, affectedUsers, affectedProjects);
d776 1
a776 1
            User user = new User(connection, dMgr, userID);
d786 1
a786 1
                User user = new User(connection, dMgr, effectiveID);
@


1.35
log
@Added dump method.
@
text
@d522 12
a533 11
            domainName,
            projectName, 
            projectID,
            brandName,
            projectDescription, 
            moduleName,  
            moduleDescription, 
            isWeb,
            userRealName,
            userName,
            userRole
@


1.34
log
@Method is now more granular.
@
text
@d843 26
d873 1
a873 2
        (Connection connection, DataManager dMgr, ArrayList projects, 
         ArrayList users)
d990 1
d992 1
a992 4
            log.info("Running MemberAdd " + project.getName() + " " + type 
                     + " for the following users: ");
                     
            for (Iterator j = list.iterator(); j.hasNext();)
d994 7
a1000 2
                User u = (User)j.next();
                log.info(" " + u.getName());
d1004 1
a1004 3
        log.info("Running MemberDelete " + project.getName()
                 + " for the following users: ");
        for (Iterator i = usersToDelete.iterator(); i.hasNext();)
d1006 7
a1012 2
            User u = (User)i.next();
            log.info(" " + u.getName());
@


1.33
log
@Fixed exceptions.
@
text
@d838 45
a1000 75
    /**
     * Returns a mapping of Issuezilla roles in projects to Users. 
     */
    public static Map getIssueTrackingAccountMap
        (Connection connection, DataManager dMgr, Domain domain)
        throws DataSetException, SQLException, JoistDatabaseException
    {
        Map m = new HashMap();
        Host host = domain.getHost();
        
        ProjectManager pMgr = (ProjectManager)dMgr.getManager
            ("org.tigris.helm.database.ProjectManager");        

        //Get the list of project IDs in this domain, including those
        //of project groups. Exclude the "all projects in domain"
        //project, which doesn't have issue tracking.
        DataSet projectSet = pMgr.getProjectsForDomainType
            (connection, domain.getID(), null);
        List projects = new ArrayList();
        for (int i = 0; i < projectSet.size(); i++)
        {
            Record project = projectSet.getRecord(i);
            if (!project.getValue(ProjectManager.PROJECT_TYPE).asString()
                .equals(ProjectType.DOMAIN))
            {
                try {
                    projects.add(new Project(connection, dMgr, project));
                } catch (DoesNotExist ignore) {}
            }
        }

        //Get the users who could concievably have roles in this domain's
        //projects. That's the users in this domain and the users in the
        //host domain.
        List domainUsers = domain.getUsers();
        List hostUsers = domain.getHostDomain().getUsers();
        List users = new ArrayList();
        if (domainUsers != null)
        {
            users.addAll(domainUsers);
        }
        if (hostUsers != null)
        {
            users.addAll(hostUsers);
        }

        //Build the data structure.
        for (Iterator i = users.iterator(); i.hasNext();)
        {
            User u = (User)i.next();
            for (Iterator j = projects.iterator(); j.hasNext();)
            {
                Project p = (Project)j.next();
                String acct = u.issueTrackingAccountType(p);
                if (!acct.equals(""))
                {
                    Map accountsForProject = (HashMap)m.get(p.getID());
                    if (accountsForProject == null)
                    {
                        accountsForProject = new HashMap();
                    }
                    List accountsOfTypeForProject =
                        (ArrayList)accountsForProject.get(acct);
                    if (accountsOfTypeForProject == null)
                    {
                        accountsOfTypeForProject = new ArrayList();
                    }
                    accountsOfTypeForProject.add(u);
                    accountsForProject.put(acct, accountsOfTypeForProject);
                    m.put(p, accountsForProject);
                }
            }
        }
        return m;
    }
@


1.32
log
@More code for the eventual reduction of Issuezilla scripts being run.
@
text
@d870 2
d1025 1
a1025 1
                    m.put(p.getID(), accountsForProject);
@


1.31
log
@Wide-ranging patch containing code which will eventually cause fewer MemberAdd and MemberDelete scripts to be run.
@
text
@d843 3
a845 1
    public static void syncIssueTrackingRoles(HashMap oldRoles, HashMap newRoles)
d847 2
a848 3
        Map usersToAdd = new HashMap();
        Map  usersToDelete = new HashMap();
        for (Iterator i = oldRoles.keySet().iterator(); i.hasNext();)
d850 6
a855 1
            Map usersForProject = (Map)i.next();
d860 95
a955 1
     * The data structure is of this form:
d957 1
a957 1
    public static Map getIssueTrackingRoleMap
@


1.30
log
@Minor formatting changes.
@
text
@d66 2
d836 92
@


1.29
log
@Changes to fix horrible mistakes in removing projects from project groups, among other things.
@
text
@d544 1
a544 1
        for (int i=0 ; i < arguments.length; i++)
@


1.28
log
@Set onBehalfOf only if it was provided.
@
text
@d89 1
d97 1
d694 2
a695 1
        } 
@


1.27
log
@Logging cleanup.
@
text
@d582 5
a586 1
        User o = new User(connection, dMgr, onBehalfOf);
d688 5
a692 1
        User o = new User(connection, dMgr, onBehalfOf);
@


1.26
log
@My side of the changes edk made.
@
text
@a623 1
                currentACL.dump();
@


1.25
log
@use AnzuTigrisTask for mailing list additions during project creation
@
text
@d89 1
a89 1
    static HelmTaskRunner tr = new HelmTaskRunner();
d541 2
a542 3
        StringBuffer newargs = new StringBuffer();
        newargs.append(arguments[0]);
        for (int i = 1; i < arguments.length; i++)
d544 1
a544 1
            newargs.append("\n").append(arguments[i]);
d546 1
d550 3
a552 4
            t = new TigrisTask(conn, dMgr, onBehalfOf,
                               TigrisTask.HELM_COMPONENT, 
                               affectedObjectID, 
                               command, newargs.toString());
d558 2
a562 11

    static void runTasks(List tasks)
        throws UpdateException
    {
        for (Iterator i = tasks.iterator(); i.hasNext();)
        {
            TigrisTask t = (TigrisTask)i.next();
            t.runTask();
        }
    }

@


1.24
log
@rename HelmAnzuTask to AnzuTigrisTask; remove an unused function from
TigrisUpdate ; and add functions (thanks to leonardr) for storing
arguments via serialization/deserialization in TigrisTask
@
text
@a320 11
     * Add a mailing list to a project
     */
    public static void addMailingList(Connection connection, DataManager dMgr,
            User onBehalfOf, Project project, String name, String type, 
            String description)
        throws SQLException, DataSetException
    {
    }

    
    /**
@


1.23
log
@steps towards providing for different kinds of tasks.  if this pattern
is used, TigrisTask should probably be broken down into an abstract base
class and a HelmCommandTask (or somesuch) -- but this involves lots
of changes elsewhere.  HelmAnzuTask will be used for anzu mailing
list creation during project creation, though it's not being used
that way yet.
@
text
@a573 18
    private static TigrisTask addAnzuTask
        (Connection conn, DataManager dMgr, String onBehalfOf, 
         String affectedObjectID, String command, String arguments)
    {
        HelmAnzuTask t = null;
        try {
            t = new HelmAnzuTask(conn, dMgr, onBehalfOf,
                    TigrisTask.ANZU_COMPONENT,
                    affectedObjectID,
                    command, arguments);
        } catch (DataSetException e) {
            log.exception(e);
        } catch (SQLException e) {
            log.exception(e);
        }
        return t;
    }

@


1.22
log
@this bug was hidden by the fact that there always happened to be a
project with the same id as the domain -- 2.  an add'l exception
has been added to the throws.
@
text
@a90 3
    //FIXME: Please!
    static final String script_dir = "/helm/perl/scripts/";

d319 11
d573 19
a591 1
    
a596 1
            UpdateException ue = null;
d598 1
a598 37
            String command = null;
            String argblob = null;
            try {
                command = t.getCommand();
                argblob = t.getArguments();
            } catch (Exception e) {
                log.exception(e);
            }

            if (command != null && argblob != null)
            {
                ArrayList args = new ArrayList();
                args.add(command);
                
                StringTokenizer tok = new StringTokenizer(argblob, "\n");
                while (tok.hasMoreTokens())
                {
                    args.add(tok.nextToken());
                }            
                try 
                {
                    runScript(args);
                } catch (UpdateException e) {
                    //TODO: If this happens, reset the timestamp of the script
                    //rather than deleting it.
                    ue = e;
                }
                
                try 
                { 
                    t.setAsDone();
                } catch (Exception e) {
                    log.exception(e);
                }

                if (ue != null) { throw ue; }
            }
a601 65
    ///////////////////////////////////////////////////////////////////
    // Script runner.
    ///////////////////////////////////////////////////////////////////

    /**
     * Run a command with a populated environment.
     * @@param argList command to run (inc. arguments)
     */
    private static synchronized void runScript(ArrayList argList)
	throws UpdateException 
    {
        String args[] = new String[argList.size()];
        for (int i = 0; i < argList.size(); i++)
        {
            args[i] = (String)argList.get(i);
        }

	//Get the sandbox directory and htdoc_root to put in the
	//script's environment.
	String htdoc_root = (String) JoistProperties.getProperty("documentRoot");
	String sandbox = (String) JoistProperties.getProperty("SANDBOX");
	String dbName = (String) JoistProperties.getProperty("databaseName");
	String dbUser = (String) JoistProperties.getProperty("databaseUser");
	String dbPassword = (String) JoistProperties.getProperty("databasePassword");

	String[] env = {"HTDOC_ROOT=" + htdoc_root, 
			"SANDBOX="+sandbox, 
			"DATABASE_NAME=" + dbName,
			"DATABASE_USER=" + dbUser,
			"DATABASE_PASSWORD=" + dbPassword
	};

	Runtime rt = Runtime.getRuntime();
	Process pr;
	int exitCode;

        StringBuffer scriptName = new StringBuffer();
        for (int i = 0; i < args.length; i++)
        {
            if (args[i] == null)
            {
                args[i] = "NULL";
            }
            scriptName.append(args[i]).append(" ");
        }            
        if (debug) log.info("Running " + scriptName.toString());

	try {
	    args[0] = sandbox + script_dir + args[0];
	    pr = rt.exec(args, env);
	} catch (IOException e) {
	    throw new UpdateException("IO error while running script.");
	}
        
	try {
	    exitCode = pr.waitFor();
	} catch (InterruptedException e) {
	    throw new UpdateException("Script was interrupted.");
	}
	if (pr.exitValue() != 0) {
	    throw new UpdateException(scriptName.toString() + "\n\nExit code: "
				      + new Integer(exitCode).toString());
	}

    }
d801 2
a802 1
            if (debug) log.info("Expand user: " + user.getLoginID() + " is affected.");
@


1.21
log
@Mega patch which makes script data persistent and which provides a general framework for tasks to be run (which will be used by anzu eventually)
@
text
@d316 1
a316 1
        throws SQLException, DataSetException
d329 1
a329 1
        throws SQLException, DataSetException
d378 1
a378 1
        throws DataSetException, SQLException
d391 1
a391 1
        throws DataSetException, SQLException
d850 2
a851 1
                TigrisUpdate.deleteMembers(connection, dMgr, onBehalfOf, project, deletedUsers);
@


1.20
log
@Added another level of Issuezilla permissions
@
text
@d69 1
d89 1
a89 1
    static QueueHandler qh = new QueueHandler();
d99 1
a99 1
        qh.start();
d109 4
a112 3
    public static void addProject(DataManager dMgr,
                                  Connection connection,
                                  String projectID)
d116 2
a117 2
        Project project = new Project(connection, dMgr, projectID);
        TigrisUpdate.addProject(project.getDomainName(),
d127 4
a130 1
    public static void addProject(String domainName, 
d137 1
a137 2
	String[] args = makeProjectArgs(cmd,
                                        domainName, 
d144 1
a144 1
	enqueue(args);
d150 8
a157 5
    public static void editProject(String domainName, 
                                  String projectName, 
                                  String projectID, 
                                  String brandName,
                                  String description)
d160 1
a160 2
	String[] args = makeProjectArgs(cmd,
                                        domainName, 
d166 2
d169 15
a183 1
	enqueue(args);
d189 4
a192 1
    public static void deleteProject(String domainName,
d199 1
a199 2
        String[] args = makeProjectArgs(cmd,
                                        domainName,
d205 1
a205 1
        enqueue(args);
d215 4
a218 3
    public static void addModule(DataManager dMgr,
                                 Connection connection,
                                 String projectID,
d225 8
a232 2
        Project project = new Project(connection, dMgr, projectID);
        TigrisUpdate.addModule(project.getDomainName(),
d245 3
a247 1
    public static void addModule(String domainName, String projectName, 
d254 1
a254 2
	String[] args = makeModuleArgs(cmd,
                                       domainName,
d262 1
a262 1
	enqueue(args);
d268 4
a271 3
    public static void deleteModule(DataManager dMgr,
                                    Connection connection,
                                    String projectID,
d276 2
a277 2
        Project project = new Project(connection, dMgr, projectID);
        TigrisUpdate.deleteModule(project.getDomainName(),
d288 3
a290 1
    public static void deleteModule(String domainName, String projectName, 
d293 1
a293 2
    {
	
d295 1
a295 2
	String[] args = makeModuleArgs(cmd,
                                       domainName,
d303 1
a303 1
	enqueue(args);
d313 3
a315 1
    public static void addMember(Project project, User user, String userRole)
d320 1
a320 1
        addMembers(project, users, userRole);
d326 3
a328 2
    public static void addMembers(Project project, ArrayList users,
                                  String userRole)
d353 6
d360 1
a360 2
	String[] args = makeUserArgs(cmd,
                                     project.getDomainName(),
d368 2
a369 1
	enqueue(args);
d375 3
a377 1
    public static void deleteMember(Project project, User user)
d382 1
a382 1
        deleteMembers(project, users);
d388 3
a390 1
    public static void deleteMembers(Project project, ArrayList users)
d404 6
d411 1
a411 2
	String[] args = makeUserArgs(cmd,                     //script
                                     project.getDomainName(), //domainName
d419 2
a420 1
	enqueue(args);
d431 1
a431 2
    public static String[] makeProjectArgs(String script,
                                           String domainName, 
d437 1
a437 2
        return makeArgs(script,
                        domainName,
d455 1
a455 2
    public static String[] makeModuleArgs(String script,
                                          String domainName, 
d463 1
a463 2
        return makeArgs(script,            //script
                        domainName,        //domainName
d481 1
a481 2
    public static String[] makeUserArgs(String script,
                                        String domainName, 
d489 1
a489 2
        return makeArgs(script,       //script
                        domainName,   //domainName
d507 1
a507 2
    private static String[] makeArgs(String script,
                                     String domainName, 
a520 1
            script,
d537 1
a537 1
    // Queue manager.
d540 24
a563 3
    public static boolean emptyQueue()
    {
        return (queue.isEmpty());
d566 1
a566 6
    private static void enqueue(String[] args)
    {
        queue.add(args);
    }
    
    static void dequeue()
d569 1
a569 1
        while(!emptyQueue())
d571 39
a609 2
            String[] args = (String[])queue.remove(0);
            runScript(args);
d619 1
a619 1
     * @@param command command to run (inc. arguments)
d621 8
a628 2
    private static synchronized void runScript(String[] args)
	throws UpdateException {
d686 2
a687 2
    public static void reflectGrant(DataManager dMgr,
                                    Connection connection, 
d697 3
a699 1
        TigrisUpdate.findNewMembers(affectedUsers, affectedProjects);
d706 2
a707 1
    public static void findNewMembers(ArrayList affectedUsers, 
d767 2
a768 1
                TigrisUpdate.addMembers(project, observerUsers, "observer");
d773 2
a774 1
                TigrisUpdate.addMembers(project, developerUsers, "developer");
d779 2
a780 1
                TigrisUpdate.addMembers(project, adminUsers, "admin");
d788 3
a790 2
    public static void reflectRevoke(DataManager dMgr,
                                     Connection connection, 
d800 2
a801 1
        TigrisUpdate.findExMembers(affectedUsers, affectedProjects);
d804 1
a804 1
        TigrisUpdate.findNewMembers(affectedUsers, affectedProjects);
d813 2
a814 1
    public static void findExMembers(ArrayList affectedUsers,
d850 1
a850 1
                TigrisUpdate.deleteMembers(project, deletedUsers);
@


1.19
log
@Print debug messages correctly.
@
text
@d617 3
a619 2
            ArrayList normalUsers = new ArrayList();
            
d630 4
d637 2
a638 3
                    if (debug) log.info(" " + user.getLoginID()
                                        + " is an administrator of " 
                                        + project.getName());
d640 1
d642 11
a652 6
                           ("Project Issue Tracking - Submit", project.getID())) 
                {
                    if (debug) log.info(" " + user.getLoginID()
                                        + " is a contributor to " 
                                        + project.getName());
                    normalUsers.add(user);
d654 2
a655 3
                    if (debug) log.info(" " + user.getLoginID()
                                        + " has no role in " 
                                        + project.getName());
d659 6
a664 1
            if (normalUsers.size() > 0)
d666 1
a666 1
                TigrisUpdate.addMembers(project, normalUsers, "user");
d691 3
d724 6
a729 4
                if (!currentACL.hasPermissionForProject
                    ("Project Issue Tracking - Configure", project.getID())
                    && !currentACL.hasPermissionForProject
                    ("Project Issue Tracking - Submit", project.getID()))
@


1.18
log
@A little format cleanup.
@
text
@d555 1
a555 1
        log.info("!!!!Running " + scriptName.toString());
d605 1
a605 1
        log.info("!!! FindNewMembers.");
d672 1
a672 1
        log.info("!!! Reflecting revoke.");
d677 1
a677 1
        log.info("!!! Done reflecting revoke.");
d689 1
a689 1
        log.info("!!! FindExMembers.");
d703 1
a703 1
                log.info("!!!Checking " + user.getLoginID());
d712 1
a712 1
                    log.info("!!!Adding " + user.getLoginID());
d722 1
a722 1
        log.info("!!!Done deleting members.");
d735 1
a735 1
        log.info("!!!Expanding user.");
d745 1
a745 1
            log.info("Expand user: " + user.getLoginID() + " is affected.");
d755 1
a755 1
                log.info("Expand user: " + user.getLoginID() 
d772 1
a772 1
        log.info("!!!Expanding project.");
d786 1
a786 1
                log.info("Expand project: " + project.getName() 
d800 1
a800 1
                    log.info("Expand project: " + project.getName() 
@


1.17
log
@Don't run MemberAdd on non-base projects.
@
text
@d792 5
a796 3
                String pID = projectsForProjectID.getRecord(i).getValue(ProjectProjectGroupManager.PROJECT_ID).asString();
                Project project = new Project
                    (connection, dMgr, pID);
@


1.16
log
@Only run delete user scripts if there are users to delete... words to live by.
@
text
@d792 9
a800 8
                projectID = projectsForProjectID.getRecord(i)
                    .getValue(ProjectProjectGroupManager.PROJECT_ID)
                    .asString();
                Project project = new Project(connection, dMgr, projectID);
                affectedProjects.add(project);
                log.info("Expand project: " + project.getName() 
                         + " is affected.");

@


1.15
log
@Made the TigrisUpdate stuff saner with the use of business objects.
@
text
@d716 5
a720 3

            TigrisUpdate.deleteMembers(project, deletedUsers);
            log.info("!!!Done deleting members.");
d722 1
@


1.14
log
@Got rid of more superfluous UpdateException throwage.
@
text
@d63 4
d110 10
a119 12
                                  String projectID,
                                  String description)
	throws SQLException, DataSetException, JoistDatabaseException
    {
        ArrayList info = TigrisUpdate.getProjectInfo
            (dMgr, connection, projectID);
        TigrisUpdate.addProject((String)info.get(0), 
                                (String)info.get(1), 
                                (String)info.get(2), 
                                (String)info.get(3),
                                description
                                );
d197 2
a198 1
	throws SQLException, DataSetException, JoistDatabaseException
d200 5
a204 6
        ArrayList info = TigrisUpdate.getProjectInfo
            (dMgr, connection, projectID);
        TigrisUpdate.addModule((String)info.get(0), 
                               (String)info.get(1), 
                               (String)info.get(2), 
                               (String)info.get(3),
d240 2
a241 1
	throws SQLException, DataSetException, JoistDatabaseException
d243 5
a247 6
        ArrayList info = TigrisUpdate.getProjectInfo
            (dMgr, connection, projectID);
        TigrisUpdate.deleteModule((String)info.get(0), 
                                  (String)info.get(1), 
                                  (String)info.get(2), 
                                  (String)info.get(3),
d280 6
a285 15
    public static void addMember(String domainName, String projectName, 
                                 String projectID,
                                 String brandName,
                                 String userRealName, 
                                 String userUsername,
                                 String userRole
                                 )
    {
        
        ArrayList a = new ArrayList();
        ArrayList b = new ArrayList();
        a.add(userRealName);
        b.add(userUsername);
        addMember(domainName, projectName, projectID, brandName,
                  userRealName, userUsername, userRole);
d291 6
a296 11
    public static void addMembers(String domainName, String projectName, 
                                  String projectID,
                                  String brandName,
                                  ArrayList userRealNames, 
                                  ArrayList userUsernames,
                                  String userRole
                                  )
    {
	
        String userRealName = "";
        for (Iterator i = userRealNames.iterator(); i.hasNext();)
d298 2
a299 1
            userRealName += (String)i.next();
d302 1
a302 1
                userRealName += ":";
d306 2
a307 2
        String userUsername = "";
        for (Iterator i = userUsernames.iterator(); i.hasNext();)
d309 2
a310 1
            userUsername += (String)i.next();
d313 1
a313 1
                userUsername += ":";
d319 6
a324 6
                                     domainName,
                                     projectName,
                                     projectID,
                                     brandName,
                                     userRealName,
                                     userUsername,
a329 1

d333 2
a334 3
    public static void deleteMember(String domainName, String projectName, 
                                    String projectID, String brandName,
                                    String userUsername)
d336 3
a338 4
        ArrayList a = new ArrayList();
        a.add(projectID);
        deleteMember(domainName, projectName, projectID, brandName,
                     userUsername);
d344 2
a345 3
    public static void deleteMembers(String domainName, String projectName, 
                                     String projectID, String brandName,
                                     ArrayList userUsernames)
d347 2
a348 2
        String userUsername = null;
        for (Iterator i = userUsernames.iterator(); i.hasNext();)
d350 2
a351 1
            userUsername += (String)i.next();
d354 1
a354 1
                projectID += ":";
d359 8
a366 8
	String[] args = makeUserArgs(cmd,
                                     domainName,
                                     projectName,
                                     projectID,
                                     brandName,
                                     null,
                                     userUsername,
                                     null
d555 1
a555 1
        log.info("Running " + scriptName.toString());
d587 2
a588 1
        throws DataSetException, SQLException, JoistDatabaseException
d603 1
a603 1
        throws DataSetException
d605 1
d613 5
a617 13
            ArrayList currentProjectInfo = (ArrayList)j.next();
            String domainName = (String)currentProjectInfo.get(0);
            String projectName = (String)currentProjectInfo.get(1);
            String projectID = (String)currentProjectInfo.get(2);
            String brandName = (String)currentProjectInfo.get(3);
            String role = null;

            if (debug) log.info("Processing project " + projectName);

            ArrayList adminUserRealNames = new ArrayList();
            ArrayList adminUserUsernames = new ArrayList();
            ArrayList normalUserRealNames = new ArrayList();
            ArrayList normalUserUsernames = new ArrayList();            
d623 4
a626 11
                ArrayList userInfo = (ArrayList)i.next();
                AccessControlList currentACL = (AccessControlList)
                    userInfo.get(0);
                Record user = (Record) userInfo.get(1);
                String userRealName = user.getValue(UserManager.NAME)
                    .toString();
                String userUsername = user.getValue(UserManager.LOGIN_ID)
                    .toString();

                if (debug) log.info(" Processing user " + userRealName);

d630 1
a630 1
                    ("Project Issue Tracking - Configure", projectID))
d632 4
a635 3
                    if (debug) log.info(" This user is an admin on this project.");
                    adminUserRealNames.add(userRealName);
                    adminUserUsernames.add(userUsername);
d637 1
a637 1
                           ("Project Issue Tracking - Submit", projectID)) 
d639 4
a642 3
                    if (debug) log.info(" This user is a lowly peon on this project.");
                    normalUserRealNames.add(userRealName);
                    normalUserUsernames.add(userUsername);
d644 3
a646 1
                    if (debug) log.info(" This user has no roles in this project.");
d650 1
a650 1
            if (normalUserUsernames.size() > 0)
d652 1
a652 5
                TigrisUpdate.addMembers(domainName, projectName, 
                                        projectID, brandName, 
                                        normalUserRealNames, 
                                        normalUserUsernames,
                                        "user");
d654 2
a655 2

            if (adminUserUsernames.size() > 0)
d657 1
a657 5
                TigrisUpdate.addMembers(domainName, projectName, 
                                        projectID, brandName, 
                                        adminUserRealNames,
                                        adminUserUsernames,
                                        "admin");
d669 2
a670 1
        throws DataSetException, SQLException, JoistDatabaseException
d672 4
a675 4
        ArrayList affectedUsers = TigrisUpdate
            .expandUser(dMgr, connection, userID);
        ArrayList affectedProjects = TigrisUpdate
            .expandProject(dMgr, connection, projectID);
d677 1
d687 1
a687 1
        throws DataSetException
d689 1
d695 1
d697 1
a697 10
            //Get the project information.
            ArrayList currentProjectInfo = (ArrayList)j.next();
            String domainName = (String)currentProjectInfo.get(0);
            String projectName = (String)currentProjectInfo.get(1);
            String projectID = (String)currentProjectInfo.get(2);
            String brandName = (String)currentProjectInfo.get(3);
            String role = null;

            ArrayList deletedUserUsernames = new ArrayList();

d701 4
a704 8
                //Get their ACL and user information.
                ArrayList userInfo = (ArrayList)i.next();
                AccessControlList currentACL = (AccessControlList)
                    userInfo.get(0);
                Record user = (Record) userInfo.get(1);
                String tuserUsername = user.getValue(UserManager.LOGIN_ID)
                    .toString();

d708 1
a708 1
                    ("Project Issue Tracking - Configure", projectID)
d710 1
a710 1
                    ("Project Issue Tracking - Submit", projectID))
d712 2
a713 1
                    deletedUserUsernames.add(tuserUsername);
d717 2
a718 3
            TigrisUpdate.deleteMembers(domainName, projectName, 
                                       projectID, brandName, 
                                       deletedUserUsernames);
d723 1
a723 1
     * Get the data structure for every user corresponding to the
d727 6
a732 8
                                Connection connection, 
                                String userID)
        throws DataSetException, SQLException, JoistDatabaseException
    {
        ArrayList affectedUsers = new ArrayList();

        UserManager uMgr = (UserManager) dMgr.getManager
            ("org.joist.database.UserManager");
a734 3

        //Get info data structures for all users represented by the
        //given userID.
d738 1
d741 3
a743 2
            Record user = uMgr.getUser(connection, userID);
            affectedUsers.add(getUserInfo(dMgr, connection, user));
d747 7
a753 2
                affectedUsers.add(getUserInfo(dMgr, connection, 
                                              usersForUserID.getRecord(i)));
d758 1
a758 1

d760 1
a760 1
     * Get the data structure for every user corresponding to the
d766 2
a767 1
        throws DataSetException, SQLException, JoistDatabaseException
d769 1
a771 3
        ProjectManager pMgr = (ProjectManager) dMgr.getManager
            ("org.tigris.helm.database.ProjectManager");
        
a774 2
        
        //Get info for all projects represented by the given projectID.
a777 1
        String domainName = null;
a778 1
        
d781 5
a785 5
            Record project = pMgr.getProjectForID(connection, projectID);
            projectInfo = TigrisUpdate.getProjectInfo(dMgr, connection, 
                                                      project, domainName);
            domainName = (String)projectInfo.get(0);
            affectedProjects.add(projectInfo); 
d790 7
a796 10
                    .getValue(ProjectProjectGroupManager
                              .PROJECT_ID).toString();
                Record project = pMgr.getProjectForID(connection, projectID);
                projectInfo = TigrisUpdate.getProjectInfo(dMgr, connection, 
                                                          project, domainName);
                if (i == 0)
                {
                    domainName = (String)projectInfo.get(0);
                }
                affectedProjects.add(projectInfo);                
a799 77
    }

    /**
     * Helper method to gather user information used by every
     * script.
     */
    public static ArrayList getUserInfo(DataManager dMgr, 
                                           Connection connection,
                                           String userID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        UserManager uMgr = (UserManager)dMgr.getManager
            ("org.joist.database.UserManager");
        Record user = uMgr.getUser(connection, userID);
        return getUserInfo(dMgr, connection, user);
    }

    /**
     * Helper method to turn user record into proper data structure.
     */
    public static ArrayList getUserInfo(DataManager dMgr,
                                        Connection connection,
                                        Record user)
        throws DataSetException, SQLException, JoistDatabaseException
    {               
        ArrayList userInfo = new ArrayList();
        String userID = user.getValue(UserManager.USER_ID).toString();
        userInfo.add(new AccessControlList(connection, dMgr, userID));
        userInfo.add(user);                
        return userInfo;
    }

    /**
     * Helper method to turn project record into proper data structure.
     */
    public static ArrayList getProjectInfo(DataManager dMgr, 
                                           Connection connection,
                                           Record project, String domainName)
        throws DataSetException, SQLException, JoistDatabaseException
    {               
        String projectName = null;
        String projectID = null;
        String brandName = null;
        
        if (domainName == null)
        {
            DomainManager domMgr = (DomainManager) dMgr.getManager
                ("org.tigris.helm.database.DomainManager");
            
            domainName = domMgr.getDomainName
                (project.getValue(ProjectManager.PROJECT_DOMAIN_ID).toString());
        }
        projectID = project.getValue(ProjectManager.PROJECT_ID).toString();
        projectName = project.getValue(ProjectManager.PROJECT_NAME).toString();

        ArrayList projectInfo = new ArrayList();
        projectInfo.add(domainName);
        projectInfo.add(projectName);
        projectInfo.add(projectID);
        projectInfo.add(brandName);
        return projectInfo;

    }

    /**
     * Helper method to gather project information used by every
     * script.
     */
    public static ArrayList getProjectInfo(DataManager dMgr, 
                                           Connection connection,
                                           String projectID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        ProjectManager pMgr = (ProjectManager)dMgr.getManager
            ("org.tigris.helm.database.ProjectManager");
        Record project = pMgr.getProjectForID(connection, projectID);
        return getProjectInfo(dMgr, connection, project, null);
@


1.13
log
@Modernized ProjectEdit; began to get rid of superfluous UpdateException handling.
@
text
@d600 1
a600 2
        throws DataSetException, SQLException, UpdateException, 
               JoistDatabaseException
d615 1
a615 1
        throws DataSetException, UpdateException
d699 1
a699 2
        throws DataSetException, SQLException, UpdateException, 
               JoistDatabaseException
d715 1
a715 1
        throws DataSetException, UpdateException
@


1.12
log
@For some reason scripts weren't being run. They seem to be now.
@
text
@d108 1
a108 2
	throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException  
a127 1
	throws UpdateException  
a148 1
	throws UpdateException  
d169 1
a169 1
	throws UpdateException {
d195 1
a195 2
	throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException  
d216 1
a216 1
	throws UpdateException  {
d238 1
a238 2
	throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException  
d256 1
a256 1
	throws UpdateException  {
a284 1
	throws UpdateException  
d305 1
a305 1
	throws UpdateException  {
d360 1
a360 2
	throws UpdateException  {
	
@


1.11
log
@Email host admins on failure of a script.
@
text
@d566 11
a589 11

            StringBuffer scriptName = new StringBuffer();
            for (int i = 0; i < args.length; i++)
            {
                if (args[i] == null)
                {
                    args[i] = "NULL";
                }
                scriptName.append(args[i]).append(" ");
            }            

@


1.10
log
@Resolved merge conflicts.
@
text
@d527 1
d529 4
a532 10
        log.info("Dequeuing " + queue.size() + "elements.");
        try {
            while(!emptyQueue())
            {
                String[] args = (String[])queue.remove(0);
                runScript(args);
            }
        } catch (UpdateException e) {
            log.exception("Update Exception: " + e.getMessage());
            return;
a546 11
        StringBuffer debugMsg = new StringBuffer("Running script: ");
        for (int i = 0; i < args.length; i++)
        {
            if (args[i] == null)
            {
                args[i] = "NULL";
            }
            debugMsg.append(args[i]).append(" ");
        }
        if (debug) log.info(debugMsg.toString());

d579 12
a590 1
	    throw new UpdateException("Script had non-zero exit value " 
@


1.9
log
@Got rid of isPrivate for modules.
@
text
@d2 1
a2 1
 * Copyright (c) 2000 Collab.Net.  All rights reserved.
d17 1
a17 1
 * software developed by Collab.Net (http://www.Collab.Net/)."
d27 1
a27 1
 * permission of Collab.Net.
d44 1
a44 1
 * individuals on behalf of Collab.Net.
a49 2
import javax.servlet.*;

d54 6
d61 1
d63 2
a64 5
//Just in order to get Log.
import org.webmacro.util.*;
import org.webmacro.servlet.*;
import org.webmacro.engine.*;
import org.webmacro.broker.*;
d77 2
a78 1
public class TigrisUpdate {
d83 4
d89 12
d102 1
a102 11
     * Update the Tigris system; take the changes made to the database
     * and propogate them to the flat files and other non-database
     * configuration tools.
     *
     * <p>Note that this method should not be called upon the creation
     * or deletion of a new project. The addProject() and delProject()
     * methods should be used instead.
     *
     * @@param tigris The Tigris context to execute the update program for
     * @@exception UpdateException if an error occurs during the execution
     *            or termination of the program.
d104 68
a171 1
    public static void update(Connection connection)
d173 60
a232 1
	runUpdate(connection, "update");
d236 21
a256 4
     * Add a new project to the Tigris system. This calls a script
     * which creates the infrastructure needed to support the new
     * project. This should be called only after the proper database
     * rows have been created.  
d258 3
a260 1
    public static void addProject(Connection connection, String domain, String project, String description, String bugs_password)
d263 16
a278 4
	/*This will have to be changed when the syntax for the Perl
          scripts changes.*/
	String cmd = "ProjectAdd";
	String[] args = {cmd, domain, project,"",description,"","","","","",bugs_password};
d280 19
a298 1
	runScript(args);
d300 46
d348 1
a348 3
     * Remove a project from the Tigris system. This should be called
     * after the database tables have been properly cleaned up to reflect
     * the removal of the project.
d350 8
a357 3
    public static void delProject(Connection connection, String project)
	throws UpdateException {
	runUpdate(connection, "del_project+" + project);	
d361 1
a361 4
     * Add a new module to the Tigris system. This calls a script
     * which creates the infrastructure needed to support the new
     * module. This should be called only after the proper database
     * rows have been created.  
d363 3
a365 3
    public static void addModule(Connection connection, String domain, 
                                 String project, String module, 
                                 String moduleDescription, boolean isWeb)
d368 171
a538 7
	/*This will have to be changed when the syntax for the Perl
          scripts changes. A method which gathers information from the
          database, and which substitutes for the current placeholder
          argument values, should be called.*/
	String cmd = "ModuleAdd";
	String[] args = {cmd, domain, project, "", "", module, moduleDescription, isWeb?"1":"0"};
	runScript(args);
d541 4
d551 12
a562 1
	
d567 3
a569 8
	String db_name = (String) JoistProperties.getProperty("databaseName");
	String db_user = (String) JoistProperties.getProperty("databaseUser");
	String db_password = (String) JoistProperties.getProperty("databasePassword");

	//Destroy once the above works.
	db_name = "tigris";
	db_user = "tigris";
	db_password = "euphrates";
d573 3
a575 3
			"DATABASE_NAME=" + db_name,
			"DATABASE_USER=" + db_user,
			"DATABASE_PASSWORD=" + db_password			
d577 1
a577 1
	
d588 1
a588 1

d598 122
d722 1
d724 50
a773 8
   * Actually run the update program
   *
   * @@param args arguments to pass to the update program, in HTTP
   * query string format (i.e., + and & deliminated)
   */
    private static synchronized void runUpdate(Connection connection,
					       String args)
	throws UpdateException {
d775 34
a808 29
	// I originally tried doing this by just using Runtime.exec()
	// to activate the program. But that only worked sporatically;
	// I suspect the Linux port may be lacking, or possibly a
	// problem with Java itself. 
	//
	// For whatever reason, the Apache server is good at running
	// programs, and Java is good at talking to Web servers. So
	// there we go.
	try {
	    //TODO: run the update scripts directly
	    //TODO: get info on update scripts via database or session manager
	    //URL updateUrl = new URL(tigris.config("update_url")
	    //                        + "?" + args);
	    String urlString = getUpdateURLString(connection) + "?" + args;
	    
	    URL updateUrl = new URL(urlString);
	    HttpURLConnection updateConnection =
		(HttpURLConnection)updateUrl.openConnection();
	    
	    if (updateConnection.getResponseCode() != 200) {
		throw new
		    UpdateException("Update program returned error code "
				    + updateConnection.getResponseCode() + ": "
				    + updateConnection.getResponseMessage());
	    }
            BufferedReader r = new BufferedReader(
                new InputStreamReader(updateConnection.getInputStream()));
            String line;
            while ((line = r.readLine()) != null);
d810 50
d861 14
a874 3
	} catch (IOException e) {
	    throw new UpdateException("Error running update program: " + e);
	}
d876 13
d891 29
a920 12
    public static String getUpdateURLString(Connection connection) {
	try {
	    Statement s = connection.createStatement();
	    ResultSet r = s.executeQuery("SELECT value " +
					 "FROM domain_config " +
					 "WHERE param='update_url'");
	    if (r.next()) return r.getString(1);
	}
	catch (SQLException e) {
	    // do nothing
	}
	return "http://collab.net/tigris";
a921 1
} /* end class TigrisUpdate */
d923 15
@


1.8
log
@Added SelfServeProjectAdd servlet, factoring out project creation
logic into ProjectCreator tool class. Big update to TigrisUpdate to
make it run kmaples' Perl scripts directly. Also updates to
{Project,Module}{Add,Manager}.
@
text
@d133 3
a135 1
    public static void addModule(Connection connection, String domain, String project, String module, String moduleDescription, boolean isWeb, boolean isPrivate)
d143 1
a143 1
	String[] args = {cmd, domain, project, "", "", module, moduleDescription, isWeb?"1":"0", isPrivate?"1":"0"};
@


1.7
log
@
Obtained from:
Submitted by:
Reviewed by:

Moved from org.helm to org.tigris.helm
Moved from org/helm to org/tigris/helm

perl -pi.bak -e, how I love thee

note: this update was done POST-CVS-REPOSITORY surgury.  In order to
get this right, you may need to remove the directories

$CVSROOT/helm/java/org/helm
$CVSROOT/helm/data/htdoc/look/www/org/helm
$CVSROOT/helm/templates/org/helm

before doing the "CVS update" call, since those directories don't
exist anymore and CVS will try to create lockfiles for you in them,
giving you an error.
@
text
@d56 8
d76 6
d86 9
a94 9
   *
   * <p>Note that this method should not be called upon the creation
   * or deletion of a new project. The addProject() and delProject()
   * methods should be used instead.
   *
   * @@param tigris The Tigris context to execute the update program for
   * @@exception UpdateException if an error occurs during the execution
   *            or termination of the program.
   */
d101 22
a122 6
   * Add a new project to the Tigris system. This calls the update
   * program and creates any infrastructure needed to support the
   * new project. This should be called only after the proper database
   * rows have been created.
   */
    public static void addProject(Connection connection, String project)
d124 1
a124 1
	runUpdate(connection, "add_project+" + project);
d128 22
a149 5
   * Remove a project from the Tigris system. This should be called
   * after the database tables have been properly cleaned up to reflect
   * the removal of the project.
   */
    public static void delProject(Connection connection, String project)
d151 41
a191 1
	runUpdate(connection, "del_project+" + project);
@


1.6
log
@reverted to 1.4 code
@
text
@d48 1
a48 1
package org.helm.tool;
@


1.5
log
@Initial commit.
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@a49 2
import org.webmacro.servlet.*;

a55 4
import org.joist.database.*;
import org.helm.database.*;
import com.workingdogs.village.*;

a67 2
    static final String scriptpath = "/home/leonardr/sandbox/helm/perl/scripts/";

d69 13
a81 6
     * Add a new project to the Tigris system. This calls the update
     * program and creates any infrastructure needed to support the
     * new project. This should be called only after the proper database
     * rows have been created.
     */
    public static void addProject(String project)
d83 1
a83 1
	runScript("ProjectAdd", new String[] {project});
d86 7
a92 2
    public static void addProject(Connection connection, String project,
				  String[] owners, String[] subscribers)
d94 1
a94 63

	//Run the add project script.
	addProject(project);
	
	//Add the owners to the project and make them owners of it.
	for (int i = 0; i < owners.length; i++) {  
	    //!!getAccountInfoForUser doesn't exist yet.!!
	    WebContext wc;
     	    QueryDataSet qds = UserManager.getAccountInfoForUser(owners[i]);
	    Record r = qds.getRecord(0);
	    TUserManager.addUser(connection, wc, r.values[0],
				 r.values[1], r.values[2], r.values[3]);
	    try {
		int uid = TUserManager.getUserID(connection, owners[i]);
	    } catch (TUserManager$NoSuchUserException e) {
		throw new UpdateException("Owner's username already exists.");
	    } catch (SQLException e) {
		throw new UpdateException("Problem adding owner.");
	    }

	    TUserManager.setModuleOwner(connection, project, wc,
					true);
	}
    
	//Add the subscribers to the announce mailing list. Note that
	//list-subscribe wants the full path to the list, so this
	//won't work. Something like it will, though.
	String[] arr = new String[subscribers.length+1];
	arr[0] = "announce";
	for (int i = 1; i < arr.length; i++) {
	    arr[i] = subscribers[i-1];
	}
	runScript("list-subscribe", arr);
    }
    
    /**
     * Remove a project from the Tigris system. This should be called
     * after the database tables have been properly cleaned up to reflect
     * the removal of the project.
     */
    public static void delProject(String project)
    throws UpdateException{
	runScript("DeleteProject", new String[] {project});
    }
    
    /**
     * Run the Perl script with the given name and arguments.
     */
    private static synchronized void runScript(String script, String[] args)
    throws UpdateException {
	try {
	    Process script_process = Runtime.getRuntime().exec(scriptpath + script,args);
	    int i = script_process.exitValue();
	    if (i != 0)
		{
		    throw new
			UpdateException("Update script returned error code " +
					Integer.toString(i));
		}
	} catch (IOException e) {
	    throw new 
		UpdateException("IO Error while performing update.");
	}
a95 4
    
    /*These are functions I would like to gradually get rid of by
      writing more specific replacements for "update", in the spirit
      of addProject and delProject.*/
d98 5
a102 13
     * Update the Tigris system; take the changes made to the database
     * and propogate them to the flat files and other non-database
     * configuration tools.
     *
     * <p>Note that this method should not be called upon the creation
     * or deletion of a new project. The addProject() and delProject()
     * methods should be used instead.
     *
     * @@param tigris The Tigris context to execute the update program for
     * @@exception UpdateException if an error occurs during the execution
     *            or termination of the program.
     */
    public static void update(Connection connection)
d104 1
a104 1
	runUpdate(connection, "update");
d108 1
a108 1
     * Actually run the update program
a167 1

@


1.4
log
@The servlet was not waiting for the CGI to complete, so the CGI was
getting a SIGPIPE and not completing. Fixed by reading all output from
the CGI.

Submitted by:	Ed Korthof and Manoj Kasichainula
@
text
@d50 2
d58 4
d74 2
d77 6
a82 13
     * Update the Tigris system; take the changes made to the database
     * and propogate them to the flat files and other non-database
     * configuration tools.
   *
   * <p>Note that this method should not be called upon the creation
   * or deletion of a new project. The addProject() and delProject()
   * methods should be used instead.
   *
   * @@param tigris The Tigris context to execute the update program for
   * @@exception UpdateException if an error occurs during the execution
   *            or termination of the program.
   */
    public static void update(Connection connection)
d84 1
a84 1
	runUpdate(connection, "update");
d87 48
d136 17
a152 8
   * Add a new project to the Tigris system. This calls the update
   * program and creates any infrastructure needed to support the
   * new project. This should be called only after the proper database
   * rows have been created.
   */
    public static void addProject(Connection connection, String project)
	throws UpdateException {
	runUpdate(connection, "add_project+" + project);
d154 4
d160 13
a172 5
   * Remove a project from the Tigris system. This should be called
   * after the database tables have been properly cleaned up to reflect
   * the removal of the project.
   */
    public static void delProject(Connection connection, String project)
d174 1
a174 1
	runUpdate(connection, "del_project+" + project);
d178 1
a178 1
   * Actually run the update program
d238 1
@


1.3
log
@Added tigris.org license
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d52 1
a52 1
import java.io.IOException;
d142 5
@


1.2
log
@updated TView since some of it was moved into joist; made copyrights consistent
@
text
@d1 46
a46 1
// Copyright (c) 2000 Collab.Net, Inc. All Rights Reserved.
@


1.1
log
@initial checking
@
text
@a100 1
// Copyright (c) 2000 Collab.Net, Inc.
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@d1 1
a1 45
/* ================================================================
 * 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 COLLAB.NET 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
d5 1
a5 1
package org.tigris.helm.tool;
d7 1
a7 1
import java.io.*;
a10 11
import java.util.*;

import org.webmacro.util.Log;

import com.workingdogs.village.*;

import org.joist.util.JoistProperties;
import org.joist.database.*;

import org.tigris.helm.database.*;
import org.tigris.helm.security.*;
d22 1
a22 24
public class TigrisUpdate 
{

    static public Log log = new Log("TUpdat", "Tigris Update");
    static private boolean debug = true;

    static List queue = Collections.synchronizedList(new LinkedList());
    static QueueHandler qh = new QueueHandler();

    //FIXME: Please!
    static final String script_dir = "/helm/perl/scripts/";

    ////////////////////////////////////////////////////////////////
    // Static initializer   
    ////////////////////////////////////////////////////////////////
    static 
    {
        qh.start();
    }
    
    ////////////////////////////////////////////////////////////////
    // Project scripts.
    ////////////////////////////////////////////////////////////////

d24 15
a38 17
     * Add a new project to CVS, Issuezilla, etc.
     */
    public static void addProject(DataManager dMgr,
                                  Connection connection,
                                  String projectID,
                                  String description)
	throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException  
    {
        ArrayList info = TigrisUpdate.getProjectInfo
            (dMgr, connection, projectID);
        TigrisUpdate.addProject((String)info.get(0), 
                                (String)info.get(1), 
                                (String)info.get(2), 
                                (String)info.get(3),
                                description
                                );
d42 8
a49 19
     * Add a new project to CVS, Issuezilla, etc.
     */
    public static void addProject(String domainName, 
                                  String projectName, 
                                  String projectID, 
                                  String brandName,
                                  String description)
	throws UpdateException  
    {
	String cmd = "ProjectAdd";
	String[] args = makeProjectArgs(cmd,
                                        domainName, 
                                        projectName,
                                        projectID,  
                                        brandName,       
                                        description 
                                        );

	enqueue(args);
d53 7
a59 19
     * Edit an existing project in place.
     */
    public static void editProject(String domainName, 
                                  String projectName, 
                                  String projectID, 
                                  String brandName,
                                  String description)
	throws UpdateException  
    {
	String cmd = "ProjectEdit";
	String[] args = makeProjectArgs(cmd,
                                        domainName, 
                                        projectName,
                                        projectID,  
                                        brandName,       
                                        description 
                                        );

	enqueue(args);
d63 7
a69 6
     * Remove a project from CVS, Issuezilla, etc.
     */
    public static void deleteProject(String domainName,
                                     String projectName,
                                     String projectID,
                                     String brandName)
a70 11
     
        String cmd = "ProjectDelete";
        String[] args = makeProjectArgs(cmd,
                                        domainName,
                                        projectName,
                                        projectID,
                                        brandName,
                                        null
                                        );
        enqueue(args);
    }
d72 25
a96 3
    ////////////////////////////////////////////////////////////////
    // Module scripts.
    ////////////////////////////////////////////////////////////////
d98 4
a101 259
    /**
     * Add a new module to Issuezilla.
     */
    public static void addModule(DataManager dMgr,
                                 Connection connection,
                                 String projectID,
                                 String moduleName,
                                 String moduleDescription,
                                 String isWeb)
	throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException  
    {
        ArrayList info = TigrisUpdate.getProjectInfo
            (dMgr, connection, projectID);
        TigrisUpdate.addModule((String)info.get(0), 
                               (String)info.get(1), 
                               (String)info.get(2), 
                               (String)info.get(3),
                               moduleName,
                               moduleDescription,
                               isWeb
                               );
    }

    /**
     * Add a new module to Issuezilla.
     */
    public static void addModule(String domainName, String projectName, 
                                 String projectID, String brandName,
                                 String moduleName, String moduleDescription, 
                                 String isWeb)
	throws UpdateException  {
	
	String cmd = "ModuleAdd";
	String[] args = makeModuleArgs(cmd,
                                       domainName,
                                       projectName,
                                       projectID,
                                       brandName,
                                       moduleName,
                                       moduleDescription,
                                       isWeb
                                       );
	enqueue(args);
    }

    /**
     * Remove a module from Issuezilla.
     */
    public static void deleteModule(DataManager dMgr,
                                    Connection connection,
                                    String projectID,
                                    String moduleName)
	throws SQLException, DataSetException, JoistDatabaseException,
               UpdateException  
    {
        ArrayList info = TigrisUpdate.getProjectInfo
            (dMgr, connection, projectID);
        TigrisUpdate.deleteModule((String)info.get(0), 
                                  (String)info.get(1), 
                                  (String)info.get(2), 
                                  (String)info.get(3),
                                  moduleName
                                  );
    }
    
    /**
     * Remove a module from Issuezilla.
     */
    public static void deleteModule(String domainName, String projectName, 
                                    String projectID, String brandName,
                                    String moduleName)
	throws UpdateException  {
	
	String cmd = "ModuleDelete";
	String[] args = makeModuleArgs(cmd,
                                       domainName,
                                       projectName,
                                       projectID,
                                       brandName,
                                       moduleName,
                                       null,
                                       null
                                       );
	enqueue(args);
    }

    ////////////////////////////////////////////////////////////////
    // User scripts
    ////////////////////////////////////////////////////////////////

    /**
     * Add a new user to Issuezilla.
     */
    public static void addMember(String domainName, String projectName, 
                                 String projectID,
                                 String brandName,
                                 String userRealName, 
                                 String userUsername,
                                 String userRole
                                 )
	throws UpdateException  
    {
        
        ArrayList a = new ArrayList();
        ArrayList b = new ArrayList();
        a.add(userRealName);
        b.add(userUsername);
        addMember(domainName, projectName, projectID, brandName,
                  userRealName, userUsername, userRole);
    }
    
    /**
     * Add a new user to Issuezilla.
     */
    public static void addMembers(String domainName, String projectName, 
                                  String projectID,
                                  String brandName,
                                  ArrayList userRealNames, 
                                  ArrayList userUsernames,
                                  String userRole
                                  )
	throws UpdateException  {
	
        String userRealName = "";
        for (Iterator i = userRealNames.iterator(); i.hasNext();)
        {
            userRealName += (String)i.next();
            if (i.hasNext())
            {
                userRealName += ":";
            }
        }

        String userUsername = "";
        for (Iterator i = userUsernames.iterator(); i.hasNext();)
        {
            userUsername += (String)i.next();
            if (i.hasNext())
            {
                userUsername += ":";
            }
        }

	String cmd = "MemberAdd";
	String[] args = makeUserArgs(cmd,
                                     domainName,
                                     projectName,
                                     projectID,
                                     brandName,
                                     userRealName,
                                     userUsername,
                                     userRole
                                     );
	enqueue(args);
    }


    /**
     * Remove a user from Issuezilla.
     */
    public static void deleteMember(String domainName, String projectName, 
                                    String projectID, String brandName,
                                    String userUsername)
    {
        ArrayList a = new ArrayList();
        a.add(projectID);
        deleteMember(domainName, projectName, projectID, brandName,
                     userUsername);
    }

    /**
     * Remove a user from Issuezilla.
     */
    public static void deleteMembers(String domainName, String projectName, 
                                     String projectID, String brandName,
                                     ArrayList userUsernames)
	throws UpdateException  {
	
        String userUsername = null;
        for (Iterator i = userUsernames.iterator(); i.hasNext();)
        {
            userUsername += (String)i.next();
            if (i.hasNext())
            {
                projectID += ":";
            }
        }

	String cmd = "MemberDelete";
	String[] args = makeUserArgs(cmd,
                                     domainName,
                                     projectName,
                                     projectID,
                                     brandName,
                                     null,
                                     userUsername,
                                     null
                                     );
	enqueue(args);
    }

    ////////////////////////////////////////////////////////////////
    // Argument builders.
    ////////////////////////////////////////////////////////////////

    /**
     * Convenience function to take only the arguments neccessary
     * for scripts that deal with projects.
     */
    public static String[] makeProjectArgs(String script,
                                           String domainName, 
                                           String projectName, 
                                           String projectID, 
                                           String brandName,
                                           String projectDescription)
    {
        return makeArgs(script,
                        domainName,
                        projectName,
                        projectID,
                        brandName,
                        projectDescription,
                        null,        //moduleName
                        null,        //moduleDescription
                        null,        //isWeb
                        null,        //userRealName
                        null,        //userUsername
                        null         //userRole
                        );
    }

    /**
     * Convenience function to take only the arguments neccessary
     * for scripts that deal with modules.
     */
    public static String[] makeModuleArgs(String script,
                                          String domainName, 
                                          String projectName, 
                                          String projectID, 
                                          String brandName,
                                          String moduleName,
                                          String moduleDescription,
                                          String moduleIsWeb)
    {
        return makeArgs(script,            //script
                        domainName,        //domainName
                        projectName,       //projectName
                        projectID,         //projectID
                        brandName,         //brandName
                        null,              //projectDescription
                        moduleName,        //moduleName
                        moduleDescription, //moduleDescription
                        moduleIsWeb,       //isWeb
                        null,              //userRealName
                        null,              //userUsername
                        null               //userRole
                        );
    }
a102 61
    /**
     * Convenience function to take only the arguments neccessary
     * for scripts that deal with users.
     */
    public static String[] makeUserArgs(String script,
                                        String domainName, 
                                        String projectName, 
                                        String projectID, 
                                        String brandName,
                                        String userRealName,
                                        String userUsername,
                                        String userRole)
    {
        return makeArgs(script,       //script
                        domainName,   //domainName
                        projectName,  //projectName
                        projectID,    //projectID
                        brandName,    //brandName
                        null,         //projectDescription
                        null,         //moduleName
                        null,         //moduleDescription
                        null,         //isWeb
                        userRealName, //userRealName
                        userUsername, //userUsername
                        userRole      //userRole
                        );
    }

    /**
     * Takes a script name and a bunch of arguments and makes a String
     * array.  
     */
    private static String[] makeArgs(String script,
                                     String domainName, 
                                     String projectName, 
                                     String projectID, 
                                     String brandName,
                                     String projectDescription, 
                                     String moduleName, 
                                     String moduleDescription,
                                     String isWeb, 
                                     String userRealName,
                                     String userName,
                                     String userRole)
    {
        String[] args =
        { 
            script,
            domainName,
            projectName, 
            projectID,
            brandName,
            projectDescription, 
            moduleName,  
            moduleDescription, 
            isWeb,
            userRealName,
            userName,
            userRole
        };
        return args;
a104 69
    ///////////////////////////////////////////////////////////////////
    // Queue manager.
    ///////////////////////////////////////////////////////////////////

    public static boolean emptyQueue()
    {
        return (queue.isEmpty());
    }
    
    private static void enqueue(String[] args)
    {
        queue.add(args);
    }
    
    static void dequeue()
    {
        log.info("Dequeuing " + queue.size() + "elements.");
        try {
            while(!emptyQueue())
            {
                String[] args = (String[])queue.remove(0);
                runScript(args);
            }
        } catch (UpdateException e) {
            log.exception("Update Exception: " + e.getMessage());
            return;
        }
    }

    ///////////////////////////////////////////////////////////////////
    // Script runner.
    ///////////////////////////////////////////////////////////////////

    /**
     * Run a command with a populated environment.
     * @@param command command to run (inc. arguments)
     */
    private static synchronized void runScript(String[] args)
	throws UpdateException {

        StringBuffer debugMsg = new StringBuffer("Running script: ");
        for (int i = 0; i < args.length; i++)
        {
            if (args[i] == null)
            {
                args[i] = "NULL";
            }
            debugMsg.append(args[i]).append(" ");
        }
        if (debug) log.info(debugMsg.toString());

	//Get the sandbox directory and htdoc_root to put in the
	//script's environment.
	String htdoc_root = (String) JoistProperties.getProperty("documentRoot");
	String sandbox = (String) JoistProperties.getProperty("SANDBOX");
	String dbName = (String) JoistProperties.getProperty("databaseName");
	String dbUser = (String) JoistProperties.getProperty("databaseUser");
	String dbPassword = (String) JoistProperties.getProperty("databasePassword");

	String[] env = {"HTDOC_ROOT=" + htdoc_root, 
			"SANDBOX="+sandbox, 
			"DATABASE_NAME=" + dbName,
			"DATABASE_USER=" + dbUser,
			"DATABASE_PASSWORD=" + dbPassword
	};

	Runtime rt = Runtime.getRuntime();
	Process pr;
	int exitCode;
d106 1
d108 5
a112 4
	    args[0] = sandbox + script_dir + args[0];
	    pr = rt.exec(args, env);
	} catch (IOException e) {
	    throw new UpdateException("IO error while running script.");
d114 2
a115 9
        
	try {
	    exitCode = pr.waitFor();
	} catch (InterruptedException e) {
	    throw new UpdateException("Script was interrupted.");
	}
	if (pr.exitValue() != 0) {
	    throw new UpdateException("Script had non-zero exit value " 
				      + new Integer(exitCode).toString());
d117 1
a117 122

    }

    //////////////////////////////////////////////////////////////////
    // Issuezilla synchronization.
    //////////////////////////////////////////////////////////////////

    /**
     * Reflects the effects of a grant on a projectID to a userID.
     */
    public static void reflectGrant(DataManager dMgr,
                                    Connection connection, 
                                    String userID,
                                    String projectID)
        throws DataSetException, SQLException, UpdateException, 
               JoistDatabaseException
    {
        ArrayList affectedUsers = TigrisUpdate
            .expandUser(dMgr, connection, userID);
        ArrayList affectedProjects = TigrisUpdate
            .expandProject(dMgr, connection, projectID);
        TigrisUpdate.findNewMembers(affectedUsers, affectedProjects);
    }

    /**
     * Runs addMember on users who have permissions in the given
     * projects.
     */
    public static void findNewMembers(ArrayList affectedUsers, 
                                      ArrayList affectedProjects)
        throws DataSetException, UpdateException
    {        
        //For each project...
        for (Iterator j = affectedProjects.iterator(); j.hasNext();)
        {
            //We're going to build two lists of users: one of users with
            //regular access and one of users with admin access.
            
            //Get the project information.
            ArrayList currentProjectInfo = (ArrayList)j.next();
            String domainName = (String)currentProjectInfo.get(0);
            String projectName = (String)currentProjectInfo.get(1);
            String projectID = (String)currentProjectInfo.get(2);
            String brandName = (String)currentProjectInfo.get(3);
            String role = null;

            if (debug) log.info("Processing project " + projectName);

            ArrayList adminUserRealNames = new ArrayList();
            ArrayList adminUserUsernames = new ArrayList();
            ArrayList normalUserRealNames = new ArrayList();
            ArrayList normalUserUsernames = new ArrayList();            
            
            //For each user...
            for (Iterator i = affectedUsers.iterator(); i.hasNext();)
            {
                //Get their ACL and user information.
                ArrayList userInfo = (ArrayList)i.next();
                AccessControlList currentACL = (AccessControlList)
                    userInfo.get(0);
                Record user = (Record) userInfo.get(1);
                String userRealName = user.getValue(UserManager.NAME)
                    .toString();
                String userUsername = user.getValue(UserManager.LOGIN_ID)
                    .toString();

                if (debug) log.info(" Processing user " + userRealName);

                //Figure out which role they have on the issue tracker
                //for this project, and put them in the appropriate list.
                if (currentACL.hasPermissionForProject
                    ("Project Issue Tracking - Configure", projectID))
                {
                    if (debug) log.info(" This user is an admin on this project.");
                    adminUserRealNames.add(userRealName);
                    adminUserUsernames.add(userUsername);
                } else if (currentACL.hasPermissionForProject
                           ("Project Issue Tracking - Submit", projectID)) 
                {
                    if (debug) log.info(" This user is a lowly peon on this project.");
                    normalUserRealNames.add(userRealName);
                    normalUserUsernames.add(userUsername);
                } else {
                    if (debug) log.info(" This user has no roles in this project.");
                }
            }
            
            if (normalUserUsernames.size() > 0)
            {
                TigrisUpdate.addMembers(domainName, projectName, 
                                        projectID, brandName, 
                                        normalUserRealNames, 
                                        normalUserUsernames,
                                        "user");
            }

            if (adminUserUsernames.size() > 0)
            {            
                TigrisUpdate.addMembers(domainName, projectName, 
                                        projectID, brandName, 
                                        adminUserRealNames,
                                        adminUserUsernames,
                                        "admin");
            }
        }
    }

    /**
     * Reflects the effects of a revoke on a projectID from a userID.
     */
    public static void reflectRevoke(DataManager dMgr,
                                     Connection connection, 
                                     String userID,
                                     String projectID)
        throws DataSetException, SQLException, UpdateException, 
               JoistDatabaseException
    {
        ArrayList affectedUsers = TigrisUpdate
            .expandUser(dMgr, connection, userID);
        ArrayList affectedProjects = TigrisUpdate
            .expandProject(dMgr, connection, projectID);
        TigrisUpdate.findExMembers(affectedUsers, affectedProjects);
a118 217


    /**
     * Runs deleteMember for users who don't have permissions in
     * the given projects.
     */
    public static void findExMembers(ArrayList affectedUsers,
                                     ArrayList affectedProjects)
        throws DataSetException, UpdateException
    {
        //For each project...
        for (Iterator j = affectedProjects.iterator(); j.hasNext();)
        {
            //We're going to make a list of users who no longer have any
            //relevant permissions in this project.
            
            //Get the project information.
            ArrayList currentProjectInfo = (ArrayList)j.next();
            String domainName = (String)currentProjectInfo.get(0);
            String projectName = (String)currentProjectInfo.get(1);
            String projectID = (String)currentProjectInfo.get(2);
            String brandName = (String)currentProjectInfo.get(3);
            String role = null;

            ArrayList deletedUserUsernames = new ArrayList();

            //For each user...
            for (Iterator i = affectedUsers.iterator(); i.hasNext();)
            {
                //Get their ACL and user information.
                ArrayList userInfo = (ArrayList)i.next();
                AccessControlList currentACL = (AccessControlList)
                    userInfo.get(0);
                Record user = (Record) userInfo.get(1);
                String tuserUsername = user.getValue(UserManager.LOGIN_ID)
                    .toString();

                //Figure out which role they have on the issue tracker
                //for this project, and put them in the appropriate list.
                if (!currentACL.hasPermissionForProject
                    ("Project Issue Tracking - Configure", projectID)
                    && !currentACL.hasPermissionForProject
                    ("Project Issue Tracking - Submit", projectID))
                {
                    deletedUserUsernames.add(tuserUsername);
                }
            }

            TigrisUpdate.deleteMembers(domainName, projectName, 
                                       projectID, brandName, 
                                       deletedUserUsernames);
        }
    }

    /**
     * Get the data structure for every user corresponding to the
     * given userID.
     */    
    public static ArrayList expandUser(DataManager dMgr,
                                Connection connection, 
                                String userID)
        throws DataSetException, SQLException, JoistDatabaseException
    {
        ArrayList affectedUsers = new ArrayList();

        UserManager uMgr = (UserManager) dMgr.getManager
            ("org.joist.database.UserManager");
        UserUserGroupManager usrGrpMgr = (UserUserGroupManager) dMgr.getManager
            ("org.tigris.helm.database.UserUserGroupManager");

        //Get info data structures for all users represented by the
        //given userID.
        DataSet usersForUserID = usrGrpMgr
            .getBasesForComposite(connection, userID);
        
        if (usersForUserID.size() == 0)
        {
            Record user = uMgr.getUser(connection, userID);
            affectedUsers.add(getUserInfo(dMgr, connection, user));
        } else {
            for (int i = 0; i < usersForUserID.size(); i++)
            {
                affectedUsers.add(getUserInfo(dMgr, connection, 
                                              usersForUserID.getRecord(i)));
            }
        }
        return affectedUsers;
    }

    /**
     * Get the data structure for every user corresponding to the
     * given projectID.
     */    
    public static ArrayList expandProject(DataManager dMgr,
                                          Connection connection, 
                                          String projectID)
        throws DataSetException, SQLException, JoistDatabaseException
    {
        ArrayList affectedProjects = new ArrayList();

        ProjectManager pMgr = (ProjectManager) dMgr.getManager
            ("org.tigris.helm.database.ProjectManager");
        
        ProjectProjectGroupManager prjGrpMgr = (ProjectProjectGroupManager) 
            dMgr.getManager
            ("org.tigris.helm.database.ProjectProjectGroupManager");
        
        //Get info for all projects represented by the given projectID.
        DataSet projectsForProjectID = prjGrpMgr
            .getBasesForComposite(connection, projectID);
        
        String domainName = null;
        ArrayList projectInfo = new ArrayList();
        
        if (projectsForProjectID.size() == 0)
        {
            Record project = pMgr.getProjectForID(connection, projectID);
            projectInfo = TigrisUpdate.getProjectInfo(dMgr, connection, 
                                                      project, domainName);
            domainName = (String)projectInfo.get(0);
            affectedProjects.add(projectInfo); 
        } else {
            for (int i = 0; i < projectsForProjectID.size(); i++)
            {
                projectID = projectsForProjectID.getRecord(i)
                    .getValue(ProjectProjectGroupManager
                              .PROJECT_ID).toString();
                Record project = pMgr.getProjectForID(connection, projectID);
                projectInfo = TigrisUpdate.getProjectInfo(dMgr, connection, 
                                                          project, domainName);
                if (i == 0)
                {
                    domainName = (String)projectInfo.get(0);
                }
                affectedProjects.add(projectInfo);                
            }
        }
        return affectedProjects;
    }

    /**
     * Helper method to gather user information used by every
     * script.
     */
    public static ArrayList getUserInfo(DataManager dMgr, 
                                           Connection connection,
                                           String userID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        UserManager uMgr = (UserManager)dMgr.getManager
            ("org.joist.database.UserManager");
        Record user = uMgr.getUser(connection, userID);
        return getUserInfo(dMgr, connection, user);
    }

    /**
     * Helper method to turn user record into proper data structure.
     */
    public static ArrayList getUserInfo(DataManager dMgr,
                                        Connection connection,
                                        Record user)
        throws DataSetException, SQLException, JoistDatabaseException
    {               
        ArrayList userInfo = new ArrayList();
        String userID = user.getValue(UserManager.USER_ID).toString();
        userInfo.add(new AccessControlList(connection, dMgr, userID));
        userInfo.add(user);                
        return userInfo;
    }

    /**
     * Helper method to turn project record into proper data structure.
     */
    public static ArrayList getProjectInfo(DataManager dMgr, 
                                           Connection connection,
                                           Record project, String domainName)
        throws DataSetException, SQLException, JoistDatabaseException
    {               
        String projectName = null;
        String projectID = null;
        String brandName = null;
        
        if (domainName == null)
        {
            DomainManager domMgr = (DomainManager) dMgr.getManager
                ("org.tigris.helm.database.DomainManager");
            
            domainName = domMgr.getDomainName
                (project.getValue(ProjectManager.PROJECT_DOMAIN_ID).toString());
        }
        projectID = project.getValue(ProjectManager.PROJECT_ID).toString();
        projectName = project.getValue(ProjectManager.PROJECT_NAME).toString();

        ArrayList projectInfo = new ArrayList();
        projectInfo.add(domainName);
        projectInfo.add(projectName);
        projectInfo.add(projectID);
        projectInfo.add(brandName);
        return projectInfo;

    }

    /**
     * Helper method to gather project information used by every
     * script.
     */
    public static ArrayList getProjectInfo(DataManager dMgr, 
                                           Connection connection,
                                           String projectID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        ProjectManager pMgr = (ProjectManager)dMgr.getManager
            ("org.tigris.helm.database.ProjectManager");
        Record project = pMgr.getProjectForID(connection, projectID);
        return getProjectInfo(dMgr, connection, project, null);
    }

@


