head	1.14;
access;
symbols
	TIGRIS_0_9_2_4:1.10.2.2
	TIGRIS_0_9_2_3:1.10.2.2
	HELM_PEER_PORT_BRANCH:1.13.0.2
	TURBINE_PEER:1.13
	TIGRIS_0_9_2_1:1.13
	TIGRIS_0_9_2:1.10.0.2
	TIGRIS_0_9_0:1.3.0.4
	TIGRIS_0_8_4:1.3.0.2;
locks; strict;
comment	@# @;


1.14
date	2001.02.21.03.23.57;	author edk;	state dead;
branches;
next	1.13;

1.13
date	2001.01.26.18.29.09;	author edk;	state Exp;
branches
	1.13.2.1;
next	1.12;

1.12
date	2001.01.26.05.24.08;	author edk;	state dead;
branches;
next	1.11;

1.11
date	2001.01.25.02.42.47;	author edk;	state Exp;
branches;
next	1.10;

1.10
date	2001.01.17.18.36.19;	author leonardr;	state Exp;
branches
	1.10.2.1;
next	1.9;

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

1.8
date	2001.01.10.20.12.34;	author dlr;	state Exp;
branches;
next	1.7;

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

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

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

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

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

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

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

1.10.2.1
date	2001.01.27.00.25.26;	author stack;	state Exp;
branches;
next	1.10.2.2;

1.10.2.2
date	2001.01.27.01.55.45;	author stack;	state Exp;
branches;
next	;

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


desc
@@


1.14
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.sql.*;
import java.util.*;
import java.io.*;

import org.webmacro.util.Log;

import com.workingdogs.village.*;
import org.joist.database.*;
import org.joist.util.JoistProperties;

import org.tigris.helm.domain.BusinessObject;
import org.tigris.helm.project.Project;
import org.tigris.helm.domain.User;

public class HelmTigrisTask extends TigrisTask
{
    public static String COMPONENT_NAME="Helm";

    public static Log log = new Log("HelmTT", "Helm Tigris Task");

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

    public static final boolean debug = true;

    public HelmTigrisTask (Connection conn, DataManager dMgr, 
                           String onBehalfOf, String affectedObjectID, 
                           String command, ArrayList arguments)
        throws SQLException, DataSetException, Exception
    {
        super(conn, dMgr, onBehalfOf, COMPONENT_NAME, affectedObjectID,
              command, arguments);
    }

    public HelmTigrisTask (Connection conn, DataManager dMgr, Record r)
        throws SQLException, DataSetException
    {
        super(conn, dMgr, r);
    }

    public void runTask() throws UpdateException
    {
        UpdateException ue = null;
        String command = null;
        ArrayList args = null;
        try 
        {
            command = getCommand();
            args = readArgsArray();
        } catch (Exception e) {
            ue = new UpdateException(e.getMessage());
        }

        if (command != null)
        {
            try 
            {
                if (command.equals("Initialize Project Resources"))
                {
                    User user = User.getInstance(conn, dMgr, getOnBehalfOf());
                    //This will just turn this task into a large number
                    //of script-running tasks.
                    Project project = new Project(conn, dMgr, 
                                                  getAffectedObjectID());
                    project.runCreationScripts(user.getACL().getUserID());
                    project.rebuildIssueTracking(user.getACL());
                } else {
                    runScript(command, args);
                }
            } catch (Exception e) {
                //TODO: If this happens, reset the timestamp of the script
                //rather than deleting it.
                ue = new UpdateException(e.getMessage());
            }

            setAsDone(); 

            if (ue != null) 
            { 
                throw ue;                
            }
        }
    }
    
    ///////////////////////////////////////////////////////////////////
    // Script runner.
    ///////////////////////////////////////////////////////////////////
    /**
     * Run a command with a populated environment.
     * @@param command Command to run.
     * @@param argList ArrayList of arguments to pass.
     */
    private static synchronized void runScript
        (String command, ArrayList argList)
        throws UpdateException 
    {
        String args[] = new String[argList.size()+1];
        args[0] = command;
        for (int i = 0; i < argList.size(); i++)
        {
            String arg = (String)argList.get(i);
            args[i+1] = arg;
        }

        //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());
        }
    }
}



@


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


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


1.12
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
@a62 2
import org.tigris.helm.database.DBException;

