Search in sources :

Example 66 with TranslatableMessage

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

the class TranslatableMessageConverter method convertOutbound.

@Override
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
    User user = Common.getHttpUser();
    Locale locale = null;
    if (user != null)
        locale = Locale.forLanguageTag(user.getLocale());
    if (locale == null)
        locale = Common.getLocale();
    TranslatableMessage message = (TranslatableMessage) data;
    String s = message.translate(Translations.getTranslations(locale));
    return super.convertOutbound(s, outctx);
}
Also used : Locale(java.util.Locale) User(com.serotonin.m2m2.vo.User)

Example 67 with TranslatableMessage

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

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

the class MangoExpiredSessionStrategy method onExpiredSessionDetected.

@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
    HttpServletRequest request = event.getRequest();
    HttpServletResponse response = event.getResponse();
    if (log.isDebugEnabled()) {
        log.debug(String.format("Expired session detected, request URI is %s", request.getRequestURI()));
    }
    if (response.isCommitted())
        return;
    if (this.browserHtmlRequestMatcher.matches(request)) {
        String loginUri = DefaultPagesDefinition.getLoginUri(request, response);
        response.sendRedirect(loginUri);
    } else {
        TranslatableMessage message = new TranslatableMessage("rest.exception.sessionExpired");
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, message.translate(Common.getTranslations()));
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 69 with TranslatableMessage

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

the class SpreadsheetEmporter method prepareSheetExport.

public void prepareSheetExport(AbstractSheetEmporter sheetEmporter) {
    if (wb == null) {
        return;
    }
    // Setup Stats For Entire Workbook
    rowsProcessed = 0;
    rowErrors = 0;
    errorMessages = new ArrayList<TranslatableMessage>();
    Sheet currentSheet = wb.createSheet(sheetEmporter.getSheetName());
    sheetEmporter.setSheet(currentSheet);
    CreationHelper createHelper = wb.getCreationHelper();
    CellStyle dateStyle = wb.createCellStyle();
    dateStyle.setDataFormat(createHelper.createDataFormat().getFormat(this.getDateFormat()));
    sheetEmporter.setDateStyle(dateStyle);
    CellStyle percentStyle = wb.createCellStyle();
    percentStyle.setDataFormat(createHelper.createDataFormat().getFormat(DeltamationCommon.decimalFormat));
    sheetEmporter.setPercentStyle(percentStyle);
    rowNum = 0;
    int cellNum = 0;
    Cell cell;
    Row row;
    // headers
    CellStyle headerStyle = wb.createCellStyle();
    Font headerFont = wb.createFont();
    headerFont.setBold(true);
    headerStyle.setFont(headerFont);
    row = currentSheet.createRow(sheetEmporter.incrementRowNum());
    int[] columnWidths = sheetEmporter.getColumnWidths();
    for (String text : sheetEmporter.getHeaders()) {
        cell = row.createCell(cellNum);
        cell.setCellValue(text);
        currentSheet.setColumnWidth(cellNum, columnWidths[cellNum]);
        cell.setCellStyle(headerStyle);
        cellNum++;
    }
}
Also used : CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) Font(org.apache.poi.ss.usermodel.Font)

Example 70 with TranslatableMessage

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

the class EventInstanceEmporter method exportRow.

/**
 * @param vo
 */
public void exportRow(EventInstanceVO vo) {
    int cellNum = 0;
    Cell cell;
    Row row;
    row = sheet.createRow(this.rowNum++);
    // Set Event Id
    cell = row.createCell(cellNum++);
    cell.setCellValue(vo.getId());
    // Alarm Level
    cell = row.createCell(cellNum++);
    cell.setCellValue(AlarmLevels.getAlarmLevelMessage(vo.getAlarmLevel()).translate(Common.getTranslations()));
    // Active Time
    cell = row.createCell(cellNum++);
    cell.setCellValue(new Date(vo.getActiveTimestamp()));
    cell.setCellStyle(dateStyle);
    // Message (Remove any HTML)
    cell = row.createCell(cellNum++);
    String messageStringHTML = vo.getMessageString();
    String messageString = StringEscapeUtils.unescapeHtml4(messageStringHTML);
    // Since we have <br/> in the code and that isn't proper HTML we need to remove it by hand
    messageString = messageString.replace("<br/>", "\n");
    cell.setCellValue(messageString);
    // Status
    cell = row.createCell(cellNum++);
    if (vo.isActive())
        cell.setCellValue(Common.translate("common.active"));
    else if (!vo.isRtnApplicable())
        cell.setCellValue("");
    else
        cell.setCellValue(vo.getRtnTimestampString() + " - " + vo.getRtnMessageString());
    // Ack Time
    // Ack User
    cell = row.createCell(cellNum++);
    Cell ackMsgCell = row.createCell(cellNum++);
    cell.setCellStyle(dateStyle);
    if (vo.isAcknowledged()) {
        cell.setCellValue(new Date(vo.getAcknowledgedTimestamp()));
        TranslatableMessage ackMessage;
        if (vo.getAcknowledgedByUserId() != 0) {
            ackMessage = new TranslatableMessage("events.export.ackedByUser", vo.getAcknowledgedByUsername());
        } else {
            ackMessage = vo.getAlternateAckSource();
        }
        if (ackMessage != null)
            ackMsgCell.setCellValue(ackMessage.translate(Common.getTranslations()));
    } else {
    // Do we need to set the cell to null explicitly
    }
}
Also used : Row(org.apache.poi.ss.usermodel.Row) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) Cell(org.apache.poi.ss.usermodel.Cell) Date(java.util.Date)

Aggregations

TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)180 User (com.serotonin.m2m2.vo.User)53 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)52 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)52 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)33 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)33 IOException (java.io.IOException)28 HashMap (java.util.HashMap)27 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)24 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)22 ArrayList (java.util.ArrayList)22 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)20 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)20 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)19 BadRequestException (com.infiniteautomation.mango.rest.v2.exception.BadRequestException)18 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)17 File (java.io.File)16 URI (java.net.URI)16 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)12 ResponseEntity (org.springframework.http.ResponseEntity)11