Pat 7 gadi atpakaļ
vecāks
revīzija
52f9928714

+ 72 - 0
GabonTelMobicashMobileAppHelper/src/main/java/com/psi/gabontel/mobileapp/helper/EulaAndroidOTPGen.java

@@ -0,0 +1,72 @@
+package com.psi.gabontel.mobileapp.helper;
+
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.Map;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import org.jboss.logging.Logger;
+
+import com.psi.applicationmanager.AppManagerFunction;
+import com.psi.applicationmanager.AppMessage;
+import com.psi.common.transactions.McomSubscriber;
+import com.psi.common.transactions.Message;
+import com.psi.common.transactions.MessageId;
+import com.psi.common.transactions.Messanger;
+import com.psi.common.transactions.SystemInfo;
+import com.psi.common.transactions.TransactionHelper;
+import com.psi.common.util.StringUtil;
+import com.psi.common.util.SystemUtil;
+import com.psi.gabontel.mobileapp.thirdparty.helper.OTPHandler;
+
+
+@Stateless
+@Remote(AppManagerFunction.class)
+public class EulaAndroidOTPGen  implements AppManagerFunction {
+	private static final Logger log = Logger.getLogger(EulaAndroidOTPGen.class);
+	
+	public String processTransaction(String refid, String msisdn, String message, Map<String, String> syntax) {
+		return manageTransaction(refid, msisdn, message, syntax).getMessage();
+	}
+	
+	
+	public AppMessage manageTransaction(String refid, String msisdn, String message, Map<String, String> syntax)  {
+		String key = SystemUtil.isNull(syntax.get("key"),"");
+		String token = SystemUtil.isNull(syntax.get("token"),"");
+		String handset =  SystemUtil.isNull(syntax.get("handset"), "");
+		String version = SystemUtil.isNull(syntax.get("version"),"");
+		String language = SystemUtil.isNull(syntax.get("language"),"");
+		McomSubscriber originator = null;
+		Message msg = Messanger.getMessage(MessageId.SYSTEM_BUSY, msisdn, "<refid>", refid);
+		try{
+		originator = McomSubscriber.getMcomSubscriber(msisdn, language);
+		Timestamp sysdate  = SystemInfo.getDb().QueryScalar("SELECT SYSDATE FROM DUAL", new Timestamp(new java.util.Date().getTime()));
+		
+		OTPHandler otp = new OTPHandler(originator.getMsisdn());
+		
+		otp.generateOTP(1,"FOR VALIDATION",token.toUpperCase(),version);
+		
+		if (!otp.isSuccess()) {
+			log.error("OTP Generation Failed for : "+originator.getMsisdn());
+    	  	return Messanger.getMessage(MessageId.SYSTEM_BUSY, originator);
+	      }
+		
+		String otpcode = otp.getOtp();
+		
+		Message otpmessage = Messanger.getMessage(272028, originator);
+		otpmessage.replace("<otp>",otpcode);
+		
+		Messanger.sendMessage(refid, originator.getMsisdn(), otpmessage);
+		
+		return otpmessage;
+	
+		}catch(Exception e){
+		log.error("Android Eula Error",e);
+		return new Message(0,0,"FAILED:" + msg.getMessage().toString());
+	}
+}
+
+
+}

+ 99 - 0
GabonTelMobicashMobileAppHelper/src/main/java/com/psi/gabontel/mobileapp/helper/EulaAndroidTransaction.java

