Subversion Repositories SmartDukaan

Rev

Rev 21646 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21543 ashik.ali 1
package com.spice.profitmandi.common.util;
2
 
3
 
4
import java.io.File;
5
import java.io.IOException;
6
import java.io.InputStream;
7
import java.net.URISyntaxException;
8
import java.net.URL;
9
import java.util.Collections;
10
import java.util.HashMap;
11
import java.util.List;
12
import java.util.Map;
13
 
14
import org.apache.commons.io.FileUtils;
15
import org.apache.commons.io.IOUtils;
16
import org.apache.http.client.utils.URIBuilder;
17
import org.slf4j.Logger;
18
import org.slf4j.LoggerFactory;
19
 
20
import com.spice.profitmandi.thrift.clients.config.ConfigClient;
21
 
22
import in.shop2020.model.v1.order.RechargeOrderStatus;
23
import in.shop2020.model.v1.order.RechargePlan;
24
import in.shop2020.model.v1.order.RechargeType;
25
 
26
 
27
public class Utils {
28
 
29
	private static final Logger logger=LoggerFactory.getLogger(Utils.class);
30
	public static final String EXPORT_ENTITIES_PATH = getExportPath();
31
	public static final String PRODUCT_PROPERTIES_SNIPPET = "ProductPropertiesSnippet.html";
32
	public static final String DOCUMENT_STORE = "/profitmandi/documents/";
33
	private static final Map<Integer, String> helpMap = new HashMap<Integer, String>(6);
34
	private static final Map<Integer, String> dthIdAliasMap = new HashMap<Integer, String>(7);
35
	private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<Long, List<RechargePlan>>(20);
36
	private static Map<Long, String> mobileProvidersMap;
37
	private static Map<Long, String> dthProvidersMap;
38
	private static final String SMS_GATEWAY ="http://103.15.179.45:8085/SMSGateway/sendingSMS";
39
	private static Map<Long,String> allProviders;
40
 
41
	static {
42
		helpMap.put(1, "Your VC number starts with 0 and is 11 digits long.");
43
		helpMap.put(2, "Smart card number starts with 2 and is 12 digits long.");
44
		helpMap.put(3, "Smart card number starts with 4 and is 11 digits long.");
45
		helpMap.put(4, "Subscriber ID starts with 1 and is 10 digits long.");
46
		helpMap.put(5, "For customer ID, SMS ID to 9212012299 from your registered mobile no.");
47
		helpMap.put(26, "Customer ID starts with 3 and is 10 digits long.");
48
 
49
		dthIdAliasMap.put(1, "VC Number :");
50
		dthIdAliasMap.put(2, "Smart Card Number :");
51
		dthIdAliasMap.put(3, "Smart Card Number :");
52
		dthIdAliasMap.put(4, "Subscriber Id :");
53
		dthIdAliasMap.put(5, "Customer Id :");
54
		dthIdAliasMap.put(0, "Account Number :");
55
		dthIdAliasMap.put(26, "Customer Id :");
56
 
57
		com.spice.profitmandi.thrift.clients.TransactionClient tcl;
58
		try {
59
			tcl = new com.spice.profitmandi.thrift.clients.TransactionClient();
60
			mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
61
			dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
62
			logger.info("mobileProvidersMap"+mobileProvidersMap);
63
			logger.info("dthProvidersMap"+dthProvidersMap);
64
			allProviders = mobileProvidersMap;
65
			logger.info("allProviders"+allProviders);
66
			allProviders.putAll(dthProvidersMap);
67
			logger.info("allProviders"+allProviders);
68
 
69
			for (Long operatorId : mobileProvidersMap.keySet()) {
70
				List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);
71
				if (!plans.isEmpty()) {
72
					operatorPlanMap.put(operatorId, plans);
73
				}
74
			}
75
		} catch (Exception e) {
76
			logger.error("Could not get providers", e);
77
		}
78
	}
79
 
80
 
81
	@SuppressWarnings("serial")
82
	public static final Map<String,String> MIME_TYPE = Collections.unmodifiableMap(
83
			new HashMap<String, String>(){
84
				{
85
					put("image/png", "png");
86
					put("image/jpeg", "jpeg");
87
					put("image/pjpeg", "jpeg");
88
					put("application/pdf","pdf");
89
				}
90
			});
