head	1.16;
access;
symbols
	TIGRIS_0_9_2_4:1.8.2.2
	TIGRIS_0_9_2_3:1.8.2.2
	HELM_PEER_PORT_BRANCH:1.11.0.2
	TURBINE_PEER:1.11
	TIGRIS_0_9_2_1:1.11
	TIGRIS_0_9_2:1.8.0.2;
locks; strict;
comment	@# @;


1.16
date	2001.02.21.16.31.36;	author edk;	state dead;
branches;
next	1.15;

1.15
date	2001.02.21.05.36.24;	author edk;	state Exp;
branches;
next	1.14;

1.14
date	2001.02.21.05.06.13;	author edk;	state Exp;
branches;
next	1.13;

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

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

1.11
date	2001.01.26.18.29.09;	author edk;	state Exp;
branches
	1.11.2.1;
next	1.10;

1.10
date	2001.01.26.05.24.08;	author edk;	state dead;
branches;
next	1.9;

1.9
date	2001.01.24.20.42.49;	author dlr;	state Exp;
branches;
next	1.8;

1.8
date	2001.01.15.19.15.05;	author leonardr;	state Exp;
branches
	1.8.2.1;
next	1.7;

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

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

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

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

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

1.2
date	2001.01.05.00.13.14;	author kmaples;	state Exp;
branches;
next	1.1;

1.1
date	2001.01.04.16.56.27;	author leonardr;	state Exp;
branches;
next	;

1.8.2.1
date	2001.01.30.00.36.21;	author leonardr;	state Exp;
branches;
next	1.8.2.2;

1.8.2.2
date	2001.01.31.03.55.31;	author leonardr;	state Exp;
branches;
next	1.8.2.3;

1.8.2.3
date	2001.03.07.17.41.36;	author leonardr;	state Exp;
branches;
next	;

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


desc
@@


1.16
log
@these were moved to org.tigris.helm.tool.task
@
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.joist.database.*;

import org.apache.turbine.util.Log;
import org.apache.turbine.util.TurbineException;

import org.tigris.helm.om.Project;
import org.tigris.helm.om.User;
import org.tigris.helm.DoesNotExist;

/**
 * IssueTrackingAccountDescriptor is a convenience class used for determining
 * which scripts to run for a set of projects. It maps Projects to
 * IssueTrackingAccountMaps.
 *
 * It looks like:
 *  Project1 -> IssueTrackingAccountMap1
 *  Project2 -> IssueTrackingAccountMap2
 *  Project3 -> IssueTrackingAccountMap3
 *  
 */
public class IssueTrackingAccountDescriptor extends HashMap
{

    static private boolean DEBUG = true;

    /**
     * Construct an IssueTrackingAccountDescriptor representing a blank slate.
     */
    public IssueTrackingAccountDescriptor()
    {
    }

    /**
     * Construct an IssueTrackingAccountDescriptor for the given project and 
     * user.
     */
    public IssueTrackingAccountDescriptor(Project project)
        throws Exception, DoesNotExist
    {
        //All users in this domain, and all users in the host domain
        //are affected.
	List users = new ArrayList();
        users.addAll(project.getDomain().getHost().getSpecialUser().expand());
        users.addAll(project.getDomain().getSpecialUser().expand());

	buildDescriptor(project.expand(), users);
    }

    /**
     * Construct an IssueTrackingAccountDescriptor for the given projects and 
     * user.
     */
    public IssueTrackingAccountDescriptor(List projects, User user)
        throws Exception, DoesNotExist
    {
	buildDescriptor(projects, user.expand());
    }


    /**
     * Construct an IssueTrackingAccountDescriptor for the given project and 
     * user.
     */
    public IssueTrackingAccountDescriptor(Project project, User user)
        throws Exception
    {
	List projects = project.expand();
	List users = user.expand();
	buildDescriptor(projects, users);
    }
    
    /**
     * Construct an IssueTrackingAccountDescriptor for the given projects and
     * users.
     */
    public IssueTrackingAccountDescriptor(List projects, List users)
        throws Exception
    {
	buildDescriptor(projects, users);
    }