@@ -0,0 +1,99 @@
+package com.psi.gabontel.mobileapp.helper;
+
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.Map;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import org.jboss.logging.Logger;
+
+import com.psi.applicationmanager.AppManagerFunction;
+import com.psi.applicationmanager.AppMessage;
+import com.psi.common.transactions.McomSubscriber;
+import com.psi.common.transactions.Message;
+import com.psi.common.transactions.MessageId;
+import com.psi.common.transactions.Messanger;
+import com.psi.common.transactions.SystemInfo;
+import com.psi.common.transactions.TransactionHelper;
+import com.psi.common.util.StringUtil;
+import com.psi.common.util.SystemUtil;
+import com.psi.gabontel.mobileapp.thirdparty.helper.OTPHandler;
+
+
+@Stateless
+@Remote(AppManagerFunction.class)
+public class EulaAndroidTransaction  implements AppManagerFunction {
+	private static final Logger log = Logger.getLogger(EulaAndroidTransaction.class);
+	
+	public String processTransaction(String refid, String msisdn, String message, Map<String, String> syntax) {
+		return manageTransaction(refid, msisdn, message, syntax).getMessage();
+	}
+	
+	
+	public AppMessage manageTransaction(String refid, String msisdn, String message, Map<String, String> syntax)  {
+		String key = SystemUtil.isNull(syntax.get("key"),"");
+		String token = SystemUtil.isNull(syntax.get("token"),"");
+		String otpcode = SystemUtil.isNull(syntax.get("otpcode"),"");
+		String handset =  SystemUtil.isNull(syntax.get("handset"), "");
+		String version = SystemUtil.isNull(syntax.get("version"),"");
+		String language = SystemUtil.isNull(syntax.get("language"),"");
+		McomSubscriber originator = null;
+		Message msg = Messanger.getMessage(MessageId.SYSTEM_BUSY, msisdn, "<refid>", refid);
+		try{
+		originator = McomSubscriber.getMcomSubscriber(msisdn, language);
+		Timestamp sysdate  = SystemInfo.getDb().QueryScalar("SELECT SYSDATE FROM DUAL", new Timestamp(new java.util.Date().getTime()));
+	
+		//VALIDATE OTP
+		OTPHandler otp = new OTPHandler(originator.getMsisdn(),otpcode);
+		otp.validateOTP();
+		if(!otp.isValid()){
+			otp.updateOTPStatus(-1, "INVALID OTP");
+			return new Message(0, 0, "INVALID OTP");
+		}
+		
+		if(otp.isExpired()){
+			otp.updateOTPStatus(-1, "OTP EXPIRED");
+			return new Message(0, 0,"OTP EXPIRED");
+		}
+		
+
+		otp.updateOTPStatus(0, "SUCCESS");
+		
+		//IF NOT SUBSCRIBED
+		if(!originator.isSubscribed()){
+			return new Message(0, 0, "REGIS:" + MessageId.MSISDN_ERROR);
+		}
+		
+		msg = TransactionHelper.validateOriginator(originator, null);
+		if(msg != null){
+			return msg;
+		}
+		msg = TransactionHelper.allowedTransaction(originator, key);		
+		if(msg != null){
+			return msg;
+		}
+		
+		log.info(key+"|"+"Msisdn"+"|"+originator.getMsisdn() +"|"+ "EULA"+"|"+ "0L"+ "|"+ "0");
+		SystemInfo.getDb().QueryUpdate("UPDATE TBLMOBILEACCOUNTINFO SET TOKEN = ?, VERSION = ? WHERE MSISDN = ? ", token, version, originator.getMsisdn());
+		
+		String strmsg = null;
+		
+		strmsg = "REGIS:" + MessageId.SUCCESS_REGISTER_MSISDN + 
+				 ":" + refid + 
+				 ":" + msisdn + 
+				 ":" + originator.getProperty("FIRSTNAME") + 
+				 ":" + originator.getProperty("LASTNAME") + 
+				 ":" + Messanger.getMessage(MessageId.SUCCESS_REGISTER_MSISDN, originator).getMessage();
+		
+		return new Message(0, 0, strmsg);
+		}catch(Exception e){
+		log.error("Android Eula Error",e);
+		
+		return new Message(0,0,"FAILED:" + msg.getMessage().toString());
+	}
+}
+
+
+}

+ 186 - 0
GabonTelMobicashMobileAppHelper/src/main/java/com/psi/gabontel/mobileapp/thirdparty/helper/OTPHandler.java

