| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import com.google.gson.Gson;
|
3 |
import com.google.gson.Gson;
|
| - |
|
4 |
import com.google.gson.JsonObject;
|
| 4 |
import com.jcraft.jsch.*;
|
5 |
import com.jcraft.jsch.*;
|
| 5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
6 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 6 |
import com.spice.profitmandi.common.solr.SolrService;
|
7 |
import com.spice.profitmandi.common.solr.SolrService;
|
| - |
|
8 |
import com.spice.profitmandi.dao.entity.catalog.FocusedModel;
|
| 7 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
9 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 8 |
import com.spice.profitmandi.dao.entity.dtr.DocumentUrl;
|
10 |
import com.spice.profitmandi.dao.entity.dtr.DocumentUrl;
|
| 9 |
import com.spice.profitmandi.dao.model.ContentPojo;
|
11 |
import com.spice.profitmandi.dao.model.ContentPojo;
|
| 10 |
import com.spice.profitmandi.dao.model.MediaPojo;
|
12 |
import com.spice.profitmandi.dao.model.MediaPojo;
|
| 11 |
import com.spice.profitmandi.dao.model.Specification;
|
13 |
import com.spice.profitmandi.dao.model.Specification;
|
| 12 |
import com.spice.profitmandi.dao.model.SpecificationGroup;
|
14 |
import com.spice.profitmandi.dao.model.SpecificationGroup;
|
| - |
|
15 |
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
|
| 13 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
16 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 14 |
import com.spice.profitmandi.dao.repository.dtr.DocumentUrlRepository;
|
17 |
import com.spice.profitmandi.dao.repository.dtr.DocumentUrlRepository;
|
| 15 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
18 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 16 |
import com.spice.profitmandi.web.model.EntityMediaPojo;
|
19 |
import com.spice.profitmandi.web.model.EntityMediaPojo;
|
| 17 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
20 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| Line 19... |
Line 22... |
| 19 |
import org.apache.commons.csv.CSVParser;
|
22 |
import org.apache.commons.csv.CSVParser;
|
| 20 |
import org.apache.commons.csv.CSVRecord;
|
23 |
import org.apache.commons.csv.CSVRecord;
|
| 21 |
import org.apache.commons.lang3.StringUtils;
|
24 |
import org.apache.commons.lang3.StringUtils;
|
| 22 |
import org.apache.logging.log4j.LogManager;
|
25 |
import org.apache.logging.log4j.LogManager;
|
| 23 |
import org.apache.logging.log4j.Logger;
|
26 |
import org.apache.logging.log4j.Logger;
|
| - |
|
27 |
import org.json.JSONArray;
|
| - |
|
28 |
import org.json.JSONObject;
|
| 24 |
import org.springframework.beans.factory.annotation.Autowired;
|
29 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 25 |
import org.springframework.stereotype.Controller;
|
30 |
import org.springframework.stereotype.Controller;
|
| 26 |
import org.springframework.ui.Model;
|
31 |
import org.springframework.ui.Model;
|
| 27 |
import org.springframework.web.bind.annotation.*;
|
32 |
import org.springframework.web.bind.annotation.*;
|
| 28 |
import org.springframework.web.multipart.MultipartFile;
|
33 |
import org.springframework.web.multipart.MultipartFile;
|
| Line 54... |
Line 59... |
| 54 |
ItemRepository itemRepository;
|
59 |
ItemRepository itemRepository;
|
| 55 |
|
60 |
|
| 56 |
@Autowired
|
61 |
@Autowired
|
| 57 |
DocumentUrlRepository documentUrlRepository;
|
62 |
DocumentUrlRepository documentUrlRepository;
|
| 58 |
|
63 |
|
| - |
|
64 |
@Autowired
|
| - |
|
65 |
FocusedModelRepository focusedModelRepository;
|
| 59 |
private Gson gson = new Gson();
|
66 |
private Gson gson = new Gson();
|
| 60 |
|
67 |
|
| 61 |
public static final int Entity_Id = 0;
|
68 |
public static final int Entity_Id = 0;
|
| 62 |
public static final int Title = 1;
|
69 |
public static final int Title = 1;
|
| 63 |
public static final int KeySpec1 = 2;
|
70 |
public static final int KeySpec1 = 2;
|
| Line 68... |
Line 75... |
| 68 |
public static final int Package_Contents = 7;
|
75 |
public static final int Package_Contents = 7;
|
| 69 |
private static final String IMAGE_REMOTE_DIR = "/var/www/dtrdashboard/uploads/campaigns/";
|
76 |
private static final String IMAGE_REMOTE_DIR = "/var/www/dtrdashboard/uploads/campaigns/";
|
| 70 |
private static final String IMAGE_STATIC_SERVER_URL = "https://images.smartdukaan.com/uploads/campaigns";
|
77 |
private static final String IMAGE_STATIC_SERVER_URL = "https://images.smartdukaan.com/uploads/campaigns";
|
| 71 |
|
78 |
|
| 72 |
private static final String REMOTE_DIR = "/var/www/static.saholic.com/images/media/";
|
79 |
private static final String REMOTE_DIR = "/var/www/static.saholic.com/images/media/";
|
| 73 |
//private static final String REMOTE_DIR = "/tmp";
|
80 |
// private static final String REMOTE_DIR = "/tmp";
|
| 74 |
private static final String STATIC_SERVER_URL = "https://static%d.smartdukaan.com/images/media/";
|
81 |
private static final String STATIC_SERVER_URL = "https://static%d.smartdukaan.com/images/media/";
|
| 75 |
|
82 |
|
| 76 |
private static final String THUMBNAIL = "thumbnail";
|
83 |
private static final String THUMBNAIL = "thumbnail";
|
| 77 |
private static final String ICON = "icon";
|
84 |
private static final String ICON = "icon";
|
| 78 |
private static final String DEFAULT = "default";
|
85 |
private static final String DEFAULT = "default";
|
| Line 152... |
Line 159... |
| 152 |
|
159 |
|
| 153 |
model.addAttribute("documents", du);
|
160 |
model.addAttribute("documents", du);
|
| 154 |
return "image-url";
|
161 |
return "image-url";
|
| 155 |
}
|
162 |
}
|
| 156 |
|
163 |
|
| 157 |
|
- |
|
| 158 |
private void fileUpload(ChannelSftp channelSftp, Map<String, InputStream> streamsFileMap, String destinationPath)
|
164 |
private void fileUpload(ChannelSftp channelSftp, Map<String, InputStream> streamsFileMap, String destinationPath)
|
| 159 |
throws SftpException, FileNotFoundException {
|
165 |
throws SftpException, FileNotFoundException {
|
| 160 |
|
166 |
|
| 161 |
channelSftp.cd(destinationPath);
|
167 |
channelSftp.cd(destinationPath);
|
| 162 |
String folderName = "image" + LocalDate.now();
|
168 |
String folderName = "image" + LocalDate.now();
|
| Line 230... |
Line 236... |
| 230 |
return ep;
|
236 |
return ep;
|
| 231 |
}
|
237 |
}
|
| 232 |
|
238 |
|
| 233 |
@GetMapping(value = "/entity")
|
239 |
@GetMapping(value = "/entity")
|
| 234 |
public String searchEntity(HttpServletRequest request, @RequestParam(defaultValue = "null") String query,
|
240 |
public String searchEntity(HttpServletRequest request, @RequestParam(defaultValue = "null") String query,
|
| 235 |
@RequestParam(defaultValue = "0") int categoryId, @RequestParam(defaultValue = "") List<String> brands,
|
241 |
@RequestParam(defaultValue = "0") int categoryId, @RequestParam(defaultValue = "") List<String> brands,
|
| 236 |
@RequestParam(defaultValue = "30") int limit,
|
242 |
@RequestParam(defaultValue = "30") int limit, @RequestParam(defaultValue = "true") boolean activeOnly,
|
| - |
|
243 |
Model model) throws Exception {
|
| - |
|
244 |
model.addAttribute("response1", solrService.getContent(query, categoryId > 0 ? Arrays.asList(categoryId) : null,
|
| - |
|
245 |
brands, limit, activeOnly));
|
| - |
|
246 |
return "response";
|
| - |
|
247 |
}
|
| - |
|
248 |
|
| - |
|
249 |
@GetMapping(value = "/focusedEntity")
|
| - |
|
250 |
public String focusedEntity(HttpServletRequest request, @RequestParam(defaultValue = "null") String query,
|
| - |
|
251 |
@RequestParam(defaultValue = "0") int categoryId, @RequestParam(defaultValue = "") List<String> brands,
|
| 237 |
@RequestParam(defaultValue = "true") boolean activeOnly,
|
252 |
@RequestParam(defaultValue = "30") int limit, @RequestParam(defaultValue = "true") boolean activeOnly,
|
| 238 |
Model model) throws Exception {
|
253 |
Model model) throws Exception {
|
| - |
|
254 |
|
| - |
|
255 |
List<Integer> catalogIds = focusedModelRepository.selectAll().stream().map(x -> x.getCatalogId())
|
| - |
|
256 |
.collect(Collectors.toList());
|
| 239 |
model.addAttribute("response1", solrService.getContent(query, categoryId > 0 ? Arrays.asList(categoryId) : null, brands, limit, activeOnly));
|
257 |
JSONArray docA = solrService.getContentDocs(query, categoryId > 0 ? Arrays.asList(categoryId) : null, brands,
|
| - |
|
258 |
limit, activeOnly);
|
| - |
|
259 |
|
| - |
|
260 |
Iterator<Object> jsonIterator = docA.iterator();
|
| - |
|
261 |
while (jsonIterator.hasNext()) {
|
| - |
|
262 |
JSONObject i = (JSONObject) jsonIterator.next();
|
| - |
|
263 |
|
| - |
|
264 |
if (!catalogIds.contains(i.get("catalogId_i"))) {
|
| - |
|
265 |
jsonIterator.remove();
|
| - |
|
266 |
}
|
| - |
|
267 |
|
| - |
|
268 |
}
|
| - |
|
269 |
|
| - |
|
270 |
model.addAttribute("response1", docA.toString());
|
| - |
|
271 |
|
| 240 |
return "response";
|
272 |
return "response";
|
| 241 |
}
|
273 |
}
|
| 242 |
|
274 |
|
| 243 |
@GetMapping(value = "/content/index")
|
275 |
@GetMapping(value = "/content/index")
|
| 244 |
public String index(HttpServletRequest request, Model model) throws Exception {
|
276 |
public String index(HttpServletRequest request, Model model) throws Exception {
|
| Line 309... |
Line 341... |
| 309 |
}
|
341 |
}
|
| 310 |
|
342 |
|
| 311 |
private ChannelSftp setupJsch() throws JSchException {
|
343 |
private ChannelSftp setupJsch() throws JSchException {
|
| 312 |
JSch jsch = new JSch();
|
344 |
JSch jsch = new JSch();
|
| 313 |
Session jschSession = jsch.getSession("root", "192.168.179.131");
|
345 |
Session jschSession = jsch.getSession("root", "192.168.179.131");
|
| 314 |
//Session jschSession = jsch.getSession("root", "173.255.254.24");
|
346 |
// Session jschSession = jsch.getSession("root", "173.255.254.24");
|
| - |
|
347 |
LOGGER.info("getClass().getResource(\"id_rsa\") {}",
|
| 315 |
LOGGER.info("getClass().getResource(\"id_rsa\") {}", getClass().getClassLoader().getResource("id_rsa").getPath());
|
348 |
getClass().getClassLoader().getResource("id_rsa").getPath());
|
| 316 |
jsch.addIdentity(getClass().getClassLoader().getResource("id_rsa").getPath());
|
349 |
jsch.addIdentity(getClass().getClassLoader().getResource("id_rsa").getPath());
|
| 317 |
//jschSession.setPassword("spic@2015static0");
|
350 |
// jschSession.setPassword("spic@2015static0");
|
| 318 |
jschSession.setConfig("StrictHostKeyChecking", "no");
|
351 |
jschSession.setConfig("StrictHostKeyChecking", "no");
|
| 319 |
jschSession.connect();
|
352 |
jschSession.connect();
|
| 320 |
return (ChannelSftp) jschSession.openChannel("sftp");
|
353 |
return (ChannelSftp) jschSession.openChannel("sftp");
|
| 321 |
}
|
354 |
}
|
| 322 |
|
355 |
|