From 66ab84454cc2ce907a719c77c9941de157f2e7e8 Mon Sep 17 00:00:00 2001 From: Markus Kreth Date: Mon, 7 Jan 2019 01:57:01 +0100 Subject: [PATCH] Removed Google Dependency --- pom.xml | 5 -- .../vaadinclubhelper/data/ClubEvent.java | 57 ------------------- .../ui/components/PersonFilter.java | 13 +++++ .../ui/components/PersonGrid.java | 23 ++++++-- .../business/EventBusinessTest.java | 8 --- .../ui/tests/TestConfiguration.java | 9 --- 6 files changed, 30 insertions(+), 85 deletions(-) diff --git a/pom.xml b/pom.xml index 04184b5..07f8404 100644 --- a/pom.xml +++ b/pom.xml @@ -216,11 +216,6 @@ jasperreports-functions 6.7.0 - - de.kreth.googleconnect - GoogleConnectors - 0.0.1-SNAPSHOT - diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/ClubEvent.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/ClubEvent.java index 4a04406..cc5f7dd 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/ClubEvent.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/ClubEvent.java @@ -3,9 +3,7 @@ package de.kreth.vaadin.clubhelper.vaadinclubhelper.data; import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; -import java.util.Calendar; import java.util.Date; -import java.util.GregorianCalendar; import java.util.HashSet; import java.util.Set; @@ -13,9 +11,6 @@ import javax.persistence.Transient; import org.vaadin.addon.calendar.item.BasicItem; -import com.google.api.services.calendar.model.Event; -import com.google.api.services.calendar.model.EventDateTime; - public class ClubEvent extends BasicItem { private static final long serialVersionUID = -3600971939167437577L; @@ -123,25 +118,6 @@ public class ClubEvent extends BasicItem { + ", getEnd()=" + getEnd() + ", getStart()=" + getStart() + ", isAllDay()=" + isAllDay() + "]"; } - public static ClubEvent parse(Event ev) { - ClubEvent clubEvent = new ClubEvent(); - clubEvent.setCaption(ev.getSummary()); - clubEvent.setStart(toZoned(parse(ev.getStart()))); - - if (clubEvent.getStart() == null) { - clubEvent.setStart(toZoned(parse(ev.getOriginalStartTime()))); - } - 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; - } - @Override public int hashCode() { final int prime = 31; @@ -198,37 +174,4 @@ public class ClubEvent extends BasicItem { } } - public static Date parse(EventDateTime date) { - if (date != null) { - if (date.getDateTime() != null) { - return new Date(date.getDateTime().getValue()); - } else if (date.getDate() != null) { - return new Date(date.getDate().getValue()); - } - } - return null; - } - - public static Date adjustExcludedEndDate(com.google.api.services.calendar.model.Event e) { - if (e.isEndTimeUnspecified() == false) { - EventDateTime end = e.getEnd(); - GregorianCalendar calendar = new GregorianCalendar(); - calendar.setTimeInMillis(end.getDate() != null ? end.getDate().getValue() : end.getDateTime().getValue()); - if (startIsDateOnly(e)) { - calendar.add(Calendar.DAY_OF_MONTH, -1); - } - return calendar.getTime(); - } - return null; - } - - public static boolean startIsDateOnly(com.google.api.services.calendar.model.Event e) { - - EventDateTime start = e.getStart(); - if (start == null) { - start = e.getOriginalStartTime(); - } - return (start.getDate() != null || (start.getDateTime() != null && start.getDateTime().isDateOnly())); - } - } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonFilter.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonFilter.java index c2e4a5c..59a036c 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonFilter.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonFilter.java @@ -14,6 +14,8 @@ import com.vaadin.server.SerializablePredicate; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.events.DataUpdatedEvent; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.events.DefaultDataUpdateHandler; public class PersonFilter implements SerializablePredicate, DataProviderListener { @@ -22,10 +24,12 @@ public class PersonFilter implements SerializablePredicate, DataProvider private Set selectedGroups = null; private final List publishedList; private final PersonDao personDao; + private final DefaultDataUpdateHandler updateHandler; public PersonFilter(PersonDao personDao) { this.personDao = personDao; publishedList = new ArrayList<>(personDao.listAll()); + this.updateHandler = new DefaultDataUpdateHandler(); } @Override @@ -94,6 +98,15 @@ public class PersonFilter implements SerializablePredicate, DataProvider public void onDataChange(DataChangeEvent event) { publishedList.clear(); publishedList.addAll(personDao.listAll().stream().filter(this).collect(Collectors.toList())); + updateHandler.fireUpdateEvent(); + } + + public void add(DataUpdatedEvent ev) { + updateHandler.add(ev); + } + + public boolean remove(DataUpdatedEvent o) { + return updateHandler.remove(o); } } 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 0135971..75e19a9 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 @@ -54,6 +54,7 @@ public class PersonGrid extends CustomComponent { private Set groupMemberFilter; private List allGroups; private PersonFilter filter; + private ClubEvent currentEvent; public PersonGrid(GroupDao groupDao, PersonDao personDao) { @@ -81,6 +82,9 @@ public class PersonGrid extends CustomComponent { filters.addComponents(checkIncluded, comboGroups); filter = new PersonFilter(personDao); + filter.add(() -> { + setEvent(currentEvent); + }); dataProvider = DataProvider.ofCollection(filter.asCollection()); dataProvider.addDataProviderListener(filter); @@ -196,20 +200,27 @@ public class PersonGrid extends CustomComponent { } public void setEvent(ClubEvent ev) { + if (ev != null) { setCaption(ev.getCaption()); setTitle(ev.getCaption()); - Set persons = ev.getPersons(); - if (persons != null) { - selectItems(persons.toArray(new Person[0])); - } else { - selectItems(new Person[0]); - } + updateSelection(ev); } else { setCaption(""); setTitle(""); + selectItems(new Person[0]); + } + this.currentEvent = ev; + } + + public void updateSelection(ClubEvent ev) { + Set persons = ev.getPersons(); + if (persons != null) { + selectItems(persons.toArray(new Person[0])); + } else { + selectItems(new Person[0]); } } diff --git a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessTest.java b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessTest.java index 4e644a2..1bb2310 100644 --- a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessTest.java +++ b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessTest.java @@ -3,8 +3,6 @@ package de.kreth.vaadin.clubhelper.vaadinclubhelper.business; import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.io.IOException; -import java.security.GeneralSecurityException; import java.time.LocalDate; import java.util.ArrayList; import java.util.HashSet; @@ -26,7 +24,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit.jupiter.SpringExtension; -import de.kreth.googleconnectors.calendar.CalendarAdapter; import de.kreth.vaadin.clubhelper.HibernateHolder; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.AbstractDatabaseTest; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.AbstractDatabaseTest.DB_TYPE; @@ -77,11 +74,6 @@ class EventBusinessTest { return new ClubEventDaoImpl(); } - @Bean - public CalendarAdapter getCalendarAdapter() throws GeneralSecurityException, IOException { - return new CalendarAdapter(); - } - @Bean public EventBusiness getEventBusiness() { return new EventBusiness(); diff --git a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/TestConfiguration.java b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/TestConfiguration.java index 29a5b0e..6ebd7ae 100644 --- a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/TestConfiguration.java +++ b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/TestConfiguration.java @@ -1,15 +1,11 @@ package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests; -import java.io.IOException; -import java.security.GeneralSecurityException; - import javax.persistence.EntityManager; import org.hibernate.SessionFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import de.kreth.googleconnectors.calendar.CalendarAdapter; import de.kreth.vaadin.clubhelper.HibernateHolder; @Configuration @@ -26,9 +22,4 @@ public class TestConfiguration { } - @Bean - public CalendarAdapter getCalendarAdapter() throws GeneralSecurityException, IOException { - return new CalendarAdapter(); - } - }