@Override public boolean isValid(Installation installation, ConstraintValidatorContext context) { final String deviceToken = installation.getDeviceToken(); if (installation.getVariant() == null || installation.getVariant().getType() == null || deviceToken == null) { return false; } final VariantType type = installation.getVariant().getType(); return isValidDeviceTokenForVariant(deviceToken, type); }
@Override public boolean isValid(Installation installation, ConstraintValidatorContext context) { final String deviceToken = installation.getDeviceToken(); if (installation.getVariant() == null || installation.getVariant().getType() == null || deviceToken == null) { return false; } final VariantType type = installation.getVariant().getType(); return isValidDeviceTokenForVariant(deviceToken, type); }
@Override @Asynchronous public void unsubscribeOldTopics(Installation installation) { FCMTopicManager topicManager = new FCMTopicManager((AndroidVariant) installation.getVariant()); Set<String> oldCategories = topicManager.getSubscribedCategories(installation); // Remove current categories from the set of old ones oldCategories.removeAll(convertToNames(installation.getCategories())); // Remove global variant topic because we don't want to unsubscribe it oldCategories.remove(installation.getVariant().getVariantID()); for (String categoryName : oldCategories) { topicManager.unsubscribe(installation, categoryName); } }
@Override public void updateInstallation(Installation installationToUpdate, Installation postedInstallation) { // copy the "updateable" values: mergeCategories(installationToUpdate, postedInstallation.getCategories()); installationToUpdate.setDeviceToken(postedInstallation.getDeviceToken()); installationToUpdate.setAlias(postedInstallation.getAlias()); installationToUpdate.setDeviceType(postedInstallation.getDeviceType()); installationToUpdate.setOperatingSystem(postedInstallation .getOperatingSystem()); installationToUpdate.setOsVersion(postedInstallation.getOsVersion()); installationToUpdate.setEnabled(postedInstallation.isEnabled()); installationToUpdate.setPlatform(postedInstallation.getPlatform()); // update it: updateInstallation(installationToUpdate); // unsubscribe Android devices from topics that device should no longer be subscribed to if (installationToUpdate.getVariant().getType() == VariantType.ANDROID) { unsubscribeOldTopics(installationToUpdate); } }