| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.awt.RenderingHints;
|
- |
|
| 4 |
import java.awt.image.BufferedImage;
|
- |
|
| 5 |
import java.io.ByteArrayInputStream;
|
- |
|
| 6 |
import java.io.File;
|
- |
|
| 7 |
import java.io.FileNotFoundException;
|
- |
|
| 8 |
import java.io.InputStream;
|
- |
|
| 9 |
import java.time.Instant;
|
- |
|
| 10 |
import java.time.LocalDate;
|
- |
|
| 11 |
import java.time.LocalDateTime;
|
- |
|
| 12 |
import java.time.YearMonth;
|
- |
|
| 13 |
import java.util.ArrayList;
|
- |
|
| 14 |
import java.util.Arrays;
|
- |
|
| 15 |
import java.util.Collection;
|
- |
|
| 16 |
import java.util.Comparator;
|
- |
|
| 17 |
import java.util.HashMap;
|
- |
|
| 18 |
import java.util.List;
|
- |
|
| 19 |
import java.util.Map;
|
- |
|
| 20 |
import java.util.Set;
|
- |
|
| 21 |
import java.util.stream.Collectors;
|
- |
|
| 22 |
|
- |
|
| 23 |
import javax.imageio.ImageIO;
|
- |
|
| 24 |
import javax.servlet.http.HttpServletRequest;
|
- |
|
| 25 |
import javax.transaction.Transactional;
|
- |
|
| 26 |
|
- |
|
| 27 |
import org.apache.commons.io.FileUtils;
|
- |
|
| 28 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
- |
|
| 29 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 30 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 31 |
import org.apache.velocity.app.VelocityEngine;
|
- |
|
| 32 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 33 |
import org.springframework.cache.CacheManager;
|
- |
|
| 34 |
import org.springframework.core.io.InputStreamResource;
|
- |
|
| 35 |
import org.springframework.http.HttpHeaders;
|
- |
|
| 36 |
import org.springframework.http.HttpStatus;
|
- |
|
| 37 |
import org.springframework.http.ResponseEntity;
|
- |
|
| 38 |
import org.springframework.stereotype.Controller;
|
- |
|
| 39 |
import org.springframework.ui.Model;
|
- |
|
| 40 |
import org.springframework.ui.velocity.VelocityEngineUtils;
|
- |
|
| 41 |
import org.springframework.web.bind.annotation.PathVariable;
|
- |
|
| 42 |
import org.springframework.web.bind.annotation.PostMapping;
|
- |
|
| 43 |
import org.springframework.web.bind.annotation.RequestBody;
|
- |
|
| 44 |
import org.springframework.web.bind.annotation.RequestMapping;
|
- |
|
| 45 |
import org.springframework.web.bind.annotation.RequestMethod;
|
- |
|
| 46 |
import org.springframework.web.bind.annotation.RequestParam;
|
- |
|
| 47 |
import org.springframework.web.bind.annotation.RequestPart;
|
- |
|
| 48 |
import org.springframework.web.multipart.MultipartFile;
|
- |
|
| 49 |
import org.xhtmlrenderer.simple.Graphics2DRenderer;
|
- |
|
| 50 |
import org.xhtmlrenderer.swing.Java2DRenderer;
|
- |
|
| 51 |
|
- |
|
| 52 |
import com.google.gson.Gson;
|
3 |
import com.google.gson.Gson;
|
| 53 |
import com.jcraft.jsch.ChannelSftp;
|
- |
|
| 54 |
import com.jcraft.jsch.JSch;
|
4 |
import com.jcraft.jsch.*;
|
| 55 |
import com.jcraft.jsch.JSchException;
|
- |
|
| 56 |
import com.jcraft.jsch.Session;
|
- |
|
| 57 |
import com.jcraft.jsch.SftpATTRS;
|
- |
|
| 58 |
import com.jcraft.jsch.SftpException;
|
- |
|
| 59 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
5 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 60 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
6 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 61 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
7 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 62 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
8 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 63 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
9 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| Line 82... |
Line 28... |
| 82 |
import com.spice.profitmandi.service.offers.OfferService;
|
28 |
import com.spice.profitmandi.service.offers.OfferService;
|
| 83 |
import com.spice.profitmandi.service.user.RetailerService;
|
29 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 84 |
import com.spice.profitmandi.web.model.LoginDetails;
|
30 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 85 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
31 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 86 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
32 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| - |
|
33 |
import org.apache.commons.io.FileUtils;
|
| - |
|
34 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| - |
|
35 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
36 |
import org.apache.logging.log4j.Logger;
|
| - |
|
37 |
import org.apache.velocity.app.VelocityEngine;
|
| - |
|
38 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
39 |
import org.springframework.cache.CacheManager;
|
| - |
|
40 |
import org.springframework.core.io.InputStreamResource;
|
| - |
|
41 |
import org.springframework.http.HttpHeaders;
|
| - |
|
42 |
import org.springframework.http.HttpStatus;
|
| - |
|
43 |
import org.springframework.http.ResponseEntity;
|
| - |
|
44 |
import org.springframework.stereotype.Controller;
|
| - |
|
45 |
import org.springframework.ui.Model;
|
| - |
|
46 |
import org.springframework.ui.velocity.VelocityEngineUtils;
|
| - |
|
47 |
import org.springframework.web.bind.annotation.*;
|
| - |
|
48 |
import org.springframework.web.multipart.MultipartFile;
|
| - |
|
49 |
import org.xhtmlrenderer.swing.Java2DRenderer;
|
| - |
|
50 |
|
| - |
|
51 |
import javax.imageio.ImageIO;
|
| - |
|
52 |
import javax.servlet.http.HttpServletRequest;
|
| - |
|
53 |
import javax.transaction.Transactional;
|
| - |
|
54 |
import java.awt.*;
|
| - |
|
55 |
import java.awt.image.BufferedImage;
|
| - |
|
56 |
import java.io.ByteArrayInputStream;
|
| - |
|
57 |
import java.io.File;
|
| - |
|
58 |
import java.io.FileNotFoundException;
|
| - |
|
59 |
import java.io.InputStream;
|
| - |
|
60 |
import java.time.Instant;
|
| - |
|
61 |
import java.time.LocalDate;
|
| - |
|
62 |
import java.time.LocalDateTime;
|
| - |
|
63 |
import java.time.YearMonth;
|
| - |
|
64 |
import java.util.List;
|
| - |
|
65 |
import java.util.*;
|
| - |
|
66 |
import java.util.stream.Collectors;
|
| 87 |
|
67 |
|
| 88 |
@Controller
|
68 |
@Controller
|
| 89 |
@Transactional(rollbackOn = Throwable.class)
|
69 |
@Transactional(rollbackOn = Throwable.class)
|
| 90 |
public class OfferController {
|
70 |
public class OfferController {
|
| 91 |
private static final Logger LOGGER = LogManager.getLogger(OfferController.class);
|
71 |
private static final Logger LOGGER = LogManager.getLogger(OfferController.class);
|
| Line 179... |
Line 159... |
| 179 |
return "scheme_offer/published";
|
159 |
return "scheme_offer/published";
|
| 180 |
|
160 |
|
| 181 |
}
|
161 |
}
|
| 182 |
|
162 |
|
| 183 |
@RequestMapping(value = "/offer/active/{offerId}", method = RequestMethod.GET)
|
163 |
@RequestMapping(value = "/offer/active/{offerId}", method = RequestMethod.GET)
|
| 184 |
public String activateOffer(HttpServletRequest request, @PathVariable int offerId, Model model,
|
164 |
public String activateOffer(HttpServletRequest request, @PathVariable String offerIdsString, Model model,
|
| 185 |
@RequestParam(defaultValue = "true") boolean active) throws ProfitMandiBusinessException, Exception {
|
165 |
@RequestParam(defaultValue = "true") boolean active) throws ProfitMandiBusinessException, Exception {
|
| - |
|
166 |
List<Integer> offerIds = Arrays.stream(offerIdsString.split(",")).map(x -> Integer.parseInt(x)).collect(Collectors.toList());
|
| 186 |
Offer offer = offerRepository.selectById(offerId);
|
167 |
List<Offer> offers = offerRepository.selectAllByIds(offerIds);
|
| - |
|
168 |
boolean shouldEvict = false;
|
| - |
|
169 |
for (Offer offer : offers) {
|
| 187 |
boolean alreadyActive = offer.isActive();
|
170 |
boolean alreadyActive = offer.isActive();
|
| 188 |
if (alreadyActive != active) {
|
171 |
if (alreadyActive != active) {
|
| 189 |
offer.setActive(active);
|
172 |
offer.setActive(active);
|
| - |
|
173 |
shouldEvict = true;
|
| - |
|
174 |
}
|
| - |
|
175 |
if (active && !alreadyActive) {
|
| 190 |
oneDayCacheManager.getCache("catalog.published_yearmonth").evict(YearMonth.now());
|
176 |
this.sendNotification(offer);
|
| - |
|
177 |
}
|
| 191 |
}
|
178 |
}
|
| 192 |
if (active && !alreadyActive) {
|
179 |
if (shouldEvict) {
|
| 193 |
this.sendNotification(offer);
|
180 |
oneDayCacheManager.getCache("catalog.published_yearmonth").evict(YearMonth.now());
|
| 194 |
}
|
181 |
}
|
| 195 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
182 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 196 |
return "response";
|
183 |
return "response";
|
| 197 |
// CreateOfferRequest createOfferRequest =
|
184 |
// CreateOfferRequest createOfferRequest =
|
| 198 |
// offerService.getCreateOfferRequest(offer);
|
185 |
// offerService.getCreateOfferRequest(offer);
|