head	1.38;
access;
symbols
	TIGRIS_1_1_0RC2:1.27
	TIGRIS_1_1_0RC1:1.27
	TIGRIS_1_1:1.27.0.4
	TIGRIS_1_0_8:1.27
	TIGRIS_1_0_8RC3:1.27
	TIGRIS_1_0_8RC2:1.27
	TIGRIS_1_0_8RC1:1.27
	TIGRIS_1_0_7:1.27
	TIGRIS_1_0_7RC3:1.27
	TIGRIS_1_0_7RC2:1.27
	TIGRIS_1_0_7RC1:1.27
	TIGRIS_1_0_6:1.27
	TIGRIS_1_0_6RC5:1.27
	TIGRIS_1_0_6RC4:1.27
	TIGRIS_1_0_6RC3:1.27
	TIGRIS_1_0_6RC2:1.27
	TIGRIS_1_0_6RC1:1.27
	TIGRIS_1_0_5:1.27
	TIGRIS_1_0_5RC6:1.27
	TIGRIS_1_0_5RC5:1.27
	TIGRIS_1_0_5RC4:1.27
	TIGRIS_1_0_5RC3:1.27
	TIGRIS_1_0_5RC2:1.27
	TIGRIS_1_0_5RC1:1.27
	TIGRIS_1_0_4:1.27
	TIGRIS_1_0_3:1.27
	TIGRIS_1_0_2:1.27
	TIGRIS_1_0_1:1.27
	TIGRIS_1_0:1.27.0.6
	TIGRIS_1_0_0:1.27
	TIGRIS_1_0_0_RC1:1.27.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.23
	TIGRIS_0_9_2_3:1.23
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.25
	TIGRIS_0_9_2_1:1.25
	TIGRIS_0_9_2:1.23.0.2
	TIGRIS_0_9_0:1.22.0.4
	TIGRIS_0_8_4:1.22.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.38
date	2001.08.28.17.45.17;	author leonardr;	state Exp;
branches;
next	1.37;

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

1.36
date	2001.08.11.09.08.01;	author dlr;	state Exp;
branches;
next	1.35;

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

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

1.33
date	2001.07.18.10.05.12;	author dlr;	state Exp;
branches;
next	1.32;

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

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

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

1.29
date	2001.05.23.01.50.09;	author dlr;	state Exp;
branches;
next	1.28;

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

1.27
date	2001.02.21.06.55.40;	author edk;	state Exp;
branches;
next	1.26;

1.26
date	2001.02.21.01.08.21;	author dlr;	state Exp;
branches;
next	1.25;

1.25
date	2001.01.26.18.29.02;	author edk;	state Exp;
branches
	1.25.2.1;
next	1.24;

1.24
date	2001.01.26.05.24.05;	author edk;	state dead;
branches;
next	1.23;

1.23
date	2000.12.26.21.53.34;	author dlr;	state Exp;
branches;
next	1.22;

1.22
date	2000.11.28.23.04.42;	author dlr;	state Exp;
branches;
next	1.21;

1.21
date	2000.11.28.22.46.43;	author dlr;	state Exp;
branches;
next	1.20;

1.20
date	2000.11.28.00.15.10;	author dlr;	state Exp;
branches;
next	1.19;

1.19
date	2000.11.27.22.59.41;	author dlr;	state Exp;
branches;
next	1.18;

1.18
date	2000.11.27.20.46.07;	author dlr;	state Exp;
branches;
next	1.17;

1.17
date	2000.11.27.20.14.51;	author dlr;	state Exp;
branches;
next	1.16;

1.16
date	2000.11.27.20.04.12;	author dlr;	state Exp;
branches;
next	1.15;

1.15
date	2000.11.26.02.19.55;	author dlr;	state Exp;
branches;
next	1.14;

1.14
date	2000.11.23.10.44.34;	author dlr;	state Exp;
branches;
next	1.13;

1.13
date	2000.11.23.09.33.53;	author dlr;	state Exp;
branches;
next	1.12;

1.12
date	2000.11.23.09.31.01;	author dlr;	state Exp;
branches;
next	1.11;

1.11
date	2000.11.23.09.13.26;	author dlr;	state Exp;
branches;
next	1.10;

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

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

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

1.7
date	2000.11.17.20.25.51;	author dlr;	state Exp;
branches;
next	1.6;

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

1.5
date	2000.11.15.23.54.38;	author elicia;	state Exp;
branches;
next	1.4;

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

1.3
date	2000.11.15.19.37.56;	author dlr;	state Exp;
branches;
next	1.2;

1.2
date	2000.11.14.22.49.28;	author elicia;	state Exp;
branches;
next	1.1;

1.1
date	2000.11.12.21.15.33;	author dlr;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2000.11.12.21.15.33;	author dlr;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2001.02.21.00.32.08;	author dlr;	state Exp;
branches;
next	;

