From 75d6ed4f09f5e53840df16bbf2e89a1ad8428f8b Mon Sep 17 00:00:00 2001 From: Markus Kreth Date: Fri, 11 Jan 2019 22:26:28 +0100 Subject: [PATCH] Refactoring: Jasper export related classes in own package --- .../vaadinclubhelper/dao/AbstractDaoImpl.java | 92 ++++++++-------- .../CalendarCreator.java | 4 +- .../components => jasper}/DateMetadata.java | 2 +- .../MonthlyCalendarCreator.java | 2 +- .../MonthlyCalendarSource.java | 2 +- .../YearlyCalendarCreator.java | 2 +- .../vaadinclubhelper/ui/LoginUI.java | 104 +++++++++--------- .../ui/components/HeadComponent.java | 1 + .../themes/vaadin-clubhelpertheme/addons.scss | 22 ++-- .../ui/components/CalendarCreatorTest.java | 2 + .../components/YearlyCalendarCreatorTest.java | 2 + 11 files changed, 120 insertions(+), 115 deletions(-) rename src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/{ui/components => jasper}/CalendarCreator.java (98%) rename src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/{ui/components => jasper}/DateMetadata.java (94%) rename src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/{ui/components => jasper}/MonthlyCalendarCreator.java (95%) rename src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/{ui/components => jasper}/MonthlyCalendarSource.java (97%) rename src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/{ui/components => jasper}/YearlyCalendarCreator.java (96%) diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/AbstractDaoImpl.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/AbstractDaoImpl.java index 7dd71d6..2f9feb4 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/AbstractDaoImpl.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/AbstractDaoImpl.java @@ -1,46 +1,46 @@ -package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao; - -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; - -public abstract class AbstractDaoImpl implements IDao { - - @Autowired - protected EntityManager em; - - private final Class entityClass; - - public AbstractDaoImpl(Class entityClass) { - super(); - this.entityClass = entityClass; - } - - @Override - @Transactional - public void save(T obj) { - em.persist(obj); - } - - @Override - @Transactional - public T update(T obj) { - return em.merge(obj); - } - - @Override - public T get(Object primaryKey) { - return em.find(entityClass, primaryKey); - } - - @Override - public List listAll() { - TypedQuery query = em.createNamedQuery(entityClass.getSimpleName() + ".findAll", entityClass); - return query.getResultList(); - } - -} +package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.TypedQuery; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +public abstract class AbstractDaoImpl implements IDao { + + @Autowired + protected EntityManager em; + + private final Class entityClass; + + public AbstractDaoImpl(Class entityClass) { + super(); + this.entityClass = entityClass; + } + + @Override + @Transactional + public void save(T obj) { + em.persist(obj); + } + + @Override + @Transactional + public T update(T obj) { + return em.merge(obj); + } + + @Override + public T get(Object primaryKey) { + return em.find(entityClass, primaryKey); + } + + @Override + public List listAll() { + TypedQuery query = em.createNamedQuery(entityClass.getSimpleName() + ".findAll", entityClass); + return query.getResultList(); + } + +} diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarCreator.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/CalendarCreator.java similarity index 98% rename from src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarCreator.java rename to src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/CalendarCreator.java index 30c4b0b..f7dd16a 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarCreator.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/CalendarCreator.java @@ -1,4 +1,4 @@ -package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; +package de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper; import java.io.InputStream; import java.time.LocalDate; @@ -168,7 +168,7 @@ public abstract class CalendarCreator { return dao.listAll(); } - static Calendar toCalendar(long time) { + public static Calendar toCalendar(long time) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(time); return cal; diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/DateMetadata.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/DateMetadata.java similarity index 94% rename from src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/DateMetadata.java rename to src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/DateMetadata.java index 4fffe9d..e24feaa 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/DateMetadata.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/DateMetadata.java @@ -1,4 +1,4 @@ -package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; +package de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper; import java.time.YearMonth; import java.util.Calendar; diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/MonthlyCalendarCreator.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/MonthlyCalendarCreator.java similarity index 95% rename from src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/MonthlyCalendarCreator.java rename to src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/MonthlyCalendarCreator.java index d927153..f51b295 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/MonthlyCalendarCreator.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/MonthlyCalendarCreator.java @@ -1,4 +1,4 @@ -package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; +package de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper; import java.io.InputStream; import java.sql.Timestamp; diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/MonthlyCalendarSource.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/MonthlyCalendarSource.java similarity index 97% rename from src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/MonthlyCalendarSource.java rename to src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/MonthlyCalendarSource.java index c01edef..73f0272 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/MonthlyCalendarSource.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/MonthlyCalendarSource.java @@ -1,4 +1,4 @@ -package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; +package de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper; import java.time.LocalDate; import java.time.YearMonth; diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/YearlyCalendarCreator.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/YearlyCalendarCreator.java similarity index 96% rename from src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/YearlyCalendarCreator.java rename to src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/YearlyCalendarCreator.java index 88f79ad..b5d36f8 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/YearlyCalendarCreator.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/jasper/YearlyCalendarCreator.java @@ -1,4 +1,4 @@ -package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; +package de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper; import java.io.InputStream; import java.time.LocalDate; diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/LoginUI.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/LoginUI.java index 05c73ba..03e3e06 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/LoginUI.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/LoginUI.java @@ -1,52 +1,52 @@ -package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui; - -import com.vaadin.navigator.Navigator; -import com.vaadin.navigator.View; -import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.LoginForm; -import com.vaadin.ui.Notification; -import com.vaadin.ui.VerticalLayout; - -import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; -import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; - -public class LoginUI extends VerticalLayout implements View { - - private static final long serialVersionUID = 4339018452507960084L; - public static final String VIEW_NAME = "LoginUI"; - - private Navigator navigator; - private String parameters; - - public LoginUI(PersonDao personDao) { - - LoginForm lf = new LoginForm(); - lf.addLoginListener(e -> { - - String username = e.getLoginParameter("username"); - String password = e.getLoginParameter("password"); - - try { - Person loggedin = personDao.findLoginUser(username, password); - this.getSession().setAttribute(Person.SESSION_LOGIN, loggedin); - navigator.navigateTo(MainView.VIEW_NAME + '/' + parameters); - } catch (final Exception ex) { - String message = "Incorrect user or password:" + ex.getMessage() + e.getLoginParameter("username") + ":" - + e.getLoginParameter("password"); - Notification.show(message, Notification.Type.ERROR_MESSAGE); - } - }); - addComponent(lf); - setComponentAlignment(lf, Alignment.MIDDLE_CENTER); - setSizeFull(); - - } - - @Override - public void enter(ViewChangeEvent event) { - View.super.enter(event); - navigator = event.getNavigator(); - parameters = event.getParameters(); - } -} +package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui; + +import com.vaadin.navigator.Navigator; +import com.vaadin.navigator.View; +import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.LoginForm; +import com.vaadin.ui.Notification; +import com.vaadin.ui.VerticalLayout; + +import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; + +public class LoginUI extends VerticalLayout implements View { + + private static final long serialVersionUID = 4339018452507960084L; + public static final String VIEW_NAME = "LoginUI"; + + private Navigator navigator; + private String parameters; + + public LoginUI(PersonDao personDao) { + + LoginForm lf = new LoginForm(); + lf.addLoginListener(e -> { + + String username = e.getLoginParameter("username"); + String password = e.getLoginParameter("password"); + + try { + Person loggedin = personDao.findLoginUser(username, password); + this.getSession().setAttribute(Person.SESSION_LOGIN, loggedin); + navigator.navigateTo(MainView.VIEW_NAME + '/' + parameters); + } catch (final Exception ex) { + String message = "Incorrect user or password:" + ex.getMessage() + e.getLoginParameter("username") + ":" + + e.getLoginParameter("password"); + Notification.show(message, Notification.Type.ERROR_MESSAGE); + } + }); + addComponent(lf); + setComponentAlignment(lf, Alignment.MIDDLE_CENTER); + setSizeFull(); + + } + + @Override + public void enter(ViewChangeEvent event) { + View.super.enter(event); + navigator = event.getNavigator(); + parameters = event.getParameters(); + } +} diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/HeadComponent.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/HeadComponent.java index f171a00..21a232e 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/HeadComponent.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/HeadComponent.java @@ -32,6 +32,7 @@ import com.vaadin.ui.Notification; import com.vaadin.ui.Window; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper.CalendarCreator; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarComponent.ClubEventProvider; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperExportManager; diff --git a/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/addons.scss b/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/addons.scss index cc01590..00d2491 100644 --- a/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/addons.scss +++ b/src/main/webapp/VAADIN/themes/vaadin-clubhelpertheme/addons.scss @@ -1,12 +1,12 @@ -/* This file is automatically managed and will be overwritten from time to time. */ -/* Do not manually edit this file. */ - -/* Provided by calendar-component-2.0-BETA4.jar */ +/* This file is automatically managed and will be overwritten from time to time. */ +/* Do not manually edit this file. */ + +/* Provided by calendar-component-2.0-BETA4.jar */ @import "../../../VAADIN/addons/calendar/calendar-addon.scss"; - - -/* Import and include this mixin into your project theme to include the addon themes */ -@mixin addons { - @include calendar-addon; -} - + + +/* Import and include this mixin into your project theme to include the addon themes */ +@mixin addons { + @include calendar-addon; +} + diff --git a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarCreatorTest.java b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarCreatorTest.java index 2730d96..09c0025 100644 --- a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarCreatorTest.java +++ b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarCreatorTest.java @@ -8,6 +8,8 @@ import org.junit.jupiter.api.Test; import com.ibm.icu.util.Calendar; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper.DateMetadata; + class CalendarCreatorTest { @Test diff --git a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/YearlyCalendarCreatorTest.java b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/YearlyCalendarCreatorTest.java index 7042cfd..ad6d7ab 100644 --- a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/YearlyCalendarCreatorTest.java +++ b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/YearlyCalendarCreatorTest.java @@ -5,6 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper.YearlyCalendarCreator; + class YearlyCalendarCreatorTest { @BeforeEach