head	1.34;
access;
symbols
	TIGRIS_1_1_0RC2:1.20.6.5
	TIGRIS_1_1_0RC1:1.20.6.5
	TIGRIS_1_1:1.20.6.5.0.2
	TIGRIS_1_0_8:1.20.6.5
	TIGRIS_1_0_8RC3:1.20.6.5
	TIGRIS_1_0_8RC2:1.20.6.5
	TIGRIS_1_0_8RC1:1.20.6.5
	TIGRIS_1_0_7:1.20.6.5
	TIGRIS_1_0_7RC3:1.20.6.5
	TIGRIS_1_0_7RC2:1.20.6.5
	TIGRIS_1_0_7RC1:1.20.6.5
	TIGRIS_1_0_6:1.20.6.5
	TIGRIS_1_0_6RC5:1.20.6.5
	TIGRIS_1_0_6RC4:1.20.6.5
	TIGRIS_1_0_6RC3:1.20.6.5
	TIGRIS_1_0_6RC2:1.20.6.5
	TIGRIS_1_0_6RC1:1.20.6.5
	TIGRIS_1_0_5:1.20.6.3
	TIGRIS_1_0_5RC6:1.20.6.3
	TIGRIS_1_0_5RC5:1.20.6.3
	TIGRIS_1_0_5RC4:1.20.6.3
	TIGRIS_1_0_5RC3:1.20.6.3
	TIGRIS_1_0_5RC2:1.20.6.3
	TIGRIS_1_0_5RC1:1.20.6.1
	TIGRIS_1_0_4:1.20.6.1
	TIGRIS_1_0_3:1.20
	TIGRIS_1_0_2:1.20
	TIGRIS_1_0_1:1.20
	TIGRIS_1_0:1.20.0.6
	TIGRIS_1_0_0:1.20
	TIGRIS_1_0_0_RC1:1.20.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.16
	TIGRIS_0_9_2_3:1.16
	HELM_PEER_PORT_BRANCH:1.1.1.1
	TURBINE_PEER:1.18
	TIGRIS_0_9_2_1:1.18
	TIGRIS_0_9_2:1.16.0.2
	TIGRIS_0_9_0:1.13.0.2
	TIGRIS_0_8_4:1.9.0.2;
locks; strict;
comment	@# @;


1.34
date	2001.08.11.09.08.08;	author dlr;	state Exp;
branches;
next	1.33;

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

1.32
date	2001.07.19.18.42.23;	author dlr;	state Exp;
branches;
next	1.31;

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

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

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

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

1.27
date	2001.05.25.16.57.15;	author leonardr;	state Exp;
branches;
next	1.26;

1.26
date	2001.05.25.01.45.29;	author leonardr;	state Exp;
branches;
next	1.25;

1.25
date	2001.05.23.01.50.21;	author dlr;	state Exp;
branches;
next	1.24;

1.24
date	2001.05.02.00.55.31;	author dlr;	state Exp;
branches;
next	1.23;

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

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

1.21
date	2001.04.30.18.10.17;	author leonardr;	state Exp;
branches;
next	1.20;

1.20
date	2001.03.07.01.53.27;	author lucas;	state Exp;
branches
	1.20.6.1;
next	1.19;

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

1.18
date	2001.01.26.18.29.09;	author edk;	state Exp;
branches
	1.18.2.1;
next	1.17;

1.17
date	2001.01.26.05.24.08;	author edk;	state dead;
branches;
next	1.16;

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

1.15
date	2001.01.09.17.10.21;	author leonardr;	state Exp;
branches;
next	1.14;

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

1.13
date	2000.12.14.22.44.21;	author leonardr;	state Exp;
branches;
next	1.12;

1.12
date	2000.12.14.21.57.38;	author leonardr;	state Exp;
branches;
next	1.11;

1.11
date	2000.12.14.21.55.13;	author leonardr;	state Exp;
branches;
next	1.10;

1.10
date	2000.12.14.03.04.18;	author edk;	state Exp;
branches;
next	1.9;

1.9
date	2000.12.02.23.52.47;	author leonardr;	state Exp;
branches
	1.9.2.1;
next	1.8;

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

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

1.6
date	2000.11.17.08.07.34;	author edk;	state Exp;
branches;
next	1.5;

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

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

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

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

1.1
date	2000.11.14.16.59.17;	author leonardr;	state Exp;
branches
	1.1.1.1;
next	;

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

1.9.2.1
date	2000.12.14.23.22.00;	author leonardr;	state Exp;
branches;
next	;

1.18.2.1
date	2001.01.28.01.02.19;	author dlr;	state dead;
branches;
next	1.18.2.2;

1.18.2.2
date	2001.02.09.16.03.11;	author leonardr;	state Exp;
branches;
next	1.18.2.3;