1.25.2.1
date	2001.01.28.01.02.17;	author dlr;	state dead;
branches;
next	1.25.2.2;

1.25.2.2
date	2001.02.08.01.29.16;	author dlr;	state Exp;
branches;
next	1.25.2.3;

1.25.2.3
date	2001.02.15.20.50.35;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.38
log
@More methods migrated to ContextAPI.
@
text
@/* ================================================================
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */

package org.tigris.helm.domain;

import java.util.List;
import java.util.Arrays;

import org.apache.commons.util.exception.NestableException;
import org.apache.turbine.util.Log;

import org.apache.velocity.context.Context;

import org.tigris.helm.security.RedirectException;

import org.tigris.helm.AlreadyExists;
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.*;
import org.tigris.helm.security.AccessControlList;
import org.tigris.helm.security.HelmServlet;
import org.tigris.helm.tool.ContextAPI;
import org.tigris.helm.tool.TagValidator;
import org.tigris.helm.tool.audit.AuditLog;

/**
 * Create a new project.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@version $Id: ProjectAdd.java,v 1.37 2001/08/14 00:38:45 dlr Exp $
 */
public class ProjectAdd extends HelmServlet
{
    /**
     * The action which creates a project.
     */
    protected static final String CREATE_PROJECT_ACTION = "Create Project";

    /**
     * A hidden field set the first time the user comes to the screen.
     * Used in setting the default for the isPublic checkbox.
     */
    protected static final String SEEN = "seen";

    /**
     * The project name key.
     */
    protected static final String PROJECT_NAME = "newProjectName";

    /**
     * The ID of the project whose parent this project is.
     */
    private static String PARENT_FIELD="parent";

    /**
     * The brief project description key.
     */
    protected static final String SHORT_DESCRIP = "shortDescription";

    /**
     * The full project description key.
     */
    protected static final String LONG_DESCRIP = "longDescription";

    /**
     * The key whose value indicates whether or not the project should
     * be publically viewable. 
     */
    protected static final String IS_PUBLIC = "isPublic";

    /**
     * The key whose value indicates whether to use the index instead of the
     * description.
     */
    protected static final String USE_INDEX = "useIndex";

    /**
     * The project alias url key.
     */
    protected static final String URL = "url";

    /**
     * The project owner key.
     */
    protected static final String PROJECT_OWNER = "projectOwner";

    /**
     * The project category type key.
     */
    protected static final String SELECTED_CATEGORIES_FIELD
        = "selectedCategories";

    /**
     * The project license key.
     */
    protected static final String LICENSE_ID = "license";

