head	1.9;
access;
symbols
	TIGRIS_0_9_2_4:1.6
	TIGRIS_0_9_2_3:1.6
	HELM_PEER_PORT_BRANCH:1.8.0.2
	TURBINE_PEER:1.8
	TIGRIS_0_9_2_1:1.8
	TIGRIS_0_9_2:1.6.0.6
	TIGRIS_0_9_0:1.6.0.4
	TIGRIS_0_8_4:1.6.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.9
date	2001.02.21.03.23.57;	author edk;	state dead;
branches;
next	1.8;

1.8
date	2001.01.26.18.29.09;	author edk;	state Exp;
branches
	1.8.2.1;
next	1.7;

1.7
date	2001.01.26.05.24.08;	author edk;	state dead;
branches;
next	1.6;

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

1.5
date	2000.11.22.08.47.59;	author edk;	state Exp;
branches;
next	1.4;

1.4
date	2000.11.22.06.09.20;	author edk;	state Exp;
branches;
next	1.3;

1.3
date	2000.11.22.01.51.09;	author edk;	state Exp;
branches;
next	1.2;

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

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

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

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


desc
@@


1.9
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 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 CollabNet.
 */

package org.tigris.helm.tool;

import java.util.List;
import java.util.Iterator;

import java.sql.Connection;
import java.sql.SQLException;

import org.joist.JoistException;
import org.joist.mail.Emailer;
import org.joist.database.DataManager;
import org.joist.database.JoistDatabaseException;

import org.webmacro.util.Log;

import com.workingdogs.village.Record;
import com.workingdogs.village.DataSetException;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.domain.Domain;
import org.tigris.helm.domain.User;
import org.tigris.helm.project.Project;
import org.tigris.helm.database.InvitationManager;

/**
 * Sends invitation mail to a list of addresses, inviting them to
 * join a project.
 */
public class Invitation
{
    /**
     * The village record underlying this Invitation
     */
    private Record invitation;

    /**
     * Our table manager
     */
    private InvitationManager inviteMgr;

    /**
     * The JDBC connection
     */
    private Connection conn;

    /**
     * Turning debugging on and off.
     */
    public static final boolean debug = true;

    /**
     * For logging.
     */
    protected Log log = new Log("invt", "Invitation");

    /**
     * Creates a new instance.
     * <p>
     * TODO: Refactor Joist's Emailer class to make use of 
     * <code>senderName</code>.
     */
    public static void sendInvitations (Connection conn, DataManager dMgr,
            Domain domain, List recipients, User sender, Project project,
            String msg)
        throws DataSetException, JoistException, JoistDatabaseException
    {
        String senderName = sender.getName();
        String host = domain.getName();
        String projectName = project.getName();
        String projectDescription = project.getLongDescription();

        StringBuffer buf = new StringBuffer();
        buf.append(senderName).append(" invites you to join the ");
        buf.append(projectName).append(" project");
        String subject = buf.toString();

        buf.setLength(0);
        buf.append(msg);
        buf.append("\n\nThe description of this project is as follows:\n\n");
        buf.append(projectDescription);
        buf.append("\n\nYou can reply to this message to ask the owner for " +
                "more information\nabout this project.\n");

        String partialMessage = buf.toString();

        Iterator i = recipients.iterator();
        while (i.hasNext()) {
            String recipient = (String) i.next();
            new Invitation(conn, dMgr, domain, recipient, sender, project,
                    subject, partialMessage);
        }
    }

    /**
     * This function isn't right ... it combines several functions which
     * should be split up.  It's private so other classes won't use it.
     */
    private Invitation(Connection conn, DataManager dMgr, Domain domain,
            String recipient, User sender, Project project, String subject,
            String partialMessage)
        throws DataSetException, JoistDatabaseException
    {
        InvitationManager inviteMgr = (InvitationManager)
            dMgr.getManager("org.tigris.helm.database.InvitationManager");
        String nonce = Nonce.buildNonce();
        try {
            invitation = inviteMgr.createRecord(conn);
            invitation.setValue(InvitationManager.PROJECT_ID, project.getID());
            invitation.setValue(InvitationManager.TICKET, nonce);
            inviteMgr.addInvitation(conn, invitation);
        } catch (SQLException e) {
            log.exception(e);
            if (debug) log.info("unable to create/add invite: "+e.getMessage());
            throw new JoistDatabaseException("database error adding invite");
        }

        StringBuffer buff = new StringBuffer(partialMessage);

        buff.append("\n\nJoin now: ");
        buff.append(project.getProjectPageFullURL("ProjectMembershipRequest",
                    "ticket=" + nonce, null));

        try {
            new Emailer().sendEmailFrom(sender.getEmail(), recipient,
                                        subject, buff.toString());
        } catch (JoistException e) {
            log.info("Unable to send invitation to " + recipient + "\n\nBody:\n" + buff.toString());
        }
        this.conn = conn;
    }

