Subversion Repositories SmartDukaan

Rev

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