Subversion Repositories SmartDukaan

Rev

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

Rev 10370 Rev 10371
Line 673... Line 673...
673
 
673
 
674
 
674
 
675
 
675
 
676
 
676
 
677
	@SuppressWarnings("deprecation")
677
	@SuppressWarnings("deprecation")
678
	public static void sendsnapdealinventory () throws NumberFormatException, TException,MessagingException, InterruptedException {
678
	public static void sendsnapdealinventory (){
679
		initilaize();
679
		initilaize();
680
		try {
680
		try {
681
			handleLogin();
681
			handleLogin();
682
		} catch (ClientProtocolException e2) {
682
		} catch (ClientProtocolException e2) {
683
			System.out.println("Handle login failed");
683
			System.out.println("Handle login failed");
Line 689... Line 689...
689
		try {
689
		try {
690
			fetchinventoryhistoryfromsnapdeal();
690
			fetchinventoryhistoryfromsnapdeal();
691
		} catch (UnsupportedEncodingException e2) {
691
		} catch (UnsupportedEncodingException e2) {
692
			System.out.println("History Inventory Fetch failed");
692
			System.out.println("History Inventory Fetch failed");
693
			e2.printStackTrace();
693
			e2.printStackTrace();
-
 
694
		} catch (TException e) {
-
 
695
			e.printStackTrace();
694
		}
696
		}
695
		try {
697
		try {
696
			fetchcurrentinventoryfromsnapdeal();
698
			fetchcurrentinventoryfromsnapdeal();
697
		} catch (UnsupportedEncodingException e2) {
699
		} catch (UnsupportedEncodingException e2) {
698
			System.out.println("Current Inventory Fetch failed");
700
			System.out.println("Current Inventory Fetch failed");
699
			e2.printStackTrace();
701
			e2.printStackTrace();
-
 
702
		} catch (TException e) {
-
 
703
			e.printStackTrace();
700
		}
704
		}
701
		calculateinventory();
705
		calculateinventory();
702
		FileInputStream fis = null;
706
		FileInputStream fis = null;
703
		Workbook hwb = null;
707
		Workbook hwb = null;
704
		Sheet sheet = null;
708
		Sheet sheet = null;
Line 944... Line 948...
944
 
948
 
945
			}
949
			}
946
			int retry = 24;
950
			int retry = 24;
947
			boolean feedsuccess =false;
951
			boolean feedsuccess =false;
948
			while(retry>0){
952
			while(retry>0){
-
 
953
				try {
949
				Thread.sleep(5*60*1000);
954
					Thread.sleep(5*60*1000);
-
 
955
				} catch (InterruptedException e) {
-
 
956
					e.printStackTrace();
-
 
957
				}
950
				try {
958
				try {
951
					lastUpdatedInventoryTime = lastSentInventoryTime; 
959
					lastUpdatedInventoryTime = lastSentInventoryTime; 
952
					fetchinventoryhistoryfromsnapdeal();
960
					fetchinventoryhistoryfromsnapdeal();
953
				} catch (UnsupportedEncodingException e1) {
961
				} catch (UnsupportedEncodingException e1) {
954
					System.out.println("Error while fetching inventory update result");
962
					System.out.println("Error while fetching inventory update result");
955
					e1.printStackTrace();
963
					e1.printStackTrace();
-
 
964
				} catch (TException e) {
-
 
965
					e.printStackTrace();
956
				}
966
				}
957
				if(inventoryhistoryItemMap.entrySet().size()==iterator -1){
967
				if(inventoryhistoryItemMap.entrySet().size()==iterator -1){
958
					feedsuccess = true;
968
					feedsuccess = true;
959
					break;
969
					break;
960
				}
970
				}
Line 978... Line 988...
978
						transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
988
						transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
979
					} catch (Exception ex) {
989
					} catch (Exception ex) {
980
						ex.printStackTrace();
990
						ex.printStackTrace();
981
					}
991
					}
982
				}
992
				}
-
 
993
				InventoryClient inventoryServiceClient = null;
-
 
994
				try {
983
				InventoryClient inventoryServiceClient = new InventoryClient();
995
					inventoryServiceClient = new InventoryClient();
-
 
996
				} catch (TTransportException e1) {
-
 
997
					e1.printStackTrace();
-
 
998
				}
984
				in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
999
				in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
985
				try {
1000
				try {
986
					inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
1001
					inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
987
				} catch (TException e) {
1002
				} catch (TException e) {
988
					e.printStackTrace();
1003
					e.printStackTrace();
989
					inventoryClient = inventoryServiceClient.getClient();
1004
					inventoryClient = inventoryServiceClient.getClient();
-
 
1005
					try {
990
					inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
1006
						inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
-
 
1007
					} catch (TException e1) {
-
 
1008
						e1.printStackTrace();
-
 
1009
					}
991
				}
1010
				}
