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;
}
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;
}
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);
}
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();
}
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);
}
Aggregations