Search in sources :

Example 6 with MessageBuilder

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

the class LoanAccountController method retrieveLoanProducts.

public LoanCreationProductDetailsDto retrieveLoanProducts(int customerId, org.springframework.binding.message.MessageContext messageContext) {
    LoanCreationProductDetailsDto loanProductDetails = this.loanAccountServiceFacade.retrieveGetProductDetailsForLoanAccountCreation(customerId);
    if (loanProductDetails.getErrors().hasErrors()) {
        List<ErrorEntry> errorList = loanProductDetails.getErrors().getErrorEntries();
        for (int i = 0; i < errorList.size(); i++) {
            MessageBuilder builder = new MessageBuilder().error().source(errorList.get(i).getFieldName()).codes(Arrays.asList(errorList.get(i).getErrorCode()).toArray(new String[1])).defaultText(errorList.get(i).getDefaultMessage());
            messageContext.addMessage(builder.build());
        }
    }
    return loanProductDetails;
}
Also used : MessageBuilder(org.springframework.binding.message.MessageBuilder) LoanCreationProductDetailsDto(org.mifos.dto.screen.LoanCreationProductDetailsDto) ErrorEntry(org.mifos.platform.validations.ErrorEntry)

Example 7 with MessageBuilder

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

the class LoanScheduleFormBean method addErrorMessageToContext.

private void addErrorMessageToContext(MessageContext messageContext, ErrorEntry fieldError) {
    String[] errorCodes = new String[1];
    errorCodes[0] = fieldError.getErrorCode();
    List<Object> args = new ArrayList<Object>();
    if (fieldError.hasErrorArgs()) {
        args = new ArrayList<Object>(fieldError.getArgs());
    }
    MessageBuilder builder = new MessageBuilder().error().source(fieldError.getFieldName()).codes(errorCodes).defaultText(fieldError.getDefaultMessage()).args(args.toArray());
    messageContext.addMessage(builder.build());
}
Also used : MessageBuilder(org.springframework.binding.message.MessageBuilder) ArrayList(java.util.ArrayList)

Example 8 with MessageBuilder

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

the class ClearOverpaymentController method applyOverpaymentClear.

// called by spring webflow
public String applyOverpaymentClear(final String overpaymentId, ClearOverpaymentFormBean clearOverpaymentFormBean, MessageContext messageContext) {
    String returnCode = "";
    try {
        BigDecimal overpaymentAmount = null;
        if (clearOverpaymentFormBean.getActualOverpaymentAmount() != null) {
            overpaymentAmount = BigDecimal.valueOf(clearOverpaymentFormBean.getActualOverpaymentAmount().doubleValue());
        }
        this.loanAccountServiceFacade.applyOverpaymentClear(overpaymentId, overpaymentAmount);
        returnCode = "success";
    } catch (BusinessRuleException e) {
        MessageBuilder builder = new MessageBuilder().error().source("overpaymentAmount").codes(Arrays.asList(e.getMessageKey()).toArray(new String[1])).defaultText(e.getMessage()).args(e.getMessageValues());
        messageContext.addMessage(builder.build());
        returnCode = "error";
    }
    return returnCode;
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) MessageBuilder(org.springframework.binding.message.MessageBuilder) BigDecimal(java.math.BigDecimal)

Example 9 with MessageBuilder

use of org.springframework.binding.message.MessageBuilder in project opennms by OpenNMS.

the class ReportParametersValidator method validateReportParameters.

/**
     * <p>validateReportParameters</p>
     *
     * @param reportCriteria a {@link org.opennms.api.reporting.parameter.ReportParameters} object.
     * @param context a {@link org.springframework.binding.validation.ValidationContext} object.
     */
