Search in sources :

Example 21 with Translations

use of com.serotonin.m2m2.i18n.Translations 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 22 with Translations

use of com.serotonin.m2m2.i18n.Translations 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 23 with Translations

use of com.serotonin.m2m2.i18n.Translations in project ma-core-public by infiniteautomation.

the class MessageFormatDirective method execute.

@Override
public void execute(Environment env, @SuppressWarnings("rawtypes") Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
    TemplateModel key = (TemplateModel) params.get("key");
    String out;
    if (key == null) {
        // No key. Look for a message.
        BeanModel model = (BeanModel) params.get("message");
        if (model == null) {
            if (params.containsKey("message"))
                // The parameter is there, but the value is null.
                out = "";
            else
                // The parameter wasn't given
                throw new TemplateModelException("One of key or message must be provided");
        } else {
            TranslatableMessage message = (TranslatableMessage) model.getWrappedObject();
            if (message == null)
                out = "";
            else
                out = message.translate(translations);
        }
    } else {
        if (key instanceof TemplateScalarModel)
            out = translations.translate(((TemplateScalarModel) key).getAsString());
        else
            throw new TemplateModelException("key must be a string");
    }
    env.getOut().write(out);
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) BeanModel(freemarker.ext.beans.BeanModel) TemplateScalarModel(freemarker.template.TemplateScalarModel) TemplateModel(freemarker.template.TemplateModel) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 24 with Translations

use of com.serotonin.m2m2.i18n.Translations in project ma-core-public by infiniteautomation.

the class ChartExportServlet method exportCsv.

/**
 * Do the export as a CSV File
 * @param response
 * @param from
 * @param to
 * @param def
 * @param user
 * @throws IOException
 */
private void exportCsv(HttpServletRequest request, HttpServletResponse response, long from, long to, DataExportDefinition def, User user) throws IOException {
    DataPointDao dataPointDao = DataPointDao.instance;
    PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
    // Stream the content.
    response.setContentType("text/csv");
    final Translations translations = Common.getTranslations();
    final ExportCsvStreamer exportCreator = new ExportCsvStreamer(request.getServerName(), request.getLocalPort(), response.getWriter(), translations);
    final ExportDataValue edv = new ExportDataValue();
    MappedRowCallback<PointValueTime> callback = new MappedRowCallback<PointValueTime>() {

        @Override
        public void row(PointValueTime pvt, int rowIndex) {
            edv.setValue(pvt.getValue());
            edv.setTime(pvt.getTime());
            if (pvt instanceof AnnotatedPointValueTime)
                edv.setAnnotation(((AnnotatedPointValueTime) pvt).getSourceMessage());
            else
                edv.setAnnotation(null);
            exportCreator.pointData(edv);
        }
    };
    for (int pointId : def.getPointIds()) {
        DataPointVO dp = dataPointDao.getDataPoint(pointId, false);
        if (Permissions.hasDataPointReadPermission(user, dp)) {
            ExportPointInfo pointInfo = new ExportPointInfo();
            pointInfo.setXid(dp.getXid());
            pointInfo.setPointName(dp.getName());
            pointInfo.setDeviceName(dp.getDeviceName());
            pointInfo.setTextRenderer(dp.getTextRenderer());
            pointInfo.setDataPointId(pointId);
            exportCreator.startPoint(pointInfo);
            pointValueDao.getPointValuesBetween(pointId, from, to, callback);
        }
    }
    exportCreator.done();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) MappedRowCallback(com.serotonin.db.MappedRowCallback) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) ExportCsvStreamer(com.serotonin.m2m2.vo.export.ExportCsvStreamer) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) Translations(com.serotonin.m2m2.i18n.Translations)

Example 25 with Translations

use of com.serotonin.m2m2.i18n.Translations in project ma-core-public by infiniteautomation.

the class PublisherEditController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = Common.getUser(request);
    Permissions.ensureAdmin(user);
    PublisherVO<? extends PublishedPointVO> publisherVO;
    // Get the id.
    String idStr = request.getParameter("pid");
    if (idStr == null) {
        // Adding a new data source? Get the type id.
        String typeId = request.getParameter("typeId");
        if (StringUtils.isBlank(typeId))
            return new ModelAndView(new RedirectView(errorViewName));
        // A new publisher
        PublisherDefinition def = ModuleRegistry.getPublisherDefinition(typeId);
        if (def == null)
            return new ModelAndView(new RedirectView(errorViewName));
        publisherVO = def.baseCreatePublisherVO();
        publisherVO.setXid(PublisherDao.instance.generateUniqueXid());
    } else {
        // An existing configuration.
        int id = Integer.parseInt(idStr);
        publisherVO = Common.runtimeManager.getPublisher(id);
        if (publisherVO == null)
            return new ModelAndView(new RedirectView(errorViewName));
    }
    // Set the id of the data source in the user object for the DWR.
    user.setEditPublisher(publisherVO);
    // Create the model.
    Map<String, Object> model = new HashMap<>();
    model.put("publisher", publisherVO);
    if (publisherVO.getId() != Common.NEW_ID) {
        List<EventInstance> events = EventDao.instance.getPendingEventsForPublisher(publisherVO.getId(), user.getId());
        List<EventInstanceBean> beans = new ArrayList<>();
        if (events != null) {
            Translations translations = ControllerUtils.getTranslations(request);
            for (EventInstance event : events) beans.add(new EventInstanceBean(event.isActive(), event.getAlarmLevel(), Functions.getTime(event.getActiveTimestamp()), event.getMessage().translate(translations)));
        }
        model.put("publisherEvents", beans);
    }
    publisherVO.addEditContext(model);
    return new ModelAndView(getViewName(), model);
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) User(com.serotonin.m2m2.vo.User) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) PublisherDefinition(com.serotonin.m2m2.module.PublisherDefinition) EventInstanceBean(com.serotonin.m2m2.web.dwr.beans.EventInstanceBean) RedirectView(org.springframework.web.servlet.view.RedirectView) Translations(com.serotonin.m2m2.i18n.Translations)

Aggregations

Translations (com.serotonin.m2m2.i18n.Translations)17 HashMap (java.util.HashMap)14 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)8 MangoEmailContent (com.serotonin.m2m2.email.MangoEmailContent)7 User (com.serotonin.m2m2.vo.User)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)5 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)5 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)4 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 Map (java.util.Map)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 InvalidArgumentException (com.serotonin.InvalidArgumentException)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)3 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)3 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)3 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)3