Search in sources :

Example 11 with RecipientListEntryBean

use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean in project ma-modules-public by infiniteautomation.

the class ReportsDwr method runReport.

@DwrPermission(custom = ReportPermissionDefinition.PERMISSION)
public ProcessResult runReport(String xid, String name, List<ReportPointVO> points, String template, int includeEvents, boolean includeUserComments, int dateRangeType, int relativeDateType, int previousPeriodCount, int previousPeriodType, int pastPeriodCount, int pastPeriodType, boolean fromNone, int fromYear, int fromMonth, int fromDay, int fromHour, int fromMinute, boolean toNone, int toYear, int toMonth, int toDay, int toHour, int toMinute, boolean email, boolean includeData, boolean zipData, List<RecipientListEntryBean> recipients) {
    ProcessResult response = new ProcessResult();
    // Basic validation
    // TODO Replace with vo.validate()
    validateData(response, name, points, dateRangeType, relativeDateType, previousPeriodCount, pastPeriodCount);
    if (!response.getHasMessages()) {
        ReportVO report = new ReportVO();
        report.setXid(xid);
        report.setName(name);
        report.setUserId(Common.getUser().getId());
        report.setPoints(points);
        report.setTemplate(template);
        report.setIncludeEvents(includeEvents);
        report.setIncludeUserComments(includeUserComments);
        report.setDateRangeType(dateRangeType);
        report.setRelativeDateType(relativeDateType);
        report.setPreviousPeriodCount(previousPeriodCount);
        report.setPreviousPeriodType(previousPeriodType);
        report.setPastPeriodCount(pastPeriodCount);
        report.setPastPeriodType(pastPeriodType);
        report.setFromNone(fromNone);
        report.setFromYear(fromYear);
        report.setFromMonth(fromMonth);
        report.setFromDay(fromDay);
        report.setFromHour(fromHour);
        report.setFromMinute(fromMinute);
        report.setToNone(toNone);
        report.setToYear(toYear);
        report.setToMonth(toMonth);
        report.setToDay(toDay);
        report.setToHour(toHour);
        report.setToMinute(toMinute);
        // Never allow schedule when running from UI
        report.setSchedule(false);
        report.setEmail(email);
        report.setIncludeData(includeData);
        report.setZipData(zipData);
        report.setRecipients(recipients);
        String host = "";
        WebContext webContext = WebContextFactory.get();
        int port;
        if (webContext != null) {
            HttpServletRequest req = webContext.getHttpServletRequest();
            host = req.getServerName();
            port = req.getLocalPort();
        } else {
            port = Common.envProps.getInt("web.port", 8080);
        }
        ReportWorkItem.queueReport(host, port, report);
    }
    return response;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebContext(org.directwebremoting.WebContext) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 12 with RecipientListEntryBean

use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean in project ma-core-public by infiniteautomation.

the class EventHandlersDwr method saveEmailEventHandler.

@DwrPermission(user = true)
public ProcessResult saveEmailEventHandler(String eventType, String eventSubtype, int eventTypeRef1, int eventTypeRef2, int handlerId, String xid, String alias, boolean disabled, List<RecipientListEntryBean> activeRecipients, String customTemplate, boolean sendEscalation, boolean repeatEscalations, int escalationDelayType, int escalationDelay, List<RecipientListEntryBean> escalationRecipients, boolean sendInactive, boolean inactiveOverride, List<RecipientListEntryBean> inactiveRecipients, boolean includeSystemInfo, int includePointValueCount, boolean includeLogfile, List<IntStringPair> additionalContext, ScriptPermissions permissions, String script) {
    EmailEventHandlerVO handler = new EmailEventHandlerVO();
    handler.setDefinition(ModuleRegistry.getEventHandlerDefinition(EmailEventHandlerDefinition.TYPE_NAME));
    handler.setActiveRecipients(activeRecipients);
    handler.setCustomTemplate(customTemplate);
    handler.setSendEscalation(sendEscalation);
    handler.setRepeatEscalations(repeatEscalations);
    handler.setEscalationDelayType(escalationDelayType);
    handler.setEscalationDelay(escalationDelay);
    handler.setEscalationRecipients(escalationRecipients);
    handler.setSendInactive(sendInactive);
    handler.setInactiveOverride(inactiveOverride);
    handler.setInactiveRecipients(inactiveRecipients);
    handler.setIncludeSystemInfo(includeSystemInfo);
    handler.setIncludePointValueCount(includePointValueCount);
    handler.setIncludeLogfile(includeLogfile);
    handler.setAdditionalContext(additionalContext);
    handler.setScriptPermissions(permissions);
    handler.setScript(script);
    return save(eventType, eventSubtype, eventTypeRef1, eventTypeRef2, handler, handlerId, xid, alias, disabled);
}
Also used : EmailEventHandlerVO(com.serotonin.m2m2.vo.event.EmailEventHandlerVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 13 with RecipientListEntryBean

use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean in project ma-core-public by infiniteautomation.

the class MailingListsDwr method sendTestEmail.

@DwrPermission(admin = true)
public ProcessResult sendTestEmail(int id, String name, List<RecipientListEntryBean> entryBeans) {
    ProcessResult response = new ProcessResult();
    MailingList ml = createMailingList(id, null, name, AlarmLevels.IGNORE, entryBeans);
    MailingListDao.instance.populateEntrySubclasses(ml.getEntries());
    Set<String> addresses = new HashSet<String>();
    ml.appendAddresses(addresses, null);
    String[] toAddrs = addresses.toArray(new String[0]);
    try {
        Translations translations = Common.getTranslations();
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("message", new TranslatableMessage("ftl.userTestEmail", ml.getName()));
        MangoEmailContent cnt = new MangoEmailContent("testEmail", model, translations, translations.translate("ftl.testEmail"), Common.UTF8);
        EmailWorkItem.queueEmail(toAddrs, cnt);
    } catch (Exception e) {
        response.addGenericMessage("mailingLists.testerror", e.getMessage());
        log.warn("", e);
    }
    return response;
}
Also used : HashMap(java.util.HashMap) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) MangoEmailContent(com.serotonin.m2m2.email.MangoEmailContent) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) Translations(com.serotonin.m2m2.i18n.Translations) HashSet(java.util.HashSet) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 14 with RecipientListEntryBean

