// new Android @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response registerAndroidVariant( AndroidVariant androidVariant, @PathParam("pushAppID") String pushApplicationID, @Context UriInfo uriInfo, @Context HttpServletRequest request) { // find the root push app PushApplication pushApp = pushAppService.findByPushApplicationIDForDeveloper( pushApplicationID, request.getUserPrincipal().getName()); if (pushApp == null) { return Response.status(Status.NOT_FOUND) .entity("Could not find requested PushApplicationEntity") .build(); } // some validation try { validateModelClass(androidVariant); } catch (ConstraintViolationException cve) { // Build and return the 400 (Bad Request) response ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } // store the "developer: androidVariant.setDeveloper(request.getUserPrincipal().getName()); // store the Android variant: variantService.addVariant(androidVariant); // add iOS variant, and merge: pushAppService.addAndroidVariant(pushApp, androidVariant); return Response.created( uriInfo .getAbsolutePathBuilder() .path(String.valueOf(androidVariant.getVariantID())) .build()) .entity(androidVariant) .build(); }
// UPDATE @PUT @Path("/{androidID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response updateAndroidVariation( @Context HttpServletRequest request, @PathParam("pushAppID") String id, @PathParam("androidID") String androidID, AndroidVariant updatedAndroidApplication) { AndroidVariant androidVariant = (AndroidVariant) variantService.findByVariantIDForDeveloper( androidID, request.getUserPrincipal().getName()); if (androidVariant != null) { // some validation try { validateModelClass(updatedAndroidApplication); } catch (ConstraintViolationException cve) { // Build and return the 400 (Bad Request) response ResponseBuilder builder = createBadRequestResponse(cve.getConstraintViolations()); return builder.build(); } // apply updated data: androidVariant.setGoogleKey(updatedAndroidApplication.getGoogleKey()); androidVariant.setProjectNumber(updatedAndroidApplication.getProjectNumber()); androidVariant.setName(updatedAndroidApplication.getName()); androidVariant.setDescription(updatedAndroidApplication.getDescription()); variantService.updateVariant(androidVariant); return Response.noContent().build(); } return Response.status(Status.NOT_FOUND).entity("Could not find requested Variant").build(); }