Subversion Repositories SmartDukaan

Rev

Rev 21915 | Rev 22139 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21915 Rev 21986
Line 1... Line 1...
1
package com.spice.profitmandi.common.util;
1
package com.spice.profitmandi.common.util;
2
 
2
 
-
 
3
import com.spice.profitmandi.common.enumuration.SchemeType;
-
 
4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
5
import com.spice.profitmandi.common.web.client.RestClient;
-
 
6
import com.spice.profitmandi.thrift.clients.TransactionClient;
-
 
7
import com.spice.profitmandi.thrift.clients.config.ConfigClient;
-
 
8
 
-
 
9
import in.shop2020.model.v1.order.RechargeOrderStatus;
-
 
10
import in.shop2020.model.v1.order.RechargePlan;
-
 
11
import in.shop2020.model.v1.order.RechargeType;
-
 
12
import in.shop2020.model.v1.order.TransactionService.Client;
3
import java.io.File;
13
import java.io.File;
4
import java.io.IOException;
14
import java.io.IOException;
5
import java.io.InputStream;
15
import java.io.InputStream;
-
 
16
import java.io.PrintStream;
-
 
17
import java.net.URI;
6
import java.net.URISyntaxException;
18
import java.net.URISyntaxException;
7
import java.net.URL;
19
import java.net.URL;
8
import java.util.ArrayList;
20
import java.util.ArrayList;
9
import java.util.Collections;
21
import java.util.Collections;
10
import java.util.HashMap;
22
import java.util.HashMap;
11
import java.util.List;
23
import java.util.List;
12
import java.util.Map;
24
import java.util.Map;
-
 
25
import java.util.Set;
13
 
26
 
14
import org.apache.commons.io.FileUtils;
27
import org.apache.commons.io.FileUtils;
15
import org.apache.commons.io.IOUtils;
28
import org.apache.commons.io.IOUtils;
16
import org.apache.http.client.utils.URIBuilder;
29
import org.apache.http.client.utils.URIBuilder;
-
 
30
import org.json.JSONObject;
17
import org.slf4j.Logger;
31
import org.slf4j.Logger;
18
import org.slf4j.LoggerFactory;
32
import org.slf4j.LoggerFactory;
-
 
33
import org.springframework.beans.factory.annotation.Value;
19
 
34
 
20
import com.spice.profitmandi.common.model.GstRate;
35
import com.spice.profitmandi.common.model.GstRate;
21
import com.spice.profitmandi.thrift.clients.CatalogClient;
36
import com.spice.profitmandi.thrift.clients.CatalogClient;
22
import com.spice.profitmandi.thrift.clients.InventoryClient;
37
import com.spice.profitmandi.thrift.clients.InventoryClient;
23
import com.spice.profitmandi.thrift.clients.TransactionClient;
38
import com.spice.profitmandi.thrift.clients.TransactionClient;
Line 32... Line 47...
32
import in.shop2020.model.v1.order.RechargeType;
47
import in.shop2020.model.v1.order.RechargeType;
33
 
48
 
34
 
49
 
35
 
50
 
