Search in sources :

Example 1 with DateTime

use of com.google.api.client.util.DateTime in project openhab1-addons by openhab.

the class GCalPersistenceService method store.

/**
     * Creates a new Google Calendar Entry for each <code>item</code> and adds
     * it to the processing queue. The entries' title will either be the items
     * name or <code>alias</code> if it is <code>!= null</code>.
     *
     * The new Calendar Entry will contain a single command to be executed e.g.<br>
     * <p>
     * <code>send &lt;item.name&gt; &lt;item.state&gt;</code>
     * </p>
     *
     * @param item the item which state should be persisted.
     * @param alias the alias under which the item should be persisted.
     */
@Override
public void store(final Item item, final String alias) {
    if (initialized) {
        String newAlias = alias != null ? alias : item.getName();
        Event event = new Event();
        event.setSummary("[PresenceSimulation] " + newAlias);
        event.setDescription(String.format(executeScript, item.getName(), item.getState().toString()));
        Date now = new Date();
        Date startDate = new Date(now.getTime() + 3600000L * 24 * offset);
        Date endDate = startDate;
        DateTime start = new DateTime(startDate);
        event.setStart(new EventDateTime().setDateTime(start));
        DateTime end = new DateTime(endDate);
        event.setEnd(new EventDateTime().setDateTime(end));
        entries.offer(event);
        logger.trace("added new entry '{}' for item '{}' to upload queue", event.getSummary(), item.getName());
    } else {
        logger.debug("GCal PresenceSimulation Service isn't initialized properly! No entries will be uploaded to your Google Calendar");
    }
}
Also used : EventDateTime(com.google.api.services.calendar.model.EventDateTime) Event(com.google.api.services.calendar.model.Event) Date(java.util.Date) DateTime(com.google.api.client.util.DateTime) EventDateTime(com.google.api.services.calendar.model.EventDateTime)

Example 2 with DateTime

use of com.google.api.client.util.DateTime in project google-cloud-java by GoogleCloudPlatform.

the class BlobInfo method toPb.

StorageObject toPb() {
    StorageObject storageObject = blobId.toPb();
    if (acl != null) {
        storageObject.setAcl(Lists.transform(acl, new Function<Acl, ObjectAccessControl>() {

            @Override
            public ObjectAccessControl apply(Acl acl) {
                return acl.toObjectPb();
            }
        }));
    }
    if (deleteTime != null) {
        storageObject.setTimeDeleted(new DateTime(deleteTime));
    }
    if (updateTime != null) {
        storageObject.setUpdated(new DateTime(updateTime));
    }
    if (createTime != null) {
        storageObject.setTimeCreated(new DateTime(createTime));
    }
    if (size != null) {
        storageObject.setSize(BigInteger.valueOf(size));
    }
    if (owner != null) {
        storageObject.setOwner(new Owner().setEntity(owner.toPb()));
    }
    if (storageClass != null) {
        storageObject.setStorageClass(storageClass.toString());
    }
    Map<String, String> pbMetadata = metadata;
    if (metadata != null && !Data.isNull(metadata)) {
        pbMetadata = Maps.newHashMapWithExpectedSize(metadata.size());
        for (Map.Entry<String, String> entry : metadata.entrySet()) {
            pbMetadata.put(entry.getKey(), firstNonNull(entry.getValue(), Data.<String>nullOf(String.class)));
        }
    }
    if (customerEncryption != null) {
        storageObject.setCustomerEncryption(customerEncryption.toPb());
    }
    storageObject.setMetadata(pbMetadata);
    storageObject.setCacheControl(cacheControl);
    storageObject.setContentEncoding(contentEncoding);
    storageObject.setCrc32c(crc32c);
    storageObject.setContentType(contentType);
    storageObject.setMd5Hash(md5);
    storageObject.setMediaLink(mediaLink);
    storageObject.setMetageneration(metageneration);
    storageObject.setContentDisposition(contentDisposition);
    storageObject.setComponentCount(componentCount);
    storageObject.setContentLanguage(contentLanguage);
    storageObject.setEtag(etag);
    storageObject.setId(generatedId);
    storageObject.setSelfLink(selfLink);
    return storageObject;
}
Also used : Function(com.google.common.base.Function) Owner(com.google.api.services.storage.model.StorageObject.Owner) StorageObject(com.google.api.services.storage.model.StorageObject) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map) DateTime(com.google.api.client.util.DateTime)

Example 3 with DateTime

use of com.google.api.client.util.DateTime in project google-cloud-java by GoogleCloudPlatform.

the class BucketInfo method toPb.

