head	1.10;
access;
symbols
	TIGRIS_1_1_0RC2:1.2.2.1
	TIGRIS_1_1_0RC1:1.2.2.1
	TIGRIS_1_1:1.2.2.1.0.2
	TIGRIS_1_0_8:1.2.2.1
	TIGRIS_1_0_8RC3:1.2.2.1
	TIGRIS_1_0_8RC2:1.2.2.1
	TIGRIS_1_0_8RC1:1.2.2.1
	TIGRIS_1_0_7:1.2.2.1
	TIGRIS_1_0_7RC3:1.2.2.1
	TIGRIS_1_0_7RC2:1.2.2.1
	TIGRIS_1_0_7RC1:1.2.2.1
	TIGRIS_1_0_6:1.2.2.1
	TIGRIS_1_0_6RC5:1.2.2.1
	TIGRIS_1_0_6RC4:1.2.2.1
	TIGRIS_1_0_6RC3:1.2.2.1
	TIGRIS_1_0_6RC2:1.2.2.1
	TIGRIS_1_0_6RC1:1.2.2.1
	TIGRIS_1_0_5:1.2.2.1
	TIGRIS_1_0_5RC6:1.2.2.1
	TIGRIS_1_0_5RC5:1.2.2.1
	TIGRIS_1_0_5RC4:1.2.2.1
	TIGRIS_1_0_5RC3:1.2.2.1
	TIGRIS_1_0_5RC2:1.2.2.1
	TIGRIS_1_0_5RC1:1.2.2.1
	TIGRIS_1_0_4:1.2.2.1
	TIGRIS_1_0_3:1.2.2.1
	TIGRIS_1_0_2:1.2.2.1
	TIGRIS_1_0_1:1.2.2.1
	TIGRIS_1_0:1.2.2.1.0.4
	TIGRIS_1_0_0:1.2.2.1
	TIGRIS_1_0_0_RC1:1.2.0.2;
locks; strict;
comment	@# @;


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

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

1.8
date	2001.05.25.16.57.15;	author leonardr;	state Exp;
branches;
next	1.7;

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

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

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

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

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

1.2
date	2001.03.23.18.52.47;	author leonardr;	state Exp;
branches
	1.2.2.1;
next	1.1;

1.1
date	2001.03.07.01.13.15;	author lucas;	state Exp;
branches;
next	;

1.2.2.1
date	2001.03.28.22.45.52;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.10
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
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.om;

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

import org.apache.fulcrum.velocity.TurbineVelocity;

import org.apache.torque.util.Criteria;

import org.apache.velocity.VelocityContext;
import org.apache.velocity.context.Context;

import org.tigris.helm.*;
import org.tigris.helm.om.*;
import org.tigris.helm.tool.*;
import org.apache.turbine.util.Log;

/**
 * Extension of generated Peer BaseInvitationPeer.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@version $Id: InvitationPeer.java,v 1.9 2001/07/19 19:31:30 dlr Exp $
 */
public class InvitationPeer extends BaseInvitationPeer
{
    /**
     * The name of the template used to create the body of the invitation
     * email.
     */
    private static final String INVITATION_TEMPLATE = 
        TemplateTool.getPathToMessageTemplate("ProjectInvitation.vm");

    /**
     * Construct an invitation which already exists.
     */
    public static Invitation getInstance(String ticket)
        throws DoesNotExist, Exception
    {
        Criteria c = new Criteria(1)
            .add(TICKET, ticket);

        Invitation i = null;
        try 
        {
            i = (Invitation)PeerTool.getFirstBO
                (doSelect(c), "Invitation for ticket " + ticket);
        }
        catch (DoesNotExist e)
        {
            throw new Exception(Invitation.BAD_TICKET_MESSAGE);
        }       
        return i;
    }

    /**
     * This function isn't right ... it combines several functions which
     * should be split up.  It's private so other classes won't use it.
     */
    public static void add(Domain domain, String recipient, User sender,
                           Project project, String message)
        throws DoesNotExist, NestableException, Exception
    {
        Invitation i = new Invitation();
        String nonce = Nonce.buildNonce();
        try
        {
            i.setProjectId(project.getProjectId());
            i.setTicket(nonce);
            i.save();
        }
        catch (Exception e) 
        {
            throw new NestableException("Unable to create/add invite", e);
        }

        String joinURL = 
            project.getProjectPageFullURL("ProjectMembershipRequest",
                                          "ticket=" + nonce, null);
        
        String subject = sender.getRealName() + " invites you to join the " 
            + project.getName() + " project";

        Context ctx = new VelocityContext();
        ctx.put("sender", sender);
        ctx.put("project", project);
        ctx.put("message", message);
        ctx.put("joinURL", joinURL);
        String body = TurbineVelocity.handleRequest(ctx, INVITATION_TEMPLATE);
        try 
        {
            new Emailer().sendEmailFrom(sender.getEmail(), recipient, subject,
                                        body);
        }
        catch (NestableException e)
        {
            Log.warn("Unable to send invitation for project " + project +
                     " to " + recipient + "\n\nBody:\n" + body);
            // HELP: Should we throw an exception here?
        }
    }
}
@


