Subversion Repositories SmartDukaan

Rev

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