Subversion Repositories SmartDukaan

Rev

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

Rev 33973 Rev 35346
Line 3... Line 3...
3
import com.google.gson.Gson;
3
import com.google.gson.Gson;
4
import com.jcraft.jsch.*;
4
import com.jcraft.jsch.*;
5
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
5
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
6
import com.spice.profitmandi.common.solr.SolrService;
6
import com.spice.profitmandi.common.solr.SolrService;
7
import com.spice.profitmandi.dao.entity.catalog.Item;
7
import com.spice.profitmandi.dao.entity.catalog.Item;
8
import com.spice.profitmandi.dao.entity.catalog.SuperCatalog;
-
 
9
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
8
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
10
import com.spice.profitmandi.dao.entity.cs.Region;
9
import com.spice.profitmandi.dao.entity.cs.Region;
11
import com.spice.profitmandi.dao.entity.dtr.DocumentUrl;
10
import com.spice.profitmandi.dao.entity.dtr.DocumentUrl;
12
import com.spice.profitmandi.dao.entity.fofo.PrintResource;
11
import com.spice.profitmandi.dao.entity.fofo.PrintResource;
13
import com.spice.profitmandi.dao.entity.fofo.PrintResourceRegion;
12
import com.spice.profitmandi.dao.entity.fofo.PrintResourceRegion;
Line 36... Line 35...
36
import org.apache.logging.log4j.LogManager;
35
import org.apache.logging.log4j.LogManager;
37
import org.apache.logging.log4j.Logger;
36
import org.apache.logging.log4j.Logger;
38
import org.json.JSONArray;
37
import org.json.JSONArray;
39
import org.json.JSONObject;
38
import org.json.JSONObject;
40
import org.springframework.beans.factory.annotation.Autowired;
39
import org.springframework.beans.factory.annotation.Autowired;
-
 
40
import org.springframework.http.ResponseEntity;
41
import org.springframework.stereotype.Controller;
41
import org.springframework.stereotype.Controller;
42
import org.springframework.ui.Model;
42
import org.springframework.ui.Model;
43
import org.springframework.web.bind.annotation.*;
43
import org.springframework.web.bind.annotation.*;
44
import org.springframework.web.multipart.MultipartFile;
44
import org.springframework.web.multipart.MultipartFile;
45
 
45
 
Line 152... Line 152...
152
		mongoClient.persistEntity(contentPojo);
152
		mongoClient.persistEntity(contentPojo);
153
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
153
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
154
		return "response";
154
		return "response";
155
	}
155
	}
156
 
156
 
-
 
157
	@PostMapping(value = "/content/video/upload")
-
 
158
	public String uploadVideoUrls(HttpServletRequest request,
-
 
159
								  @RequestPart("file") MultipartFile file,
-
 
160
								  Model model) throws Exception {
-
 
161
 
-
 
162
		List<VideoUrlPojo> videoRows = readVideoFile(file);
-
 
163
 
-
 
164
		LOGGER.info("Received {} video rows", videoRows.size());
-
 
165
 
-
 
166
		// group by catalogId
-
 
167
		Map<Integer, List<VideoUrlPojo>> videoCatalogMap =
-
 
168
				videoRows.stream().collect(Collectors.groupingBy(VideoUrlPojo::getCatalogId));
-
 
169
 
-
 
170
		for (Map.Entry<Integer, List<VideoUrlPojo>> entry : videoCatalogMap.entrySet()) {
-
 
171
 
-
 
172
			int catalogId = entry.getKey();
-
 
173
			List<VideoUrlPojo> rowsForCatalog = entry.getValue();
-
 
174
 
-
 
175
			ContentPojo content = mongoClient.getEntityById(catalogId);
-
 
176
 
-
 
177
			if (content == null) {
-
 
178
				LOGGER.warn("No content found for catalogId {}", catalogId);
-
 
179
				continue;
-
 
180
			}
-
 
181
 
-
 
182
			updateVideoUrls(content, rowsForCatalog);
-
 
183
 
-
 
184
			mongoClient.persistEntity(content);
-
 
185
 
-
 
186
			LOGGER.info("Updated video URLs for catalogId {}", catalogId);
-
 
187
		}
-
 
188
 
-
 
189
		model.addAttribute("response1", mvcResponseSender.createResponseString(true));
-
 
190
		return "response";
-
 
191
	}
-
 
192
 
-
 
193
 
-
 