public void validateReportParameters(ReportParameters reportCriteria, ValidationContext context) {
    MessageContext messages = context.getMessageContext();
    List<ReportDateParm> dateParms = reportCriteria.getDateParms();
    for (Iterator<ReportDateParm> dateParmIter = dateParms.iterator(); dateParmIter.hasNext(); ) {
        ReportDateParm dateParm = dateParmIter.next();
        if (dateParm.getDate() == null) {
            messages.addMessage(new MessageBuilder().error().source("date parms").defaultText("cannot have null date field" + dateParm.getDisplayName()).build());
        }
    }
    List<ReportStringParm> stringParms = reportCriteria.getStringParms();
    for (Iterator<ReportStringParm> stringParmIter = stringParms.iterator(); stringParmIter.hasNext(); ) {
        ReportStringParm stringParm = stringParmIter.next();
        if (stringParm.getValue() == "") {
            messages.addMessage(new MessageBuilder().error().source("string parms").defaultText("cannot have empty string field" + stringParm.getDisplayName()).build());
        }
    }
    List<ReportIntParm> intParms = reportCriteria.getIntParms();
    for (Iterator<ReportIntParm> intParmIter = intParms.iterator(); intParmIter.hasNext(); ) {
        ReportIntParm intParm = intParmIter.next();
        // TODO add a more sensible check here - I think we probably can have zero int parm
        if (intParm.getValue() == 0) {
            messages.addMessage(new MessageBuilder().error().source("int parms").defaultText("cannot have zero integer field" + intParm.getDisplayName()).build());
        }
    }
    List<ReportFloatParm> floatParms = reportCriteria.getFloatParms();
    for (Iterator<ReportFloatParm> floatParmIter = floatParms.iterator(); floatParmIter.hasNext(); ) {
        ReportFloatParm floatParm = floatParmIter.next();
        if (floatParm.getValue() == null) {
            messages.addMessage(new MessageBuilder().error().source("float parms").defaultText("cannot have null float field" + floatParm.getDisplayName()).build());
        }
    }
    List<ReportDoubleParm> doubleParms = reportCriteria.getDoubleParms();
    for (Iterator<ReportDoubleParm> doubleParmIter = doubleParms.iterator(); doubleParmIter.hasNext(); ) {
        ReportDoubleParm doubleParm = doubleParmIter.next();
        if (doubleParm.getValue() == null) {
            messages.addMessage(new MessageBuilder().error().source("double parms").defaultText("cannot have null double field" + doubleParm.getDisplayName()).build());
        }
    }
}
Also used : ReportDateParm(org.opennms.api.reporting.parameter.ReportDateParm) ReportDoubleParm(org.opennms.api.reporting.parameter.ReportDoubleParm) ReportFloatParm(org.opennms.api.reporting.parameter.ReportFloatParm) MessageBuilder(org.springframework.binding.message.MessageBuilder) ReportStringParm(org.opennms.api.reporting.parameter.ReportStringParm) MessageContext(org.springframework.binding.message.MessageContext) ReportIntParm(org.opennms.api.reporting.parameter.ReportIntParm)

Example 10 with MessageBuilder

use of org.springframework.binding.message.MessageBuilder in project opennms by OpenNMS.

the class DefaultSchedulerService method addCronTrigger.

/*
     * (non-Javadoc)
     * @see
     * org.opennms.web.svclayer.support.SchedulerService#addCronTrigger(org
     * .opennms.web.report.database.model.DatabaseReportCriteria,
     * java.lang.String, java.lang.String, java.lang.String,
     * org.springframework.webflow.execution.RequestContext)
     */
/** {@inheritDoc} */
@Override
public String addCronTrigger(String id, ReportParameters criteria, DeliveryOptions deliveryOptions, String cronExpression, RequestContext context) {
    CronTriggerImpl cronTrigger = null;
    try {
        if (m_reportWrapperService.validate(criteria, id) == false) {
            LOG.error(PARAMETER_ERROR);
            context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(PARAMETER_ERROR).build());
            return ERROR;
        } else {
            try {
                cronTrigger = new CronTriggerImpl();
                cronTrigger.setGroup(m_triggerGroup);
                cronTrigger.setName(deliveryOptions.getInstanceId());
                cronTrigger.setJobName(m_jobDetail.getKey().getName());
                cronTrigger.setCronExpression(cronExpression);
            // cronTrigger = new CronTrigger(triggerName, m_triggerGroup,
            // cronExpression);
            } catch (ParseException e) {
                LOG.error(TRIGGER_PARSE_ERROR, e);
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(TRIGGER_PARSE_ERROR).build());
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(e.getMessage()).build());
                return ERROR;
            }
            cronTrigger.setJobName(m_jobDetail.getKey().getName());
            cronTrigger.getJobDataMap().put("criteria", (ReportParameters) criteria);
            cronTrigger.getJobDataMap().put("reportId", id);
            cronTrigger.getJobDataMap().put("mode", ReportMode.SCHEDULED);
            cronTrigger.getJobDataMap().put("deliveryOptions", (DeliveryOptions) deliveryOptions);
            try {
                m_scheduler.scheduleJob(cronTrigger);
            } catch (SchedulerException e) {
                LOG.error(SCHEDULER_ERROR, e);
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(SCHEDULER_ERROR).build());
                return ERROR;
            }
            return SUCCESS;
        }
    } catch (ReportServiceLocatorException e) {
        LOG.error(REPORTID_ERROR);
        context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(REPORTID_ERROR).build());
        return ERROR;
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) MessageBuilder(org.springframework.binding.message.MessageBuilder) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) ParseException(java.text.ParseException) ReportServiceLocatorException(org.opennms.reporting.core.svclayer.ReportServiceLocatorException)

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