Subversion Repositories SmartDukaan

Rev

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

Rev 3209 Rev 3561
Line 1... Line 1...
1
package in.shop2020.serving.utils;
1
package in.shop2020.serving.utils;
2
 
2
 
3
import in.shop2020.config.ConfigException;
3
import in.shop2020.config.ConfigException;
4
import in.shop2020.model.v1.catalog.InventoryService.Client;
-
 
5
import in.shop2020.model.v1.catalog.Item;
-
 
6
import in.shop2020.model.v1.order.LineItem;
4
import in.shop2020.model.v1.order.LineItem;
7
import in.shop2020.model.v1.order.Order;
5
import in.shop2020.model.v1.order.Order;
8
import in.shop2020.model.v1.user.Cart;
6
import in.shop2020.model.v1.user.Cart;
9
import in.shop2020.model.v1.user.Line;
7
import in.shop2020.model.v1.user.Line;
10
import in.shop2020.thrift.clients.CatalogClient;
-
 
11
import in.shop2020.thrift.clients.config.ConfigClient;
8
import in.shop2020.thrift.clients.config.ConfigClient;
12
 
9
 
13
import java.util.ArrayList;
10
import java.util.ArrayList;
-
 
11
import java.util.HashMap;
14
import java.util.List;
12
import java.util.List;
-
 
13
import java.util.Map;
15
 
14
 
16
import org.apache.commons.lang.StringUtils;
15
import org.apache.commons.lang.StringUtils;
17
import org.apache.log4j.Logger;
16
import org.apache.log4j.Logger;
18
 
17
 
19
public class Utils {
18
public class Utils {
Line 21... Line 20...
21
    
20
    
22
	public static final String EXPORT_ENTITIES_PATH = getExportPath();
21
	public static final String EXPORT_ENTITIES_PATH = getExportPath();
23
	public static final long ROOT_CATEGORY = 10000;
22
	public static final long ROOT_CATEGORY = 10000;
24
	public static final long MOBILE_PHONES_CATEGORY = 10001;
23
	public static final long MOBILE_PHONES_CATEGORY = 10001;
25
	public static final long MOBILE_ACCESSORIES_CATEGORY = 10011;
24
	public static final long MOBILE_ACCESSORIES_CATEGORY = 10011;
26
	public static final long TABLETS_CATEGORY = 10010;
25
	public static final long TABLETS_CATEGORY = 10010;		
27
    
26
		
28
	private static String getExportPath(){
27
	private static String getExportPath(){
29
		String exportPath=null;
28
		String exportPath=null;
30
		ConfigClient client = ConfigClient.getClient();
29
		ConfigClient client = ConfigClient.getClient();
31
		try{
30
		try{
32
			exportPath = client.get("export_entities_path");
31
			exportPath = client.get("export_entities_path");
Line 36... Line 35...
36
			exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
35
			exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
37
		}
36
		}
38
		return exportPath;
37
		return exportPath;
39
	}
38
	}
40
	
39
	
41
	public static double getItemPrice(long itemId){
-
 
42
		CatalogClient catalogServiceClient = null;
-
 
43
		Client client = null;
-
 
44
		Double itemPrice = 0.0;
-
 
45
		try {
-
 
46
			catalogServiceClient = new CatalogClient();
-
 
47
			client = catalogServiceClient.getClient();
-
 
48
			Item item = client.getItem(itemId);
-
 
49
			itemPrice = item.getSellingPrice();
-
 
50
			
-
 
51
		} catch(Exception e){
-
 
52
			logger.error("Unable to get the item price because of:", e);
-
 
53
		}
-
 
54
		return itemPrice;
-
 
55
	}
-
 
56
 
-
 
57
 
-
 
58
/*	
-
 
59
	public static void storeCategories(Object obj) throws Exception {
-
 
60
	
-
 
61
		ByteArrayOutputStream bStream = new ByteArrayOutputStream();
-
 
62
		ObjectOutputStream oStream = new ObjectOutputStream( bStream );
-
 
63
		oStream.writeObject ( obj );
-
 
64
		
-
 
65
		byte[] byteVal = bStream. toByteArray();
-
 
66
		
-
 
67
		CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
-
 
68
		Client client = catalogServiceClient.getClient();
-
 
69
		
-
 
70
		client.putCategoryObject(byteVal);
-
 
71
	}
-
 
72
	*/
-
 
73
	/*
-
 
74
	public static Object getCategories() throws Exception {
-
 
75
		CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
-
 
76
		Client client = catalogServiceClient.getClient();
-
 
77
		
-
 
78
		byte[] byteVal  = client.getCategoryObject();
-
 
79
		
-
 
80
		Object obj = null;
-
 
81
		ObjectInputStream in = null;
-
 
82
		try {
-
 
83
			ByteArrayInputStream bStream = new ByteArrayInputStream(byteVal);
-
 
84
			in = new ObjectInputStream(bStream);
-
 
85
			obj = in.readObject();
-
 
86
		}
-
 
87
		finally {
-
 
88
			if(in != null) {
-
 
89
				in.close();
-
 
90
			}
-
 
91
		}
-
 
92
		return obj;
-
 
93
	}
-
 
94
	*/
-
 
95
	public static boolean validatePin(String pincode) {
40
	public static boolean validatePin(String pincode) {
96
		int pin;
41
		int pin;
97
		try {
42
		try {
98
			pin = Integer.parseInt(pincode);
43
			pin = Integer.parseInt(pincode);
99
		}
44
		}
Line 141... Line 86...
141
        }
86
        }
142
        return StringUtils.join(itemIds, '_');
87
        return StringUtils.join(itemIds, '_');
143
    }
88
    }
144
 
89
 
145
	
90
	
146
//	public static void main(String args[]) throws Exception{
-
 
147
//		// to store categories
-
 
148
//		Map<Long, Category> categories = new HashMap<Long, Category>();
-
 
149
//		Map<Long, in.shop2020.metamodel.definitions.Category> cmsCategories = Catalog.getInstance().getDefinitionsContainer().getCategories();
-
 
150
//		for(in.shop2020.metamodel.definitions.Category cmsCategory: cmsCategories.values()){
-
 
151
//			Category category = new Category(cmsCategory.getID());
-
 
152
//			category.setLabel(cmsCategory.getLabel());
-
 
153
//			if(cmsCategory.getParentCategory()!=null){
-
 
154
//				category.setParentCategoryId(cmsCategory.getParentCategory().getID());
-
 
155
//			}
-
 
156
//			if(cmsCategory.getChildrenCategory()!=null){
-
 
157
//				for(in.shop2020.metamodel.definitions.Category childCategory: cmsCategory.getChildrenCategory()){
-
 
158
//					category.addChild(childCategory.getID());
-
 
159
//				}
-
 
160
//			}
-
 
161
//			categories.put(cmsCategory.getID(), category);
-
 
162
//		}
-
 
163
//		Utils.storeCategories(categories);
-
 
164
//		// to get categories
-
 
165
//		//Map<Long, Category> 
-
 
166
//		categories = (Map<Long, Category>)Utils.getCategories();
-
 
167
//		System.out.println("hello");
-
 
168
//	}
-
 
169
	
-
 
170
}
91
}
171
	
92