Search in sources :

Example 1 with Email

use of org.cerberus.service.email.entity.Email in project cerberus-source by cerberustesting.

the class EmailFactory method create.

@Override
public Email create(String host, int smtpPort, String userName, String password, boolean setTls, String subject, String body, String from, String to, String cc) {
    Email email = new Email();
    email.setBody(body);
    email.setCc(cc);
    email.setFrom(from);
    email.setHost(host);
    email.setPassword(password);
    email.setSetTls(setTls);
    email.setSmtpPort(smtpPort);
    email.setSubject(subject);
    email.setTo(to);
    email.setUserName(userName);
    return email;
}
Also used : Email(org.cerberus.service.email.entity.Email)

Example 2 with Email

use of org.cerberus.service.email.entity.Email in project cerberus-source by cerberustesting.

the class EmailGenerationService method generateAccountCreationEmail.

@Override
public Email generateAccountCreationEmail(User user) throws Exception {
    String system = "";
    Email email = new Email();
    /* Pick the datas from the database */
    String from = parameterService.findParameterByKey("cerberus_notification_accountcreation_from", system).getValue();
    String host = parameterService.findParameterByKey("cerberus_smtp_host", system).getValue();
    int port = Integer.valueOf(parameterService.findParameterByKey("cerberus_smtp_port", system).getValue());
    String userName = parameterService.findParameterByKey("cerberus_smtp_username", system).getValue();
    String password = parameterService.findParameterByKey("cerberus_smtp_password", system).getValue();
    String to = user.getEmail();
    String cc = cc = parameterService.findParameterByKey("cerberus_notification_accountcreation_cc", system).getValue();
    String subject = parameterService.findParameterByKey("cerberus_notification_accountcreation_subject", system).getValue();
    String body = parameterService.findParameterByKey("cerberus_notification_accountcreation_body", system).getValue();
    body = body.replace("%NAME%", user.getName());
    body = body.replace("%LOGIN%", user.getLogin());
    body = body.replace("%DEFAULT_PASSWORD%", parameterService.findParameterByKey("cerberus_accountcreation_defaultpassword", system).getValue());
    email = emailFactory.create(host, port, userName, password, true, subject, body, from, to, cc);
    return email;
}
Also used : Email(org.cerberus.service.email.entity.Email)

Example 3 with Email

use of org.cerberus.service.email.entity.Email in project cerberus-source by cerberustesting.

the class EmailGenerationService method generateNewChainEmail.

@Override
public Email generateNewChainEmail(String system, String country, String env, String chain) throws Exception {
    Email email = new Email();
    /* Page Display - START */
    CountryEnvParam myCountryEnvParam;
    myCountryEnvParam = countryEnvParamService.convert(countryEnvParamService.readByKey(system, country, env));
    BatchInvariant myBatchInvariant;
    myBatchInvariant = batchInvariantService.convert(batchInvariantService.readByKey(chain));
    String lastchain = myBatchInvariant.getBatch() + " (" + myBatchInvariant.getDescription() + ")";
    /* Pick the datas from the database */
    String from = parameterService.findParameterByKey("cerberus_smtp_from", system).getValue();
    String host = parameterService.findParameterByKey("cerberus_smtp_host", system).getValue();
    int port = Integer.valueOf(parameterService.findParameterByKey("cerberus_smtp_port", system).getValue());
    String userName = parameterService.findParameterByKey("cerberus_smtp_username", system).getValue();
    String password = parameterService.findParameterByKey("cerberus_smtp_password", system).getValue();
    String to = parameterService.findParameterByKey("cerberus_notification_newchain_to", system).getValue();
    String cc = parameterService.findParameterByKey("cerberus_notification_newchain_cc", system).getValue();
    String subject = parameterService.findParameterByKey("cerberus_notification_newchain_subject", system).getValue();
    String body = parameterService.findParameterByKey("cerberus_notification_newchain_body", system).getValue();
    if (!StringUtil.isNullOrEmptyOrNull(myCountryEnvParam.geteMailBodyChain())) {
        body = myCountryEnvParam.geteMailBodyChain();
    }
    if (!StringUtil.isNullOrEmptyOrNull(myCountryEnvParam.getDistribList())) {
        to = myCountryEnvParam.getDistribList();
    }
    subject = subject.replace("%SYSTEM%", system);
    subject = subject.replace("%COUNTRY%", country);
    subject = subject.replace("%ENV%", env);
    subject = subject.replace("%BUILD%", myCountryEnvParam.getBuild());
    subject = subject.replace("%REVISION%", myCountryEnvParam.getRevision());
    subject = subject.replace("%CHAIN%", lastchain);
    body = body.replace("%SYSTEM%", system);
    body = body.replace("%COUNTRY%", country);
    body = body.replace("%ENV%", env);
    body = body.replace("%BUILD%", myCountryEnvParam.getBuild());
    body = body.replace("%REVISION%", myCountryEnvParam.getRevision());
    body = body.replace("%CHAIN%", lastchain);
    email = emailFactory.create(host, port, userName, password, true, subject, body, from, to, cc);
    return email;
}
Also used : Email(org.cerberus.service.email.entity.Email) CountryEnvParam(org.cerberus.crud.entity.CountryEnvParam) BatchInvariant(org.cerberus.crud.entity.BatchInvariant)