1.18.2.3
date	2001.02.14.23.20.30;	author leonardr;	state Exp;
branches;
next	1.18.2.4;

1.18.2.4
date	2001.02.15.20.50.44;	author leonardr;	state Exp;
branches;
next	1.18.2.5;

1.18.2.5
date	2001.02.16.03.01.35;	author dlr;	state Exp;
branches;
next	;

1.20.6.1
date	2001.04.30.23.09.32;	author dlr;	state Exp;
branches;
next	1.20.6.2;

1.20.6.2
date	2001.05.16.00.20.21;	author leonardr;	state Exp;
branches;
next	1.20.6.3;

1.20.6.3
date	2001.05.16.01.14.12;	author leonardr;	state Exp;
branches;
next	1.20.6.4;

1.20.6.4
date	2001.05.25.21.48.37;	author leonardr;	state Exp;
branches;
next	1.20.6.5;

1.20.6.5
date	2001.05.25.22.06.33;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.34
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.tool;

import java.util.*;

import org.apache.turbine.util.Log;
import org.apache.commons.util.StringUtils;
import org.apache.commons.util.exception.NestableException;
import org.apache.torque.util.Criteria;

import org.tigris.helm.tool.HelmProperties;
import org.tigris.helm.tool.Emailer;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.*;
import org.tigris.helm.om.*;
/**
 * HelmEmailer can send email to a specific user, to everyone with an
 * ownership role in a project/domain, etc.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a> 
 */
public class HelmEmailer extends Emailer
{
    /**
     * Turning debugging on and off.
     */
    public static final boolean debug = true;

    /**
     * Number of viewable columns we assume mail readers to have.
     */
    private static final int VIEWABLE_WIDTH = 78;

    /**
     * Send an error message to the host admins.
     */
    public void sendError (String subject, String body)
    {
        Log.warn("SYSTEM ERROR! " + subject);
        Log.warn(body);
        Log.warn("Sending mail to host admin...");
        subject = "ERROR: " + subject;
        try
        {
            messageUsersWithHostOwnership(subject, body);
        }
        catch (Exception e)
        {
            Log.error("Could not send mail to host admin!", e);
        }
    }

    /**
     * Send system mail to every user with an ownership role in the host.
     */
    public void messageUsersWithHostOwnership(String subject, String body)
        throws Exception
    {
        messageUsersWithProjectOwnership(ProjectPeer.getHost(), subject, body);
    }        
    
    /**
     * Send system mail to every user with a domain ownership role in the
     * given domain.
     */
    public void messageUsersWithDomainOwnership(Domain domain, String subject, 
                                                String body)
        throws Exception
    {
        messageUsersWithProjectOwnership(domain, subject, body);
    }        
    
    /**
     * Send system mail to every user with a given role in a given
     * project. Note that this only sends mail to people who have the
     * role in the project directly (not through groups).  
     */
    public void messageUsersWithProjectOwnership
        (Project project, String subject, String body)
        throws Exception
    {
        List users = project.getOwners();
        if (users.size() > 0)
        {
            for (Iterator i = users.iterator(); i.hasNext();)
            {
                User user = (User)i.next();
                mailUserFromSystem(user, subject, body);
            }
        }
        else
        {
            if (project.isHost())
            {
                //We're screwed.
            } 
            else if (project.isDomain())
            {
                //Nobody is in charge of the domain.
                //This is a serious problem--mail the host admins.
                StringBuffer newBody = new StringBuffer();
                newBody.append("Since no one seems to have responsibility")
                    .append(" for the ")
                    .append(project.getDomain().getName())
                    .append(" domain, the following message is being sent to")
                    .append(" those with responsibility for the host:\n\n");
                printHorizontalLine(newBody);
                newBody.append(body);
                
                messageUsersWithHostOwnership(subject, newBody.toString());
            }
            else
            {
                //Nobody has the project role. Mail the domain admins instead.
                StringBuffer newBody = new StringBuffer();
                newBody.append("Since no one seems to have responsibility")
                    .append(" for the ")
                    .append(project.getName())
                    .append(" project, the following message is being sent to")
                    .append(" those with responsibility for the domain:\n\n");
                printHorizontalLine(newBody);
                newBody.append(body);
                
                Domain projectDomain = project.getDomain();
                messageUsersWithDomainOwnership
                    (projectDomain, subject, newBody.toString());
            }
        }
    }        

    /**
     * Prints a dash-based horizontal rule to the supplied buffer.
     */
    private final void printHorizontalLine(StringBuffer buf)
    {
        for (int i = 0; i < VIEWABLE_WIDTH; i++) 
        {
            buf.append('-');
        }
        buf.append("\n\n");
    }

