Rev 21646 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.common.util;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.net.URISyntaxException;import java.net.URL;import java.util.Collections;import java.util.HashMap;import java.util.List;import java.util.Map;import org.apache.commons.io.FileUtils;import org.apache.commons.io.IOUtils;import org.apache.http.client.utils.URIBuilder;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import com.spice.profitmandi.thrift.clients.config.ConfigClient;import in.shop2020.model.v1.order.RechargeOrderStatus;import in.shop2020.model.v1.order.RechargePlan;import in.shop2020.model.v1.order.RechargeType;public class Utils {private static final Logger logger=LoggerFactory.getLogger(Utils.class);public static final String EXPORT_ENTITIES_PATH = getExportPath();public static final String PRODUCT_PROPERTIES_SNIPPET = "ProductPropertiesSnippet.html";public static final String DOCUMENT_STORE = "/profitmandi/documents/";private static final Map<Integer, String> helpMap = new HashMap<Integer, String>(6);private static final Map<Integer, String> dthIdAliasMap = new HashMap<Integer, String>(7);private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<Long, List<RechargePlan>>(20);private static Map<Long, String> mobileProvidersMap;private static Map<Long, String> dthProvidersMap;private static final String SMS_GATEWAY ="http://103.15.179.45:8085/SMSGateway/sendingSMS";private static Map<Long,String> allProviders;static {helpMap.put(1, "Your VC number starts with 0 and is 11 digits long.");helpMap.put(2, "Smart card number starts with 2 and is 12 digits long.");helpMap.put(3, "Smart card number starts with 4 and is 11 digits long.");helpMap.put(4, "Subscriber ID starts with 1 and is 10 digits long.");helpMap.put(5, "For customer ID, SMS ID to 9212012299 from your registered mobile no.");helpMap.put(26, "Customer ID starts with 3 and is 10 digits long.");dthIdAliasMap.put(1, "VC Number :");dthIdAliasMap.put(2, "Smart Card Number :");dthIdAliasMap.put(3, "Smart Card Number :");dthIdAliasMap.put(4, "Subscriber Id :");dthIdAliasMap.put(5, "Customer Id :");dthIdAliasMap.put(0, "Account Number :");dthIdAliasMap.put(26, "Customer Id :");com.spice.profitmandi.thrift.clients.TransactionClient tcl;try {tcl = new com.spice.profitmandi.thrift.clients.TransactionClient();mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);logger.info("mobileProvidersMap"+mobileProvidersMap);logger.info("dthProvidersMap"+dthProvidersMap);allProviders = mobileProvidersMap;logger.info("allProviders"+allProviders);allProviders.putAll(dthProvidersMap);logger.info("allProviders"+allProviders);for (Long operatorId : mobileProvidersMap.keySet()) {List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId);if (!plans.isEmpty()) {operatorPlanMap.put(operatorId, plans);}}} catch (Exception e) {logger.error("Could not get providers", e);}}@SuppressWarnings("serial")public static final Map<String,String> MIME_TYPE = Collections.unmodifiableMap(new HashMap<String, String>(){{put("image/png", "png");put("image/jpeg", "jpeg");put("image/pjpeg", "jpeg");put("application/pdf","pdf");}});private static String getExportPath(){String exportPath=null;ConfigClient client = ConfigClient.getClient();try{exportPath = client.get("export_entities_path");}catch(Exception ce){logger.error("Unable to read export path from the config client: ", ce);logger.warn("Setting the default export path");exportPath = "/var/lib/tomcat7/webapps/export/html/entities/";}return exportPath;}public static boolean copyDocument(String documentPath){File source = new File(documentPath);File dest = new File(DOCUMENT_STORE+source.getName());try {FileUtils.copyFile(source, dest);} catch (IOException e) {e.printStackTrace();return false;}return true;}public static Map<Long, String> getMobileProvidersMap() {return mobileProvidersMap;}public static Map<Long, String> getDthProvidersMap() {return dthProvidersMap;}public static Map<Long, String> getAllProviders() {return allProviders;}public static String getProvider(long operatorId) {return allProviders.get(operatorId);}public static void sendSms(String text, String mobileNumber) throws URISyntaxException, IOException{URIBuilder generalSearchUrl = new URIBuilder(SMS_GATEWAY);generalSearchUrl.addParameter("ani", "91"+mobileNumber);generalSearchUrl.addParameter("uname", "srlsaholic");generalSearchUrl.addParameter("passwd", "sr18mar");generalSearchUrl.addParameter("cli", "PROFTM");generalSearchUrl.setParameter("message", text);URL url = generalSearchUrl.build().toURL();InputStream is = url.openStream();String response;try{response = IOUtils.toString(is, "UTF-8");System.out.println("response sms gateway "+response);}finally{is.close();}}public static String[] getOrderStatus(RechargeOrderStatus status){if (status == null){status = RechargeOrderStatus.INIT;}if(status.equals(RechargeOrderStatus.PAYMENT_FAILED)||status.equals(RechargeOrderStatus.PAYMENT_PENDING)){return new String[]{"false", "PAYMENT FAILED", "Payment failed at the payment gateway."};}else if(status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL) || status.equals(RechargeOrderStatus.RECHARGE_UNKNOWN)) {if(status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)){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."+ " We have put your recharge under process."+ " As soon as we get a confirmation on this transaction, we will notify you."};}else{return new String[]{"false", "RECHARGE IN PROCESS", "Your Payment is successful.We have put your recharge under process." +" Please wait while we check with the operator."};}}else if (status.equals(RechargeOrderStatus.RECHARGE_FAILED) || status.equals(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED)){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."+ " The entire Amount has been refunded to your wallet."};} else if(status.equals(RechargeOrderStatus.RECHARGE_SUCCESSFUL)){return new String[] {"false", "SUCCESS", "Congratulations! Your device is successfully recharged."};} else if (status.equals(RechargeOrderStatus.PARTIALLY_REFUNDED) || status.equals(RechargeOrderStatus.REFUNDED)) {return new String[]{"false", "PAYMENT REFUNDED","The payment associated with this recharge order has been refunded."};} else {return new String[]{"true", "ERROR", "INVALID INPUT"};}}}