Commit 602865ea authored by ptajane's avatar ptajane

- Add new option 3 for device security in ENTERPRISE table

3 - Admin Approval (More than one device tries to login then send approval to admin, if admin approves then only allow to login.)

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@202764 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 1db18862
package ibase.webitm.ejb.sys;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import org.w3c.dom.Document;
import ibase.ejb.CommonDBAccessEJB;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
public class UserDevicePosJB extends ValidatorEJB
{
public String postSave(String xmlString, String tranId,String editFlag, String xtraParams, Connection conn)throws RemoteException,ITMException
{
String responseStr = "";
Document dom = null;
System.out.println("In UserDevicePosJB postSave called");
System.out.println("In UserDevicePosJB postSave tranId : ["+tranId+"]");
System.out.println("In UserDevicePosJB postSave editFlag : ["+editFlag+"]");
System.out.println("In UserDevicePosJB postSave xtraParams : ["+xtraParams+"]");
System.out.println("In UserDevicePosJB postSave xmlString : ["+xmlString+"]");
try
{
E12GenericUtility genericUtility= new E12GenericUtility();
if (xmlString != null && xmlString.trim().length() > 0)
{
dom = genericUtility.parseString(xmlString);
responseStr = executePostSave(dom, tranId, editFlag, xtraParams, conn);
System.out.println("UserDevicePosJB responseStr : ["+responseStr+"]");
}
}
catch(Exception e)
{
System.out.println("Exception :UserDevicePosJB : [" + e + "]");
e.printStackTrace();
throw new ITMException(e);
}
return responseStr;
}
public String executePostSave(Document dom, String tranId,String editFlag, String xtraParams, Connection conn)throws RemoteException,ITMException
{
String responseStr = "";
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
CommonDBAccessEJB commonDBAccessEJB = new CommonDBAccessEJB();
E12GenericUtility e12GenericUtility = new E12GenericUtility();
UserInfoBean userInfo = getUserInfo();
System.out.println("In UserDevicePosJB executePostSave userInfo : ["+userInfo+"]");
String userID = userInfo.getLoginCode();
String transDB = userInfo.getTransDB();
System.out.println("In UserDevicePosJB executePostSave userID : ["+userID+"]");
System.out.println("In UserDevicePosJB executePostSave transDB : ["+transDB+"]");
ConnDriver connDriver = new ConnDriver();
connection = connDriver.getConnectDB( transDB );
String requsetedIP = checkNull( e12GenericUtility.getColumnValue("requested_ip", dom, "1") );
System.out.println("In UserDevicePosJB executePostSave requsetedIP : ["+requsetedIP+"]");
StringBuilder whereCond = new StringBuilder();
whereCond.append( " WHERE USER_ID ='" ).append( userInfo.getLoginCode() ).append( "' " );
whereCond.append( " AND IP ='" ).append( requsetedIP ).append( "' ");
String recExist = E12GenericUtility.checkNull(commonDBAccessEJB.getDBColumnValue("USER_IP", "COUNT(*)", whereCond.toString()));
int recExistCount = Integer.valueOf(recExist);
System.out.println("In UserDevicePosJB executePostSave USER_IP exist record count : ["+recExistCount+"]");
if( recExistCount == 0 )
{
String sql = "INSERT INTO USER_IP (USER_ID, IP) VALUES('"+userID+"','"+requsetedIP+"')";
preparedStatement = connection.prepareStatement(sql);
int insertCount = preparedStatement.executeUpdate();
System.out.println("In UserDevicePosJB executePostSave user_ip insertCount : ["+insertCount+"]");
connection.commit();
preparedStatement.close();
preparedStatement = null;
}
String deviceIdPush = checkNull( e12GenericUtility.getColumnValue("device_id__push", dom, "1") );
System.out.println("In UserDevicePosJB executePostSave device_id__push : ["+deviceIdPush+"]");
if( deviceIdPush.indexOf("_") != -1 )
{
String geopos = checkNull( deviceIdPush.substring( deviceIdPush.lastIndexOf("_")+1 ) );
System.out.println("In UserDevicePosJB executePostSave geoposition : ["+geopos+"]");
if( geopos.length() > 0 )
{
StringBuilder whereCondition = new StringBuilder();
whereCondition.append( " WHERE USER_ID ='" ).append( userInfo.getLoginCode() ).append( "' " );
whereCondition.append( " AND GEOPOS ='" ).append( geopos ).append( "' ");
String recordExist = E12GenericUtility.checkNull(commonDBAccessEJB.getDBColumnValue("USER_GEOPOS", "COUNT(*)", whereCondition.toString()));
int recordExistCount = Integer.valueOf(recordExist);
System.out.println("In UserDevicePosJB executePostSave USER_GEOPOS exist record count : ["+recordExistCount+"]");
if( recordExistCount == 0 )
{
String sql = "INSERT INTO USER_GEOPOS (USER_ID, GEOPOS) VALUES('"+userID+"','"+geopos+"')";
preparedStatement = connection.prepareStatement(sql);
int insertCount = preparedStatement.executeUpdate();
System.out.println("In UserDevicePosJB executePostSave user_gepos insertCount : ["+insertCount+"]");
connection.commit();
preparedStatement.close();
preparedStatement = null;
}
}
}
}
catch(ITMException e)
{
System.out.println("In UserDevicePosJB executePostSave ITMException : ["+e.getMessage()+"]");
try
{
if( connection != null )
{
connection.rollback();
connection.close();
connection = null;
}
}
catch (Exception e2)
{
System.out.println("In UserDevicePosJB executePostSave ITMException::: ["+e2+"]");
}
throw e;
}
catch (Exception e)
{
System.out.println("In UserDevicePosJB executePostSave Exception : ["+e+"]");
try
{
if( connection != null )
{
connection.rollback();
connection.close();
connection = null;
}
}
catch (Exception e2)
{
System.out.println("In UserDevicePosJB executePostSave Exception::: ["+e2+"]");
}
throw new ITMException(e);
}
finally
{
try
{
if( preparedStatement != null )
{
preparedStatement.close();
preparedStatement = null;
}
if( connection != null )
{
connection.close();
connection = null;
}
}
catch (Exception e2)
{
System.out.println("In UserDevicePosJB executePostSave finally Exception : ["+e2+"]");
}
}
return responseStr;
}
public static String checkNull(String input)
{
if (input == null || "null".equalsIgnoreCase(input) || "undefined".equalsIgnoreCase(input))
{
input= "";
}
return input.trim();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment