Example usage for org.springframework.context.support DefaultMessageSourceResolvable DefaultMessageSourceResolvable

List of usage examples for org.springframework.context.support DefaultMessageSourceResolvable DefaultMessageSourceResolvable

Introduction

In this page you can find the example usage for org.springframework.context.support DefaultMessageSourceResolvable DefaultMessageSourceResolvable.

Prototype

public DefaultMessageSourceResolvable(MessageSourceResolvable resolvable) 

Source Link

Document

Copy constructor: Create a new instance from another resolvable.

Usage

From source file:org.springmodules.validation.valang.functions.ResolveFunction.java

protected Object doGetResult(Object target) throws Exception {
    Object value = getArguments()[0].getResult(target);
    Assert.isInstanceOf(String.class, value,
            "Argument of resolve method must be a string value or return a string value "
                    + getTemplate().getAtLineString() + "!");
    return new DefaultMessageSourceResolvable((String) value);
}

From source file:com.github.pjungermann.config.ConfigTest.java

@Test
public void constructor_otherConfig_copyEntriesAndErrors() {
    Config other = new Config();
    other.put("other.key", 123);
    ConfigError error = () -> new DefaultMessageSourceResolvable("my.fake.code");
    other.errors.add(error);/*  ww  w.j  a v a 2 s  .  c o m*/

    Config config = new Config(other);
    assertEquals(123, config.get("other.key"));
    assertEquals(1, config.errors.size());
    assertSame(error, config.errors.get(0));
}

From source file:com.github.pjungermann.config.ConfigTest.java

@Test
public void constructor_putAllOfOtherConfig_copyEntriesAndErrors() {
    Config other = new Config();
    other.put("other.key", 123);
    ConfigError error = () -> new DefaultMessageSourceResolvable("my.fake.code");
    other.errors.add(error);//www  . ja va 2s  . co m

    Config config = new Config();
    config.putAll(other);

    assertEquals(123, config.get("other.key"));
    assertEquals(1, config.errors.size());
    assertSame(error, config.errors.get(0));
}

From source file:jp.co.ntt.atrs.app.b0.ReservationFlightValidator.java

/**
 * {@inheritDoc}/*from ww  w  .j a  v a2  s.c o m*/
 */
@Override
public void validate(Object target, Errors errors) {

    IReservationFlightForm form = (IReservationFlightForm) target;
    List<SelectFlightForm> selectFlightFormList = form.getSelectFlightFormList();

    // ????
    if (!errors.hasFieldErrors("flightType")) {

        switch (form.getFlightType()) {
        case RT:
            // ??

            // ??
            if (CollectionUtils.isEmpty(selectFlightFormList)) {

                // ????
                errors.reject("NotNull.outwardFlight",
                        new Object[] { new DefaultMessageSourceResolvable("outwardFlight") }, "");
                errors.reject("NotNull.homewardFlight",
                        new Object[] { new DefaultMessageSourceResolvable("homewardFlight") }, "");
            } else {

                // ?2????????
                if (selectFlightFormList.size() == 2) {
                    // OK
                } else if (selectFlightFormList.size() == 1) {

                    // ????????
                    errors.reject(TicketReserveErrorCode.E_AR_B2_5001.code());
                } else {

                    // ???0-2??????????
                    // ?????
                    // ???????
                    // ?????
                    // Invalid?(????)
                    errors.rejectValue("selectFlightFormList", "Invalid");
                }
            }

            break;

        case OW:
            // ???

            // ??
            if (CollectionUtils.isEmpty(selectFlightFormList)) {
                errors.reject("NotNull.outwardFlight",
                        new Object[] { new DefaultMessageSourceResolvable("outwardFlight") }, "");
            } else {

                // ?1????????
                if (1 == selectFlightFormList.size()) {
                    // OK
                } else {

                    // ????0-1??????????
                    // ?????
                    // ???????
                    // ?????
                    // Invalid?(????)
                    errors.rejectValue("selectFlightFormList", "Invalid");
                }
            }

            break;

        default:
            // ???

            break;
        }
    }

}

From source file:org.obiba.onyx.core.service.impl.DefaultUserPasswordServiceImplTest.java

@Test
public void testValidatePassword() {
    expect(iPasswordValidationStrategyMock.validatePassword(user, "GoodPassword"))
            .andReturn(new ArrayList<MessageSourceResolvable>());
    List<MessageSourceResolvable> errorList = new ArrayList<MessageSourceResolvable>(1);
    errorList.add(new DefaultMessageSourceResolvable("BadPasswordCode"));
    expect(iPasswordValidationStrategyMock.validatePassword(user, "BadPassword")).andReturn(errorList);
    replay(iPasswordValidationStrategyMock);
    userPasswordService.validatePassword(user, "GoodPassword");
    userPasswordService.validatePassword(user, "BadPassword");
    verify(iPasswordValidationStrategyMock);
}

