Subversion Repositories SmartDukaan

Rev

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

Rev 10151 Rev 10162
Line 60... Line 60...
60
import org.apache.thrift.TException;
60
import org.apache.thrift.TException;
61
import org.apache.thrift.transport.TTransportException;
61
import org.apache.thrift.transport.TTransportException;
62
 
62
 
63
import com.google.gson.Gson;
63
import com.google.gson.Gson;
64
 
64
 
65
public class UpdateSnapdealInventoryUsingPanel{
65
public class UpdateSnapdealInventoryUsingPanel {
-
 
66
	private static final boolean PANEL = true;
66
	private static long time = System.currentTimeMillis();
67
	private static long time = System.currentTimeMillis();
67
	private static String SNAPDEAL_INVENTORY_SHEET;
68
	private static String SNAPDEAL_INVENTORY_SHEET;
68
	private static Map<Long, SnapdealItemForInventory> allItemsInventoryMap = new HashMap<Long, SnapdealItemForInventory>();
69
	private static Map<Long, SnapdealItemForInventory> allItemsInventoryMap = new HashMap<Long, SnapdealItemForInventory>();
69
	private static ArrayList<Inventory> currentInventoryItemList;
70
	private static ArrayList<Inventory> currentInventoryItemList;
70
	static Map<Long,Long> itemIdpendingOrdersMap;
71
	static Map<Long,Long> itemIdpendingOrdersMap;
Line 78... Line 79...
78
	static String emailFromAddress;
79
	static String emailFromAddress;
79
	static String password;
80
	static String password;
80
	static GmailUtils mailer;
81
	static GmailUtils mailer;
81
	static String sendTo[];
82
	static String sendTo[];
82
	static StringBuffer notMappedItems =new StringBuffer();
83
	static StringBuffer notMappedItems =new StringBuffer();
83
	private static boolean UPDATEUSINGPANEL=true;
-
 
84
	static{
84
	static{
85
		sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
85
		sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
86
		emailFromAddress = "build@shop2020.in";
86
		emailFromAddress = "build@shop2020.in";
87
		password = "cafe@nes";
87
		password = "cafe@nes";
88
		mailer = new GmailUtils();
88
		mailer = new GmailUtils();
Line 100... Line 100...
100
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
100
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
101
		List<SnapdealItemDetails> allSnapdealItems = null;
101
		List<SnapdealItemDetails> allSnapdealItems = null;
102
		try {
102
		try {
103
			allSnapdealItems = catalogClient.getAllSnapdealItems();
103
			allSnapdealItems = catalogClient.getAllSnapdealItems();
104
		} catch (TException e) {
104
		} catch (TException e) {
-
 
105
 
105
			e.printStackTrace();
106
			e.printStackTrace();
106
		}
107
		}
107
		for(SnapdealItemDetails snapdealItem:allSnapdealItems){
108
		for(SnapdealItemDetails snapdealItem:allSnapdealItems){
108
			snapdealItemMap.put(snapdealItem.getSkuAtSnapdeal(),snapdealItem);
109
			snapdealItemMap.put(snapdealItem.getSkuAtSnapdeal(),snapdealItem);
109
			itemSnapdealMap.put(snapdealItem.getItem_id(), snapdealItem);
110
			itemSnapdealMap.put(snapdealItem.getItem_id(), snapdealItem);
Line 120... Line 121...
120
				lastUpdatedInventoryTime = transactionClient.getSourceDetail(7).getLastUpdatedOn();
121
				lastUpdatedInventoryTime = transactionClient.getSourceDetail(7).getLastUpdatedOn();
121
			} catch (Exception ex) {
122
			} catch (Exception ex) {
122
				ex.printStackTrace();
123
				ex.printStackTrace();
123
			}
124
			}
124
		}
125
		}
-
 
126
 
125
	}
127
	}
126
 
128
 