@@ -0,0 +1,186 @@
+package com.psi.gabontel.mobileapp.thirdparty.helper;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.jboss.logging.Logger;
+
+import com.psi.common.crypto.PasswordGenerator;
+import com.psi.common.db.DataRow;
+import com.psi.common.transactions.SystemInfo;
+import com.psi.common.util.StringUtil;
+
+public class OTPHandler
+{
+	
+  private static final Logger log = Logger.getLogger(OTPHandler.class);
+  private String msisdn;
+  private String otp;
+  
+  private boolean success = false;
+  private boolean valid = false;
+
+  
+  public OTPHandler() {
+  }
+  
+  public OTPHandler(String msisdn){
+    setMsisdn(msisdn);
+  }
+  
+  public OTPHandler(String msisdn, String otp){
+    setMsisdn(msisdn);
+    setOtp(otp);
+  }
+
+  
+  public boolean isExpired(){
+    try
+    {
+      DataRow dr = SystemInfo.getDb().QueryDataRow("SELECT TO_CHAR(SYSDATE,'MM-DD-YYYY HH24:MI:SS') NOW, TO_CHAR(NVL(EXPIRATION,SYSDATE-1),'MM-DD-YYYY HH24:MI:SS') EXPIRATION FROM TBLREGISTRATIONOTP WHERE MSISDN = ? AND OTP=?", new Object[] { getMsisdn(), getOtp()});
+      
+      String now = dr.getString("NOW");
+      String expirydate = dr.getString("EXPIRATION");
+      
+      log.trace("CHECKING IF EXPIRED : "+getMsisdn() +" : "+getOtp());
+      log.trace("SYSDATE : "+now);
+      log.trace("EXPIRYDATE : "+expirydate);
+    	
+      
+      if (StringUtil.isNullOrEmpty(expirydate)) {
+        return true;
+      }
+      
+      SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
+      Date _now = sdf.parse(now);
+      Date _expirydate = sdf.parse(expirydate);
+      
+      log.trace("SYSDATE after parsing : "+_now);
+      log.trace("EXPIRYDATE after parsing :"+_expirydate);
+    	
+      
+      if (_now.after(_expirydate)) {
+        return true;
+      }
+      return false;
+    }
+    catch (ParseException e)
+    {
+    	log.trace("Date parsing error ~ " + e.getStackTrace());
+    }
+    return true;
+  }
+  
+  
+  
+  public void generateOTP(int status , String remarks)
+  {
+    int count = ((Integer)SystemInfo.getDb().QueryScalar("SELECT COUNT(1) FROM TBLREGISTRATIONOTP WHERE MSISDN = ?", Integer.valueOf(-1), new Object[] { getMsisdn() })).intValue();
+    String otp = generateOTP();
+    setOtp(otp);
+    if (count > 0)
+    {
+      if (SystemInfo.getDb().QueryUpdate("UPDATE TBLREGISTRATIONOTP SET OTP = ?,STATUS = ?, REMARKS = ?, EXPIRATION = SYSDATE + ?/(60*24) WHERE MSISDN = ?", new Object[] { otp,status,remarks, 30, getMsisdn() }) > 0) {
+        setSuccess(true);
+      }
+    }
+    else if (SystemInfo.getDb().QueryUpdate("INSERT INTO TBLREGISTRATIONOTP(MSISDN,OTP,EXPIRATION,REMARKS,STATUS) VALUES(?,?,SYSDATE + ?/(60*24),?,?)", new Object[] { getMsisdn(), otp, 30,remarks,status }) > 0) {
+      setSuccess(true);
+    }
+  }
+  
+  //active
+  public void generateOTP(int status , String remarks, String token, String version)
+  {
+    int count = ((Integer)SystemInfo.getDb().QueryScalar("SELECT COUNT(1) FROM TBLREGISTRATIONOTP WHERE MSISDN = ?", Integer.valueOf(-1), new Object[] { getMsisdn() })).intValue();
+    String otp = generateOTP();
+    setOtp(otp);
+    if (count > 0)
+    {
+      if (SystemInfo.getDb().QueryUpdate("UPDATE TBLREGISTRATIONOTP SET OTP = ?,STATUS = ?, REMARKS = ?, EXPIRATION = SYSDATE + ?/(60*24), TOKEN=?, VERSION=? WHERE MSISDN = ?", new Object[] { otp,status,remarks, SystemInfo.getProperty("MOBILEOTP", Integer.valueOf(5)),token,version , getMsisdn()}) > 0) {
+        setSuccess(true);
+      }
+    }
+    else if (SystemInfo.getDb().QueryUpdate("INSERT INTO TBLREGISTRATIONOTP(MSISDN,OTP,EXPIRATION,REMARKS,STATUS,TOKEN,VERSION) VALUES(?,?,SYSDATE + ?/(60*24),?,?,?,?)", new Object[] { getMsisdn(), otp, SystemInfo.getProperty("MOBILEOTP", Integer.valueOf(5)),remarks,status,token,version }) > 0) {
+      setSuccess(true);
+    }
+  }
+
+  
+  public void validateOTP()
+  {
+    int count = ((Integer)SystemInfo.getDb().QueryScalar("SELECT COUNT(1) FROM TBLREGISTRATIONOTP WHERE MSISDN = ? AND OTP = ?", Integer.valueOf(-1), new Object[] { getMsisdn(), getOtp() })).intValue();
+    if (count > 0) {
+      setValid(true);
+    }
+  }
+  
+
+  
+  private String generateOTP()
+  {
+    return PasswordGenerator.generatePassword(6, 4);
+  }
+  
+  
+  
+	public boolean updateOTPStatus(int status, String remarks){
+		
+		if(SystemInfo.getDb().QueryUpdate("UPDATE TBLREGISTRATIONOTP SET STATUS = ?, REMARKS = ? WHERE MSISDN=?", new Object[] { 
+				Integer.valueOf(status), 
+				remarks,
+				getMsisdn()
+			    })>0){
+			return true;
+			
+		}else{
+			//CustomLogger.LogServer("UPDATE FAILED on TBLOTP "+status+"~"+pushreference);
+			log.error("UPDATE FAILED on TBLREGISTRATIONOTP for : "+getMsisdn());
+		}
+		return false;		
+	}
+  
+  
+  public String getMsisdn()
+  {
+    return this.msisdn;
+  }
+  
+  public void setMsisdn(String msisdn)
+  {
+    this.msisdn = msisdn;
+  }
+  
+  public String getOtp()
+  {
+    return this.otp;
+  }
+  
+  public void setOtp(String otp)
+  {
+    this.otp = otp;
+  }
+  
+  public boolean isSuccess()
+  {
+    return this.success;
+  }
+  
+  public void setSuccess(boolean success)
+  {
+    this.success = success;
+  }
+  
+  public boolean isValid()
+  {
+    return this.valid;
+  }
+  
+  public void setValid(boolean valid)
+  {
+    this.valid = valid;
+  }
+
+  
+}