From source file:org.obiba.onyx.core.service.impl.DefaultUserPasswordServiceImplTest.java

@Test
public void testAssignPasswordValidationFails() {
    List<MessageSourceResolvable> errorList = new ArrayList<MessageSourceResolvable>(1);
    errorList.add(new DefaultMessageSourceResolvable("BadPasswordCode"));
    expect(iPasswordValidationStrategyMock.validatePassword(user, "BadPassword")).andReturn(errorList);
    replay(iPasswordValidationStrategyMock);
    userPasswordService.assignPassword(user, "BadPassword");
    verify(iPasswordValidationStrategyMock);
}

From source file:org.jasig.portlet.weather.dao.yahoo.YahooWeatherDaoImpl.java

public Collection<Location> find(String location) {
    if ((key == null) || (key.length() == 0)) {
        MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(
                new String[] { ERR_API_MISSING_KEY, ERR_GENERAL_KEY });
        throw new InvalidConfigurationException(messageSource.getMessage(resolvable, Locale.getDefault()));
    }//from  ww  w  .j a v  a 2 s  . co  m

    final String url = FIND_URL.replace("@KEY@", key).replace("@QUERY@",
            QuietUrlCodec.encode(location, Constants.URL_ENCODING));

    HttpMethod getMethod = new GetMethod(url);
    InputStream inputStream = null;
    try {
        // Execute the method.
        int statusCode = httpClient.executeMethod(getMethod);
        if (statusCode != HttpStatus.SC_OK) {
            final String statusText = getMethod.getStatusText();
            throw new DataRetrievalFailureException(
                    "get of '" + url + "' failed with status '" + statusCode + "' due to '" + statusText + "'");
        }

        // Read the response body
        inputStream = getMethod.getResponseBodyAsStream();

        List<Location> locations = locationParsingService.parseLocations(inputStream);

        return locations;

    } catch (HttpException e) {
        throw new RuntimeException(
                "http protocol exception while getting data from weather service from: " + url, e);
    } catch (IOException e) {
        throw new RuntimeException("IO exception while getting data from weather service from: " + url, e);
    } finally {
        //try to close the inputstream
        IOUtils.closeQuietly(inputStream);
        //release the connection
        getMethod.releaseConnection();
    }
}

From source file:org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.java

private JsonSchemaProperty getSchemaProperty(BeanPropertyDefinition definition, TypeInformation<?> type,
        ResourceDescription description) {

    String name = definition.getName();
    String title = resolveMessageWithDefault(new ResolvableProperty(definition));
    String resolvedDescription = resolveMessage(description);
    boolean required = definition.isRequired();
    Class<?> rawType = type.getType();

    if (!rawType.isEnum()) {
        return new JsonSchemaProperty(name, title, resolvedDescription, required).with(type);
    }/*from  w w  w  .  ja v a2  s  . co m*/

    String message = resolveMessage(new DefaultMessageSourceResolvable(description.getMessage()));

    return new EnumProperty(name, title, rawType,
            description.getDefaultMessage().equals(resolvedDescription) ? message : resolvedDescription,
            required);
}

From source file:alfio.controller.ReservationController.java

