Package org.jboss.aerogear.unifiedpush.api

Examples of org.jboss.aerogear.unifiedpush.api.Variant


        // header:
        String[] credentials = HttpBasicHelper.extractUsernameAndPasswordFromBasicHeader(request);
        String variantID = credentials[0];
        String secret = credentials[1];

        final Variant variant = genericVariantService.findByVariantID(variantID);
        if (variant != null && variant.getSecret().equals(secret)) {
            return variant;
        }

        // unauthorized...
        return null;
View Full Code Here


        merge(variant);
    }

    @Override
    public void delete(Variant variant) {
        Variant entity = entityManager.find(Variant.class, variant.getId());
        remove(entity);
    }
View Full Code Here


    @Override
    public Variant findByVariantID(String variantID) {

        Variant entity = getSingleResultForQuery(createQuery("select t from Variant t where t.variantID = :variantID")
                .setParameter("variantID", variantID));

        return entity;
    }
View Full Code Here

    }

    @Override
    public Variant findByVariantIDForDeveloper(String variantID, String loginName) {

        Variant entity = getSingleResultForQuery(createQuery("select t from Variant t where t.variantID = :variantID and t.developer = :developer")
                .setParameter("variantID", variantID)
                .setParameter("developer", loginName));


        return entity;
View Full Code Here

                .setParameter("variantIDs", variantIDs).getResultList();
    }

    @Override
    public Variant find(String id) {
        Variant entity = entityManager.find(Variant.class, id);
        return entity;
    }
View Full Code Here

    @PUT
    @Path("/{variantId}/reset")
    @Consumes(MediaType.APPLICATION_JSON)
    public javax.ws.rs.core.Response resetSecret(@Context HttpServletRequest request, @PathParam("variantId") String variantId) {

        Variant variant = variantService.findByVariantIDForDeveloper(variantId, extractUsername(request));

        if (variant != null) {
            logger.log(Level.FINEST, "Resetting secret for: " + variant.getClass().getSimpleName());

            // generate the new 'secret' and apply it:
            String newSecret = UUID.randomUUID().toString();
            variant.setSecret(newSecret);
            variantService.updateVariant(variant);

            return Response.ok(variant).build();
        }
View Full Code Here

    @GET
    @Path("/{variantId}")
    @Produces(MediaType.APPLICATION_JSON)
    public Response findVariantById(@Context HttpServletRequest request, @PathParam("variantId") String variantId) {

        Variant variant = variantService.findByVariantIDForDeveloper(variantId, extractUsername(request));

        if (variant != null) {
            return Response.ok(variant).build();
        }
View Full Code Here

    // DELETE
    @DELETE
    @Path("/{variantId}")
    public Response deleteVariant(@Context HttpServletRequest request, @PathParam("variantId") String variantId) {

        Variant variant = variantService.findByVariantIDForDeveloper(variantId, extractUsername(request));

        if (variant != null) {
            logger.log(Level.FINEST, "Deleting: " + variant.getClass().getSimpleName());

            variantService.removeVariant(variant);
            return Response.noContent().build();
        }
View Full Code Here

    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()) {
View Full Code Here

    public Response unregisterInstallations(
            @PathParam("token") String token,
            @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);
        }

        // look up all installations (with same token) for the given variant:
        Installation installation =
                clientInstallationService.findInstallationForVariantByDeviceToken(variant.getVariantID(), token);

        if (installation == null) {
            return appendAllowOriginHeader(Response.status(Status.NOT_FOUND), request);
        } else {
            logger.log(Level.INFO, "Deleting metadata Installation");
View Full Code Here

TOP

Related Classes of org.jboss.aerogear.unifiedpush.api.Variant

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.