From 96f3862ab0f73553982b4ea0473431b0425fb681 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 13 Aug 2015 11:52:14 +0200 Subject: [PATCH] Revert "Updating JPSInstallationDao to use variant.id instead of variantID" This reverts commit 75ff5cdad7ca1561ab62ccd5ac3bf0a0b0826c5d. --- .../jpa/dao/impl/JPAInstallationDao.java | 8 ++-- .../unifiedpush/message/TokenLoader.java | 2 +- .../impl/ClientInstallationServiceImpl.java | 4 +- .../service/impl/PushSearchServiceImpl.java | 11 ++--- .../ClientInstallationServiceTest.java | 41 ++++++++++--------- 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/model/jpa/src/main/java/org/jboss/aerogear/unifiedpush/jpa/dao/impl/JPAInstallationDao.java b/model/jpa/src/main/java/org/jboss/aerogear/unifiedpush/jpa/dao/impl/JPAInstallationDao.java index eecbc011fe..dad0ec0621 100644 --- a/model/jpa/src/main/java/org/jboss/aerogear/unifiedpush/jpa/dao/impl/JPAInstallationDao.java +++ b/model/jpa/src/main/java/org/jboss/aerogear/unifiedpush/jpa/dao/impl/JPAInstallationDao.java @@ -42,11 +42,11 @@ public class JPAInstallationDao extends JPABaseDao impleme private static final String FIND_ALL_DEVICES_FOR_VARIANT_QUERY = "select distinct installation.deviceToken" + " from Installation installation" + " left join installation.categories c " - + " join installation.variant abstractVariant where abstractVariant.id = :variantID AND installation.enabled = true"; + + " join installation.variant abstractVariant where abstractVariant.variantID = :variantID AND installation.enabled = true"; private static final String FIND_INSTALLATIONS = "FROM Installation installation" + " JOIN installation.variant v" - + " WHERE v.id = :variantID"; + + " WHERE v.variantID = :variantID"; public PageResult findInstallationsByVariantForDeveloper(String variantID, String developer, Integer page, Integer pageSize, String search) { @@ -95,7 +95,7 @@ public Installation findInstallationForVariantByDeviceToken(String variantID, St return getSingleResultForQuery(createQuery("select installation from Installation installation " + " join installation.variant abstractVariant" + - " where abstractVariant.id = :variantID" + + " where abstractVariant.variantID = :variantID" + " and installation.deviceToken = :deviceToken") .setParameter("variantID", variantID) .setParameter("deviceToken", deviceToken)); @@ -111,7 +111,7 @@ public List findInstallationsForVariantByDeviceTokens(String varia return createQuery("select installation from Installation installation " + " join installation.variant abstractVariant " + - " where abstractVariant.id = :variantID" + + " where abstractVariant.variantID = :variantID" + " and installation.deviceToken IN :deviceTokens") .setParameter("variantID", variantID) .setParameter("deviceTokens", deviceTokens) diff --git a/push/sender/src/main/java/org/jboss/aerogear/unifiedpush/message/TokenLoader.java b/push/sender/src/main/java/org/jboss/aerogear/unifiedpush/message/TokenLoader.java index 78918652e2..4cf0cb2057 100644 --- a/push/sender/src/main/java/org/jboss/aerogear/unifiedpush/message/TokenLoader.java +++ b/push/sender/src/main/java/org/jboss/aerogear/unifiedpush/message/TokenLoader.java @@ -110,7 +110,7 @@ public void loadAndQueueTokenBatch(@Observes @Dequeue MessageHolderWithVariants for (Variant variant : variants) { ResultsStream tokenStream = - clientInstallationService.findAllDeviceTokenForVariantIDByCriteria(variant.getId(), categories, aliases, deviceTypes, configuration.tokensToLoad(), lastTokenFromPreviousBatch) + clientInstallationService.findAllDeviceTokenForVariantIDByCriteria(variant.getVariantID(), categories, aliases, deviceTypes, configuration.tokensToLoad(), lastTokenFromPreviousBatch) .fetchSize(configuration.batchSize()) .executeQuery(); diff --git a/service/src/main/java/org/jboss/aerogear/unifiedpush/service/impl/ClientInstallationServiceImpl.java b/service/src/main/java/org/jboss/aerogear/unifiedpush/service/impl/ClientInstallationServiceImpl.java index 8f37e650ce..db46ef23f5 100644 --- a/service/src/main/java/org/jboss/aerogear/unifiedpush/service/impl/ClientInstallationServiceImpl.java +++ b/service/src/main/java/org/jboss/aerogear/unifiedpush/service/impl/ClientInstallationServiceImpl.java @@ -60,7 +60,7 @@ public class ClientInstallationServiceImpl implements ClientInstallationService public void addInstallation(Variant variant, Installation entity) { // does it already exist ? - Installation installation = this.findInstallationForVariantByDeviceToken(variant.getId(), entity.getDeviceToken()); + Installation installation = this.findInstallationForVariantByDeviceToken(variant.getVariantID(), entity.getDeviceToken()); // Needed for the Admin UI Only. Help for setting up Routes entity.setPlatform(variant.getType().getTypeName()); @@ -90,7 +90,7 @@ public void addInstallations(Variant variant, List installations) return; } - Set existingTokens = installationDao.findAllDeviceTokenForVariantID(variant.getId()); + Set existingTokens = installationDao.findAllDeviceTokenForVariantID(variant.getVariantID()); // clear out: installationDao.flushAndClear(); diff --git a/service/src/main/java/org/jboss/aerogear/unifiedpush/service/impl/PushSearchServiceImpl.java b/service/src/main/java/org/jboss/aerogear/unifiedpush/service/impl/PushSearchServiceImpl.java index 10cd855565..09e7170aba 100644 --- a/service/src/main/java/org/jboss/aerogear/unifiedpush/service/impl/PushSearchServiceImpl.java +++ b/service/src/main/java/org/jboss/aerogear/unifiedpush/service/impl/PushSearchServiceImpl.java @@ -143,13 +143,10 @@ private List wrapApplicationVariant(List ap private List wrapApplication(List pushMessageInformations) { final List applications = new ArrayList(pushMessageInformations.size()); for (PushMessageInformation pushMessageInformation : pushMessageInformations) { - final PushApplication pa = pushApplicationDao.findByPushApplicationID(pushMessageInformation.getPushApplicationId()); - if (pa != null) { - applications.add(new Application(pa.getName(), - pushMessageInformation.getPushApplicationId(), - pushMessageInformation.getTotalReceivers(), - pushMessageInformation.getSubmitDate())); - } + String applicationName = pushApplicationDao.findByPushApplicationID(pushMessageInformation.getPushApplicationId()).getName(); + final Application application = new Application(applicationName, pushMessageInformation.getPushApplicationId(), pushMessageInformation.getTotalReceivers(), pushMessageInformation.getSubmitDate()); + applications.add(application); + } return applications; } diff --git a/service/src/test/java/org/jboss/aerogear/unifiedpush/service/ClientInstallationServiceTest.java b/service/src/test/java/org/jboss/aerogear/unifiedpush/service/ClientInstallationServiceTest.java index 352bd5953d..c516fe7aff 100644 --- a/service/src/test/java/org/jboss/aerogear/unifiedpush/service/ClientInstallationServiceTest.java +++ b/service/src/test/java/org/jboss/aerogear/unifiedpush/service/ClientInstallationServiceTest.java @@ -73,8 +73,8 @@ public void testLowerCaseForIOS() throws IOException { clientInstallationService.addInstallation(iOSVariant, device); - assertThat(clientInstallationService.findInstallationForVariantByDeviceToken(iOSVariant.getId(), deviceToken)).isNull(); - assertThat(clientInstallationService.findInstallationForVariantByDeviceToken(iOSVariant.getId(), deviceToken.toLowerCase())).isNotNull(); + assertThat(clientInstallationService.findInstallationForVariantByDeviceToken(iOSVariant.getVariantID(), deviceToken)).isNull(); + assertThat(clientInstallationService.findInstallationForVariantByDeviceToken(iOSVariant.getVariantID(), deviceToken.toLowerCase())).isNotNull(); } @Test @@ -85,7 +85,7 @@ public void registerDevices() { device.setDeviceToken(deviceToken); clientInstallationService.addInstallation(androidVariant, device); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null)).hasSize(1); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null)).hasSize(1); // apply some update: Installation otherDevice = new Installation(); @@ -93,7 +93,7 @@ public void registerDevices() { otherDevice.setAlias("username"); clientInstallationService.addInstallation(androidVariant, otherDevice); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null)).hasSize(2); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null)).hasSize(2); } @Test @@ -103,14 +103,15 @@ public void updateDevice() { device.setDeviceToken(deviceToken); clientInstallationService.addInstallation(androidVariant, device); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null)).hasSize(1); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null)).hasSize(1); + // apply some update: Installation sameDeviceDifferentRegistration = new Installation(); sameDeviceDifferentRegistration.setDeviceToken(deviceToken); sameDeviceDifferentRegistration.setAlias("username"); clientInstallationService.addInstallation(androidVariant, sameDeviceDifferentRegistration); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null)).hasSize(1); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null)).hasSize(1); } @Test @@ -140,7 +141,7 @@ public void importDevicesWithAndWithoutTokenDuplicates() { clientInstallationService.addInstallations(androidVariant, devices); // but they got ignored: - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null)).hasSize(NUMBER_OF_INSTALLATIONS); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null)).hasSize(NUMBER_OF_INSTALLATIONS); // add just one device: device = new Installation(); @@ -149,7 +150,7 @@ public void importDevicesWithAndWithoutTokenDuplicates() { // run the importer again clientInstallationService.addInstallations(androidVariant, devices); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null)).hasSize(NUMBER_OF_INSTALLATIONS + 1); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null)).hasSize(NUMBER_OF_INSTALLATIONS + 1); } @Test @@ -159,11 +160,11 @@ public void createAndDeleteDeviceByToken() { device.setDeviceToken(generateFakedDeviceTokenString()); clientInstallationService.addInstallation(androidVariant, device); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null)).hasSize(1); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null)).hasSize(1); final String singleToken = device.getDeviceToken(); - clientInstallationService.removeInstallationForVariantByDeviceToken(androidVariant.getId(), singleToken); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null)).isEmpty(); + clientInstallationService.removeInstallationForVariantByDeviceToken(androidVariant.getVariantID(), singleToken); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null)).isEmpty(); } @Test @@ -179,7 +180,7 @@ public void importDevicesWithoutDuplicates() { } clientInstallationService.addInstallations(androidVariant, devices); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null)).hasSize(NUMBER_OF_INSTALLATIONS); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null)).hasSize(NUMBER_OF_INSTALLATIONS); // add just one device: Installation device = new Installation(); @@ -188,7 +189,7 @@ public void importDevicesWithoutDuplicates() { // run the importer again clientInstallationService.addInstallations(androidVariant, devices); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null)).hasSize(NUMBER_OF_INSTALLATIONS + 1); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null)).hasSize(NUMBER_OF_INSTALLATIONS + 1); } @Test @@ -205,7 +206,7 @@ public void importDevices() { clientInstallationService.addInstallations(androidVariant, devices); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null)).hasSize(NUMBER_OF_INSTALLATIONS); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null)).hasSize(NUMBER_OF_INSTALLATIONS); } @Test @@ -220,7 +221,7 @@ public void findSingleDeviceTokenWithMultipleCategories() { clientInstallationService.addInstallation(androidVariant, device); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), Arrays.asList("football", "soccer"), null, null)).hasSize(1); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), Arrays.asList("football", "soccer"), null, null)).hasSize(1); } @Test @@ -236,7 +237,7 @@ public void findSingleDeviceTokenWithMultipleCategoriesAndByAlias() { clientInstallationService.addInstallation(androidVariant, device); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), Arrays.asList("football", "soccer"), Arrays.asList("root"), null)).hasSize(1); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), Arrays.asList("football", "soccer"), Arrays.asList("root"), null)).hasSize(1); } @Test @@ -260,7 +261,7 @@ public void findDeviceTokensWithSingleCategory() { device3.setCategories(categories); clientInstallationService.addInstallation(androidVariant, device3); - final List queriedTokens = findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), Arrays.asList("soccer"), null, null); + final List queriedTokens = findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), Arrays.asList("soccer"), null, null); assertThat(queriedTokens).hasSize(2); assertThat(queriedTokens).contains( @@ -290,7 +291,7 @@ public void findDeviceTokensWithMultipleCategories() { device3.setCategories(categories); clientInstallationService.addInstallation(androidVariant, device3); - final List queriedTokens = findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), Arrays.asList("soccer", "football"), null, null); + final List queriedTokens = findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), Arrays.asList("soccer", "football"), null, null); assertThat(queriedTokens).hasSize(3); assertThat(queriedTokens).contains( @@ -321,7 +322,7 @@ public void findDeviceTokensWithoutAnyCriteria() { device3.setCategories(categories); clientInstallationService.addInstallation(androidVariant, device3); - final List queriedTokens = findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null); + final List queriedTokens = findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null); assertThat(queriedTokens).hasSize(3); assertThat(queriedTokens).contains( @@ -346,7 +347,7 @@ public void findDeviceTokensByAlias() { otherDevice.setAlias("root"); clientInstallationService.addInstallation(androidVariant, otherDevice); - assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, Arrays.asList("root"), null)).hasSize(2); + assertThat(findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, Arrays.asList("root"), null)).hasSize(2); }