CalendarCreator creates Jan - June

master
Markus Kreth 7 years ago
parent 187d9098ce
commit 9b803d581c
  1. 27
      pom.xml
  2. 4
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/CalendarTaskRefresher.java
  3. 3
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/AbstractDaoImpl.java
  4. 10
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDaoImpl.java
  5. 8
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/YearlyCalendarCreator.java
  6. 9
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/calendar/WeeksOfMonth.java
  7. 32
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/calendar/Year.java
  8. 1850
      src/main/resources/jasper/calendar_year.jrxml
  9. 13
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/calendar/YearTest.java

@ -12,6 +12,10 @@
<name>vaadin-clubhelper</name>
<description>Vaadin Administation Frontend for Clubhelper.</description>
<prerequisites>
<maven>3</maven>
</prerequisites>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
@ -147,11 +151,6 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
@ -202,6 +201,11 @@
<artifactId>jasperreports</artifactId>
<version>6.7.0</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-functions</artifactId>
<version>6.7.0</version>
</dependency>
</dependencies>
<dependencyManagement>
@ -266,19 +270,6 @@
</execution>
<execution>
<id>default-jacoco-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>

@ -44,4 +44,8 @@ public class CalendarTaskRefresher {
log.debug("successfully stored {}", e);
}
}
public void setDao(ClubEventDao dao) {
this.dao = dao;
}
}

@ -39,8 +39,7 @@ public abstract class AbstractDaoImpl<T> implements IDao<T> {
@Override
public List<T> listAll() {
TypedQuery<T> query = em.createNamedQuery(
entityClass.getSimpleName() + ".findAll", entityClass);
TypedQuery<T> query = em.createNamedQuery(entityClass.getSimpleName() + ".findAll", entityClass);
return query.getResultList();
}

@ -1,16 +1,20 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao;
import javax.persistence.EntityManager;
import org.springframework.stereotype.Repository;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
@Repository
public class ClubEventDaoImpl extends AbstractDaoImpl<ClubEvent>
implements
ClubEventDao {
public class ClubEventDaoImpl extends AbstractDaoImpl<ClubEvent> implements ClubEventDao {
public ClubEventDaoImpl() {
super(ClubEvent.class);
}
public void setEntityManager(EntityManager em) {
this.em = em;
}
}

@ -1,6 +1,7 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components;
import java.io.InputStream;
import java.time.LocalDate;
import java.util.Map;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.calendar.Year;
@ -12,8 +13,11 @@ public class YearlyCalendarCreator extends CalendarCreator {
private Year year;
public YearlyCalendarCreator(int year) {
this.year = new Year(year);
public YearlyCalendarCreator(int year, Map<LocalDate, CharSequence> values) {
if (values == null) {
throw new NullPointerException("Calendar values must not be null!");
}
this.year = new Year(year, values);
}
@Override

@ -13,7 +13,8 @@ import java.util.Map;
public class WeeksOfMonth {
private static final List<DayOfWeek> ORDERED_WEEKDAY = Arrays.asList(DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY, DayOfWeek.SATURDAY, DayOfWeek.SUNDAY);
private static final List<DayOfWeek> ORDERED_WEEKDAY = Arrays.asList(DayOfWeek.MONDAY, DayOfWeek.TUESDAY,
DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY, DayOfWeek.SATURDAY, DayOfWeek.SUNDAY);
private final YearMonth yearMonth;
private final List<Map<DayOfWeek, Integer>> weeks;
@ -54,7 +55,9 @@ public class WeeksOfMonth {
}
/**
* Week in Month >=0 && < {@link #weekCount()} depending on day count and weekday order.
* Week in Month >=0 && < {@link #weekCount()} depending on day count and
* weekday order.
*
* @param index
* @return
*/
@ -64,11 +67,11 @@ public class WeeksOfMonth {
/**
* Count of week (parts) in this month.
*
* @return
*/
public int weekCount() {
return weeks.size();
}
}

@ -4,6 +4,7 @@ import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.format.TextStyle;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@ -13,12 +14,17 @@ public class Year {
private final LocalDate date;
private final Locale locale;
private final Map<Month, WeeksOfMonth> monthWeeks;
private final Map<LocalDate, CharSequence> values;
public Year(int year) {
this(year, Locale.getDefault());
this(year, Collections.emptyMap(), Locale.getDefault());
}
public Year(int year, Locale locale) {
public Year(int year, Map<LocalDate, CharSequence> values) {
this(year, values, Locale.getDefault());
}
public Year(int year, Map<LocalDate, CharSequence> values, Locale locale) {
if (year < 1900 || year > 2100) {
throw new IllegalArgumentException("Year value must be between 1900 and 2100");
}
@ -28,6 +34,10 @@ public class Year {
for (Month m : Month.values()) {
monthWeeks.put(m, new WeeksOfMonth(m, year));
}
this.values = values;
for (LocalDate d : values.keySet()) {
System.out.println(d + "\t" + values.get(d));
}
}
public int getYear() {
@ -47,14 +57,24 @@ public class Year {
* @return numeric value of the day of the month.
*/
public String getDay(Month month, short week, DayOfWeek dayOfWeek) {
Integer res = getDayOfMonth(month, week, dayOfWeek);
return res == null ? "" : res.toString();
}
public Integer getDayOfMonth(Month month, short week, DayOfWeek dayOfWeek) {
WeeksOfMonth weeksOfMonth = monthWeeks.get(month);
if (week > weeksOfMonth.weekCount()) {
return "";
return null;
}
Integer res = weeksOfMonth.getWeek(week - 1).get(dayOfWeek);
return res == null ? "" : res.toString();
return weeksOfMonth.getWeek(week - 1).get(dayOfWeek);
}
public CharSequence getContent(Month month, short week, DayOfWeek dayOfWeek) {
Integer res = getDayOfMonth(month, week, dayOfWeek);
LocalDate day = date.withMonth(month.getValue()).withDayOfMonth(res);
return values.get(day);
}
}

File diff suppressed because it is too large Load Diff

@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.DayOfWeek;
import java.time.Month;
import java.util.Collections;
import org.junit.jupiter.api.Test;
@ -12,21 +13,21 @@ class YearTest {
@Test()
void test18thCenturyEx() {
assertThrows(IllegalArgumentException.class, () -> new Year(1899));
assertThrows(IllegalArgumentException.class, () -> new Year(2101));
new Year(1900);
new Year(2100);
assertThrows(IllegalArgumentException.class, () -> new Year(1899, Collections.emptyMap()));
assertThrows(IllegalArgumentException.class, () -> new Year(2101, Collections.emptyMap()));
new Year(1900, Collections.emptyMap());
new Year(2100, Collections.emptyMap());
}
@Test
void testMondayIsFirst() {
Year y = new Year(2018);
Year y = new Year(2018, Collections.emptyMap());
assertEquals("1", y.getDay(Month.OCTOBER, (short) 1, DayOfWeek.MONDAY));
}
@Test
void testThursdayIsFirst() {
Year y = new Year(2018);
Year y = new Year(2018, Collections.emptyMap());
assertEquals("", y.getDay(Month.NOVEMBER, (short) 1, DayOfWeek.MONDAY));
}

Loading…
Cancel
Save