You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/09/05 23:11:06 UTC

[03/33] git commit: add notification entities

add notification entities


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/05d90c66
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/05d90c66
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/05d90c66

Branch: refs/heads/two-dot-o
Commit: 05d90c6680363dedd1d3aae0c7587bd7b6b4a55f
Parents: 9d2121c
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Aug 18 13:49:29 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Aug 18 13:49:29 2014 -0600

----------------------------------------------------------------------
 .../usergrid/persistence/Notification.java      | 241 +++++++++++++++++++
 .../apache/usergrid/persistence/Notifier.java   | 139 +++++++++++
 .../apache/usergrid/persistence/Receipt.java    | 133 ++++++++++
 3 files changed, 513 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/05d90c66/stack/core/src/main/java/org/apache/usergrid/persistence/Notification.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Notification.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Notification.java
new file mode 100644
index 0000000..f3b7392
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/Notification.java
@@ -0,0 +1,241 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.persistence;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.PathQuery;
+import org.apache.usergrid.persistence.TypedEntity;
+import org.apache.usergrid.persistence.annotations.EntityCollection;
+import org.apache.usergrid.persistence.annotations.EntityProperty;
+import org.apache.usergrid.persistence.entities.Device;
+
+/**
+ * The entity class for representing Notifications.
+ */
+@XmlRootElement
+public class Notification extends TypedEntity {
+
+    public static final String ENTITY_TYPE = "notification";
+
+    public static final String RECEIPTS_COLLECTION = "receipts";
+
+    public static enum State {
+        CREATED, FAILED, SCHEDULED, STARTED, FINISHED, CANCELED, EXPIRED
+    }
+
+    /** Map Notifier ID -> Payload data */
+    @EntityProperty
+    protected Map<String, Object> payloads;
+
+    /** Time processed */
+    @EntityProperty
+    protected Long queued;
+
+    /** Time send started */
+    @EntityProperty
+    protected Long started;
+
+    /** Time processed */
+    @EntityProperty
+    protected Long finished;
+
+    /** Time to deliver to provider */
+    @EntityProperty
+    protected Long deliver;
+
+    /** Time to expire the notification */
+    @EntityProperty
+    protected Long expire;
+
+    /** True if notification is canceled */
+    @EntityProperty
+    protected Boolean canceled;
+
+    /** Error message */
+    @EntityProperty
+    protected String errorMessage;
+
+    @EntityCollection(type = "receipt")
+    protected List<UUID> receipts;
+
+    /** stats (sent & errors) */
+    @EntityProperty
+    protected Map<String, Long> statistics;
+
+    /** stats (sent & errors) */
+    @EntityProperty
+    @JsonIgnore
+    protected PathQuery<Device> pathQuery;
+
+    public Notification() {
+    }
+
+    @JsonIgnore
+    public List<UUID> getReceipts() {
+        return receipts;
+    }
+
+    public void setReceipts(List<UUID> receipts) {
+        this.receipts = receipts;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Map<String, Object> getPayloads() {
+        return payloads;
+    }
+
+    public void setPayloads(Map<String, Object> payloads) {
+        this.payloads = payloads;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Long getFinished() {
+        return finished;
+    }
+
+    public void setFinished(Long finished) {
+        this.finished = finished;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Long getDeliver() {
+        return deliver;
+    }
+
+    public void setDeliver(Long deliver) {
+        this.deliver = deliver;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Long getExpire() {
+        return expire;
+    }
+
+    public void setExpire(Long expire) {
+        this.expire = expire;
+    }
+
+    @JsonIgnore
+    public boolean isExpired() {
+        return expire != null && expire > System.currentTimeMillis();
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Boolean getCanceled() {
+        return canceled;
+    }
+
+    public void setCanceled(Boolean canceled) {
+        this.canceled = canceled;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Long getStarted() {
+        return started;
+    }
+
+    public void setStarted(Long started) {
+        this.started = started;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String errorMessage) {
+        this.errorMessage = errorMessage;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Map<String, Long> getStatistics() {
+        return statistics;
+    }
+
+    public void setStatistics(Map<String, Long> statistics) {
+        this.statistics = statistics;
+    }
+
+    public void updateStatistics(long sent, long errors) {
+        if (this.statistics == null) {
+            this.statistics = new HashMap<String, Long>(2);
+            this.statistics.put("sent", sent);
+            this.statistics.put("errors", errors);
+        } else {
+            this.statistics.put("sent", sent + this.statistics.get("sent"));
+            this.statistics.put("errors",
+                    errors + this.statistics.get("errors"));
+        }
+    }
+
+    /** don't bother, I will ignore you */
+    public void setState(State ignored) {
+        // does nothing - state is derived
+    }
+
+    @EntityProperty
+    public State getState() {
+        if (getErrorMessage() != null) {
+            return State.FAILED;
+        } else if (getCanceled() == Boolean.TRUE) {
+            return State.CANCELED;
+        } else if (getFinished() != null) {
+            return State.FINISHED;
+        } else if (getStarted() != null && getDeliver() == null) {
+            return State.STARTED;
+        } else if (isExpired()) {
+            return State.EXPIRED;
+        } else if (getDeliver() != null || getQueued() != null) {
+            return State.SCHEDULED;
+        }
+        return State.CREATED;
+    }
+
+    @JsonIgnore
+    public PathQuery<Device> getPathQuery() {
+        return pathQuery;
+    }
+
+    public void setPathQuery(PathQuery<Device> pathQuery) {
+        this.pathQuery = pathQuery;
+    }
+
+    @JsonIgnore
+    public int getExpireTimeInSeconds() {
+        long expirySeconds = getExpire() != null ? getExpire() * 1000 : 0;
+        return (expirySeconds > Integer.MAX_VALUE) ? Integer.MAX_VALUE
+                : (int) expirySeconds;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Long getQueued() {
+        return queued;
+    }
+
+    public void setQueued(Long queued) {
+        this.queued = queued;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/05d90c66/stack/core/src/main/java/org/apache/usergrid/persistence/Notifier.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Notifier.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Notifier.java
new file mode 100644
index 0000000..953ec6d
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/Notifier.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.persistence;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+import org.apache.usergrid.persistence.TypedEntity;
+import org.apache.usergrid.persistence.annotations.EntityProperty;
+
+import javax.net.ssl.SSLContext;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.util.Random;
+import java.util.UUID;
+
+/**
+ * The entity class for representing Notifiers.
+ */
+@XmlRootElement
+public class Notifier extends TypedEntity {
+
+    public static final String ENTITY_TYPE = "notifier";
+
+    @EntityProperty(aliasProperty = true, unique = true, basic = true)
+    protected String name;
+
+    @EntityProperty(required = true)
+    protected String provider;
+
+    @EntityProperty
+    protected String environment;
+
+    // Apple APNs
+    @EntityProperty(indexed = false, includedInExport = false, encrypted = true)
+    protected byte[] p12Certificate;
+
+    // Apple APNs
+    @EntityProperty(indexed = false, includedInExport = false, encrypted = true)
+    protected String certificatePassword;
+
+    // Google GCM
+    @EntityProperty(indexed = false, includedInExport = false, encrypted = true)
+    protected String apiKey;
+    private javax.net.ssl.SSLContext SSLContext;
+
+    public Notifier() {
+    }
+
+    public Notifier(UUID id) {
+        uuid = id;
+    }
+
+
+
+    @Override
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public String getProvider() {
+        return provider;
+    }
+
+    public void setProvider(String provider) {
+        this.provider = provider;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public String getEnvironment() {
+        return environment;
+    }
+
+    public void setEnvironment(String environment) {
+        this.environment = environment;
+    }
+
+    @JsonIgnore
+    public boolean isProduction() {
+        return !"development".equals(environment);
+    }
+
+    @JsonIgnore
+    public byte[] getP12Certificate() {
+        return p12Certificate;
+    }
+
+    public void setP12Certificate(byte[] p12Certificate) {
+        this.p12Certificate = p12Certificate;
+    }
+
+    @JsonIgnore
+    public InputStream getP12CertificateStream() {
+        byte[] cert = getP12Certificate();
+        return cert != null ? new ByteArrayInputStream(cert) : null;
+    }
+
+    @JsonIgnore
+    public String getCertificatePassword() {
+        return certificatePassword;
+    }
+
+    public void setCertificatePassword(String certificatePassword) {
+        this.certificatePassword = certificatePassword;
+    }
+
+    @JsonIgnore
+    public String getApiKey() {
+        return apiKey;
+    }
+
+    public void setApiKey(String apiKey) {
+        this.apiKey = apiKey;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/05d90c66/stack/core/src/main/java/org/apache/usergrid/persistence/Receipt.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Receipt.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Receipt.java
new file mode 100644
index 0000000..f1c034b
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/Receipt.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.persistence;
+
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.UUID;
+import org.apache.usergrid.persistence.annotations.EntityProperty;
+
+@XmlRootElement
+public class Receipt extends TypedEntity {
+
+    public static final String ENTITY_TYPE = "receipt";
+    public static final String NOTIFICATION_CONNECTION = "notification";
+
+    /** device id **/
+    @EntityProperty
+    protected UUID deviceId;
+
+    /** data sent to provider */
+    @EntityProperty
+    protected Object payload;
+
+    /** Time sent to provider */
+    @EntityProperty
+    protected Long sent;
+
+    /** Error code */
+    @EntityProperty
+    protected Object errorCode;
+
+    /** Error message */
+    @EntityProperty
+    protected String errorMessage;
+
+    /** The push token given by the provider */
+    @EntityProperty
+    protected String notifierId;
+
+    /**
+     * UUID of the Notification that sent this - not a Connection for
+     * performance reasons
+     */
+    @EntityProperty
+    protected UUID notificationUUID;
+
+    public Receipt() {
+    }
+
+    public Receipt(UUID notificationUUID, String notifierId, Object payload,UUID deviceId) {
+        this.notificationUUID = notificationUUID;
+        this.notifierId = notifierId;
+        this.payload = payload;
+        this.setDeviceId(deviceId);
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Object getPayload() {
+        return payload;
+    }
+
+    public void setPayload(Object payload) {
+        this.payload = payload;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Long getSent() {
+        return sent;
+    }
+
+    public void setSent(Long sent) {
+        this.sent = sent;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Object getErrorCode() {
+        return errorCode;
+    }
+
+    public void setErrorCode(Object errorCode) {
+        this.errorCode = errorCode;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String errorMessage) {
+        this.errorMessage = errorMessage;
+    }
+
+    public String getNotifierId() {
+        return notifierId;
+    }
+
+    public void setNotifierId(String notifierId) {
+        this.notifierId = notifierId;
+    }
+
+    public UUID getNotificationUUID() {
+        return notificationUUID;
+    }
+
+    public void setNotificationUUID(UUID notificationUUID) {
+        this.notificationUUID = notificationUUID;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public UUID getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(UUID deviceId) {
+        this.deviceId = deviceId;
+    }
+}