public Response registerInstallation(
Installation entity,
@Context HttpServletRequest request) {
// find the matching variation:
final Variant variant = loadVariantWhenAuthorized(request);
if (variant == null) {
return appendAllowOriginHeader(
Response.status(Status.UNAUTHORIZED)
.header("WWW-Authenticate", "Basic realm=\"AeroGear UnifiedPush Server\"")
.entity("Unauthorized Request"),
request);
}
// Poor validation: We require the Token! And the 'simplePushEndpoint' for SimplePush clients!
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:
Installation installation =
clientInstallationService.findInstallationForVariantByDeviceToken(variant.getVariantID(), entity.getDeviceToken());
// Needed for the Admin UI Only. Help for setting up Routes
entity.setPlatform(variant.getType().getTypeName());
// The 'mobile application' on the device/client was launched.
// If the installation is already in the DB, let's update the metadata,
// otherwise we register a new installation:
logger.log(Level.FINEST, "Mobile Application on device was launched");
// new device/client ?
if (installation == null) {
logger.log(Level.FINEST, "Performing new device/client registration");
// store the installation:
clientInstallationService.addInstallation(variant.getType(), 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()) {