Search in sources :

Example 1 with MessageBuilder

use of org.springframework.binding.message.MessageBuilder in project cas by apereo.

the class AuthenticationExceptionHandler method handleAbstractTicketException.

/**
     * Maps an {@link AbstractTicketException} onto a state name equal to the simple class name of the exception with
     * highest precedence. Also sets an ERROR severity message in the message context with the error code found in
     * {@link AbstractTicketException#getCode()}. If no match is found,
     * {@value AuthenticationExceptionHandler#UNKNOWN} is returned.
     *
     * @param e              Ticket exception to handle.
     * @param messageContext the spring message context
     * @return Name of next flow state to transition to or {@value AuthenticationExceptionHandler#UNKNOWN}
     */
protected String handleAbstractTicketException(final AbstractTicketException e, final MessageContext messageContext) {
    // find the first error in the error list that matches the AbstractTicketException
    final Optional<String> match = this.errors.stream().filter(c -> c.isInstance(e)).map(Class::getSimpleName).findFirst();
    match.ifPresent(s -> messageContext.addMessage(new MessageBuilder().error().code(e.getCode()).build()));
    return match.orElse(UNKNOWN);
}
Also used : MessageBuilder(org.springframework.binding.message.MessageBuilder)

Example 2 with MessageBuilder

use of org.springframework.binding.message.MessageBuilder in project cas by apereo.

the class AbstractCasWebflowEventResolver method handleAuthenticationTransactionAndGrantTicketGrantingTicket.

/**
     * Handle authentication transaction and grant ticket granting ticket set.
     *
     * @param context the context
     * @return the set
     */
protected Set<Event> handleAuthenticationTransactionAndGrantTicketGrantingTicket(final RequestContext context) {
    try {
        final Credential credential = getCredentialFromContext(context);
        AuthenticationResultBuilder builder = WebUtils.getAuthenticationResultBuilder(context);
        LOGGER.debug("Handling authentication transaction for credential [{}]", credential);
        final Service service = WebUtils.getService(context);
        builder = this.authenticationSystemSupport.handleAuthenticationTransaction(service, builder, credential);
        LOGGER.debug("Issuing ticket-granting tickets for service [{}]", service);
        return Collections.singleton(grantTicketGrantingTicketToAuthenticationResult(context, builder, service));
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        final MessageContext messageContext = context.getMessageContext();
        messageContext.addMessage(new MessageBuilder().error().code(DEFAULT_MESSAGE_BUNDLE_PREFIX.concat(e.getClass().getSimpleName())).build());
        return Collections.singleton(new EventFactorySupport().error(this));
    }
}
Also used : Credential(org.apereo.cas.authentication.Credential) MessageBuilder(org.springframework.binding.message.MessageBuilder) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) MessageContext(org.springframework.binding.message.MessageContext) AuthenticationResultBuilder(org.apereo.cas.authentication.AuthenticationResultBuilder) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 3 with MessageBuilder

use of org.springframework.binding.message.MessageBuilder in project head by mifos.

the class QuestionnaireController method constructErrorMessage.

protected void constructErrorMessage(String code, String message, MessageContext context, Object... args) {
    MessageResolver messageResolver = new MessageBuilder().error().code(code).defaultText(message).args(args).build();
    context.addMessage(messageResolver);
}
Also used : MessageResolver(org.springframework.binding.message.MessageResolver) MessageBuilder(org.springframework.binding.message.MessageBuilder)

Example 4 with MessageBuilder

use of org.springframework.binding.message.MessageBuilder in project head by mifos.

the class UserFormBean method bindDateField.

private void bindDateField(MessageContext messages, CustomFieldDto additionalField, DateFieldBean additionalDateField) {
    try {
        DateTime date = new DateTime().withDate(Integer.valueOf(additionalDateField.getYear()), additionalDateField.getMonth().intValue(), additionalDateField.getDay().intValue());
        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
        additionalField.setFieldValue(format.format(date.toDate()));
    } catch (Throwable e) {
        messages.addMessage(new MessageBuilder().error().source("customFields").code("Valid.UserFormBean.additionaldatefield").defaultText("date not valid.").build());
    }
}
Also used : MessageBuilder(org.springframework.binding.message.MessageBuilder) SimpleDateFormat(java.text.SimpleDateFormat) DateTime(org.joda.time.DateTime)

Example 5 with MessageBuilder

use of org.springframework.binding.message.MessageBuilder in project head by mifos.

the class CashFlowValidator method constructErrorMessage.

void constructErrorMessage(String code, String message, MessageContext context, Object... args) {
    MessageResolver messageResolver = new MessageBuilder().error().code(code).defaultText(message).args(args).build();
    context.addMessage(messageResolver);
}
Also used : MessageResolver(org.springframework.binding.message.MessageResolver) MessageBuilder(org.springframework.binding.message.MessageBuilder)

Aggregations

MessageBuilder (org.springframework.binding.message.MessageBuilder)24 MessageContext (org.springframework.binding.message.MessageContext)6 MessageResolver (org.springframework.binding.message.MessageResolver)6 BigDecimal (java.math.BigDecimal)4 DateTime (org.joda.time.DateTime)3 ArrayList (java.util.ArrayList)2 ErrorEntry (org.mifos.platform.validations.ErrorEntry)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 ReportServiceLocatorException (org.opennms.reporting.core.svclayer.ReportServiceLocatorException)2 SchedulerException (org.quartz.SchedulerException)2 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)2 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)1 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)1 AuthenticationResultBuilder (org.apereo.cas.authentication.AuthenticationResultBuilder)1 Credential (org.apereo.cas.authentication.Credential)1 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)1 Service (org.apereo.cas.authentication.principal.Service)1