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 public void delete(Variant variant) { entityManager.createQuery("delete from Installation i where i.variant in :variant") .setParameter("variant", variant).executeUpdate(); entityManager.createQuery("delete from VariantErrorStatus ves where ves.variant in :variant") .setParameter("variant", variant).executeUpdate(); Variant entity = find(variant.getId()); super.delete(entity); }
/** * Secret Reset * * @param variantId id of {@link Variant} * @return {@link Variant} with new secret * * @statuscode 200 The secret of Variant reset successfully * @statuscode 400 The requested Variant resource exists but it is not of the given type * @statuscode 404 The requested Variant resource does not exist */ @PUT @Path("/{variantId}/reset") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response resetSecret(@PathParam("variantId") String variantId) { Variant variant = variantService.findByVariantID(variantId); if (variant == null) { return Response.status(Response.Status.NOT_FOUND).entity("Could not find requested Variant").build(); } if (!type.isInstance(variant)) { return Response.status(Response.Status.BAD_REQUEST).entity("Requested Variant is of another type/platform").build(); } logger.trace("Resetting secret for: {}", variant.getName()); // generate the new 'secret' and apply it: String newSecret = UUID.randomUUID().toString(); variant.setSecret(newSecret); variantService.updateVariant(variant); return Response.ok(variant).build(); }
/** * Receives a {@link UnifiedPushMessage} and list of device tokens that the message should be sent to, selects appropriate sender implementation that * the push notifications are submitted to. * * @param msg object containing details about the payload and the related device tokens */ public void sendMessagesToPushNetwork(@Observes @Dequeue MessageHolderWithTokens msg) { final Variant variant = msg.getVariant(); final UnifiedPushMessage unifiedPushMessage = msg.getUnifiedPushMessage(); final Collection<String> deviceTokens = msg.getDeviceTokens(); logger.info("Received UnifiedPushMessage from JMS queue, will now trigger the Push Notification delivery for the %s variant ({})", variant.getType().getTypeName(), variant.getVariantID()); senders.select(new SenderTypeLiteral(variant.getType())).get() .sendPushMessage(variant, deviceTokens, unifiedPushMessage, msg.getPushMessageInformation().getId(), new SenderServiceCallback( variant, deviceTokens.size(), msg.getPushMessageInformation() ) ); }
if (deviceToken == null || !DeviceTokenValidator.isValidDeviceTokenForVariant(deviceToken, variant.getType())) { logger.trace("Invalid device token was delivered: {} for variant type: {}", deviceToken, variant.getType()); return appendAllowOriginHeader(Response.status(Status.BAD_REQUEST), request); clientInstallationService.removeInstallationForVariantByDeviceToken(variant.getVariantID(), oldToken); logger.trace("Adding new device to {} variant", variant.getName());
/** * returns application if the masterSecret is valid for the request * PushApplicationEntity */ private Variant loadVariantWhenAuthorized(final HttpServletRequest request) { // extract the pushApplicationID and its secret from the HTTP Basic // header: final String[] credentials = HttpBasicHelper.extractUsernameAndPasswordFromBasicHeader(request); final String variantID = credentials[0]; final String secret = credentials[1]; final Variant variant = genericVariantService.findByVariantID(variantID); if (variant != null && variant.getSecret().equals(secret)) { return variant; } // unauthorized... return null; } }
/** * Receives a {@link UnifiedPushMessage} and list of device tokens that the message should be sent to, selects appropriate sender implementation that * the push notifications are submitted to. * * @param msg object containing details about the payload and the related device tokens */ public void sendMessagesToPushNetwork(@Observes @Dequeue MessageHolderWithTokens msg) { final Variant variant = msg.getVariant(); final UnifiedPushMessage unifiedPushMessage = msg.getUnifiedPushMessage(); final Collection<String> deviceTokens = msg.getDeviceTokens(); logger.info("Received UnifiedPushMessage from JMS queue, will now trigger the Push Notification delivery for the %s variant ({})", variant.getType().getTypeName(), variant.getVariantID()); senders.select(new SenderTypeLiteral(variant.getType())).get() .sendPushMessage(variant, deviceTokens, unifiedPushMessage, msg.getPushMessageInformation().getId(), new SenderServiceCallback( variant, deviceTokens.size(), msg.getPushMessageInformation() ) ); }
@Override @Asynchronous public void addInstallation(Variant variant, Installation entity) { // does it already exist ? Installation installation = this.findInstallationForVariantByDeviceToken(variant.getVariantID(), entity.getDeviceToken()); // Needed for the Admin UI Only. Help for setting up Routes entity.setPlatform(variant.getType().getTypeName()); // new device/client ? if (installation == null) { logger.trace("Performing new device/client registration"); // store the installation: storeInstallationAndSetReferences(variant, entity); } else { // We only update the metadata, if the device is enabled: if (installation.isEnabled()) { logger.trace("Updating received metadata for an 'enabled' installation"); // fix variant property of installation object installation.setVariant(variant); // update the entity: this.updateInstallation(installation, entity); } } }
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 public void delete(Variant variant) { entityManager.createQuery("delete from Installation i where i.variant in :variant") .setParameter("variant", variant).executeUpdate(); entityManager.createQuery("delete from VariantErrorStatus ves where ves.variant in :variant") .setParameter("variant", variant).executeUpdate(); Variant entity = find(variant.getId()); super.delete(entity); }
topics.addAll(TokenLoaderUtils.extractFCMTopics(criteria, variant.getVariantID())); tokenStream = clientInstallationService.findAllOldGoogleCloudMessagingDeviceTokenForVariantIDByCriteria(variant.getVariantID(), categories, aliases, deviceTypes, configuration.tokensToLoad(), lastTokenFromPreviousBatch) .fetchSize(configuration.batchSize()) .executeQuery(); tokenStream = clientInstallationService.findAllDeviceTokenForVariantIDByCriteria(variant.getVariantID(), categories, aliases, deviceTypes, configuration.tokensToLoad(), lastTokenFromPreviousBatch) .fetchSize(configuration.batchSize()) .executeQuery(); logger.info(String.format("Loaded batch #%s, containing %d tokens, for %s variant (%s)", serialId, tokens.size() ,variant.getType().getTypeName(), variant.getVariantID())); } else { logger.debug(String.format("Failing token loading transaction for batch token #%s for %s variant (%s), since queue is full, will retry...", serialId, variant.getType().getTypeName(), variant.getVariantID())); context.setRollbackOnly(); return; logger.info("Loaded batch #{}, containing {} tokens, for {} variant ({})", serialId, tokens.size() ,variant.getType().getTypeName(), variant.getVariantID()); logger.debug(String.format("Ending token loading transaction for %s variant (%s)", variant.getType().getTypeName(), variant.getVariantID())); nextBatchEvent.fire(new MessageHolderWithVariants(msg.getPushMessageInformation(), message, msg.getVariantType(), variants, serialId, lastTokenInBatch)); } else { logger.debug("All batches for {} variant were loaded ({})", variant.getType().getTypeName(), variant.getVariantID());
@Override public void onSuccess() { logger.debug("Sent '{}' message to '{}' devices", variant.getType().getTypeName(), tokenSize); }
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); }
topics.addAll(TokenLoaderUtils.extractFCMTopics(criteria, variant.getVariantID())); tokenStream = clientInstallationService.findAllOldGoogleCloudMessagingDeviceTokenForVariantIDByCriteria(variant.getVariantID(), categories, aliases, deviceTypes, configuration.tokensToLoad(), lastTokenFromPreviousBatch) .fetchSize(configuration.batchSize()) .executeQuery(); tokenStream = clientInstallationService.findAllDeviceTokenForVariantIDByCriteria(variant.getVariantID(), categories, aliases, deviceTypes, configuration.tokensToLoad(), lastTokenFromPreviousBatch) .fetchSize(configuration.batchSize()) .executeQuery(); logger.info(String.format("Loaded batch #%s, containing %d tokens, for %s variant (%s)", serialId, tokens.size() ,variant.getType().getTypeName(), variant.getVariantID())); } else { logger.debug(String.format("Failing token loading transaction for batch token #%s for %s variant (%s), since queue is full, will retry...", serialId, variant.getType().getTypeName(), variant.getVariantID())); context.setRollbackOnly(); return; logger.info("Loaded batch #{}, containing {} tokens, for {} variant ({})", serialId, tokens.size() ,variant.getType().getTypeName(), variant.getVariantID()); logger.debug(String.format("Ending token loading transaction for %s variant (%s)", variant.getType().getTypeName(), variant.getVariantID())); nextBatchEvent.fire(new MessageHolderWithVariants(msg.getPushMessageInformation(), message, msg.getVariantType(), variants, serialId, lastTokenInBatch)); } else { logger.debug("All batches for {} variant were loaded ({})", variant.getType().getTypeName(), variant.getVariantID());
@Override public void onSuccess() { logger.debug("Sent '{}' message to '{}' devices", variant.getType().getTypeName(), tokenSize); }
clientInstallationService.findInstallationForVariantByDeviceToken(variant.getVariantID(), token);
@Override public void onError(final String reason) { logger.warn("Error on '{}' delivery: {}", variant.getType().getTypeName(), reason); pushMessageMetricsService.appendError(pushMessageInformation, variant, reason); } }