| Line 181... |
Line 181... |
| 181 |
Model model, @RequestParam(defaultValue = "true") boolean active)
|
181 |
Model model, @RequestParam(defaultValue = "true") boolean active)
|
| 182 |
throws ProfitMandiBusinessException, Exception {
|
182 |
throws ProfitMandiBusinessException, Exception {
|
| 183 |
List<Integer> offerIds = Arrays.stream(offerIdsString.split(",")).map(x -> Integer.parseInt(x))
|
183 |
List<Integer> offerIds = Arrays.stream(offerIdsString.split(",")).map(x -> Integer.parseInt(x))
|
| 184 |
.collect(Collectors.toList());
|
184 |
.collect(Collectors.toList());
|
| 185 |
|
185 |
|
| 186 |
// REQUIRES_NEW: commits active flag to DB before cache eviction
|
186 |
// REQUIRES_NEW: commits the active flag and evicts the offer caches before notifications go out
|
| 187 |
List<Offer> offers = offerService.activateOffers(offerIds, active);
|
187 |
List<Offer> offers = offerService.activateOffers(offerIds, active);
|
| 188 |
|
188 |
|
| 189 |
for (Offer offer : offers) {
|
- |
|
| 190 |
offerService.evictOfferCaches(offer.getId());
|
- |
|
| 191 |
}
|
- |
|
| 192 |
if (active) {
|
189 |
if (active) {
|
| 193 |
for (Offer offer : offers) {
|
190 |
for (Offer offer : offers) {
|
| 194 |
try {
|
191 |
try {
|
| 195 |
this.sendNotification(offer);
|
192 |
this.sendNotification(offer);
|
| 196 |
} catch (Exception e) {
|
193 |
} catch (Exception e) {
|
| Line 207... |
Line 204... |
| 207 |
public ResponseEntity<?> publishAllUnpublished(@RequestParam YearMonth yearMonth)
|
204 |
public ResponseEntity<?> publishAllUnpublished(@RequestParam YearMonth yearMonth)
|
| 208 |
throws ProfitMandiBusinessException, Exception {
|
205 |
throws ProfitMandiBusinessException, Exception {
|
| 209 |
List<Offer> published = offerService.publishAllUnpublished(yearMonth);
|
206 |
List<Offer> published = offerService.publishAllUnpublished(yearMonth);
|
| 210 |
if (!published.isEmpty()) {
|
207 |
if (!published.isEmpty()) {
|
| 211 |
for (Offer offer : published) {
|
208 |
for (Offer offer : published) {
|
| 212 |
offerService.evictOfferCaches(offer.getId());
|
- |
|
| 213 |
try {
|
209 |
try {
|
| 214 |
this.sendNotification(offer);
|
210 |
this.sendNotification(offer);
|
| 215 |
} catch (Exception e) {
|
211 |
} catch (Exception e) {
|
| 216 |
LOGGER.error("Notification failed for offer {}", offer.getId(), e);
|
212 |
LOGGER.error("Notification failed for offer {}", offer.getId(), e);
|
| 217 |
}
|
213 |
}
|
| Line 220... |
Line 216... |
| 220 |
return responseSender.ok(published.size() + " offers published");
|
216 |
return responseSender.ok(published.size() + " offers published");
|
| 221 |
}
|
217 |
}
|
| 222 |
|
218 |
|
| 223 |
/**
|
219 |
/**
|
| 224 |
* Evicts month-level offer caches so newly created/modified offers appear in listings.
|
220 |
* Evicts month-level offer caches so newly created/modified offers appear in listings.
|
| 225 |
* Clears: monthOfferIds (admin list), catalog.published_yearmonth (partner view), todayOffers.
|
221 |
* Clears: monthOfferIds (admin list), catalog.published_yearmonth (partner view), todayOffers,
|
| - |
|
222 |
* and each of the month's offer.definition / offer.slabpayout entries.
|
| 226 |
*/
|
223 |
*/
|
| 227 |
@RequestMapping(value = "/offer/refreshCache", method = RequestMethod.GET)
|
224 |
@RequestMapping(value = "/offer/refreshCache", method = RequestMethod.GET)
|
| 228 |
public ResponseEntity<?> refreshOfferCache(@RequestParam YearMonth yearMonth) {
|
225 |
public ResponseEntity<?> refreshOfferCache(@RequestParam YearMonth yearMonth) {
|
| 229 |
offerService.evictMonthCaches(yearMonth);
|
226 |
offerService.evictAllOfferCaches(yearMonth);
|
| 230 |
return responseSender.ok("Offer cache refreshed for " + yearMonth);
|
227 |
return responseSender.ok("Offer cache refreshed for " + yearMonth);
|
| 231 |
}
|
228 |
}
|
| 232 |
|
229 |
|
| 233 |
@RequestMapping(value = "/offer/delete/{offerId}", method = RequestMethod.DELETE)
|
230 |
@RequestMapping(value = "/offer/delete/{offerId}", method = RequestMethod.DELETE)
|
| 234 |
public ResponseEntity<?> deleteOffer(@PathVariable int offerId) throws ProfitMandiBusinessException {
|
231 |
public ResponseEntity<?> deleteOffer(@PathVariable int offerId) throws ProfitMandiBusinessException {
|