    private void buildDescriptor(List projects, List users)
	throws Exception
    {
        //Expand out all the projects and users first.
        List expandedProjects = new ArrayList();
        for (Iterator i = projects.iterator(); i.hasNext();)
        {
            Project p = (Project)i.next();
            expandedProjects.addAll(p.expand());
        }

        List expandedUsers = new ArrayList();
        for (Iterator i = users.iterator(); i.hasNext();)
        {
            User u = (User)i.next();
            try {
                expandedUsers.addAll(u.expand());
            } catch (DoesNotExist e) {
                throw new TurbineException("Could not expand user " +
                        u.getLoginName(), e);
            }
        }

        StringBuffer s = new StringBuffer();
        s.append("\nI am building a descriptor.\n")
            .append(" ").append(expandedProjects.size()).append(" projects, ")
            .append(expandedUsers.size()).append(" users.");

        for (Iterator i = expandedProjects.iterator(); i.hasNext();)
        {
            Project p = (Project)i.next();
            //s.append(p.getName()).append(" ");
            IssueTrackingAccountMap m = new IssueTrackingAccountMap(p, expandedUsers);
            put(p,m);
        }        

        /*s.append("\n ").append(users.size()).append(" Users. ");
        for (Iterator i = users.iterator(); i.hasNext();)
        {
            User u = (User)i.next();
            s.append(u.getName()).append(" ");
            }*/

        if (DEBUG)
            Log.info(s.toString());
    }

    /**
     * Dumps the descriptor to the log.
     */
    public String dump()
    {
	StringBuffer s = new StringBuffer();
        for (Iterator i = keySet().iterator(); i.hasNext();)
        {
            Project p = (Project)i.next();
            s.append(" Dump of IssueTrackingAccountMap for project " + p.getName() + "\n");
            IssueTrackingAccountMap m = (IssueTrackingAccountMap)get(p);
            s.append(m.dump());
        }
	return s.toString();
    }

    /**
     * Runs whatever scripts are neccessary to bridge the delta
     * between this IssueTrackingAccountDescriptor and another
     * (assumed to be more recent).  
     */
    public void syncTo(Connection connection, DataManager dMgr, 
		       IssueTrackingAccountDescriptor newDesc, User onBehalfOf)
        throws Exception
    {
        StringBuffer s = new StringBuffer();
        s.append("Syncing descriptors.\n").append("Old descriptor:")
            .append(dump())
            .append("\nNew descriptor:").append(newDesc.dump());
        if (DEBUG)
            Log.info(s.toString());

        //Make sure the old descriptor has all the projects in the 
        //new descriptor.
        for (Iterator i = newDesc.keySet().iterator(); i.hasNext();)
        {
            Project p = (Project)i.next();
            if (!containsProject(p))
            {
                IssueTrackingAccountMap m = new IssueTrackingAccountMap(p);
                put(p,m);
            }            
        } 

        for (Iterator i = keySet().iterator(); i.hasNext();)
        {
            Project p = (Project)i.next();
            IssueTrackingAccountMap map1 =  (IssueTrackingAccountMap)get(p);
            IssueTrackingAccountMap map2 = newDesc.getMapForProject(p);
            if (DEBUG)
                Log.debug("Syncing maps for project " + p.getName());
	    map1.syncTo(connection, dMgr, map2, onBehalfOf);
        }
    }

    public boolean containsProject(Project p)
    {
        boolean c = false;
        for (Iterator i = keySet().iterator(); i.hasNext();)
        {
            Project p2 = (Project)i.next();
            if (p.equals(p2))
            {
                c = true;
                break;
            }
        }
        return c;
    }

    public IssueTrackingAccountMap getMapForProject(Project p)
    {
        IssueTrackingAccountMap m = null;
        for (Iterator i = keySet().iterator(); i.hasNext();)
        {
            Project p2 = (Project)i.next();
            if (p.equals(p2))
            {
                m = (IssueTrackingAccountMap)get(p2);
                break;
            }
        }
        return m;
    }

    public void syncTo(Connection connection, DataManager dMgr, 
		       IssueTrackingAccountDescriptor newDesc)
        throws Exception
    {
        syncTo(connection, dMgr, newDesc, null);
    }
}
@


1.15
log
@fix imports, exceptions, and use turbine logging
@
text
@@


