public static dix.walton.moore.model.Event convertToOurEvent(Event googleEvent) {

    dix.walton.moore.model.Event internalEvent = new dix.walton.moore.model.Event();

    DateFormat dateFormat = new SimpleDateFormat("yyyy-dd-MM");
    DateFormat timeFormat = new SimpleDateFormat("HH:mm");
    String startString;
    try {
      startString = googleEvent.getStart().getDateTime().toString();
      int T = startString.indexOf('T');
      internalEvent.setEventDate(startString.substring(0, T));
      internalEvent.setStartTime(startString.substring(T + 1, T + 6));

      if (googleEvent.getEnd() != null) {
        String endString = googleEvent.getEnd().getDateTime().toString();
        T = endString.indexOf('T');
        internalEvent.setEndTime(endString.substring(T + 1, T + 6));
      }
    } catch (Exception e) {
      System.out.println("Exception thrown");
    }

    internalEvent.setId(googleEvent.getId());
    internalEvent.setLocation(googleEvent.getLocation());
    internalEvent.setTitle(googleEvent.getSummary());
    return internalEvent;
  }
 private void createOrUpdateEvent(
     final UpdateInfo updateInfo, final CalendarListEntry calendarEntry, final Event event)
     throws Exception {
   if (event.getStatus().equalsIgnoreCase("cancelled")) {
     System.out.println(
         "event " + event.getSummary() + "/" + event.getDescription() + " was canceled");
     final int deleted =
         jpaDaoService.execute(
             String.format(
                 "DELETE FROM Facet_GoogleCalendarEvent facet WHERE "
                     + "facet.apiKeyId=%s AND facet.googleId='%s'",
                 updateInfo.apiKey.getId(), event.getId()));
     System.out.println("deleted " + deleted + " calendar entry");
     return;
   }
   final String googleIdHash = hash(event.getId());
   final String calendarIdHash = hash(calendarEntry.getId());
   final ApiDataService.FacetQuery facetQuery =
       new ApiDataService.FacetQuery(
           "e.apiKeyId=? AND (e.googleId=? OR e.googleId=?) AND (e.calendarId=? OR e.calendarId=?)",
           updateInfo.apiKey.getId(),
           event.getId(),
           googleIdHash,
           calendarEntry.getId(),
           calendarIdHash);
   final ApiDataService.FacetModifier<GoogleCalendarEventFacet> facetModifier =
       new ApiDataService.FacetModifier<GoogleCalendarEventFacet>() {
         @Override
         public GoogleCalendarEventFacet createOrModify(
             GoogleCalendarEventFacet facet, final Long apiKeyId) {
           if (facet == null) {
             facet = new GoogleCalendarEventFacet(updateInfo.apiKey.getId());
             facet.googleId = event.getId().length() > 250 ? googleIdHash : event.getId();
             facet.guestId = updateInfo.apiKey.getGuestId();
             facet.api = updateInfo.apiKey.getConnector().value();
             facet.calendarId =
                 calendarEntry.getId().length() > 250 ? calendarIdHash : calendarEntry.getId();
           }
           facet.summary = event.getSummary();
           facet.setCreated(event.getCreated());
           facet.setAttendees(event.getAttendees());
           facet.etag = event.getEtag();
           facet.setStart(event.getStart());
           facet.endTimeUnspecified = event.getEndTimeUnspecified();
           facet.setEnd(event.getEnd());
           facet.colorId = event.getColorId();
           facet.setCreator(event.getCreator());
           facet.description = event.getDescription();
           facet.guestsCanSeeOtherGuests = event.getGuestsCanSeeOtherGuests();
           facet.hangoutLink = event.getHangoutLink();
           facet.htmlLink = event.getHtmlLink();
           facet.iCalUID = event.getICalUID();
           facet.kind = event.getKind();
           facet.location = event.getLocation();
           facet.locked = event.getLocked();
           facet.setOrganizer(event.getOrganizer());
           facet.setOriginalStartTime(event.getOriginalStartTime());
           facet.status = event.getStatus();
           facet.timeUpdated = System.currentTimeMillis();
           facet.transparency = event.getTransparency();
           facet.visibility = event.getVisibility();
           facet.setRecurrence(event.getRecurrence());
           if (event.getRecurringEventId() != null) {
             final String recurringEventIdHash = hash(event.getRecurringEventId());
             facet.recurringEventId =
                 event.getRecurringEventId().length() > 250
                     ? recurringEventIdHash
                     : event.getRecurringEventId();
           }
           facet.sequence = event.getSequence();
           facet.setUpdated(event.getUpdated());
           return facet;
         }
       };
   // we could use the resulting value (facet) from this call if we needed to do further processing
   // on it (e.g. passing it on to the datastore)
   apiDataService.createOrReadModifyWrite(
       GoogleCalendarEventFacet.class, facetQuery, facetModifier, updateInfo.apiKey.getId());
 }
