Subversion Repositories SmartDukaan

Rev

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