/** * API for this method is .../rest/premium_package_properties This method recieves JSON object, * and update database. Example for JSON that you need. Required filed is id. * * <p>{ <br> * "forNonPayingUsers": 0,<br> * "redirectPositionTop": null,<br> * "redirectPositionLeft": null,<br> * "redirectImageUrl": "",<br> * "charityDonation": null, <br> * "charityDescription": "",<br> * "showUntil": null,<br> * "maxPurchasesPerUser": null, <br> * "idPremiumPackageUpgrade": null,<br> * "idFavoriteClub": null,<br> * "highlightImageUrl": "",<br> * "showOnlySpecial": 0,<br> * "imageUrlSpecial": "",<br> * "forPayingUsers": 0, <br> * "showFrom": null, <br> * "updateTimestamp": null,<br> * "createDate": 1427204490000, <br> * "redirectUrl": "", <br> * "googlePlayStoreId": null,<br> * "itunesStoreId": null,<br> * "amazonStoreId": null,<br> * "id": 1 <br> * } * * @param token is a header parameter for checking permission * @param request * @param premiumPackageProperty * @return Response with status OK (200) "Successfully updated!" * @throws InputValidationException Example for this exception: <br> * {<br> * "errorMessage": "Validation failed",<br> * "errorCode": 400<br> * } * @throws DataNotFoundException DataNotFoundException Example for exception:<br> * {<br> * "errorMessage": "Premium package properies at index 15 does not exits",<br> * "errorCode": 404<br> * } */ @PUT @Consumes(MediaType.APPLICATION_JSON) public Response updatePremiumAction( @HeaderParam("authorization") String token, @Context HttpServletRequest request, PremiumPackageProperties premiumPackageProperty) { EntityManager em = helper.getEntityManager(); CmsActionHistory history = helper.checkUserAndPrivileges( em, TableConstants.SHOP, MethodConstants.EDIT, token, request.getRequestURL().toString() + (request.getQueryString() != null ? "?" + request.getQueryString() : ""), premiumPackageProperty); PremiumPackageProperties oldPremiumPackageProperty = em.find(PremiumPackageProperties.class, premiumPackageProperty.getId()); if (oldPremiumPackageProperty != null) { if (validator.checkLenght(premiumPackageProperty.getCharityDescription(), 255, true) && someAttributeIsNotNull(premiumPackageProperty) && oldPremiumPackageProperty.getId() != 0) { premiumPackageProperty.setCreateDate(oldPremiumPackageProperty.getCreateDate()); helper.mergeObject(em, premiumPackageProperty); } else { helper.setResponseToHistory(history, new InputValidationException("Validation failed"), em); throw new InputValidationException("Validation failed"); } } else { helper.setResponseToHistory( history, new DataNotFoundException( "Premium package properies at index" + premiumPackageProperty.getId() + " does not exits"), em); throw new DataNotFoundException( "Premium package properies at index" + premiumPackageProperty.getId() + " does not exits"); } Response response = Response.ok().build(); helper.setResponseToHistory(history, response, em); return response; }