Events from database show to google calendar - java

I am developing an app, which works like a booking system. The main-component is a calendar which shows created events, which are stored in PostgreSQL database. My challenge now, is to show all the events from database to the adminĀ“s google calendar. When the admin opens his google calendar, he only has rights to see the events, but not to edit them.
The technologies i am using is Apache/Tomcat, Java, Spring and Hibernate.
Can someone help me, or guide me to some clear solution?

If you are looking for guide, then the documentation can help you a lot.
First thing, you need to understand the concept of Google Calendar API. You can read the basic concept on the overview page for further details. Moreover, if your aim is just more on the events, then you will need to make sure that you have visited this.
Here is a sample snippet all the way from the sample given in the documentation. This sample demonstrate creating an event and setting its metadata:
// Refer to the Java quickstart on how to setup the environment:
// https://developers.google.com/calendar/quickstart/java
// Change the scope to CalendarScopes.CALENDAR and delete any stored
// credentials.
Event event = new Event()
.setSummary("Google I/O 2015")
.setLocation("800 Howard St., San Francisco, CA 94103")
.setDescription("A chance to hear more about Google's developer products.");
DateTime startDateTime = new DateTime("2015-05-28T09:00:00-07:00");
EventDateTime start = new EventDateTime()
.setDateTime(startDateTime)
.setTimeZone("America/Los_Angeles");
event.setStart(start);
DateTime endDateTime = new DateTime("2015-05-28T17:00:00-07:00");
EventDateTime end = new EventDateTime()
.setDateTime(endDateTime)
.setTimeZone("America/Los_Angeles");
event.setEnd(end);
String[] recurrence = new String[] {"RRULE:FREQ=DAILY;COUNT=2"};
event.setRecurrence(Arrays.asList(recurrence));
EventAttendee[] attendees = new EventAttendee[] {
new EventAttendee().setEmail("lpage#example.com"),
new EventAttendee().setEmail("sbrin#example.com"),
};
event.setAttendees(Arrays.asList(attendees));
EventReminder[] reminderOverrides = new EventReminder[] {
new EventReminder().setMethod("email").setMinutes(24 * 60),
new EventReminder().setMethod("popup").setMinutes(10),
};
Event.Reminders reminders = new Event.Reminders()
.setUseDefault(false)
.setOverrides(Arrays.asList(reminderOverrides));
event.setReminders(reminders);
String calendarId = "primary";
event = service.events().insert(calendarId, event).execute();
System.out.printf("Event created: %s\n", event.getHtmlLink());

Related

Not getting invite acceptation email in ical4j

I am using the iCal4j for sending the calendar invite. I am able to send the invite to user. But when user accepting the invite I am not getting the revert mail.
net.fortuna.ical4j.model.Calendar cal = new net.fortuna.ical4j.model.Calendar();
cal.getProperties().add(new ProdId("//Google Inc//Google Calendar 70.9054//EN"));
cal.getProperties().add(Version.VERSION_2_0);
cal.getProperties().add(CalScale.GREGORIAN);
System.setProperty(CompatibilityHints.KEY_OUTLOOK_COMPATIBILITY, "true");
java.util.Calendar c1 = java.util.Calendar.getInstance();
c1.add(java.util.Calendar.HOUR, 1);
c1.add(java.util.Calendar.DATE, 1);
DateTime start = new DateTime(c1.getTime());
c1.add(java.util.Calendar.HOUR, 1);
DateTime end = new DateTime(c1.getTime());
VEvent vEvent = new VEvent();
vEvent.getProperties().add(new DtStart(start));
vEvent.getProperties().add(new DtEnd(end));
vEvent.getProperties().add(Clazz.PUBLIC);
Organizer organizer = new Organizer(URI.create("mailto:mail#gmail.com"));
organizer.getParameters().add(new Cn("mail#gmail.com"));
vEvent.getProperties().add(organizer);
UidGenerator uid = new RandomUidGenerator();
vEvent.getProperties().add(uid.generateUid());
Attendee attendee1 = new Attendee(URI.create("mailto:mail#yahoo.com"));
attendee1.getParameters().add(CuType.INDIVIDUAL);
attendee1.getParameters().add(Role.REQ_PARTICIPANT);
attendee1.getParameters().add(PartStat.NEEDS_ACTION);
attendee1.getParameters().add(Rsvp.TRUE);
attendee1.getParameters().add(new Cn("mail#yahoo.com"));
vEvent.getProperties().add(attendee1);
vEvent.getProperties().add(new Description("some description");
vEvent.getProperties().add(new Location("location"));
vEvent.getProperties().add(Status.VEVENT_CONFIRMED);
vEvent.getProperties().add(new Summary("Invite summery"));
vEvent.getProperties().add(Transp.OPAQUE);
Any suggestion???
When sending calendar invites you need to include directives that tell the client software (e.g. Outlook, etc.) how it should handle the event. This is done via the METHOD property:
http://ical4j.github.io/docs/ical4j/api/3.0.26/net/fortuna/ical4j/model/property/Method.html
Usually you would use either METHOD:PUBLISH for events that don't require a response, or METHOD:REQUEST where you want accept/decline response.
So if you add METHOD:REQUEST property to your invitation you should get a response.

How to create new event in Google Calendar API with java in NetBeans

I followed the quickstart guide that Google provides on Calendar API https://developers.google.com/google-apps/calendar/quickstart/java but they dont explain how to create a new event. I found this snippet of code online
public void createEvent(Calendar cal){
Event event = new Event();
event.setSummary("Event name here");
event.setLocation("event place here");
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));
Event createdEvent = cal.events().insert("primary", event).execute();
System.out.println("Created event id: " + createdEvent.getId());
}
But it didn't help me, i got an error in the Event createdEvent = cal.events() section as events() doesn't exist. Any help is much appreciated, thank you.
At the bottom of your link to the documentation there is a link to Create Events. I won't duplicate the entire page here, but the gist is that you need to Create an Event object (perhaps called MyNewEvent), populate it, and then call:
MyNewEvent = service.events().insert("Some Calendar Id", MyNewEvent).execute();

