if (entity.getDeviceToken() == null || (variant.getType() == VariantType.SIMPLE_PUSH && entity.getSimplePushEndpoint() == null)) {
return appendAllowOriginHeader(Response.status(Status.BAD_REQUEST), request);
}
// look up all installations (with same token) for the given variant:
InstallationImpl installation =
clientInstallationService.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.fine("Performing client registration for: " + entity.getDeviceToken());
// store the installation:
entity = clientInstallationService.addInstallation(entity);
// add installation to the matching variant
genericVariantService.addInstallation(variant, entity);
} else {
// We only update the metadata, if the device is enabled:
if (installation.isEnabled()) {
logger.info("Updating received metadata for Installation");
// update the entity:
entity = clientInstallationService.updateInstallation(installation, entity);
}
}