Subversion Repositories SmartDukaan

Rev

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

Rev 7506 Rev 7629
Line 43... Line 43...
43
 
43
 
44
import org.apache.commons.lang.StringEscapeUtils;
44
import org.apache.commons.lang.StringEscapeUtils;
45
import org.apache.commons.lang.StringUtils;
45
import org.apache.commons.lang.StringUtils;
46
import org.apache.commons.logging.Log;
46
import org.apache.commons.logging.Log;
47
import org.apache.commons.logging.LogFactory;
47
import org.apache.commons.logging.LogFactory;
-
 
48
import org.apache.struts.chain.commands.servlet.PopulateActionForm;
48
import org.apache.xerces.parsers.DOMParser;
49
import org.apache.xerces.parsers.DOMParser;
49
import org.json.JSONObject;
50
import org.json.JSONObject;
50
import org.w3c.dom.Document;
51
import org.w3c.dom.Document;
51
import org.w3c.dom.Node;
52
import org.w3c.dom.Node;
52
import org.w3c.dom.NodeList;
53
import org.w3c.dom.NodeList;
Line 67... Line 68...
67
 
68
 
68
	public Map<Long, List<Item>> entityIdItemMap;
69
	public Map<Long, List<Item>> entityIdItemMap;
69
	private static final String DEFAULT_PINCODE = "110001";
70
	private static final String DEFAULT_PINCODE = "110001";
70
	DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
71
	DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
71
	private List<Long> validParentCategories = Arrays.asList((long)Utils.LAPTOPS_CATEGORY, (long)Utils.CAMERAS_CATEGORY, (long)Utils.MOBILE_PHONES_CATAGORY, (long)Utils.TABLETS_CATEGORY);
72
	private List<Long> validParentCategories = Arrays.asList((long)Utils.LAPTOPS_CATEGORY, (long)Utils.CAMERAS_CATEGORY, (long)Utils.MOBILE_PHONES_CATAGORY, (long)Utils.TABLETS_CATEGORY);
72
	private List<Long> voucherEntities = new ArrayList<Long>();
73
	/*private List<Long> voucherEntities = new ArrayList<Long>();*/
73
	
74
	
74
	public ProductListGenerator(Map<Long, List<Item>> entityIdItemMap) throws Exception {
75
	public ProductListGenerator(Map<Long, List<Item>> entityIdItemMap) throws Exception {
75
		this.entityIdItemMap = entityIdItemMap;
76
		this.entityIdItemMap = entityIdItemMap;
-
 
77
	}
-
 
78
	
76
		String vouchers = readFile(Utils.CONTENT_DB_PATH + "voucher-entities.txt");
79
	public ProductListGenerator(List<Item> items) throws Exception {
77
		for (String voucher : vouchers.split(",")){
80
		populateEntityIdItemMap(items);
78
			voucherEntities.add(Long.parseLong(voucher.trim()));
-
 
79
		}
-
 
80
	}
81
	}
81
	
82
	
82
	
83
	
83
	/**
84
	/**
84
	 * Get the url of the entity
85
	 * Get the url of the entity
Line 150... Line 151...
150
	 * @param items
151
	 * @param items
151
	 * @return
152
	 * @return
152
	 */
153
	 */
153
	private double getMinPrice(List<Item> items){
154
	private double getMinPrice(List<Item> items){
154
        double minPrice = Double.MAX_VALUE;
155
        double minPrice = Double.MAX_VALUE;
155
        Item it = null;
-
 
156
        for(Item item: items){
156
        for(Item item: items){
157
            if(minPrice > item.getSellingPrice()){
157
            if(minPrice > item.getSellingPrice()){
158
                minPrice = item.getSellingPrice();
158
                minPrice = item.getSellingPrice();
159
                it = item;
-
 
160
            }
159
            }
161
        }
160
        }
162
        if(it != null && voucherEntities.contains(it.getCatalogItemId())) {
-
 
163
    		try {
-
 
164
				cc = new CatalogClient().getClient();
-
 
165
				List<VoucherItemMapping> mapping;
-
 
166
				mapping = cc.getAllItemVouchers(it.getId());
-
 
167
				for (VoucherItemMapping vim : mapping) {
-
 
168
					minPrice = minPrice - vim.getAmount();
-
 
169
				}
-
 
170
			} catch (Exception e) {
-
 
171
				// TODO Auto-generated catch block
-
 
172
				e.printStackTrace();
-
 
173
			}
-
 
174
        }
-
 
175
        return minPrice;
161
        return minPrice;
176
    }
162
    }
177
 
163
 
178
	/**
164
	/**
179
	 * Check whether product is mobile or not
165
	 * Check whether product is mobile or not
Line 527... Line 513...
527
 
513
 
528
    private void populateEntityIdItemMap(List<Item> items){
514
    private void populateEntityIdItemMap(List<Item> items){
529
        Date toDate = new Date();
515
        Date toDate = new Date();
530
        for(Item item: items){
516
        for(Item item: items){
531
            //TODO Can be removed as we are checking in calling function
517
            //TODO Can be removed as we are checking in calling function
532
            if(!(item.getItemStatus()==status.ACTIVE || item.getItemStatus()==status.CONTENT_COMPLETE || item.getItemStatus() == status.PAUSED)){
518
            if(!(item.getItemStatus()==status.ACTIVE || item.getItemStatus() == status.PAUSED)){
533
                continue;
519
                continue;
534
            }
520
            }
535
            if(toDate.getTime() < item.getStartDate() ||  item.getSellingPrice() == 0){
521
            if( item.getSellingPrice() == 0){
536
                continue;
522
                continue;
537
            }
523
            }
538
            List<Item> itemList = entityIdItemMap.get(item.getCatalogItemId());
524
            List<Item> itemList = entityIdItemMap.get(item.getCatalogItemId());
539
            if(itemList == null){
525
            if(itemList == null){
540
                itemList = new ArrayList<Item>();
526
                itemList = new ArrayList<Item>();
Line 751... Line 737...
751
	}
737
	}
752
	
738
	
753
	public static void main(String[] args) throws Exception {
739
	public static void main(String[] args) throws Exception {
754
			CatalogClient cl = new CatalogClient();
740
			CatalogClient cl = new CatalogClient();
755
			in.shop2020.model.v1.catalog.CatalogService.Client client = cl.getClient();
741
			in.shop2020.model.v1.catalog.CatalogService.Client client = cl.getClient();
756
	
-
 
757
			Map<Long, List<Item>> entityIdItemMap1 = new HashMap<Long, List<Item>>();
742
			List<Item> items = client.getAllItemsByStatus(status.ACTIVE);
-
 
743
			items.addAll(client.getAllItemsByStatus(status.PAUSED));
758
			ProductListGenerator generator = new ProductListGenerator(entityIdItemMap1);
744
			ProductListGenerator generator = new ProductListGenerator(items);
759
        	
745
        	
760
        	log.info("Before thinkdigit feed.");
746
        	log.info("Before thinkdigit feed.");
761
        	generator.generateThinkDigitFeed();
747
        	generator.generateThinkDigitFeed();
762
 
748
 
763
        	
749