91
 
92
	private static String getExportPath(){
93
		String exportPath=null;
94
 
95
		ConfigClient client = ConfigClient.getClient();
96
		try{
97
			exportPath = client.get("export_entities_path");
98
		}catch(Exception ce){
99
			logger.error("Unable to read export path from the config client: ", ce);
100
			logger.warn("Setting the default export path");
101
			exportPath = "/var/lib/tomcat7/webapps/export/html/entities/";
102
		}
103
		return exportPath;
104
	}
105
 
106
	public static boolean copyDocument(String documentPath){
107
		File source = new File(documentPath);
108
		File dest = new File(DOCUMENT_STORE+source.getName());
109
		try {
110
			FileUtils.copyFile(source, dest);
111
		} catch (IOException e) {
112
			e.printStackTrace();
113
			return false;
114
		}
115
		return true;
116
	}
117
 
118
	public static Map<Long, String> getMobileProvidersMap() {
119
		return mobileProvidersMap;
120
	}
121
 
122
	public static Map<Long, String> getDthProvidersMap() {
123
		return dthProvidersMap;
124
	}
125
 
126
	public static Map<Long, String> getAllProviders() {
127
		return allProviders;
128
	}
129
 
130
	public static String getProvider(long operatorId) {
131
    	return allProviders.get(operatorId);
132
    }
133
 
134
	public static void sendSms(String text, String mobileNumber) throws URISyntaxException, IOException{
135
		URIBuilder generalSearchUrl = new URIBuilder(SMS_GATEWAY);
136
		generalSearchUrl.addParameter("ani", "91"+mobileNumber);
137
		generalSearchUrl.addParameter("uname", "srlsaholic");                  
138
		generalSearchUrl.addParameter("passwd", "sr18mar"); 					  
139
		generalSearchUrl.addParameter("cli", "PROFTM");             			  
140
		generalSearchUrl.setParameter("message", text);
141
		URL url = generalSearchUrl.build().toURL();
142
		InputStream is = url.openStream();
143
		String response;
144
		try{
145
			response = IOUtils.toString(is, "UTF-8");
146
			System.out.println("response sms gateway "+response);
147
		}
148
		finally{
149
			is.close();
150
		}
151
	}
152
 
153
	public static String[] getOrderStatus(RechargeOrderStatus status){
154
		if (status == null){
155
			status = RechargeOrderStatus.INIT;
156
		}
157
		if(status.equals(RechargeOrderStatus.PAYMENT_FAILED)||status.equals(RechargeOrderStatus.PAYMENT_PENDING)){
158
			return new String[]{"false", "PAYMENT FAILED", "Payment failed at the payment gateway."};
159
		}
160
		else if(status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL) || status.equals(RechargeOrderStatus.RECHARGE_UNKNOWN)) {
161
			if(status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)){
162
				return new String[]{"false", "PAYMENT SUCCESSFUL", "Your Payment was successful but due to some internal error with the operator's system we are not sure if the recharge was successful."
163
						+ " We have put your recharge under process."
164
						+ " As soon as we get a confirmation on this transaction, we will notify you."};
165
			}
166
			else{
167
				return new String[]{"false", "RECHARGE IN PROCESS", "Your Payment is successful.We have put your recharge under process." +
168
				" Please wait while we check with the operator."};
169
			}
170
		}
171
		else if (status.equals(RechargeOrderStatus.RECHARGE_FAILED) || status.equals(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED)){
172
			return new String[]{"false", "RECHARGE IN PROCESS", "Your Payment was successful but unfortunately the recharge failed.Don't worry your payment is safe with us."
173
					+ " The entire Amount has been refunded to your wallet."};
174
		} else if(status.equals(RechargeOrderStatus.RECHARGE_SUCCESSFUL)){
175
			return new String[] {"false", "SUCCESS", "Congratulations! Your device is successfully recharged."};
176
		} else if (status.equals(RechargeOrderStatus.PARTIALLY_REFUNDED) || status.equals(RechargeOrderStatus.REFUNDED)) {
177
			return new String[]{"false", "PAYMENT REFUNDED","The payment associated with this recharge order has been refunded."};
178
		} else {
179
			return new String[]{"true", "ERROR", "INVALID INPUT"};
180
		}
181
 
182
	}
183
 
184
}