Subversion Repositories SmartDukaan

Rev

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

Rev 35923 Rev 35925
Line 199... Line 199...
199
        for (YearMonth ymToEvict : yearMonthsToEvict) {
199
        for (YearMonth ymToEvict : yearMonthsToEvict) {
200
            redisCacheManager.getCache("catalog.published_yearmonth").evict(ymToEvict);
200
            redisCacheManager.getCache("catalog.published_yearmonth").evict(ymToEvict);
201
            oneDayCacheManager.getCache("allOffers").evict(ymToEvict);
201
            oneDayCacheManager.getCache("allOffers").evict(ymToEvict);
202
        }
202
        }
203
        // Evict partner's published offer list with achievement data
203
        // Evict partner's published offer list with achievement data
204
        redisShortCacheManager.getCache("publishedOffersWithAchievement").clear();
204
        oneDayCacheManager.getCache("publishedOffersWithAchievement").clear();
-
 
205
        redisShortCacheManager.getCache("todayOffers").clear();
205
        // Evict offer detail (price circular) for each involved partner; key=(fofoId, offerId), 0=admin
206
        // Evict offer detail (price circular) for each involved partner; key=(fofoId, offerId), 0=admin
206
        for (Offer offer : offers) {
207
        for (Offer offer : offers) {
207
            PartnerCriteria partnerCriteria = gson.fromJson(offer.getPartnerCriteria(), PartnerCriteria.class);
208
            PartnerCriteria partnerCriteria = gson.fromJson(offer.getPartnerCriteria(), PartnerCriteria.class);
208
            if (partnerCriteria != null && partnerCriteria.getFofoIds() != null) {
209
            if (partnerCriteria != null && partnerCriteria.getFofoIds() != null) {
209
                for (Integer fofoId : partnerCriteria.getFofoIds()) {
210
                for (Integer fofoId : partnerCriteria.getFofoIds()) {
Line 229... Line 230...
229
        List<Offer> published = offerService.publishAllUnpublished(yearMonth);
230
        List<Offer> published = offerService.publishAllUnpublished(yearMonth);
230
        if (!published.isEmpty()) {
231
        if (!published.isEmpty()) {
231
            // Evict partner-to-offer mapping and offer listing
232
            // Evict partner-to-offer mapping and offer listing
232
            redisCacheManager.getCache("catalog.published_yearmonth").evict(yearMonth);
233
            redisCacheManager.getCache("catalog.published_yearmonth").evict(yearMonth);
233
            oneDayCacheManager.getCache("allOffers").evict(yearMonth);
234
            oneDayCacheManager.getCache("allOffers").evict(yearMonth);
234
            redisShortCacheManager.getCache("publishedOffersWithAchievement").clear();
235
            oneDayCacheManager.getCache("publishedOffersWithAchievement").clear();
-
 
236
        redisShortCacheManager.getCache("todayOffers").clear();
235
            // Evict offer detail (price circular) for each involved partner; key=(fofoId, offerId), 0=admin
237
            // Evict offer detail (price circular) for each involved partner; key=(fofoId, offerId), 0=admin
236
            for (Offer offer : published) {
238
            for (Offer offer : published) {
237
                PartnerCriteria pc = gson.fromJson(offer.getPartnerCriteria(), PartnerCriteria.class);
239
                PartnerCriteria pc = gson.fromJson(offer.getPartnerCriteria(), PartnerCriteria.class);
238
                if (pc != null && pc.getFofoIds() != null) {
240
                if (pc != null && pc.getFofoIds() != null) {
239
                    for (Integer fofoId : pc.getFofoIds()) {
241
                    for (Integer fofoId : pc.getFofoIds()) {
Line 690... Line 692...
690
        }
692
        }
691
 
693
 
692
        // Evict partner-to-offer mapping (removed partners no longer see this offer)
694
        // Evict partner-to-offer mapping (removed partners no longer see this offer)
693
        oneDayCacheManager.getCache("allOffers").evict(ym);
695
        oneDayCacheManager.getCache("allOffers").evict(ym);
694
        redisCacheManager.getCache("catalog.published_yearmonth").evict(ym);
696
        redisCacheManager.getCache("catalog.published_yearmonth").evict(ym);
695
        redisShortCacheManager.getCache("publishedOffersWithAchievement").clear();
697
        oneDayCacheManager.getCache("publishedOffersWithAchievement").clear();
-
 
698
        redisShortCacheManager.getCache("todayOffers").clear();
696
        // Evict offer detail (price circular) for removed partners; key=(fofoId, offerId), 0=admin
699
        // Evict offer detail (price circular) for removed partners; key=(fofoId, offerId), 0=admin
697
        for (Integer fofoId : fofoIds) {
700
        for (Integer fofoId : fofoIds) {
698
            thirtyMinsTimeOutCacheManager.getCache("partnerOffers").evict(new SimpleKey(fofoId, offerId));
701
            thirtyMinsTimeOutCacheManager.getCache("partnerOffers").evict(new SimpleKey(fofoId, offerId));
699
        }
702
        }
700
        thirtyMinsTimeOutCacheManager.getCache("partnerOffers").evict(new SimpleKey(0, offerId));
703
        thirtyMinsTimeOutCacheManager.getCache("partnerOffers").evict(new SimpleKey(0, offerId));
Line 718... Line 721...
718
        Offer offer = offerRepository.selectById(offerId);
721
        Offer offer = offerRepository.selectById(offerId);
719
        YearMonth ym = YearMonth.from(offer.getStartDate());
722
        YearMonth ym = YearMonth.from(offer.getStartDate());
720
        // Evict partner-to-offer mapping (added partners now see this offer)
723
        // Evict partner-to-offer mapping (added partners now see this offer)
721
        oneDayCacheManager.getCache("allOffers").evict(ym);
724
        oneDayCacheManager.getCache("allOffers").evict(ym);
722
        redisCacheManager.getCache("catalog.published_yearmonth").evict(ym);
725
        redisCacheManager.getCache("catalog.published_yearmonth").evict(ym);
723
        redisShortCacheManager.getCache("publishedOffersWithAchievement").clear();
726
        oneDayCacheManager.getCache("publishedOffersWithAchievement").clear();
-
 
727
        redisShortCacheManager.getCache("todayOffers").clear();
724
        // Evict offer detail (price circular) for added partners; key=(fofoId, offerId), 0=admin
728
        // Evict offer detail (price circular) for added partners; key=(fofoId, offerId), 0=admin
725
        for (Integer fofoId : fofoIds) {
729
        for (Integer fofoId : fofoIds) {
726
            thirtyMinsTimeOutCacheManager.getCache("partnerOffers").evict(new SimpleKey(fofoId, offerId));
730
            thirtyMinsTimeOutCacheManager.getCache("partnerOffers").evict(new SimpleKey(fofoId, offerId));
727
        }
731
        }
728
        thirtyMinsTimeOutCacheManager.getCache("partnerOffers").evict(new SimpleKey(0, offerId));
732
        thirtyMinsTimeOutCacheManager.getCache("partnerOffers").evict(new SimpleKey(0, offerId));
Line 739... Line 743...
739
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
743
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
740
        if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
744
        if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
741
            throw new ProfitMandiBusinessException("Unauthorized", "Unauthorized", "");
745
            throw new ProfitMandiBusinessException("Unauthorized", "Unauthorized", "");
742
        }
746
        }
743
        offerService.updateOfferTargets(offerId, targets);
747
        offerService.updateOfferTargets(offerId, targets);
-
 
748
        evictOfferCaches(offerId);
-
 
749
        return responseSender.ok("Targets updated for Offer #" + offerId);
-
 
750
    }
-
 
751
 
-
 
752
    @RequestMapping(value = "/offer/updateSlabs", method = RequestMethod.POST, consumes = "application/json")
-
 
753
    public ResponseEntity<?> updateOfferSlabs(HttpServletRequest request,
-
 
754
            @RequestBody com.spice.profitmandi.dao.model.UpdateOfferSlabsRequest updateRequest) throws Exception {
-
 
755
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
756
        if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
-
 
757
            throw new ProfitMandiBusinessException("Unauthorized", "Unauthorized", "");
-
 
758
        }
-
 
759
        offerService.updateOfferSlabs(updateRequest);
-
 
760
        evictOfferCaches(updateRequest.getOfferId());
-
 
761
        return responseSender.ok("Slabs updated for Offer #" + updateRequest.getOfferId());
-
 
762
    }
744
 
763
 
-
 
764
    private void evictOfferCaches(int offerId) {
745
        Offer offer = offerRepository.selectById(offerId);
765
        Offer offer = offerRepository.selectById(offerId);
746
        YearMonth ym = YearMonth.from(offer.getStartDate());
766
        YearMonth ym = YearMonth.from(offer.getStartDate());
747
        // Evict offer listing and partner-to-offer mapping (targets changed for published offer)
-
 
748
        oneDayCacheManager.getCache("allOffers").evict(ym);
767
        oneDayCacheManager.getCache("allOffers").evict(ym);
749
        redisCacheManager.getCache("catalog.published_yearmonth").evict(ym);
768
        redisCacheManager.getCache("catalog.published_yearmonth").evict(ym);
750
        redisShortCacheManager.getCache("publishedOffersWithAchievement").clear();
769
        oneDayCacheManager.getCache("publishedOffersWithAchievement").clear();
751
        // Evict offer detail (price circular) for all partners of this offer; key=(fofoId, offerId), 0=admin
770
        redisShortCacheManager.getCache("todayOffers").clear();
752
        PartnerCriteria partnerCriteria = gson.fromJson(offer.getPartnerCriteria(), PartnerCriteria.class);
771
        PartnerCriteria partnerCriteria = gson.fromJson(offer.getPartnerCriteria(), PartnerCriteria.class);
753
        if (partnerCriteria != null && partnerCriteria.getFofoIds() != null) {
772
        if (partnerCriteria != null && partnerCriteria.getFofoIds() != null) {
754
            for (Integer fofoId : partnerCriteria.getFofoIds()) {
773
            for (Integer fofoId : partnerCriteria.getFofoIds()) {
755
                thirtyMinsTimeOutCacheManager.getCache("partnerOffers").evict(new SimpleKey(fofoId, offerId));
774
                thirtyMinsTimeOutCacheManager.getCache("partnerOffers").evict(new SimpleKey(fofoId, offerId));
756
            }
775
            }
757
        }
776
        }
758
        thirtyMinsTimeOutCacheManager.getCache("partnerOffers").evict(new SimpleKey(0, offerId));
777
        thirtyMinsTimeOutCacheManager.getCache("partnerOffers").evict(new SimpleKey(0, offerId));
759
 
-
 
760
        return responseSender.ok("Targets updated for Offer #" + offerId);
-
 
761
    }
778
    }
762
 
779
 
763
}
780
}
764
781