protected void doServe(HttpServletRequest request, HttpServletResponse response) { log.entering(sourceClass, "doServe"); List<UserDTO> users = userService.readUsers(); String priceChangeKey = request.getParameter(PARAM_PRICE_CHANGE_KEY); PriceChangeDTO priceChange = articleTypeService.readPriceChange(priceChangeKey); log.info( "distributing price-change on articleTypeId=" + priceChange.getArticleTypeKey() + " to " + users.size() + " users"); for (UserDTO user : users) { if (hasPriceChangedForUser(priceChange, user)) { log.info("user " + user.getUsername() + " has this article"); PriceChangeDTO shopPriceChange = priceChange.clone(); userService.createPriceChangeForShop(user.getShop().getKeyString(), shopPriceChange); } else { log.info("user skipped - does not have this article"); } } articleTypeService.deletePriceChange(priceChange); log.exiting(sourceClass, "doServe"); }
private boolean hasPriceChangedForUser(PriceChangeDTO priceChange, UserDTO user) { boolean changedForUser = false; if (Boolean.TRUE.equals(user.getEnabled()) && user.getRole().equals(UserRole.SHOP)) { switch (user.getCountry()) { case AT: changedForUser = priceChange.getSellPriceAt() != null; break; case DE: changedForUser = priceChange.getSellPriceDe() != null; break; } } return changedForUser; }