use of com.google.api.client.util.DateTime in project drbookings by DrBookings.
the class GoogleCalendarSync method clear.
public GoogleCalendarSync clear(final LocalDate date) throws IOException {
final CalendarListEntry flats = getCalendar();
// Iterate over the events in the specified calendar
String pageToken = null;
int cnt = 0;
do {
final Events events;
if (date != null) {
events = client.events().list(flats.getId()).setTimeMin(new DateTime(new DateConverter().convert(date))).setPageToken(pageToken).execute();
} else {
events = client.events().list(flats.getId()).setPageToken(pageToken).execute();
}
final List<Event> items = events.getItems();
for (final Event event : items) {
if (event == null) {
if (logger.isWarnEnabled()) {
logger.warn("Skipping null event");
}
continue;
}
clearEvent(flats.getId(), event);
cnt++;
}
pageToken = events.getNextPageToken();
} while (pageToken != null);
if (logger.isDebugEnabled()) {
logger.debug("Processed " + cnt + " events");
}
return this;
}
use of com.google.api.client.util.DateTime in project data-transfer-project by google.
the class GoogleBloggerImporter method insertActivity.
private void insertActivity(IdempotentImportExecutor idempotentExecutor, SocialActivityActor actor, SocialActivityModel activity, String blogId, TokensAndUrlAuthData authData) throws Exception {
String content = activity.getContent() == null ? "" : activity.getContent();
Collection<SocialActivityAttachment> linkAttachments = activity.getAttachments().stream().filter(attachment -> attachment.getType() == SocialActivityAttachmentType.LINK).collect(Collectors.toList());
Collection<SocialActivityAttachment> imageAttachments = activity.getAttachments().stream().filter(attachment -> attachment.getType() == SocialActivityAttachmentType.IMAGE).collect(Collectors.toList());
// don't know how they were laid out in the originating service.
for (SocialActivityAttachment attachment : linkAttachments) {
content = "<a href=\"" + attachment.getUrl() + "\">" + attachment.getName() + "</a>\n</hr>\n" + content;
}
if (!imageAttachments.isEmpty()) {
// Store any attached images in Drive in a new folder.
Drive driveInterface = getOrCreateDriveService(authData);
String folderId = idempotentExecutor.executeOrThrowException("MainAlbum", "Photo Album", () -> createAlbumFolder(driveInterface));
for (SocialActivityAttachment image : imageAttachments) {
try {
String newImgSrc = idempotentExecutor.executeAndSwallowIOExceptions(image.toString(), "Image", () -> uploadImage(image, driveInterface, folderId));
content += "\n<hr/><img src=\"" + newImgSrc + "\">";
} catch (RuntimeException e) {
throw new IOException("Couldn't import: " + imageAttachments, e);
}
}
}
String title = "";
if (activity.getTitle() != null && !Strings.isNullOrEmpty(activity.getTitle())) {
title = activity.getTitle();
}
Post post = new Post().setTitle("Imported post: " + title).setContent(content);
if (actor != null) {
Post.Author author = new Post.Author();
if (!Strings.isNullOrEmpty(actor.getName())) {
author.setDisplayName(actor.getName());
}
if (!Strings.isNullOrEmpty(actor.getUrl())) {
author.setUrl(actor.getUrl());
}
post.setAuthor(author);
}
if (activity.getPublished() != null) {
post.setPublished(new DateTime(activity.getPublished().toEpochMilli()));
}
idempotentExecutor.executeAndSwallowIOExceptions(title, title, () -> getOrCreateBloggerService(authData).posts().insert(blogId, post).setIsDraft(true).execute().getId());
}
use of com.google.api.client.util.DateTime in project syndesis-qe by syndesisio.
the class GoogleCalendarSteps method getDateOrDateTime.
/**
* Method that returns EventDateTime instance based on the row defined in table for the step.
*
* @param prefix either "start" or "end"
* @param row the row with data (expecting presence of either prefix+"_date" or prefix+"_time"),
* if none provided, time is defined as now()+24h for "start" and now()+25h for "end" times
* @return EventDateTime instance with either prefix+"_date" or prefix+"_time" fields set
*/
private EventDateTime getDateOrDateTime(String prefix, Map<String, String> row) {
EventDateTime edt = new EventDateTime();
String dateValueIdentifier = prefix + "_date";
String timeValueIdentifier = prefix + "_time";
String dateValue = row.get(dateValueIdentifier);
String timeValue = row.get(timeValueIdentifier);
if (dateValue != null && !dateValue.isEmpty()) {
// if date value are provided set it
if (timeValue != null && !timeValue.isEmpty()) {
edt.setDateTime(DateTime.parseRfc3339(dateValue + "T" + timeValue));
} else {
edt.setDate(DateTime.parseRfc3339(dateValue));
}
} else {
// if date value not provided set time in future
// offset of 24 or 25 hours to future: start time now()+24, end time now()+25
long millisToFuture = (("start".equalsIgnoreCase(prefix) ? 0 : 1) + 24) * 60 * 60 * 1000;
edt.setDateTime(new DateTime(System.currentTimeMillis() + millisToFuture));
}
return edt;
}
use of com.google.api.client.util.DateTime in project muikku by otavanopisto.
the class GoogleCalendarClient method listEvents.
public List<CalendarEvent> listEvents(java.time.OffsetDateTime minTime, java.time.OffsetDateTime maxTime, String... calendarId) throws CalendarServiceException {
ArrayList<CalendarEvent> result = new ArrayList<>();
for (String calId : calendarId) {
try {
for (Event event : getClient().events().list(calId).setTimeMin(minTime != null ? new DateTime(minTime.toInstant().toEpochMilli()) : null).setTimeMax(maxTime != null ? new DateTime(maxTime.toInstant().toEpochMilli()) : null).execute().getItems()) {
result.add(toMuikkuEvent(calId, event));
logger.log(Level.INFO, event.toPrettyString());
}
} catch (GeneralSecurityException | IOException ex) {
throw new CalendarServiceException(ex);
}
}
return result;
}
use of com.google.api.client.util.DateTime in project muikku by otavanopisto.
the class Convert method toEventDateTime.
static EventDateTime toEventDateTime(boolean dateOnly, CalendarEventTemporalField datetime) {
EventDateTime result = new EventDateTime();
result.setTimeZone(datetime.getTimeZone().getID());
if (dateOnly) {
long timestamp = datetime.getDateTime().getTime();
long offset = datetime.getTimeZone().getOffset(timestamp);
result.setDate(new DateTime(true, timestamp + offset, (int) msToMinutes(offset)));
} else {
result.setDateTime(toDateTime(datetime));
}
return result;
}
Aggregations