194
	private void updateVideoUrls(ContentPojo content, List<VideoUrlPojo> rows) {
-
 
195
 
-
 
196
		if (content.getVideoUrls() == null) {
-
 
197
			content.setVideoUrls(new ArrayList<>());
-
 
198
		}
-
 
199
 
-
 
200
		List<VideoUrlsContentPojo> existing = content.getVideoUrls();
-
 
201
 
-
 
202
		for (VideoUrlPojo row : rows) {
-
 
203
			VideoUrlsContentPojo newUrl = new VideoUrlsContentPojo(row.getUrl());
-
 
204
 
-
 
205
			// add only if not duplicate
-
 
206
			if (!existing.contains(newUrl)) {
-
 
207
				existing.add(newUrl);
-
 
208
			}
-
 
209
		}
-
 
210
 
-
 
211
		content.setVideoUrls(existing);
-
 
212
 
-
 
213
		LOGGER.info("Final video list = {}", existing);
-
 
214
	}
-
 
215
 
-
 
216
 
-
 
217
 
-
 
218
 
157
	@PostMapping(value = "/image/media/upload")
219
	@PostMapping(value = "/image/media/upload")
158
	public String uploadImageMediaContent(HttpServletRequest request, @RequestBody MediaPojo mediaPojo, Model model)
220
	public String uploadImageMediaContent(HttpServletRequest request, @RequestBody MediaPojo mediaPojo, Model model)
159
			throws Exception {
221
			throws Exception {
160
 
222
 
161
		LOGGER.info("mediaPojo" + mediaPojo);
223
		LOGGER.info("mediaPojo" + mediaPojo);
Line 352... Line 414...
352
		}
414
		}
353
		parser.close();
415
		parser.close();
354
		return returnList;
416
		return returnList;
355
	}
417
	}
356
 
418
 
-
 
419
 
-
 
420
	private List<VideoUrlPojo> readVideoFile(MultipartFile file) throws Exception {
-
 
421
 
-
 
422
		CSVParser parser = new CSVParser(
-
 
423
				new InputStreamReader(file.getInputStream()),
-
 
424
				CSVFormat.DEFAULT
-
 
425
		);
-
 
426
 
-
 
427
		List<CSVRecord> records = parser.getRecords();
-
 
428
 
-
 
429
		if (records.size() < 2) {
-
 
430
			parser.close();
-
 
431
			throw new ProfitMandiBusinessException("Uploaded File", "", "No records found");
-
 
432
		}
-
 
433
 
-
 
434
		// Remove header
-
 
435
		records.remove(0);
-
 
436
 
-
 
437
		List<VideoUrlPojo> returnList = new ArrayList<>();
-
 
438
 
-
 
439
		for (CSVRecord record : records) {
-
 
440
 
-
 
441
			try {
-
 
442
				// Must match CSV column order
-
 
443
				Long catalogId = Long.parseLong(record.get(0));
-
 
444
				String url = record.get(1);
-
 
445
 
-
 
446
				VideoUrlPojo row = new VideoUrlPojo();
-
 
447
				row.setCatalogId(Math.toIntExact(catalogId));
-
 
448
				row.setUrl(url);
-
 
449
 
-
 
450
				returnList.add(row);
-
 
451
 
-
 
452
			} catch (Exception e) {
-
 
453
				// skip bad rows, same as your style
-
 
454
				continue;
-
 
455
			}
-
 
456
		}
-
 
457
 
-
 
458
		parser.close();
-
 
459
		return returnList;
-
 
460
	}
-
 
461
 
-
 
462
 
357
	private List<SpecificationGroup> getDetailedSpecs(CSVRecord record) throws Exception {
463
	private List<SpecificationGroup> getDetailedSpecs(CSVRecord record) throws Exception {
358
		List<SpecificationGroup> specificationGroups = new ArrayList<>();
464
		List<SpecificationGroup> specificationGroups = new ArrayList<>();
359
		int currentIndex = 8;
465
		int currentIndex = 8;
360
		while (StringUtils.isNotEmpty(record.get(currentIndex))) {
466
		while (StringUtils.isNotEmpty(record.get(currentIndex))) {
361
			int start = currentIndex;
467
			int start = currentIndex;
Line 602... Line 708...
602
		List<PrintResource> printResources = printResourceRepository.selectAllPrintResources(currentDate);
708
		List<PrintResource> printResources = printResourceRepository.selectAllPrintResources(currentDate);
603
		model.addAttribute("printResources", printResources);
709
		model.addAttribute("printResources", printResources);
604
		return "all-print-resource";
710
		return "all-print-resource";
605
	}
711
	}
606
 
712
 
-
 
713
	@GetMapping("/content/video/check/{catalogId}")
-
 
714
	public ResponseEntity<?> checkVideo(@PathVariable int catalogId) throws Exception {
-
 
715
		ContentPojo cp = mongoClient.getEntityById(catalogId);
-
 
716
 
-
 
717
		LOGGER.info("Video Url {}", cp.getVideoUrls());
-
 
718
		return ResponseEntity.ok(cp.getVideoUrls());
-
 
719
	}
-
 
720
 
-
 
721
 
607
}
722
}