parent
eaf55dc452
commit
17812be1f7
@ -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 |
eclipse.preferences.version=1 |
||||||
|
|||||||
@ -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<ClubEvent> events = business.loadEvents(null, true); |
||||||
|
for (ClubEvent e : events) { |
||||||
|
log.trace("try storing {}", e); |
||||||
|
dao.save(e); |
||||||
|
log.debug("successfully stored {}", e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -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<ZonedDateTime, Date> { |
||||||
|
|
||||||
|
@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())); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
/** |
||||||
|
* Tasks running on Server side only. |
||||||
|
* |
||||||
|
* @author markus |
||||||
|
* |
||||||
|
*/ |
||||||
|
package de.kreth.vaadin.clubhelper.vaadinclubhelper.business; |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao; |
||||||
|
|
||||||
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; |
||||||
|
|
||||||
|
public interface ClubEventDao extends IDao<ClubEvent> { |
||||||
|
|
||||||
|
} |
||||||
@ -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<ClubEvent> |
||||||
|
implements |
||||||
|
ClubEventDao { |
||||||
|
|
||||||
|
public ClubEventDaoImpl() { |
||||||
|
super(ClubEvent.class); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" |
||||||
|
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> |
||||||
|
<hibernate-mapping> |
||||||
|
<class |
||||||
|
name="de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent" table="ClubEvent"> |
||||||
|
<id column="id" name="id" type="string"/> |
||||||
|
<property column="caption" generated="never" lazy="false" |
||||||
|
name="caption" type="string"/> |
||||||
|
<property column="description" generated="never" lazy="false" |
||||||
|
name="description" type="string"/> |
||||||
|
<property column="iCalUID" generated="never" lazy="false" |
||||||
|
name="iCalUID" type="string"/> |
||||||
|
<property column="location" generated="never" lazy="false" |
||||||
|
name="location" type="string"/> |
||||||
|
<property column="start" generated="never" lazy="false" name="start" /> |
||||||
|
<property column="end" generated="never" lazy="false" name="end" /> |
||||||
|
<property column="allDay" generated="never" lazy="false" name="allDay" type="true_false"/> |
||||||
|
<property column="organizerDisplayName" generated="never" lazy="false" |
||||||
|
name="organizerDisplayName" type="string"/> |
||||||
|
</class> |
||||||
|
</hibernate-mapping> |
||||||
@ -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`)); |
||||||
@ -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(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,5 @@ |
|||||||
|
/** |
||||||
|
* @author markus |
||||||
|
* |
||||||
|
*/ |
||||||
|
package de.kreth.vaadin.clubhelper.vaadinclubhelper.data; |
||||||
Loading…
Reference in new issue