36
public class Utils {
51
public class Utils {
37
	
52
 
38
	private static final Logger logger = LoggerFactory.getLogger(Utils.class);
53
	private static final Logger logger = LoggerFactory.getLogger(Utils.class);
39
	  public static final String EXPORT_ENTITIES_PATH = getExportPath();
54
	public static final String EXPORT_ENTITIES_PATH = getExportPath();
40
	  public static final String PRODUCT_PROPERTIES_SNIPPET = "ProductPropertiesSnippet.html";
55
	public static final String PRODUCT_PROPERTIES_SNIPPET = "ProductPropertiesSnippet.html";
41
	  public static final String DOCUMENT_STORE = "/profitmandi/documents/";
56
	public static final String DOCUMENT_STORE = "/profitmandi/documents/";
42
	  private static final Map<Integer, String> helpMap = new HashMap(6);
57
	private static final Map<Integer, String> helpMap = new HashMap(6);
43
	  private static final Map<Integer, String> dthIdAliasMap = new HashMap(7);
58
	private static final Map<Integer, String> dthIdAliasMap = new HashMap(7);
44
	  private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap(20);
59
	private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap(20);
45
	  private static Map<Long, String> mobileProvidersMap;
60
	private static Map<Long, String> mobileProvidersMap;
46
	  private static Map<Long, String> dthProvidersMap;
61
	private static Map<Long, String> dthProvidersMap;
47
	  private static final String SMS_GATEWAY = "http://103.15.179.45:8085/SMSGateway/sendingSMS";
62
	private static final String SMS_GATEWAY = "http://103.15.179.45:8085/SMSGateway/sendingSMS";
48
	  private static Map<Long, String> allProviders;
63
	private static Map<Long, String> allProviders;
49
	  public static Map<RechargeOrderStatus, String> rechargeStatusMap = new HashMap();
64
	public static Map<RechargeOrderStatus, String> rechargeStatusMap = new HashMap();
50
	  
65
	
51
	  static {
66
	static {
52
	    helpMap.put(Integer.valueOf(1), "Your VC number starts with 0 and is 11 digits long.");
67
		helpMap.put(Integer.valueOf(1), "Your VC number starts with 0 and is 11 digits long.");
53
	    helpMap.put(Integer.valueOf(2), "Smart card number starts with 2 and is 12 digits long.");
68
		helpMap.put(Integer.valueOf(2), "Smart card number starts with 2 and is 12 digits long.");
54
	    helpMap.put(Integer.valueOf(3), "Smart card number starts with 4 and is 11 digits long.");
69
		helpMap.put(Integer.valueOf(3), "Smart card number starts with 4 and is 11 digits long.");
55
	    helpMap.put(Integer.valueOf(4), "Subscriber ID starts with 1 and is 10 digits long.");
70
		helpMap.put(Integer.valueOf(4), "Subscriber ID starts with 1 and is 10 digits long.");
56
	    helpMap.put(Integer.valueOf(5), "For customer ID, SMS ID to 9212012299 from your registered mobile no.");
71
		helpMap.put(Integer.valueOf(5), "For customer ID, SMS ID to 9212012299 from your registered mobile no.");
57
	    helpMap.put(Integer.valueOf(26), "Customer ID starts with 3 and is 10 digits long.");
72
		helpMap.put(Integer.valueOf(26), "Customer ID starts with 3 and is 10 digits long.");
58
	    
73
 
59
	    dthIdAliasMap.put(Integer.valueOf(1), "VC Number :");
74
		dthIdAliasMap.put(Integer.valueOf(1), "VC Number :");
60
	    dthIdAliasMap.put(Integer.valueOf(2), "Smart Card Number :");
75
		dthIdAliasMap.put(Integer.valueOf(2), "Smart Card Number :");
61
	    dthIdAliasMap.put(Integer.valueOf(3), "Smart Card Number :");
76
		dthIdAliasMap.put(Integer.valueOf(3), "Smart Card Number :");
62
	    dthIdAliasMap.put(Integer.valueOf(4), "Subscriber Id :");
77
		dthIdAliasMap.put(Integer.valueOf(4), "Subscriber Id :");
63
	    dthIdAliasMap.put(Integer.valueOf(5), "Customer Id :");
78
		dthIdAliasMap.put(Integer.valueOf(5), "Customer Id :");
64
	    dthIdAliasMap.put(Integer.valueOf(0), "Account Number :");
79
		dthIdAliasMap.put(Integer.valueOf(0), "Account Number :");
65
	    dthIdAliasMap.put(Integer.valueOf(26), "Customer Id :");
80
		dthIdAliasMap.put(Integer.valueOf(26), "Customer Id :");
66
	    
81
 
67
	    rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_FAILED, "Payment Unsuccessful");
82
		rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_FAILED, "Payment Unsuccessful");
68
	    rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_SUCCESSFUL, "Processing Recharge");
83
		rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_SUCCESSFUL, "Processing Recharge");
69
	    rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_FAILED, "Recharge Failed");
84
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_FAILED, "Recharge Failed");
70
	    rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED, "Recharge Failed Refunded");
85
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED, "Recharge Failed Refunded");
71
	    rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_SUCCESSFUL, "Recharge Successful");
86
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_SUCCESSFUL, "Recharge Successful");
72
	    rechargeStatusMap.put(RechargeOrderStatus.REFUNDED, "Amount Refunded");
