/** * 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>. * * <p>The new Calendar Entry will contain a single command to be executed e.g.<br> * * <p><code>send <item.name> <item.state></code> * * @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(); CalendarEventEntry myEntry = new CalendarEventEntry(); myEntry.setTitle(new PlainTextConstruct("[PresenceSimulation] " + newAlias)); myEntry.setContent( new PlainTextConstruct( String.format(executeScript, item.getName(), item.getState().toString()))); DateTime nowPlusOffset = new DateTime().plusDays(offset); com.google.gdata.data.DateTime time = com.google.gdata.data.DateTime.parseDateTime(nowPlusOffset.toString()); When eventTimes = new When(); eventTimes.setStartTime(time); eventTimes.setEndTime(time); myEntry.addTime(eventTimes); entries.offer(myEntry); logger.trace( "added new entry '{}' for item '{}' to upload queue", myEntry.getTitle().getPlainText(), item.getName()); } else { logger.debug( "GCal PresenceSimulation Service isn't initialized properly! No entries will be uploaded to your Google Calendar"); } }
/** * créée un nouvl évenement dans un calendrier * * @param email * @param dateDebut * @param dateFin * @param titre * @param description * @throws Exception */ public void createEvent( String email, Date dateDebut, Date dateFin, String titre, String description) throws Exception { try { CalendarEventEntry myEntry = new CalendarEventEntry(); myEntry.setTitle(new PlainTextConstruct(titre)); myEntry.setContent(new PlainTextConstruct(description)); When eventTimes = new When(); eventTimes.setStartTime(new DateTime(dateDebut.getTime(), TIME_OFFSET)); eventTimes.setEndTime(new DateTime(dateFin.getTime(), TIME_OFFSET)); myEntry.addTime(eventTimes); getService() .insert( new URL("https://www.google.com/calendar/feeds/" + email + "/private/full"), myEntry); } catch (Exception e) { e.printStackTrace(); } }