head	1.10;
access;
symbols
	TIGRIS_0_9_2_4:1.5
	TIGRIS_0_9_2_3:1.5
	HELM_PEER_PORT_BRANCH:1.8.0.2
	TURBINE_PEER:1.8
	TIGRIS_0_9_2_1:1.8
	TIGRIS_0_9_2:1.5.0.2;
locks; strict;
comment	@# @;


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

1.9
date	2001.02.21.05.36.24;	author edk;	state Exp;
branches;
next	1.8;

1.8
date	2001.01.26.18.29.09;	author edk;	state Exp;
branches
	1.8.2.1;
next	1.7;

1.7
date	2001.01.26.05.24.08;	author edk;	state dead;
branches;
next	1.6;

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

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

1.4
date	2001.01.05.22.41.36;	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.28.01.02.19;	author dlr;	state dead;
branches;
next	;


desc
@@


1.10
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.apache.turbine.util.Log;

import org.joist.database.*;

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

/**
 * IssueTrackingAccountMap is a convenience class used for determining
 * which scripts to run for a project. It maps Users to Strings
 * describing Roles.
 *
 * It looks like:
 *  User1 -> "Role1"
 *  User2 -> "Role1"
 *  User3 -> "Role2"
 *  
 */
public class IssueTrackingAccountMap extends HashMap
{

    static private boolean DEBUG = true;
    
    private Project project;
    
    /**
     * Construct an IssueTrackingAccountMap for the given project and
     * the given users.
     */
    public IssueTrackingAccountMap(Project p, List users)
        throws Exception
    {
        project = p;

        for (Iterator i = users.iterator(); i.hasNext();)
        {
            User u = (User)i.next();
            String acct = u.issueTrackingAccountType(project);
            if (!acct.equals("")) 
            {
                put(u, acct);
            }
        }        
    }

    public IssueTrackingAccountMap(Project p)
    {
	project = p;
    }

    public String accountType(User u)
    {
        String acctType = "";
        for (Iterator i = keySet().iterator(); i.hasNext();)
        {
            User x = (User)i.next();
            if (x.equals(u))
            {
                acctType = (String)get(x);
            }
        }
        return acctType;
    }

    /**
     * Dumps the map to the log.
     */
    public String dump()
    {
	StringBuffer s = new StringBuffer();
        for (Iterator i = keySet().iterator(); i.hasNext();)
        {
            User u = (User)i.next();
            s.append("  User ").append(u.getLoginName())
                .append(" has role ").append((String)get(u)).append("\n");
        }
	return s.toString();
    }

    /**
     * Runs whatever scripts are neccessary to bridge the delta between this
     * IssueTrackingAccountMap and another (assumed to be more recent).     
     */
    public void syncTo(Connection connection, DataManager dMgr,
		       IssueTrackingAccountMap newMap, User onBehalfOf)
	throws Exception
    {
	if (newMap == null)
	{
	    newMap = new IssueTrackingAccountMap(project);
	}

        List usersToDelete = usersLosingAccounts(newMap);
        Map scriptsToRun = usersChangingAccounts(newMap);

        for (Iterator i = scriptsToRun.keySet().iterator(); i.hasNext();)
	{
	    String type = (String)i.next();
            if (DEBUG)
                Log.info("Considering accounts of type " + type);
            List list = (List)scriptsToRun.get(type);
            for (Iterator j = list.iterator(); j.hasNext();)
            {
                User u = (User)j.next();
                if (DEBUG)
                    Log.info("Giving " + u.getLoginName() + " a " +
                            type + " account.");
                // TODO : FIXME
                //TigrisUpdate.addMember(connection, dMgr, onBehalfOf,
                //        project, u, type);
            }
        }

        for (Iterator i = usersToDelete.iterator(); i.hasNext();)
        {
            User u = (User)i.next();
            if (DEBUG)
                Log.info("Deleting " + u.getLoginName()); 
            // TODO: FIXME
            //TigrisUpdate.deleteMember(connection, dMgr, onBehalfOf, project, u);
        }
    }

    /**
     * Returns a list of users who have an account in the current
     * map but not in the new map.
     */
    public List usersLosingAccounts(IssueTrackingAccountMap newMap)
    {
        List usersToDelete = new ArrayList();
        for (Iterator i = keySet().iterator(); i.hasNext();)
        {
            User u = (User)i.next();
            String oldAcct = (String)get(u);
            if (!oldAcct.equals(""))
            {
                String newAcct = newMap.accountType(u);
                if (newAcct.equals(""))
                {
                    usersToDelete.add(u);
                }
            }
        }
        return usersToDelete;
    }