87
		rechargeStatusMap.put(RechargeOrderStatus.REFUNDED, "Amount Refunded");
73
	    rechargeStatusMap.put(RechargeOrderStatus.PARTIALLY_REFUNDED, "Amount Refunded");
88
		rechargeStatusMap.put(RechargeOrderStatus.PARTIALLY_REFUNDED, "Amount Refunded");
74
	    rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_PENDING, "Payment Failed");
89
		rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_PENDING, "Payment Failed");
75
	    rechargeStatusMap.put(RechargeOrderStatus.INIT, "Payment Initiated");
90
		rechargeStatusMap.put(RechargeOrderStatus.INIT, "Payment Initiated");
76
	    rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_UNKNOWN, "Recharge In Process");
91
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_UNKNOWN, "Recharge In Process");
77
	    rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_IN_PROCESS, "Recharge In Process");
92
		rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_IN_PROCESS, "Recharge In Process");
78
	    
93
 
79
	    TransactionClient tcl;
94
		TransactionClient tcl;
80
	    try
95
		try
81
	    {
96
		{
82
	      tcl = new TransactionClient();
97
			tcl = new TransactionClient();
83
	      mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
98
			mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
84
	      dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
99
			dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
85
	      logger.info("mobileProvidersMap" + mobileProvidersMap);
100
			logger.info("mobileProvidersMap" + mobileProvidersMap);
86
	      logger.info("dthProvidersMap" + dthProvidersMap);
101
			logger.info("dthProvidersMap" + dthProvidersMap);
87
	      allProviders = mobileProvidersMap;
102
			allProviders = mobileProvidersMap;
88
	      logger.info("allProviders" + allProviders);
103
			logger.info("allProviders" + allProviders);
89
	      allProviders.putAll(dthProvidersMap);
104
			allProviders.putAll(dthProvidersMap);
90
	      logger.info("allProviders" + allProviders);
105
			logger.info("allProviders" + allProviders);
91
	      
106
 
92
	      for (Long operatorId : mobileProvidersMap.keySet()) {
107
			for (Long operatorId : mobileProvidersMap.keySet()) {
93
	        List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId.longValue());
108
				List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId.longValue());
94
	        if (!plans.isEmpty())
109
				if (!plans.isEmpty())
95
	          operatorPlanMap.put(operatorId, plans);
110
					operatorPlanMap.put(operatorId, plans);
96
	      }
111
			}
97
	    } catch (Exception e) {
112
		} catch (Exception e) {
98
	      logger.error("Could not get providers", e);
113
			logger.error("Could not get providers", e);
99
	    }
114
		}
100
	  }
115
	}
101
	  
116
 
102
 
117
 
103
 
118
 
104
	@SuppressWarnings("serial")
119
	@SuppressWarnings("serial")
105
	public static final Map<String,String> MIME_TYPE = Collections.unmodifiableMap(
120
	public static final Map<String,String> MIME_TYPE = Collections.unmodifiableMap(
106
			new HashMap<String, String>(){
121
			new HashMap<String, String>(){
Line 123... Line 138...
123
			logger.warn("Setting the default export path");
138
			logger.warn("Setting the default export path");
124
			exportPath = "/var/lib/tomcat7/webapps/export/html/entities/";
139
			exportPath = "/var/lib/tomcat7/webapps/export/html/entities/";
125
		}
140
		}
126
		return exportPath;
141
		return exportPath;
127
	}
142
	}
128
	
143
 
129
	public static String getRechargeDisplayStatus(RechargeOrderStatus status) {
144
	public static String getRechargeDisplayStatus(RechargeOrderStatus status) {
130
	    if (status == null) {
145
		if (status == null) {
131
	      status = RechargeOrderStatus.INIT;
146
			status = RechargeOrderStatus.INIT;
132
	    }
147
		}
133
	    String displayStatus = (String)rechargeStatusMap.get(status);
148
		String displayStatus = (String)rechargeStatusMap.get(status);
134
	    if (displayStatus == null) {
149
		if (displayStatus == null) {
135
	      return "";
150
			return "";
136
	    }
151
		}
137
	    return displayStatus;
152
		return displayStatus;
138
	  }
153
	}
139
 
154
 