Example 4 with Email

use of org.cerberus.service.email.entity.Email in project cerberus-source by cerberustesting.

the class EmailGenerationService method generateRevisionChangeEmail.

@Override
public Email generateRevisionChangeEmail(String system, String country, String env, String build, String revision) throws Exception {
    Email email = new Email();
    CountryEnvParam myCountryEnvParam;
    myCountryEnvParam = countryEnvParamService.convert(countryEnvParamService.readByKey(system, country, env));
    /* Pick the datas from the database */
    String from = parameterService.findParameterByKey("cerberus_smtp_from", system).getValue();
    String host = parameterService.findParameterByKey("cerberus_smtp_host", system).getValue();
    int port = Integer.valueOf(parameterService.findParameterByKey("cerberus_smtp_port", system).getValue());
    String userName = parameterService.findParameterByKey("cerberus_smtp_username", system).getValue();
    String password = parameterService.findParameterByKey("cerberus_smtp_password", system).getValue();
    String to = parameterService.findParameterByKey("cerberus_notification_newbuildrevision_to", system).getValue();
    String cc = parameterService.findParameterByKey("cerberus_notification_newbuildrevision_cc", system).getValue();
    String subject = parameterService.findParameterByKey("cerberus_notification_newbuildrevision_subject", system).getValue();
    String body = parameterService.findParameterByKey("cerberus_notification_newbuildrevision_body", system).getValue();
    if (!StringUtil.isNullOrEmptyOrNull(myCountryEnvParam.geteMailBodyRevision())) {
        body = myCountryEnvParam.geteMailBodyRevision();
    }
    if (!StringUtil.isNullOrEmptyOrNull(myCountryEnvParam.getDistribList())) {
        to = myCountryEnvParam.getDistribList();
    }
    /* Replace the Keywords from the fed text  */
    subject = subject.replace("%SYSTEM%", system);
    subject = subject.replace("%COUNTRY%", country);
    subject = subject.replace("%ENV%", env);
    subject = subject.replace("%BUILD%", build);
    subject = subject.replace("%REVISION%", revision);
    body = body.replace("%SYSTEM%", system);
    body = body.replace("%COUNTRY%", country);
    body = body.replace("%ENV%", env);
    body = body.replace("%BUILD%", build);
    body = body.replace("%REVISION%", revision);
    // Generate the Table Contented in the mail
    String content;
    String lastBuild = myCountryEnvParam.getBuild();
    String lastRev = myCountryEnvParam.getRevision();
    content = emailBodyGeneration.GenerateBuildContentTable(system, build, revision, lastBuild, lastRev);
    content = content.replace("$", " ");
    body = body.replace("%BUILDCONTENT%", content);
    content = emailBodyGeneration.GenerateTestRecapTable(system, build, revision, country);
    content = content.replace("$", " ");
    body = body.replace("%TESTRECAP%", content);
    content = emailBodyGeneration.GenerateTestRecapTable(system, build, revision, "ALL");
    content = content.replace("$", " ");
    body = body.replace("%TESTRECAPALL%", content);
    // End
    email = emailFactory.create(host, port, userName, password, true, subject, body, from, to, cc);
    return email;
}
Also used : Email(org.cerberus.service.email.entity.Email) CountryEnvParam(org.cerberus.crud.entity.CountryEnvParam)

