Subversion Repositories SmartDukaan

Rev

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

Rev 7662 Rev 7837
Line 18... Line 18...
18
import in.shop2020.thrift.clients.PromotionClient;
18
import in.shop2020.thrift.clients.PromotionClient;
19
import in.shop2020.utils.ConfigClientKeys;
19
import in.shop2020.utils.ConfigClientKeys;
20
 
20
 
21
import java.io.File;
21
import java.io.File;
22
import java.io.FileInputStream;
22
import java.io.FileInputStream;
-
 
23
import java.io.FileNotFoundException;
-
 
24
import java.io.FileReader;
23
import java.io.IOException;
25
import java.io.IOException;
-
 
26
import java.io.Reader;
24
import java.nio.MappedByteBuffer;
27
import java.nio.MappedByteBuffer;
25
import java.nio.channels.FileChannel;
28
import java.nio.channels.FileChannel;
26
import java.nio.charset.Charset;
29
import java.nio.charset.Charset;
27
import java.util.ArrayList;
30
import java.util.ArrayList;
28
import java.util.Arrays;
31
import java.util.Arrays;
Line 47... Line 50...
47
import org.json.JSONObject;
50
import org.json.JSONObject;
48
import org.w3c.dom.Document;
51
import org.w3c.dom.Document;
49
import org.w3c.dom.Node;
52
import org.w3c.dom.Node;
50
import org.w3c.dom.NodeList;
53
import org.w3c.dom.NodeList;
51
 
54
 
-
 
55
import com.google.gson.Gson;
-
 
56
import com.google.gson.reflect.TypeToken;
-
 
57
 
52
/**
58
/**
53
 * Command line utility to generate xml file for partners
59
 * Command line utility to generate xml file for partners
54
 * 
60
 * 
55
 * @author rajveer
61
 * @author rajveer
56
 *
62
 *
Line 755... Line 761...
755
     * Feed generated for thinkdigit that only contains the live items
761
     * Feed generated for thinkdigit that only contains the live items
756
     * feed should have s
762
     * feed should have s
757
     */
763
     */
