Subversion Repositories SmartDukaan

Rev

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