head	1.8;
access;
symbols
	TIGRIS_NOV_12_2000:1.7
	OLDHELM:1.7.0.2
	TIGRIS_NOV_11_2000:1.7
	TIGRIS_SEP_13_2000:1.5.0.2
	TIGRIS_BASELINE:1.6;
locks; strict;
comment	@# @;


1.8
date	2000.11.12.23.05.54;	author dlr;	state dead;
branches;
next	1.7;

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

1.6
date	2000.09.21.19.44.07;	author kmaples;	state Exp;
branches;
next	1.5;

1.5
date	2000.09.20.03.13.14;	author brian;	state Exp;
branches;
next	1.4;

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

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

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

1.1
date	2000.01.30.01.59.36;	author jrobbins;	state Exp;
branches;
next	;


desc
@@


1.8
log
@Does not exist in newhelm.
@
text
@/* ================================================================
 * Copyright (c) 2000 Collab.Net.  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 Collab.Net (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 Collab.Net.
 * 
 * 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 Collab.Net.
 */


package org.tigris.helm.admin;

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

import javax.servlet.*;
import javax.servlet.http.*;

import com.sun.java.util.collections.ArrayList;
import java.sql.*;
import gnu.regexp.RE;

import org.joist.security.PermissionSet;
import org.joist.security.RedirectException;
import org.joist.security.SecureServlet;
import org.tigris.helm.tool.TigrisUpdate;
import org.tigris.helm.tool.UpdateException;
import org.tigris.helm.tool.InnerNavPopulator;
import org.tigris.helm.database.ModuleManager;

/**
 * Present a form for the addition of a new module
 */

public class ModuleAdd extends SecureServlet {

    static private Log log = new Log("modAdd", "ModuleAdd");
    static private boolean debug = true;
    
    static private RE moduleRE = null;
    
    public void start() throws ServletException {
	super.start();
	try {
	    moduleRE= new RE("^([a-zA-Z0-9_]+/?)+$");
	}
	catch (gnu.regexp.REException e) {
	    log.exception(e);
	}
    }
  
  protected String processRequest(Connection connection, WebContext context)
    throws HandlerException, RedirectException
  {
    if (debug) log.debug("ModuleAdd: prestart");
    String templateName = super.processRequest(connection, context);
    // super sets $UserName, Cancel

    if (debug) log.debug("ModuleAdd: started");

	
    // Get the userID and permissions of the person who logged in.
    String loginUserID = (String)context.get("loginUserID");
    PermissionSet userPerms = (PermissionSet)context.get("UserPermissions");

    String project = context.getForm("project");
    String module = context.getForm("module");
    if (project == null)
	redirectToError(context, "No project specified");
    context.put("project", project);
    InnerNavPopulator.Populate(connection,context,false);

    context.put("module", "");

    context.put("long_name", "");
    context.put("missingFields", new ArrayList());
    context.put("validationErrors", new ArrayList());

    // Determine which button was pushed
    String action = (String) context.get("action");	
	
    try {
	if (action.equals("Create Module"))
	    doCreateModule(connection, context, project, module);
    }
    catch (UpdateException e) {
	log.exception(e);
	String message = "ModuleAdd: " + e.getMessage();
	if (debug) log.debug(message);
	throw new HandlerException(e.getMessage());
    }
    catch (SQLException e) {
	log.exception(e);
	String message = "ModuleAdd: " + e.getMessage();
	if (debug) log.debug(message);
	throw new HandlerException(e.getMessage());
    }
    catch (ModuleManager.AlreadyExists e) {
	context.put("moduleExists", Boolean.TRUE);
	// Fall through to the standard template
    }

    return templateName;
  }

    protected void doCreateModule(Connection connection,
				  WebContext context,
				  String project, String module)
	throws UpdateException, RedirectException,
	       SQLException, ModuleManager.AlreadyExists
    {
	ArrayList missingFields = new ArrayList();
	ArrayList validationErrors = new ArrayList();
	boolean moduleExists = false;
	
	HttpServletRequest request = context.getRequest();
	String domain = request.getServerName();

	if (debug) log.debug("Button=Create Module");
	if (debug) log.debug("ModuleAdd: module="+module);
	if (module == null || module.equals(""))
	    missingFields.add("Module");
	else {
	    context.put("module", module);
	    if (debug) log.debug("ModuleAdd: module=" + module);
	    if (!moduleRE.isMatch(module)) {
		validationErrors.add("Module name must be one word, "+
				     "or the name of an existing "+
				     "module plus '/' and another word.");
		//TODO: validate nested module names
	    }
	}
	
	String long_name = context.getForm("long_name");
	if (long_name == null || long_name.equals(""))
	    missingFields.add("Long Name");
	else
	    context.put("long_name", long_name);
	if (debug) log.debug("ModuleAdd: long_name=" + long_name);
	
	
	boolean privateModule = (context.getForm("private") != null);
	if (missingFields.isEmpty() && validationErrors.isEmpty()) {
		ModuleManager.addModule(connection, domain, project,
					module, long_name,
					false);
		redirectTo("ProjectEdit");
	}

	context.put("missingFields", missingFields);
	context.put("validationErrors", validationErrors);
	context.put("moduleExists", new Boolean(moduleExists));

    }
    
} /* end class ModuleAdd */
@


1.7
log
@No longer uses isPrivate.
@
text
@@


1.6
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
@a117 3
    context.put("privateModule", Boolean.FALSE);
    if (debug) log.debug("ModuleAdd: privateModule=false");

a181 3
	context.put("privateModule", new Boolean(privateModule));
	if (debug) log.debug("ModuleAdd: privateModule=" + privateModule);
	
d185 1
a185 1
					false, privateModule);
@


1.5
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
@d158 3
d189 1
a189 1
		ModuleManager.addModule(connection, project,
d191 1
a191 1
					privateModule);
@


1.4
log
@Initial commit.
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d48 1
a48 1
package org.helm.admin;
d65 4
a68 4
import org.helm.tool.TigrisUpdate;
import org.helm.tool.UpdateException;
import org.helm.tool.InnerNavPopulator;
import org.helm.database.ModuleManager;
@


1.3
log
@switched from collections2.jar to collections.jar
@
text
@d67 1
d110 1
a110 1

@


1.2
log
@Added tigris.org license
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d58 1
a58 1
import java.util.ArrayList;
@


1.1
log
@initial checking
@
text
@d1 46
a46 1
// Copyright (c) 2000 Collab.Net, Inc. All Rights Reserved.
@

