diff --git a/.project b/.project
index 2e27278..6f562c7 100644
--- a/.project
+++ b/.project
@@ -36,12 +36,12 @@
- org.eclipse.m2e.core.maven2Builder
+ org.springframework.ide.eclipse.core.springbuilder
- org.springframework.ide.eclipse.core.springbuilder
+ org.eclipse.m2e.core.maven2Builder
diff --git a/.settings/com.vaadin.integration.eclipse.prefs b/.settings/com.vaadin.integration.eclipse.prefs
index bb18c71..7bed5f9 100644
--- a/.settings/com.vaadin.integration.eclipse.prefs
+++ b/.settings/com.vaadin.integration.eclipse.prefs
@@ -1,2 +1,2 @@
-com.vaadin.integration.eclipse.mavenLatestVersionsUpgrade=["8.4.5"]
+com.vaadin.integration.eclipse.mavenLatestVersionsUpgrade=["8.4.5","8.5.0"]
eclipse.preferences.version=1
diff --git a/pom.xml b/pom.xml
index c00c9d7..3b7825b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,16 +59,6 @@
mysql-connector-java
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
- org.springframework.security
- spring-security-test
- test
-
org.vaadin.blackbluegl
calendar-component
@@ -100,6 +90,31 @@
google-oauth-client-jetty
${google-api-version}
+
+ org.slf4j
+ slf4j-api
+
+
+ ch.qos.logback
+ logback-classic
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.security
+ spring-security-test
+ test
+
+
+ com.h2database
+ h2
+ 1.4.197
+ test
+
@@ -120,7 +135,7 @@
org.springframework.boot
spring-boot-maven-plugin
-
+
com.vaadin
vaadin-maven-plugin
diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/VaadinClubhelperApplication.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/VaadinClubhelperApplication.java
index eb0b9ab..b70578a 100644
--- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/VaadinClubhelperApplication.java
+++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/VaadinClubhelperApplication.java
@@ -2,8 +2,10 @@ package de.kreth.vaadin.clubhelper.vaadinclubhelper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
+@EnableScheduling
public class VaadinClubhelperApplication {
public static void main(String[] args) {
diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/CalendarTaskRefresher.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/CalendarTaskRefresher.java
new file mode 100644
index 0000000..afd4924
--- /dev/null
+++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/CalendarTaskRefresher.java
@@ -0,0 +1,35 @@
+package de.kreth.vaadin.clubhelper.vaadinclubhelper.business;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.ClubEventDao;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.EventBusiness;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
+
+@Component
+public class CalendarTaskRefresher {
+
+ private static final long RATE = 1000 * 60 * 10;
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Autowired
+ ClubEventDao dao;
+
+ EventBusiness business = new EventBusiness();
+
+ @Scheduled(fixedDelay = RATE)
+ public void synchronizeCalendarTasks() {
+ List events = business.loadEvents(null, true);
+ for (ClubEvent e : events) {
+ log.trace("try storing {}", e);
+ dao.save(e);
+ log.debug("successfully stored {}", e);
+ }
+ }
+}
diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/ZonedDateTimeAttributeConverter.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/ZonedDateTimeAttributeConverter.java
new file mode 100644
index 0000000..a3d98d7
--- /dev/null
+++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/ZonedDateTimeAttributeConverter.java
@@ -0,0 +1,26 @@
+package de.kreth.vaadin.clubhelper.vaadinclubhelper.business;
+
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.util.Date;
+
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+
+@Converter(autoApply = true)
+public class ZonedDateTimeAttributeConverter
+ implements
+ AttributeConverter {
+
+ @Override
+ public Date convertToDatabaseColumn(ZonedDateTime attribute) {
+ return Date.from(attribute.toInstant());
+ }
+
+ @Override
+ public ZonedDateTime convertToEntityAttribute(Date dbData) {
+ return ZonedDateTime.ofInstant(dbData.toInstant(),
+ ZoneId.from(dbData.toInstant()));
+ }
+
+}
diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/package-info.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/package-info.java
new file mode 100644
index 0000000..60c29bc
--- /dev/null
+++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/package-info.java
@@ -0,0 +1,7 @@
+/**
+ * Tasks running on Server side only.
+ *
+ * @author markus
+ *
+ */
+package de.kreth.vaadin.clubhelper.vaadinclubhelper.business;
\ No newline at end of file
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 c4ece34..99a4a57 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
@@ -6,6 +6,7 @@ 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 {
@@ -20,8 +21,16 @@ public abstract class AbstractDaoImpl implements IDao {
}
@Override
+ @Transactional
public void save(T obj) {
+ // EntityTransaction tx = em.getTransaction();
+ // tx.begin();
+ // try {
em.persist(obj);
+ // tx.commit();
+ // } catch (Exception e) {
+ // tx.rollback();
+ // }
}
@Override
diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDao.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDao.java
new file mode 100644
index 0000000..9ea3faa
--- /dev/null
+++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDao.java
@@ -0,0 +1,7 @@
+package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao;
+
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
+
+public interface ClubEventDao extends IDao {
+
+}
diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDaoImpl.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDaoImpl.java
new file mode 100644
index 0000000..66c4370
--- /dev/null
+++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDaoImpl.java
@@ -0,0 +1,16 @@
+package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao;
+
+import org.springframework.stereotype.Repository;
+
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
+
+@Repository
+public class ClubEventDaoImpl extends AbstractDaoImpl
+ implements
+ ClubEventDao {
+
+ public ClubEventDaoImpl() {
+ super(ClubEvent.class);
+ }
+
+}
diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/EventBusiness.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/EventBusiness.java
index 45934a1..955e87d 100644
--- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/EventBusiness.java
+++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/EventBusiness.java
@@ -1,45 +1,79 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.vaadin.server.VaadinRequest;
import de.kreth.clubhelperbackend.google.calendar.CalendarAdapter;
-import de.kreth.clubhelperbackend.google.calendar.ClubEvent;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
public class EventBusiness {
+ private final Logger log = LoggerFactory.getLogger(getClass());
private final List cache = new ArrayList<>();
public List loadEvents(VaadinRequest request) {
- if (cache.isEmpty() == false) {
+ return loadEvents(request, false);
+ }
+
+ public synchronized List loadEvents(VaadinRequest request,
+ boolean forceRefresh) {
+ if (cache.isEmpty() == false && forceRefresh == false) {
+ log.trace("Returning cached events: {}", cache);
return Collections.unmodifiableList(cache);
}
+ log.debug(
+ "Loading events from Google Calendar, cache size was: {}, forceRefresh={}",
+ cache.size(), forceRefresh);
cache.clear();
+ BufferedWriter out = null;
try {
+ if (forceRefresh) {
+ File f = new File("google_events.json");
+ f.delete();
+ out = new BufferedWriter(new FileWriter(f));
- // String remoteHost = request.getRemoteHost();
+ }
String remoteHost = "localhost";
CalendarAdapter adapter = new CalendarAdapter();
List events = adapter
.getAllEvents(remoteHost);
for (com.google.api.services.calendar.model.Event ev : events) {
+ if (out != null) {
+ out.write(ev.toPrettyString());
+ out.newLine();
+ }
+
if ("cancelled".equals(ev.getStatus()) == false) {
cache.add(ClubEvent.parse(ev));
} else {
- System.out.println("Cancelled: " + ev.getSummary());
+ log.debug("Cancelled: {}", ev.getSummary());
}
}
} catch (GeneralSecurityException | IOException
| InterruptedException e) {
- e.printStackTrace();
+ log.error("Error loading events from google.", e);
+ }
+
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ log.error("Error writing File", e);
+ }
}
return Collections.unmodifiableList(cache);
}
diff --git a/src/main/java/de/kreth/clubhelperbackend/google/calendar/ClubEvent.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/ClubEvent.java
similarity index 60%
rename from src/main/java/de/kreth/clubhelperbackend/google/calendar/ClubEvent.java
rename to src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/ClubEvent.java
index 71377e6..4bac52f 100644
--- a/src/main/java/de/kreth/clubhelperbackend/google/calendar/ClubEvent.java
+++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/ClubEvent.java
@@ -1,4 +1,4 @@
-package de.kreth.clubhelperbackend.google.calendar;
+package de.kreth.vaadin.clubhelper.vaadinclubhelper.data;
import java.time.Instant;
import java.time.ZoneId;
@@ -7,6 +7,8 @@ import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
+import javax.persistence.Transient;
+
import org.vaadin.addon.calendar.item.BasicItem;
import com.google.api.services.calendar.model.Event;
@@ -16,20 +18,86 @@ public class ClubEvent extends BasicItem {
private static final long serialVersionUID = -3600971939167437577L;
private String location;
+ private String iCalUID;
+
+ private String id;
+ private String organizerDisplayName;
ClubEvent() {
}
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public void setiCalUID(String iCalUID) {
+ this.iCalUID = iCalUID;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setOrganizerDisplayName(String organizerDisplayName) {
+ this.organizerDisplayName = organizerDisplayName;
+ }
+
+ public String getCaption() {
+ return super.getCaption();
+ }
+
+ @Override
+ public String getDescription() {
+
+ return super.getDescription();
+ }
+
+ @Override
+ public ZonedDateTime getEnd() {
+ return super.getEnd();
+ }
+
+ @Override
+ public ZonedDateTime getStart() {
+ return super.getStart();
+ }
+
+ @Override
+ public boolean isAllDay() {
+ return super.isAllDay();
+ }
+
public String getLocation() {
return location;
}
- @Override
- public String toString() {
+ public String getId() {
+ return id;
+ }
+
+ public String getiCalUID() {
+ return iCalUID;
+ }
+
+ public String getOrganizerDisplayName() {
+ return organizerDisplayName;
+ }
+
+ @Transient
+ public String toDisplayString() {
return "ClubEvent [Caption=" + getCaption() + ", Start=" + getStart()
+ ", location=" + location + "]";
}
+ @Override
+ public String toString() {
+ return "ClubEvent [id=" + id + ", iCalUID=" + iCalUID + ", location="
+ + location + ", organizerDisplayName=" + organizerDisplayName
+ + ", getCaption()=" + getCaption() + ", getDescription()="
+ + getDescription() + ", getEnd()=" + getEnd() + ", getStart()="
+ + getStart() + ", isAllDay()=" + isAllDay() + "]";
+ }
+
public static ClubEvent parse(Event ev) {
ClubEvent clubEvent = new ClubEvent();
clubEvent.setCaption(ev.getSummary());
@@ -41,6 +109,10 @@ public class ClubEvent extends BasicItem {
clubEvent.setEnd(toZoned(adjustExcludedEndDate(ev)));
clubEvent.setDescription(ev.getDescription());
clubEvent.location = ev.getLocation();
+ clubEvent.iCalUID = ev.getICalUID();
+ clubEvent.id = ev.getId();
+ clubEvent.organizerDisplayName = ev.getOrganizer().getDisplayName();
+ clubEvent.setAllDay(startIsDateOnly(ev));
return clubEvent;
}
diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java
index 6d1b657..55f1c11 100644
--- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java
+++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java
@@ -4,6 +4,8 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.vaadin.addon.calendar.ui.CalendarComponentEvents;
@@ -11,13 +13,12 @@ import com.vaadin.annotations.Theme;
import com.vaadin.server.VaadinRequest;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.HorizontalLayout;
-import com.vaadin.ui.Notification;
import com.vaadin.ui.UI;
-import de.kreth.clubhelperbackend.google.calendar.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.EventBusiness;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.CalendarComponent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonGrid;
@@ -27,6 +28,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonGrid;
public class MainUi extends UI {
private static final long serialVersionUID = 7581634188909841919L;
+ private static final Logger LOGGER = LoggerFactory.getLogger(MainUi.class);
@Autowired
PersonDao personDao;
@@ -43,11 +45,12 @@ public class MainUi extends UI {
@Override
protected void init(VaadinRequest request) {
+ LOGGER.debug("Starting Vaadin UI with " + getClass().getName());
+
List persons = personDao.list();
personGrid = new PersonGrid(groupDao);
personGrid.setItems(persons);
personGrid.setCaption("Personen");
- personGrid.setVisible(false);
personGrid.onClosedFunction(() -> detailClosed());
this.calendar = new CalendarComponent();
@@ -55,7 +58,7 @@ public class MainUi extends UI {
contentLayout = new HorizontalLayout();
contentLayout.setSizeFull();
- contentLayout.addComponents(calendar, personGrid);
+ contentLayout.addComponents(calendar);
contentLayout.setExpandRatio(calendar, 1.0f);
setContent(contentLayout);
@@ -66,14 +69,15 @@ public class MainUi extends UI {
EventBusiness business = new EventBusiness();
List events = business.loadEvents(request);
+ LOGGER.info("Loaded events: {}", events);
calendar.setItems(events);
- System.out.println("Updated data: " + events);
});
exec.shutdown();
}
private void detailClosed() {
- personGrid.setVisible(false);
+ LOGGER.debug("Closing detail view.");
+ contentLayout.removeComponent(personGrid);
calendar.setSizeFull();
contentLayout.setExpandRatio(calendar, 1.0f);
}
@@ -84,14 +88,15 @@ public class MainUi extends UI {
}
private void showDetails(ClubEvent ev) {
- personGrid.setVisible(true);
- personGrid.setCaption(ev.getCaption());
- personGrid.setTitle(ev.getCaption());
+ LOGGER.debug("Opening detail view for {}", ev);
contentLayout.setExpandRatio(calendar, .5f);
calendar.setWidth("50%");
- Notification.show("" + ev);
+ contentLayout.addComponent(personGrid);
+ personGrid.setCaption(ev.getCaption());
+ personGrid.setTitle(ev.getCaption());
+
}
}
diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java
index e0c2329..0dcee95 100644
--- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java
+++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java
@@ -20,7 +20,7 @@ import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
-import de.kreth.clubhelperbackend.google.calendar.ClubEvent;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
public class CalendarComponent extends CustomComponent {
diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/EventGrid.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/EventGrid.java
index 2160513..57c7353 100644
--- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/EventGrid.java
+++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/EventGrid.java
@@ -5,7 +5,7 @@ import java.time.format.FormatStyle;
import com.vaadin.ui.Grid;
-import de.kreth.clubhelperbackend.google.calendar.ClubEvent;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
public class EventGrid extends Grid {
diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java
index 397358d..6b3ea36 100644
--- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java
+++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java
@@ -6,6 +6,9 @@ import java.util.Collection;
import java.util.List;
import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.vaadin.data.HasValue.ValueChangeEvent;
import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.event.selection.SingleSelectionEvent;
@@ -27,6 +30,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Persongroup;
public class PersonGrid extends CustomComponent {
private static final long serialVersionUID = -8148097982839343673L;
+ private final Logger log = LoggerFactory.getLogger(getClass());
private final DateFormat birthFormat = DateFormat
.getDateInstance(DateFormat.MEDIUM);
@@ -55,7 +59,9 @@ public class PersonGrid extends CustomComponent {
comboGroups.setEmptySelectionCaption("Alle");
comboGroups.setItemCaptionGenerator(GroupDef::getName);
comboGroups.addSelectionListener(ev -> onGroupSelected(ev));
- comboGroups.setItems(groupDao.list());
+ List items = groupDao.list();
+ comboGroups.setItems(items);
+ log.info("Loaded Groups: {}", items);
HorizontalLayout filters = new HorizontalLayout();
filters.addComponents(checkIncluded, comboGroups);
diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml
index 056fb7e..3786a5e 100644
--- a/src/main/resources/hibernate.cfg.xml
+++ b/src/main/resources/hibernate.cfg.xml
@@ -17,5 +17,6 @@
org.hibernate.context.internal.ThreadLocalSessionContext
+
diff --git a/src/main/resources/schema/ClubEvent.hbm.xml b/src/main/resources/schema/ClubEvent.hbm.xml
new file mode 100644
index 0000000..94ee2c2
--- /dev/null
+++ b/src/main/resources/schema/ClubEvent.hbm.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/schema/version0.sql b/src/main/resources/schema/version0.sql
new file mode 100644
index 0000000..bdc2f65
--- /dev/null
+++ b/src/main/resources/schema/version0.sql
@@ -0,0 +1,11 @@
+CREATE TABLE `clubhelper`.`ClubEvent` (
+ `id` VARCHAR(250) NOT NULL,
+ `location` VARCHAR(255) NULL,
+ `iCalUID` VARCHAR(150) NULL,
+ `organizerDisplayName` VARCHAR(150) NULL,
+ `caption` VARCHAR(150) NULL,
+ `description` VARCHAR(500) NULL,
+ `start` DATETIME NULL,
+ `end` DATETIME NULL,
+ `allDay` SMALLINT(1) NULL,
+ PRIMARY KEY (`id`));
diff --git a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/AbstractDatabaseTest.java b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/AbstractDatabaseTest.java
new file mode 100644
index 0000000..e638f58
--- /dev/null
+++ b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/AbstractDatabaseTest.java
@@ -0,0 +1,57 @@
+package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.junit.Before;
+
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Adress;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Attendance;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Contact;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.DeletedEntry;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Persongroup;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Relative;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Startpaesse;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.StartpassStartrechte;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Version;
+
+public abstract class AbstractDatabaseTest {
+
+ protected SessionFactory sessionFactory;
+ protected Session session;
+
+ @Before
+ public void setUp() throws Exception {
+
+ // setup the session factory
+ Configuration configuration = new Configuration();
+ configuration.addAnnotatedClass(Adress.class);
+ configuration.addAnnotatedClass(Attendance.class);
+ configuration.addAnnotatedClass(Contact.class);
+ configuration.addAnnotatedClass(DeletedEntry.class);
+ configuration.addAnnotatedClass(GroupDef.class);
+ configuration.addAnnotatedClass(Person.class);
+ configuration.addAnnotatedClass(Persongroup.class);
+ configuration.addAnnotatedClass(Relative.class);
+ configuration.addAnnotatedClass(Startpaesse.class);
+ configuration.addAnnotatedClass(StartpassStartrechte.class);
+ configuration.addAnnotatedClass(Version.class);
+ configuration.addInputStream(
+ getClass().getResourceAsStream("/schema/ClubEvent.hbm.xml"));
+
+ configuration.setProperty("hibernate.dialect",
+ "org.hibernate.dialect.H2Dialect");
+ configuration.setProperty("hibernate.connection.driver_class",
+ "org.h2.Driver");
+ configuration.setProperty("hibernate.connection.url",
+ "jdbc:h2:mem:test");
+ configuration.setProperty("hibernate.hbm2ddl.auto", "create");
+
+ sessionFactory = configuration.buildSessionFactory();
+ session = sessionFactory.openSession();
+
+ }
+
+}
diff --git a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDaoImplTest.java b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDaoImplTest.java
new file mode 100644
index 0000000..38bc3ad
--- /dev/null
+++ b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDaoImplTest.java
@@ -0,0 +1,56 @@
+package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao;
+
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.util.Date;
+
+import org.hibernate.Transaction;
+import org.junit.Test;
+
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEventBuilder;
+import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
+
+public class ClubEventDaoImplTest extends AbstractDatabaseTest {
+
+ @Test
+ public void testInsertPerson() {
+ Person p = new Person();
+ p.setPrename("prename");
+ p.setSurname("surname");
+ p.setBirth(new Date());
+ Transaction tx = session.beginTransaction();
+ session.save(p);
+ tx.commit();
+ }
+
+ @Test
+ public void testInsertEvent() {
+ ClubEvent ev = creteEvent();
+
+ Transaction tx = session.beginTransaction();
+ session.save(ev);
+ tx.commit();
+ }
+
+ @Test
+ public void testSelectEvents() {
+ ClubEvent ev = creteEvent();
+
+ Transaction tx = session.beginTransaction();
+ session.save(ev);
+ tx.commit();
+ }
+
+ private ClubEvent creteEvent() {
+ ClubEvent ev = ClubEventBuilder.builder().withId("id").withAllDay(true)
+ .withCaption("caption").withDescription("description")
+ .withStart(ZonedDateTime.of(2018, 8, 13, 0, 0, 0, 0,
+ ZoneId.systemDefault()))
+ .withEnd(ZonedDateTime.of(2018, 8, 13, 0, 0, 0, 0,
+ ZoneId.systemDefault()))
+ .withiCalUID("iCalUID")
+ .withOrganizerDisplayName("organizerDisplayName").build();
+ return ev;
+ }
+}
diff --git a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/ClubEventBuilder.java b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/ClubEventBuilder.java
new file mode 100644
index 0000000..10ba5a6
--- /dev/null
+++ b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/ClubEventBuilder.java
@@ -0,0 +1,73 @@
+package de.kreth.vaadin.clubhelper.vaadinclubhelper.data;
+
+import java.time.ZonedDateTime;
+
+public class ClubEventBuilder {
+
+ private final ClubEvent current = new ClubEvent();
+
+ public static ClubEvent createEmpty() {
+ return new ClubEvent();
+ }
+
+ public static ClubEventBuilder builder() {
+ ClubEventBuilder bld = new ClubEventBuilder();
+ return bld;
+ }
+
+ public ClubEventBuilder withCaption(String caption) {
+ current.setCaption(caption);
+ return this;
+ }
+
+ public ClubEventBuilder withLocation(String location) {
+ current.setLocation(location);
+ return this;
+ }
+
+ public ClubEventBuilder withiCalUID(String iCalUID) {
+ current.setiCalUID(iCalUID);
+ return this;
+
+ }
+
+ public ClubEventBuilder withId(String id) {
+ current.setId(id);
+ return this;
+ }
+
+ public ClubEventBuilder withOrganizerDisplayName(
+ String organizerDisplayName) {
+ current.setOrganizerDisplayName(organizerDisplayName);
+ return this;
+ }
+
+ public ClubEventBuilder withDescription(String description) {
+ current.setDescription(description);
+ return this;
+ }
+
+ public ClubEventBuilder withEnd(ZonedDateTime end) {
+ current.setEnd(end);
+ return this;
+ }
+
+ public ClubEventBuilder withStart(ZonedDateTime start) {
+ current.setStart(start);
+ return this;
+ }
+
+ public ClubEventBuilder withStyleName(String styleName) {
+ current.setStyleName(styleName);
+ return this;
+ }
+
+ public ClubEventBuilder withAllDay(boolean isAllDay) {
+ current.setAllDay(isAllDay);
+ return this;
+ }
+
+ public ClubEvent build() {
+ return current;
+ }
+}
diff --git a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/package-info.java b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/package-info.java
new file mode 100644
index 0000000..0a9c639
--- /dev/null
+++ b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/package-info.java
@@ -0,0 +1,5 @@
+/**
+ * @author markus
+ *
+ */
+package de.kreth.vaadin.clubhelper.vaadinclubhelper.data;
\ No newline at end of file