// 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();
// let's check if we actually have data for native platforms!
if (message.getData() != null) {
// TODO: DISPATCH TO A QUEUE .....
for (final Variant variant : variants) {
final List<String> tokenPerVariant = clientInstallationService.findAllDeviceTokenForVariantIDByCriteria(variant.getVariantID(), categories, aliases, deviceTypes);
// extracting the size for our counters
final int tokenSize = tokenPerVariant.size();
senders.select(new SenderTypeLiteral(variant.getClass())).get().sendPushMessage(variant, tokenPerVariant, message, new NotificationSenderCallback() {
@Override
public void onSuccess() {
logger.log(Level.FINE, String.format("Sent '%s' message to '%d' devices", variant.getType().getTypeName(), tokenSize));
updateStatusOfPushMessageInformation(pushMessageInformation, variant.getVariantID(), tokenSize, Boolean.TRUE);
}
@Override
public void onError(final String reason) {
logger.log(Level.WARNING, String.format("Error on '%s' delivery", variant.getType().getTypeName()));
updateStatusOfPushMessageInformation(pushMessageInformation, variant.getVariantID(), tokenSize, Boolean.FALSE, reason);
}
});
}
}