Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #631 from danbev/revert-variantID-agpush-1491
Browse files Browse the repository at this point in the history
Revert "Updating JPSInstallationDao to use variant.id instead of vari…
  • Loading branch information
edewit committed Aug 14, 2015
2 parents 7ac7422 + 96f3862 commit b41d7f6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public class JPAInstallationDao extends JPABaseDao<Installation, String> 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<Installation, Count> findInstallationsByVariantForDeveloper(String variantID, String developer, Integer page, Integer pageSize, String search) {

Expand Down Expand Up @@ -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));
Expand All @@ -111,7 +111,7 @@ public List<Installation> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void loadAndQueueTokenBatch(@Observes @Dequeue MessageHolderWithVariants

for (Variant variant : variants) {
ResultsStream<String> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -90,7 +90,7 @@ public void addInstallations(Variant variant, List<Installation> installations)
return;
}

Set<String> existingTokens = installationDao.findAllDeviceTokenForVariantID(variant.getId());
Set<String> existingTokens = installationDao.findAllDeviceTokenForVariantID(variant.getVariantID());

// clear out:
installationDao.flushAndClear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,10 @@ private List<ApplicationVariant> wrapApplicationVariant(List<PushApplication> ap
private List<Application> wrapApplication(List<PushMessageInformation> pushMessageInformations) {
final List<Application> applications = new ArrayList<Application>(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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -85,15 +85,15 @@ 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();
otherDevice.setDeviceToken(generateFakedDeviceTokenString());
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
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -260,7 +261,7 @@ public void findDeviceTokensWithSingleCategory() {
device3.setCategories(categories);
clientInstallationService.addInstallation(androidVariant, device3);

final List<String> queriedTokens = findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), Arrays.asList("soccer"), null, null);
final List<String> queriedTokens = findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), Arrays.asList("soccer"), null, null);

assertThat(queriedTokens).hasSize(2);
assertThat(queriedTokens).contains(
Expand Down Expand Up @@ -290,7 +291,7 @@ public void findDeviceTokensWithMultipleCategories() {
device3.setCategories(categories);
clientInstallationService.addInstallation(androidVariant, device3);

final List<String> queriedTokens = findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), Arrays.asList("soccer", "football"), null, null);
final List<String> queriedTokens = findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), Arrays.asList("soccer", "football"), null, null);

assertThat(queriedTokens).hasSize(3);
assertThat(queriedTokens).contains(
Expand Down Expand Up @@ -321,7 +322,7 @@ public void findDeviceTokensWithoutAnyCriteria() {
device3.setCategories(categories);
clientInstallationService.addInstallation(androidVariant, device3);

final List<String> queriedTokens = findAllDeviceTokenForVariantIDByCriteria(androidVariant.getId(), null, null, null);
final List<String> queriedTokens = findAllDeviceTokenForVariantIDByCriteria(androidVariant.getVariantID(), null, null, null);

assertThat(queriedTokens).hasSize(3);
assertThat(queriedTokens).contains(
Expand All @@ -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);
}


Expand Down

0 comments on commit b41d7f6

Please sign in to comment.