buildframework/helium/sf/java/signaling/src/com/nokia/helium/signal/ant/types/EMAILNotifier.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 645 b8d81fa19e7d
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
/*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
 * All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
 * Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
 * Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
 * Description:  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
package com.nokia.helium.signal.ant.types;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
import com.nokia.helium.core.EmailDataSender;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    21
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    22
import com.nokia.helium.core.EmailSendException;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import com.nokia.helium.core.PropertiesSource;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import com.nokia.helium.core.TemplateInputSource;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import com.nokia.helium.signal.Notifier;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import com.nokia.helium.core.TemplateProcessor;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import java.util.List;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import java.util.Hashtable;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import java.util.ArrayList;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
import java.io.IOException;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    31
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    32
import org.apache.tools.ant.BuildException;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
import org.apache.tools.ant.Project;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
import org.apache.tools.ant.types.DataType;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
import java.io.File;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
/**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
 * The emailNotifier provides you an easy way to send a you and email containing
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
 * the summary of a build failure.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
 * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
 * @ant.type name="emailNotifier" category="Signaling"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
public class EMAILNotifier extends DataType implements Notifier {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
    private TemplateProcessor templateProcessor = new TemplateProcessor();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
    private File defaultTemplate;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
    private String title;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
    private String smtp;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
    private String ldap;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
    private String rootdn;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
    private String notifyWhen = "never";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
    private String from;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
    private String additionalRecipients;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
     * Rendering the template, and sending the result through email.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    57
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
     * @param signalName
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    59
     *            - is the name of the signal that has been raised.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    60
     * @param failStatus
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    61
     *            - indicates whether to fail the build or not
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    62
     * @param notifierInput
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    63
     *            - contains signal notifier info
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    64
     * @param message
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    65
     *            - is the message from the signal that has been raised.
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
    @SuppressWarnings("unchecked")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
    public void sendData(String signalName, boolean failStatus,
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    70
            NotifierInput notifierInput, String message) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        if (notifyWhen != null
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    72
                && (notifyWhen.equals("always")
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    73
                        || (notifyWhen.equals("fail") && failStatus) || (notifyWhen
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    74
                        .equals("pass") && !failStatus))) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
            if (title == null) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    76
                throw new BuildException(
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    77
                        "The 'title' attribute has not been defined.");
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
            if (smtp == null) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    81
                throw new BuildException(
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    82
                        "The 'smtp' attribute has not been defined.");
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    85
            if (ldap == null && from == null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    86
                throw new BuildException(
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    87
                        "The 'ldap' attribute has not been defined.");
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
            }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    89
            EmailDataSender emailSender = createEmailDataSender();
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    91
            Project subProject = getProject().createSubProject();
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    92
            subProject.setProperty("signal.name", signalName);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    93
            subProject.setProperty("signal.status", "" + failStatus);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    94
            subProject.setProperty("signal.message", "" + message);
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    95
            try {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    96
                
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    97
                File fileToSend = null;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    98
                if (notifierInput != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    99
                    fileToSend = notifierInput.getFile(".*.html");
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
                }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   101
                if (fileToSend == null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   102
                    if (defaultTemplate != null && defaultTemplate.exists()) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   103
                        File emailOutputFile;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   104
                        try {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   105
                            emailOutputFile = File.createTempFile("helium_",
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   106
                                    "email.html");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   107
                            emailOutputFile.deleteOnExit();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   108
                            log("sending data by e-mail:outputDir: "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   109
                                    + emailOutputFile.getAbsolutePath(), Project.MSG_DEBUG);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   111
                            List<TemplateInputSource> sourceList = new ArrayList<TemplateInputSource>();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   112
                            sourceList.add(new PropertiesSource("ant",
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   113
                                    getProject().getProperties()));
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   114
                            Hashtable<String, String> signalProperties = new Hashtable<String, String>();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   115
                            signalProperties.put("signal.name", signalName);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   116
                            signalProperties.put("signal.status", ""
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   117
                                    + failStatus);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   118
                            signalProperties
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   119
                                    .put("signal.message", "" + message);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   120
                            sourceList.add(new PropertiesSource("signaling",
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   121
                                    signalProperties));
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   123
                            templateProcessor.convertTemplate(defaultTemplate,
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   124
                                    emailOutputFile, sourceList);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   125
                            fileToSend = emailOutputFile;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   126
                        } catch (IOException e) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   127
                            log("EmailNotifier: IOexception: " + e.getMessage(), Project.MSG_DEBUG);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   128
                        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   129
                    } else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   130
                        if (defaultTemplate == null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   131
                            log("The 'defaultTemplate' has not been defined.",
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   132
                                    Project.MSG_WARN);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   133
                        } else if (!defaultTemplate.exists()) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   134
                            log("Could not find default template: "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   135
                                    + defaultTemplate.getAbsolutePath(),
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   136
                                    Project.MSG_WARN);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   137
                        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   138
                    }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
                }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   140
                emailSender.sendData("signaling", fileToSend, "application/html",
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   141
                        subProject.replaceProperties(title), null);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   142
            } catch (EmailSendException ese) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   143
                log(this.getDataTypeName() + " Warning: " + ese.getMessage(), Project.MSG_WARN);
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
   144
            }
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
    /**
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   149
     * Create an EmailDataSender base on this type settings.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   150
     * @return
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   151
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   152
    private EmailDataSender createEmailDataSender() {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   153
        String smtpUpdated = getProject().replaceProperties(smtp);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   154
        String ldapUpdated = getProject().replaceProperties(ldap);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   155
        String additionalRecipientsUpdated = getProject()
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   156
                .replaceProperties(additionalRecipients);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   157
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   158
        log("Sending data by e-mail.", Project.MSG_DEBUG);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   159
        EmailDataSender emailSender;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   160
        if (additionalRecipientsUpdated == null) { 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   161
            additionalRecipientsUpdated = from;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   162
        } else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   163
            additionalRecipientsUpdated += (from != null) ? (additionalRecipientsUpdated.length() > 0 ? "," : "") + from : "";
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   164
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   165
        if (rootdn != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   166
            String[] to = null;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   167
            if (additionalRecipientsUpdated != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   168
                to = additionalRecipientsUpdated.split(",");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   169
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   170
            emailSender = new EmailDataSender(to, smtpUpdated, ldapUpdated,
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   171
                    getProject().replaceProperties(rootdn));
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   172
        } else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   173
            emailSender = new EmailDataSender(additionalRecipientsUpdated,
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   174
                    smtpUpdated, ldapUpdated);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   175
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   176
        if (from == null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   177
            try {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   178
                emailSender.addCurrentUserToAddressList();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   179
            } catch (EmailSendException ex) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   180
                // Consider the error as a warning, let's try to send the email anyway
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   181
                log(this.getDataTypeName() + " Warning: " + ex.getMessage(), Project.MSG_WARN);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   182
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   183
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   184
        if (from != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   185
            log("Setting from: " + from);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   186
            emailSender.setFrom(from);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   187
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   188
        log("EmailNotifier:arlist: " + additionalRecipientsUpdated, Project.MSG_DEBUG);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   189
        return emailSender;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   190
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   191
    
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   192
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   193
     * Set when the notifier should emit the massage. Possible values are:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   194
     * never, always, fail, pass.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   195
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
     * @ant.not-required Default is never.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   198
    public void setNotifyWhen(NotifyWhenEnum notifyWhen) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   199
        this.notifyWhen = notifyWhen.getValue();
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   202
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   203
     * When do we need to notify the user?
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   204
     * 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   205
     * @return
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   206
     */
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
    public String getNotifyWhen() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
        return notifyWhen;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
     * Define the template source file to use while rendering the message.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
     * @ant.required
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
    public void setDefaultTemplate(File template) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
        this.defaultTemplate = template;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
     * Define the template source file to use while rendering the message.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   222
     * 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
     * @deprecated
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
     * @ant.required
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   226
    @Deprecated
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
    public void setTemplateSrc(File template) {
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   228
        log(
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   229
                "The usage of the templateSrc attribute is deprecated,"
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   230
                        + " please consider using the defaultTemplate attribute instead.",
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   231
                Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   232
        this.defaultTemplate = template;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   233
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   234
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   235
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   236
     * The title of the email.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   237
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   238
     * @ant.required
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   239
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   240
    public void setTitle(String title) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   241
        this.title = title;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   242
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   243
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   244
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   245
     * The STMP server address.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   246
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   247
     * @ant.required
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   248
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   249
    public void setSmtp(String smtp) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   250
        this.smtp = smtp;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   251
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   252
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   253
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   254
     * Who the email is sent from.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   255
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   256
     * @ant.not-required
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   257
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   258
    public void setFrom(String from) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   259
        this.from = from;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   260
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   261
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   262
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   263
     * Comma separated list of additional email addresses.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   264
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   265
     * @ant.not-required
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   266
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   267
    public void setAdditionalRecipients(String ar) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   268
        this.additionalRecipients = ar;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   269
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   270
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   271
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   272
     * The LDAP server URL.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   273
     * 
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   274
     * @ant.required (or from attribute can be used)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   275
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   276
    public void setLdap(String ldap) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   277
        this.ldap = ldap;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   278
    }
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   279
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   280
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   281
     * The LDAP rootdn.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   282
     * @param rootdn
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   283
     * @ant.required
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
   284
     */
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   285
    public void setRootdn(String rootdn) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   286
        this.rootdn = rootdn;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   287
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   288
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   289
}