Example 5 with Email

use of org.cerberus.service.email.entity.Email in project cerberus-source by cerberustesting.

the class EmailService method generateAndSendNotifyEndTagExecution.

@Override
public MessageEvent generateAndSendNotifyEndTagExecution(String tag, String campaign) {
    try {
        Campaign myCampaign = campaignService.convert(campaignService.readByKey(campaign));
        if (!StringUtil.isNullOrEmpty(myCampaign.getDistribList())) {
            if (myCampaign.getNotifyEndTagExecution().equalsIgnoreCase(Campaign.NOTIFYSTARTTAGEXECUTION_Y) || myCampaign.getNotifyEndTagExecution().equalsIgnoreCase(Campaign.NOTIFYSTARTTAGEXECUTION_CIKO)) {
                // Flag is activated.
                JSONObject jsonResponse = new JSONObject();
                jsonResponse = ciService.getCIResult(tag);
                if (myCampaign.getNotifyEndTagExecution().equalsIgnoreCase(Campaign.NOTIFYSTARTTAGEXECUTION_Y) || (myCampaign.getNotifyEndTagExecution().equalsIgnoreCase(Campaign.NOTIFYSTARTTAGEXECUTION_CIKO) && jsonResponse.getString("result").equalsIgnoreCase("KO"))) {
                    // Flag is Y or CIKO with KO result.
                    Email email = null;
                    try {
                        email = emailGenerationService.generateNotifyEndTagExecution(tag, campaign, myCampaign.getDistribList(), jsonResponse.getString("result"), (double) jsonResponse.get("CI_finalResult"));
                    } catch (Exception ex) {
                        LOG.warn("Exception generating email for End Tag Execution :" + ex);
                        return new MessageEvent(MessageEventEnum.GENERIC_ERROR).resolveDescription("REASON", ex.toString());
                    }
                    try {
                        this.sendHtmlMail(email);
                    } catch (Exception ex) {
                        LOG.warn("Exception sending email for End Tag Execution :" + ex);
                        return new MessageEvent(MessageEventEnum.GENERIC_ERROR).resolveDescription("REASON", ex.toString());
                    }
                }
            }
        }
    } catch (Exception ex) {
        LOG.warn("Exception generating email for End Tag Execution :" + ex);
        return new MessageEvent(MessageEventEnum.GENERIC_ERROR).resolveDescription("REASON", ex.toString());
    }
    return new MessageEvent(MessageEventEnum.GENERIC_OK);
}
Also used : Campaign(org.cerberus.crud.entity.Campaign) HtmlEmail(org.apache.commons.mail.HtmlEmail) Email(org.cerberus.service.email.entity.Email) JSONObject(org.json.JSONObject) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Aggregations

Email (org.cerberus.service.email.entity.Email)13 CountryEnvParam (org.cerberus.crud.entity.CountryEnvParam)5 MessageEvent (org.cerberus.engine.entity.MessageEvent)5 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 IEmailGenerationService (org.cerberus.service.email.IEmailGenerationService)3 Answer (org.cerberus.util.answer.Answer)3 JSONObject (org.json.JSONObject)3 ApplicationContext (org.springframework.context.ApplicationContext)3 HtmlEmail (org.apache.commons.mail.HtmlEmail)2 Campaign (org.cerberus.crud.entity.Campaign)2 ICountryEnvParamService (org.cerberus.crud.service.ICountryEnvParamService)2 ICountryEnvParam_logService (org.cerberus.crud.service.ICountryEnvParam_logService)2 ILogEventService (org.cerberus.crud.service.ILogEventService)2 IParameterService (org.cerberus.crud.service.IParameterService)2 IEmailService (org.cerberus.service.email.IEmailService)2 JSONException (org.json.JSONException)2 PolicyFactory (org.owasp.html.PolicyFactory)2 PrintWriter (java.io.PrintWriter)1 DecimalFormat (java.text.DecimalFormat)1