    /**
     * Send system mail to a given user.
     */
    public void mailUserFromSystem(User to, String subject, String body)
        throws Exception
    {
        //TODO: Make this a real address... host contact or something.
        HelmProperties prop = HelmProperties.getInstance();
        String systemName = prop.getProperty("systemEmail");
        String systemEmail = prop.getProperty("systemEmailName");
        mailUserFromAddress(to, systemName, systemEmail, subject, body);
    }

    /**
     * Sends mail from one user to another.
     */
    public void mailUserFromUser(User to, User from, String subject, 
                                 String body)
            throws Exception
    {
        mailUserFromAddress(to, from.getRealName(), from.getEmail(), subject,
                            body);
    }

    /**
     * Sends mail from one user to another.
     */
    public void sendMailFromUser(String toAddress, User from, String subject, 
                                 String body)
        throws Exception
    {
        sendEmailFrom(from.getEmail(), toAddress, subject, body);
    }

    /**
     * Sends mail to a user from a given address.
     */
    public void mailUserFromAddress(User to, String fromEmail, String fromName,
                                    String subject, String body)
        throws Exception
    {
        String toEmail = to.getEmail();
        if (StringUtils.isValid(toEmail))
        {
            sendEmailFrom(fromEmail, toEmail, subject, body);
        }
    }
}
@


1.33
log
@Removed Joist references.
@
text
@d52 3
a54 3
import org.apache.turbine.util.StringUtils;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.db.Criteria;
@


1.32
log
@Updated in light of the port of Joist JoistProperties class to Helm (as class HelmProperties).
@
text
@d57 1
a57 1
import org.joist.mail.Emailer;
@


1.31
log
@Huge patch of the day: Got rid of redundant HELM_DOMAIN table. The project representation of the domain and the host is now the canonical one. Host and Domain now subclass ProjectGroup. The canonical representation of a project's membership in a domain group is now the corresponding mapping in HELM_PROJECT_PROJECTGROUP. Schema changes: No more HELM_DOMAIN table (obviously); no more DOMAIN_ID in HELM_PROJECT; HELM_USER and HELM_VC_VIEW now have foreign keys in HELM_PROJECT instead of HELM_DOMAIN.
@
text
@d56 1
a56 1
import org.joist.util.JoistProperties;
d196 1
a196 1
        JoistProperties prop = JoistProperties.getInstance();
@


1.30
log
@Removed debug.
@
text
@d105 1
a105 2
        messageUsersWithProjectOwnership(ProjectPeer.getHostProject(),
                                         subject, body);
d109 2
a110 1
     * Send system mail to every user with a given domain role.
d112 2
a113 2
    public void messageUsersWithDomainOwnership(Domain domain,
                                                String subject, String body)
d116 1
a116 2
        messageUsersWithProjectOwnership(domain.getSpecialProject(),
                                         subject, body);
@


1.29
log
@* Added to debugging message.

* Checked To email address more rigorously.
@
text
@a129 2
        Log.debug("HelmEmailer.messageUsersWithProjectOwnership: Project " + 
                  project.getName() + " has " + users.size() + " owners");
@


1.28
log
@Don't send mail if the user has no email address.
@
text
@d52 1
a52 1
import org.apache.turbine.util.TurbineException;
d130 2
a131 1
        Log.debug("Project " + project.getName() + " has " + users.size() + " owners.");
d234 1
a234 1
        if (toEmail != null)
@


1.27
log
@.wm is now .vm
@
text
@d232 5
a236 1
        sendEmailFrom(fromEmail, to.getEmail(), subject, body);
@


1.26
log
@Finally got rid of REQUESTABLE and DENOTES_OWNER fields in HELM_ROLE.
@
text
@d129 2
a130 8
        Criteria c = RolePeer.getCriteriaForRolesWithBooleanAttribute
            (AttributePeer.DENOTES_OWNERSHIP_ATTRIBUTE)
            .addJoin(UserRoleProjectPeer.USER_ID, UserPeer.USER_ID)
            .addJoin(UserRoleProjectPeer.ROLE_ID, RolePeer.ROLE_ID)
            .add(UserRoleProjectPeer.PROJECT_ID, project.getProjectId())
            .add(UserRoleProjectPeer.APPROVED_BY, 
                 (Object)UserPeer.getNobodyUser().getID(), Criteria.NOT_EQUAL);
        List users = UserPeer.doSelect(c);
@


1.25
log
@Ported Helm from WebMacro to Velocity.
@
text
@d129 2
a130 1
        Criteria c = new Criteria()
d135 1
a135 2
                 (Object)UserPeer.getNobodyUser().getID(), Criteria.NOT_EQUAL)
            .add(RolePeer.DENOTES_OWNER, DBFlag.ON);
@


1.24
log
@Ripe for inlining.
@
text
@d52 2
@