Exemplo n.º 3
0
  public Event(com.google.api.services.calendar.model.Event current, int $colorNumber) {
    name = current.getSummary();
    summary = current.getDescription();
    Calendar calS = Calendar.getInstance();
    Calendar calE = Calendar.getInstance();
    colorNumber = $colorNumber;
    // cal.setTimeInMillis(current.getStart().getDateTime().getValue());
    // startDate = cal;
    if (current.getStart().getDate() != null) {
      String[] date = current.getStart().getDate().toString().split("-");
      calS.set(Integer.parseInt(date[0]), Integer.parseInt(date[1]) - 1, Integer.parseInt(date[2]));
      date = current.getEnd().getDate().toString().split("-");
      calE.set(Integer.parseInt(date[0]), Integer.parseInt(date[1]) - 1, Integer.parseInt(date[2]));
      startDate = calS;
      endDate = calE;
    } else {
      String date = current.getStart().getDateTime().toString();

      int dateCutoff = date.indexOf("T");
      int timeCutoff = date.indexOf("."); // to remove nanoseconds
      if (timeCutoff == -1) // if nanoseconds not set remove timezone shift
      timeCutoff = date.indexOf("-");
      if (timeCutoff == -1) // if timezone shift not set isolate time only
      timeCutoff = date.indexOf("Z");

      String time = date.substring(dateCutoff + 1, timeCutoff);
      String[] timeC = time.split(":");

      date = date.substring(0, dateCutoff);
      String[] dateC = date.split("-");

      calS.set(
          Integer.parseInt(dateC[0]),
          Integer.parseInt(dateC[1]) - 1,
          Integer.parseInt(dateC[2]),
          Integer.parseInt(timeC[0]),
          Integer.parseInt(timeC[1]),
          Integer.parseInt(timeC[2]));

      date = current.getEnd().getDateTime().toString();
      timeCutoff = date.indexOf(".");
      dateCutoff = date.indexOf("T");

      // to remove nanoseconds
      if (timeCutoff == -1) // if nanoseconds not set remove timezone shift
      timeCutoff = date.indexOf("-");
      if (timeCutoff == -1) // if timezone shift not set isolate time only
      timeCutoff = date.indexOf("Z");

      time = date.substring(dateCutoff + 1, timeCutoff);
      String[] timeE = time.split(":");

      date = date.substring(0, dateCutoff);
      dateC = date.split("-");
      calE.set(
          Integer.parseInt(dateC[0]),
          Integer.parseInt(dateC[1]) - 1,
          Integer.parseInt(dateC[2]),
          Integer.parseInt(timeE[0]),
          Integer.parseInt(timeE[1]),
          Integer.parseInt(timeE[2]));

      startDate = calS;
      endDate = calE;
    }

    id = current.getId();
    calendarName = current.getOrganizer().getDisplayName();
    // cal.setTimeInMillis(current.getEnd().getDateTime().getValue());
    // endDate = cal;
  }