public ApplicationVariant(PushApplication application, Variant variant) { this.applicationID = application.getPushApplicationID(); this.applicationName = application.getName(); this.variant = variant; }
@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 void onSuccess() { logger.debug("Sent '{}' message to '{}' devices", variant.getType().getTypeName(), tokenSize); }
@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); } }
private void storeInstallationAndSetReferences(Variant variant, Installation entity) { // ensure lower case for iOS if (variant.getType() == VariantType.IOS) { entity.setDeviceToken(entity.getDeviceToken().toLowerCase()); } // set reference entity.setVariant(variant); // update attached categories mergeCategories(entity, entity.getCategories()); // store Installation entity installationDao.create(entity); } }
private void putDeviceCountIntoResponseHeaders(PushApplication app, ResponseBuilder response) { long appCount = 0; for (Variant variant : app.getVariants()) { long variantCount = installationDao.getNumberOfDevicesForVariantID(variant.getVariantID()); appCount += variantCount; response.header("deviceCount_variant_" + variant.getVariantID(), variantCount); } response.header("deviceCount_app_" + app.getPushApplicationID(), appCount); }
public VariantErrorStatus(final FlatPushMessageInformation pushMessageInformation, final Variant variant, final String errorReason) { this.pushMessageVariantId = new StringBuilder(pushMessageInformation.getId()).append(':').append(variant.getVariantID()).toString(); this.variantID = variant.getVariantID(); this.pushJobId = pushMessageInformation.getId(); this.errorReason = errorReason; this.pushMessageInformation = pushMessageInformation; this.variant = variant; }
@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); } }
private String extractConnectionKey(final iOSVariant iOSVariant) { final StringBuilder sb = new StringBuilder() .append(iOSVariant.getVariantID()) .append(iOSVariant.isProduction() ? "-prod" : "-dev"); return sb.toString(); }
private List<Application> wrapApplication(List<FlatPushMessageInformation> pushMessageInformations) { final List<Application> applications = new ArrayList<>(pushMessageInformations.size()); pushMessageInformations.forEach(pushMessageInformation -> { final String applicationName = pushApplicationDao.findByPushApplicationID(pushMessageInformation.getPushApplicationId()).getName(); final Application application = new Application(applicationName, pushMessageInformation.getPushApplicationId(), pushMessageInformation.getSubmitDate()); applications.add(application); }); return applications; } }
@Override public void addVariant(PushApplication pushApp, Variant variant) { pushApp.getVariants().add(variant); pushApplicationDao.update(pushApp); }
/** * A simple validation util that checks if a token is present */ private static boolean hasTokenValue(Installation installation) { return installation.getDeviceToken() != null && !installation.getDeviceToken().isEmpty(); }
private HttpURLConnection prepareAuthorizedConnection(URL url) throws IOException { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded" ); conn.setRequestProperty("Authorization", "key=" + variant.getGoogleKey()); return conn; }
public void appendError(final FlatPushMessageInformation pushMessageInformation, final Variant variant, final String errorMessage) { final VariantErrorStatus ves = new VariantErrorStatus(pushMessageInformation, variant, errorMessage); pushMessageInformation.getErrors().add(ves); try { flatPushMessageInformationDao.update(pushMessageInformation); } catch (Exception e) { logger.info("Failed to save pushMessageInformation: {}", e.getMessage()); logger.debug("Details:", e); } }
@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 void onSuccess() { logger.debug("Sent '{}' message to '{}' devices", variant.getType().getTypeName(), tokenSize); }
public VariantErrorStatus(final FlatPushMessageInformation pushMessageInformation, final Variant variant, final String errorReason) { this.pushMessageVariantId = new StringBuilder(pushMessageInformation.getId()).append(':').append(variant.getVariantID()).toString(); this.variantID = variant.getVariantID(); this.pushJobId = pushMessageInformation.getId(); this.errorReason = errorReason; this.pushMessageInformation = pushMessageInformation; this.variant = variant; }
private String extractConnectionKey(final iOSVariant iOSVariant) { final StringBuilder sb = new StringBuilder() .append(iOSVariant.getVariantID()) .append(iOSVariant.isProduction() ? "-prod" : "-dev"); return sb.toString(); }
@Override public void onError(final String reason) { logger.warn("Error on '{}' delivery: {}", variant.getType().getTypeName(), reason); pushMessageMetricsService.appendError(pushMessageInformation, variant, reason); } }
@Override public void onError(final String reason) { logger.warn("Error on '{}' delivery: {}", variant.getType().getTypeName(), reason); pushMessageMetricsService.appendError(pushMessageInformation, variant, reason); } }