Subversion Repositories SmartDukaan

Rev

Rev 21543 | Rev 21894 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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