|
|
|
@ -11,16 +11,21 @@ import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
import com.vaadin.server.VaadinRequest; |
|
|
|
import com.vaadin.server.VaadinRequest; |
|
|
|
|
|
|
|
|
|
|
|
import de.kreth.clubhelperbackend.google.calendar.CalendarAdapter; |
|
|
|
import de.kreth.clubhelperbackend.google.calendar.CalendarAdapter; |
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; |
|
|
|
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component |
|
|
|
public class EventBusiness { |
|
|
|
public class EventBusiness { |
|
|
|
|
|
|
|
|
|
|
|
private final Logger log = LoggerFactory.getLogger(getClass()); |
|
|
|
private final Logger log = LoggerFactory.getLogger(getClass()); |
|
|
|
private final List<ClubEvent> cache = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
ClubEventDao dao; |
|
|
|
|
|
|
|
|
|
|
|
public List<ClubEvent> loadEvents(VaadinRequest request) { |
|
|
|
public List<ClubEvent> loadEvents(VaadinRequest request) { |
|
|
|
return loadEvents(request, false); |
|
|
|
return loadEvents(request, false); |
|
|
|
@ -28,17 +33,21 @@ public class EventBusiness { |
|
|
|
|
|
|
|
|
|
|
|
public synchronized List<ClubEvent> loadEvents(VaadinRequest request, |
|
|
|
public synchronized List<ClubEvent> loadEvents(VaadinRequest request, |
|
|
|
boolean forceRefresh) { |
|
|
|
boolean forceRefresh) { |
|
|
|
if (cache.isEmpty() == false && forceRefresh == false) { |
|
|
|
|
|
|
|
log.trace("Returning cached events: {}", cache); |
|
|
|
if (forceRefresh == false) { |
|
|
|
return Collections.unmodifiableList(cache); |
|
|
|
List<ClubEvent> list = dao.list(); |
|
|
|
|
|
|
|
log.trace("Returning events from database: {}"); |
|
|
|
|
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.debug( |
|
|
|
log.debug( |
|
|
|
"Loading events from Google Calendar, cache size was: {}, forceRefresh={}", |
|
|
|
"Loading events from Google Calendar, forceRefresh={}", |
|
|
|
cache.size(), forceRefresh); |
|
|
|
forceRefresh); |
|
|
|
cache.clear(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BufferedWriter out = null; |
|
|
|
BufferedWriter out = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ClubEvent> list = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
if (forceRefresh) { |
|
|
|
if (forceRefresh) { |
|
|
|
File f = new File("google_events.json"); |
|
|
|
File f = new File("google_events.json"); |
|
|
|
@ -58,7 +67,7 @@ public class EventBusiness { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ("cancelled".equals(ev.getStatus()) == false) { |
|
|
|
if ("cancelled".equals(ev.getStatus()) == false) { |
|
|
|
cache.add(ClubEvent.parse(ev)); |
|
|
|
list.add(ClubEvent.parse(ev)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
log.debug("Cancelled: {}", ev.getSummary()); |
|
|
|
log.debug("Cancelled: {}", ev.getSummary()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -75,6 +84,6 @@ public class EventBusiness { |
|
|
|
log.error("Error writing File", e); |
|
|
|
log.error("Error writing File", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return Collections.unmodifiableList(cache); |
|
|
|
return Collections.unmodifiableList(list); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|