Subversion Repositories SmartDukaan

Rev

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

Rev 9557 Rev 9558
Line 742... Line 742...
742
		}
742
		}
743
		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
743
		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
744
		String emailFromAddress = "build@shop2020.in";
744
		String emailFromAddress = "build@shop2020.in";
745
		String password = "cafe@nes";
745
		String password = "cafe@nes";
746
		GmailUtils mailer = new GmailUtils();
746
		GmailUtils mailer = new GmailUtils();
747
		String sendTo[] = new String[]{"vikram.raghav@shop2020.in"};
747
		//String sendTo[] = new String[]{"vikram.raghav@shop2020.in"};
748
		/*String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
748
		String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
749
				"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
749
				"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
750
				"yukti.jain@shop2020.in","manisha.sharma@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","amar.kumar@shop2020.in"};
750
				"yukti.jain@shop2020.in","manisha.sharma@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","amar.kumar@shop2020.in"};
751
		 */if(iterator > 1){
751
		if(iterator > 1){
752
			 FileOutputStream fileOut = null;
752
			FileOutputStream fileOut = null;
753
			 fis.close();
753
			fis.close();
754
			 try {
754
			try {
755
				 //System.out.println("Before writing file ");
755
				//System.out.println("Before writing file ");
756
				 fileOut = new FileOutputStream(SNAPDEAL_INVENTORY_SHEET);
756
				fileOut = new FileOutputStream(SNAPDEAL_INVENTORY_SHEET);
757
			 } catch (FileNotFoundException e) {
757
			} catch (FileNotFoundException e) {
758
				 // TODO Auto-generated catch block
758
				// TODO Auto-generated catch block
759
				 e.printStackTrace();
759
				e.printStackTrace();
760
			 }
760
			}
761
			 try {
761
			try {
762
 
762
 
763
				 hwb.write(fileOut);
763
				hwb.write(fileOut);
764
			 } catch (IOException e) {
764
			} catch (IOException e) {
765
				 // TODO Auto-generated catch block
765
				// TODO Auto-generated catch block
766
				 e.printStackTrace();
766
				e.printStackTrace();
767
			 }
767
			}
768
			 HttpClient client = new DefaultHttpClient();
768
			HttpClient client = new DefaultHttpClient();
769
			 HttpPost post = new HttpPost("http://seller.snapdeal.com/login_security_check?spring-security-redirect=http://seller.snapdeal.com/inventory&");
769
			HttpPost post = new HttpPost("http://seller.snapdeal.com/login_security_check?spring-security-redirect=http://seller.snapdeal.com/inventory&");
770
			 BufferedReader rd= null;
770
			BufferedReader rd= null;
771
			 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
771
			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
772
			 nameValuePairs.add(new BasicNameValuePair("j_username",
772
			nameValuePairs.add(new BasicNameValuePair("j_username",
773
			 "khushal.bhatia@saholic.com"));
773
			"khushal.bhatia@saholic.com"));
774
			 nameValuePairs.add(new BasicNameValuePair("j_password",
774
			nameValuePairs.add(new BasicNameValuePair("j_password",
775
			 "sonline"));
775
			"sonline"));
776
			 post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
776
			post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
777
			 HttpResponse response = null;
777
			HttpResponse response = null;
778
			 String line;
778
			String line;
779
			 try {
779
			try {
780
				 response = client.execute(post);
780
				response = client.execute(post);
781
				 rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
781
				rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
782
				 while ((line = rd.readLine()) != null) {
782
				while ((line = rd.readLine()) != null) {
783
					 System.out.println(line);
783
					System.out.println(line);
784
				 }
784
				}
785
 
785
 
786
			 } catch (ClientProtocolException e) {
786
			} catch (ClientProtocolException e) {
787
				 // TODO Auto-generated catch block
787
				// TODO Auto-generated catch block
788
				 e.printStackTrace();
788
				e.printStackTrace();
789
			 } catch (IOException e) {
789
			} catch (IOException e) {
790
				 // TODO Auto-generated catch block
790
				// TODO Auto-generated catch block
791
				 e.printStackTrace();
791
				e.printStackTrace();
792
			 }
792
			}
793
			 post = new HttpPost("http://seller.snapdeal.com/inventory/upload");
793
			post = new HttpPost("http://seller.snapdeal.com/inventory/upload");
794
			 File file = new File(SNAPDEAL_INVENTORY_SHEET);
794
			File file = new File(SNAPDEAL_INVENTORY_SHEET);
795
			 MultipartEntity mpEntity = new MultipartEntity();
795
			MultipartEntity mpEntity = new MultipartEntity();
796
			 ContentBody cbFile = new FileBody(file,"application/vnd.ms-excel");
796
			ContentBody cbFile = new FileBody(file,"application/vnd.ms-excel");
797
			 mpEntity.addPart("file", cbFile);
797
			mpEntity.addPart("file", cbFile);
798
			 post.setEntity(mpEntity);
798
			post.setEntity(mpEntity);
799
			 //response = client.execute(post);
799
			response = client.execute(post);
800
			 try {
800
			try {
801
				 rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
801
				rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
802
			 } catch (IllegalStateException e1) {
802
			} catch (IllegalStateException e1) {
803
				 // TODO Auto-generated catch block
803
				// TODO Auto-generated catch block
804
				 e1.printStackTrace();
804
				e1.printStackTrace();
805
			 } catch (IOException e1) {
805
			} catch (IOException e1) {
806
				 // TODO Auto-generated catch block
806
				// TODO Auto-generated catch block
807
				 e1.printStackTrace();
807
				e1.printStackTrace();
808
			 }
808
			}
809
			 line = "";
809
			line = "";
810
			 String feedresponse = null;
810
			String feedresponse = null;
811
			 try {
811
			try {
812
				 while ((line = rd.readLine()) != null) {
812
				while ((line = rd.readLine()) != null) {
813
					 System.out.println(line);
813
					System.out.println(line);
814
					 feedresponse = line;
814
					feedresponse = line;
815
				 }
815
				}
816
			 } catch (IOException e) {
816
			} catch (IOException e) {
817
				 // TODO Auto-generated catch block
817
				// TODO Auto-generated catch block
818
				 e.printStackTrace();
818
				e.printStackTrace();
819
			 }
819
			}
820
			 in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
820
			in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
821
			 long lastSentInventoryTime = System.currentTimeMillis();
821
			long lastSentInventoryTime = System.currentTimeMillis();
822
			 try {
822
			try {
823
				 transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
823
				transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
824
				 transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
824
				transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
825
			 } catch (Exception e) {
825
			} catch (Exception e) {
826
				 try {
826
				try {
827
					 transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
827
					transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
828
					 transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
828
					transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
829
				 } catch (Exception ex) {
829
				} catch (Exception ex) {
830
					 ex.printStackTrace();
830
					ex.printStackTrace();
831
				 }
831
				}
832
			 }
832
			}
833
			 String emailSubjectTxt = "Products back in stock on Snapdeal "+sdf.format(lastSentInventoryTime);
833
			String emailSubjectTxt = "Products back in stock on Snapdeal "+sdf.format(lastSentInventoryTime);
834
			 String text = backInStockItems.toString();
834
			String text = backInStockItems.toString();
835
			 if(text.length() > 0){
835
			if(text.length() > 0){
836
				 try {
836
				try {
837
					 mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
837
					mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
838
				 } catch (MessagingException e) {
838
				} catch (MessagingException e) {
839
					 e.printStackTrace();
839
					e.printStackTrace();
840
				 }
840
				}
841
			 }
841
			}
842
			 emailSubjectTxt = "Products out of stock on Snapdeal "+sdf.format(lastSentInventoryTime);
842
			emailSubjectTxt = "Products out of stock on Snapdeal "+sdf.format(lastSentInventoryTime);
843
			 text = outOfStockItems.toString();
843
			text = outOfStockItems.toString();
844
			 if(text.length() > 0){
844
			if(text.length() > 0){
845
				 try {
845
				try {
846
					 mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
846
					mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
847
				 } catch (MessagingException e) {
847
				} catch (MessagingException e) {
848
					 e.printStackTrace();
848
					e.printStackTrace();
849
				 }
849
				}
850
			 }
850
			}
851
			 /*			List<File> files = new ArrayList<File>();
851
			/*			List<File> files = new ArrayList<File>();
852
			files.add(new File(SNAPDEAL_INVENTORY_SHEET));
852
			files.add(new File(SNAPDEAL_INVENTORY_SHEET));
853
			try {
853
			try {
854
				mailer.sendSSLMessage(sendTo,"Inventory File",feedresponse, emailFromAddress, password, files);
854
				mailer.sendSSLMessage(sendTo,"Inventory File",feedresponse, emailFromAddress, password, files);
855
			} catch (MessagingException e) {
855
			} catch (MessagingException e) {
856
				e.printStackTrace();
856
				e.printStackTrace();
857
			}
857
			}
858
			  */
858
			 */
859
			 try {
859
			try {
860
				 mailer.sendSSLMessage(sendTo,"Snapdeal Inventory Updates sent for " +(iterator-1)+" items "+ sdf.format(System.currentTimeMillis()),feedresponse, emailFromAddress, password, new ArrayList<File>());
860
				mailer.sendSSLMessage(sendTo,"Snapdeal Inventory Updates sent for " +(iterator-1)+" items "+ sdf.format(System.currentTimeMillis()),feedresponse, emailFromAddress, password, new ArrayList<File>());
861
			 } catch (MessagingException e) {
861
			} catch (MessagingException e) {
862
				 e.printStackTrace();
862
				e.printStackTrace();
863
			 }
863
			}
864
 
864
 
865
		 }
865
		}
866
		 else{
866
		else{
867
			 try {
867
			try {
868
				 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>());
868
				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>());
869
			 } catch (MessagingException e) {
869
			} catch (MessagingException e) {
870
				 e.printStackTrace();
870
				e.printStackTrace();
871
			 }
871
			}
872
		 }
872
		}
873
 
873
 
874
 
874
 
875
 
875
 
876
	}
876
	}
877
 
877