127
	private static void calculateinventory(){
129
	private static void calculateinventory(){
128
		CatalogClient catalogServiceClient = null;
130
		CatalogClient catalogServiceClient = null;
129
		Map<Long,ItemInventory> availability= new HashMap<Long,ItemInventory>();
131
		Map<Long,ItemInventory> availability= new HashMap<Long,ItemInventory>();
130
		try {
132
		try {
131
			catalogServiceClient = new CatalogClient();
133
			catalogServiceClient = new CatalogClient();
132
		} catch (TTransportException e) {
134
		} catch (TTransportException e) {
-
 
135
 
133
			e.printStackTrace();
136
			e.printStackTrace();
134
		}
137
		}
135
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
138
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
136
		try {
139
		try {
137
			List<Item> aliveItems = catalogClient.getAllAliveItems();
140
			List<Item> aliveItems = catalogClient.getAllAliveItems();
138
			Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>(); 
141
			Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>(); 
139
			for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItems){
142
			for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItems){
140
				aliveItemsMap.put(thriftItem.getId(), thriftItem);
143
				aliveItemsMap.put(thriftItem.getId(), thriftItem);
-
 
144
 
141
			}
145
			}
142
			InventoryClient inventoryServiceClient = new InventoryClient();
146
			InventoryClient inventoryServiceClient = new InventoryClient();
143
			try {
147
			try {
144
				inventoryServiceClient = new InventoryClient();
148
				inventoryServiceClient = new InventoryClient();
145
			} catch (TTransportException e) {
149
			} catch (TTransportException e) {
Line 361... Line 365...
361
				allItemsInventoryMap.put(thriftItem.getId(),item);
365
				allItemsInventoryMap.put(thriftItem.getId(),item);
362
 
366
 
363
			}
367
			}
364
 
368
 
365
		} catch (TException e) {
369
		} catch (TException e) {
-
 
370
 
366
			e.printStackTrace();
371
			e.printStackTrace();
367
		}
372
		}
368
 
373
 
369
	}
374
	}