com.google.api.services.storage.model.Bucket toPb() {
    com.google.api.services.storage.model.Bucket bucketPb = new com.google.api.services.storage.model.Bucket();
    bucketPb.setId(generatedId);
    bucketPb.setName(name);
    bucketPb.setEtag(etag);
    if (createTime != null) {
        bucketPb.setTimeCreated(new DateTime(createTime));
    }
    if (metageneration != null) {
        bucketPb.setMetageneration(metageneration);
    }
    if (location != null) {
        bucketPb.setLocation(location);
    }
    if (storageClass != null) {
        bucketPb.setStorageClass(storageClass.toString());
    }
    if (cors != null) {
        bucketPb.setCors(transform(cors, Cors.TO_PB_FUNCTION));
    }
    if (acl != null) {
        bucketPb.setAcl(transform(acl, new Function<Acl, BucketAccessControl>() {

            @Override
            public BucketAccessControl apply(Acl acl) {
                return acl.toBucketPb();
            }
        }));
    }
    if (defaultAcl != null) {
        bucketPb.setDefaultObjectAcl(transform(defaultAcl, new Function<Acl, ObjectAccessControl>() {

            @Override
            public ObjectAccessControl apply(Acl acl) {
                return acl.toObjectPb();
            }
        }));
    }
    if (owner != null) {
        bucketPb.setOwner(new Owner().setEntity(owner.toPb()));
    }
    bucketPb.setSelfLink(selfLink);
    if (versioningEnabled != null) {
        bucketPb.setVersioning(new Versioning().setEnabled(versioningEnabled));
    }
    if (indexPage != null || notFoundPage != null) {
        Website website = new Website();
        website.setMainPageSuffix(indexPage);
        website.setNotFoundPage(notFoundPage);
        bucketPb.setWebsite(website);
    }
    if (deleteRules != null) {
        Lifecycle lifecycle = new Lifecycle();
        lifecycle.setRule(transform(deleteRules, new Function<DeleteRule, Rule>() {

            @Override
            public Rule apply(DeleteRule deleteRule) {
                return deleteRule.toPb();
            }
        }));
        bucketPb.setLifecycle(lifecycle);
    }
    return bucketPb;
}
Also used : Owner(com.google.api.services.storage.model.Bucket.Owner) Lifecycle(com.google.api.services.storage.model.Bucket.Lifecycle) Website(com.google.api.services.storage.model.Bucket.Website) DateTime(com.google.api.client.util.DateTime) Function(com.google.common.base.Function) Versioning(com.google.api.services.storage.model.Bucket.Versioning)

Example 4 with DateTime

use of com.google.api.client.util.DateTime in project local-data-aragopedia by aragonopendata.

the class GoogleDriveAPI method listOwnerFilesAfterDate.

/**
	 * Method to list files and folders of id account after date of parameter
	 */
public List<File> listOwnerFilesAfterDate(String stringDateLastChange) {
    SimpleDateFormat formatFullDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date dateLastChange = null;
    try {
        dateLastChange = formatFullDate.parse(stringDateLastChange);
    } catch (ParseException e1) {
        log.error("Error parse date in list", e1);
    }
    FileList result;
    List<File> files = null;
    try {
        result = drive.files().list().setMaxResults(1000).execute();
        files = result.getItems();
    } catch (Exception e) {
        log.error("Error list files", e);
    }
    if (files == null || files.size() == 0) {
        log.error("No files found");
    } else {
        for (File file : files) {
            if (file.getShared()) {
                DateTime dateTime = file.getModifiedDate();
                Date dateModifyFile = new Date(dateTime.getValue());
                if (dateModifyFile.after(dateLastChange))
                    log.info("Title " + file.getTitle() + " id " + file.getId() + " DateTime " + formatFullDate.format(dateModifyFile));
            }
        }
    }
    return files;
}
Also used : FileList(com.google.api.services.drive.model.FileList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) File(com.google.api.services.drive.model.File) Date(java.util.Date) GeneralSecurityException(java.security.GeneralSecurityException) ParseException(java.text.ParseException) IOException(java.io.IOException) DateTime(com.google.api.client.util.DateTime)

Example 5 with DateTime

use of com.google.api.client.util.DateTime in project DisCal-Discord-Bot by NovaFox161.

the class EventCommand method moduleStartDate.

