Subversion Repositories SmartDukaan

Rev

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

Rev 37208 Rev 37214
Line 25... Line 25...
25
import com.spice.profitmandi.dao.repository.dtr.DocumentUrlRepository;
25
import com.spice.profitmandi.dao.repository.dtr.DocumentUrlRepository;
26
import com.spice.profitmandi.dao.repository.dtr.Mongo;
26
import com.spice.profitmandi.dao.repository.dtr.Mongo;
27
import com.spice.profitmandi.dao.repository.fofo.PrintResourceRegionRepository;
27
import com.spice.profitmandi.dao.repository.fofo.PrintResourceRegionRepository;
28
import com.spice.profitmandi.dao.repository.fofo.PrintResourceRepository;
28
import com.spice.profitmandi.dao.repository.fofo.PrintResourceRepository;
29
import com.spice.profitmandi.dao.repository.user.UserRepository;
29
import com.spice.profitmandi.dao.repository.user.UserRepository;
-
 
30
import com.spice.profitmandi.service.catalog.CategorySpecUtil;
30
import com.spice.profitmandi.service.catalog.ItemLoaderService;
31
import com.spice.profitmandi.service.catalog.ItemLoaderService;
31
import com.spice.profitmandi.web.model.EntityMediaPojo;
32
import com.spice.profitmandi.web.model.EntityMediaPojo;
32
import com.spice.profitmandi.web.model.LoginDetails;
33
import com.spice.profitmandi.web.model.LoginDetails;
33
import com.spice.profitmandi.web.util.CookiesProcessor;
34
import com.spice.profitmandi.web.util.CookiesProcessor;
34
import com.spice.profitmandi.web.util.MVCResponseSender;
35
import com.spice.profitmandi.web.util.MVCResponseSender;
Line 94... Line 95...
94
	@Autowired
95
	@Autowired
95
	CatalogRepository catalogRepository;
96
	CatalogRepository catalogRepository;
96
	@Autowired
97
	@Autowired
97
	CatalogMonitorTypeRepository catalogMonitorTypeRepository;
98
	CatalogMonitorTypeRepository catalogMonitorTypeRepository;
98
	@Autowired
99
	@Autowired
-
 
100
	CategorySpecDefinitionRepository categorySpecDefinitionRepository;
-
 
101
	@Autowired
99
	BulletinRepository bulletinRepository;
102
	BulletinRepository bulletinRepository;
100
	private Gson gson = new Gson();
103
	private Gson gson = new Gson();
101
 
104
 
102
	public static final int Entity_Id = 0;
105
	public static final int Entity_Id = 0;
103
	public static final int Title = 1;
106
	public static final int Title = 1;
Line 105... Line 108...
105
	public static final int KeySpec2 = 3;
108
	public static final int KeySpec2 = 3;
106
	public static final int KeySpec3 = 4;
109
	public static final int KeySpec3 = 4;
107
	public static final int KeySpec4 = 5;
110
	public static final int KeySpec4 = 5;
108
	public static final int Warranty = 6;
111
	public static final int Warranty = 6;
109
	public static final int Package_Contents = 7;
112
	public static final int Package_Contents = 7;
-
 
113
	// new-layout template only: SpecValue1..5 at 8-12, detailed specs from 13.
-
 
114
	// Legacy templates (no SpecValue header at col 8) keep detailed specs at 8.
-
 
115
	public static final int SpecValue1 = 8;
-
 
116
	public static final int SPEC_VALUE_COUNT = 5;
-
 
117
	public static final int DetailedSpecsLegacyStart = 8;
-
 
118
	public static final int DetailedSpecsSpecLayoutStart = 13;
110
	private static final String IMAGE_REMOTE_DIR = "/var/www/dtrdashboard/uploads/campaigns/";
119
	private static final String IMAGE_REMOTE_DIR = "/var/www/dtrdashboard/uploads/campaigns/";
111
	private static final String IMAGE_STATIC_SERVER_URL = "https://images.smartdukaan.com/uploads/campaigns";
120
	private static final String IMAGE_STATIC_SERVER_URL = "https://images.smartdukaan.com/uploads/campaigns";
112
 
121
 
113
	private static final String REMOTE_DIR = "/var/www/static.saholic.com/images/media/";
122
	private static final String REMOTE_DIR = "/var/www/static.saholic.com/images/media/";
114
	// private static final String REMOTE_DIR = "/tmp";
123
	// private static final String REMOTE_DIR = "/tmp";
Line 455... Line 464...
455
		List<CSVRecord> records = parser.getRecords();
464
		List<CSVRecord> records = parser.getRecords();
456
		if (records.size() < 2) {
465
		if (records.size() < 2) {
457
			parser.close();
466
			parser.close();
458
			throw new ProfitMandiBusinessException("Uploaded File", "", "No records Found");
467
			throw new ProfitMandiBusinessException("Uploaded File", "", "No records Found");
459
		}
468
		}
-
 
469
		// header decides the layout: SpecValue columns present at 8-12 or not
-
 
470
		CSVRecord header = records.get(0);