use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean in project ma-core-public by infiniteautomation.

the class MiscDwr method sendTestEmail.

@DwrPermission(user = true)
public ProcessResult sendTestEmail(List<RecipientListEntryBean> recipientList, String prefix, String message) {
    ProcessResult response = new ProcessResult();
    String[] toAddrs = MailingListDao.instance.getRecipientAddresses(recipientList, null).toArray(new String[0]);
    if (toAddrs.length == 0)
        response.addGenericMessage("js.email.noRecipForEmail");
    else {
        try {
            Translations translations = Common.getTranslations();
            Map<String, Object> model = new HashMap<String, Object>();
            model.put("user", Common.getHttpUser());
            model.put("message", new TranslatableMessage("common.default", message));
            MangoEmailContent cnt = new MangoEmailContent("testEmail", model, translations, translations.translate("ftl.testEmail"), Common.UTF8);
            EmailWorkItem.queueEmail(toAddrs, cnt);
        } catch (Exception e) {
            response.addGenericMessage("common.default", e.getMessage());
        }
    }
    response.addData("prefix", prefix);
    return response;
}
Also used : HashMap(java.util.HashMap) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) MangoEmailContent(com.serotonin.m2m2.email.MangoEmailContent) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) Translations(com.serotonin.m2m2.i18n.Translations) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 15 with RecipientListEntryBean

use of com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean in project ma-core-public by infiniteautomation.

the class EmailEventHandlerVO method readObject.

@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    int ver = in.readInt();
    if (ver == 1) {
        activeRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(activeRecipients);
        sendEscalation = in.readBoolean();
        repeatEscalations = false;
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        escalationRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(escalationRecipients);
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        inactiveRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(inactiveRecipients);
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = null;
        additionalContext = new ArrayList<IntStringPair>();
        scriptPermissions = new ScriptPermissions();
        script = null;
    } else if (ver == 2) {
        activeRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(activeRecipients);
        sendEscalation = in.readBoolean();
        repeatEscalations = false;
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        escalationRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(escalationRecipients);
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        inactiveRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(inactiveRecipients);
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = new ArrayList<IntStringPair>();
        scriptPermissions = new ScriptPermissions();
        script = null;
    } else if (ver == 3) {
        activeRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(activeRecipients);
        sendEscalation = in.readBoolean();
        repeatEscalations = false;
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        escalationRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(escalationRecipients);
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        inactiveRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(inactiveRecipients);
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        scriptPermissions = new ScriptPermissions();
        script = null;
    } else if (ver == 4) {
        activeRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(activeRecipients);
        sendEscalation = in.readBoolean();
        repeatEscalations = false;
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        escalationRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(escalationRecipients);
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        inactiveRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(inactiveRecipients);
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        scriptPermissions = (ScriptPermissions) in.readObject();
        script = SerializationHelper.readSafeUTF(in);
    } else if (ver == 5) {
        activeRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(activeRecipients);
        sendEscalation = in.readBoolean();
        repeatEscalations = in.readBoolean();
        escalationDelayType = in.readInt();
        escalationDelay = in.readInt();
        escalationRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(escalationRecipients);
        sendInactive = in.readBoolean();
        inactiveOverride = in.readBoolean();
        inactiveRecipients = (List<RecipientListEntryBean>) in.readObject();
        RecipientListEntryBean.cleanRecipientList(inactiveRecipients);
        includeSystemInfo = in.readBoolean();
        includePointValueCount = in.readInt();
        includeLogfile = in.readBoolean();
        customTemplate = SerializationHelper.readSafeUTF(in);
        additionalContext = (List<IntStringPair>) in.readObject();
        scriptPermissions = (ScriptPermissions) in.readObject();
        script = SerializationHelper.readSafeUTF(in);
    }
}
Also used : IntStringPair(com.serotonin.db.pair.IntStringPair) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RecipientListEntryBean(com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean) ScriptPermissions(com.serotonin.m2m2.rt.script.ScriptPermissions)

Aggregations

RecipientListEntryBean (com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)8 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)6 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)5 User (com.serotonin.m2m2.vo.User)5 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)5 ArrayList (java.util.ArrayList)5 JsonArray (com.serotonin.json.type.JsonArray)3 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)3 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)3 EmailRecipient (com.serotonin.m2m2.vo.mailingList.EmailRecipient)3 List (java.util.List)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 IntStringPair (com.serotonin.db.pair.IntStringPair)2 JsonBoolean (com.serotonin.json.type.JsonBoolean)2 JsonValue (com.serotonin.json.type.JsonValue)2 TypeDefinition (com.serotonin.json.util.TypeDefinition)2 MailingListDao (com.serotonin.m2m2.db.dao.MailingListDao)2 MangoEmailContent (com.serotonin.m2m2.email.MangoEmailContent)2 Translations (com.serotonin.m2m2.i18n.Translations)2