Refactoring CalendarCreator, Testdesign YearCalendar

master
Markus Kreth 7 years ago
parent 17820770e7
commit 3709ddfdbe
  1. 1
      .settings/org.eclipse.core.resources.prefs
  2. 20
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java
  3. 144
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarCreator.java
  4. 79
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/DateMetadata.java
  5. 52
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/MonthlyCalendarCreator.java
  6. 8
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/MonthlyCalendarSource.java
  7. 49
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/YearlyCalendarCreator.java
  8. 60
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/calendar/Year.java
  9. 69
      src/main/resources/jasper/calendar_month.jrxml
  10. 300
      src/main/resources/jasper/calendar_year.jrxml
  11. 2
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarCreatorTest.java
  12. 32
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/calendar/YearTest.java

@ -2,6 +2,7 @@ eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/main/resources/jasper/calendar_month.jrxml=UTF-8
encoding//src/main/resources/jasper/calendar_year.jrxml=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding//target/generated-resources/gwt=UTF-8

@ -7,6 +7,8 @@ import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalUnit;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
@ -111,11 +113,14 @@ public class CalendarComponent extends CustomComponent {
String calendarName = ev.getOrganizerDisplayName();
if ("Schulferien".equals(calendarName)) {
int endDayOfMonth = ev.getEnd().getDayOfMonth();
for (int dayOfMonth = ev.getStart().getDayOfMonth(); dayOfMonth<=endDayOfMonth; dayOfMonth++) {
log.trace("Added to holiday List: {}", ev);
TemporalUnit unit = ChronoUnit.DAYS;
int durationDays = (int) ev.getStart().until(ev.getEnd(), unit) + 1;
for (int dayOfMonth = ev.getStart().getDayOfMonth(), endDay=dayOfMonth + durationDays; dayOfMonth<=endDay; dayOfMonth++) {
holidays.add(dayOfMonth);
}
} else {
log.trace("Added to eventsd: {}", ev);
StringBuilder content;
int dayOfMonth = ev.getStart().getDayOfMonth();
@ -133,22 +138,25 @@ public class CalendarComponent extends CustomComponent {
}
}
}
String calendarMonth = dfMonth.format(start);
try {
JasperPrint print = CalendarCreator.createCalendar(new Date(start.toInstant().toEpochMilli()), values, holidays);
log.trace("Created Jasper print for {}", calendarMonth);
Window window = new Window();
window.setCaption("View PDF");
AbstractComponent e = createEmbedded(dfMonth.format(start), print);
AbstractComponent e = createEmbedded(calendarMonth, print);
window.setContent(e);
window.setModal(true);
window.setWidth("50%");
window.setHeight("90%");
monthName.getUI().addWindow(window);
log.trace("Added pdf window for {}", calendarMonth);
} catch (JRException e) {
log.error("Error Creating Jasper Report.", e);
log.error("Error Creating Jasper Report for {}", calendarMonth, e);
Notification.show("Fehler bei PDF: " + e);
} catch (IOException e1) {
log.error("Error Creating Jasper Report.", e1);
log.error("Error Creating Jasper Report for {}", calendarMonth, e1);
Notification.show("Fehler bei PDF: " + e1);
}
}

