Created
July 11, 2014 14:33
-
-
Save matzew/95471393bc2a485fce10 to your computer and use it in GitHub Desktop.
Vivek's patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: api/Installation.java | |
=================================================================== | |
--- api/Installation.java (revision 619) | |
+++ api/Installation.java (working copy) | |
@@ -123,4 +123,8 @@ | |
String getSimplePushEndpoint(); | |
+ public String getVariantID(); | |
+ | |
+ public void setVariantID(String variantID); | |
+ | |
} | |
Index: jpa/dao/impl/InstallationDaoImpl.java | |
=================================================================== | |
--- jpa/dao/impl/InstallationDaoImpl.java (revision 619) | |
+++ jpa/dao/impl/InstallationDaoImpl.java (working copy) | |
@@ -24,6 +24,7 @@ | |
import javax.persistence.Query; | |
+import org.jboss.aerogear.unifiedpush.api.Installation; | |
import org.jboss.aerogear.unifiedpush.jpa.AbstractGenericDao; | |
import org.jboss.aerogear.unifiedpush.jpa.dao.InstallationDao; | |
import org.jboss.aerogear.unifiedpush.model.AbstractVariant; | |
@@ -34,21 +35,24 @@ | |
*/ | |
public class InstallationDaoImpl extends AbstractGenericDao<InstallationImpl, String> implements InstallationDao { | |
- return getSingleResultForQuery(createQuery("select installation from " + AbstractVariant.class.getSimpleName() + | |
- " abstractVariant join abstractVariant.installations installation" + | |
- " where abstractVariant.variantID = :variantID" + | |
- " and installation.deviceToken = :deviceToken") | |
- .setParameter("variantID", variantID) | |
- .setParameter("deviceToken", deviceToken)); | |
- } | |
+ return getSingleResultForQuery(createQuery("from " + InstallationImpl.class.getSimpleName() + " where variantID = :variantID and deviceToken = :deviceToken") | |
+ .setParameter("variantID", variantID).setParameter("deviceToken", deviceToken)); | |
+ } | |
/** | |
* Usage: Clean UP: | |
@@ -169,4 +173,11 @@ | |
private boolean isListEmpty(List list) { | |
return (list != null && !list.isEmpty()); | |
} | |
+ | |
+ @Override | |
+ public List<Installation> findInstallationsByVariant(String variantID, String developer) { | |
+ return entityManager | |
+ .createQuery("select i from Variant v join v.installations i where v.variantID = :variantID and v.developer = :developer", Installation.class) | |
+ .setParameter("variantID", variantID).setParameter("developer", developer).getResultList(); | |
+ } | |
} | |
Index: jpa/dao/InstallationDao.java | |
=================================================================== | |
--- jpa/dao/InstallationDao.java (revision 619) | |
+++ jpa/dao/InstallationDao.java (working copy) | |
@@ -19,6 +19,7 @@ | |
import java.util.List; | |
import java.util.Set; | |
+import org.jboss.aerogear.unifiedpush.api.Installation; | |
import org.jboss.aerogear.unifiedpush.jpa.GenericDao; | |
import org.jboss.aerogear.unifiedpush.model.InstallationImpl; | |
@@ -51,4 +52,15 @@ | |
* Query all pushEndpoint URLs for the given SimplePush variant, by respecting a few criteria arguments (categories, aliases and deviceTypes) | |
*/ | |
List<String> findAllPushEndpointURLsForVariantIDByCriteria(String variantID, List<String> categories, List<String> aliases, List<String> deviceTypes); | |
+ | |
+ /** | |
+ * Find all installations for the variant specified. | |
+ * | |
+ * @param variantID | |
+ * the id of the variant to find the installations for | |
+ * @param developer | |
+ * the developer | |
+ * @return all installations found or empty list | |
+ */ | |
+ List<Installation> findInstallationsByVariant(String variantID, String developer); | |
} | |
Index: message/sender/APNsPushNotificationSender.java | |
=================================================================== | |
--- message/sender/APNsPushNotificationSender.java (revision 619) | |
+++ message/sender/APNsPushNotificationSender.java (working copy) | |
@@ -83,6 +83,9 @@ | |
service.start(); | |
Date expireDate = createFutureDateBasedOnTTL(pushMessage.getTimeToLive()); | |
+ | |
+ logger.log(Level.FINE, "Sending payload for [" + tokens.size() + "] devices to APNS"); | |
+ | |
service.push(tokens, apnsMessage, expireDate); | |
// after sending, let's ask for the inactive tokens: | |
Index: model/AbstractVariant.java | |
=================================================================== | |
--- model/AbstractVariant.java (revision 619) | |
+++ model/AbstractVariant.java (working copy) | |
@@ -30,6 +30,7 @@ | |
import javax.persistence.InheritanceType; | |
import javax.persistence.JoinColumn; | |
import javax.persistence.OneToMany; | |
+import javax.persistence.Transient; | |
import javax.validation.constraints.NotNull; | |
import javax.validation.constraints.Size; | |
@@ -37,6 +38,9 @@ | |
import org.jboss.aerogear.unifiedpush.api.VariantType; | |
import org.jboss.aerogear.unifiedpush.jpa.PersistentObject; | |
+import com.fasterxml.jackson.annotation.JsonIgnore; | |
+import com.fasterxml.jackson.annotation.JsonProperty; | |
+ | |
/** | |
* Abstract Base Class for the different supported variant types. | |
*/ | |
@@ -63,10 +67,12 @@ | |
@Column | |
private String developer; | |
- // TODO: let's do LAZY | |
- @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE) | |
- @JoinColumn(name = "variantID", referencedColumnName = "variantID") | |
- private Set<InstallationImpl> installations = new HashSet<InstallationImpl>(); | |
+ @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) | |
+ @JoinColumn(name = "variantID", referencedColumnName = "variantID") | |
+ private Set<InstallationImpl> installations = new HashSet<InstallationImpl>(); | |
+ | |
+ @Transient | |
+ /* This is a HACK to serialize an empty list of installations to UI. This ideally should be done by making changes to the UI*/ | |
+ private Set<InstallationImpl> fakeInstallations = new HashSet<InstallationImpl>(); | |
public String getName() { | |
return this.name; | |
@@ -85,6 +91,8 @@ | |
} | |
@Override | |
+ @JsonIgnore /* This is a HACK to prevent installations from getting serialized to UI. This ideally should be done by making changes to the UI*/ | |
public Set<InstallationImpl> getInstallations() { | |
return this.installations; | |
} | |
@@ -93,7 +101,13 @@ | |
this.installations = installations; | |
} | |
- public String getVariantID() { | |
+ @JsonProperty("installations") | |
+ public Set<InstallationImpl> getFakeInstallations() { | |
+ return fakeInstallations; | |
+ } | |
+ | |
+ public String getVariantID() { | |
return variantID; | |
} | |
Index: model/InstallationImpl.java | |
=================================================================== | |
--- model/InstallationImpl.java (revision 619) | |
+++ model/InstallationImpl.java (working copy) | |
@@ -23,6 +23,8 @@ | |
import java.util.List; | |
import java.util.Set; | |
+ import com.fasterxml.jackson.annotation.JsonIgnore; | |
+ | |
@Entity | |
public class InstallationImpl extends PersistentObject implements Installation { | |
private static final long serialVersionUID = 7177135979544758234L; | |
@@ -47,7 +49,10 @@ | |
private String platform; | |
@Column | |
private String simplePushEndpoint; | |
+ @Column | |
+ private String variantID; | |
+ | |
@Override | |
public boolean isEnabled() { | |
return this.enabled; | |
@@ -137,4 +142,14 @@ | |
public String getSimplePushEndpoint() { | |
return simplePushEndpoint; | |
} | |
+ | |
+ @Override | |
+ public String getVariantID() { | |
+ return variantID; | |
+ } | |
+ | |
+ @Override | |
+ public void setVariantID(String variantID) { | |
+ this.variantID = variantID; | |
+ } | |
} | |
Index: model/PushApplication.java | |
=================================================================== | |
--- model/PushApplication.java (revision 619) | |
+++ model/PushApplication.java (working copy) | |
@@ -53,22 +53,20 @@ | |
@Size(min = 1, max = 255) | |
private String developer; | |
- // TODO: let's do LAZY | |
+ | |
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE) | |
@JoinColumn | |
private Set<iOSVariant> iOSVariants = new HashSet<iOSVariant>(); | |
- // TODO: let's do LAZY | |
+ | |
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE) | |
@JoinColumn | |
private Set<AndroidVariant> androidVariants = new HashSet<AndroidVariant>(); | |
- // TODO: let's do LAZY | |
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE) | |
@JoinColumn | |
private Set<SimplePushVariant> simplePushVariants = new HashSet<SimplePushVariant>(); | |
- // TODO: let's do LAZY | |
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE) | |
@JoinColumn | |
private Set<ChromePackagedAppVariant> chromePackagedAppVariants = new HashSet<ChromePackagedAppVariant>(); | |
@@ -88,7 +86,7 @@ | |
public void setDescription(final String description) { | |
this.description = description; | |
} | |
- | |
+ | |
public Set<iOSVariant> getIOSVariants() { | |
return this.iOSVariants; | |
} | |
Index: rest/registry/applications/InstallationManagementEndpoint.java | |
=================================================================== | |
--- rest/registry/applications/InstallationManagementEndpoint.java (revision 619) | |
+++ rest/registry/applications/InstallationManagementEndpoint.java (working copy) | |
@@ -18,6 +18,7 @@ | |
import org.jboss.aerogear.security.auth.LoggedUser; | |
import org.jboss.aerogear.unifiedpush.api.Variant; | |
+import org.jboss.aerogear.unifiedpush.api.Installation; | |
import org.jboss.aerogear.unifiedpush.model.InstallationImpl; | |
import org.jboss.aerogear.unifiedpush.service.ClientInstallationService; | |
import org.jboss.aerogear.unifiedpush.service.GenericVariantService; | |
@@ -37,6 +38,8 @@ | |
import javax.ws.rs.core.MediaType; | |
import javax.ws.rs.core.Response; | |
+import java.util.List; | |
+ | |
@Stateless | |
@TransactionAttribute | |
@Path("/applications/{variantID}/installations/") | |
@@ -57,14 +60,13 @@ | |
@Produces(MediaType.APPLICATION_JSON) | |
public Response findInstallations(@PathParam("variantID") String variantId) { | |
- //Find the variant using the variantID | |
- Variant variant = genericVariantService.findByVariantIDForDeveloper(variantId, loginName.get()); | |
+ // Find the installations using the variantID | |
+ List<Installation> installations = clientInstallationService.findInstallationsByVariant(variantId, loginName.get()); | |
+ if (installations.isEmpty()) { | |
+ return Response.status(Response.Status.NOT_FOUND).entity("Could not find requested Variant").build(); | |
+ } | |
- if (variant == null) { | |
- return Response.status(Response.Status.NOT_FOUND).entity("Could not find requested Variant").build(); | |
- } | |
- | |
- return Response.ok(variant.getInstallations()).build(); | |
+ return Response.ok(installations).build(); | |
} | |
@GET | |
Index: rest/registry/installations/InstallationRegistrationEndpoint.java | |
=================================================================== | |
--- rest/registry/installations/InstallationRegistrationEndpoint.java (revision 619) | |
+++ rest/registry/installations/InstallationRegistrationEndpoint.java (working copy) | |
@@ -99,9 +99,8 @@ | |
if (installation == null) { | |
logger.fine("Performing client registration for: " + entity.getDeviceToken()); | |
// store the installation: | |
- entity = clientInstallationService.addInstallation(entity); | |
- // add installation to the matching variant | |
- genericVariantService.addInstallation(variant, entity); | |
+ entity.setVariantID(variant.getVariantID()); | |
+ entity = clientInstallationService.addInstallation(entity); | |
} else { | |
// We only update the metadata, if the device is enabled: | |
if (installation.isEnabled()) { | |
Index: service/ClientInstallationService.java | |
=================================================================== | |
--- service/ClientInstallationService.java (revision 619) | |
+++ service/ClientInstallationService.java (working copy) | |
@@ -19,6 +19,7 @@ | |
import java.util.List; | |
import java.util.Set; | |
+import org.jboss.aerogear.unifiedpush.api.Installation; | |
import org.jboss.aerogear.unifiedpush.model.InstallationImpl; | |
/** | |
@@ -72,6 +73,18 @@ | |
*/ | |
InstallationImpl findInstallationForVariantByDeviceToken(String variantID, String deviceToken); | |
+ /** | |
+ * Find all installations for the variant specified. | |
+ * | |
+ * @param variantId | |
+ * the id of the variant to find the installations for | |
+ * @param developer | |
+ * the developer | |
+ * @return all installations found or empty list | |
+ */ | |
+ | |
+ List<Installation> findInstallationsByVariant(String variantId, String developer); | |
+ | |
// =================== SENDER API =================== | |
/** | |
Index: service/impl/ClientInstallationServiceImpl.java | |
=================================================================== | |
--- service/impl/ClientInstallationServiceImpl.java (revision 619) | |
+++ service/impl/ClientInstallationServiceImpl.java (working copy) | |
@@ -16,6 +16,7 @@ | |
*/ | |
package org.jboss.aerogear.unifiedpush.service.impl; | |
+import org.jboss.aerogear.unifiedpush.api.Installation; | |
import org.jboss.aerogear.unifiedpush.jpa.dao.InstallationDao; | |
import org.jboss.aerogear.unifiedpush.model.InstallationImpl; | |
import org.jboss.aerogear.unifiedpush.service.ClientInstallationService; | |
@@ -98,6 +99,11 @@ | |
return dao.findInstallationForVariantByDeviceToken(variantID, deviceToken); | |
} | |
+ @Override | |
+ public List<Installation> findInstallationsByVariant(String variantId, String developer) { | |
+ return dao.findInstallationsByVariant(variantId, developer); | |
+ } | |
+ | |
// ===================================================================== | |
// ======== Various finder services for the Sender REST API ============ | |
// ===================================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment