use of com.google.api.services.calendar.model.EventDateTime in project openhab1-addons by openhab.
the class GCalPersistenceService method store.
/**
* Creates a new Google Calendar Entry for each <code>item</code> and adds
* it to the processing queue. The entries' title will either be the items
* name or <code>alias</code> if it is <code>!= null</code>.
*
* The new Calendar Entry will contain a single command to be executed e.g.<br>
* <p>
* <code>send <item.name> <item.state></code>
* </p>
*
* @param item the item which state should be persisted.
* @param alias the alias under which the item should be persisted.
*/
@Override
public void store(final Item item, final String alias) {
if (initialized) {
String newAlias = alias != null ? alias : item.getName();
Event event = new Event();
event.setSummary("[PresenceSimulation] " + newAlias);
event.setDescription(String.format(executeScript, item.getName(), item.getState().toString()));
Date now = new Date();
Date startDate = new Date(now.getTime() + 3600000L * 24 * offset);
Date endDate = startDate;
DateTime start = new DateTime(startDate);
event.setStart(new EventDateTime().setDateTime(start));
DateTime end = new DateTime(endDate);
event.setEnd(new EventDateTime().setDateTime(end));
entries.offer(event);
logger.trace("added new entry '{}' for item '{}' to upload queue", event.getSummary(), item.getName());
} else {
logger.debug("GCal PresenceSimulation Service isn't initialized properly! No entries will be uploaded to your Google Calendar");
}
}
use of com.google.api.services.calendar.model.EventDateTime in project openhab1-addons by openhab.
the class GCalEventDownloader method createTriggerAndSchedule.
/**
* Creates a set quartz-triggers for <code>job</code>. For each {@link When}
* object of <code>event</code> a new trigger is created. That is the case
* in recurring events where gcal creates one event (with one unique IcalUID)
* and a set of {@link When}-object for each occurrence.
*
* @param job the {@link Job} to create triggers for
* @param event the {@link CalendarEventEntry} to read the {@link When}-objects
* from
* @param modifiedByEvent defines the name of an event which modifies the
* schedule of the new Trigger
* @param isStartEvent indicator to identify whether this trigger will be
* triggering a start or an end command.
*
* @throws SchedulerException if there is an internal Scheduler error.
*/
protected boolean createTriggerAndSchedule(JobDetail job, Event event, String modifiedByEvent, boolean isStartEvent) {
boolean triggersCreated = false;
if (job == null) {
logger.debug("job is null -> no triggers are created");
return false;
}
String jobIdentity = event.getICalUID() + (isStartEvent ? "_start" : "_end");
EventDateTime date = isStartEvent ? event.getStart() : event.getEnd();
long dateValue = date.getDateTime().getValue();
/*
* TODO: TEE: do only create a new trigger when the start/endtime
* lies in the future. This exclusion is necessary because the SimpleTrigger
* triggers a job even if the startTime lies in the past. If somebody
* knows the way to let quartz ignore such triggers this exclusion
* can be omitted.
*/
if (dateValue >= (new Date()).getTime()) {
Trigger trigger;
if (StringUtils.isBlank(modifiedByEvent)) {
trigger = newTrigger().forJob(job).withIdentity(jobIdentity + "_" + dateValue + "_trigger", GCAL_SCHEDULER_GROUP).startAt(new Date(dateValue)).build();
} else {
trigger = newTrigger().forJob(job).withIdentity(jobIdentity + "_" + dateValue + "_trigger", GCAL_SCHEDULER_GROUP).startAt(new Date(dateValue)).modifiedByCalendar(modifiedByEvent).build();
}
try {
scheduler.scheduleJob(job, trigger);
triggersCreated = true;
} catch (SchedulerException se) {
logger.warn("scheduling Trigger '{}' throws an exception: {}", trigger, se);
}
}
// }
return triggersCreated;
}
use of com.google.api.services.calendar.model.EventDateTime in project camel by apache.
the class CalendarEventsIntegrationTest method testInsert.
@Test
public void testInsert() throws Exception {
Event event = new Event();
event.setSummary("Feed the Camel");
event.setLocation("Somewhere");
ArrayList<EventAttendee> attendees = new ArrayList<EventAttendee>();
attendees.add(new EventAttendee().setEmail("camel-google-calendar.janstey@gmail.com"));
event.setAttendees(attendees);
Date startDate = new Date();
Date endDate = new Date(startDate.getTime() + 3600000);
DateTime start = new DateTime(startDate, TimeZone.getTimeZone("UTC"));
event.setStart(new EventDateTime().setDateTime(start));
DateTime end = new DateTime(endDate, TimeZone.getTimeZone("UTC"));
event.setEnd(new EventDateTime().setDateTime(end));
final Map<String, Object> headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelGoogleCalendar.calendarId", getCalendar().getId());
// parameter type is com.google.api.services.calendar.model.Event
headers.put("CamelGoogleCalendar.content", event);
final com.google.api.services.calendar.model.Event result = requestBodyAndHeaders("direct://INSERT", null, headers);
assertEquals("Feed the Camel", result.getSummary());
LOG.debug("insert: " + result);
}
Aggregations