-
 
471
		boolean specLayout = header.size() > SpecValue1 && header.get(SpecValue1) != null
-
 
472
				&& header.get(SpecValue1).trim().toUpperCase().startsWith("SPECVALUE");
460
		// Remove header
473
		// Remove header
461
		records.remove(0);
474
		records.remove(0);
462
		List<ContentPojo> returnList = new ArrayList<ContentPojo>();
475
		List<ContentPojo> returnList = new ArrayList<ContentPojo>();
463
		for (CSVRecord record : records) {
476
		for (CSVRecord record : records) {
464
			ContentPojo cp = null;
477
			ContentPojo cp = null;
Line 474... Line 487...
474
				cp.setWarranty(record.get(Warranty));
487
				cp.setWarranty(record.get(Warranty));
475
				cp.setKeySpecs(Arrays
488
				cp.setKeySpecs(Arrays
476
						.asList(record.get(KeySpec1), record.get(KeySpec2), record.get(KeySpec3), record.get(KeySpec4))
489
						.asList(record.get(KeySpec1), record.get(KeySpec2), record.get(KeySpec3), record.get(KeySpec4))
477
						.stream().filter(x -> x != null && !x.equals("")).collect(Collectors.toList()));
490
						.stream().filter(x -> x != null && !x.equals("")).collect(Collectors.toList()));
478
				cp.setPackageContents(Arrays.asList(record.get(Package_Contents).split(",")));
491
				cp.setPackageContents(Arrays.asList(record.get(Package_Contents).split(",")));
479
				cp.setDetailedSpecs(getDetailedSpecs(record));
492
				cp.setDetailedSpecs(getDetailedSpecs(record,
-
 
493
						specLayout ? DetailedSpecsSpecLayoutStart : DetailedSpecsLegacyStart));
480
				if (cp.getCategoryId() == null) {
494
				if (cp.getCategoryId() == null) {
481
					Catalog catalog = catalogRepository.selectCatalogById(Math.toIntExact(entityId));
495
					Catalog catalog = catalogRepository.selectCatalogById(Math.toIntExact(entityId));
482
					if (catalog != null) {
496
					if (catalog != null) {
483
						cp.setCategoryId(catalog.getCategoryId());
497
						cp.setCategoryId(catalog.getCategoryId());
484
					}
498
					}
485
				}
499
				}
-
 
500
				if (specLayout) {
-
 
501
					List<String> specValues = new ArrayList<>();
-
 
502
					for (int col = SpecValue1; col < SpecValue1 + SPEC_VALUE_COUNT; col++) {
-
 
503
						specValues.add(record.size() > col ? record.get(col) : "");
-
 
504
					}
-
 
505
					boolean anyValue = specValues.stream().anyMatch(v -> v != null && !v.trim().isEmpty());
-
 
506
					if (anyValue) {
-
 
507
						if (cp.getCategoryId() == null) {
-
 
508
							throw new ProfitMandiBusinessException("CatalogId", String.valueOf(entityId),
-
 
509
									"Spec values supplied but catalog/category unknown");
-
 
510
						}
-
 
511
						cp.setCategorySpecs(CategorySpecUtil.pairValues(
-
 
512
								categorySpecDefinitionRepository.selectActiveByCategoryId(cp.getCategoryId()),
-
 
513
								specValues));
-
 
514
					}
-
 
515
					// all-blank spec columns: leave existing categorySpecs untouched
-
 
516
				}
486
				returnList.add(cp);
517
				returnList.add(cp);
-
 
518
			} catch (ProfitMandiBusinessException e) {
-
 
519
				parser.close();
-
 
520
				throw new ProfitMandiBusinessException(e.getRejectedType(), e.getRejectedValue(),
-
 
521
						e.getCode() + " at row " + record.getRecordNumber());
487
			} catch (Exception e) {
522
			} catch (Exception e) {
488
				continue;
523
				continue;
489
			}
524
			}
490
		}
525
		}
491
		parser.close();
526
		parser.close();
Line 534... Line 569...
534
		parser.close();
569
		parser.close();
535
		return returnList;
570
		return returnList;
536
	}
571
	}
537
 
572
 
538
 
573
 
539
	private List<SpecificationGroup> getDetailedSpecs(CSVRecord record) throws Exception {
574
	private List<SpecificationGroup> getDetailedSpecs(CSVRecord record, int startIndex) throws Exception {
540
		List<SpecificationGroup> specificationGroups = new ArrayList<>();
575
		List<SpecificationGroup> specificationGroups = new ArrayList<>();
541
		int currentIndex = 8;
576
		int currentIndex = startIndex;
542
		while (StringUtils.isNotEmpty(record.get(currentIndex))) {
577
		while (StringUtils.isNotEmpty(record.get(currentIndex))) {
543
			int start = currentIndex;
578
			int start = currentIndex;
544
			List<Specification> specifications = new ArrayList<>();
579
			List<Specification> specifications = new ArrayList<>();
545
			int begin = 0;
580
			int begin = 0;
546
			while (begin < 5) {
581
			while (begin < 5) {