Subversion Repositories SmartDukaan

Rev

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

Rev 5363 Rev 5612
Line 5... Line 5...
5
import in.shop2020.logistics.LogisticsService;
5
import in.shop2020.logistics.LogisticsService;
6
import in.shop2020.metamodel.core.Entity;
6
import in.shop2020.metamodel.core.Entity;
7
import in.shop2020.metamodel.definitions.Catalog;
7
import in.shop2020.metamodel.definitions.Catalog;
8
import in.shop2020.metamodel.definitions.DefinitionsContainer;
8
import in.shop2020.metamodel.definitions.DefinitionsContainer;
9
import in.shop2020.metamodel.util.CreationUtils;
9
import in.shop2020.metamodel.util.CreationUtils;
-
 
10
import in.shop2020.model.v1.catalog.InventoryService.Client;
10
import in.shop2020.model.v1.catalog.Item;
11
import in.shop2020.model.v1.catalog.Item;
-
 
12
import in.shop2020.model.v1.catalog.VoucherItemMapping;
11
import in.shop2020.model.v1.catalog.status;
13
import in.shop2020.model.v1.catalog.status;
12
import in.shop2020.model.v1.user.ItemCouponDiscount;
14
import in.shop2020.model.v1.user.ItemCouponDiscount;
13
import in.shop2020.thrift.clients.CatalogClient;
15
import in.shop2020.thrift.clients.CatalogClient;
14
import in.shop2020.thrift.clients.LogisticsClient;
16
import in.shop2020.thrift.clients.LogisticsClient;
15
import in.shop2020.thrift.clients.PromotionClient;
17
import in.shop2020.thrift.clients.PromotionClient;
16
 
18
 
17
import java.io.File;
19
import java.io.File;
-
 
20
import java.io.FileInputStream;
-
 
21
import java.io.IOException;
-
 
22
import java.nio.MappedByteBuffer;
-
 
23
import java.nio.channels.FileChannel;
-
 
24
import java.nio.charset.Charset;
18
import java.util.ArrayList;
25
import java.util.ArrayList;
-
 
26
import java.util.Arrays;
19
import java.util.Date;
27
import java.util.Date;
20
import java.util.HashMap;
28
import java.util.HashMap;
21
import java.util.List;
29
import java.util.List;
22
import java.util.Map;
30
import java.util.Map;
23
 
31
 
Line 32... Line 40...
32
 *
40
 *
33
 */
41
 */