758
    public void generateThinkDigitFeed() throws Exception{
764
    public void generateThinkDigitFeed() throws Exception{
759
    	
765
    	
-
 
766
    	List<Long> riskyPausedItems = this.getRiskyPausedItems();
760
    	List<String> productXMLSnippets = new ArrayList<String>();
767
    	List<String> productXMLSnippets = new ArrayList<String>();
761
    	productXMLSnippets.add("<root>");
768
    	productXMLSnippets.add("<root>");
762
    	String thinkDigitFeedFileName = Utils.EXPORT_PARTNERS_CONTENT_PATH + "all-categories.xml";
769
    	String thinkDigitFeedFileName = Utils.EXPORT_PARTNERS_CONTENT_PATH + "all-categories.xml";
763
    	Client catalogClientProd = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(), ConfigClientKeys.catalog_service_server_port.toString()).getClient();
-
 
764
    	for (Long entityId : entityIdItemMap.keySet()){
770
    	for (Long entityId : entityIdItemMap.keySet()){
765
    		List<Item> items = entityIdItemMap.get(entityId);
771
    		List<Item> items = entityIdItemMap.get(entityId);
766
    		long cate = items.get(0).getCategory();
772
    		long cate = items.get(0).getCategory();
767
    		
773
    		
768
    		Utils.info(items.get(0).getId() + ","  + String.valueOf(cate));
774
    		Utils.info(items.get(0).getId() + ","  + String.valueOf(cate));
769
    		Category category = Catalog.getInstance().getDefinitionsContainer().getCategory(cate);
775
    		Category category = Catalog.getInstance().getDefinitionsContainer().getCategory(cate);
770
    		Category parentCategory = category.getParentCategory(); 
776
    		Category parentCategory = category.getParentCategory(); 
771
    		
-
 
772
    		for(Item item: items){
777
            for(Item item: items){
773
    			if(!item.getItemStatus().equals(status.ACTIVE)){
778
            	if(item.getItemStatus().equals(status.ACTIVE)) {
774
    				continue;
-
 
775
    			}
-
 
776
    			boolean isActive = true;
-
 
777
    			if(!inStockCatalogItemIds.contains(entityId)) {
779
            		if(!(item.isRisky() && riskyPausedItems.contains(item.getId()) )){
778
    				if(item.isRisky()){
-
 
779
	    				try {
-
 
780
	    					ItemShippingInfo isi = catalogClientProd.isActive(item.getId());
-
 
781
	    					isActive = isi.isIsActive();
-
 
782
	    				} catch (Exception e) {
-
 
783
	    					Utils.info("Some problem Occurred while fetching shippingInfo for catalogitem " + item.getCatalogItemId() + "\n" +e + "\nTrying again");
-
 
784
	    					try {
-
 
785
	    					catalogClientProd = new CatalogClient(ConfigClientKeys.catalog_service_server_host_prod.toString(), ConfigClientKeys.catalog_service_server_port.toString()).getClient();
-
 
786
	    					ItemShippingInfo isi = catalogClientProd.isActive(item.getId());
-
 
787
	    					isActive = isi.isIsActive();
-
 
788
	    					} catch (Exception e1) {
-
 
789
	    						Utils.info("Some problem in catalog Service for catalog item " +  item.getCatalogItemId()+ " . Marking it true");
-
 
790
	        					isActive = true;
-
 
791
							}
-
 
792
	    				}
-
 
793
    				}
-
 
794
	    			if(isActive) {
-
 
795
		    			inStockCatalogItemIds.add(item.getCatalogItemId());
780
            			inStockCatalogItemIds.add(entityId);
796
		    			if(validParentCategories.contains(parentCategory.getID())) { 
781
            			if(validParentCategories.contains(parentCategory.getID())) { 
797
			    			productXMLSnippets.add(this.xmlIndentation[1] + "<products>");
782
            				productXMLSnippets.add(this.xmlIndentation[1] + "<products>");
798
			    			productXMLSnippets.add(this.xmlIndentation[2] + "<id>" + item.getCatalogItemId() + "</id>");
783
            				productXMLSnippets.add(this.xmlIndentation[2] + "<id>" + item.getCatalogItemId() + "</id>");
799
			    			productXMLSnippets.add(this.xmlIndentation[2] + "<product>" + getProductTitle(item) + "</product>");
784
            				productXMLSnippets.add(this.xmlIndentation[2] + "<product>" + getProductTitle(item) + "</product>");
800
			    			productXMLSnippets.add(this.xmlIndentation[2] + "<Product_URL>" + getProductURL(item.getCatalogItemId(), item, 59) + "</Product_URL>");
785
            				productXMLSnippets.add(this.xmlIndentation[2] + "<Product_URL>" + getProductURL(item.getCatalogItemId(), item, 59) + "</Product_URL>");
801
			    			productXMLSnippets.add(this.xmlIndentation[2] + "<Product_Price>" + (int)item.getSellingPrice() + "</Product_Price>");
786
            				productXMLSnippets.add(this.xmlIndentation[2] + "<Product_Price>" + (int)item.getSellingPrice() + "</Product_Price>");
802
			    			productXMLSnippets.add(this.xmlIndentation[2] + "<Merchant_Name>" + "saholic.com" + "</Merchant_Name>");
787
            				productXMLSnippets.add(this.xmlIndentation[2] + "<Merchant_Name>" + "saholic.com" + "</Merchant_Name>");
803
			    			productXMLSnippets.add(this.xmlIndentation[2] + "<Category_Name>" + parentCategory.getLabel() + "</Category_Name>");
788
            				productXMLSnippets.add(this.xmlIndentation[2] + "<Category_Name>" + parentCategory.getLabel() + "</Category_Name>");
804
			    			productXMLSnippets.add(this.xmlIndentation[1] + "</products>");
789
            				productXMLSnippets.add(this.xmlIndentation[1] + "</products>");
805
		    			}
790
            			}
-
 
791
            			break;
806
	    			}
792
            		}
807
    			}
793
            	}
808
    		}
794
            }
809
    	}
795
    	}
810
    	productXMLSnippets.add("</root>");
796
    	productXMLSnippets.add("</root>");
811
    	String productDataXML = StringUtils.join(productXMLSnippets, "\n");
797
    	String productDataXML = StringUtils.join(productXMLSnippets, "\n");
812
    	DBUtils.store(productDataXML, thinkDigitFeedFileName);
798
    	DBUtils.store(productDataXML, thinkDigitFeedFileName);
813
 
799
 
Line 856... Line 842...
856
    		xformer.transform(source, result);
842
    		xformer.transform(source, result);
857
    	} catch (TransformerConfigurationException e) {
843
    	} catch (TransformerConfigurationException e) {
858
    	} catch (TransformerException e) {
844
    	} catch (TransformerException e) {
859
    	}
845
    	}
860
    }
846
    }
-
 
847
    
-
 
848
    private List<Long> getRiskyPausedItems() {
-
 
849
		try {
-
 
850
			Reader reader = new FileReader(Utils.EXPORT_PATH + Utils.RISKY_PAUSED_JSON);
-
 
851
			return new Gson().fromJson(reader, new TypeToken<List<Long>>() {}.getType());
-
 
852
		} catch (FileNotFoundException e) {
-
 
853
			log.error("Could not read paused file");
-
 
854
			e.printStackTrace();
-
 
855
			return new ArrayList<Long>();
-
 
856
		}
-
 
857
	}
861
}
858
}
862
859