1.9
log
@Removed Joist references.
@
text
@d49 5
a53 6
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.Log;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.services.velocity.TurbineVelocity;
d55 1
d58 1
a59 1
import org.tigris.helm.*;
d61 1
d68 1
a68 1
 * @@version $Id: InvitationPeer.java,v 1.8 2001/05/25 16:57:15 leonardr Exp $
d107 1
a107 1
        throws DoesNotExist, TurbineException, Exception
d119 1
a119 1
            throw new TurbineException("Unable to create/add invite", e);
d129 1
a129 1
        Context ctx = TurbineVelocity.getContext();
d140 1
a140 1
        catch (TurbineException e)
@


1.8
log
@.wm is now .vm
@
text
@a57 3
import org.joist.mail.Emailer;
import org.joist.JoistException;

d67 1
a67 1
 * @@version $Id: InvitationPeer.java,v 1.7 2001/05/23 01:50:13 dlr Exp $
d139 4
a142 3
        catch (JoistException e) {
            Log.warn("Unable to send invitation to " + recipient +
                     "\n\nBody:\n" + body);
@


1.7
log
@Ported Helm from WebMacro to Velocity.
@
text
@d70 1
a70 1
 * @@version $Id: InvitationPeer.java,v 1.6 2001/05/01 23:33:41 dlr Exp $
d79 1
a79 1
        TemplateTool.getPathToMessageTemplate("ProjectInvitation.wm");
@


1.6
log
@Minor formatting change for consistancy.
@
text
@d52 3
a54 1
import org.apache.turbine.services.webmacro.TurbineWebMacro;
d56 1
a56 1
import org.webmacro.servlet.WebContext;
d70 1
a70 1
 * @@version $Id: InvitationPeer.java,v 1.5 2001/04/02 19:25:04 leonardr Exp $
d131 1
a131 1
        WebContext ctx = TurbineWebMacro.getContext();
d136 1
a136 1
        String body = TurbineWebMacro.handleRequest(ctx, INVITATION_TEMPLATE);
@


1.5
log
@Invitation message is now in a template where it belongs.
@
text
@d68 1
a68 1
 * @@version $Id: InvitationPeer.java,v 1.4 2001/03/30 00:25:57 leonardr Exp $
d111 2
a112 1
        try {
@


1.4
log
@Factored out messages into constants, and used message in another place.
@
text
@d52 3
d61 1
a61 2
import org.tigris.helm.tool.PeerTool;
import org.tigris.helm.tool.Nonce;
d68 1
a68 1
 * @@version $Id: InvitationPeer.java,v 1.3 2001/03/28 22:22:31 leonardr Exp $
d73 7
d106 1
a106 2
                           Project project, String subject,
                           String partialMessage)
d116 2
a117 1
        catch (Exception e) {
d121 1
a121 1
        String msg = partialMessage + "\n\nJoin now: " + 
d124 12
a135 1
        try {
d137 1
a137 1
                                        msg);
d141 1
a141 1
                     "\n\nBody:\n" + msg);
@


1.3
log
@Corrected misspelling.
@
text
@d66 1
a66 1
 * @@version $Id: InvitationPeer.java,v 1.2 2001/03/23 18:52:47 leonardr Exp $
a75 1
        Log.debug("Getting invitation for " + ticket);
d78 12
a89 2
        return (Invitation)PeerTool.getFirstBO
            (doSelect(c), "Invitation for ticket " + ticket);
@


1.2
log
@Some fixes for the whole ProjectMembershipRequest/Join/Login/Invitation Rube Goldberg.
@
text
@d66 1
a66 1
 * @@version $Id: InvitationPeer.java,v 1.1 2001/03/07 01:13:15 lucas Exp $
d80 1
a80 1
            (doSelect(c), "Inviation for ticket " + ticket);
@


1.2.2.1
log
@Corrected misspelling.
@
text
@d66 1
a66 1
 * @@version $Id: InvitationPeer.java,v 1.2 2001/03/23 18:52:47 leonardr Exp $
d80 1
a80 1
            (doSelect(c), "Invitation for ticket " + ticket);
@


1.1
log
@Moved in from peer package to handle Torque changes. -dlr
@
text
@d66 1
a66 1
 * @@version $Id: InvitationPeer.java,v 1.2 2001/02/21 03:02:28 edk Exp $
d76 1
@