34
public class ProductListGenerator {
42
public class ProductListGenerator {
35
	
43
	
36
	private String[] xmlIndentation = {"", "    ", "        ", "            ","                "};
44
	private String[] xmlIndentation = {"", "    ", "        ", "            ","                "};
-
 
45
	private Client cc = null;
37
	public Map<Long, List<Item>> entityIdItemMap;
46
	public Map<Long, List<Item>> entityIdItemMap;
38
	private static final String DEFAULT_PINCODE = "110001";
47
	private static final String DEFAULT_PINCODE = "110001";
39
	DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
48
	DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
-
 
49
 
-
 
50
	private List<Long> voucherEntities = new ArrayList<Long>();
40
	
51
	
41
	public ProductListGenerator(Map<Long, List<Item>> entityIdItemMap) throws Exception {
52
	public ProductListGenerator(Map<Long, List<Item>> entityIdItemMap) throws Exception {
42
		this.entityIdItemMap = entityIdItemMap;
53
		this.entityIdItemMap = entityIdItemMap;
-
 
54
		String vouchers = readFile(Utils.CONTENT_DB_PATH + "voucher-entities.txt");
-
 
55
		for (String voucher : vouchers.split(",")){
-
 
56
			voucherEntities.add(Long.parseLong(voucher.trim()));
-
 
57
		}
43
	}
58
	}
44
	
59
	
45
	
60
	
46
	/**
61
	/**
47
	 * Get the url of the entity
62
	 * Get the url of the entity
Line 87... Line 102...
87
	 * @param items
102
	 * @param items
88
	 * @return
103
	 * @return
89
	 */
104
	 */
90
	private double getMinPrice(List<Item> items){
105
	private double getMinPrice(List<Item> items){
91
        double minPrice = Double.MAX_VALUE;
106
        double minPrice = Double.MAX_VALUE;
-
 
107
        Item it = null;
92
        for(Item item: items){
108
        for(Item item: items){
93
            if(minPrice > item.getSellingPrice()){
109
            if(minPrice > item.getSellingPrice()){
94
                minPrice = item.getSellingPrice();
110
                minPrice = item.getSellingPrice();
-
 
111
                it = item;
95
            }
112
            }
96
        }
113
        }
-
 
114
        if(Arrays.asList(1587l,2222l,2258l,2270l,5836l,6718l, 6719l).contains(it.getId())){
-
 
115
        	System.out.println(it.getId());
-
 
116
        }
-
 
117
        if(it != null && voucherEntities.contains(it.getCatalogItemId())) {
-
 
118
    		try {
-
 
119
				cc = new CatalogClient().getClient();
-
 
120
				List<VoucherItemMapping> mapping;
-
 
121
				mapping = cc.getAllItemVouchers(it.getId());
-
 
122
				for (VoucherItemMapping vim : mapping) {
-
 
123
					minPrice = minPrice - vim.getAmount();
-
 
124
				}
-
 
125
			} catch (Exception e) {
-
 
126
				// TODO Auto-generated catch block
-
 
127
				e.printStackTrace();
-
 
128
			}
-
 
129
        }
97
        return minPrice;
130
        return minPrice;
98
    }
131
    }
99
 
132
 
100
	/**
133
	/**
101
	 * Check whether product is mobile or not
134
	 * Check whether product is mobile or not
Line 594... Line 627...
594
	
627
	
595
	public static void main(String[] args) throws Exception {
628
	public static void main(String[] args) throws Exception {
596
		CatalogClient cl = new CatalogClient();
629
		CatalogClient cl = new CatalogClient();
597
		in.shop2020.model.v1.catalog.InventoryService.Client client = cl.getClient();
630
		in.shop2020.model.v1.catalog.InventoryService.Client client = cl.getClient();
598
		
631
		
599
		List<Item> items = cl.getClient().getAllItemsByStatus(status.ACTIVE);
632
//		List<Item> items = cl.getClient().getAllItemsByStatus(status.ACTIVE);
-
 
633
		List<Long> items1 = Arrays.asList(1587l,2222l,2258l,2270l,5836l,6718l, 6719l);
-
 
634
		List<Item> items = new ArrayList<Item>();
-
 
635
		for (Long l : items1) {
-
 
636
			items.add(cl.getClient().getItem(l));
-
 
637
		}
600
		items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED));
638
		//items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED));
601
//		items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED_BY_RISK));
639
//		items.addAll(cl.getClient().getAllItemsByStatus(status.PAUSED_BY_RISK));
602
 
640
 
603
		Map<Long, List<Item>> entityIdItemMap1 = new HashMap<Long, List<Item>>();
641
		Map<Long, List<Item>> entityIdItemMap1 = new HashMap<Long, List<Item>>();
604
		ProductListGenerator pl = new ProductListGenerator(entityIdItemMap1);
642
		ProductListGenerator pl = new ProductListGenerator(entityIdItemMap1);
605
		pl.populateEntityIdItemMap(items);
643
		pl.populateEntityIdItemMap(items);
606
		pl.generateAccessoriesXML();
644
		//pl.generateAccessoriesXML();
-
 
645
		pl.generateXMLFeedForMobileSite();
-
 
646
	}
-
 
647
	
-
 
648
    private String readFile(String path) throws IOException {
-
 
649
		FileInputStream stream = new FileInputStream(new File(path));
-
 
650
		try {
-
 
651
			FileChannel fc = stream.getChannel();
-
 
652
			MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()-1);
-
 
653
			/* Instead of using default, pass in a decoder. */
-
 
654
			return Charset.defaultCharset().decode(bb).toString();
-
 
655
		}
-
 
656
		finally {
-
 
657
			stream.close();
-
 
658
		}
607
	}
659
	}
608
}
660
}
609
661