Creating Meeting lotus Meeting using ICall

In a eclipse plugin for the Lotus Notes client I need to create a meeting in a user's mailfile. I have created successfully an appointment in my own mailfile using the NotesCalendar object. (see code below ). What I don't seem to get right is to create a meeting instead of an appointment. On the database level the difference is made by a field called appointmenttype which is set to 3 in the case of a meeting and 0 in the case of a appointment.
According to resources I found I need to add the xProperty "X-LOTUS-APPTTYPE" with a value of "3" to my Ical4j object but for some reason this is not being processed by the NotesCalendar.createEntry() method.
Does someone have any idea how to create a Meeting in a mailfile using the NotesCalendar notes classes and Ical4j?
(the reason I have added the xPages tag is that I hope someone in the xPages community ever has used the notescalendar objects before )
Code that creates an appointment:
DateTime meetingStart = new DateTime(c.getStartTime().getTime());
DateTime meetingEnd = new DateTime(c.getEndTime().getTime());
VEvent meeting = new VEvent(meetingStart, meetingEnd, c.getSubject());
// Add chair
Attendee chairAttendee = new Attendee(URI.create("mailto:j.somhorst#development.acuity.nl"));
chairAttendee.getParameters().add(Role.CHAIR);
// Add invitees
for(User invitee : c.getUserParticipants()){
Attendee attendee = new Attendee(URI.create("mailto:"+invitee.getEmail()));
attendee.getParameters().add(Role.REQ_PARTICIPANT);
meeting.getProperties().add(attendee);
}
// create calendar for ics export
Calendar call = new Calendar();
call.getProperties().add(new ProdId("-//Lotus Development Corporation//NONSGML Notes 9.0.1//EN_API_C"));
call.getComponents().add(meeting);
// notes specific fields
meeting.getProperties().add(new XProperty("X-LOTUS-NOTESVERSION","2"));
meeting.getProperties().add(new XProperty("X-LOTUS-APPTTYPE","3"));
NotesCalendar notesCalendar = NotesUtil.getNotesCalendar(s);
if(notesCalendar!=null){
notesCalendar.setAutoSendNotices(false);
NotesCalendarEntry entry = notesCalendar.createEntry(call.toString());
String icallvalue = entry.read();
System.out.println(icallvalue);
}

EWS Java get meetings

I am trying to integrate exchange calendar with my custom calendar. Till now i am able to integrate new creation of meeting from my calendar to Exchange.
But the issue i am facing is from Exchange to my calendar. If i create a new meeting in outlook, and and if i search it through below code i am getting results.
<code>
CalendarFolder calendarFolder = CalendarFolder.bind(eService, WellKnownFolderName.Calendar);
CalendarView calendarView = new CalendarView(startOfMonth.toDate(), endOfMonth.toDate());
FindItemsResults<Appointment> aprilMeetings = alendarFolder.findAppointments(calendarView);
</code>
in above list i am getting all meetings between start and end date. My question is how to identify whether its a new meeting or updated meeting or canceled meeting.
I tried these methods,
<code>
appointment.getIsNew().
appointment.getIsCancelled()
appointment.getIsUnmodified()
</code>
But all above methods return false. I need to find a way to figure out this so that i can sync items from my Exchange Server to my custom application (Note: I am also creating iCal file in my application, so i can use my application when exchange is not connected).
Regards.
you can use the following code to get updated/new meetings.
Date startDate1 = formatter.parse("2014-04-25 07:00:00");
SearchFilter filter = new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.LastModifiedTime,startDate1);
FindItemsResults<Item> findResults = exchange.findItems(WellKnownFolderName.Calendar, filter, new ItemView(10));
for (Item item : findResults.getItems())
{
Appointment appt = (Appointment)item;
System.out.println("SUBJECT====="+appt.getSubject());
System.out.println("Location========"+appt.getLocation());
System.out.println("Start Time========"+appt.getStart());
System.out.println("End Time========"+appt.getEnd());
System.out.println("Email Address========"+ appt.getOrganizer().getAddress());
System.out.println("Last Modified Time========"+appt.getLastModifiedTime());
}

Choose Non-default googlecalendar with google-java-client-api

I want to get all the Calendars, which are in my GoogleAccount, using the google java client API.
In my application I want that a user can choose in wich calendar his events will be saved (not only in the default). But therefore I need their CalendarIDs. I don't want that the users have to search their calendar ids to write them by hand into the app.
Would it be possible to create a new Calendar in his account, to write all the events in this new one.
Sorry for my bad English.
Yes of course it is possible.You only have to know the calendarId in which you want to save the new event, and use them with the event insert function.
For example :
Event event = new Event();
event.setSummary("This is my Event");
event.setLocation("127.0.0.1 -- Home sweet Home!!");
ArrayList<EventAttendee> participants = new ArrayList<EventAttendee>();
participants .add(new EventAttendee().setEmail("member#domain.com"));
event.setAttendees(participants);
DateTime start = new DateTime(new Date(), TimeZone.getTimeZone("UTC"));
event.setStart(new EventDateTime().setDateTime(start));
DateTime end = new DateTime(new Date(startDate.getTime() + 3600000), TimeZone.getTimeZone("UTC"));
event.setEnd(new EventDateTime().setDateTime(end));
Event createdEvent = service.events().insert("YourCalendarID", event).execute();
Hope this could help you!

Categories

Resources