    /**
     * Adds action keys to the context.
     */
    protected String processRequest(Context context)
        throws NestableException, RedirectException
    {
        String templateName = super.processRequest(context);
        
        String action = getAction(context);

        User loginUser = getLoginUser(context);
        Domain domain = getCurrentDomain(context);

        //Get field information.
        String newProjectName = ContextAPI.processRequiredField
            (context, PROJECT_NAME, "Project name");
        String parentID = ContextAPI.processField
            (context, PARENT_FIELD, domain.getID());
        String shortDescription = ContextAPI.processRequiredField
            (context, SHORT_DESCRIP, "Summary");
        String longDescription = ContextAPI.processField
            (context, LONG_DESCRIP);
        
        String licenseID = ContextAPI.processRequiredField
            (context, LICENSE_ID, "License");

        String seen = ContextAPI.processField(context, SEEN);
        String isPublic = ContextAPI.processField(context, IS_PUBLIC);
        String useIndex = ContextAPI.processField(context, USE_INDEX);

        String projectOwner = ContextAPI.processField
            (context, PROJECT_OWNER, getLoginUser(context).getLoginName());
        
        String[] selectedCategories = 
            ContextAPI.getParameterValues(context, SELECTED_CATEGORIES_FIELD);
        if (selectedCategories == null)
        {
            selectedCategories = new String[0];
        }
        context.put(SELECTED_CATEGORIES_FIELD, 
                    Arrays.asList(selectedCategories));

        //Validate all this data.
        TagValidator tagger = new TagValidator();
            
        if (tagger.containsHTML(newProjectName))
        {
            context.put(PROJECT_NAME, TagValidator.escapeHTML(newProjectName));
            ContextAPI.addValidationError
                (context, "Project name contains HTML");
        }

        if (tagger.containsHTML(shortDescription))
        {
            context.put(SHORT_DESCRIP, 
                        TagValidator.escapeHTML(shortDescription));
            ContextAPI.addValidationError(context, "Summary contains HTML");
        }
            
        if (!tagger.validate(longDescription,
                             TagValidator.TEXT_FORMAT_TAGS))
        {
            context.put(LONG_DESCRIP, 
                        TagValidator.escapeHTML(longDescription));
            ContextAPI.addValidationError
                (context, "Invalid HTML or Javascript in description");
        }

        Project parentProject = null;
        License license = null;
        User projectOwnerUser = null;

        try
        {
            try
            {
                parentProject = ProjectPeer.getInstance(parentID);
            }
            catch (DoesNotExist e)
            {
                ContextAPI.addValidationError(context, "Parent project " 
                                              + parentID + " does not exist.");
            }

            if (!Project.isValidName(newProjectName))
            {
                ContextAPI.addValidationError
                    (context, 
                     "You specified an invalid project name. Please read" +
                     " the guidelines beneath the \"Project Name\" field.");
            }
            try
            {
                Project.assertNonexistance(domain, newProjectName);
            }
            catch (AlreadyExists e)
            {
                ContextAPI.addValidationError
                    (context, "Project " + newProjectName + " already exists.");
            }
            
            try
            {
                license = LicensePeer.getInstance(licenseID);
            }
            catch (DoesNotExist e)
            {
                ContextAPI.addValidationError
                    (context, e.getMessage());
            }
            
            try
            {
                projectOwnerUser = UserPeer.getInstanceByIdentifier
                    (domain, projectOwner);
            }
            catch (DoesNotExist e)
            {
                ContextAPI.addValidationError
                    (context, "Designated project owner " + projectOwner 
                     + " does not exist");
            }
            
        }
        catch (Exception e)
        {
            throw new NestableException(e);
        }

        
        if (CREATE_PROJECT_ACTION.equals(action)
            && ContextAPI.isValidUserInput(context))
        {       
            try
            {
                Project project = Project.add(loginUser.getACL(),
                                              parentProject,
                                              newProjectName, 
                                              license,
                                              isPublic,
                                              shortDescription, 
                                              longDescription,
                                              useIndex,
                                              "",  //status
                                              "", //URL 
                                              loginUser, 
                                              projectOwnerUser);

                for (int i = 0; i < selectedCategories.length; i++)
                {
                    Category category = 
                        (Category)ProjectPeer.getInstance
                        (selectedCategories[i]);
                    category.associate(loginUser.getACL(), project);
                }
                
                AuditLog.logEvent
                    (loginUser, domain,
                     "Added " + project.getName() + " project.");

                redirectToURL(context, 
                              project.getProjectPageURL
                              ("ProjectCreated"));
            }
            catch (RedirectException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new NestableException(e);
            }
        }
        return templateName;
    }
}
@


1.37
log
@Removed whitespace.
@
text
@d73 1
a73 1
 * @@version $Id: ProjectAdd.java,v 1.36 2001/08/11 09:08:01 dlr Exp $
d175 1
a175 1
            getParameterValues(context, SELECTED_CATEGORIES_FIELD);
@


1.36
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@d59 3
a61 3
import org.tigris.helm.AlreadyExists; 
import org.tigris.helm.DoesNotExist; 
import org.tigris.helm.om.*; 
d64 1
a64 1
import org.tigris.helm.tool.ContextAPI; 
d66 1
a66 1
import org.tigris.helm.tool.audit.AuditLog; 
d73 1
a73 1
 * @@version $Id: ProjectAdd.java,v 1.35 2001/07/24 18:52:21 leonardr Exp $
a76 1

d283 1
a283 1
                                              useIndex, 
@


1.35
log
@Enabled nested projects for regular projects.
@
text
@d52 1
a52 1
import org.apache.turbine.util.TurbineException;
d73 1
a73 1
 * @@version $Id: ProjectAdd.java,v 1.34 2001/07/24 00:02:27 leonardr Exp $
d146 1
a146 1
        throws TurbineException, RedirectException
d268 1
a268 1
            throw new TurbineException(e);
d312 1
a312 1
                throw new TurbineException(e);
@


1.34
log
@The final pieces of the error handling revolution.
@
text
@d69 1
a69 1
 * Project addition UI commonalities (i.e. context and session keys).
d72 2
a73 1
 * @@version $Id: ProjectAdd.java,v 1.33 2001/07/18 10:05:12 dlr Exp $
d95 5
d158 2
d161 1
a161 1
            (context, SHORT_DESCRIP, "Short description");
d210 1
d213 1
d216 10
d278 1
a278 1
                                              domain,
@


1.33
log
@Ported Joist Redirect*Exception to Helm.
@
text
@d50 1
a50 1
import java.sql.Connection;
d53 1
d59 4
d64 3
a66 1
import org.tigris.helm.tool.ContextAPI;
d72 1
a72 1
 * @@version $Id: ProjectAdd.java,v 1.32 2001/07/17 17:55:45 leonardr Exp $