    /**
     * Construct an Invitation which already exists.
     */
    public Invitation(Connection conn, DataManager dMgr, String ticket) 
        throws DoesNotExist
    {
        inviteMgr = (InvitationManager)
            dMgr.getManager("org.tigris.helm.database.InvitationManager");
        invitation = inviteMgr.getInvitation(conn, ticket);
        this.conn = conn;
    }

    /**
     * Is this invitation valid for a given project?
     */
    public boolean isValidForProject(String projectID)
    {
        if (projectID == null) return false;
        try {
            return projectID.equals(invitation.
                    getValue(InvitationManager.PROJECT_ID).asString());
        } catch (DataSetException e) {
            log.exception(e);
            if (debug) log.info("error checking validity of invite: " +
                    e.toString());
            return false;
        }
    }

    /**
     * Remove this invitation (it's been used)
     */
    public void delete() throws JoistDatabaseException
    {
        inviteMgr.deleteInvitation(conn, invitation);
    }
}

@


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


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


1.7
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.6
log
@Make errors sending mail less destructive.
@
text
@@


1.5
log
@don't specific protocol
@
text
@d147 1
a147 1
        throws DataSetException, JoistException, JoistDatabaseException
d169 6
a174 2
        new Emailer().sendEmailFrom(sender.getEmail(), recipient,
                subject, buff.toString());
@


1.4
log
@provide better use guidance wrt new / unapproved projects: suggest
mailing the project owner (by replying) and provide a way for the
template to determine if the project is approved yet.
@
text
@d167 1
a167 1
                    "ticket=" + nonce, "http"));
@


1.3
log
@new invitations stuff : if you have a valid ticket, you can request
roles, even if the project is private and you have none so far.
@
text
@d124 2
a125 2
	buf.append(msg);
	buf.append("\n\nThe description of this project is as follows:\n\n");
d127 3
@


1.2
log
@send out invitations with nonces during SSPAS2 (soon to be renamed)
@
text
@d65 1
d80 11
a90 1
    private Record invite;
d137 5
a141 1
    public Invitation(Connection conn, DataManager dMgr, Domain domain,
d150 4
a153 4
            this.invite = inviteMgr.createRecord(conn);
            invite.setValue(InvitationManager.PROJECT_ID, project.getID());
            invite.setValue(InvitationManager.NONCE, nonce);
            inviteMgr.addInvitation(conn, invite);
d164 1
a164 1
                    "nonce=" + nonce, "http"));
d168 38
@


1.1
log
@Initial revision
@
text
@d50 4
d57 12
d77 1
a77 6
     * The name of the sender.
     */
    private String senderName;

    /**
     * The email address of the sender.
d79 1
a79 1
    private String senderEmail;
d82 1
a82 1
     * The recipients' email addresses.
d84 1
a84 6
    private List recipients;
    
    /**
     * The subject of the invitation email.
     */
    private String subject;
d87 1
a87 1
     * The invitation message body.
d89 1
a89 2
    private String body;

d97 4
a100 3
    public Invitation (String host, List recipients, String senderEmail, 
                       String senderName, String projectName, 
                       String projectDescription, String msg)
d102 4
a105 3
	this.senderName = senderName;
	this.senderEmail = senderEmail;
	this.recipients = recipients;
d110 1
a110 1
        this.subject = buf.toString();
d116 8
a123 1
        this.body = buf.toString();
d126 4
a129 4
    /**
     * Send the the invitation via email.
     */
    public void send () throws JoistException
d131 22
a152 1
        new Emailer().sendEmailFrom(senderEmail, recipients, subject, body);
@


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