d74 1
a74 1
    public HelmTigrisTask (DataManager dMgr, 
d77 1
a77 1
        throws DBException, Exception
d79 1
a79 1
        super(dMgr, onBehalfOf, COMPONENT_NAME, affectedObjectID,
d83 2
a84 2
    public HelmTigrisTask (DataManager dMgr, Record r)
        throws DBException
d86 1
a86 1
        super(dMgr, r);
d108 1
a108 1
                    User user = User.getInstance(dMgr, getOnBehalfOf());
d111 1
a111 1
                    Project project = new Project(dMgr, 
@


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


1.10
log
@Allow a special Helm task to initialize  project resources.
@
text
@d63 2
d76 1
a76 1
    public HelmTigrisTask (Connection conn, DataManager dMgr, 
d79 1
a79 1
        throws SQLException, DataSetException, Exception
d81 1
a81 1
        super(conn, dMgr, onBehalfOf, COMPONENT_NAME, affectedObjectID,
d85 2
a86 2
    public HelmTigrisTask (Connection conn, DataManager dMgr, Record r)
        throws SQLException, DataSetException
d88 1
a88 1
        super(conn, dMgr, r);
d110 1
a110 1
                    User user = User.getInstance(conn, dMgr, getOnBehalfOf());
d113 1
a113 1
                    Project project = new Project(conn, dMgr, 
@


1.10.2.1
log
@Moving revision 1.124 into 092 to fix IZ 2156, 'IZ generating 'internal server errors'
@
text
@a62 2
import org.tigris.helm.database.DBException;

d74 1
a74 1
    public HelmTigrisTask (DataManager dMgr, 
d77 1
a77 1
        throws DBException, Exception
d79 1
a79 1
        super(dMgr, onBehalfOf, COMPONENT_NAME, affectedObjectID,
d83 2
a84 2
    public HelmTigrisTask (DataManager dMgr, Record r)
        throws DBException
d86 1
a86 1
        super(dMgr, r);
d108 1
a108 1
                    User user = User.getInstance(dMgr, getOnBehalfOf());
d111 1
a111 1
                    Project project = new Project(dMgr, 
@


1.10.2.2
log
@Reverted to 1.10.  1.11 wasn't wanted at all.  Regards reversion, I couldn't make the '-j' work dispite all the good intentions of #scast and http://cvsbook.red-bean.com/cvsbook.html#The_Fast_Method_Of_Reverting.  In the end, #The_Slow_Method_Of_Reverting worked.  Methinks has something to do w/ being on a branch.  Thats a guess
@
text
@d63 2
d76 1
a76 1
    public HelmTigrisTask (Connection conn, DataManager dMgr, 
d79 1
a79 1
        throws SQLException, DataSetException, Exception
d81 1
a81 1
        super(conn, dMgr, onBehalfOf, COMPONENT_NAME, affectedObjectID,
d85 2
a86 2
    public HelmTigrisTask (Connection conn, DataManager dMgr, Record r)
        throws SQLException, DataSetException
d88 1
a88 1
        super(conn, dMgr, r);
d110 1
a110 1
                    User user = User.getInstance(conn, dMgr, getOnBehalfOf());
d113 1
a113 1
                    Project project = new Project(conn, dMgr, 
@


1.9
log
@Don't throw exceptions when tasks that were going to be deleted are already gone.
@
text
@d106 1
a106 1
                if (command.equals("Rebuild Issue Tracking"))
d113 1
@


1.8
log
@strcmp(), not memory address comparison
@
text
@d123 3
a125 1
            try 
d127 1
a127 3
                setAsDone();
            } catch (Exception e) {
                ue = new UpdateException(e.getMessage());
a128 2

            if (ue != null) { throw ue; }
@


1.7
log
@Fixes related to IssueTrackingRebuild.
@
text
@d106 1
a106 1
                if (command == "Rebuild Issue Tracking")
@


1.6
log
@New servlet and support for same: IssueTrackingRebuild
@
text
@d61 1
d108 1
d113 1
a113 1
                    project.rebuildIssueTracking();
@


1.5
log
@Removed unnecessary getCache() implementations in BusinessObject subclasses and migrated to a factory method for User's primary database key ctor.
@
text
@d58 1
d60 1
d93 2
a94 1
        try {
d98 1
a98 1
            log.exception(e);
d100 1
a100 1
        
d105 11
a115 2
                runScript(command, args);
            } catch (UpdateException e) {
d118 2
a119 2
                ue = e;
            }            
d125 1
a125 1
                log.exception(e);
@


1.4
log
@Propogated object cache interface.
@
text
@a85 5
    protected Dictionary getCache ()
    {
        return null;
    }

@


1.3
log
@Minor formatting changes.
@
text
@d86 5
@


1.2
log
@fix OBOE
@
text
@d136 2
a137 1
            args[i+1] = (String)argList.get(i);
@


1.1
log
@My side of the changes edk made.
@
text
@d134 1
a134 1
        for (int i = 1; i < argList.size(); i++)
d136 1
a136 1
            args[i] = (String)argList.get(i);
@