@ -1,19 +1,15 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components;
import java.io.InputStream;
import java.sql.Timestamp;
import java.time.YearMonth;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
@ -21,132 +17,62 @@ import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
public class CalendarCreator {
private final YearMonth yearMonthObject;
public abstract class CalendarCreator {
public static JasperPrint createCalendar(Date date) throws JRException {
return new CalendarCreator(date).createCalendar(Collections.emptyMap(), Collections.emptyList());
return new MonthlyCalendarCreator<CharSequence>(date).setValues(Collections.emptyMap()).setHolidays(Collections.emptyList()).createCalendar();
}
public static <T extends CharSequence> JasperPrint createCalendar(Date date, Map<Integer, T> values, Collection<Integer> holidays) throws JRException {
return new CalendarCreator(date).createCalendar(values, holidays);
}
CalendarCreator(Date date) {
yearMonthObject = YearMonth
.from(date.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate()
);
public static <T extends CharSequence> JasperPrint createCalendar(Date date, Map<Integer, T> values,
Collection<Integer> holidays) throws JRException {
return new MonthlyCalendarCreator<T>(date).setValues(values).setHolidays(holidays).createCalendar();
}
<T extends CharSequence> JasperPrint createCalendar(Map<Integer, T> values, Collection<Integer> holidays) throws JRException {
public static JasperPrint createCalendar(int year) throws JRException {
return new YearlyCalendarCreator(year).createCalendar();
}
public final JasperPrint createCalendar() throws JRException {
Map<String, Object> parameters = new HashMap<>();
Timestamp timestamp = new Timestamp(yearMonthObject.atDay(1).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
fillParameterMap(parameters);
parameters.put("Date", timestamp);
InputStream jrxmlResource = CalendarCreator.class.getResourceAsStream("/jasper/calendar_month.jrxml");
JasperReport report = JasperCompileManager
.compileReport(jrxmlResource);
JasperReport report = JasperCompileManager.compileReport(jrxmlResource());
JasperPrint print = JasperFillManager.fillReport(report,
parameters, new CalendarSource<>(yearMonthObject, values, holidays));
JasperPrint print = JasperFillManager.fillReport(report, parameters,
getSource());
return print;
}
protected abstract JRDataSource getSource();
protected abstract void fillParameterMap(Map<String, Object> parameters);
protected abstract InputStream jrxmlResource();
public static void main(String[] args) throws JRException {
Locale.setDefault(Locale.GERMANY);
Calendar cal = new GregorianCalendar(2018, Calendar.AUGUST, 1);
JasperViewer v1 = new JasperViewer(createCalendar(cal.getTime(), Collections.emptyMap(), Arrays.asList(2,3,4,5,6)));
// Calendar cal = new GregorianCalendar(2018, Calendar.DECEMBER, 1);
//
// Map<Integer, String> events = new HashMap<>();
// events.put(3, "Event at 3rd.");
// events.put(23, "Event at 23th.");
// JasperViewer v1 = new JasperViewer(
// createCalendar(cal.getTime(), events, Arrays.asList(2, 3, 4, 5, 6, 22, 23, 24)));
// v1.setVisible(true);
JasperViewer v1 = new JasperViewer(
createCalendar(2018));
v1.setVisible(true);
// cal = new GregorianCalendar(2018, Calendar.FEBRUARY, 1);
// JasperViewer v3 = new JasperViewer(createCalendar(cal.getTime()));
// v3.setVisible(true);
}
/**
*
* @author markus
*
*/
public static class DateMetadata {
private Calendar date;
private int dow;
private int dom;
private int doy;
private int days;
private int cells;
private int limit;
public DateMetadata(java.sql.Date date) {
this(toCalendar(date.getTime()));
}
public DateMetadata(long date) {
this(toCalendar(date));
}
public DateMetadata(Calendar date) {
this.date = (Calendar) date.clone();
date.set(Calendar.DAY_OF_MONTH, 1);
dow = date.get(Calendar.DAY_OF_WEEK);
dom = date.get(Calendar.MONTH) + 1;
doy = date.get(Calendar.YEAR);
days = YearMonth.of(doy, dom).lengthOfMonth();
cells = dow - 1 + days;
limit = cells > 28 ? (cells>35?42:35) : 28;
}
/**
*
* @param date
*/
public DateMetadata(Date date) {
this(toCalendar(date.getTime()));
}
public Date getDate() {
return date.getTime();
}
public int getDow() {
return dow;
}
public int getDom() {
return dom;
}
public int getDoy() {
return doy;
}
public int getDays() {
return days;
}
public int getCells() {
return cells;
}
public int getLimit() {
return limit;
}
}
private static Calendar toCalendar(long time) {
static Calendar toCalendar(long time) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(time);
return cal;

@ -0,0 +1,79 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components;
import java.time.YearMonth;
import java.util.Calendar;
import java.util.Date;
/**
*
* @author markus
*
*/
public class DateMetadata {
private Calendar date;
private int dow;
private int dom;
private int doy;
private int days;
private int cells;
private int limit;
public DateMetadata(java.sql.Date date) {
this(CalendarCreator.toCalendar(date.getTime()));
}
public DateMetadata(long date) {
this(CalendarCreator.toCalendar(date));
}
public DateMetadata(Calendar date) {
this.date = (Calendar) date.clone();
date.set(Calendar.DAY_OF_MONTH, 1);
dow = date.get(Calendar.DAY_OF_WEEK);
dom = date.get(Calendar.MONTH) + 1;
doy = date.get(Calendar.YEAR);
days = YearMonth.of(doy, dom).lengthOfMonth();
cells = dow - 1 + days;
limit = cells > 28 ? (cells>35?42:35) : 28;
}
/**
*
* @param date
*/
public DateMetadata(Date date) {
this(CalendarCreator.toCalendar(date.getTime()));
}
public Date getDate() {
return date.getTime();
}
public int getDow() {
return dow;
}
public int getDom() {
return dom;
}
public int getDoy() {
return doy;
}
public int getDays() {
return days;
}
public int getCells() {
return cells;
}
public int getLimit() {
return limit;
}
}

@ -0,0 +1,52 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components;
import java.io.InputStream;
import java.sql.Timestamp;
import java.time.YearMonth;
import java.time.ZoneId;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import net.sf.jasperreports.engine.JRDataSource;
public class MonthlyCalendarCreator<T extends CharSequence> extends CalendarCreator {
private final YearMonth yearMonthObject;
private Map<Integer, T> values;
private Collection<Integer> holidays;
public MonthlyCalendarCreator(Date date) {
this.yearMonthObject = YearMonth.from(date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
}
public MonthlyCalendarCreator<T> setValues(Map<Integer, T> values) {
this.values = values;
return this;
}
public MonthlyCalendarCreator<T> setHolidays(Collection<Integer> holidays) {
this.holidays = holidays;
return this;
}
@Override
protected void fillParameterMap(Map<String, Object> parameters) {
Timestamp timestamp = new Timestamp(
yearMonthObject.atDay(1).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
parameters.put("Date", timestamp);
}
@Override
protected InputStream jrxmlResource() {
return CalendarCreator.class.getResourceAsStream("/jasper/calendar_month.jrxml");
}
@Override
protected JRDataSource getSource() {
return new MonthlyCalendarSource<>(yearMonthObject, values, holidays);
}
}

@ -12,7 +12,7 @@ import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
public class CalendarSource<T extends CharSequence> implements JRDataSource {
public class MonthlyCalendarSource<T extends CharSequence> implements JRDataSource {
private final List<Integer> days;
private final Map<Integer, T> dayContent;
@ -20,7 +20,7 @@ public class CalendarSource<T extends CharSequence> implements JRDataSource {
private int prefix;
private final Collection<Integer> holidays;
public CalendarSource(YearMonth yearMonthObject, Map<Integer, T> dayContent, Collection<Integer> holidays) {
public MonthlyCalendarSource(YearMonth yearMonthObject, Map<Integer, T> dayContent, Collection<Integer> holidays) {
days = new ArrayList<>();
this.dayContent = dayContent;
@ -64,13 +64,13 @@ public class CalendarSource<T extends CharSequence> implements JRDataSource {
}
}
public static CalendarSource<String> createTestSource() {
public static MonthlyCalendarSource<String> createTestSource() {
Map<Integer, String> values = new HashMap<>();
for (int i=1; i<30;i+=3) {
values.put(i, String.format("Termin am %s.", i));
}
List<Integer> holi = Arrays.asList(2,3,4,5,6);
return new CalendarSource<>(YearMonth.now(), values, holi );
return new MonthlyCalendarSource<>(YearMonth.now(), values, holi );
}
}

@ -0,0 +1,49 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components;
import java.io.InputStream;
import java.util.Collection;
import java.util.Map;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.calendar.Year;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import net.sf.jasperreports.engine.JasperPrint;
public class YearlyCalendarCreator extends CalendarCreator {
private Year year;
public YearlyCalendarCreator(int year) {
this.year = new Year(year);
}
@Override
protected JRDataSource getSource() {
return new EmptySource();
}
@Override
protected void fillParameterMap(Map<String, Object> parameters) {
parameters.put("Year", year);
}
@Override
protected InputStream jrxmlResource() {
return CalendarCreator.class.getResourceAsStream("/jasper/calendar_year.jrxml");
}
private static class EmptySource implements JRDataSource {
@Override
public boolean next() throws JRException {
return false;
}
@Override
public Object getFieldValue(JRField jrField) throws JRException {
return null;
}
}
}

@ -0,0 +1,60 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.calendar;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.format.TextStyle;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Queue;
public class Year {
private final LocalDate date;
private final Locale locale;
public Year(int year) {
this(year, Locale.getDefault());
}
public Year(int year, Locale locale) {
if (year < 1900 || year >2100) {
throw new IllegalArgumentException("Year value must be between 1900 and 2100");
}
this.date = LocalDate.of(year, 1, 1);
this.locale = locale;
}
public int getYear() {
return date.getYear();
}
public CharSequence getMonth(Month month) {
return month.getDisplayName(TextStyle.FULL_STANDALONE, locale);
}
List<Integer> days = Arrays.asList(null, null, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,28,30,31,32);
Queue<Integer> queue = new LinkedList<>(days);
/**
* Day of month, numeric for the specified by parameters.
* @param month month of the day
* @param week 1-5th week of the month
* @param dayOfWeek weekday of the week in the month.
* @return numeric value of the day of the month.
*/
public String getDay(Month month, short week, DayOfWeek dayOfWeek) {
if (queue.isEmpty()) {
queue.addAll(days);
}
Integer poll = queue.poll();
if (poll != null) {
return poll.toString();
} else {
return "";
}
}
}

@ -56,6 +56,12 @@
<band height="60">
<textField pattern="yyyy MMMM">
<reportElement x="0" y="0" width="770" height="30" uuid="21293131-3839-43aa-b449-b19867eee2da"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center">
<font size="16" isBold="true"/>
</textElement>
@ -66,12 +72,10 @@
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid"/>
<leftPen lineWidth="0.0" lineStyle="Solid"/>
<bottomPen lineWidth="0.0" lineStyle="Solid"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#FFFCFC"/>
<pen lineColor="#403D3D"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.GregorianCalendar(2018, Calendar.OCTOBER, 1).getTime()]]></textFieldExpression>
@ -81,12 +85,10 @@
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="1.0" lineStyle="Solid"/>
<leftPen lineWidth="1.0" lineStyle="Solid"/>
<bottomPen lineWidth="1.0" lineStyle="Solid"/>
<rightPen lineWidth="1.0" lineStyle="Solid"/>
<pen lineColor="#403D3D"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.GregorianCalendar(2018, Calendar.OCTOBER, 2).getTime()]]></textFieldExpression>
@ -96,12 +98,10 @@
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="1.0" lineStyle="Solid"/>
<leftPen lineWidth="1.0" lineStyle="Solid"/>
<bottomPen lineWidth="1.0" lineStyle="Solid"/>
<rightPen lineWidth="1.0" lineStyle="Solid"/>
<pen lineColor="#403D3D"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.GregorianCalendar(2018, Calendar.OCTOBER, 3).getTime()]]></textFieldExpression>
@ -111,12 +111,10 @@
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="1.0" lineStyle="Solid"/>
<leftPen lineWidth="1.0" lineStyle="Solid"/>
<bottomPen lineWidth="1.0" lineStyle="Solid"/>
<rightPen lineWidth="1.0" lineStyle="Solid"/>
<pen lineColor="#403D3D"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.GregorianCalendar(2018, Calendar.OCTOBER, 4).getTime()]]></textFieldExpression>
@ -126,12 +124,10 @@
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="1.0" lineStyle="Solid"/>
<leftPen lineWidth="1.0" lineStyle="Solid"/>
<bottomPen lineWidth="1.0" lineStyle="Solid"/>
<rightPen lineWidth="1.0" lineStyle="Solid"/>
<pen lineColor="#403D3D"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.GregorianCalendar(2018, Calendar.OCTOBER, 5).getTime()]]></textFieldExpression>
@ -141,12 +137,10 @@
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="1.0" lineStyle="Solid"/>
<leftPen lineWidth="1.0" lineStyle="Solid"/>
<bottomPen lineWidth="1.0" lineStyle="Solid"/>
<rightPen lineWidth="1.0" lineStyle="Solid"/>
<pen lineColor="#000000"/>
<bottomPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.GregorianCalendar(2018, Calendar.OCTOBER, 6).getTime()]]></textFieldExpression>
@ -156,12 +150,11 @@
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="1.0" lineStyle="Solid"/>
<leftPen lineWidth="1.0" lineStyle="Solid"/>
<bottomPen lineWidth="1.0" lineStyle="Solid"/>
<rightPen lineWidth="1.0" lineStyle="Solid"/>
<pen lineColor="#000000"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.GregorianCalendar(2018, Calendar.OCTOBER, 7).getTime()]]></textFieldExpression>
@ -176,6 +169,12 @@
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement style="Style_Calendar_Day_Number" mode="Opaque" x="80" y="0" width="30" height="21" isRemoveLineWhenBlank="true" uuid="733ff549-0109-4f55-b9de-476f0ad9fbeb">
<printWhenExpression><![CDATA[$V{Date}.intValue()>0&&$V{Date}.intValue()<=$P{Days}.intValue()]]></printWhenExpression>

