private static GEvent newGEvent(Event event, GCalendar calendar) {
    DateTime start = event.getStart().getDateTime();
    DateTime end = event.getEnd().getDateTime();
    if (start == null) {
      // All-day events don't have start times, so just use
      // the start date.
      start = event.getStart().getDate();
    }
    if (end == null) {
      end = event.getEnd().getDate();
    }
    Calendar startEvent = new GregorianCalendar();
    Calendar endEvent = new GregorianCalendar();
    startEvent.setTime(new Date(start.getValue()));
    endEvent.setTime(new Date(end.getValue()));

    //        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd H:m:s");
    //        Log.d("gevent", "start = " + format1.format(startEvent.getTime()) + ", end = " +
    // format1.format(endEvent.getTime()));

    GEvent nEvent = new GEvent(event.getSummary(), startEvent, endEvent);
    nEvent.SetBackgroundColor(calendar.backgroundColor);
    nEvent.SetForegroundColor(calendar.foregroundColor);

    return nEvent;
  }
Exemplo n.º 2
0
  public Event newEvent(DateTime start, DateTime end, String title) {
    Event event = new Event();
    event.setSummary(title);
    Date startDate = new Date();
    Date endDate = new Date(startDate.getTime() + 3600000);

    event.setStart(new EventDateTime().setDateTime(start));
    event.setEnd(new EventDateTime().setDateTime(end));
    return event;
  }
  public String getTimeDescription() {
    EventDateTime startDT = event.getStart();
    EventDateTime endDT = event.getEnd();
    // this field is populated if event has time
    if (startDT.getDateTime() != null) {
      return String.format(
          "Start: %s End: %s",
          formatDateTime(startDT.getDateTime()), formatDateTime(endDT.getDateTime()));
    }
    DateTime startDate = startDT.getDate();
    DateTime endDate = endDT.getDate();
    // special case for 1 full day event - just show the one date instead of start end
    final long oneDayTime = 1000 * 60 * 60 * 24;
    if (endDate.getValue() - startDate.getValue() == oneDayTime)
      return String.format("Date: %s", startDate);

    return String.format("Start: %s End: %s", startDate, endDate);
  }
  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;
  }
  public void listAllEvents() throws IOException, ParseException {
    List<String[]> myList = new ArrayList<String[]>();

    eventsList = new ArrayList<Object[]>();

    com.google.api.services.calendar.Calendar service = getCalendarService();

    // List the next 10 events from the primary calendar.
    DateTime now = new DateTime(System.currentTimeMillis());
    Events events =
        service
            .events()
            .list("primary")
            .setMaxResults(20)
            .setTimeMin(now)
            .setOrderBy("startTime")
            .setSingleEvents(true)
            .execute();
    List<Event> items = events.getItems();
    for (Event e : items) {
      System.out.println(e.getSummary() + " , " + e.getStart());
    }
    if (items.size() == 0) {
      System.out.println("No upcoming events found.");
    } else {
      System.out.println("Upcoming events");
      for (Event event : items) {
        DateTime start = event.getStart().getDateTime();
        if (start == null) {
          start = event.getStart().getDate();
        }
        String today = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
        String startString =
            new SimpleDateFormat("MM/dd/yyyy")
                .format(
                    new SimpleDateFormat("yyyy-MM-dd").parse(start.toString().substring(0, 10)));
        Object[] eventArray = new Object[2];
        eventArray[0] = event.getSummary();
        eventArray[1] = start.toString().equals(today) ? "Today" : startString;
        eventsList.add(eventArray);
      }
    }
  }
  public void createCalEvent(Date startDate, Date endDate, String summary, String desc)
      throws IOException {

    com.google.api.services.calendar.Calendar service = getCalendarService();
    Event createEvent = new Event().setSummary(summary).setDescription(desc);

    DateTime startTime = new DateTime(startDate);
    DateTime endTime = new DateTime(endDate);

    EventDateTime start = new EventDateTime().setDateTime(startTime).setTimeZone("Asia/Kolkata");

    createEvent.setStart(start);

    EventDateTime end = new EventDateTime().setDateTime(endTime).setTimeZone("Asia/Kolkata");

    createEvent.setEnd(end);

    EventAttendee[] attendees =
        new EventAttendee[] {
          new EventAttendee().setEmail("*****@*****.**"),
          new EventAttendee().setEmail("*****@*****.**"),
          new EventAttendee().setEmail("*****@*****.**")
        };

    createEvent.setAttendees(Arrays.asList(attendees));

    EventReminder[] reminderOverrides =
        new EventReminder[] {new EventReminder().setMethod("popup").setMinutes(10)};

    Event.Reminders reminders =
        new Event.Reminders().setUseDefault(false).setOverrides(Arrays.asList(reminderOverrides));

    createEvent.setReminders(reminders);

    String calendarId = "primary";
    createEvent = service.events().insert(calendarId, createEvent).execute();
    System.out.printf("Event created: %s\n", createEvent.getHtmlLink());
  }
 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());
 }
  @Override
  protected void channelRead0(
      ChannelHandlerContext channelHandlerContext, FullHttpRequest fullHttpRequest)
      throws Exception {
    String jsonReturn = "";

    String messageContent = getHttpMessageContent(fullHttpRequest);

    if (isPost(fullHttpRequest) && messageContent != null) {
      BookingInquiryObject bookingInquiry =
          new Gson().fromJson(messageContent, BookingInquiryObject.class);

      if (bookingInquiry != null
          && bookingInquiry.getBookingInquiry() != null
          && bookingInquiry.getBookingInquiry().getFirmanavn() != null
          && bookingInquiry.getBookingInquiry().getEvents().size() > 0) {

        bookingInquiry
            .getBookingInquiry()
            .setId(
                bookingInquiry.getBookingInquiry().getFirmanavn().replace("/", "_")
                    + "_"
                    + System.currentTimeMillis());
        bookingInquiry
            .getBookingInquiry()
            .setSubject(
                "Ny Reservasjonsforespørsel fra: "
                    + bookingInquiry.getBookingInquiry().getFirmanavn());

        StringBuilder message = new StringBuilder();

        if (bookingInquiry.getBookingInquiry().getCommunityBeskrivelse() != null) {
          message
              .append(bookingInquiry.getBookingInquiry().getCommunityBeskrivelse())
              .append("\n;;;\n");
        }

        message
            .append("firmanavn: " + bookingInquiry.getBookingInquiry().getFirmanavn())
            .append("\n");
        message.append("epost: " + bookingInquiry.getBookingInquiry().getEpost()).append("\n");
        message.append("tlf: " + bookingInquiry.getBookingInquiry().getTlf()).append("\n");
        message
            .append("beskrivelse: " + bookingInquiry.getBookingInquiry().getBeskrivelse())
            .append("\n");
        message
            .append("bevertning: " + bookingInquiry.getBookingInquiry().getOenskerBevertning())
            .append("\n");
        message.append("events: \n");

        StringBuilder emailMessage = new StringBuilder();
        emailMessage
            .append("Ny booking forespoersel fra: ")
            .append(bookingInquiry.getBookingInquiry().getFirmanavn())
            .append(" \r\n ");

        for (String event : bookingInquiry.getBookingInquiry().getEvents()) {
          String[] eventParts = event.split("-|_|;");
          if (eventParts.length == 5) {
            Event googleEvent =
                createEvent(
                    eventParts[0],
                    eventParts[1],
                    eventParts[2],
                    eventParts[3],
                    eventParts[4],
                    bookingInquiry.getBookingInquiry().getFirmanavn(),
                    bookingInquiry.getBookingInquiry().getEpost(),
                    message.toString());
            emailMessage.append(googleEvent.getHtmlLink()).append(" \r\n");
          }
          message.append(event).append("\n");
        }
        bookingInquiry.getBookingInquiry().setMessage(emailMessage.toString());

        // Email to Customer
        String filename =
            System.getProperty("no.haagensoftware.contentice.webappDir")
                + "/"
                + getDomain().getWebappName()
                + "/uploads/booking_kvittering.html";
        File template = new File(filename);
        String templateHtml = null;

        if (template != null && template.isFile() && template.exists()) {
          try {
            templateHtml = FileUtil.getFilecontents(template);
            BookingInquiry emailToCustomer = new BookingInquiry(bookingInquiry.getBookingInquiry());
            emailToCustomer.setId(emailToCustomer.getId() + "_customer");
            emailToCustomer.setSubject("Takk for din bookingforespørsel på Teknologihuset!");
            emailToCustomer.setMessage(templateHtml);

            getStorage()
                .setSubCategory(
                    getDomain().getWebappName(),
                    "emailsNotSent",
                    emailToCustomer.getId(),
                    BookingInquiryAssembler.convertBookingInquiryToSubCategory(emailToCustomer));
          } catch (IOException e) {
            e.printStackTrace();
            templateHtml = null;
          }
        }

        // Email to vert!
        getStorage()
            .setSubCategory(
                getDomain().getWebappName(),
                "emailsNotSent",
                bookingInquiry.getBookingInquiry().getId(),
                BookingInquiryAssembler.convertBookingInquiryToSubCategory(
                    bookingInquiry.getBookingInquiry()));

        EpostExecutor.getInstance(getDomain().getWebappName()).sendRemainingEmails(getStorage());

        jsonReturn = "{\"bookingInquiry\": {}}";

        /*Event event = new Event();
        event.setSummary("New Event");
        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));
        return event;*/
      }
    }

    writeContentsToBuffer(channelHandlerContext, jsonReturn, "application/json");
  }
  private Event createEvent(
      String roomName,
      String yearNum,
      String monthNum,
      String dayNum,
      String eventTime,
      String firmanavn,
      String attendeeEmail,
      String besrkivelse) {
    Event event = null;

    Calendar startCal = null;
    Calendar endCal = null;

    try {
      int year = Integer.parseInt(yearNum);
      int month = Integer.parseInt(monthNum) - 1;
      int day = Integer.parseInt(dayNum);

      startCal = Calendar.getInstance();
      startCal.set(Calendar.YEAR, year);
      startCal.set(Calendar.MONTH, month);
      startCal.set(Calendar.DATE, day);

      endCal = Calendar.getInstance();
      endCal.set(Calendar.YEAR, year);
      endCal.set(Calendar.MONTH, month);
      endCal.set(Calendar.DATE, day);

      if (eventTime.equals("early")) {
        startCal.set(Calendar.HOUR_OF_DAY, 8);
        endCal.set(Calendar.HOUR_OF_DAY, 12);
      } else if (eventTime.equals("late")) {
        startCal.set(Calendar.HOUR_OF_DAY, 13);
        endCal.set(Calendar.HOUR_OF_DAY, 17);
      } else if (eventTime.equals("full")) {
        startCal.set(Calendar.HOUR_OF_DAY, 8);
        endCal.set(Calendar.HOUR_OF_DAY, 17);
      } else if (eventTime.equals("community")) {
        startCal.set(Calendar.HOUR_OF_DAY, 17);
        startCal.set(Calendar.MINUTE, 1);
        endCal.set(Calendar.HOUR_OF_DAY, 22);
      } else {
        int startHour = Integer.parseInt(eventTime);
        startCal.set(Calendar.HOUR_OF_DAY, startHour);
        endCal.set(Calendar.HOUR_OF_DAY, (startHour + 1));
      }

      startCal.set(Calendar.MINUTE, 0);
      endCal.set(Calendar.MINUTE, 0);

      event = new Event();
      DateTime start = new DateTime(startCal.getTime(), TimeZone.getTimeZone("UTC"));
      event.setStart(new EventDateTime().setDateTime(start));
      DateTime end = new DateTime(endCal.getTime(), TimeZone.getTimeZone("UTC"));
      event.setEnd(new EventDateTime().setDateTime(end));

      event.setSummary(firmanavn);
      event.setLocation(roomName);
      event.setDescription(besrkivelse);

      EventAttendee room = new EventAttendee();
      room.setDisplayName(roomName);
      room.setEmail("*****@*****.**");

      List<EventAttendee> attendeeList = new ArrayList<>();
      attendeeList.add(room);

      EventAttendee attendee = new EventAttendee();
      attendee.setDisplayName(firmanavn);
      attendee.setEmail(attendeeEmail);
      attendeeList.add(attendee);

      event.setAttendees(attendeeList);

      GoogleCal googleCal = GoogleCal.getInstance();
      event = googleCal.addEvent(event);
    } catch (NumberFormatException nfe) {
      nfe.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return event;
  }
Exemplo n.º 10
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;
  }
 public long getStartTime() {
   EventDateTime startDT = event.getStart();
   if (startDT.getDateTime() != null) return startDT.getDateTime().getValue();
   return startDT.getDate().getValue();
 }
 public String getSummary() {
   return event.getSummary();
 }