1.23
log
@Used constant instead of magic string.
@
text
@d186 1
a186 1
    private void printHorizontalLine(StringBuffer buf)
@


1.22
log
@* Added printHorizontalLine(StringBuffer buf) method and
VIEWABLE_WIDTH constant.

* Cleaned up.
@
text
@d133 1
a133 1
            .add(RolePeer.DENOTES_OWNER, "Y");
@


1.21
log
@Corrected database query which was never returning any results.
@
text
@d74 5
d87 2
a88 1
        try {
d90 4
a93 2
        } catch (Exception e) {
            Log.error("Could not send mail to host admin! ", e);
d142 3
a144 1
        } else {
d159 1
a159 5
                for (int i = 0; i < 80; i++) 
                {
                    newBody.append("-");
                }
                newBody.append("\n\n");
d163 3
a165 2
                
            } else {
d173 1
a173 5
                for (int i = 0; i < 80; i++) 
                {
                    newBody.append("-");
                }
                newBody.append("\n\n");
d184 12
d215 2
a216 1
        mailUserFromAddress(to, from.getRealName(), from.getEmail(), subject, body);
a228 1

d238 1
a238 2

} /*End of class HelmEmailer*/
@


1.20
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d120 2
d123 5
a127 3
            .add(RolePeer.DENOTES_OWNER, true);
        List mappings = UserRoleProjectPeer.doSelect(c);
        if (mappings.size() > 0)
d129 1
a129 1
            for (Iterator i = mappings.iterator(); i.hasNext();)
d131 1
a131 3
                UserRoleProject mapping = (UserRoleProject)i.next();
                User user = UserPeer.getInstance(String.valueOf
                                                 (mapping.getUserId()));
@


1.20.6.1
log
@* Added printHorizontalLine(StringBuffer buf) method and
VIEWABLE_WIDTH constant.