@ -0,0 +1,300 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="clubhelper_calendar" printOrder="Horizontal" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="573" leftMargin="11" rightMargin="11" topMargin="6" bottomMargin="6" uuid="32abf871-39b8-4cc7-b03c-d950a55e2bfb">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="CalendarSource"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<style name="Style_Calendar_Day_Number" forecolor="#050505" backcolor="#FFFFFF">
<conditionalStyle>
<conditionExpression><![CDATA[$F{id}.intValue()%7==0]]></conditionExpression>
<style forecolor="#FA0702"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$F{IsHoliday}]]></conditionExpression>
<style backcolor="#FFFFCC"/>
</conditionalStyle>
</style>
<style name="Style_Calendar_Holiday" backcolor="#FFFFFF">
<conditionalStyle>
<conditionExpression><![CDATA[$F{IsHoliday}]]></conditionExpression>
<style backcolor="#FFFFCC"/>
</conditionalStyle>
</style>
<parameter name="Date" class="java.time.LocalDate">
<defaultValueExpression><![CDATA[java.time.LocalDate.now()]]></defaultValueExpression>
</parameter>
<parameter name="Year" class="de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.calendar.Year"/>
<queryString>
<![CDATA[SELECT i as id FROM generate_series(1, 31 ) i]]>
</queryString>
<field name="id" class="java.lang.Integer"/>
<field name="Field_Value" class="java.lang.String"/>
<field name="IsHoliday" class="java.lang.Boolean">
<fieldDescription><![CDATA[Current Day is a holiday]]></fieldDescription>
</field>
<title>
<band height="505">
<textField pattern="MMMM">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="286" height="25" uuid="21293131-3839-43aa-b449-b19867eee2da"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font size="16" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[java.time.Month.JANUARY.getDisplayName(java.time.format.TextStyle.FULL_STANDALONE, java.util.Locale.getDefault())]]></textFieldExpression>
</textField>
<staticText>
<reportElement mode="Opaque" x="0" y="26" width="41" height="10" forecolor="#FFFCFC" backcolor="#403D3D" uuid="1b4d6c56-6d09-482b-8eb5-662c88cbe870">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<pen lineColor="#000000"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="6" isBold="true"/>
</textElement>
<text><![CDATA[Montag]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="42" y="26" width="41" height="10" forecolor="#FFFCFC" backcolor="#403D3D" uuid="a373077e-66c1-4218-b9a2-bd35f7d19f7a">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<pen lineColor="#000000"/>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="6" isBold="true"/>
</textElement>
<text><![CDATA[Dienstag]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="84" y="26" width="41" height="10" forecolor="#FFFCFC" backcolor="#403D3D" uuid="d1e26dda-0b1a-4ef2-b48c-276accc3eeaa">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<pen lineColor="#000000"/>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="6" isBold="true"/>
</textElement>
<text><![CDATA[Mittwoch]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="126" y="26" width="41" height="10" forecolor="#FFFCFC" backcolor="#403D3D" uuid="9c9395c6-7cc2-4571-97f6-e3b4bfe58263">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<pen lineColor="#000000"/>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="6" isBold="true"/>
</textElement>
<text><![CDATA[Donnerstag]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="168" y="26" width="41" height="10" forecolor="#FFFCFC" backcolor="#403D3D" uuid="12589ff4-2da8-448f-995a-99cf8446ccfa">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<pen lineColor="#000000"/>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="6" isBold="true"/>
</textElement>
<text><![CDATA[Freitag]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="210" y="26" width="41" height="10" forecolor="#FFFCFC" backcolor="#403D3D" uuid="c2f7be3d-5ccf-4838-b55d-51eafd78f3e4">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<pen lineColor="#000000"/>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="6" isBold="true"/>
</textElement>
<text><![CDATA[Samstag]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="252" y="26" width="41" height="10" forecolor="#FFFCFC" backcolor="#403D3D" uuid="bc9c8dee-afda-435c-8f11-d7294c248f8c">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<pen lineColor="#000000"/>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="6" isBold="true"/>
</textElement>
<text><![CDATA[Sonntag]]></text>
</staticText>
<frame>
<reportElement mode="Transparent" x="0" y="38" width="41" height="50" backcolor="#F7C86F" uuid="7621d880-6dae-4cfb-9d99-6c4c83dd1983">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textField>
<reportElement style="Style_Calendar_Day_Number" mode="Opaque" x="0" y="0" width="41" height="10" isRemoveLineWhenBlank="true" uuid="e30cd5f6-c9f8-459d-b37e-401dadccba90"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="6" isBold="true"/>
<paragraph rightIndent="1"/>
</textElement>
<textFieldExpression><![CDATA[$P{Year}.getDay( java.time.Month.JANUARY, (short)1, java.time.DayOfWeek.MONDAY )]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="41" height="40" isRemoveLineWhenBlank="true" uuid="660304e6-2981-448f-8990-0cf8f2efbc23"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement>
<font size="4"/>
</textElement>
<textFieldExpression><![CDATA[$F{Field_Value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement mode="Transparent" x="41" y="38" width="41" height="50" backcolor="#F7C86F" uuid="7e44315b-20e3-43bf-9014-e0d0aa6072f3">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textField>
<reportElement style="Style_Calendar_Day_Number" mode="Opaque" x="0" y="0" width="41" height="10" isRemoveLineWhenBlank="true" uuid="202fe000-98be-4c0f-b59c-7bc91a656a5b"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="6" isBold="true"/>
<paragraph rightIndent="1"/>
</textElement>
<textFieldExpression><![CDATA[$P{Year}.getDay( java.time.Month.JANUARY, (short)1, java.time.DayOfWeek.TUESDAY )]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="41" height="40" isRemoveLineWhenBlank="true" uuid="208dff4b-9244-4c50-9ae1-e6b1a36fc06a"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement>
<font size="4"/>
</textElement>
<textFieldExpression><![CDATA[$F{Field_Value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement mode="Transparent" x="41" y="90" width="41" height="50" backcolor="#F7C86F" uuid="55a1c7f6-7ce3-4824-9d1b-fb0290572f7c">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textField>
<reportElement style="Style_Calendar_Day_Number" mode="Opaque" x="0" y="0" width="41" height="10" isRemoveLineWhenBlank="true" uuid="389d3764-a279-4825-bb7d-e36f1be6b580"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="6" isBold="true"/>
<paragraph rightIndent="1"/>
</textElement>
<textFieldExpression><![CDATA[$P{Year}.getDay( java.time.Month.JANUARY, (short)2, java.time.DayOfWeek.TUESDAY )]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="41" height="40" isRemoveLineWhenBlank="true" uuid="ecf323b4-70bd-4cdf-96e5-f16c400d7710"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement>
<font size="4"/>
</textElement>
<textFieldExpression><![CDATA[$F{Field_Value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement mode="Transparent" x="0" y="90" width="41" height="50" backcolor="#F7C86F" uuid="f72aa4b4-fc79-4ee5-bb8e-51df4c08d0b4">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textField>
<reportElement style="Style_Calendar_Day_Number" mode="Opaque" x="0" y="0" width="41" height="10" isRemoveLineWhenBlank="true" uuid="74c81ac8-3588-4df4-bec7-bb3193c625c1"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="6" isBold="true"/>
<paragraph rightIndent="1"/>
</textElement>
<textFieldExpression><![CDATA[$P{Year}.getDay( java.time.Month.JANUARY, (short)2, java.time.DayOfWeek.MONDAY )]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="41" height="40" isRemoveLineWhenBlank="true" uuid="16724e14-9391-4fe0-99b8-4284ec4d39d1"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement>
<font size="4"/>
</textElement>
<textFieldExpression><![CDATA[$F{Field_Value}]]></textFieldExpression>
</textField>
</frame>
</band>
</title>
<detail>
<band/>
</detail>
</jasperReport>

@ -8,8 +8,6 @@ import org.junit.jupiter.api.Test;
import com.ibm.icu.util.Calendar;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarCreator.DateMetadata;
class CalendarCreatorTest {
@Test

@ -0,0 +1,32 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.calendar;
import static org.junit.jupiter.api.Assertions.*;
import java.time.DayOfWeek;
import java.time.Month;
import org.junit.jupiter.api.Test;
class YearTest {
@Test()
void test18thCenturyEx() {
assertThrows(IllegalArgumentException.class, () -> new Year(1899));
assertThrows(IllegalArgumentException.class, () -> new Year(2101));
new Year(1900);
new Year(2100);
}
@Test
void testMondayIsFirst() {
Year y = new Year(2018);
assertEquals(Short.valueOf((short)1), y.getDay(Month.OCTOBER, (short)1, DayOfWeek.MONDAY));
}
@Test
void testThursdayIsFirst() {
Year y = new Year(2018);
assertNull(y.getDay(Month.NOVEMBER, (short)1, DayOfWeek.MONDAY));
}
}
Loading…
Cancel
Save