use of com.serotonin.m2m2.i18n.Translations in project ma-core-public by infiniteautomation.
the class PasswordResetService method sendEmail.
public void sendEmail(User user, String token) throws TemplateException, IOException, AddressException {
URI uri = null;
try {
uri = this.generateResetUrl(token);
} catch (Exception e) {
}
Translations translations = Translations.getTranslations(user.getLocaleObject());
Jws<Claims> parsed = this.parse(token);
Date expiration = parsed.getBody().getExpiration();
Map<String, Object> model = new HashMap<>();
model.put("username", user.getUsername());
model.put("resetUri", uri != null ? uri : "");
model.put("token", token);
model.put("expiration", expiration);
TranslatableMessage subject = new TranslatableMessage("ftl.passwordReset.subject", user.getUsername());
MangoEmailContent content = new MangoEmailContent("passwordReset", model, translations, subject.translate(translations), Common.UTF8);
EmailWorkItem.queueEmail(user.getEmail(), content);
}
use of com.serotonin.m2m2.i18n.Translations in project ma-core-public by infiniteautomation.
the class EventExportServlet method exportCsv.
/**
* @param response
* @param def
* @param user
* @throws IOException
*/
private void exportCsv(HttpServletResponse response, EventExportDefinition def, User user) throws IOException {
final Translations translations = Common.getTranslations();
List<EventInstance> events = EventDao.instance.search(def.getEventId(), def.getEventType(), def.getStatus(), def.getAlarmLevel(), def.getKeywords(), def.getDateFrom(), def.getDateTo(), user.getId(), translations, 0, Integer.MAX_VALUE, null);
// Stream the content.
response.setContentType("text/csv");
new EventCsvStreamer(response.getWriter(), events, translations);
}
use of com.serotonin.m2m2.i18n.Translations in project ma-core-public by infiniteautomation.
the class SystemSettingsDwr method sendTestEmail.
@DwrPermission(admin = true)
public Map<String, Object> sendTestEmail(String host, int port, String from, String name, boolean auth, String username, String password, boolean tls, int contentType) {
// Save the settings
saveEmailSettings(host, port, from, name, auth, username, password, tls, contentType);
// Get the web context information
User user = Common.getHttpUser();
Map<String, Object> result = new HashMap<>();
try {
Translations translations = getTranslations();
Map<String, Object> model = new HashMap<>();
model.put("message", new TranslatableMessage("systemSettings.testEmail"));
MangoEmailContent cnt = new MangoEmailContent("testEmail", model, translations, translations.translate("ftl.testEmail"), Common.UTF8);
EmailWorkItem.queueEmail(user.getEmail(), cnt);
result.put("message", new TranslatableMessage("common.testEmailSent", user.getEmail()));
} catch (Exception e) {
result.put("exception", e.getMessage());
}
return result;
}
use of com.serotonin.m2m2.i18n.Translations in project ma-core-public by infiniteautomation.
the class FileUploadController method parseFile.
/**
* Parse the Import Files
* @param input
* @param model
* @param translations
*/
protected void parseFile(InputStream input, Map<String, Object> model, Translations translations, HttpServletRequest request) {
// Get the filename
String filename = (String) model.get("filename");
SpreadsheetEmporter emporter;
if (filename == null)
return;
else {
if (filename.toLowerCase().endsWith(".xls"))
emporter = new SpreadsheetEmporter(FileType.XLS);
else if (filename.toLowerCase().endsWith(".xlsx"))
emporter = new SpreadsheetEmporter(FileType.XLSX);
else
return;
}
// Switch on the type
String dataType = (String) model.get("dataType");
if (dataType != null) {
if (dataType.equals("pointValue")) {
// List the sheets and create sheet emporters for each
for (Sheet sheet : emporter.listSheets(input)) emporter.doImport(input, new PointValueEmporter(sheet.getSheetName()));
} else
throw new ShouldNeverHappenException("Unsupported data.");
}
model.put("hasImportErrors", emporter.hasErrors());
// Get the messages
if (emporter.hasErrors()) {
List<String> errorMessages = new ArrayList<String>();
for (TranslatableMessage msg : emporter.getErrorMessages()) {
errorMessages.add(msg.translate(translations));
}
model.put("errorMessages", errorMessages);
}
model.put("rowsImported", emporter.getRowsAdded());
model.put("rowsDeleted", emporter.getRowsDeleted());
model.put("rowsWithErrors", emporter.getRowErrors());
}
use of com.serotonin.m2m2.i18n.Translations in project ma-core-public by infiniteautomation.
the class RealTimeDataPointValueCache method createPointHierarchy.
/**
* Create a point hierarchy for this user out of all points they can read
*
* @param translations
* @param user
* @return
*/
private static PointHierarchy createPointHierarchy(Translations translations) {
// Create a point hierarchy for the user.
PointHierarchy ph = DataPointDao.instance.getPointHierarchy(true).copyFoldersOnly();
List<DataPointVO> points = DataPointDao.instance.getDataPoints(DataPointExtendedNameComparator.instance, false);
for (DataPointVO point : points) {
ph.addDataPoint(point.getPointFolderId(), new DataPointSummary(point));
}
ph.parseEmptyFolders();
return ph;
}
Aggregations