Search in sources :

Example 6 with ReportEmailRecipient

use of au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipient in project VaadinUtils by rlsutton1.

the class JasperReportScheduleLayout method interceptSaveValues.

@Override
protected void interceptSaveValues(EntityItem<ReportEmailScheduleEntity> entityItem) {
    ReportEmailScheduleEntity entity = entityItem.getEntity();
    entity.setNextScheduledRunTime(entity.getScheduleMode().getNextRuntime(entity, new Date()));
    List<ReportEmailRecipient> recips = entity.getRecipients();
    Set<ReportEmailRecipient> matchedRecips = new HashSet<ReportEmailRecipient>();
    for (EmailTargetLine line : emailTargetLayout.getTargets()) {
        // check if the recipient exists
        String email = (String) line.targetAddress.getValue();
        if (email != null && email.length() > 0) {
            // String email = (String)
            // item.getItemProperty("id").getValue();
            boolean found = false;
            for (ReportEmailRecipient recip : recips) {
                if (recip.getEmail() != null && recip.getEmail().equalsIgnoreCase(email)) {
                    found = true;
                    recip.setVisibility((ReportEmailRecipientVisibility) line.targetTypeCombo.getValue());
                    matchedRecips.add(recip);
                    break;
                }
            }
            // if not then add them
            if (!found) {
                ReportEmailRecipient reportEmailRecipient = new ReportEmailRecipient();
                reportEmailRecipient.setEmail(email);
                reportEmailRecipient.setVisibility((ReportEmailRecipientVisibility) line.targetTypeCombo.getValue());
                recips.add(reportEmailRecipient);
                matchedRecips.add(reportEmailRecipient);
            }
        }
    }
    recips.clear();
    recips.addAll(matchedRecips);
    if (recips.size() == 0) {
        throw new InvalidValueException("Select at least one Recipient");
    }
    saveChangesToReportParameters(entity);
}
Also used : InvalidValueException(com.vaadin.data.Validator.InvalidValueException) ReportEmailRecipient(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipient) ReportEmailScheduleEntity(au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

ReportEmailRecipient (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailRecipient)6 ReportEmailScheduleEntity (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduleEntity)3 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2 AttachmentType (au.com.vaadinutils.jasper.AttachmentType)1 JasperEmailBuilder (au.com.vaadinutils.jasper.JasperEmailBuilder)1 JasperManager (au.com.vaadinutils.jasper.JasperManager)1 OutputFormat (au.com.vaadinutils.jasper.JasperManager.OutputFormat)1 RenderedReport (au.com.vaadinutils.jasper.RenderedReport)1 ReportChooser (au.com.vaadinutils.jasper.parameter.ReportChooser)1 ReportParameter (au.com.vaadinutils.jasper.parameter.ReportParameter)1 ReportEmailParameterEntity (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailParameterEntity)1 ReportEmailScheduledDateParameter (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailScheduledDateParameter)1 ReportEmailSender (au.com.vaadinutils.jasper.scheduler.entities.ReportEmailSender)1 JasperReportPropertiesAlternateFile (au.com.vaadinutils.jasper.ui.JasperReportPropertiesAlternateFile)1 Item (com.vaadin.data.Item)1 InvalidValueException (com.vaadin.data.Validator.InvalidValueException)1 HashSet (java.util.HashSet)1 EntityManager (javax.persistence.EntityManager)1