    /**
     * Returns a Map of users who get a different account in the new
     * IssueTrackingAccountMap (or who don't have an account in this
     * one at all, and who do in the new one).  
     */
    public Map usersChangingAccounts(IssueTrackingAccountMap newMap)
    {
        Map changedAccounts = new HashMap();
        for (Iterator i = newMap.keySet().iterator(); i.hasNext();)
        {
            User u = (User)i.next();
            String oldAccountType = accountType(u);
            String newAccountType = newMap.accountType(u);
            if (!newAccountType.equals(oldAccountType))
            {
                if (!changedAccounts.containsKey(newAccountType))
                {
                    changedAccounts.put(newAccountType, new ArrayList());
                }
            
                List usersWithAccountType = 
                    (List)changedAccounts.get(newAccountType);
                usersWithAccountType.add(u);
                changedAccounts.put(newAccountType, usersWithAccountType);
            }
        }
        return changedAccounts;
    }    
}
@


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


1.8
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d56 1
a56 3
import org.webmacro.util.Log;

import com.workingdogs.village.DataSetException;
d60 2
a61 2
import org.tigris.helm.project.Project;
import org.tigris.helm.domain.User;
d77 1
a77 2
    static public Log log = new Log("AcctMap", "Issue Tracking Account Map");
    static private boolean debug = true;
d86 1
a86 1
        throws DataSetException, SQLException, JoistDatabaseException
a123 1
        throws DataSetException
d129 2
a130 2
            s.append("  User " + u.getName() + " has role " + (String)get(u))
		.append("\n");
d141 1
a141 1
	throws DataSetException, SQLException, JoistDatabaseException
d154 2
a155 1
            log.info("Considering accounts of type " + type);
d160 6
a165 2
                log.info("Giving " + u.getName() + " a " + type + " account.");
                TigrisUpdate.addMember(connection, dMgr, onBehalfOf, project, u, type);
d172 4
a175 2
            log.info("Deleting " + u.getName()); 
            TigrisUpdate.deleteMember(connection, dMgr, onBehalfOf, project, u);
a183 1
    throws DataSetException
@


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


1.7
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;
d89 1
a89 1
        throws DBException
d127 1
a127 1
        throws DBException
d145 1
a145 1
	throws DBException
d181 1
a181 1
        throws DBException
@


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


1.5
log
@MemberDelete actions are caused properly on a sync.
@
text
@d62 1
d90 1
a90 1
        throws DataSetException, SQLException, JoistDatabaseException
d128 1
a128 1
        throws DataSetException
d146 1
a146 1
	throws DataSetException, SQLException, JoistDatabaseException
d182 1
a182 1
    throws DataSetException
@


1.4
log
@Actually run the scripts.
@
text
@d190 1
a190 1
                String newAcct = accountType(u);
@


1.3
log
@Big patch bringing the smart script runner online.
@
text
@d164 1
d172 1
a172 2
            //TigrisUpdate.deleteMember(connection, dMgr, onBehalfOf,
            //project, u);
@


1.2
log
@Big patch implementing a pilot test of the smart 'determine which scripts to run' system.
@
text
@d97 4
a100 1
            put(u, acct);
a101 1
	dump();
d109 14
d158 1
d160 1
a160 1
            if (list.size() > 0)
d162 2
a163 5
                for (Iterator j = list.iterator(); j.hasNext();)
                {
                    User u = (User)j.next();
                    log.info(" " + u.getName());
                }
d167 1
a167 1
        if (usersToDelete.size() > 0)
d169 4
a172 6
            for (Iterator i = usersToDelete.iterator(); i.hasNext();)
            {
                User u = (User)i.next();
		TigrisUpdate.deleteMember(connection, dMgr, onBehalfOf,
					  project, u);
            }
d181 1
d187 2
a188 1
            if (!newMap.containsKey(u))
d190 5
a194 2
                //They no longer have any account in this project.
                usersToDelete.add(u);
d211 2
a212 7
            String oldAccountType = "";
            String newAccountType = (String)newMap.get(u);
            if (containsKey(u))
            {
                oldAccountType = (String)get(u);
            }

@


1.1
log
@Moved functionality out of TigrisUpdate into new classes.
@
text
@d60 1
a60 1
import org.joist.database.JoistDatabaseException;
d83 1
a83 1

d92 1
d99 6
d110 1
a110 1
    public void dump()
d113 1
d117 2
a118 1
            log.info("  User " + u.getName() + " has role " + (String)get(u));
d120 1
d127 3
a129 2
    public void syncTo(IssueTrackingAccountMap newMap)
    throws DataSetException
d131 5
d138 1
a138 3
        
        //Don't run the scripts yet; just print out which scripts would
        //have been run.
d140 2
a141 3
        {
            String type = (String)i.next();
            log.info("Considering users with role type " + type);
a144 2
                log.info("Running MemberAdd " + project.getName() + " " + type 
                         + " for the following users: ");                     
a154 2
            log.info("Running MemberDelete " + project.getName()
                     + " for the following users: ");
d158 2
a159 1
                log.info(" " + u.getName());
@