1.14
log
@fix import and throws
@
text
@d56 1
a56 1
import org.webmacro.util.Log;
d58 2
a59 1
import org.joist.database.*;
d79 1
a79 2
    static public Log log = new Log("AcctDesc", "Issue Tracking Account Descriptor");
    static private boolean debug = true;
d120 1
a120 2
        throws DataSetException, SQLException, JoistDatabaseException,
	       DoesNotExist
d132 1
a132 1
        throws DataSetException, SQLException, JoistDatabaseException
d138 1
a138 1
	throws DataSetException, SQLException, JoistDatabaseException
d155 2
a156 1
                throw new JoistDatabaseException("Could not expand user " + u.getName());
d180 2
a181 1
        log.info(s.toString());
a187 1
        throws DataSetException
d207 1
a207 1
        throws DataSetException, SQLException, JoistDatabaseException
d213 2
a214 1
        log.info(s.toString());
d233 2
a234 1
	    log.info("Syncing maps for project " + p.getName());
d271 1
a271 1
        throws DataSetException, SQLException, JoistDatabaseException
@


1.13
log
@Expand out projects and users before making use of them in descriptors.
@
text
@a57 2
import com.workingdogs.village.DataSetException;

d60 2
a61 2
import org.tigris.helm.project.Project;
import org.tigris.helm.domain.User;
d93 1
a93 2
        throws DataSetException, SQLException, JoistDatabaseException,
	       DoesNotExist
d109 1
a109 2
        throws DataSetException, SQLException, JoistDatabaseException,
	       DoesNotExist
@


1.12
log
@Explicitly use project.equals() rather than rely onhashtable object comparisons.
@
text
@d145 19
d166 2
a167 2
            .append(" ").append(projects.size()).append(" projects, ")
            .append(users.size()).append(" users.");
d169 1
a169 1
        for (Iterator i = projects.iterator(); i.hasNext();)
d173 1
a173 1
            IssueTrackingAccountMap m = new IssueTrackingAccountMap(p, users);
@


1.11
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d205 1
a205 1
            if (!containsKey(p))
d216 28
a243 2
            IssueTrackingAccountMap map2 = null;
            if (newDesc.containsKey(p))
d245 2
a246 1
		map2 = (IssueTrackingAccountMap)(newDesc.get(p));
a247 2
	    log.info("Syncing maps for project " + p.getName());
	    map1.syncTo(connection, dMgr, map2, onBehalfOf);
d249 1
@


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


1.10
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
@a61 1
import org.tigris.helm.database.DBException;
d95 2
a96 1
        throws DoesNotExist, DBException
d112 1
a112 1
        throws DBException,
d124 1
a124 1
        throws DBException,
d137 1
a137 1
        throws DBException
d143 1
a143 1
	throws DBException
d172 1
a172 1
        throws DBException
d178 1
a178 2
            s.append(" Dump of IssueTrackingAccountMap for project ");
            s.append(p.getName()).append('\n');
d192 1
a192 1
        throws DBException
d228 1
a228 1
        throws DBException
@


1.9
log
@Making use of DBException.
@
text
@@


1.8
log
@MemberDelete actions are caused properly on a sync.
@
text
@d62 1
d96 1
a96 2
        throws DataSetException, SQLException, JoistDatabaseException,
	       DoesNotExist
d112 1
a112 1
        throws DataSetException, SQLException, JoistDatabaseException,
d124 1
a124 1
        throws DataSetException, SQLException, JoistDatabaseException,
d137 1
a137 1
        throws DataSetException, SQLException, JoistDatabaseException
d143 1
a143 1
	throws DataSetException, SQLException, JoistDatabaseException
d172 1
a172 1
        throws DataSetException
d178 2
a179 1
            s.append(" Dump of IssueTrackingAccountMap for project " + p.getName() + "\n");
d193 1
a193 1
        throws DataSetException, SQLException, JoistDatabaseException
d229 1
a229 1
        throws DataSetException, SQLException, JoistDatabaseException
@


1.8.2.1
log
@Porting changes from HEAD into branch.
@
text
@d205 1
a205 1
            if (!containsProject(p))
d216 5
a220 1
            IssueTrackingAccountMap map2 = newDesc.getMapForProject(p);
