Search in sources :

Example 1 with JpaDslBuilder

use of au.com.vaadinutils.dao.JpaDslBuilder in project VaadinUtils by rlsutton1.

the class JasperReportLayout method addButtonListener.

private void addButtonListener(Button button, final OutputFormat format) {
    button.addClickListener(new ClickEventLogged.ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void clicked(ClickEvent event) {
            try {
                createFrequentlyUsed();
                createHistory();
                printButton.setEnabled(false);
                exportButton.setEnabled(false);
                showButton.setEnabled(false);
                for (ExpanderComponent componet : components) {
                    componet.getComponent().setEnabled(false);
                }
                generateReport(format, JasperReportLayout.this.builder.getReportParameters());
            } catch (Exception e) {
                printButton.setEnabled(true);
                exportButton.setEnabled(true);
                showButton.setEnabled(true);
                for (ExpanderComponent componet : components) {
                    componet.getComponent().setEnabled(true);
                }
                Notification.show(e.getMessage(), Type.ERROR_MESSAGE);
                logger.error(e, e);
            } finally {
            }
        }

        private void createHistory() {
            Collection<ReportParameter<?>> params = builder.getReportParameters();
            ReportSave reportSave = new ReportSave();
            reportSave.setReportClass(reportProperties.getReportClass().getName());
            reportSave.setUserDescription("");
            reportSave.setUser(reportProperties.getUsername());
            reportSave.setSaveType(SaveType.HISTORY);
            JpaBaseDao.getEntityManager().persist(reportSave);
            for (ReportParameter<?> param : params) {
                for (String pname : param.getParameterNames()) {
                    if (StringUtils.isNotBlank(param.getLabel(pname))) {
                        ReportSaveParameter reportSaveparam = new ReportSaveParameter();
                        reportSaveparam.setParameterName(param.getLabel(pname));
                        reportSaveparam.setTextualRepresentation(param.getDisplayValue(pname));
                        reportSaveparam.setParameterValue(param.getValue(pname).toString());
                        reportSaveparam.setMetaData(param.getSaveMetaData());
                        reportSaveparam.setMetaDataComment(param.getMetaDataComment());
                        reportSave.addParameter(reportSaveparam);
                        JpaBaseDao.getEntityManager().persist(reportSaveparam);
                    }
                }
            }
            // remove excess history
            JpaDslBuilder<ReportSave> q = new JpaBaseDao<>(ReportSave.class).select();
            List<ReportSave> history = q.where(q.eq(ReportSave_.user, reportProperties.getUsername()).and(q.eq(ReportSave_.saveType, SaveType.HISTORY))).orderBy(ReportSave_.lastUsed, true).getResultList();
            if (history.size() > 50) {
                ReportSave old = history.get(0);
                for (ReportSaveParameter param : old.getParameters()) {
                    EntityManagerProvider.remove(param);
                }
                EntityManagerProvider.remove(old);
            }
        }

        private void createFrequentlyUsed() {
            JpaDslBuilder<ReportSave> q = new JpaBaseDao<>(ReportSave.class).select();
            ReportSave reportSave = q.where(q.eq(ReportSave_.reportClass, reportProperties.getReportClass().getName()).and(q.eq(ReportSave_.user, reportProperties.getUsername()).and(q.eq(ReportSave_.saveType, SaveType.FREQUENTLY_USED)))).getSingleResultOrNull();
            if (reportSave == null) {
                reportSave = new ReportSave();
                reportSave.setReportClass(reportProperties.getReportClass().getName());
                reportSave.setUserDescription("Frequently used");
                reportSave.setUser(reportProperties.getUsername());
                reportSave.setSaveType(SaveType.FREQUENTLY_USED);
                JpaBaseDao.getEntityManager().persist(reportSave);
            }
            reportSave.incrementRunCounter();
        }
    });
}
Also used : JpaDslBuilder(au.com.vaadinutils.dao.JpaDslBuilder) ClickEventLogged(au.com.vaadinutils.listener.ClickEventLogged) ExpanderComponent(au.com.vaadinutils.jasper.filter.ExpanderComponent) ReportParameter(au.com.vaadinutils.jasper.parameter.ReportParameter) JpaBaseDao(au.com.vaadinutils.dao.JpaBaseDao) ClickEvent(com.vaadin.ui.Button.ClickEvent) ParseException(java.text.ParseException) ConversionException(com.vaadin.data.util.converter.Converter.ConversionException) ReadOnlyException(com.vaadin.data.Property.ReadOnlyException) Collection(java.util.Collection) List(java.util.List) LinkedList(java.util.LinkedList) ReportSave(au.com.vaadinutils.jasper.scheduler.entities.ReportSave) ReportSaveParameter(au.com.vaadinutils.jasper.scheduler.entities.ReportSaveParameter)

Example 2 with JpaDslBuilder

use of au.com.vaadinutils.dao.JpaDslBuilder in project VaadinUtils by rlsutton1.

the class BasePortal method createHeader.

private HorizontalLayout createHeader(String title, final DashBoardController dashBoard) {
    HorizontalLayout header = new HorizontalLayout();
    header.setWidth("100%");
    header.setHeight("25");
    titleLabel = new Label(title);
    titleLabel.setStyleName(ValoTheme.LABEL_COLORED);
    header.addComponent(titleLabel);
    HorizontalLayout controlLayout = new HorizontalLayout();
    Button removeButton = new Button(FontAwesome.CLOSE);
    removeButton.setStyleName(ValoTheme.BUTTON_LINK);
    removeButton.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            dashBoard.removeComponent(BasePortal.this);
            Tblportal portal = JpaBaseDao.getGenericDao(Tblportal.class).findOneByAttribute(Tblportal_.guid, guid);
            if (portal != null) {
                portal.getPortalLayout().removePortal(portal);
                JpaDslBuilder<Tblportalconfig> q = JpaBaseDao.getGenericDao(Tblportalconfig.class).select();
                q.where(q.eq(Tblportalconfig_.portal, portal)).delete();
                EntityManagerProvider.remove(portal);
            }
        }
    });
    if (canUserConfigurePortal()) {
        addCustomHeaderButtons(controlLayout);
        controlLayout.addComponent(removeButton);
    }
    header.addComponent(controlLayout);
    header.setComponentAlignment(controlLayout, Alignment.MIDDLE_RIGHT);
    return header;
}
Also used : JpaDslBuilder(au.com.vaadinutils.dao.JpaDslBuilder) Button(com.vaadin.ui.Button) ClickEvent(com.vaadin.ui.Button.ClickEvent) Label(com.vaadin.ui.Label) ClickListener(com.vaadin.ui.Button.ClickListener) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Aggregations

JpaDslBuilder (au.com.vaadinutils.dao.JpaDslBuilder)2 ClickEvent (com.vaadin.ui.Button.ClickEvent)2 JpaBaseDao (au.com.vaadinutils.dao.JpaBaseDao)1 ExpanderComponent (au.com.vaadinutils.jasper.filter.ExpanderComponent)1 ReportParameter (au.com.vaadinutils.jasper.parameter.ReportParameter)1 ReportSave (au.com.vaadinutils.jasper.scheduler.entities.ReportSave)1 ReportSaveParameter (au.com.vaadinutils.jasper.scheduler.entities.ReportSaveParameter)1 ClickEventLogged (au.com.vaadinutils.listener.ClickEventLogged)1 ReadOnlyException (com.vaadin.data.Property.ReadOnlyException)1 ConversionException (com.vaadin.data.util.converter.Converter.ConversionException)1 Button (com.vaadin.ui.Button)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Label (com.vaadin.ui.Label)1 ParseException (java.text.ParseException)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1