// if the criteria payload did specify the "variants" field,
// we look up each of those mentioned variants, by their "variantID":
if (variantIDs != null) {
for (String variantID : variantIDs) {
Variant variant = genericVariantService.findByVariantID(variantID);
// does the variant exist ?
if (variant != null) {
variants.add(variant);
}
}
} else {
// No specific variants have been requested,
// we get all the variants, from the given PushApplicationEntity:
variants.addAll(pushApplication.getVariants());
}
// all possible criteria
final List<String> categories = criteria.getCategories();
final List<String> aliases = criteria.getAliases();
final List<String> deviceTypes = criteria.getDeviceTypes();
// TODO: DISPATCH TO A QUEUE .....
for (final Variant variant : variants) {
if (variant instanceof SimplePushVariant && message.getSimplePush() != null) {
// SP needs the 'simple-push' be present, the 'message' (aka data) has no meanings here
final PushNotificationSender simplePushSender = senders.select(new SenderTypeLiteral(SimplePushVariant.class)).get();
final List<String> tokenPerVariant = clientInstallationService.findAllDeviceTokenForVariantIDByCriteria(variant.getVariantID(), categories, aliases, deviceTypes);
final SenderServiceCallback senderCallback = new SenderServiceCallback(variant, tokenPerVariant.size(), pushMessageInformation);
simplePushSender.sendPushMessage(variant, tokenPerVariant, message, senderCallback);
} else if (!(variant instanceof SimplePushVariant) && message.getData() != null) {
// all other variants require 'message' (aka data) to be present
final List<String> tokenPerVariant = clientInstallationService.findAllDeviceTokenForVariantIDByCriteria(variant.getVariantID(), categories, aliases, deviceTypes);
senders.select(new SenderTypeLiteral(variant.getClass())).get()
.sendPushMessage(variant, tokenPerVariant, message, new SenderServiceCallback(variant, tokenPerVariant.size(), pushMessageInformation));
}
}
}