}
private Event newEvent(final String subject, final String description,
final Date startDate, final Date endDate, final Participant from,
final List<Participant> attendeesList, final String location) {
Event event = new Event();
if (subject != null) {
event.setSummary(subject);
}
if (description != null) {
event.setDescription(description);
}
if (location != null) {
event.setLocation(location);
}
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));
List<EventAttendee> list = new ArrayList<EventAttendee>();
for (Participant bean : attendeesList) {
EventAttendee attendee = new EventAttendee();
attendee.setDisplayName(bean.getName());
attendee.setEmail(bean.getEmail());
if (ParticipantType.REQUIRED.equals(bean.getType())) {
attendee.setOptional(false);
}
list.add(attendee);
}
EventAttendee organizer = new EventAttendee();
organizer.setDisplayName(from.getName());
organizer.setEmail(from.getEmail());
if (ParticipantType.REQUIRED.equals(from.getType())) {
organizer.setOptional(false);
}
organizer.setOrganizer(true);
list.add(organizer);
event.setAttendees(list);
return event;
}