Subversion Repositories SmartDukaan

Rev

Rev 36521 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36521 Rev 36634
Line 174... Line 174...
174
    public String activateOffer(HttpServletRequest request, @PathVariable(name = "offerId") String offerIdsString,
174
    public String activateOffer(HttpServletRequest request, @PathVariable(name = "offerId") String offerIdsString,
175
                                Model model, @RequestParam(defaultValue = "true") boolean active)
175
                                Model model, @RequestParam(defaultValue = "true") boolean active)
176
            throws ProfitMandiBusinessException, Exception {
176
            throws ProfitMandiBusinessException, Exception {
177
        List<Integer> offerIds = Arrays.stream(offerIdsString.split(",")).map(x -> Integer.parseInt(x))
177
        List<Integer> offerIds = Arrays.stream(offerIdsString.split(",")).map(x -> Integer.parseInt(x))
178
                .collect(Collectors.toList());
178
                .collect(Collectors.toList());
179
        List<Offer> offers = offerRepository.selectAllByIds(offerIds);
-
 
180
 
179
 
181
        //Consider only offers that have opposite status
180
        // REQUIRES_NEW: commits active flag to DB before cache eviction
182
        offers = offers.stream().filter(x -> x.isActive() != active).collect(Collectors.toList());
181
        List<Offer> offers = offerService.activateOffers(offerIds, active);
183
 
182
 
184
        for (Offer offer : offers) {
183
        for (Offer offer : offers) {
185
            offer.setActive(active);
-
 
186
            offerService.evictOfferCaches(offer.getId());
184
            offerService.evictOfferCaches(offer.getId());
187
        }
185
        }
188
        if (active) {
186
        if (active) {
189
            for (Offer offer : offers) {
187
            for (Offer offer : offers) {
-
 
188
                try {
190
                this.sendNotification(offer);
189
                    this.sendNotification(offer);
-
 
190
                } catch (Exception e) {
-
 
191
                    LOGGER.error("Notification failed for offer {}", offer.getId(), e);
-
 
192
                }
191
            }
193
            }
192
        }
194
        }
193
 
195
 
194
 
-
 
195
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
196
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
196
        return "response";
197
        return "response";
197
    }
198
    }
198
 
199
 
199
    @RequestMapping(value = "/offers/publishAll", method = RequestMethod.POST)
200
    @RequestMapping(value = "/offers/publishAll", method = RequestMethod.POST)
Line 201... Line 202...
201
            throws ProfitMandiBusinessException, Exception {
202
            throws ProfitMandiBusinessException, Exception {
202
        List<Offer> published = offerService.publishAllUnpublished(yearMonth);
203
        List<Offer> published = offerService.publishAllUnpublished(yearMonth);
203
        if (!published.isEmpty()) {
204
        if (!published.isEmpty()) {
204
            for (Offer offer : published) {
205
            for (Offer offer : published) {
205
                offerService.evictOfferCaches(offer.getId());
206
                offerService.evictOfferCaches(offer.getId());
-
 
207
                try {
206
                this.sendNotification(offer);
208
                    this.sendNotification(offer);
-
 
209
                } catch (Exception e) {
-
 
210
                    LOGGER.error("Notification failed for offer {}", offer.getId(), e);
-
 
211
                }
207
            }
212
            }
208
        }
213
        }
209
        return responseSender.ok(published.size() + " offers published");
214
        return responseSender.ok(published.size() + " offers published");
210
    }
215
    }
211
 
216