Subversion Repositories SmartDukaan

Rev

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

Rev 21543 Rev 21646
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.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;
3
 
-
 
4
import java.io.File;
9
import java.io.File;
5
import java.io.IOException;
10
import java.io.IOException;
6
import java.io.InputStream;
11
import java.io.InputStream;
-
 
12
import java.io.PrintStream;
-
 
13
import java.net.URI;
7
import java.net.URISyntaxException;
14
import java.net.URISyntaxException;
8
import java.net.URL;
15
import java.net.URL;
9
import java.util.Collections;
16
import java.util.Collections;
10
import java.util.HashMap;
17
import java.util.HashMap;
11
import java.util.List;
18
import java.util.List;
12
import java.util.Map;
19
import java.util.Map;
13
 
-
 
14
import org.apache.commons.io.FileUtils;
20
import org.apache.commons.io.FileUtils;
15
import org.apache.commons.io.IOUtils;
21
import org.apache.commons.io.IOUtils;
16
import org.apache.http.client.utils.URIBuilder;
22
import org.apache.http.client.utils.URIBuilder;
17
import org.slf4j.Logger;
23
import org.slf4j.Logger;
18
import org.slf4j.LoggerFactory;
24
import org.slf4j.LoggerFactory;
19
 
25
 
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
 
26
 
27
 
27
public class Utils {
28
public class Utils {
28
 
29
	
29
	private static final Logger logger=LoggerFactory.getLogger(Utils.class);
30
	private static final Logger logger = LoggerFactory.getLogger(Utils.class);
30
	public static final String EXPORT_ENTITIES_PATH = getExportPath();
31
	  public static final String EXPORT_ENTITIES_PATH = getExportPath();
31
	public static final String PRODUCT_PROPERTIES_SNIPPET = "ProductPropertiesSnippet.html";
32
	  public static final String PRODUCT_PROPERTIES_SNIPPET = "ProductPropertiesSnippet.html";
32
	public static final String DOCUMENT_STORE = "/profitmandi/documents/";
33
	  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> helpMap = new HashMap(6);
34
	private static final Map<Integer, String> dthIdAliasMap = new HashMap<Integer, String>(7);
35
	  private static final Map<Integer, String> dthIdAliasMap = new HashMap(7);
35
	private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<Long, List<RechargePlan>>(20);
36
	  private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap(20);
36
	private static Map<Long, String> mobileProvidersMap;
37
	  private static Map<Long, String> mobileProvidersMap;
37
	private static Map<Long, String> dthProvidersMap;
38
	  private static Map<Long, String> dthProvidersMap;
38
	private static final String SMS_GATEWAY ="http://103.15.179.45:8085/SMSGateway/sendingSMS";
39
	  private static final String SMS_GATEWAY = "http://103.15.179.45:8085/SMSGateway/sendingSMS";
39
	private static Map<Long,String> allProviders;
40
	  private static Map<Long, String> allProviders;
-
 
41
	  public static Map<RechargeOrderStatus, String> rechargeStatusMap = new HashMap();
40
 
42
	  
41
	static {
43
	  static {
42
		helpMap.put(1, "Your VC number starts with 0 and is 11 digits long.");
44
	    helpMap.put(Integer.valueOf(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.");
45
	    helpMap.put(Integer.valueOf(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.");
46
	    helpMap.put(Integer.valueOf(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.");
47
	    helpMap.put(Integer.valueOf(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.");
48
	    helpMap.put(Integer.valueOf(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.");
49
	    helpMap.put(Integer.valueOf(26), "Customer ID starts with 3 and is 10 digits long.");
48
 
50
	    
49
		dthIdAliasMap.put(1, "VC Number :");
51
	    dthIdAliasMap.put(Integer.valueOf(1), "VC Number :");
50
		dthIdAliasMap.put(2, "Smart Card Number :");
52
	    dthIdAliasMap.put(Integer.valueOf(2), "Smart Card Number :");
51
		dthIdAliasMap.put(3, "Smart Card Number :");
53
	    dthIdAliasMap.put(Integer.valueOf(3), "Smart Card Number :");
52
		dthIdAliasMap.put(4, "Subscriber Id :");
54
	    dthIdAliasMap.put(Integer.valueOf(4), "Subscriber Id :");
53
		dthIdAliasMap.put(5, "Customer Id :");
55
	    dthIdAliasMap.put(Integer.valueOf(5), "Customer Id :");
54
		dthIdAliasMap.put(0, "Account Number :");
56
	    dthIdAliasMap.put(Integer.valueOf(0), "Account Number :");
55
		dthIdAliasMap.put(26, "Customer Id :");
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");
56
 
70
	    
57
		com.spice.profitmandi.thrift.clients.TransactionClient tcl;
71
	    TransactionClient tcl;
-
 
72
	    try
58
		try {
73
	    {
59
			tcl = new com.spice.profitmandi.thrift.clients.TransactionClient();
74
	      tcl = new TransactionClient();
60
			mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
75
	      mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
61
			dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
76
	      dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
62
			logger.info("mobileProvidersMap"+mobileProvidersMap);
77
	      logger.info("mobileProvidersMap" + mobileProvidersMap);
63
			logger.info("dthProvidersMap"+dthProvidersMap);
78
	      logger.info("dthProvidersMap" + dthProvidersMap);
64
			allProviders = mobileProvidersMap;
79
	      allProviders = mobileProvidersMap;
65
			logger.info("allProviders"+allProviders);
80
	      logger.info("allProviders" + allProviders);
66
			allProviders.putAll(dthProvidersMap);
81
	      allProviders.putAll(dthProvidersMap);
67
			logger.info("allProviders"+allProviders);
82
	      logger.info("allProviders" + allProviders);
68
 
83
	      
69
			for (Long operatorId : mobileProvidersMap.keySet()) {
84
	      for (Long operatorId : mobileProvidersMap.keySet()) {
70
				List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);
85
	        List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId.longValue());
71
				if (!plans.isEmpty()) {
86
	        if (!plans.isEmpty())
72
					operatorPlanMap.put(operatorId, plans);
87
	          operatorPlanMap.put(operatorId, plans);
73
				}
88
	      }
74
			}
-
 
75
		} catch (Exception e) {
89
	    } catch (Exception e) {
76
			logger.error("Could not get providers", e);
90
	      logger.error("Could not get providers", e);
-
 
91
	    }
77
		}
92
	  }
78
	}
93
	  
79
 
94
 
80
 
95
 
81
	@SuppressWarnings("serial")
96
	@SuppressWarnings("serial")
82
	public static final Map<String,String> MIME_TYPE = Collections.unmodifiableMap(
97
	public static final Map<String,String> MIME_TYPE = Collections.unmodifiableMap(
83
			new HashMap<String, String>(){
98
			new HashMap<String, String>(){
Line 100... Line 115...
100
			logger.warn("Setting the default export path");
115
			logger.warn("Setting the default export path");
101
			exportPath = "/var/lib/tomcat7/webapps/export/html/entities/";
116
			exportPath = "/var/lib/tomcat7/webapps/export/html/entities/";
102
		}
117
		}
103
		return exportPath;
118
		return exportPath;
104
	}
119
	}
-
 
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
	  }
105
 
131
 
106
	public static boolean copyDocument(String documentPath){
132
	public static boolean copyDocument(String documentPath){
107
		File source = new File(documentPath);
133
		File source = new File(documentPath);
108
		File dest = new File(DOCUMENT_STORE+source.getName());
134
		File dest = new File(DOCUMENT_STORE+source.getName());
109
		try {
135
		try {