Subversion Repositories SmartDukaan

Rev

Rev 3656 | Rev 4137 | 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
 
1453 chandransh 3
import in.shop2020.config.ConfigException;
3209 vikas 4
import in.shop2020.model.v1.order.LineItem;
5
import in.shop2020.model.v1.order.Order;
6
import in.shop2020.model.v1.user.Cart;
7
import in.shop2020.model.v1.user.Line;
1453 chandransh 8
import in.shop2020.thrift.clients.config.ConfigClient;
419 rajveer 9
 
3209 vikas 10
import java.util.ArrayList;
11
import java.util.List;
12
 
13
import org.apache.commons.lang.StringUtils;
14
import org.apache.log4j.Logger;
15
 
419 rajveer 16
public class Utils {
2942 chandransh 17
    private static Logger logger = Logger.getLogger(Utils.class);
18
 
1453 chandransh 19
	public static final String EXPORT_ENTITIES_PATH = getExportPath();
2306 vikas 20
	public static final long ROOT_CATEGORY = 10000;
21
	public static final long MOBILE_PHONES_CATEGORY = 10001;
22
	public static final long MOBILE_ACCESSORIES_CATEGORY = 10011;
3656 mandeep.dh 23
	public static final long TABLETS_CATEGORY = 10010;
24
    public static final long LAPTOPS_CATEGORY = 10050;
25
 
1453 chandransh 26
	private static String getExportPath(){
1457 chandransh 27
		String exportPath=null;
1453 chandransh 28
		ConfigClient client = ConfigClient.getClient();
29
		try{
30
			exportPath = client.get("export_entities_path");
31
		}catch(ConfigException ce){
2942 chandransh 32
			logger.error("Unable to read export path from the config client: ", ce);
33
			logger.warn("Setting the default export path");
1475 chandransh 34
			exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
1453 chandransh 35
		}
36
		return exportPath;
37
	}
38
 
822 vikas 39
	public static boolean validatePin(String pincode) {
40
		int pin;
41
		try {
42
			pin = Integer.parseInt(pincode);
43
		}
44
		catch (NumberFormatException e) {
45
			return false;
46
		}
47
 
48
		if (pin < 100000 || pin > 999999) {
49
			return false;
50
		}
51
		return true;
52
	}
53
 
54
	public static boolean validatePhone(String phone) {
839 vikas 55
		long iPhone;
822 vikas 56
		try {
839 vikas 57
    		iPhone = Long.parseLong(phone);
822 vikas 58
		}
59
		catch (NumberFormatException e) {
60
			return false;
61
		}
839 vikas 62
 
63
		if (iPhone < 1000000000l || iPhone > 9999999999l) {
64
			return false;
65
		}
822 vikas 66
		return true;
67
	}
3209 vikas 68
 
69
	public static String getItemIdStringInCart(Cart cart) {
70
	    List<String> itemIds = new ArrayList<String>();
71
        for (Line line : cart.getLines()) {
72
            itemIds.add(Long.toString(line.getItemId()));
73
        }
74
        return StringUtils.join(itemIds, '_');
75
    }
76
 
77
	public static String getItemIdStringFromOrders(List<Order> orders) {
78
        List<String> itemIds = new ArrayList<String>();
79
        if (orders != null) {
80
            for (Order order : orders) {
81
                for (LineItem lItem : order.getLineitems()) {
82
                    itemIds.add(Long.toString(lItem.getItem_id()));
83
                }
84
            }
85
        }
86
        return StringUtils.join(itemIds, '_');
87
    }
822 vikas 88
 
89
 
419 rajveer 90
}
745 chandransh 91