Subversion Repositories SmartDukaan

Rev

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