* Cleaned up.
@
text
@a73 5
     * Number of viewable columns we assume mail readers to have.
     */
    private static final int VIEWABLE_WIDTH = 78;

    /**
d82 1
a82 2
        try
        {
d84 2
a85 4
        }
        catch (Exception e)
        {
            Log.error("Could not send mail to host admin!", e);
d132 1
a132 3
        }
        else
        {
d147 5
a151 1
                printHorizontalLine(newBody);
d155 2
a156 3
            }
            else
            {
d164 5
a168 1
                printHorizontalLine(newBody);
a178 12
     * Prints a dash-based horizontal rule to the supplied buffer.
     */
    private void printHorizontalLine(StringBuffer buf)
    {
        for (int i = 0; i < VIEWABLE_WIDTH; i++) 
        {
            buf.append('-');
        }
        buf.append("\n\n");
    }

    /**
d198 1
a198 2
        mailUserFromAddress(to, from.getRealName(), from.getEmail(), subject,
                            body);
d211 1
d221 2
a222 1
}
@


1.20.6.2
log
@Use the correct constant.
@
text
@d58 1
a58 1
import org.tigris.helm.tool.DBFlag;
d129 1
a129 1
            .add(RolePeer.DENOTES_OWNER, DBFlag.ON);
@


1.20.6.3
log
@Backported change from HEAD. This change puts in a condition and a
join from HELM_URP to HELM_ROLE so that only users with approved roles
in the project will get email.
@
text
@a127 2
            .addJoin(UserRoleProjectPeer.USER_ID, UserPeer.USER_ID)
            .addJoin(UserRoleProjectPeer.ROLE_ID, RolePeer.ROLE_ID)
a128 2
            .add(UserRoleProjectPeer.APPROVED_BY, 
                 (Object)UserPeer.getNobodyUser().getID(), Criteria.NOT_EQUAL)
@


1.20.6.4
log
@Only send mail to valid email addresses.
@
text
@a51 1
import org.apache.turbine.util.StringUtils;
d238 1
a238 5
        String toEmail = to.getEmail();
        if (StringUtils.isValid(toEmail))
        {
            sendEmailFrom(fromEmail, toEmail, subject, body);
        }
@


1.20.6.5
log
@Backported fix to mail-sending system.
@
text
@d128 9
a136 2
        List owners = project.getOwners();
        if (owners.size() > 0)
d138 1
a138 1
            for (Iterator i = owners.iterator(); i.hasNext();)
d140 4
a143 2
                User owner = (User)i.next();
                mailUserFromSystem(owner, subject, body);
@


1.19
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@d59 1
a59 3
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;

@


1.18
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.
d49 1
a49 2
import java.util.List;
import java.util.Iterator;
d51 2
a52 2
import java.sql.Connection;
import java.sql.SQLException;
a53 3
import org.webmacro.util.Log;

import org.joist.JoistException;
a55 4
import org.joist.database.DataManager;
import org.joist.database.JoistDatabaseException;

import com.workingdogs.village.*;
d58 3
a60 6
import org.tigris.helm.domain.Domain;
import org.tigris.helm.domain.User;
import org.tigris.helm.domain.Role;
import org.tigris.helm.project.Project;
import org.tigris.helm.database.UserRoleProjectManager;
import org.tigris.helm.database.ProjectManager;
d63 2
a64 2
 * HelmEmailer can send email to people by their userID, to everyone
 * with a role in a project, etc.
d66 1
a66 1
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
a75 24
     * For logging.
     */
    protected static Log log = new Log("HMail", "HelmEmailer");    

    /**
     * For database access.
     */
    private Connection connection;

    /**
     * For database access.
     */
    private DataManager dMgr;

    /**
     * Constructor.
     */
    public HelmEmailer(Connection connection, DataManager dMgr)
    {
        this.connection = connection;
        this.dMgr = dMgr;
    }

    /**
d80 3
a82 3
        log.warning("SYSTEM ERROR! " + subject);
        log.warning(body);
        log.warning("Sending mail to host admin...");
d85 1
a85 2
            Role role = new Role(connection, dMgr, "Host Admin", false);
            messageUsersWithHostRole(role, subject, body);
d87 1
a87 1
            log.warning("Could not send mail to host admin!");
d92 1
a92 1
     * Send system mail to every user with a given host role.
d94 5
a98 9
    public void messageUsersWithHostRole(Role role, String subject,
            String body)
        throws DataSetException, SQLException, JoistException,
               JoistDatabaseException, DoesNotExist
    {
        ProjectManager pMgr = (ProjectManager)dMgr.getManager
            ("org.tigris.helm.database.ProjectManager");
        Project p = new Project(connection, dMgr, pMgr.getHostProjectID());
        messageUsersWithProjectRole(role, p, subject, body);
d104 3
a106 4
    public void messageUsersWithDomainRole(Role role, Domain domain,
                                           String subject, String body)
        throws DataSetException, SQLException, JoistException,
               JoistDatabaseException, DoesNotExist
d108 2
a109 2
        messageUsersWithProjectRole
            (role, domain.getSpecialProject(), subject, body);
d117 9
a125 10
    public void messageUsersWithProjectRole
        (Role role, Project project, String subject, String body)
        throws DataSetException, SQLException, JoistException,
               JoistDatabaseException, DoesNotExist
    {
        UserRoleProjectManager urpMgr = (UserRoleProjectManager)dMgr.getManager
            ("org.tigris.helm.database.UserRoleProjectManager");
        DataSet users = urpMgr.getUsersForRoleProject(connection, role.getID(),
                                                      project.getID());
        if (users.size() > 0 || role.getName().equals("Domain Admin"))
d127 1
a127 1
            for (int i = 0; i < users.size(); i++)
d129 3
a131 3
                String uid = users.getRecord(i)
                    .getValue(UserRoleProjectManager.USER_ID).toString();
                User user = User.getInstance(connection, dMgr, uid);
d135 5
a139 7
            //Nobody has the project role. Mail the domain admins instead.
            StringBuffer newBody = new StringBuffer();
            newBody.append("Since no one has the ").append(role.getName())
                .append(" role in the ").append(project.getName())
                .append(" project, the following message is being sent to ")
                .append("all domain admins:\n\n");
            for (int i = 0; i < 80; i++) 
d141 35
a175 1
                newBody.append("-");
a176 8
            newBody.append("\n\n");
            newBody.append(body);
            Domain projectDomain = 
                new Domain(connection, dMgr, project.getDomainID());
            Role domainRole = 
                new Role(connection, dMgr, "Domain Admin", false);
            messageUsersWithDomainRole
                (domainRole, projectDomain, subject, newBody.toString());
d184 1
a184 1
        throws DataSetException, JoistException
d196 13
a208 2
    public void mailUserFromUser(User to, User from, String subject,
            String body) throws DataSetException, JoistException
d210 1
a210 1
        mailUserFromAddress(to, from.getName(), from.getEmail(), subject, body);
d213 1
d219 1
a219 1
        throws DataSetException, JoistException
@


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


1.18.2.2
log
@Ported HelmEmailer.
@
text
@d49 2
a50 1
import java.util.*;
d52 2
a53 2
import org.apache.turbine.util.Log;
import org.apache.turbine.util.db.Criteria;
d55 3
d60 4
d66 6
a71 2
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
d74 2
a75 2
 * HelmEmailer can send email to a specific user, to everyone with an
 * ownership role in a project/domain, etc.
d77 1
a77 1
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a> 
d87 24
d115 3
a117 3
        Log.warn("SYSTEM ERROR! " + subject);
        Log.warn(body);
        Log.warn("Sending mail to host admin...");
d120 2
a121 1
            messageUsersWithHostOwnership(subject, body);
d123 1
a123 1
            Log.error("Could not send mail to host admin! ", e);
d128 1
a128 1
     * Send system mail to every user with an ownership role in the host.
d130 9
a138 5
    public void messageUsersWithHostOwnership(String subject, String body)
        throws Exception
    {
        messageUsersWithProjectOwnership(ProjectPeer.getHostProject(),
                                         subject, body);
d144 4
a147 3
    public void messageUsersWithDomainOwnership(Domain domain,
                                                String subject, String body)
        throws Exception
d149 2
a150 2
        messageUsersWithProjectOwnership(domain.getSpecialProject(),
                                         subject, body);
d158 10
a167 9
    public void messageUsersWithProjectOwnership
        (Project project, String subject, String body)
        throws Exception
    {
        Criteria c = new Criteria()
            .add(UserRoleProjectPeer.PROJECT_ID, project.getProjectId())
            .add(RolePeer.DENOTES_OWNER, true);
        List mappings = UserRoleProjectPeer.doSelect(c);
        if (mappings.size() > 0)
d169 1
a169 1
            for (Iterator i = mappings.iterator(); i.hasNext();)
d171 3
a173 3
                UserRoleProject mapping = (UserRoleProject)i.next();
                User user = UserPeer.getInstance(String.valueOf
                                                 (mapping.getUserId()));
d177 7
a183 5
            if (project.isHost())
            {
                //We're screwed.
            } 
            else if (project.isDomain())
d185 1
a185 35
                //Nobody is in charge of the domain.
                //This is a serious problem--mail the host admins.
                StringBuffer newBody = new StringBuffer();
                newBody.append("Since no one seems to have responsibility")
                    .append(" for the ")
                    .append(project.getDomain().getName())
                    .append(" domain, the following message is being sent to")
                    .append(" those with responsibility for the host:\n\n");
                for (int i = 0; i < 80; i++) 
                {
                    newBody.append("-");
                }
                newBody.append("\n\n");
                newBody.append(body);
                
                messageUsersWithHostOwnership(subject, newBody.toString());
                
            } else {
                //Nobody has the project role. Mail the domain admins instead.
                StringBuffer newBody = new StringBuffer();
                newBody.append("Since no one seems to have responsibility")
                    .append(" for the ")
                    .append(project.getName())
                    .append(" project, the following message is being sent to")
                    .append(" those with responsibility for the domain:\n\n");
                for (int i = 0; i < 80; i++) 
                {
                    newBody.append("-");
                }
                newBody.append("\n\n");
                newBody.append(body);
                
                Domain projectDomain = project.getDomain();
                messageUsersWithDomainOwnership
                    (projectDomain, subject, newBody.toString());
d187 8
d202 1
a202 1
        throws Exception
d214 2
a215 3
    public void mailUserFromUser(User to, User from, String subject, 
                                 String body)
            throws Exception
d217 1
a217 1
        mailUserFromAddress(to, from.getRealName(), from.getEmail(), subject, body);
d225 1
a225 1
        throws Exception
@


1.18.2.3
log
@Big wide-ranging patch being committed all at once due to network downness. Features of this patch include: lots of added and updated JavaDoc, conversion of emails to use TemplateInterpolator and HelmEmailer, rearrangement of methods, changing code that gets mappings and loops over them to code that just gets the appropriate objects from the peer using AddJoin.
@
text
@a202 11
     * Sends mail from one user to another.
     */
    public void sendMailFromUser(String toAddress, User from, String subject, 
                                 String body)
        throws Exception
    {
        sendEmailFrom(from.getEmail(), toAddress, subject, body);
    }


    /**
@


1.18.2.4
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
@


1.18.2.5
log
@Added new imports necessitated by Torque.
@
text
@a59 1
import org.tigris.helm.om.base.*;
@


1.17
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.16
log
@Broke into two lines for better readability.
@
text
@@


1.15
log
@Pedantic correction ahoy!
@
text
@d137 2
a138 4
        messageUsersWithProjectRole(role, 
                                    new Project(connection, dMgr, 
                                                pMgr.getHostProjectID()),
                                    subject, body);
@


1.14
log
@Removed unnecessary getCache() implementations in BusinessObject subclasses and migrated to a factory method for User's primary database key ctor.
@
text
@d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
@


1.13
log
@Patch to my previous commit--infinite loop blah.
@
text
@d173 3
a175 3
                User user = new User(connection, dMgr, users.getRecord(i)
                                     .getValue(UserRoleProjectManager.USER_ID)
                                     .toString());
@


1.12
log
@Defused potential infinite recursion.
@
text
@d111 1
a111 1
     * Send system mail to every user with a given host role.
d144 1
a144 1
     * Send system mail to every user with a given host role.
d168 1
a168 1
                project.getID());
d193 4
a196 1
            messageUsersWithDomainRole(role, projectDomain, subject, newBody.toString());
@


1.11
log
@If sending mail to people with role in project, and there are no such people, mail it to domain admins instead.
@
text
@d169 1
a169 1
        if (users.size() > 0)
@


1.10
log
@* adjust for corrections to Role constructor
* correct another Role constructor which listed the DataManager before
  the Connection
@
text
@d169 1
a169 1
        for (int i = 0; i < users.size(); i++)
d171 23
a193 4
            User user = new User(connection, dMgr, users.getRecord(i)
                                 .getValue(UserRoleProjectManager.USER_ID)
                                 .toString());
            mailUserFromSystem(user, subject, body);                                 
@


1.9
log
@Make errors sending mail less destructive.
@
text
@d120 1
a120 1
            Role role = new Role(dMgr, connection, "Host Admin", false);
@


1.9.2.1
log
@If no one has the role in a project neccessary to trigger an email message, send the message instead to the domain admins.
@
text
@d111 1
a111 1
     * Send an error message to the host admins.
d144 1
a144 1
     * Send system mail to every user with a given domain role.
d168 2
a169 2
                                                      project.getID());
        if (users.size() > 0 || role.getName().equals("Domain Admin"))
d171 4
a174 26
            for (int i = 0; i < users.size(); i++)
            {
                User user = new User(connection, dMgr, users.getRecord(i)
                                     .getValue(UserRoleProjectManager.USER_ID)
                                     .toString());
                mailUserFromSystem(user, subject, body);
            }
        } else {
            //Nobody has the project role. Mail the domain admins instead.
            StringBuffer newBody = new StringBuffer();
            newBody.append("Since no one has the ").append(role.getName())
                .append(" role in the ").append(project.getName())
                .append(" project, the following message is being sent to ")
                .append("all domain admins:\n\n");
            for (int i = 0; i < 80; i++) 
            {
                newBody.append("-");
            }
            newBody.append("\n\n");
            newBody.append(body);
            Domain projectDomain = 
                new Domain(connection, dMgr, project.getDomainID());
            Role domainRole = 
                new Role(dMgr, connection, "Domain Admin", false);
            messageUsersWithDomainRole
                (domainRole, projectDomain, subject, newBody.toString());
@


1.8
log
@Factored out system email settings into properties file.
@
text
@a122 1
            log.exception(e);
@


1.7
log
@Send mail to domain admins on creation of unapproved project.
@
text
@d58 1
d186 4
a189 3
        log.info("!!!Sending mail to " + to.getEmail());
        mailUserFromAddress(to, "SourceCast", "admin@@sourcecast.com", subject,
                            body);
@


1.6
log
@reformat to avoid lines longer than 80 characters ...
@
text
@d65 1
d120 1
a120 1
            mailUsersWithHostRoleFromSystem(role, subject, body);
d130 1
a130 1
    public void mailUsersWithHostRoleFromSystem(Role role, String subject,
d137 16
a152 3
        mailUsersWithProjectRoleFromSystem(role, new Project(connection, dMgr, 
                                                             pMgr.getHostProjectID()),
                                           subject, body);
d160 1
a160 1
    public void mailUsersWithProjectRoleFromSystem
d185 1
@


1.5
log
@Cleanup.
@
text
@d129 4
a132 2
    public void mailUsersWithHostRoleFromSystem(Role role, String subject, String body)
        throws DataSetException, SQLException, JoistException, JoistDatabaseException, DoesNotExist
d148 2
a149 1
        throws DataSetException, SQLException, JoistException, JoistDatabaseException, DoesNotExist
d153 2
a154 1
        DataSet users = urpMgr.getUsersForRoleProject(connection, role.getID(), project.getID());
d158 2
a159 1
                                 .getValue(UserRoleProjectManager.USER_ID).toString());
d171 2
a172 1
        mailUserFromAddress(to, "SourceCast", "admin@@sourcecast.com", subject, body);
d178 2
a179 2
    public void mailUserFromUser(User to, User from, String subject, String body)
        throws DataSetException, JoistException
d187 2
a188 2
    public void mailUserFromAddress(User to, String fromEmail, String fromName, String subject,
                                    String body)
@


1.4
log
@Fixed incorrect method call.
@
text
@a154 1
            log.info("Sending email to: " + user.getID() + " re: " + subject);
@


1.3
log
@Send mail to project owners when someone requests a role in a project.
@
text
@d155 1
@


1.2
log
@Email host admins on failure of a script.
@
text
@d144 2
a145 2
    public void mailUsersWithProjectRoleFromSystem(Role role, Project project, String subject, 
                                                   String body)
@


1.1
log
@New class for sending system alert emails--to be used in QueueHandler, project approval, etc.
@
text
@d108 17
d138 1
a138 1

d153 2
a154 1
            User user = new User(connection, dMgr, users.getRecord(i));
@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d49 2
a50 1
import java.util.*;
d52 2
a53 2
import org.apache.turbine.util.Log;
import org.apache.turbine.util.db.Criteria;
d55 3
a57 1
import org.joist.util.JoistProperties;
d59 4
d65 5
a69 3
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
d72 2
a73 2
 * HelmEmailer can send email to a specific user, to everyone with an
 * ownership role in a project/domain, etc.
d75 1
a75 1
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a> 
d85 11
a95 1
     * Send an error message to the host admins.
d97 1
a97 12
    public void sendError (String subject, String body)
    {
        Log.warn("SYSTEM ERROR! " + subject);
        Log.warn(body);
        Log.warn("Sending mail to host admin...");
        subject = "ERROR: " + subject;
        try {
            messageUsersWithHostOwnership(subject, body);
        } catch (Exception e) {
            Log.error("Could not send mail to host admin! ", e);
        }
    }
d100 1
a100 1
     * Send system mail to every user with an ownership role in the host.
d102 1
a102 2
    public void messageUsersWithHostOwnership(String subject, String body)
        throws Exception
d104 5
a108 4
        messageUsersWithProjectOwnership(ProjectPeer.getHostProject(),
                                         subject, body);
    }        
    
d110 1
a110 1
     * Send system mail to every user with a given domain role.
d112 2
a113 3
    public void messageUsersWithDomainOwnership(Domain domain,
                                                String subject, String body)
        throws Exception
d115 5
a119 2
        messageUsersWithProjectOwnership(domain.getSpecialProject(),
                                         subject, body);
d121 1
a121 1
    
d127 8
a134 9
    public void messageUsersWithProjectOwnership
        (Project project, String subject, String body)
        throws Exception
    {
        Criteria c = new Criteria()
            .add(UserRoleProjectPeer.PROJECT_ID, project.getProjectId())
            .add(RolePeer.DENOTES_OWNER, true);
        List mappings = UserRoleProjectPeer.doSelect(c);
        if (mappings.size() > 0)
d136 2
a137 50
            for (Iterator i = mappings.iterator(); i.hasNext();)
            {
                UserRoleProject mapping = (UserRoleProject)i.next();
                User user = UserPeer.getInstance(String.valueOf
                                                 (mapping.getUserId()));
                mailUserFromSystem(user, subject, body);
            }
        } else {
            if (project.isHost())
            {
                //We're screwed.
            } 
            else if (project.isDomain())
            {
                //Nobody is in charge of the domain.
                //This is a serious problem--mail the host admins.
                StringBuffer newBody = new StringBuffer();
                newBody.append("Since no one seems to have responsibility")
                    .append(" for the ")
                    .append(project.getDomain().getName())
                    .append(" domain, the following message is being sent to")
                    .append(" those with responsibility for the host:\n\n");
                for (int i = 0; i < 80; i++) 
                {
                    newBody.append("-");
                }
                newBody.append("\n\n");
                newBody.append(body);
                
                messageUsersWithHostOwnership(subject, newBody.toString());
                
            } else {
                //Nobody has the project role. Mail the domain admins instead.
                StringBuffer newBody = new StringBuffer();
                newBody.append("Since no one seems to have responsibility")
                    .append(" for the ")
                    .append(project.getName())
                    .append(" project, the following message is being sent to")
                    .append(" those with responsibility for the domain:\n\n");
                for (int i = 0; i < 80; i++) 
                {
                    newBody.append("-");
                }
                newBody.append("\n\n");
                newBody.append(body);
                
                Domain projectDomain = project.getDomain();
                messageUsersWithDomainOwnership
                    (projectDomain, subject, newBody.toString());
            }
d145 1
a145 1
        throws Exception
d148 1
a148 14
        JoistProperties prop = JoistProperties.getInstance();
        String systemName = prop.getProperty("systemEmail");
        String systemEmail = prop.getProperty("systemEmailName");
        mailUserFromAddress(to, systemName, systemEmail, subject, body);
    }

    /**
     * Sends mail from one user to another.
     */
    public void mailUserFromUser(User to, User from, String subject, 
                                 String body)
            throws Exception
    {
        mailUserFromAddress(to, from.getRealName(), from.getEmail(), subject, body);
d154 2
a155 3
    public void sendMailFromUser(String toAddress, User from, String subject, 
                                 String body)
        throws Exception
d157 1
a157 1
        sendEmailFrom(from.getEmail(), toAddress, subject, body);
a159 1

d163 3
a165 3
    public void mailUserFromAddress(User to, String fromEmail, String fromName,
                                    String subject, String body)
        throws Exception
@


