Search in sources :

Example 21 with MessageBuilder

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

the class MandatorySavings method validateMandatoryDepositAmountDigits.

private void validateMandatoryDepositAmountDigits(ValidationContext context) {
    if (mandatoryDepositAmount == null) {
        return;
    }
    AccountingConfigurationDto accountingConfiguration = configurationServiceFacade.getAccountingConfiguration();
    BigDecimal decimalAmount;
    try {
        decimalAmount = new BigDecimal(mandatoryDepositAmount);
    } catch (NumberFormatException e) {
        return;
    }
    if ((decimalAmount.precision() - decimalAmount.scale()) > accountingConfiguration.getDigitsBeforeDecimal()) {
        context.getMessageContext().addMessage(new MessageBuilder().error().source("mandatoryDepositAmount").code("DigitsBefore.CreateSavingsAccountFormBean.mandatoryDepositAmount").arg(accountingConfiguration.getDigitsBeforeDecimal()).build());
    }
    if (decimalAmount.scale() > accountingConfiguration.getDigitsAfterDecimal()) {
        context.getMessageContext().addMessage(new MessageBuilder().error().source("mandatoryDepositAmount").code("DigitsAfter.CreateSavingsAccountFormBean.mandatoryDepositAmount").arg(accountingConfiguration.getDigitsAfterDecimal()).build());
    }
}
Also used : MessageBuilder(org.springframework.binding.message.MessageBuilder) AccountingConfigurationDto(org.mifos.config.servicefacade.dto.AccountingConfigurationDto) BigDecimal(java.math.BigDecimal)

Example 22 with MessageBuilder

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

the class DefaultSchedulerService method execute.

/*
     * (non-Javadoc)
     * @see
     * org.opennms.web.svclayer.support.SchedulerService#execute(org.opennms
     * .web.report.database.model.DatabaseReportCriteria, java.lang.String,
     * org.springframework.webflow.execution.RequestContext)
     */
/** {@inheritDoc} */
@Override
public String execute(String id, ReportParameters criteria, DeliveryOptions deliveryOptions, RequestContext context) {
    try {
        if (m_reportWrapperService.validate(criteria, id) == false) {
            context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(PARAMETER_ERROR).build());
            return ERROR;
        } else {
            SimpleTriggerImpl trigger = new SimpleTriggerImpl(deliveryOptions.getInstanceId(), m_triggerGroup, new Date(), null, 0, 0L);
            trigger.setJobName(m_jobDetail.getKey().getName());
            trigger.getJobDataMap().put("criteria", (ReportParameters) criteria);
            trigger.getJobDataMap().put("reportId", id);
            trigger.getJobDataMap().put("mode", ReportMode.IMMEDIATE);
            trigger.getJobDataMap().put("deliveryOptions", (DeliveryOptions) deliveryOptions);
            try {
                m_scheduler.scheduleJob(trigger);
            } catch (SchedulerException e) {
                LOG.warn(SCHEDULER_ERROR, e);
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(SCHEDULER_ERROR).build());
                return ERROR;
            }
            return SUCCESS;
        }
    } catch (ReportServiceLocatorException e) {
        LOG.error(REPORTID_ERROR, e);
        context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(REPORTID_ERROR).build());
        return ERROR;
    }
}
Also used : SimpleTriggerImpl(org.quartz.impl.triggers.SimpleTriggerImpl) SchedulerException(org.quartz.SchedulerException) MessageBuilder(org.springframework.binding.message.MessageBuilder) ReportServiceLocatorException(org.opennms.reporting.core.svclayer.ReportServiceLocatorException) Date(java.util.Date)

Example 23 with MessageBuilder

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

the class DeliveryOptionsValidator method validateDeliveryOptions.

/**
     * <p>validateDeliveryOptions</p>
     *
     * @param deliveryOptions a {@link org.opennms.reporting.core.DeliveryOptions} object.
     * @param context a {@link org.springframework.binding.validation.ValidationContext} object.
     */
public void validateDeliveryOptions(DeliveryOptions deliveryOptions, ValidationContext context) {
    MessageContext messages = context.getMessageContext();
    if (!((deliveryOptions.getSendMail() || deliveryOptions.getPersist()))) {
        messages.addMessage(new MessageBuilder().error().source("sendMail").defaultText("one of send mail or persist should be selected").build());
        messages.addMessage(new MessageBuilder().error().source("persist").defaultText("one of send mail or persist should be selected").build());
    } else {
        if (deliveryOptions.getSendMail() && (deliveryOptions.getMailTo() == "")) {
            messages.addMessage(new MessageBuilder().error().source("mailTo").defaultText("cannot have empty mail recipient").build());
        }
    }
    if (deliveryOptions.getInstanceId().length() == 0) {
        messages.addMessage(new MessageBuilder().error().source("instanceId").defaultText("cannot have an empty Id for the report instance").build());
    } else if (m_reportSchedulerService.exists(deliveryOptions.getInstanceId())) {
        messages.addMessage(new MessageBuilder().error().source("instanceId").defaultText("report instanceId is already in use").build());
    }
}
Also used : MessageBuilder(org.springframework.binding.message.MessageBuilder) MessageContext(org.springframework.binding.message.MessageContext)

Example 24 with MessageBuilder

use of org.springframework.binding.message.MessageBuilder in project uPortal by Jasig.

the class AttributeSwapRequestValidator method checkAttributesMap.

/**
     * Checks the keys in the Map on the model against a Set to ensure there are no values in the
     * Map that aren't also in the Set
     */
protected void checkAttributesMap(MessageContext context, String basePath, Set<String> swappableAttributes, Map<String, Attribute> attributesToCopy) {
    for (final String attribute : attributesToCopy.keySet()) {
        if (!swappableAttributes.contains(attribute)) {
            final MessageBuilder messageBuilder = new MessageBuilder();
            messageBuilder.error();
            messageBuilder.source(basePath + "[" + attribute + "].value");
            messageBuilder.code("x.is.not.a.valid.attribute");
            messageBuilder.arg(attribute);
            final MessageResolver errorMessage = messageBuilder.build();
            context.addMessage(errorMessage);
        }
    }
}
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