370
	private static void fetchinventoryhistoryfromsnapdeal() throws UnsupportedEncodingException, TException{
375
	private static void fetchinventoryhistoryfromsnapdeal() throws UnsupportedEncodingException, TException{
Line 381... Line 386...
381
			get = new HttpGet("http://seller.snapdeal.com/inventory/search?gridType=history&_search=false&nd="+time+"&rows=30&page="+i+"&sidx=&sord=dsc");
386
			get = new HttpGet("http://seller.snapdeal.com/inventory/search?gridType=history&_search=false&nd="+time+"&rows=30&page="+i+"&sidx=&sord=dsc");
382
 
387
 
383
			try {
388
			try {
384
				response = client.execute(get);
389
				response = client.execute(get);
385
			} catch (ClientProtocolException e) {
390
			} catch (ClientProtocolException e) {
-
 
391
 
386
				e.printStackTrace();
392
				e.printStackTrace();
387
			} catch (IOException e) {
393
			} catch (IOException e) {
-
 
394
 
388
				e.printStackTrace();
395
				e.printStackTrace();
389
			}
396
			}
390
 
397
 
391
			try {
398
			try {
392
				rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
399
				rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
393
 
400
 
394
			} catch (IllegalStateException e) {
401
			} catch (IllegalStateException e) {
-
 
402
 
395
				e.printStackTrace();
403
				e.printStackTrace();
396
			} catch (IOException e) {
404
			} catch (IOException e) {
-
 
405
 
397
				e.printStackTrace();
406
				e.printStackTrace();
398
			}
407
			}
399
			InventoryHistoryItems inventoryhistoryitems = (InventoryHistoryItems) gson.fromJson(rd, InventoryHistoryItems.class);
408
			InventoryHistoryItems inventoryhistoryitems = (InventoryHistoryItems) gson.fromJson(rd, InventoryHistoryItems.class);
400
			if(inventoryhistoryitems.getRows().size()!=0){
409
			if(inventoryhistoryitems.getRows().size()!=0){
401
				//System.out.println("Parsing page " + i);
410
				//System.out.println("Parsing page " + i);
402
				for(InventoryHistory inventoryhistory : inventoryhistoryitems.getRows()){
411
				for(InventoryHistory inventoryhistory : inventoryhistoryitems.getRows()){
403
					System.out.println("Inventory History " + inventoryhistory.getSellerSku() +" "+ inventoryhistory.getSupc()+" "+inventoryhistory.getNewValue());
412
					//System.out.println("Inventory History " + inventoryhistory.getSellerSku() +" "+ inventoryhistory.getSupc());
404
					if(inventoryhistory.getUpdateTime() > lastUpdatedInventoryTime){
413
					if(inventoryhistory.getUpdateTime() > lastUpdatedInventoryTime){
405
						if(inventoryhistoryItemMap.containsKey(inventoryhistory.getSellerSku())){
414
						if(inventoryhistoryItemMap.containsKey(inventoryhistory.getSellerSku())){
406
							if(inventoryhistoryItemMap.get(inventoryhistory.getSellerSku()).getUpdateTime() < inventoryhistory.getUpdateTime()){  
415
							if(inventoryhistoryItemMap.get(inventoryhistory.getSellerSku()).getUpdateTime() < inventoryhistory.getUpdateTime()){  
407
								inventoryhistoryItemMap.put(inventoryhistory.getSellerSku(),inventoryhistory);
416
								inventoryhistoryItemMap.put(inventoryhistory.getSellerSku(),inventoryhistory);
408
							}
417
							}
Line 423... Line 432...
423
		}
432
		}
424
		if(inventoryhistoryItemMap.entrySet().size()==0){
433
		if(inventoryhistoryItemMap.entrySet().size()==0){
425
			try {
434
			try {
426
				mailer.sendSSLMessage(sendTo,"Error : Last Inventory Sent still not updated"+ sdf.format(System.currentTimeMillis()),"This e-mail is sent when there is some time lag on inventory updation on snapdeal ", emailFromAddress, password, new ArrayList<File>());
435
				mailer.sendSSLMessage(sendTo,"Error : Last Inventory Sent still not updated"+ sdf.format(System.currentTimeMillis()),"This e-mail is sent when there is some time lag on inventory updation on snapdeal ", emailFromAddress, password, new ArrayList<File>());
427
			} catch (MessagingException e) {
436
			} catch (MessagingException e) {
-
 
437
 
428
				e.printStackTrace();
438
				e.printStackTrace();
429
			}
439
			}
430
		}
440
		}
431
		InventoryClient inventoryServiceClient = new InventoryClient();
441
		InventoryClient inventoryServiceClient = new InventoryClient();
432
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
442
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
Line 474... Line 484...
474
			//System.out.println("Fetching current inventory page " +i);
484
			//System.out.println("Fetching current inventory page " +i);
475
			get = new HttpGet("http://seller.snapdeal.com/inventory/search?gridType=normal&_search=false&nd="+time+"&rows="+30+"&page="+i+"&sidx=&sord=asc");
485
			get = new HttpGet("http://seller.snapdeal.com/inventory/search?gridType=normal&_search=false&nd="+time+"&rows="+30+"&page="+i+"&sidx=&sord=asc");
476
			try {
486
			try {
477
				response = client.execute(get);
487
				response = client.execute(get);
478
			} catch (ClientProtocolException e) {
488
			} catch (ClientProtocolException e) {
-
 
489
 
479
				e.printStackTrace();
490
				e.printStackTrace();
480
			} catch (IOException e) {
491
			} catch (IOException e) {
-
 
492
 
481
				e.printStackTrace();
493
				e.printStackTrace();
482
			}
494
			}
483
			try {
495
			try {
484
				rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
496
				rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
485
			} catch (IllegalStateException e) {
497
			} catch (IllegalStateException e) {
-
 
498
 
486
				e.printStackTrace();
499
				e.printStackTrace();
487
			} catch (IOException e) {
500
			} catch (IOException e) {
-
 
501
 
488
				e.printStackTrace();
502
				e.printStackTrace();
489
			}
503
			}
490
			InventoryItems inventoryitems = (InventoryItems) gson.fromJson(rd, InventoryItems.class);
504
			InventoryItems inventoryitems = (InventoryItems) gson.fromJson(rd, InventoryItems.class);
491
			if(inventoryitems.getRows().size()!=0){
505
			if(inventoryitems.getRows().size()!=0){
492
				for(Inventory inventory : inventoryitems.getRows()){
506
				for(Inventory inventory : inventoryitems.getRows()){
Line 522... Line 536...
522
			if(lastUpdatedInventoryTime > 0){
536
			if(lastUpdatedInventoryTime > 0){
523
				itemIdCreatedOrdersMap = transactionClient.getOrdersCreatedAfterTimestampForSource(lastUpdatedInventoryTime, 7);
537
				itemIdCreatedOrdersMap = transactionClient.getOrdersCreatedAfterTimestampForSource(lastUpdatedInventoryTime, 7);
524
				System.out.println("Item id orders created map size "+ itemIdCreatedOrdersMap.entrySet().size());
538
				System.out.println("Item id orders created map size "+ itemIdCreatedOrdersMap.entrySet().size());
525
			}
539
			}
526
		} catch (TTransportException e1) {
540
		} catch (TTransportException e1) {
-
 
541
 
527
			e1.printStackTrace();
542
			e1.printStackTrace();
528
		}
543
		}
529
		try {
544
		try {
530
			catalogServiceClient = new CatalogClient().getClient();
545
			catalogServiceClient = new CatalogClient().getClient();
531
		} catch (TTransportException e1) {
546
		} catch (TTransportException e1) {
-
 
547
 
532
			e1.printStackTrace();
548
			e1.printStackTrace();
533
		}
549
		}
534
		List<String> notMappedItems = new ArrayList<String>();
550
		List<String> notMappedItems = new ArrayList<String>();
535
 
551
 
536
		for(Inventory inventory:currentInventoryItemList){
552
		for(Inventory inventory:currentInventoryItemList){
Line 598... Line 614...
598
		InventoryClient inventoryServiceClient = new InventoryClient();
614
		InventoryClient inventoryServiceClient = new InventoryClient();
599
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
615
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
600
		try {
616
		try {
601
			inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
617
			inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
602
		} catch (TException e) {
618
		} catch (TException e) {
-
 
619
 
603
			e.printStackTrace();
620
			e.printStackTrace();
604
			inventoryClient = inventoryServiceClient.getClient();
621
			inventoryClient = inventoryServiceClient.getClient();
605
			inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
622
			inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
606
		}
623
		}
607
 
624
 
Line 611... Line 628...
611
		HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/keymaker/login");
628
		HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/keymaker/login");
612
		HttpResponse response = null;
629
		HttpResponse response = null;
613
		try {
630
		try {
614
			response = client.execute(get);
631
			response = client.execute(get);
615
		} catch (ClientProtocolException e) {
632
		} catch (ClientProtocolException e) {
-
 
633
 
616
			e.printStackTrace();
634
			e.printStackTrace();
617
		} catch (IOException e) {
635
		} catch (IOException e) {
-
 
636
 
618
			e.printStackTrace();
637
			e.printStackTrace();
619
		}
638
		}
620
		BufferedReader rd = null;
639
		BufferedReader rd = null;
621
		try {
640
		try {
622
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
641
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
623
		} catch (IllegalStateException e1) {
642
		} catch (IllegalStateException e1) {
-
 
643
 
624
			e1.printStackTrace();
644
			e1.printStackTrace();
625
		} catch (IOException e1) {
645
		} catch (IOException e1) {
-
 
646
 
626
			e1.printStackTrace();
647
			e1.printStackTrace();
627
		}
648
		}
628
		String line = "";
649
		String line = "";
629
		StringBuffer sb = new StringBuffer();
650
		StringBuffer sb = new StringBuffer();
630
		try {
651
		try {
631
			while ((line = rd.readLine()) != null) {
652
			while ((line = rd.readLine()) != null) {
632
				sb.append(line);
653
				sb.append(line);
633
				//System.out.println(line);
654
				//System.out.println(line);
634
			}
655
			}
635
		} catch (IOException e) {
656
		} catch (IOException e) {
-
 
657
 
636
			e.printStackTrace();
658
			e.printStackTrace();
637
		}
659
		}
638
		int i= sb.toString().indexOf("name=\"lt\" value=");
660
		int i= sb.toString().indexOf("name=\"lt\" value=");
639
		char[] charArray = sb.toString().toCharArray();
661
		char[] charArray = sb.toString().toCharArray();
640
		String lt = "";
662
		String lt = "";
Line 686... Line 708...
686
			//System.out.println(line);
708
			//System.out.println(line);
687
		}
709
		}
688
	}
710
	}
689
 
711
 
690
 
712
 
-
 
713
 
-
 
714
 
691
	@SuppressWarnings("deprecation")
715
	@SuppressWarnings("deprecation")
692
	public static void main(String[] args) throws NumberFormatException, TException, ClientProtocolException, IOException, MessagingException {
716
	public static void main(String[] args) throws NumberFormatException, TException, ClientProtocolException, IOException, MessagingException {
693
 
-
 
694
		handleLogin();
717
		handleLogin();
695
		fetchinventoryhistoryfromsnapdeal();
718
		fetchinventoryhistoryfromsnapdeal();
696
		fetchcurrentinventoryfromsnapdeal();
719
		fetchcurrentinventoryfromsnapdeal();
697
		calculateinventory();
720
		calculateinventory();
698
		in.shop2020.model.v1.catalog.CatalogService.Client catalogServiceClient = null;
721
		in.shop2020.model.v1.catalog.CatalogService.Client catalogServiceClient = null;
699
		try {
722
		try {
700
			catalogServiceClient = new CatalogClient().getClient();
723
			catalogServiceClient = new CatalogClient().getClient();
701
		} catch (TTransportException e) {
724
		} catch (TTransportException e) {
-
 
725
 
702
			e.printStackTrace();
726
			e.printStackTrace();
703
		}
727
		}
-
 
728
		FileInputStream fis = null;
-
 
729
		Workbook hwb = null;
-
 
730
		Sheet sheet = null;
-
 
731
		if(!PANEL){
704
		FileInputStream fis = new FileInputStream("/root/code/trunk/SnapDealFeeds/SellerInventory.xls");
732
			fis = new FileInputStream("/root/code/trunk/SnapDealFeeds/SellerInventory.xls");
705
		Workbook hwb = new HSSFWorkbook(fis);
733
			hwb = new HSSFWorkbook(fis);
706
		Sheet sheet = hwb.getSheetAt(0);
734
			sheet = hwb.getSheetAt(0);
-
 
735
		}
707
		Row row;
736
		Row row = null;
708
		int iterator=1;
737
		int iterator=1;
709
		long available,reserve,defaultinventory,holdinventory,heldorders=0,sent_inventory = 0,totalheld,heldforsource,allocable;
738
		long available,reserve,defaultinventory,holdinventory,heldorders=0,sent_inventory = 0,totalheld,heldforsource,allocable;
710
		SnapdealItemForInventory  inventoryItem;
739
		SnapdealItemForInventory  inventoryItem;
711
		StringBuffer outOfStockItems =new StringBuffer();
740
		StringBuffer outOfStockItems =new StringBuffer();
712
		StringBuffer backInStockItems =new StringBuffer();
741
		StringBuffer backInStockItems =new StringBuffer();
Line 742... Line 771...
742
				}
771
				}
743
				System.out.println("itemId: " + inventoryItem.getId() + "\trisky: " + inventoryItem.getRisky()+ 
772
				System.out.println("itemId: " + inventoryItem.getId() + "\trisky: " + inventoryItem.getRisky()+ 
744
						"\tavailable: " + available + "\treserve: " + reserve + "\theldForSource:" + heldforsource +
773
						"\tavailable: " + available + "\treserve: " + reserve + "\theldForSource:" + heldforsource +
745
						"\twebsite_hold: " + holdinventory + "\ttotal_held: " +totalheld +"\tdefault_inv: "
774
						"\twebsite_hold: " + holdinventory + "\ttotal_held: " +totalheld +"\tdefault_inv: "
746
						+ defaultinventory + "\theldorders " + heldorders);
775
						+ defaultinventory + "\theldorders " + heldorders);
-
 
776
				if(!PANEL){
747
				row =   sheet.getRow((short) iterator);
777
					row =   sheet.getRow((short) iterator);
-
 
778
				}
748
				if(!inventoryItem.getStatus().equals(status.PAUSED)){
779
				if(!inventoryItem.getStatus().equals(status.PAUSED)){
749
					if(inventoryItem.getRisky()){
780
					if(inventoryItem.getRisky()){
750
						if((available - reserve) < totalheld && totalheld!=0){
781
						if((available - reserve) < totalheld && totalheld!=0){
751
							sent_inventory = (long) Math.floor(((available - reserve)*heldforsource/totalheld)) - heldorders;
782
							sent_inventory = (long) Math.floor(((available - reserve)*heldforsource/totalheld)) - heldorders;
752
							heldMoreThanAvailable.append("<tr>" 
783
							heldMoreThanAvailable.append("<tr>" 
Line 791... Line 822...
791
				}
822
				}
792
				else{
823
				else{
793
					sent_inventory = 0;
824
					sent_inventory = 0;
794
				}
825
				}
795
				if(inventory.getAvailableInventory()!= sent_inventory){
826
				if(inventory.getAvailableInventory()!= sent_inventory){
796
 
-
 
797
					if(UPDATEUSINGPANEL){
827
					if(!PANEL){
798
						UpdateSDIUsingPanel.updateInventory(sent_inventory,inventory.getSupc());	
-
 
799
					}
-
 
800
					else{
-
 
801
						row.getCell((short) 0).setCellValue(inventory.getSupc());
828
						row.getCell((short) 0).setCellValue(inventory.getSupc());
802
						row.getCell((short) 1).setCellValue(inventory.getSellerSku());
829
						row.getCell((short) 1).setCellValue(inventory.getSellerSku());
803
						row.getCell((short) 2).setCellValue(inventory.getProductName());
830
						row.getCell((short) 2).setCellValue(inventory.getProductName());
804
						row.getCell((short) 3).setCellValue(inventory.getAvailableInventory());
831
						row.getCell((short) 3).setCellValue(inventory.getAvailableInventory());
805
						row.getCell((short) 4).setCellValue(sent_inventory);
832
						row.getCell((short) 4).setCellValue(sent_inventory);
Line 832... Line 859...
832
						}
859
						}
833
						else{
860
						else{
834
							row.getCell((short) 5).setCellValue("No");
861
							row.getCell((short) 5).setCellValue("No");
835
						}
862
						}
836
					}
863
					}
-
 
864
					else{
-
 
865
						UpdateSDIUsingPanel UDSI = new UpdateSDIUsingPanel();
-
 
866
						UDSI.handleLogin();
-
 
867
						UDSI.updateInventory(sent_inventory,inventory.getSupc());
-
 
868
					}
837
					iterator++;
869
					iterator++;
838
				}
870
				}
839
			}
871
			}
840
			else{
872
			else{
841
				continue;
873
				continue;
842
			}
874
			}
843
		}
875
		}
844
 
-
 
845
		if(iterator > 1){
876
		if(iterator > 1){
846
			if(!UPDATEUSINGPANEL){
-
 
847
				FileOutputStream fileOut = null;
877
			FileOutputStream fileOut = null;
-
 
878
			if(!PANEL){
848
				fis.close();
879
				fis.close();
849
				try {
880
				try {
850
					System.out.println("Before writing file ");
881
					System.out.println("Before writing file ");
851
					fileOut = new FileOutputStream(SNAPDEAL_INVENTORY_SHEET);
882
					fileOut = new FileOutputStream(SNAPDEAL_INVENTORY_SHEET);
852
				} catch (FileNotFoundException e) {
883
				} catch (FileNotFoundException e) {
-
 
884
 
853
					e.printStackTrace();
885
					e.printStackTrace();
854
				}
886
				}
855
				try {
887
				try {
856
 
888
 
857
					hwb.write(fileOut);
889
					hwb.write(fileOut);
858
				} catch (IOException e) {
890
				} catch (IOException e) {
-
 
891
 
859
					e.printStackTrace();
892
					e.printStackTrace();
860
				}
893
				}
861
				HttpPost post = new HttpPost("http://seller.snapdeal.com/inventory/upload");
894
				HttpPost post = new HttpPost("http://seller.snapdeal.com/inventory/upload");
862
				File file = new File(SNAPDEAL_INVENTORY_SHEET);
895
				File file = new File(SNAPDEAL_INVENTORY_SHEET);
863
				MultipartEntity mpEntity = new MultipartEntity();
896
				MultipartEntity mpEntity = new MultipartEntity();
Line 868... Line 901...
868
				HttpResponse response = client.execute(post);
901
				HttpResponse response = client.execute(post);
869
				BufferedReader rd = null;
902
				BufferedReader rd = null;
870
				try {
903
				try {
871
					rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
904
					rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
872
				} catch (IllegalStateException e1) {
905
				} catch (IllegalStateException e1) {
-
 
906
 
873
					e1.printStackTrace();
907
					e1.printStackTrace();
874
				} catch (IOException e1) {
908
				} catch (IOException e1) {
-
 
909
 
875
					e1.printStackTrace();
910
					e1.printStackTrace();
876
				}
911
				}
877
				String line = "";
912
				String line = "";
878
				String feedresponse = null;
913
				String feedresponse = null;
879
				try {
914
				try {
880
					while ((line = rd.readLine()) != null) {
915
					while ((line = rd.readLine()) != null) {
881
						System.out.println(line);
916
						System.out.println(line);
882
						feedresponse = line;
917
						feedresponse = line;
883
					}
918
					}
884
				} catch (IOException e) {
919
				} catch (IOException e) {
-
 
920
 
885
					e.printStackTrace();
921
					e.printStackTrace();
886
				}
922
				}
887
				System.out.println("posting response" + feedresponse);
923
				System.out.println("posting response" + feedresponse);
-
 
924
 
888
			}
925
			}
889
		}
-
 
890
		else{
-
 
891
			try {
-
 
892
				mailer.sendSSLMessage(sendTo,"No changes in Snapdeal inventory to update "+ sdf.format(System.currentTimeMillis()),"No change in Snapdeal Inventory to be updated ", emailFromAddress, password, new ArrayList<File>());
-
 
893
			} catch (MessagingException e) {
-
 
894
				e.printStackTrace();
-
 
895
			}
-
 
896
		}
-
 
897
		in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
926
			in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
898
		long lastSentInventoryTime = System.currentTimeMillis();
927
			long lastSentInventoryTime = System.currentTimeMillis();
899
		try {
-
 
900
			transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
-
 
901
			transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
-
 
902
		} catch (Exception e) {
-
 
903
			try {
928
			try {
904
				transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
929
				transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
905
				transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
930
				transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
906
			} catch (Exception ex) {
931
			} catch (Exception e) {
907
				ex.printStackTrace();
-
 
908
			}
932
				try {
909
		}
-
 
-
 
933
					transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
-
 
934
					transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
910
		String emailSubjectTxt;
935
				} catch (Exception ex) {
911
		if(UPDATEUSINGPANEL){
936
					ex.printStackTrace();
912
			emailSubjectTxt = "Products back in stock on Snapdeal (Using Panel) "+sdf.format(lastSentInventoryTime);
-
 
913
		}
937
				}
914
		else{
938
			}
915
			emailSubjectTxt = "Products back in stock on Snapdeal "+sdf.format(lastSentInventoryTime);
939
			String emailSubjectTxt = "Products back in stock on Snapdeal "+sdf.format(lastSentInventoryTime);
916
		}
-
 
917
 
-
 
918
		String text;
940
			String text;
919
		String tableHeader = "<tr>" 
941
			String tableHeader = "<tr>" 
920
			+ "<td>" + "Product Name" +"</td>"
942
				+ "<td>" + "Product Name" +"</td>"
921
			+"<td>" + "Item ID" + "</td>"
943
				+"<td>" + "Item ID" + "</td>"
922
			+"<td>" + "Old Inventory" + "</td>"
944
				+"<td>" + "Old Inventory" + "</td>"
923
			+"<td>" + "New Inventory" + "</td>"
945
				+"<td>" + "New Inventory" + "</td>"
924
			+"</tr>";
946
				+"</tr>";
925
		if(backInStockItems.length() > 0){
947
			if(backInStockItems.length() > 0){
926
			text = "<html><table border=\"1\" align=\"center\">"+tableHeader+backInStockItems.toString()+"</table></html>";
948
				text = "<html><table border=\"1\" align=\"center\">"+tableHeader+backInStockItems.toString()+"</table></html>";
927
			try {
949
				try {
928
				mailer.sendSSLMessage(sendTo,emailSubjectTxt, emailFromAddress, password, text);
950
					mailer.sendSSLMessage(sendTo,emailSubjectTxt, emailFromAddress, password, text);
929
				//mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
951
					//mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
930
			} catch (MessagingException e) {
952
				} catch (MessagingException e) {
931
				e.printStackTrace();
953
					e.printStackTrace();
-
 
954
				}
932
			}
955
			}
933
		}
-
 
934
		if(UPDATEUSINGPANEL){
-
 
935
			emailSubjectTxt = "Products back in stock on Snapdeal (Using Panel) "+sdf.format(lastSentInventoryTime);
-
 
936
		}
-
 
937
		else{
-
 
938
			emailSubjectTxt = "Products out of stock on Snapdeal "+sdf.format(lastSentInventoryTime);
956
			emailSubjectTxt = "Products out of stock on Snapdeal "+sdf.format(lastSentInventoryTime);
939
		}
-
 
940
		if(outOfStockItems.length() > 0){
957
			if(outOfStockItems.length() > 0){
941
			text = "<html><table border=\"1\" align=\"center\">"+tableHeader+outOfStockItems.toString()+"</table></html>";
958
				text = "<html><table border=\"1\" align=\"center\">"+tableHeader+outOfStockItems.toString()+"</table></html>";
942
			try {
959
				try {
943
				mailer.sendSSLMessage(sendTo,emailSubjectTxt, emailFromAddress, password, text);
960
					mailer.sendSSLMessage(sendTo,emailSubjectTxt, emailFromAddress, password, text);
944
				//mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
961
					//mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
945
			} catch (MessagingException e) {
962
				} catch (MessagingException e) {
946
				e.printStackTrace();
963
					e.printStackTrace();
-
 
964
				}
947
			}
965
			}
948
		}
-
 
949
		/*			List<File> files = new ArrayList<File>();
966
			/*			List<File> files = new ArrayList<File>();
950
			files.add(new File(SNAPDEAL_INVENTORY_SHEET));
967
			files.add(new File(SNAPDEAL_INVENTORY_SHEET));
951
			try {
968
			try {
952
				mailer.sendSSLMessage(sendTo,"Inventory File",feedresponse, emailFromAddress, password, files);
969
				mailer.sendSSLMessage(sendTo,"Inventory File",feedresponse, emailFromAddress, password, files);
953
			} catch (MessagingException e) {
970
			} catch (MessagingException e) {
954
				e.printStackTrace();
971
				e.printStackTrace();
955
			}
972
			}
956
		 */
973
			 */
957
		if(UPDATEUSINGPANEL){
-
 
958
			emailSubjectTxt = "Snapdeal Inventory Updates sent for " +(iterator-1)+" items "+ sdf.format(System.currentTimeMillis() +" "+"(Using Panel)");
-
 
959
		}
-
 
960
		else{
-
 
961
			emailSubjectTxt = "Snapdeal Inventory Updates sent for " +(iterator-1)+" items "+ sdf.format(System.currentTimeMillis());
974
			emailSubjectTxt = "Snapdeal Inventory Updates sent for " +(iterator-1)+" items "+ sdf.format(System.currentTimeMillis());
962
		}
-
 
963
		if(inventoryChangeItems.length() > 0){
975
			if(inventoryChangeItems.length() > 0){
964
			text = "<html><table border=\"1\" align=\"center\">"+tableHeader+inventoryChangeItems.toString()+"</table></html>";
976
				text = "<html><table border=\"1\" align=\"center\">"+tableHeader+inventoryChangeItems.toString()+"</table></html>";
965
			try {
977
				try {
966
				mailer.sendSSLMessage(sendTo,emailSubjectTxt, emailFromAddress, password, text);
978
					mailer.sendSSLMessage(sendTo,emailSubjectTxt, emailFromAddress, password, text);
967
			} catch (MessagingException e) {
979
				} catch (MessagingException e) {
968
				e.printStackTrace();
980
					e.printStackTrace();
-
 
981
				}
969
			}
982
			}
970
		}
-
 
971
 
983
 
972
		tableHeader = "<tr>" 
984
			tableHeader = "<tr>" 
973
			+ "<td>" + "Product Name" +"</td>"
985
				+ "<td>" + "Product Name" +"</td>"
974
			+"<td>" + "Item ID" + "</td>"
986
				+"<td>" + "Item ID" + "</td>"
975
			+"<td>" + "Available - Reserve" + "</td>"
987
				+"<td>" + "Available - Reserve" + "</td>"
976
			+"<td>" + "Total Held" + "</td>"
988
				+"<td>" + "Total Held" + "</td>"
977
			+"</tr>";
989
				+"</tr>";
-
 
990
 
-
 
991
			emailSubjectTxt = "Items with (Total Held > Net Available) Inventory "+ sdf.format(System.currentTimeMillis());
-
 
992
			if(heldMoreThanAvailable.length() > 0){
-
 
993
				text = "<html><table border=\"1\" align=\"center\">"+tableHeader+heldMoreThanAvailable.toString()+"</table></html>";
-
 
994
				try {
-
 
995
					mailer.sendSSLMessage(sendTo,emailSubjectTxt, emailFromAddress, password, text);
-
 
996
					//mailer.sendSSLMessage(sendTo,"Snapdeal Inventory Updates sent for " +(iterator-1)+" items "+ sdf.format(System.currentTimeMillis()),inventoryChangeItems.toString(), emailFromAddress, password, new ArrayList<File>());
-
 
997
				} catch (MessagingException e) {
-
 
998
					e.printStackTrace();
-
 
999
				}
-
 
1000
			}
978
 
1001
 
979
		emailSubjectTxt = "Items with (Total Held > Net Available) Inventory "+ sdf.format(System.currentTimeMillis());
-
 
-
 
1002
		}
980
		if(heldMoreThanAvailable.length() > 0){
1003
		else{
981
			text = "<html><table border=\"1\" align=\"center\">"+tableHeader+heldMoreThanAvailable.toString()+"</table></html>";
-
 
982
			try {
1004
			try {
983
				mailer.sendSSLMessage(sendTo,emailSubjectTxt, emailFromAddress, password, text);
-
 
984
				//mailer.sendSSLMessage(sendTo,"Snapdeal Inventory Updates sent for " +(iterator-1)+" items "+ sdf.format(System.currentTimeMillis()),inventoryChangeItems.toString(), emailFromAddress, password, new ArrayList<File>());
1005
				mailer.sendSSLMessage(sendTo,"No changes in Snapdeal inventory to update "+ sdf.format(System.currentTimeMillis()),"No change in Snapdeal Inventory to be updated ", emailFromAddress, password, new ArrayList<File>());
985
			} catch (MessagingException e) {
1006
			} catch (MessagingException e) {
986
				e.printStackTrace();
1007
				e.printStackTrace();
987
			}
1008
			}
988
		}
1009
		}
989
		tableHeader = "<tr>" 
1010
		String tableHeader = "<tr>" 
990
			+ "<td>" + "Product Name" +"</td>"
1011
			+ "<td>" + "Product Name" +"</td>"
991
			+"<td>" + "SKU at Snapdeal" + "</td>"
1012
			+"<td>" + "SKU at Snapdeal" + "</td>"
992
			+"<td>" + "SUPC" + "</td>"
1013
			+"<td>" + "SUPC" + "</td>"
993
			+"</tr>";
1014
			+"</tr>";
-
 
1015
		String text;
-
 
1016
 
994
		if(notMappedItems.length() >0){
1017
		if(notMappedItems.length() >0){
995
			text = "<html><table border=\"1\" align=\"center\">"+tableHeader+notMappedItems.toString()+"</table></html>";
1018
			text = "<html><table border=\"1\" align=\"center\">"+tableHeader+notMappedItems.toString()+"</table></html>";
996
			mailer.sendSSLMessage(sendTo,"Please create Warehouse ID and Item ID mapping", emailFromAddress, password, text);
1019
			mailer.sendSSLMessage(sendTo,"Please create Warehouse ID and Item ID mapping", emailFromAddress, password, text);
997
		}
1020
		}
-
 
1021
 
998
	}
1022
	}
-
 
1023
 
999
}
1024
}