Subversion Repositories SmartDukaan

Rev

Rev 894 | Rev 1453 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
419 rajveer 1
package in.shop2020.serving.utils;
2
 
637 rajveer 3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.ObjectInputStream;
6
import java.io.ObjectOutputStream;
421 rajveer 7
import java.util.List;
8
 
424 rajveer 9
import in.shop2020.model.v1.catalog.Item;
10
import in.shop2020.model.v1.catalog.InventoryService.Client;
741 rajveer 11
import in.shop2020.model.v1.order.LineItem;
12
import in.shop2020.model.v1.order.Order;
13
import in.shop2020.model.v1.order.Transaction;
555 chandransh 14
import in.shop2020.model.v1.user.Cart;
15
 
16
import in.shop2020.model.v1.user.Line;
595 rajveer 17
import in.shop2020.model.v1.user.Sex;
555 chandransh 18
import in.shop2020.model.v1.user.ShoppingCartException;
19
import in.shop2020.model.v1.user.User;
419 rajveer 20
import in.shop2020.model.v1.user.UserContextException;
681 rajveer 21
import in.shop2020.model.v1.user.WidgetException;
421 rajveer 22
import in.shop2020.thrift.clients.CatalogServiceClient;
741 rajveer 23
import in.shop2020.thrift.clients.TransactionServiceClient;
419 rajveer 24
import in.shop2020.thrift.clients.UserContextServiceClient;
25
 
26
import org.apache.thrift.TException;
27
 
28
public class Utils {
649 chandransh 29
	//FIXME: Read this path from the config server
637 rajveer 30
	public static final String EXPORT_ENTITIES_PATH =	"/var/lib/tomcat6/webapps/export/html/entities/";
419 rajveer 31
 
424 rajveer 32
 
637 rajveer 33
	public static double getItemPrice(long itemId){
424 rajveer 34
		CatalogServiceClient catalogServiceClient = null;
35
		Client client = null;
36
		Double itemPrice = 0.0;
37
		try {
38
			catalogServiceClient = new CatalogServiceClient();
39
			client = catalogServiceClient.getClient();
637 rajveer 40
			Item item = client.getItem(itemId);
517 rajveer 41
			itemPrice = item.getSellingPrice();
536 rajveer 42
 
424 rajveer 43
		}
44
		catch(Exception e){
45
			e.printStackTrace();
46
		}
47
		return itemPrice;
48
	}
49
 
449 rajveer 50
 
507 rajveer 51
 
637 rajveer 52
	public static void storeCategories(Object obj) throws Exception {
53
 
54
		ByteArrayOutputStream bStream = new ByteArrayOutputStream();
55
		ObjectOutputStream oStream = new ObjectOutputStream( bStream );
56
		oStream.writeObject ( obj );
57
 
58
		byte[] byteVal = bStream. toByteArray();
59
 
60
		CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
61
		Client client = catalogServiceClient.getClient();
62
 
63
		client.putCategoryObject(byteVal);
64
	}
65
 
66
	public static Object getCategories() throws Exception {
67
		CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
68
		Client client = catalogServiceClient.getClient();
69
 
70
		byte[] byteVal  = client.getCategoryObject();
71
 
72
		Object obj = null;
73
		ObjectInputStream in = null;
74
		try {
75
			ByteArrayInputStream bStream = new ByteArrayInputStream(byteVal);
76
			in = new ObjectInputStream(bStream);
77
			obj = in.readObject();
78
		}
79
		finally {
80
			if(in != null) {
81
				in.close();
82
			}
83
		}
84
		return obj;
85
	}
649 chandransh 86
 
822 vikas 87
	public static boolean validatePin(String pincode) {
88
		int pin;
89
		try {
90
			pin = Integer.parseInt(pincode);
91
		}
92
		catch (NumberFormatException e) {
93
			return false;
94
		}
95
 
96
		if (pin < 100000 || pin > 999999) {
97
			return false;
98
		}
99
		return true;
100
	}
101
 
102
	public static boolean validatePhone(String phone) {
839 vikas 103
		long iPhone;
822 vikas 104
		try {
839 vikas 105
    		iPhone = Long.parseLong(phone);
822 vikas 106
		}
107
		catch (NumberFormatException e) {
108
			return false;
109
		}
839 vikas 110
 
111
		if (iPhone < 1000000000l || iPhone > 9999999999l) {
112
			return false;
113
		}
822 vikas 114
		return true;
115
	}
116
 
117
 
649 chandransh 118
//	public static void main(String args[]) throws Exception{
119
//		// to store categories
120
//		Map<Long, Category> categories = new HashMap<Long, Category>();
121
//		Map<Long, in.shop2020.metamodel.definitions.Category> cmsCategories = Catalog.getInstance().getDefinitionsContainer().getCategories();
122
//		for(in.shop2020.metamodel.definitions.Category cmsCategory: cmsCategories.values()){
123
//			Category category = new Category(cmsCategory.getID());
124
//			category.setLabel(cmsCategory.getLabel());
125
//			if(cmsCategory.getParentCategory()!=null){
126
//				category.setParentCategoryId(cmsCategory.getParentCategory().getID());
127
//			}
128
//			if(cmsCategory.getChildrenCategory()!=null){
129
//				for(in.shop2020.metamodel.definitions.Category childCategory: cmsCategory.getChildrenCategory()){
130
//					category.addChild(childCategory.getID());
131
//				}
132
//			}
133
//			categories.put(cmsCategory.getID(), category);
134
//		}
135
//		Utils.storeCategories(categories);
136
//		// to get categories
137
//		//Map<Long, Category> 
138
//		categories = (Map<Long, Category>)Utils.getCategories();
139
//		System.out.println("hello");
140
//	}
141
 
419 rajveer 142
}
745 chandransh 143