Search in sources :

Example 1 with Translations

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);
}
Also used : Claims(io.jsonwebtoken.Claims) HashMap(java.util.HashMap) MangoEmailContent(com.serotonin.m2m2.email.MangoEmailContent) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) URI(java.net.URI) Translations(com.serotonin.m2m2.i18n.Translations) TemplateException(freemarker.template.TemplateException) AddressException(javax.mail.internet.AddressException) NotFoundException(com.serotonin.m2m2.vo.exception.NotFoundException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Date(java.util.Date)

Example 2 with Translations

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);
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) EventCsvStreamer(com.serotonin.m2m2.vo.export.EventCsvStreamer) Translations(com.serotonin.m2m2.i18n.Translations)

Example 3 with 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;
}
Also used : User(com.serotonin.m2m2.vo.User) HashMap(java.util.HashMap) MangoEmailContent(com.serotonin.m2m2.email.MangoEmailContent) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) Translations(com.serotonin.m2m2.i18n.Translations) InvalidArgumentException(com.serotonin.InvalidArgumentException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 4 with Translations

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());
}
Also used : PointValueEmporter(com.serotonin.m2m2.rt.dataImage.PointValueEmporter) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ArrayList(java.util.ArrayList) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) SpreadsheetEmporter(com.serotonin.m2m2.vo.emport.SpreadsheetEmporter) Sheet(org.apache.poi.ss.usermodel.Sheet)

Example 5 with Translations

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;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) PointHierarchy(com.serotonin.m2m2.vo.hierarchy.PointHierarchy)

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