private void moduleStartDate(String[] args, MessageReceivedEvent event, GuildSettings settings) {
    long guildId = event.getGuild().getLongID();
    if (args.length == 2) {
        if (EventCreator.getCreator().hasPreEvent(guildId)) {
            String dateRaw = args[1].trim();
            if (dateRaw.length() > 10) {
                try {
                    // Do a lot of date shuffling to get to proper formats and shit like that.
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
                    TimeZone tz = TimeZone.getTimeZone(EventCreator.getCreator().getPreEvent(guildId).getTimeZone());
                    sdf.setTimeZone(tz);
                    Date dateObj = sdf.parse(dateRaw);
                    DateTime dateTime = new DateTime(dateObj);
                    EventDateTime eventDateTime = new EventDateTime();
                    eventDateTime.setDateTime(dateTime);
                    // Wait! Lets check now if its in the future and not the past!
                    if (!TimeUtils.inPast(dateRaw, tz) && !TimeUtils.startAfterEnd(dateRaw, tz, EventCreator.getCreator().getPreEvent(guildId))) {
                        // Date shuffling done, now actually apply all that damn stuff here.
                        EventCreator.getCreator().getPreEvent(guildId).setStartDateTime(eventDateTime);
                        // Apply viewable date/times...
                        SimpleDateFormat sdfV = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
                        Date dateObjV = sdfV.parse(dateRaw);
                        DateTime dateTimeV = new DateTime(dateObjV);
                        EventDateTime eventDateTimeV = new EventDateTime();
                        eventDateTimeV.setDateTime(dateTimeV);
                        EventCreator.getCreator().getPreEvent(guildId).setViewableStartDate(eventDateTimeV);
                        if (EventCreator.getCreator().hasCreatorMessage(guildId)) {
                            Message.deleteMessage(event);
                            Message.deleteMessage(EventCreator.getCreator().getCreatorMessage(guildId));
                            EventCreator.getCreator().setCreatorMessage(Message.sendMessage(EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(guildId), settings), MessageManager.getMessage("Creator.Event.Start.Success.New", settings), event));
                        } else {
                            String msg = MessageManager.getMessage("Creator.Event.Start.Success", settings);
                            msg = msg.replaceAll("%date%", EventMessageFormatter.getHumanReadableDate(eventDateTimeV, settings, true)).replaceAll("%time%", EventMessageFormatter.getHumanReadableTime(eventDateTimeV, settings, true));
                            Message.sendMessage(msg, event);
                        }
                    } else {
                        // Oops! Time is in the past or after end...
                        if (EventCreator.getCreator().hasCreatorMessage(guildId)) {
                            Message.deleteMessage(event);
                            Message.deleteMessage(EventCreator.getCreator().getCreatorMessage(guildId));
                            EventCreator.getCreator().setCreatorMessage(Message.sendMessage(EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(guildId), settings), MessageManager.getMessage("Creator.Event.Start.Failure.Illegal", settings), event));
                        } else {
                            Message.sendMessage(MessageManager.getMessage("Creator.Event.Start.Failure.Illegal", settings), event);
                        }
                    }
                } catch (ParseException e) {
                    if (EventCreator.getCreator().hasCreatorMessage(guildId)) {
                        Message.deleteMessage(event);
                        Message.deleteMessage(EventCreator.getCreator().getCreatorMessage(guildId));
                        EventCreator.getCreator().setCreatorMessage(Message.sendMessage(EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(guildId), settings), MessageManager.getMessage("Creator.Event.Time.Invalid", settings), event));
                    } else {
                        Message.sendMessage(MessageManager.getMessage("Creator.Event.Time.Invalid", settings), event);
                    }
                }
            } else {
                if (EventCreator.getCreator().hasCreatorMessage(guildId)) {
                    Message.deleteMessage(event);
                    Message.deleteMessage(EventCreator.getCreator().getCreatorMessage(guildId));
                    EventCreator.getCreator().setCreatorMessage(Message.sendMessage(EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(guildId), settings), MessageManager.getMessage("Creator.Event.Time.InvalidFormat", settings), event));
                } else {
                    Message.sendMessage(MessageManager.getMessage("Creator.Event.Time.InvalidFormat", settings), event);
                }
            }
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Event.NotInit", settings), event);
        }
    } else {
        if (EventCreator.getCreator().hasCreatorMessage(guildId)) {
            Message.deleteMessage(event);
            Message.deleteMessage(EventCreator.getCreator().getCreatorMessage(guildId));
            EventCreator.getCreator().setCreatorMessage(Message.sendMessage(EventMessageFormatter.getPreEventEmbed(EventCreator.getCreator().getPreEvent(guildId), settings), MessageManager.getMessage("Creator.Event.Start.Specify", settings), event));
        } else {
            Message.sendMessage(MessageManager.getMessage("Creator.Event.Start.Specify", settings), event);
        }
    }
}
Also used : TimeZone(java.util.TimeZone) EventDateTime(com.google.api.services.calendar.model.EventDateTime) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) DateTime(com.google.api.client.util.DateTime) EventDateTime(com.google.api.services.calendar.model.EventDateTime)

Aggregations

DateTime (com.google.api.client.util.DateTime)37 Event (com.google.api.services.calendar.model.Event)13 EventDateTime (com.google.api.services.calendar.model.EventDateTime)13 IOException (java.io.IOException)10 Date (java.util.Date)9 Calendar (com.google.api.services.calendar.Calendar)8 ArrayList (java.util.ArrayList)8 Events (com.google.api.services.calendar.model.Events)7 CalendarData (com.cloudcraftgaming.discal.api.object.calendar.CalendarData)6 File (com.google.api.services.drive.model.File)6 SimpleDateFormat (java.text.SimpleDateFormat)6 Map (java.util.Map)5 GuildSettings (com.cloudcraftgaming.discal.api.object.GuildSettings)4 WebGuild (com.cloudcraftgaming.discal.api.object.web.WebGuild)4 FileList (com.google.api.services.drive.model.FileList)4 StorageObject (com.google.api.services.storage.model.StorageObject)4 ParseException (java.text.ParseException)4 Test (org.junit.Test)4 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)3 Recurrence (com.cloudcraftgaming.discal.api.object.event.Recurrence)3