992
				emailSubjectTxt = "Products back in stock on Snapdeal "+sdf.format(lastSentInventoryTime) + PANEL_TEXT_MAIL;
1011
				emailSubjectTxt = "Products back in stock on Snapdeal "+sdf.format(lastSentInventoryTime) + PANEL_TEXT_MAIL;
993
				tableHeader = "<tr>" 
1012
				tableHeader = "<tr>" 
994
					+ "<td>" + "Product Name" +"</td>"
1013
					+ "<td>" + "Product Name" +"</td>"
995
					+"<td>" + "Item ID" + "</td>"
1014
					+"<td>" + "Item ID" + "</td>"
Line 1026... Line 1045...
1026
					}
1045
					}
1027
				}
1046
				}
1028
			}
1047
			}
1029
			else{
1048
			else{
1030
				emailSubjectTxt = "Snapdeal Inventory Could not be updated "+PANEL_TEXT_MAIL+" " +sdf.format(System.currentTimeMillis());
1049
				emailSubjectTxt = "Snapdeal Inventory Could not be updated "+PANEL_TEXT_MAIL+" " +sdf.format(System.currentTimeMillis());
-
 
1050
				try {
1031
				mailer.sendSSLMessage(sendTo,emailSubjectTxt, emailFromAddress, password,"Please contact Engg ");
1051
					mailer.sendSSLMessage(sendTo,emailSubjectTxt, emailFromAddress, password,"Please contact Engg ");
-
 
1052
				} catch (MessagingException e) {
-
 
1053
					e.printStackTrace();
-
 
1054
				}
1032
			}
1055
			}
1033
			tableHeader = "<tr>" 
1056
			tableHeader = "<tr>" 
1034
				+ "<td>" + "Product Name" +"</td>"
1057
				+ "<td>" + "Product Name" +"</td>"
1035
				+"<td>" + "Item ID" + "</td>"
1058
				+"<td>" + "Item ID" + "</td>"
1036
				+"<td>" + "Available - Reserve" + "</td>"
1059
				+"<td>" + "Available - Reserve" + "</td>"
Line 1053... Line 1076...
1053
			try {
1076
			try {
1054
				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>());
1077
				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>());
1055
			} catch (MessagingException e) {
1078
			} catch (MessagingException e) {
1056
				e.printStackTrace();
1079
				e.printStackTrace();
1057
			}
1080
			}
-
 
1081
			try {
1058
			Thread.sleep(30*60*1000);
1082
				Thread.sleep(30*60*1000);
-
 
1083
			} catch (InterruptedException e) {
-
 
1084
				e.printStackTrace();
-
 
1085
			}
1059
		}
1086
		}
1060
		String tableHeader = "<tr>" 
1087
		String tableHeader = "<tr>" 
1061
			+ "<td>" + "Product Name" +"</td>"
1088
			+ "<td>" + "Product Name" +"</td>"
1062
			+"<td>" + "SKU at Snapdeal" + "</td>"
1089
			+"<td>" + "SKU at Snapdeal" + "</td>"
1063
			+"<td>" + "SUPC" + "</td>"
1090
			+"<td>" + "SUPC" + "</td>"
1064
			+"</tr>";
1091
			+"</tr>";
1065
		String text;
1092
		String text;
1066
 
1093
 
1067
		if(notMappedItems.length() >0){
1094
		if(notMappedItems.length() >0){
1068
			text = "<html><table border=\"1\" align=\"center\">"+tableHeader+notMappedItems.toString()+"</table></html>";
1095
			text = "<html><table border=\"1\" align=\"center\">"+tableHeader+notMappedItems.toString()+"</table></html>";
-
 
1096
			try {
1069
			mailer.sendSSLMessage(sendTo,"Please create Warehouse ID and Item ID mapping", emailFromAddress, password, text);
1097
				mailer.sendSSLMessage(sendTo,"Please create Warehouse ID and Item ID mapping", emailFromAddress, password, text);
-
 
1098
			} catch (MessagingException e) {
-
 
1099
				e.printStackTrace();
-
 
1100
			}
1070
		}
1101
		}
1071
 
1102
 
1072
	}
1103
	}
1073
 
1104
 
1074
    public static void main(String[] args){
1105
    public static void main(String[] args){
1075
    	while(true){
1106
    	while(true){
1076
    		try {
-
 
1077
				sendsnapdealinventory();
1107
				sendsnapdealinventory();
1078
			} catch (NumberFormatException e) {
-
 
1079
				e.printStackTrace();
-
 
1080
			} catch (TException e) {
-
 
1081
				e.printStackTrace();
-
 
1082
			} catch (MessagingException e) {
-
 
1083
				e.printStackTrace();
-
 
1084
			} catch (InterruptedException e) {
-
 
1085
				e.printStackTrace();
-
 
1086
			}
-
 
1087
    	}
1108
    	}
1088
    	
1109
    	
1089
    }
1110
    }
1090
 
1111
 
1091
}
1112
}