/**
  * API for this method is .../rest/premium_package_properties This method recieves JSON object,
  * and put it in the base. Example for JSON that you need to send some of this attributes not to
  * be default values: <br>
  * {<br>
  * "googlePlayStoreId": null,<br>
  * "itunesStoreId": null,<br>
  * "amazonStoreId": null,<br>
  * "forNonPayingUsers": 0, <br>
  * "redirectPositionTop": null,<br>
  * "redirectPositionLeft": null, <br>
  * "redirectImageUrl": "", "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>
  * "redirectUrl": "", <br>
  * }
  *
  * @param token is a header parameter for checking permission
  * @param request
  * @param premiumPackageProperties
  * @return Response with status CREATED (201)
  * @throws InputValidationException Example for this exception: <br>
  *     {<br>
  *     "errorMessage": "Validation failed",<br>
  *     "errorCode": 400<br>
  *     }
  */
 @POST
 @Consumes(MediaType.APPLICATION_JSON)
 public Response insertPremiumAction(
     @HeaderParam("authorization") String token,
     @Context HttpServletRequest request,
     PremiumPackageProperties premiumPackageProperties) {
   EntityManager em = helper.getEntityManager();
   CmsActionHistory history =
       helper.checkUserAndPrivileges(
           em,
           TableConstants.SHOP,
           MethodConstants.ADD,
           token,
           request.getRequestURL().toString()
               + (request.getQueryString() != null ? "?" + request.getQueryString() : ""),
           premiumPackageProperties);
   premiumPackageProperties.setCreateDate(new Date());
   if (validator.checkLenght(premiumPackageProperties.getCharityDescription(), 255, true)
       && someAttributeIsNotNull(premiumPackageProperties)) {
     premiumPackageProperties.setCreateDate(new Date());
     helper.persistObject(em, premiumPackageProperties);
     Response response = Response.status(Response.Status.CREATED).build();
     helper.setResponseToHistory(history, response, em);
     return response;
   } else {
     helper.setResponseToHistory(history, new InputValidationException("Validation failed"), em);
     throw new InputValidationException("Validation failed");
   }
 }
 /**
  * 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;
 }
 private boolean someAttributeIsNotNull(PremiumPackageProperties premiumPackageProperties) {
   return premiumPackageProperties.getCharityDescription() != null
       || premiumPackageProperties.getCharityDonation() != BigDecimal.valueOf(0)
       || premiumPackageProperties.getForNonPayingUsers() != 0
       || premiumPackageProperties.getForPayingUsers() != Short.parseShort("0")
       || premiumPackageProperties.getHighlightImageUrl() != null
       || premiumPackageProperties.getIdFavoriteClub() != null
       || premiumPackageProperties.getIdPremiumPackageSuccessor() != null
       || premiumPackageProperties.getIdPremiumPackageUpgrade() != null
       || premiumPackageProperties.getImageUrlSpecial() != null
       || premiumPackageProperties.getMaxPurchasesPerUser() != 0
       || premiumPackageProperties.getPremiumPackageList() != null
       || premiumPackageProperties.getRedirectImageUrl() != null
       || premiumPackageProperties.getRedirectPositionLeft() != 0
       || premiumPackageProperties.getRedirectPositionTop() != 0
       || premiumPackageProperties.getRedirectUrl() != null
       || premiumPackageProperties.getUpdateTimestamp() != null
       || premiumPackageProperties.getShowUntil() != null
       || premiumPackageProperties.getShowOnlySpecial() != 0
       || premiumPackageProperties.getShowFrom() != null;
 }