Commit 08af7a97 authored by steurwadkar's avatar steurwadkar

Added new component for webservices created for integrating Invoice, Credit, debit note etc

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@179288 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 38070a6e
package ibase.webitm.ejb.dis;
import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.InitialContext;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ibase.system.config.AppConnectParm;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.DBAccessLocal;
import ibase.webitm.ejb.MasterStatefulLocal;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
public class SCMWebServiceDao extends ValidatorEJB
{
E12GenericUtility e12GenericUtility = new E12GenericUtility();
public String addTransaction(String dataXML, String userCode) throws ITMException
{
String retString = "", userInfo = "";
MasterStatefulLocal masterStatefulLocal = null;
DBAccessLocal dbAccessEJBLocal = null;
UserInfoBean userInfoBean = null;
Connection conn = null;
boolean isError = false, isCommit = false;
Document errDom = null;
StringBuffer retSBuff = new StringBuffer("<Root>");
try
{
System.out.println("SCMWebServiceDao.addTransaction().dataXML["+dataXML+"]");
System.out.println("SCMWebServiceDao.addTransaction().userCode["+userCode+"]");
dbAccessEJBLocal = (DBAccessLocal)getInitialContext().lookup("ibase/DBAccessEJB/local");
userInfoBean = dbAccessEJBLocal.createUserInfo(userCode);
setUserInfo(userInfoBean);
userInfo = userInfoBean.toString();
System.out.println("SCMWebServiceDao.addTransaction().userInfo["+userInfo+"]");
conn = getConnection();
masterStatefulLocal = (MasterStatefulLocal) getInitialContext().lookup( "ibase/MasterStatefulEJB/local" );
retString = masterStatefulLocal.processRequest(userInfo, dataXML, true, conn);
System.out.println("After masterstateful retString["+retString+"]");
if(retString != null && retString.trim().length()>0 && retString.indexOf("<Errors>") >-1)
{
isCommit = false;
errDom = e12GenericUtility.parseString(retString);
NodeList errNodeList = errDom.getElementsByTagName("error");
int errNodeListLen = errNodeList.getLength();
for(int i=0; i<errNodeListLen; i++)
{
String errorMessage = "";
Node eachErrNode = errNodeList.item(i);
NodeList eachErrNodeList = eachErrNode.getChildNodes();
int eachErrNodeListLen = eachErrNodeList.getLength();
String msgNo = eachErrNode.getAttributes().getNamedItem("id").getNodeValue();
System.out.println("msgNo["+msgNo+"]");
for(int j=0; j<eachErrNodeListLen; j++)
{
Node eachNode = eachErrNodeList.item(j);
String nodeName = eachNode.getNodeName();
String nodeValue = eachNode.getFirstChild() != null ? eachNode.getFirstChild().getNodeValue():"";
if("description".equalsIgnoreCase(nodeName))
{
errorMessage = nodeValue;
}
}
retSBuff.append("<tran_id><![CDATA[]]></tran_id>");
retSBuff.append("<msg_code><![CDATA["+msgNo+"]]></msg_code>");
retSBuff.append("<msg_descr><![CDATA["+errorMessage+"]]></msg_descr>");
retSBuff.append("<result><![CDATA[FAILED]]></result>");
}
}
else
{
isCommit = true;
if ( retString.indexOf("Success") > -1 && retString.indexOf("<TranID>") > 0 )
{
String tranId = retString.substring( retString.indexOf("<TranID>")+8, retString.indexOf("</TranID>"));
retSBuff.append("<tran_id><![CDATA["+tranId+"]]></tran_id>");
retSBuff.append("<msg_code><![CDATA[]]></msg_code>");
retSBuff.append("<msg_descr><![CDATA[Transaction is saved]]></msg_descr>");
retSBuff.append("<result><![CDATA[SUCCESS]]></result>");
}
}
retSBuff.append("</Root>");
retString = retSBuff.toString();
System.out.println("Final retString["+retString+"]");
}
catch(Exception e)
{
isError = true;
System.out.println("SCMWebServiceDao.addTransaction()["+e.getMessage()+"]");
throw new ITMException (e);
}
finally
{
try
{
if(isError)
{
if( conn != null && !conn.isClosed() )
{
conn.rollback();
}
}
if( conn != null && !conn.isClosed() && !isError)
{
if(isCommit)
{
conn.commit();
}
else
{
conn.rollback();
}
}
if( conn != null && !conn.isClosed())
{
conn.close();
conn = null;
}
}
catch(SQLException se)
{
System.out.println("SCMWebServiceDao.addTransaction().finally["+se.getMessage()+"]");
}
}
return retString;
}
private InitialContext getInitialContext() throws ITMException
{
InitialContext ctx = null;
try
{
AppConnectParm appConnect = new AppConnectParm();
ctx = new InitialContext( appConnect.getProperty() );
}
catch( ITMException itme )
{
System.out.println( "SCMWebServiceDao : getInitialContext : "+ itme.getMessage() );
throw itme;
}
catch(Exception e)
{
System.out.println( "SCMWebServiceDao : getInitialContext : "+ e.getMessage() );
throw new ITMException(e);
}
return ctx;
}
}
package ibase.webitm.servlet.dis;
import java.util.ArrayList;
import javax.naming.InitialContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import org.w3c.dom.Document;
import ibase.ejb.CommonDBAccessLocal;
import ibase.servlet.Messages;
import ibase.system.config.AppConnectParm;
import ibase.utility.BaseException;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.dis.SCMWebServiceDao;
import ibase.webitm.utility.ITMException;
@Path("/scm")
public class SCMWebService
{
SCMWebServiceDao scmWSDao = new SCMWebServiceDao();
@POST
@Path("/addTransaction")
@Produces({"application/xml"})
public Response addTransaction(@Context HttpServletRequest request, @FormParam("DATA_XML") String dataXML, @FormParam("USERNAME") String userCode, @FormParam("PASSWORD") String password)
{
String retString = "";
ArrayList<String> langAndCountryList = new ArrayList<String>();
CommonDBAccessLocal commonDBAccessLocal = null;
try
{
if(dataXML == null || dataXML.trim().length() == 0 || userCode == null || userCode.trim().length() == 0 || password == null || password.trim().length() == 0)
{
System.out.println("IN missing parameters");
retString = "<Root><tran_id><![CDATA[]]></tran_id><msg_code><![CDATA[]]></msg_code><msg_descr><![CDATA[Missing required paramters]]></msg_descr><result><![CDATA[FAILED]]></result></Root>";
return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity(retString).build();
}
commonDBAccessLocal = (CommonDBAccessLocal)getInitialContext().lookup("ibase/CommonDBAccessEJB/local");
String siteCode = commonDBAccessLocal.getDBColumnValue( "USERS", "SITE_CODE__DEF","WHERE CODE = "+"'" +userCode+"'" );
String xmlInfoStr = commonDBAccessLocal.authenticate(userCode, password, siteCode, "I", "true");
System.out.println("authRetString["+xmlInfoStr+"]");
String userLanguage = commonDBAccessLocal.getDBColumnValue( "USERS", "USER_LANG","WHERE CODE = "+"'" +userCode+"'" );
String userCountry = commonDBAccessLocal.getDBColumnValue( "USERS", "USER_COUNTRY", "WHERE CODE = "+"'" +userCode+"'" );
if( userLanguage != null && userCountry != null )
{
langAndCountryList.add( userLanguage );
langAndCountryList.add( userCountry );
}
retString = generateResponse(xmlInfoStr, langAndCountryList);
if(retString != null && retString.trim().length()>0)
{
return Response.status(HttpServletResponse.SC_UNAUTHORIZED).entity(retString).build();
}
retString = scmWSDao.addTransaction(dataXML, userCode);
}
catch(Exception e)
{
System.out.println("SCMWebService.addTransaction()["+e.getMessage()+"]");
e.printStackTrace();
}
return Response.status(HttpServletResponse.SC_OK).entity( retString ).build();
}
private String generateResponse( String xmlInfo, ArrayList<String> langAndCountryList )throws BaseException
{
StringBuffer responseString = new StringBuffer();
String errorMessage = "";
try
{
if ( E12GenericUtility.checkNull( xmlInfo ).length() > 0 )
{
Document document = new E12GenericUtility().parseString( xmlInfo );
if ( document.getElementsByTagName( "STATUS_CODE" ).item(0) != null && document.getElementsByTagName("STATUS_CODE").item(0).getFirstChild() != null )
{
String statusCode = document.getElementsByTagName("STATUS_CODE").item(0).getFirstChild().getNodeValue();
if ( statusCode.equalsIgnoreCase("RESIGNED") )
{
errorMessage = Messages.getString( "AuthenticateServlet_employeeHasResigned", langAndCountryList );
}
else if ( statusCode.equalsIgnoreCase("LOCKED") )
{
errorMessage = Messages.getString( "AuthenticateServlet_accountIsLockedContactAdmin", langAndCountryList );
}
else if ( statusCode.indexOf("INVALID") != -1 )
{
if ( statusCode.equalsIgnoreCase("INVALID_USR") )
{
errorMessage = Messages.getString( "AuthenticateServlet_pleaseEnterValidUserNameAndPassword", langAndCountryList );
}
else if ( statusCode.equalsIgnoreCase("INVALID_PWD") )
{
errorMessage = Messages.getString( "AuthenticateServlet_pleaseEnterValidUserNameAndPassword", langAndCountryList );
}
}
else if( statusCode.indexOf("PASS_EXP") != -1 )
{
if ( statusCode.equalsIgnoreCase("PASS_EXP_NOGRACE") )
{
errorMessage = Messages.getString( "AuthenticateServlet_passwordExpiredChangeIt", langAndCountryList );
}
}
if( !"VALID".equalsIgnoreCase(statusCode) )
{
responseString.append("<Root>");
responseString.append("<tran_id><![CDATA[]]></tran_id>");
responseString.append("<msg_code><![CDATA[]]></msg_code>");
responseString.append("<msg_descr><![CDATA["+errorMessage+"]]></msg_descr>");
responseString.append("<result><![CDATA[FAILED]]></result>");
responseString.append("</Root>");
}
}
}
System.out.println("Final auth retString["+responseString.toString()+"]");
}
catch( BaseException be )
{
System.out.println("Exception: generateResponse:==>\n"+be);
throw be;
}
catch( Exception e )
{
System.out.println("Exception: generateResponse:==>\n"+e);
throw new BaseException( e );
}
return responseString.toString();
}
private InitialContext getInitialContext() throws ITMException
{
InitialContext ctx = null;
try
{
AppConnectParm appConnect = new AppConnectParm();
ctx = new InitialContext( appConnect.getProperty() );
}
catch( ITMException itme )
{
System.out.println( "SCMWebService : getInitialContext : "+ itme.getMessage() );
throw itme;
}
catch(Exception e)
{
System.out.println( "SCMWebService : getInitialContext : "+ e.getMessage() );
throw new ITMException(e);
}
return ctx;
}
}
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