a223 30
    }

    public boolean containsProject(Project p)
    {
        boolean c = false;
        for (Iterator i = keySet().iterator(); i.hasNext();)
        {
            Project p2 = (Project)i.next();
            if (p.equals(p2))
            {
                c = true;
                break;
            }
        }
        return c;
    }

    public IssueTrackingAccountMap getMapForProject(Project p)
    {
        IssueTrackingAccountMap m = null;
        for (Iterator i = keySet().iterator(); i.hasNext();)
        {
            Project p2 = (Project)i.next();
            if (p.equals(p2))
            {
                m = (IssueTrackingAccountMap)get(p2);
                break;
            }
        }
        return m;
@


1.8.2.2
log
@Ported in changes that cause new users to be properly added to Issuezilla when user groups have IZ roles in project groups.
@
text
@a144 19
        //Expand out all the projects and users first.
        List expandedProjects = new ArrayList();
        for (Iterator i = projects.iterator(); i.hasNext();)
        {
            Project p = (Project)i.next();
            expandedProjects.addAll(p.expand());
        }

        List expandedUsers = new ArrayList();
        for (Iterator i = users.iterator(); i.hasNext();)
        {
            User u = (User)i.next();
            try {
                expandedUsers.addAll(u.expand());
            } catch (DoesNotExist e) {
                throw new JoistDatabaseException("Could not expand user " + u.getName());
            }
        }

d147 2
a148 2
            .append(" ").append(expandedProjects.size()).append(" projects, ")
            .append(expandedUsers.size()).append(" users.");
d150 1
a150 1
        for (Iterator i = expandedProjects.iterator(); i.hasNext();)
d154 1
a154 1
            IssueTrackingAccountMap m = new IssueTrackingAccountMap(p, expandedUsers);
@


1.8.2.3
log
@Since project groups themselves have issue tracking, they should be considered as well as the projects they contain.
@
text
@a150 4
            if (!p.isBase() && !p.isHost() && !p.isDomain())
            {
                expandedProjects.add(p);
            }
@


1.7
log
@Don't throw exceptions when tasks that were going to be deleted are already gone.
@
text
@d158 2
a159 2
        s.append("\n ").append(users.size()).append(" Users. ");
        /*        for (Iterator i = users.iterator(); i.hasNext();)
d163 1
a163 1
            } */       
@


1.6
log
@corrected case--might affect a global search and replace
@
text
@d147 2
a148 1
            .append(" ").append(projects.size()).append(" Projects. ");
@


1.5
log
@Fixes related to IssueTrackingRebuild.
@
text
@d84 1
a84 1
     * Construct an IssueTRackingAccountDescriptor representing a blank slate.
@


1.4
log
@New servlet and support for same: IssueTrackingRebuild
@
text
@a187 5
     *
     * This method operates under the assumption that the Projects
     * specified in both descriptors are the same, and that
     * discrepancies can be ignored. This assumption may not always
     * be valid.
d198 12
@


1.3
log
@Big patch bringing the smart script runner online.
@
text
@d84 7
@


1.2
log
@Big patch implementing a pilot test of the smart 'determine which scripts to run' system.
@
text
@d87 29
d120 3
a122 3
	List affectedProjects = project.expand();
	List affectedUsers = user.expand();
	buildDescriptor(affectedProjects, affectedUsers);
d138 4
d145 1
d149 9
d163 1
a163 1
    public void dump()
d174 1
a174 1
	log.info(s.toString());
d191 6
a196 5
	log.info("Syncing descriptors.");
	log.info("Old descriptor:");
	dump();
	log.info("\nNew descriptor:");
	newDesc.dump();
d209 7
@


1.1
log
@Moved functionality out of TigrisUpdate into new classes.
@
text
@d60 1
a60 1
import org.joist.database.JoistDatabaseException;
d64 1
d82 13
d103 6
d123 1
a123 1
        log.info("Beginning dump of IssueTrackingAccountDescriptor.");
d127 1
a127 1
            log.info(" Dump of IssueTrackingAccountMap for project " + p.getName());
d129 1
a129 1
            m.dump();
d131 1
d144 3
a146 2
    public void syncTo(IssueTrackingAccountDescriptor newDesc)
        throws DataSetException
d148 5
d160 1
a160 5
                map2 =  (IssueTrackingAccountMap)(newDesc.get(p));
            }
            if (map2 != null)
            {
                map1.syncTo(map2);
d162 2
@

