Subversion Repositories SmartDukaan

Rev

Rev 6204 | Rev 6208 | 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;
6178 anupam.sin 6
import in.shop2020.model.v1.order.RechargePlan;
6135 anupam.sin 7
import in.shop2020.model.v1.order.RechargeType;
3209 vikas 8
import in.shop2020.model.v1.user.Cart;
9
import in.shop2020.model.v1.user.Line;
6135 anupam.sin 10
import in.shop2020.thrift.clients.TransactionClient;
1453 chandransh 11
import in.shop2020.thrift.clients.config.ConfigClient;
419 rajveer 12
 
3209 vikas 13
import java.util.ArrayList;
6178 anupam.sin 14
import java.util.HashMap;
3209 vikas 15
import java.util.List;
6135 anupam.sin 16
import java.util.Map;
3209 vikas 17
 
4891 varun.gupt 18
import javax.mail.internet.AddressException;
19
import javax.mail.internet.InternetAddress;
20
 
3209 vikas 21
import org.apache.commons.lang.StringUtils;
22
import org.apache.log4j.Logger;
23
 
419 rajveer 24
public class Utils {
2942 chandransh 25
    private static Logger logger = Logger.getLogger(Utils.class);
26
 
4892 varun.gupt 27
	public static final String EXPORT_ENTITIES_PATH = getExportPath();
5084 phani.kuma 28
	public static final String EXPORT_JAVASCRIPT_CONTENT_PATH = "/var/lib/tomcat6/webapps/export/javascripts/";
2306 vikas 29
	public static final long ROOT_CATEGORY = 10000;
30
	public static final long MOBILE_PHONES_CATEGORY = 10001;
31
	public static final long MOBILE_ACCESSORIES_CATEGORY = 10011;
3656 mandeep.dh 32
	public static final long TABLETS_CATEGORY = 10010;
33
    public static final long LAPTOPS_CATEGORY = 10050;
5873 amit.gupta 34
    public static final long CAMERAS_CATEGORY = 11001;
6135 anupam.sin 35
 
36
    static Map<Long, String> providersMap;
6178 anupam.sin 37
    static Map<Long, String> mobileProvidersMap;
38
    static Map<Long, String> dthProvidersMap;
39
    static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<Long, List<RechargePlan>>(); 
6204 rajveer 40
    private static Map<String, Map<String, String>> uriOperatorMap = new HashMap<String, Map<String,String>>();
41
 
4137 varun.gupt 42
    public static String[] facetDefIDs = new String[] {
5941 amit.gupta 43
    	"F_50010","F_50011","F_50002","F_50001",  "F_50006", "F_50007", "F_50012", "F_50013", "F_50014", "F_50015", "F_50017", "F_50018", "F_50019", "F_50020", "F_50021", "F_50022", "F_50023", "F_50024", "F_50025", "F_50026", "F_50027" };
4272 varun.gupt 44
    public static String[] facetLabels = new String[] {"Category","Sub Category","Price", "Brand", "Data Connectivity", 
5439 phani.kuma 45
    	"Camera Resolution", "Display", "Operating System", "RAM", "Storage Capacity", "Processor",
5941 amit.gupta 46
    	"Capacity", "Class", "Capacity", "Capacity", "Type", "Interface", "Resolution", "Optical Zoom", "Display Size", "Effective Resolution" };
5525 phani.kuma 47
    public static String[] rootfacetDefIDs = new String[] {"F_50010","F_50011","F_50002","F_50001"};
48
    public static String[] rootfacetLabels = new String[] {"Category","Sub Category","Price", "Brand"};
6135 anupam.sin 49
 
50
    static {
51
        TransactionClient tcl;
52
        try {
53
            tcl = new TransactionClient();
6206 rajveer 54
            mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
55
            dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
6178 anupam.sin 56
//            providersMap.putAll(mobileProvidersMap);
57
//            providersMap.putAll(dthProvidersMap);
58
            for (Long operatorId : mobileProvidersMap.keySet()) {
59
                List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);
60
                if (!plans.isEmpty()) {
61
                    operatorPlanMap.put(operatorId, plans);
62
                }
63
            }
6204 rajveer 64
            for (Long operatorId : mobileProvidersMap.keySet()) {
65
            	Map<String,String> valueMap = new HashMap<String,String>();
66
            	valueMap.put("Id", operatorId+"");
67
                valueMap.put("Name", mobileProvidersMap.get(operatorId)+"");
68
                valueMap.put("ServiceType", "1");
69
                valueMap.put("ServiceName", "Prepaid Mobile");
70
                uriOperatorMap.put(mobileProvidersMap.get(operatorId).toLowerCase().trim().replace(" ", "-")+"-online-recharge", valueMap);
71
            }
72
            for (Long operatorId : dthProvidersMap.keySet()) {
73
            	Map<String,String> valueMap = new HashMap<String,String>();
74
            	valueMap.put("Id", operatorId+"");
75
            	valueMap.put("Name", dthProvidersMap.get(operatorId)+"");
76
                valueMap.put("ServiceType", "2");
77
                valueMap.put("ServiceName", "DTH TV");
78
                uriOperatorMap.put(dthProvidersMap.get(operatorId).toLowerCase().trim().replace(" ", "-")+"-online-recharge", valueMap);
79
            }
80
            Map<String,String> valueMap = new HashMap<String,String>();
81
            valueMap.put("Id", "0");
82
	    	valueMap.put("Name", "Mobile and DTH");
83
	        valueMap.put("ServiceType", "1");
84
	        valueMap.put("ServiceName", "");
85
	        uriOperatorMap.put("recharge", valueMap);
6178 anupam.sin 86
//            providersMap.putAll(tcl.getClient().getServiceProviders(RechargeType.DTH));
6135 anupam.sin 87
        } catch (Exception e) {
88
            logger.error("Could not get providers", e);
89
        }
90
    }
