head	1.3;
access;
symbols
	NEWHELM:1.1.1.1 TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.3
date	2000.11.21.01.47.58;	author leonardr;	state dead;
branches;
next	1.2;

1.2
date	2000.11.20.20.07.32;	author leonardr;	state Exp;
branches;
next	1.1;

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

1.1.1.1
date	2000.11.12.21.15.24;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.3
log
@First stab at UserGroups.
@
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.domain;

import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

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

import org.joist.*;
import org.joist.util.*;
import org.joist.session.*;

import com.workingdogs.village.*;

import org.joist.security.RedirectException;
import org.joist.database.*;

import org.tigris.helm.security.HelmServlet;
import org.tigris.helm.database.UserUserGroupManager;

/**
 * Create a new project group.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@version $Id: GroupAdd.java,v 1.2 2000/11/20 20:07:32 leonardr Exp $
 */
public class GroupAdd extends org.tigris.helm.security.HelmServlet {
    public static final  String versionID = "$Id: GroupAdd.java,v 1.2 2000/11/20 20:07:32 leonardr Exp $";
    private static Log log = new Log("GroupAdd", "Group Add Servlet");
    private static boolean debug = true;

    /**
     *  Display and process the login screen.
     */
    protected String
	processRequest (Connection connection, WebContext context)
	throws HandlerException, RedirectException
    {
	if (debug) log.debug("GroupAdd: started!");

	String templateName = super.processRequest(connection, context);
	
	String action = getAction(context);

        try 
        {
            // 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.
            ArrayList missingFields = new ArrayList();
            ArrayList validationErrors = new ArrayList();
            String groupName = processField(context, "groupName", 
                                            "Group name", missingFields);
            String description = processField(context, "description",
                                              "Short description", 
                                              missingFields);    
            String members = processField(context, "members", 
                                          "Initial Members", missingFields);

            if (action != null && action.equals("Create Group"))
            {
                if (isValidUserInput(missingFields, validationErrors))
                {
                    // Add the user group.
                    String groupID = uugMgr.addUserGroup
                        (connection, groupName, description, UserType.DOMAIN)
                        .toString();
                    
                    // Add members to the newly formed group.
                    ArrayList memberList = new ArrayList();
                    StringTokenizer tok = new StringTokenizer(members);
                    while (tok.hasMoreTokens())
                    {
                        memberList.add(tok.nextToken());
                    }
                    for (Iterator i = memberList.iterator(); i.hasNext();)
                    {
                        String member = (String)i.next();
                        //This should be replaced with one call.
                        Record r = userMgr.getUserForLoginID(connection, 
                                                             member);
                        String userID = r.getValue(UserManager.USER_ID)
                            .toString();
                        uugMgr.addBaseToComposite(connection, userID,
                                                     groupID);
                    }
                } else {
                    // Report missing fields and validation errors.
                    reportInvalidUserInput(context, missingFields, 
                                           validationErrors);
                }
            }

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


        return templateName;
    }
  
} /* end class GroupAdd */
@


1.2
log
@Initial run at ProjectGroup business object.
@
text
@d75 1
a75 1
 * @@version $Id: GroupAdd.java,v 1.1.1.1 2000/11/12 21:15:24 dlr Exp $
d78 1
a78 1
    public static final  String versionID = "$Id: GroupAdd.java,v 1.1.1.1 2000/11/12 21:15:24 dlr Exp $";
@


1.1
log
@Initial revision
@
text
@d75 1
a75 1
 * @@version $Id: GroupAdd.java,v 1.13 2000/11/06 06:15:30 edk Exp $
d78 1
a78 1
    public static final  String versionID = "$Id: GroupAdd.java,v 1.13 2000/11/06 06:15:30 edk Exp $";
d93 1
a93 1
	String action = (String)context.get("action");
d100 1
a100 1
            String errorMessage = (String) context.get("Error");
a106 3
            UserUserGroupManager usrGrpMgr = (UserUserGroupManager)
                dMgr.getManager("org.tigris.helm.database.UserUserGroupManager");

d142 1
a142 1
                        usrGrpMgr.addBaseToComposite(connection, userID,
@


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