140
	public static boolean copyDocument(String documentPath){
155
	public static boolean copyDocument(String documentPath){
141
		File source = new File(documentPath);
156
		File source = new File(documentPath);
142
		File dest = new File(DOCUMENT_STORE+source.getName());
157
		File dest = new File(DOCUMENT_STORE+source.getName());
143
		try {
158
		try {
Line 154... Line 169...
154
	}
169
	}
155
 
170
 
156
	public static Map<Long, String> getDthProvidersMap() {
171
	public static Map<Long, String> getDthProvidersMap() {
157
		return dthProvidersMap;
172
		return dthProvidersMap;
158
	}
173
	}
159
	
174
 
160
	public static Map<Long, String> getAllProviders() {
175
	public static Map<Long, String> getAllProviders() {
161
		return allProviders;
176
		return allProviders;
162
	}
177
	}
163
	
178
 
164
	public static String getProvider(long operatorId) {
179
	public static String getProvider(long operatorId) {
165
    	return allProviders.get(operatorId);
180
		return allProviders.get(operatorId);
166
    }
181
	}
167
 
182
 
168
	public static void sendSms(String text, String mobileNumber) throws URISyntaxException, IOException{
183
	public static void sendSms(String text, String mobileNumber) throws URISyntaxException, IOException{
169
		URIBuilder generalSearchUrl = new URIBuilder(SMS_GATEWAY);
184
		URIBuilder generalSearchUrl = new URIBuilder(SMS_GATEWAY);
170
		generalSearchUrl.addParameter("ani", "91"+mobileNumber);
185
		generalSearchUrl.addParameter("ani", "91"+mobileNumber);
171
		generalSearchUrl.addParameter("uname", "srlsaholic");                  
186
		generalSearchUrl.addParameter("uname", "srlsaholic");                  
Line 210... Line 225...
210
		} else if (status.equals(RechargeOrderStatus.PARTIALLY_REFUNDED) || status.equals(RechargeOrderStatus.REFUNDED)) {
225
		} else if (status.equals(RechargeOrderStatus.PARTIALLY_REFUNDED) || status.equals(RechargeOrderStatus.REFUNDED)) {
211
			return new String[]{"false", "PAYMENT REFUNDED","The payment associated with this recharge order has been refunded."};
226
			return new String[]{"false", "PAYMENT REFUNDED","The payment associated with this recharge order has been refunded."};
212
		} else {
227
		} else {
213
			return new String[]{"true", "ERROR", "INVALID INPUT"};
228
			return new String[]{"true", "ERROR", "INVALID INPUT"};
214
		}
229
		}
-
 
230
	}
-
 
231
 
-
 
232
 
-
 
233
	public static String getIconUrl(int entityId,String host, int port, String webapp){
-
 
234
		RestClient rc = new RestClient(SchemeType.HTTP, host , port);
-
 
235
		Map<String, String> params = new HashMap<String, String>();
-
 
236
		String response = null;
-
 
237
		String uri = webapp+"/entity/"+entityId;
-
 
238
		try {
-
 
239
			response = rc.get(uri, params);
-
 
240
		} catch (ProfitMandiBusinessException e) {
-
 
241
			// TODO Auto-generated catch block
-
 
242
			e.printStackTrace();
-
 
243
			return "";
215
		
244
		}
-
 
245
		JSONObject obj = new JSONObject(response);
-
 
246
		String iconUrl = null;
-
 
247
		try{
-
 
248
		iconUrl = obj.getJSONObject("entity").getString("iconImageUrl");
-
 
249
		}
-
 
250
		catch(Exception e){
-
 
251
			return "";
-
 
252
		}
-
 
253
		return iconUrl==null?"":iconUrl;
216
	}
254
	}
217
	
255
	
218
	public static Map<String, GstRate> getInterGstRates(){
256
	public static Map<String, GstRate> getInterGstRates(){
219
		try{
257
		try{
220
			CatalogService.Client catalogClient = getCatalogClient();
258
			CatalogService.Client catalogClient = getCatalogClient();
Line 285... Line 323...
285
		}catch (Exception e) {
323
		}catch (Exception e) {
286
			e.printStackTrace();
324
			e.printStackTrace();
287
			throw e;
325
			throw e;
288
		}
326
		}
289
	}
327
	}
290
 
-
 
291
}
328
}