91
 
92
 
93
 
1453 chandransh 94
	private static String getExportPath(){
1457 chandransh 95
		String exportPath=null;
1453 chandransh 96
		ConfigClient client = ConfigClient.getClient();
97
		try{
98
			exportPath = client.get("export_entities_path");
99
		}catch(ConfigException ce){
2942 chandransh 100
			logger.error("Unable to read export path from the config client: ", ce);
101
			logger.warn("Setting the default export path");
1475 chandransh 102
			exportPath = "/var/lib/tomcat6/webapps/export/html/entities/";
1453 chandransh 103
		}
104
		return exportPath;
105
	}
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
	}
4891 varun.gupt 121
 
122
	public static boolean isValidEmail(String emailAddress)	{
123
 
124
		if(emailAddress == null || emailAddress.isEmpty())	{
125
			return false;
126
		}
127
		try {
128
			InternetAddress address = new InternetAddress(emailAddress, true);
129
			address.validate();
130
			return true;
131
 
132
		} catch (AddressException e) {
133
			logger.error(emailAddress + " is not valid email address ", e);
134
			return false;
135
		}
136
	}
822 vikas 137
 
138
	public static boolean validatePhone(String phone) {
839 vikas 139
		long iPhone;
822 vikas 140
		try {
839 vikas 141
    		iPhone = Long.parseLong(phone);
822 vikas 142
		}
143
		catch (NumberFormatException e) {
144
			return false;
145
		}
839 vikas 146
 
147
		if (iPhone < 1000000000l || iPhone > 9999999999l) {
148
			return false;
149
		}
822 vikas 150
		return true;
151
	}
3209 vikas 152
 
153
	public static String getItemIdStringInCart(Cart cart) {
154
	    List<String> itemIds = new ArrayList<String>();
155
        for (Line line : cart.getLines()) {
156
            itemIds.add(Long.toString(line.getItemId()));
157
        }
158
        return StringUtils.join(itemIds, '_');
159
    }
160
 
161
	public static String getItemIdStringFromOrders(List<Order> orders) {
162
        List<String> itemIds = new ArrayList<String>();
163
        if (orders != null) {
164
            for (Order order : orders) {
165
                for (LineItem lItem : order.getLineitems()) {
166
                    itemIds.add(Long.toString(lItem.getItem_id()));
167
                }
168
            }
169
        }
170
        return StringUtils.join(itemIds, '_');
6135 anupam.sin 171
    }
172
 
173
 
174
 
175
	public static String getRechargeProviderName(long providerId) {
176
            return providersMap.get(providerId);
177
	}
6178 anupam.sin 178
 
179
    public static Map<Long, String> getMobileProvidersMap() {
180
        return mobileProvidersMap;
181
    }
182
 
183
    public static Map<Long, String> getDthProvidersMap() {
184
        return dthProvidersMap;
185
    }
186
 
187
    public static Map<Long, List<RechargePlan>> getOperatorPlanMap() {
188
        return operatorPlanMap;
189
    }
6204 rajveer 190
 
191
    public static Map<String, String> getOperatorByUri(String uri){
192
    	return uriOperatorMap.get(uri);
193
	}
4891 varun.gupt 194
}