@RequestMapping(value = "/event/{eventName}/reservation/{reservationId}", method = RequestMethod.POST)
public String handleReservation(@PathVariable("eventName") String eventName,
        @PathVariable("reservationId") String reservationId, PaymentForm paymentForm,
        BindingResult bindingResult, Model model, HttpServletRequest request, Locale locale,
        RedirectAttributes redirectAttributes) {

    Optional<Event> eventOptional = eventRepository.findOptionalByShortName(eventName);
    if (!eventOptional.isPresent()) {
        return "redirect:/";
    }/* w w  w . java2 s . c  o  m*/
    Event event = eventOptional.get();
    Optional<TicketReservation> ticketReservation = ticketReservationManager.findById(reservationId);
    if (!ticketReservation.isPresent()) {
        return redirectReservation(ticketReservation, eventName, reservationId);
    }
    if (paymentForm.shouldCancelReservation()) {
        ticketReservationManager.cancelPendingReservation(reservationId, false);
        SessionUtil.removeSpecialPriceData(request);
        return "redirect:/event/" + eventName + "/";
    }
    if (!ticketReservation.get().getValidity().after(new Date())) {
        bindingResult.reject(ErrorsCode.STEP_2_ORDER_EXPIRED);
    }

    final TotalPrice reservationCost = ticketReservationManager.totalReservationCostWithVAT(reservationId);
    if (isCaptchaInvalid(reservationCost.getPriceWithVAT(), paymentForm.getPaymentMethod(), request, event)) {
        log.debug("captcha validation failed.");
        bindingResult.reject(ErrorsCode.STEP_2_CAPTCHA_VALIDATION_FAILED);
    }

    if (paymentForm.getPaymentMethod() != PaymentProxy.PAYPAL || !paymentForm.hasPaypalTokens()) {
        if (!paymentForm.isPostponeAssignment()
                && !ticketRepository.checkTicketUUIDs(reservationId, paymentForm.getTickets().keySet())) {
            bindingResult.reject(ErrorsCode.STEP_2_MISSING_ATTENDEE_DATA);
        }
        paymentForm.validate(bindingResult, reservationCost, event,
                ticketFieldRepository.findAdditionalFieldsForEvent(event.getId()));
        if (bindingResult.hasErrors()) {
            SessionUtil.addToFlash(bindingResult, redirectAttributes);
            return redirectReservation(ticketReservation, eventName, reservationId);
        }
    }

    CustomerName customerName = new CustomerName(paymentForm.getFullName(), paymentForm.getFirstName(),
            paymentForm.getLastName(), event);

    //handle paypal redirect!
    if (paymentForm.getPaymentMethod() == PaymentProxy.PAYPAL && !paymentForm.hasPaypalTokens()) {
        OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, event,
                locale);
        try {
            String checkoutUrl = paymentManager.createPaypalCheckoutRequest(event, reservationId, orderSummary,
                    customerName, paymentForm.getEmail(), paymentForm.getBillingAddress(), locale,
                    paymentForm.isPostponeAssignment());
            assignTickets(eventName, reservationId, paymentForm, bindingResult, request, true);
            return "redirect:" + checkoutUrl;
        } catch (Exception e) {
            bindingResult.reject(ErrorsCode.STEP_2_PAYMENT_REQUEST_CREATION);
            SessionUtil.addToFlash(bindingResult, redirectAttributes);
            return redirectReservation(ticketReservation, eventName, reservationId);
        }
    }

    //handle mollie redirect
    if (paymentForm.getPaymentMethod() == PaymentProxy.MOLLIE) {
        OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, event,
                locale);
        try {
            String checkoutUrl = mollieManager.createCheckoutRequest(event, reservationId, orderSummary,
                    customerName, paymentForm.getEmail(), paymentForm.getBillingAddress(), locale,
                    paymentForm.isInvoiceRequested(), paymentForm.getVatCountryCode(), paymentForm.getVatNr(),
                    ticketReservation.get().getVatStatus());
            assignTickets(eventName, reservationId, paymentForm, bindingResult, request, true);
            return "redirect:" + checkoutUrl;
        } catch (Exception e) {
            bindingResult.reject(ErrorsCode.STEP_2_PAYMENT_REQUEST_CREATION);
            SessionUtil.addToFlash(bindingResult, redirectAttributes);
            return redirectReservation(ticketReservation, eventName, reservationId);
        }
    }
    //

    final PaymentResult status = ticketReservationManager.confirm(paymentForm.getToken(),
            paymentForm.getPaypalPayerID(), event, reservationId, paymentForm.getEmail(), customerName, locale,
            paymentForm.getBillingAddress(), reservationCost,
            SessionUtil.retrieveSpecialPriceSessionId(request),
            Optional.ofNullable(paymentForm.getPaymentMethod()), paymentForm.isInvoiceRequested(),
            paymentForm.getVatCountryCode(), paymentForm.getVatNr(), ticketReservation.get().getVatStatus());

    if (!status.isSuccessful()) {
        String errorMessageCode = status.getErrorCode().get();
        MessageSourceResolvable message = new DefaultMessageSourceResolvable(
                new String[] { errorMessageCode, StripeManager.STRIPE_UNEXPECTED });
        bindingResult.reject(ErrorsCode.STEP_2_PAYMENT_PROCESSING_ERROR,
                new Object[] { messageSource.getMessage(message, locale) }, null);
        SessionUtil.addToFlash(bindingResult, redirectAttributes);
        return redirectReservation(ticketReservation, eventName, reservationId);
    }

    //
    TicketReservation reservation = ticketReservationManager.findById(reservationId)
            .orElseThrow(IllegalStateException::new);
    sendReservationCompleteEmail(request, event, reservation);
    sendReservationCompleteEmailToOrganizer(request, event, reservation);
    //

    if (paymentForm.getPaymentMethod() != PaymentProxy.PAYPAL) {
        assignTickets(eventName, reservationId, paymentForm, bindingResult, request,
                paymentForm.getPaymentMethod() == PaymentProxy.OFFLINE);
    }

    return "redirect:/event/" + eventName + "/reservation/" + reservationId + "/success";
}

From source file:org.webcurator.ui.target.controller.QaTiSummaryController.java

/**
 * Retrurn the Object array containing the specified label.
 * @param aLabel the label to add to the array
 * @return the object array//from w w  w . jav a  2  s.  co m
 */
protected Object[] getObjectArrayForLabel(String aLabel) {
    return new Object[] {
            new DefaultMessageSourceResolvable(new String[] { Constants.GBL_CMD_DATA + "." + aLabel }) };
}