Example usage for org.springframework.context MessageSource getMessage

List of usage examples for org.springframework.context MessageSource getMessage

Introduction

In this page you can find the example usage for org.springframework.context MessageSource getMessage.

Prototype

String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException;

Source Link

Document

Try to resolve the message.

Usage

From source file:ro.cs.om.web.controller.root.ControllerUtils.java

/**
 * Returns a string (JSON pattern) of all departments, inclusive with fake dept, from an organization 
 * containing the name's of the departments
 *  /*from   w w  w  .j  ava  2 s .c  om*/
 * @author Adelina
 * 
 * @param organisationId
 * @param locale
 * @param errorMessages
 * @param messageSource
 * @return
 */
public String getDepartmentsWithFakeFromOrgAsJSON(HttpServletRequest request, Integer organisationId,
        Locale locale, ArrayList<String> errorMessages, MessageSource messageSource) {
    logger.debug("getDepartmentFromOrgAsJSON - START - ORGANISATION ".concat(String.valueOf(organisationId)));

    JSONArray jsonArray = new JSONArray();

    try {
        Set<Department> departments = BLOrganisation.getInstance().getDepartments(organisationId);
        JSONObject jsonObj = new JSONObject();
        for (Department department : departments) {
            if (department.getStatus() != IConstant.NOM_DEPARTMENT_FAKE) {
                jsonObj.accumulate("name", department.getName().concat(" "));
                jsonObj.accumulate("id", department.getDepartmentId());
                jsonArray.add(jsonObj);
                jsonObj.clear();
            } else {
                jsonObj.accumulate("name",
                        messageSource.getMessage(DEPARTMENT_FAKE,
                                new Object[] { ControllerUtils.getInstance().getFormattedCurrentTime() },
                                RequestContextUtils.getLocale(request)).concat(" "));
                jsonObj.accumulate("id", department.getDepartmentId());
                jsonArray.add(jsonObj);
                jsonObj.clear();
            }
        }
    } catch (BusinessException be) {
        logger.error("", be);
        errorMessages.add(messageSource.getMessage(GET_DEPARTMENTS_FROM_ORG_AS_JSON_ERROR,
                new Object[] { be.getCode(), ControllerUtils.getInstance().getFormattedCurrentTime() },
                locale));
    } catch (Exception e) {
        logger.error("", e);
        errorMessages.add(messageSource.getMessage(GET_DEPARTMENTS_FROM_ORG_AS_JSON_ERROR,
                new Object[] { null, ControllerUtils.getInstance().getFormattedCurrentTime() }, locale));
    }

    logger.debug("getDepartmentFromOrgAsJSON - END - json:".concat(jsonArray.toString()));
    return jsonArray.toString();
}

From source file:ro.cs.om.web.controller.root.ControllerUtils.java

/**
 * Returns a string (JSON pattern) of all persons from an organization that are not deleted neither disabled
 *
 * @author Adelina/*from   ww w  .java 2  s .  co  m*/
 * 
 * @param orgId
 * @param locale
 * @param errorMessages
 * @return
 */
public String getPersonsActivated(Integer organizationId, Locale locale, ArrayList<String> errorMessages,
        MessageSource messageSource) {
    logger.debug("getPersonsActivated - START - orgID:".concat(String.valueOf(organizationId)));
    JSONArray jsonArray = new JSONArray();
    try {
        // get all persons from user's organization         
        Iterator<Person> it = BLPerson.getInstance().getPersonsActivated(organizationId).iterator();
        JSONObject jsonObj = new JSONObject();
        while (it.hasNext()) {
            Person pers = (Person) it.next();

            // add the name and the id
            jsonObj.accumulate("id", pers.getPersonId());
            jsonObj.accumulate("name", pers.getFirstName().concat(" ").concat(pers.getLastName()));
            jsonArray.add(jsonObj);
            jsonObj.clear();
        }
    } catch (BusinessException be) {
        logger.error("", be);
        errorMessages.add(messageSource.getMessage(GET_PERSONS_ACTIVATES_FROM_ORG_AS_JSON_ERROR,
                new Object[] { be.getCode(), ControllerUtils.getInstance().getFormattedCurrentTime() },
                locale));
    } catch (Exception e) {
        logger.error("", e);
        errorMessages.add(messageSource.getMessage(GET_PERSONS_ACTIVATES_FROM_ORG_AS_JSON_ERROR,
                new Object[] { null, ControllerUtils.getInstance().getFormattedCurrentTime() }, locale));
    }

    logger.debug("getPersonsActivated - END - json:".concat(jsonArray.toString()));
    return jsonArray.toString();
}

From source file:xyz.codevomit.bootlog.blog.BackupController.java

@PostMapping(path = "import")
public RedirectView importContent(@RequestParam(name = "jsonContent", required = true) MultipartFile jsonFile,
        RedirectAttributes redirectAttributes, MessageSource source, Locale locale) {
    try {/* w  ww.  j  a  v  a 2  s  . c o  m*/
        String json = IOUtils.toString(jsonFile.getInputStream());
        backupService.importPostContent(json);
        redirectAttributes.addFlashAttribute("message", "Import successful!");
    } catch (Exception e) {
        log.error("Error during content import:", e);
        String errorMessage = source.getMessage("backup.error.message", null, locale) + e.getMessage();
        redirectAttributes.addFlashAttribute("message", errorMessage);
    }

    return new RedirectView(contextPath + "/backup");
}