List of usage examples for org.joda.time DateTimeZone UTC
DateTimeZone UTC
To view the source code for org.joda.time DateTimeZone UTC.
Click Source Link
From source file:com.sappenin.utils.appengine.customernotifications.framework.data.dao.AggregatableNotificationDaoObjectify.java
License:Apache License
@Override public void deleteProcessedNotifications(final Key<?> notificationTargetKey, NotificationType notificationType) { // Query for all NRM keys that are parented by the notificationTargetKey and notificationType, that have a // creationDateTime before "now". Key<NotificationType> ancestorKey = AggregatableNotificationEntity.ancestorKey(notificationTargetKey, notificationType);//from www. j a v a2s . co m DateTime now = DateTime.now(DateTimeZone.UTC); QueryResultIterable<Key<AggregatableNotificationEntity>> keysIterator = ObjectifyService.ofy().load() .type(AggregatableNotificationEntity.class).ancestor(ancestorKey).filter("creationDateTime <", now) .keys().iterable(); ObjectifyService.ofy().delete().keys(keysIterator); }
From source file:com.sappenin.utils.appengine.customernotifications.framework.delivery.NotificationDelivererEmailAppengine.java
License:Apache License
@Override public void deliver(Notification notification) { Preconditions.checkNotNull(notification, "Cannot deliver a null Notification!"); Preconditions.checkArgument(notification.getSender() != null); Preconditions.checkArgument(notification.getSender().getSenderAddress() != null); Preconditions.checkArgument(notification.getRecipient() != null); Preconditions.checkArgument(notification.getRecipient().getRecipientAddress() != null); Preconditions.checkArgument(notification.getMessageContent().getSubject() != null); Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); try {//ww w. j av a2 s.co m Message mimeMessage = new MimeMessage(session); InternetAddress senderInternetAddress = new InternetAddress( notification.getSender().getSenderAddress()); this.populatePersonalName(notification, senderInternetAddress); mimeMessage.setFrom(senderInternetAddress); // Allow multiple recipients in the TO field InternetAddress[] toAddresses = InternetAddress.parse(notification.getRecipient().getRecipientAddress(), true); mimeMessage.addRecipients(Message.RecipientType.TO, toAddresses); boolean alertAdmin = notification.shouldCopyAdmin(); if (alertAdmin) { // Alert the admin, too, but only if the admin is *not* part of // the "to" list. InternetAddress addrAdminEmailAddress = InternetAddress .parse(notification.getRecipient().getAdminAddress())[0]; String sAdminEmailAddress = addrAdminEmailAddress.getAddress(); // The recipients... Address[] tos = mimeMessage.getRecipients(RecipientType.TO); if (tos != null) { for (int i = 0; i < tos.length; i++) { Address addr = tos[i]; if (addr != null && addr instanceof InternetAddress) { InternetAddress iAddr = (InternetAddress) addr; if (iAddr != null && iAddr.getAddress() != null && iAddr.getAddress().equalsIgnoreCase(sAdminEmailAddress)) { // The admin is one of the recipients, so abort // and don't BCC the admin below. alertAdmin = false; break; } } } } // If alertAdmin is still true, then we should bcc the admin. if (alertAdmin) { mimeMessage.addRecipient(Message.RecipientType.BCC, addrAdminEmailAddress); } } mimeMessage.setReplyTo(new Address[] { senderInternetAddress }); mimeMessage.setSubject(notification.getMessageContent().getSubject()); // Create the various MIME Message types based on the Alert Content // type. // FormatType. if ("text/plain".equals(notification.getMessageContent().getContentType())) { Preconditions.checkArgument(notification.getMessageContent().getTextContent() != null); // Add the TEXT component of the Alert mimeMessage.setText(notification.getMessageContent().getTextContent().getValue()); } if ("text/html".equals(notification.getMessageContent().getContentType())) { Preconditions.checkArgument(notification.getMessageContent().getTextContent() != null); Preconditions.checkArgument(notification.getMessageContent().getHtmlContent() != null); // Add the HTML component of the Alert Multipart mp = new MimeMultipart(); MimeBodyPart textPart = new MimeBodyPart(); Text textContent = notification.getMessageContent().getTextContent(); if (textContent != null) { textPart.setContent(textContent.getValue(), "text/plain"); mp.addBodyPart(textPart); } MimeBodyPart htmlPart = new MimeBodyPart(); Text htmlContent = notification.getMessageContent().getHtmlContent(); if (htmlContent != null) { htmlPart.setContent(htmlContent.getValue(), "text/html"); mp.addBodyPart(htmlPart); } mimeMessage.setText(notification.getMessageContent().getTextContent().getValue()); mimeMessage.setContent(mp); } // GAE Queues all messages for sending as soon as possible. Transport.send(mimeMessage); DateTime nowDateTime = new DateTime(DateTimeZone.UTC); logger.info("Alert (To: " + notification.getRecipient().getRecipientAddress() + ") sent to GAE Email Service at " + nowDateTime); // ////////////////////////////////// // Update the Notification in the datastore... // ////////////////////////////////// MetaData metaData = notification.getMetaData(); MetaDataEntity metaDataEntity = new MetaDataEntity(metaData).withSendStatus(SendStatus.SENT) .withSendDateTime(nowDateTime).withLastSendAttemptDate(nowDateTime); NotificationEntity notificationEntity = NotificationEntity.createNotificationEntityWithId(notification) .withMetaData(metaDataEntity); this.notificationDao.save(notificationEntity); } catch (MessagingException me) { try { // If there's an address exception, then store the stack trace // into the Datastore for future purposes. DateTime nowDateTime = new DateTime(DateTimeZone.UTC); String error = me.toString() + "\n\n" + getStackTrace(me); MetaData metaData = notification.getMetaData(); MetaDataEntity metaDataEntity = new MetaDataEntity(metaData).withSendStatus(SendStatus.ERROR) .withStatusReason(new Text(error)).withLastSendAttemptDate(nowDateTime); NotificationEntity notificationEntity = NotificationEntity .createNotificationEntityWithId(notification).withMetaData(metaDataEntity); this.notificationDao.save(notificationEntity); } catch (Exception e) { throw new RuntimeException("Unable to update Notification with error information!", e); } // Throw this to a higher level since this method cannot function // with an invalid address throw new RuntimeException(me); } }
From source file:com.sappenin.utils.appengine.data.dao.base.AbstractObjectifyDao.java
License:Apache License
/** * Doesn't allow an entity with a non-null Key<T> to be saved, and optinoally updates the updatedDateTime to be * "now" if {@code touchUpdateDateTime} is set to {@code true}. *///from www . j a v a 2 s .c om @Override public void save(final T entity, final boolean touchUpdateDateTime) { Preconditions.checkNotNull(entity); Preconditions.checkArgument(entity.getKey() != null, "Cannot #save an Entity that has no Key. Call the Dao's #createNew function instead."); ObjectifyService.ofy().transact(new VoidWork() { @Override public void vrun() { final Optional<T> optExisting = findByTypedKey(entity.getTypedKey()); if (!optExisting.isPresent()) { throw new DuplicateEntityException( "Unable to save an existing " + entity.getClass().getSimpleName() + " with id \"" + entity.getId() + "\" because it does not exist in the Datastore!"); } if (touchUpdateDateTime) { entity.setUpdateDateTime(DateTime.now(DateTimeZone.UTC)); } ObjectifyService.ofy().save().entity(entity).now(); } }); }
From source file:com.sappenin.utils.appengine.data.model.base.AbstractEntity.java
License:Apache License
/** * Default Constructor (for Date initialization) */// w w w . ja v a2s . c o m public AbstractEntity() { // Use the Setter in case a particular class wants to override these // values for indexing setCreationDateTime(DateTime.now(DateTimeZone.UTC)); setUpdateDateTime(DateTime.now(DateTimeZone.UTC)); }
From source file:com.sappenin.utils.rest.model.meta.impl.AbstractDateTimeMeta.java
License:Apache License
/** * No Arg Constructor. In certain cases, such as when a client is going to create a new server-side resource, the * meta information is not important, so this constructor variant may be used. * /*from www .j a v a 2 s .c om*/ * @deprecated Meta objects should be immutable, so this version is slated for removal in a future release. */ @Deprecated public AbstractDateTimeMeta() { this.creationDateTime = DateTime.now(DateTimeZone.UTC); this.updateDateTime = DateTime.now(DateTimeZone.UTC); }
From source file:com.shekar.msrp.utils.DateUtils.java
License:Apache License
/** * Encode a long date to string value in Z format (see RFC 3339) * //from w w w . jav a2 s .c o m * @param date Date in milliseconds * @return String */ public static String encodeDate(long date) { // Apply RFC3339 format using JODA-TIME DateTime dateTime = new DateTime(date, DateTimeZone.UTC); DateTimeFormatter dateFormatter = ISODateTimeFormat.dateTime(); String dateString = dateFormatter.print(dateTime); System.out.println("Server side date (RFC 3339): " + dateString); return dateString; }
From source file:com.simplymeasured.hive.UDFISO8601ToTimestamp.java
License:Apache License
public long evaluate(String iso8601Date) { DateTime dateTime = new DateTime(iso8601Date, DateTimeZone.UTC); return dateTime.getMillis() / 1000; }
From source file:com.smoketurner.notification.api.Notification.java
License:Apache License
/** * Constructor/*from ww w . j a v a 2 s. com*/ * * @param id * @param idStr * @param category * @param message * @param createdAt * @param unseen * @param properties * @param notifications */ @JsonCreator private Notification(@JsonProperty("id") final Optional<Long> id, @JsonProperty("id_str") final Optional<String> idStr, @JsonProperty("category") final String category, @JsonProperty("message") final String message, @JsonProperty("created_at") final Optional<DateTime> createdAt, @JsonProperty("unseen") final Optional<Boolean> unseen, @JsonProperty("properties") final Optional<Map<String, String>> properties, @JsonProperty("notifications") final Optional<Collection<Notification>> notifications) { this.id = id.orElse(null); this.idStr = idStr.orElse(null); this.category = category; this.message = message; this.createdAt = createdAt.orElse(DateTime.now(DateTimeZone.UTC)); this.unseen = unseen.orElse(null); this.properties = properties.orElse(Collections.<String, String>emptyMap()); this.notifications = notifications.orElse(null); }
From source file:com.smoketurner.notification.application.riak.NotificationListConverter.java
License:Apache License
public static Notification convert(@Nonnull final NotificationPB notification) { final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); notification.getPropertyList().forEach(property -> builder.put(property.getKey(), property.getValue())); return Notification.builder().withId(notification.getId()).withCategory(notification.getCategory()) .withMessage(notification.getMessage()) .withCreatedAt(new DateTime(notification.getCreatedAt(), DateTimeZone.UTC)) .withProperties(builder.build()).build(); }
From source file:com.smoketurner.notification.application.store.NotificationStore.java
License:Apache License
/** * Return the current date time (overridden in tests) * * @return the current date time */ @VisibleForTesting public DateTime now() { return DateTime.now(DateTimeZone.UTC); }