d74 1
a74 1
abstract class ProjectAdd extends HelmServlet
a75 9
    /**
     * The action which takes the user to the last step.
     */
    protected static final String FINISH = "Finish";

    /**
     * The action which takes the user to the next step.
     */
    protected static final String NEXT_STEP = "Next Step";
d78 1
a78 1
     * The action which takes the user to the previous step.
d80 1
a80 1
    protected static final String PREV_STEP = "Previous Step";
d83 1
a83 1
     * A hidden field set the first time the user comes to screen 2.
d86 1
a86 1
    protected static final String SEEN_SCREEN_2 = "screen2Seen";
a136 20
     * The project profile key.
     */
    protected static final String PROJECT_PROFILE = "projectProfile";

    /**
     * The invitation flag key.
     */
    protected static final String IS_INVITING = "isInviting";

    /**
     * The list of email addresses for invitation recipients key.
     */
    protected static final String INVITE_EMAIL_ADDRS = "inviteEmailAddrs";

    /**
     * The invitation key.
     */
    protected static final String INVITATION = "inviteMessage";

    /**
d139 1
a139 1
    protected String processRequest(Context ctx)
d142 153
a294 4
        String templateName = super.processRequest(ctx);
        ctx.put("prevStep", PREV_STEP);
        ctx.put("nextStep", NEXT_STEP);
        ctx.put("finish", FINISH);
a295 32
    }

    /**
     * Redirects to the servlet handling the previous step.
     */
    protected void redirectToPreviousStep (Context ctx)
        throws RedirectException
    {
        redirectToURL(ctx, myProperties.getProperty("prevStep"));
    }

    /**
     * Redirects to the servlet handling the next step.
     */
    protected void redirectToNextStep (Context ctx)
        throws RedirectException
    {
        redirectToURL(ctx, myProperties.getProperty("nextStep"));
    }

    /**
     * Adds a note to the list of validation errors that the project name was
     * just registerd.
     *
     * @@param validationErrors The list to add to.
     */
    protected final void addProjectNameJustRegistered (Context context)
    {
        ContextAPI.addValidationError
            (context, "The project name you've chosen was just " + 
             "registered.  Please click the back button on " + 
             "your browser and use a different name.");
@


1.32
log
@Porting of domain package to new error handling API.
@
text
@d56 1
a56 1
import org.joist.security.RedirectException;
d65 1
a65 1
 * @@version $Id: ProjectAdd.java,v 1.31 2001/07/05 22:21:38 leonardr Exp $
@


1.31
log
@Licenses are now contained in a database-managed table rather than in a custom Java class (yay!)
@
text
@d59 1
d65 1
a65 1
 * @@version $Id: ProjectAdd.java,v 1.30 2001/06/21 00:22:14 leonardr Exp $
d195 1
a195 1
    protected final void addProjectNameJustRegistered (List validationErrors)
d197 4
a200 3
        validationErrors.add("The project name you've chosen was just " + 
                             "registered.  Please click the back button on " + 
                             "your browser and use a different name.");
@


1.30
log
@Projects can now belong to more than one category.
@
text
@d17 1
a17 1
 * software developed by Collab.Net (http://www.collab.net/)."
d27 1
a27 1
 * permission of Collab.Net.
d64 1
a64 1
 * @@version $Id: ProjectAdd.java,v 1.29 2001/05/23 01:50:09 dlr Exp $
d135 1
a135 1
    protected static final String LICENSE = "license";
@


1.29
log
@Ported Helm from WebMacro to Velocity.
@
text
@d64 1
a64 1
 * @@version $Id: ProjectAdd.java,v 1.28 2001/04/26 16:16:43 leonardr Exp $
d129 2
a130 1
    protected static final String CAT_TYPE_ID = "catTypeID";
@


1.28
log
@Patches I forgot to commit before, for decoupling privateness from proprietariness.
@
text
@d52 3
a54 1
import org.webmacro.servlet.*;
d64 1
a64 1
 * @@version $Id: ProjectAdd.java,v 1.27 2001/02/21 06:55:40 edk Exp $
d159 2
a160 2
    protected String processRequest (Connection conn, WebContext ctx)
        throws HandlerException, RedirectException
d162 1
a162 1
        String templateName = super.processRequest(conn, ctx);
d172 1
a172 1
    protected void redirectToPreviousStep (WebContext ctx)
d181 1
a181 1
    protected void redirectToNextStep (WebContext ctx)
@


1.27
log
@rename projectName to newProjectName to avoid conflicts with HelmServlet's
heuristics for determining the current project
@
text
@d62 1
a62 1
 * @@version $Id: ProjectAdd.java,v 1.26 2001/02/21 01:08:21 dlr Exp $
d82 6
d101 6
@


1.26
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@d62 1
a62 1
 * @@version $Id: ProjectAdd.java,v 1.25.2.3 2001/02/15 20:50:35 leonardr Exp $
d84 1
a84 1
    protected static final String PROJECT_NAME = "projectName";
@


1.25
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d2 1
a2 1
 * Copyright (c) 2000 CollabNet.  All rights reserved.
d17 1
a17 1
 * software developed by Collab.Net (http://www.Collab.Net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d59 1
a59 1
 * Project addition commonalities (i.e. context and session keys).
d62 1
a62 1
 * @@version $Id: ProjectAdd.java,v 1.23 2000/12/26 21:53:34 dlr Exp $
@


1.25.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d62 1
a62 1
 * @@version $Id: ProjectAdd.java,v 1.25 2001/01/26 18:29:02 edk Exp $
@


1.25.2.2
log
@Project addition UI commonalities (i.e. context and session keys).
@
text
@d17 1
a17 1
 * software developed by Collab.Net (http://www.collab.net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d59 1
a59 1
 * Project addition UI commonalities (i.e. context and session keys).
@


1.25.2.3
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d62 1
a62 1
 * @@version $Id: ProjectAdd.java,v 1.25.2.2 2001/02/08 01:29:16 dlr Exp $
@


1.24
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
@@


1.23
log
@Added new key (USE_INDEX constant).
@
text
@d62 1
a62 1
 * @@version $Id: ProjectAdd.java,v 1.22 2000/11/28 23:04:42 dlr Exp $
@


1.22
log
@It's a race to the finish line.
@
text
@d62 1
a62 1
 * @@version $Id: ProjectAdd.java,v 1.21 2000/11/28 22:46:43 dlr Exp $
d95 6
@


1.21
log
@Add the actions to the context.
@
text
@d62 1
a62 1
 * @@version $Id: ProjectAdd.java,v 1.20 2000/11/28 00:15:10 dlr Exp $
d67 5
d145 1
@


1.20
log
@Handle session values used in step 4 correctly.
@
text
@d50 1
d62 1
a62 1
 * @@version $Id: ProjectAdd.java,v 1.19 2000/11/27 22:59:41 dlr Exp $
d130 12
@


1.19
log
@Fixes and default settings for steps 2 and 3.
@
text
@d61 1
a61 1
 * @@version $Id: ProjectAdd.java,v 1.18 2000/11/27 20:46:07 dlr Exp $
d99 5
@


1.18
log
@Corrected build errors.
@
text
@d61 1
a61 1
 * @@version $Id: ProjectAdd.java,v 1.17 2000/11/27 20:14:51 dlr Exp $
d123 1
a123 1
    protected static final String INVITATION = "invitation";
@


1.17
log
@Corrected build errors.
@
text
@d61 1
a61 1
 * @@version $Id: ProjectAdd.java,v 1.16 2000/11/27 20:04:12 dlr Exp $
d106 1
a106 1
     * The default project type key.
d108 6
a113 1
    protected static final String DEF_PROJ_TYPE_KEY = "development";
@


1.16
log
@Modifications to make project addition more wizard-like...small breakage on this commit, will fix immediatly.
@
text
@d49 6
d61 1
a61 1
 * @@version $Id: ProjectAdd.java,v 1.15 2000/11/26 02:19:55 dlr Exp $
d124 1
a124 1
        throws RedirectURLException
d126 1
a126 1
        redirectToURL(myProperties.getProperty(ctx, "prevStep"));
d133 1
a133 1
        throws RedirectURLException
d135 1
a135 1
        redirectToURL(myProperties.getProperty(ctx, "nextStep"));
@


1.15
log
@Added a tad more documentation.
@
text
@d55 1
a55 1
 * @@version $Id: ProjectAdd.java,v 1.14 2000/11/23 10:44:34 dlr Exp $
d100 1
a100 1
     * The project approval time key.
d102 42
a143 1
    protected static final String APPROVAL_TIME = "approvalTime";
@


1.14
log
@Added PROJECT_OWNER context key.
@
text
@d55 1
a55 1
 * @@version $Id: ProjectAdd.java,v 1.13 2000/11/23 09:33:53 dlr Exp $
d69 3
d74 3
d79 3
d84 3
@


1.13
log
@Removed duplicate variable.
@
text
@d55 1
a55 1
 * @@version $Id: ProjectAdd.java,v 1.12 2000/11/23 09:31:01 dlr Exp $
d76 5
@


1.12
log
@Do the right import.
@
text
@d55 1
a55 1
 * @@version $Id: ProjectAdd.java,v 1.11 2000/11/23 09:13:26 dlr Exp $
a75 2

    protected static final String LONG_DESCRIP = "longDescription";
@


1.11
log
@This is not a useable servlet, so we make it abstract.
@
text
@d49 1
a49 1
import org.tigris.helm.HelmServlet;
d55 1
a55 1
 * @@version $Id: ProjectAdd.java,v 1.10 2000/11/23 09:09:21 dlr Exp $
@


1.10
log
@Superclass for all project addition steps.
@
text
@d55 1
a55 1
 * @@version $Id: $
d57 1
a57 1
class ProjectAdd extends HelmServlet
@


1.9
log
@Sync'd w/ method name change.
@
text
@d27 1
a27 1
 * permission of CollabNet.
d49 1
a49 21
import java.util.*;
import java.sql.*;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import javax.servlet.*;
import javax.servlet.http.*;

import org.webmacro.util.*;
import org.webmacro.servlet.*;

import com.workingdogs.village.*;

import org.joist.*;
import org.joist.util.*;
import org.joist.session.SessionManager;
import org.joist.security.RedirectException;

import org.tigris.helm.AlreadyExists;
import org.tigris.helm.database.*;
import org.tigris.helm.security.*;
import org.tigris.helm.project.*;
d52 1
a52 1
 * The first step in adding a new project.  Fill out project information.
d55 1
a55 1
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
d57 1
a57 1
public class ProjectAdd extends org.tigris.helm.security.HelmServlet
a58 2
    public static final  String versionID = "$Id: ProjectAdd.java,v 1.8 2000/11/23 06:19:44 dlr Exp $";

d60 1
a60 1
     * Open the log file.
d62 1
a62 1
    private static Log log = new Log("prjAdd", "ProjectAdd");
d65 1
a65 1
     * Whether to log debugging information.
d67 11
a77 1
    private static boolean debug = true;
d80 1
a80 1
     * Called on servlet startup by the servlet container.
d82 1
a82 4
    public void start () throws ServletException
    {
        super.start();
    }
d85 1
a85 1
     * Display and process the project addition request.
d87 1
a87 95
    protected String processRequest (Connection conn, WebContext context)
        throws HandlerException, RedirectException 
    {
        String templateName = super.processRequest(conn, context);
        HttpSession session = getSessionManager(context).getSession();

        String action = (String)context.get("action");
        if (debug) log.info("action=" + action );

        try
        {
            User loginUser = getLoginUser(context);
            String userID = loginUser.getID();
            String loginID = loginUser.getLoginID();
            context.put("loginID", loginID);

            // If we are returning to this page as a result of an
            // error, we just want to refresh the display, without
            // doing any further action.
            String errorMessage = (String) context.get("Error");
            if (errorMessage != null)
            {
                action = null;
                appendToMessage(context, errorMessage);
            }

            // Gather any user input, adding it to the context as well.
            List missingFields = new ArrayList();
            String projectName = processField(context, "projectName", 
                                              "Project name",
                                              missingFields);
            projectName = projectName.toLowerCase();
            String shortDescription = processField(context, "shortDescription",
                                                   "Short description", 
                                                   missingFields);    
            String longDescription = processField(context, "longDescription",
                                                  "Long description", 
                                                  missingFields);
            String url = processField(context, "url");

            Domain currentDomain = getCurrentDomain(context);

            if (debug) log.debug("step 3");    
            List validationErrors = new ArrayList();
            if (action != null && action.equals("Next Step"))
            {
                if (projectName != null && !Project.isValidName(projectName))
                {
                    validationErrors.add("Project name is invalid.");
                }
                try
                {
                    Project.assertNonexistance(conn, dMgr, 
                                               currentDomain.getID(),
                                               projectName);
                }
                catch (AlreadyExists e)
                {
                    validationErrors.add("Project name already exists.");
                }

                if (isValidUserInput(missingFields, validationErrors))
                {                   
                    session.putValue("projectName", projectName);
                    session.putValue("shortDescription", shortDescription);
                    session.putValue("longDescription", longDescription);
                    session.putValue("url", url);

                    // Send the user to the next project addition step.
                    redirectToURL(context, 
                                  myProperties.getProperty("nextStep"));
                }
                else
                {
                    // Report missing fields and validation errors.
                    reportInvalidUserInput(context, missingFields, 
                                           validationErrors);
                }
            }

        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            log.exception(e);
            String message = e.getMessage();
            if (debug) log.debug(message);
            appendToMessage(context, message);
        }

        return templateName;
    }
@


1.8
log
@Sync'd w/ moved interface.
@
text
@d79 1
a79 1
    public static final  String versionID = "$Id: ProjectAdd.java,v 1.7 2000/11/17 20:25:51 dlr Exp $";
d148 1
a148 2
                if (projectName != null &&
                    !Project.isValidProjectName(projectName))
@


1.7
log
@Sync'd check for project existance w/ new interface.
@
text
@d79 1
a79 1
    public static final  String versionID = "$Id: ProjectAdd.java,v 1.6 2000/11/16 04:26:47 dlr Exp $";
d149 1
a149 1
                    !projMgr.isValidProjectName(projectName))
@


1.6
log
@removed tabs
@
text
@d66 1
d79 1
a79 1
    public static final  String versionID = "$Id: ProjectAdd.java,v 1.5 2000/11/15 23:54:38 elicia Exp $";
d153 7
a159 2
                if (projMgr.assertProjectNonexistance(conn, 
                                                      currentDomain.getID(), projectName))
a197 1

@


1.5
log
@checking to see if project name already exists before you can move on to Step 2
@
text
@d78 1
a78 1
    public static final  String versionID = "$Id: ProjectAdd.java,v 1.4 2000/11/15 19:42:32 dlr Exp $";
d152 3
a154 3
		if (projMgr.assertProjectNonexistance(conn, 
		            currentDomain.getID(), projectName))
	        {
d156 1
a156 1
		}
d160 8
a167 8
		   session.putValue("projectName", projectName);
		   session.putValue("shortDescription", shortDescription);
		   session.putValue("longDescription", longDescription);
		   session.putValue("url", url);

                   // Send the user to the next project addition step.
                   redirectToURL(context, 
                                 myProperties.getProperty("nextStep"));
@


1.4
log
@Added TODO item.
@
text
@d78 1
a78 1
    public static final  String versionID = "$Id: ProjectAdd.java,v 1.3 2000/11/15 19:37:56 dlr Exp $";
d152 5
a156 2

                // TODO: Check to see if the project name is already taken.
@


1.3
log
@Don't catch RedirectExceptions.
@
text
@d78 1
a78 1
    public static final  String versionID = "$Id: ProjectAdd.java,v 1.2 2000/11/14 22:49:28 elicia Exp $";
d153 1
@


1.2
log
@broke up ProjectAdd into ProjectAdd and ProjectAddStep2.  Renamed later steps. Removed Member Policy field.
@
text
@d78 1
a78 1
    public static final  String versionID = "$Id: ProjectAdd.java,v 1.1.1.1 2000/11/12 21:15:33 dlr Exp $";
d160 1
d162 2
a163 1
                   redirectToURL(context, myProperties.getProperty("nextStep"));
d173 4
@


1.1
log
@Initial revision
@
text
@a68 2
import org.tigris.helm.tool.Licenses;
import org.tigris.helm.tool.Policies;
a74 1
 * @@version $Id: ProjectAdd.java,v 1.75 2000/11/11 03:33:32 dlr Exp $
d78 1
a78 6
    public static final  String versionID = "$Id: ProjectAdd.java,v 1.75 2000/11/11 03:33:32 dlr Exp $";

    /**
     * The default project type.
     */
    private static final String DEF_PROJ_TYPE_KEY = "development";
a90 5
     * A list of ProjectProfiles instances, keyed by ProjectProfile key.
     */
    ProjectProfiles projectProfiles;

    /**
a95 3

        // Load the project types.
        projectProfiles = ProjectProfiles.getInstance();
d105 1
d107 2
a108 2
        if (debug) log.debug("Step 1");
        String action = (String)context.getForm("action");
a109 3
        if (debug) log.debug("action=" + action );

        if (debug) log.debug("Step 2");
a111 10
            
            /* HELP: Replaced this code with that below. Equivalent?
            SessionManager sMgr = getSessionManager(context);
            String userID = sMgr.getUserID();
            if (debug) log.debug("userID=" + userID);
            String loginID = sMgr.getLoginID();
            if (debug) log.debug("loginID=" + loginID);
            context.put("loginID", loginID);
            */

a139 22
            String license = processField(context, "license", "License", 
                                          missingFields);

            String projectOwner = (String)context.getForm("projectOwner");
            if (projectOwner == null)
            {
                projectOwner = loginID;
                context.put("projectOwner", loginID);
            }

            String policyType = processField(context, "policyType", "Policy", 
                                             missingFields);
            String catTypeID = processField(context, "catTypeID", "Category", 
                                            missingFields);
            String projectTypeKey = processField(context, "projectTypeKey", 
                                                 DEF_PROJ_TYPE_KEY, "Type", 
                                                 missingFields);
            context.put("projectProfList", projectProfiles.elements());

            // Give the template lists of licenses, policies, and categories.
            Licenses.addToContext(context, "licenseList");
            Policies.addToContext(context, "policyList");
d145 1
a145 1
            if (action != null && action.equals("Create Project"))
a152 7
                ProjectProfile projectType = 
                    projectProfiles.get(projectTypeKey);

                if (projectType == null)
                {
                    validationErrors.add("Project type is invalid.");
                }
d156 6
a161 38
                    if (!Licenses.isValid(license)) {
                        license = Licenses.getDefault();
                    }
                    log.info("license=" + license);
                    String policyID=String.valueOf(Policies.getKey(policyType));
                    log.info("policyID=" + policyID);
                    
                    // Add the project.
                    Project project = 
                        new Project(conn, dMgr, getACL(context, conn),
                                    projectType, 
                                    currentDomain.getID(), 
                                    projectName, 
                                    license,
                                    shortDescription, 
                                    longDescription, 
                                    null, //status
                                    url, 
                                    policyID,
                                    userID,                                    
                                    projectOwner);

                    project.changeCategory
                        (new Category(conn, dMgr, catTypeID.toString()));
                    
                    StringBuffer buf = new StringBuffer();
                    if (project != null)
                    {
                        // Send the user to the next project addition step.
                        buf.append(myProperties.getProperty("nextStep"));
                        buf.append("?projectID=").append(project.getID());
                        if (debug) log.debug("redirecting to: " + buf);
                        redirectToURL(context, buf.toString());
                    }
                    else
                    {
                        redirectToError(context, "Could not add project");
                    }
@


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
@@


1.1.1.2
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d17 1
a17 1
 * software developed by Collab.Net (http://www.collab.net/)."
d27 1
a27 1
 * permission of Collab.Net.
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d49 6
a54 2
import java.util.List;
import java.sql.Connection;
d56 1
d59 5
d66 5
a70 1
import org.tigris.helm.security.HelmServlet;
d73 1
a73 1
 * Project addition UI commonalities (i.e. context and session keys).
d76 2
a77 1
 * @@version $Id: ProjectAdd.java,v 1.25.2.3 2001/02/15 20:50:35 leonardr Exp $
d79 1
a79 1
abstract class ProjectAdd extends HelmServlet
d81 1
a81 4
    /**
     * The action which takes the user to the last step.
     */
    protected static final String FINISH = "Finish";
d84 1
a84 1
     * The action which takes the user to the next step.
d86 1
a86 1
    protected static final String NEXT_STEP = "Next Step";
d89 1
a89 1
     * The action which takes the user to the previous step.
d91 1
a91 1
    protected static final String PREV_STEP = "Previous Step";
d94 1
a94 1
     * The project name key.
d96 1
a96 1
    protected static final String PROJECT_NAME = "projectName";
d99 1
a99 1
     * The brief project description key.
d101 1
a101 1
    protected static final String SHORT_DESCRIP = "shortDescription";
d104 1
a104 1
     * The full project description key.
d106 3
a108 1
    protected static final String LONG_DESCRIP = "longDescription";
d110 3
a112 5
    /**
     * The key whose value indicates whether to use the index instead of the
     * description.
     */
    protected static final String USE_INDEX = "useIndex";
d115 1
a115 1
     * The project alias url key.
d117 4
a120 6
    protected static final String URL = "url";

    /**
     * The project owner key.
     */
    protected static final String PROJECT_OWNER = "projectOwner";
d122 2
a123 4
    /**
     * The project category type key.
     */
    protected static final String CAT_TYPE_ID = "catTypeID";
d125 1
a125 4
    /**
     * The project license key.
     */
    protected static final String LICENSE = "license";
d127 141
a267 4
    /**
     * The project profile key.
     */
    protected static final String PROJECT_PROFILE = "projectProfile";
a268 25
    /**
     * The invitation flag key.
     */
    protected static final String IS_INVITING = "isInviting";

    /**
     * The list of email addresses for invitation recipients key.
     */
    protected static final String INVITE_EMAIL_ADDRS = "inviteEmailAddrs";

    /**
     * The invitation key.
     */
    protected static final String INVITATION = "inviteMessage";

    /**
     * Adds action keys to the context.
     */
    protected String processRequest (Connection conn, WebContext ctx)
        throws HandlerException, RedirectException
    {
        String templateName = super.processRequest(conn, ctx);
        ctx.put("prevStep", PREV_STEP);
        ctx.put("nextStep", NEXT_STEP);
        ctx.put("finish", FINISH);
a271 30
    /**
     * Redirects to the servlet handling the previous step.
     */
    protected void redirectToPreviousStep (WebContext ctx)
        throws RedirectException
    {
        redirectToURL(ctx, myProperties.getProperty("prevStep"));
    }

    /**
     * Redirects to the servlet handling the next step.
     */
    protected void redirectToNextStep (WebContext ctx)
        throws RedirectException
    {
        redirectToURL(ctx, myProperties.getProperty("nextStep"));
    }

    /**
     * Adds a note to the list of validation errors that the project name was
     * just registerd.
     *
     * @@param validationErrors The list to add to.
     */
    protected final void addProjectNameJustRegistered (List validationErrors)
    {
        validationErrors.add("The project name you've chosen was just " + 
                             "registered.  Please click the back button on " + 
                             "your browser and use a different name.");
    }
@

