Permalink
Browse files

selectonload moving to backend

  • Loading branch information...
samarjit committed Aug 10, 2011
1 parent 3021ba8 commit 6aecefc8fd0e39b66b855af3fc2b9a2a2c7fcd21
@@ -53,8 +53,8 @@
*/
public ResultDTO commandProcessor( JSONObject submitdataObj, String screenName) throws Exception{
// JsrpcPojo rpc = new JsrpcPojo();
-
- ResultDTO resDTO = null;
+ logger.debug("Remote command processor");
+ ResultDTO resDTO = new ResultDTO();
try{
if(Constants.APP_LAYER == Constants.FRONTEND){
Element rootXml = ScreenMapRepo.findMapXMLRoot(screenName);
@@ -1,27 +1,31 @@
package com.ycs.fe.crud;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
-import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import org.apache.log4j.Logger;
import org.dom4j.DocumentException;
import org.dom4j.Element;
+import org.dom4j.Node;
import org.dom4j.io.SAXReader;
-import com.google.gson.Gson;
+import com.ycs.fe.commandprocessor.BaseCommandProcessor;
+import com.ycs.fe.commandprocessor.CommandProcessorResolver;
import com.ycs.fe.dao.FETranslatorDAO;
import com.ycs.fe.dto.InputDTO;
-import com.ycs.fe.dto.PrepstmtDTO.DataType;
-import com.ycs.fe.dto.PrepstmtDTOArray;
import com.ycs.fe.dto.ResultDTO;
import com.ycs.fe.util.Constants;
import com.ycs.fe.util.ScreenMapRepo;
import com.ycs.struts.mock.ActionContext;
+import com.ycs.struts.mock.ServletActionContext;
+import com.ycs.ws.beclient.QueryService;
+import com.ycs.ws.beclient.QueryServiceService;
/**
* Used for prepopulating data onto value stack for. It can be called from any Action class or Interceptor.
@@ -32,6 +36,47 @@
private Logger logger = Logger.getLogger(this.getClass());
public void selectOnLoad(String screenName1, JSONObject jsonsubmitdata ){
+
+ try {
+ if (Constants.APP_LAYER == Constants.FRONTEND) {
+ Element rootXml = ScreenMapRepo.findMapXMLRoot(screenName1);
+ Node sessionVar = rootXml
+ .selectSingleNode("/root/screen/sessionvars");
+ if (sessionVar != null) {
+ String strSessionVar = sessionVar.getText();
+ Map<String, String> sessionMap = new HashMap<String, String>();
+ if (strSessionVar != null || !"".equals(strSessionVar)) {
+ String[] arSessionVar = strSessionVar.split(",");
+ if (arSessionVar.length > 0) {
+ for (String sessVariable : arSessionVar) {
+ String[] sessionField = sessVariable.trim()
+ .split("\\|");
+ String sessionData = "";
+ if (sessionField.length > 1) {
+ //datatype is defined and it is required
+ sessionData = (String) ServletActionContext
+ .getContext().getSession()
+ .get(sessionField[0]);
+ System.out.println("sessionData:"
+ + sessionData);
+ if (sessionField[1].equals("INT")) {
+ sessionData.matches("0-9");
+ //TODO some data validation
+
+ }
+ }
+ sessionMap.put(sessionField[0], sessionData);
+ }
+ }
+ }
+ if(jsonsubmitdata == null || jsonsubmitdata.isNullObject())jsonsubmitdata = new JSONObject();
+ logger.debug("output session data:"+JSONObject.fromObject(sessionMap));
+ jsonsubmitdata.put("sessionvars", JSONObject.fromObject(sessionMap));
+ }
+ }
+ } catch (Exception e) {
+ logger.debug("error in setting sessionvars",e);
+ }
if(Constants.CMD_PROCESSOR == Constants.APP_LAYER){
localSelectOnLoad( screenName1, jsonsubmitdata );
}else{
@@ -46,27 +91,75 @@ public void localSelectOnLoad(String screenName1, JSONObject jsonsubmitdata ){
try {
org.dom4j.Document document1 = new SAXReader().read(xmlconfigfile);
org.dom4j.Element root = document1.getRootElement();
+ HashMap<String, Object> adhocstackids = new HashMap<String, Object>();
+ List<String> outstackList = new ArrayList<String>();
//preload select queries
List nodeList = root.selectNodes("//query");
logger.debug("query list size:"+nodeList.size());
for (Iterator queryList = nodeList.iterator(); queryList.hasNext();) {
org.dom4j.Node node = (org.dom4j.Node) queryList.next();
- logger.debug("Query Node:"+node.getText());
String stackid = ((org.dom4j.Element) node).attributeValue("stackid");
+ logger.debug("Query Node:"+node.getText()+" stackid:"+stackid);
String type = ((org.dom4j.Element) node).attributeValue("type");
String sqlquery = node.getText();
FETranslatorDAO feDAO = new FETranslatorDAO();
- feDAO.executequery(sqlquery,stackid,type);
+ feDAO.executequery(sqlquery,stackid,type); //outputs in different stack ids
org.dom4j.Element e = (org.dom4j.Element) node;
-
+
+ if(stackid != null && !"".equals(stackid))
+ outstackList.add(stackid);
}
//preload selectonload queries
- List selonloadnl = root.selectNodes("//selectonload");
+ /* List selonloadnl = root.selectNodes("//selectonload");
Element elm = (Element) root.selectSingleNode("/root/screen");
String screenName = elm.attributeValue("name");
- logger.debug("query selectonload list size:"+selonloadnl.size());
+ logger.debug("query selectonload list size:"+selonloadnl.size());*/
+
+ ResultDTO resDTO = new ResultDTO();
+ for (String vstackkey : outstackList) {
+ ResultDTO tempDTO = new ResultDTO();
+ HashMap<String,Object> valueStack = new HashMap<String, Object>();
+ valueStack.put(vstackkey, ActionContext.getContext().getValueStack().getContext().get(vstackkey));
+ tempDTO.setData(valueStack);
+ resDTO.merge(tempDTO);
+ }
+
+ /////command onload ////
+ Element onloadElm = (Element) root.selectSingleNode("/root/screen/commands/onload");
+ String commandChain = onloadElm.attributeValue("opt");
+ String[] opts = commandChain.split("\\|");
+ ResultDTO resultDTO = new ResultDTO();
+ InputDTO inputDTO = new InputDTO();
+ inputDTO.setData(jsonsubmitdata);
+
+ for (String opt : opts) {
+ String[] sqlcmd = opt.split("\\:"); //get Id of query
+ String querynodeXpath = sqlcmd[0]+"[@id='"+sqlcmd[1]+"']"; //Query node xpath
+ Element processorElm = (Element) root.selectSingleNode("/root/screen/*/"+querynodeXpath+" ");
+ String strProcessor = processorElm.getParent().getName();
+ String outstack = processorElm.attributeValue("outstack");
+ BaseCommandProcessor cmdProcessor = CommandProcessorResolver.getCommandProcessor(strProcessor);
+ resultDTO = cmdProcessor.processCommand(screenName1, querynodeXpath, null, inputDTO, resultDTO);
+ if(outstack != null && !"".equals(outstack))
+ outstackList.add(outstack);
+ //resDTO = rpc.selectData( screenName, null, querynodeXpath , (JSONObject)jsonRecord);
+ }
+ resultDTO.merge(resDTO);
+
+
+ adhocstackids.put("adhocstackids", outstackList);
+ resDTO.setData(adhocstackids);
+
+ resultDTO.merge(resDTO);
+
+ ActionContext.getContext().getValueStack().set("resDTO",JSONSerializer.toJSON(resultDTO).toString());
+ System.out.println("SelectOnLoad::"+ JSONSerializer.toJSON(resultDTO).toString());
+ System.out.println("SelectOnLoad::adhocstackids"+ JSONSerializer.toJSON(resultDTO.getData().get("adhocstackids")).toString());
+ /////end command onload ////
+
+ /*
for (Iterator queryList = selonloadnl.iterator(); queryList.hasNext();) {
org.dom4j.Node queryNode = (org.dom4j.Node) queryList.next();
logger.debug("Query Node:"+queryNode.getText());
@@ -89,26 +182,26 @@ public void localSelectOnLoad(String screenName1, JSONObject jsonsubmitdata ){
PrepstmtDTOArray arparam = new PrepstmtDTOArray();
InputDTO inputDTO = new InputDTO();
inputDTO.setData(jsonsubmitdata);
- String parsedquery = QueryParser.parseQuery(sqlquery, null, jsonsubmitdata, arparam, hmfielddbtype, inputDTO, null /*TODO no prev calls*/);
+ String parsedquery = QueryParser.parseQuery(sqlquery, null, jsonsubmitdata, arparam, hmfielddbtype, inputDTO, resDTO );
logger.debug("selonload Query query:"+parsedquery+"\n Expanded prep:"+arparam.toString(parsedquery));
FETranslatorDAO feDAO = new FETranslatorDAO();
ResultDTO resDTO = feDAO.executecrud(screenName,parsedquery,stackid,jsonsubmitdata, arparam, errorTemplate, messageTemplate );
-
+ resDTO.merge(resultDTO);
logger.debug("resDTO (gson converter)= "+new Gson().toJson(resDTO).toString());
logger.debug("resDTO (JSONSerializer converter)= "+JSONSerializer.toJSON(resDTO).toString());
- ActionContext.getContext().getValueStack().set("resDTO",new Gson().toJson(resDTO).toString());
+ ActionContext.getContext().getValueStack().set("resDTO", JSONSerializer.toJSON(resDTO).toString());
ActionContext.getContext().getValueStack().getContext().put("ZHello", "World");
ActionContext.getContext().getValueStack().set("ZHello2", "World2");
org.dom4j.Element e = (org.dom4j.Element) queryNode;
System.out.println("HTMLProcessor **************** populating value stack");
}
-
+ */
} catch (DocumentException e) {
logger.debug("result xml file not readable --",e);
e.printStackTrace();
- } catch (JSONException e) {
- logger.debug("result xml file not readable --",e);
- e.printStackTrace();
+// } catch (JSONException e) {
+// logger.debug("result xml file not readable --",e);
+// e.printStackTrace();
} catch (Exception e) {
logger.debug("result xml file not readable --",e);
e.printStackTrace();
@@ -121,6 +214,10 @@ public void localSelectOnLoad(String screenName1, JSONObject jsonsubmitdata ){
}
public void remoteSelectOnLoad(String screenName1, String jsonsubmitdata ){
-
+ logger.debug("Sent to BE:"+jsonsubmitdata);
+ QueryServiceService qss = new QueryServiceService();
+ QueryService queryServicePort = qss.getQueryServicePort();
+ String strResDTO = queryServicePort.selectOnLoad(screenName1, jsonsubmitdata);
+ logger.debug("returned result from select on load:"+strResDTO);
}
}
@@ -1,6 +1,7 @@
package com.ycs.ws;
import java.util.EnumSet;
+import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@@ -42,10 +43,13 @@ public String selectOnLoad(String screenName, String jsonsubmitdata ){
InputDTO inpDTO = new InputDTO();
inpDTO.setData(jsonsubmitdata1);
ServletActionContext.getContext().getValueStack().set("inputDTO", inpDTO);
- Map<String, String> sessionvars = inpDTO.getData().getJSONObject("sessionvars");
+ JSONObject sessionvars = inpDTO.getData().getJSONObject("sessionvars");
System.out.println(inpDTO.getData().toString());
- for (Entry<String, String> itr : sessionvars.entrySet()) {
- ServletActionContext.getContext().getSession().put(itr.getKey(), itr.getValue());
+ for (Iterator iterator = sessionvars.keys(); iterator.hasNext();) {
+ String sessionkey = (String) iterator.next();
+ String sessionval = sessionvars.getString(sessionkey);
+ System.out.println("sessionvars getValue :"+sessionval);
+ ServletActionContext.getContext().getSession().put(sessionkey, sessionval);
}
sl.selectOnLoad(screenName, jsonsubmitdata1 );
@@ -66,10 +70,13 @@ public String remoteCommandProcessor(String submitdataObj, String screenName) th
InputDTO inpDTO = new InputDTO();
inpDTO.setData(submitdata);
ServletActionContext.getContext().getValueStack().set("inputDTO", inpDTO);
- Map<String, String> sessionvars = inpDTO.getData().getJSONObject("sessionvars");
- System.out.println(inpDTO.getData().toString());
- for (Entry<String, String> itr : sessionvars.entrySet()) {
- ServletActionContext.getContext().getSession().put(itr.getKey(), itr.getValue());
+ JSONObject sessionvars = inpDTO.getData().getJSONObject("sessionvars");
+ System.out.println("InputDTO.getData() is "+inpDTO.getData().toString());
+ for (Iterator iterator = sessionvars.keys(); iterator.hasNext();) {
+ String sessionkey = (String) iterator.next();
+ String sessionval = sessionvars.getString(sessionkey);
+ System.out.println("sessionvars getValue :"+sessionval);
+ ServletActionContext.getContext().getSession().put(sessionkey, sessionval);
}
CommandProcessor processor = new CommandProcessor();
View
@@ -29,10 +29,16 @@
</text>
<styleinclude>some2.css</styleinclude>
</stylesheets>
+ <sessionvars>
+ mysessionkey|STRING
+ </sessionvars>
<crud>
+
<jsonrpc id="rpc1" outstack="form1">SELECT PROGNAME "txtnewprogname",PROGDESC "txtprogramdesc",ISSUERNAME "issuername", COUNTRY_ISSUE "countryofissue", STATUS "txtstatus" FROM
PROGRAMDETAILS
where PROGNAME=:whereval|STRING order by 1</jsonrpc>
+ <jsonrpc id="progdetails" outstack="form1">SELECT p.prog_desc "desc", p.issuer_name "issuername", c.country_name "country", p.country "countrycode" FROM
+ PROGRAM_SETUP p, country c where p.country = c.country_code and p.prog_name=:whereval|STRING </jsonrpc>
<jsonrpc id="rpc3" outstack="form1"><![CDATA[
SELECT PROGNAME "txtnewprogname",PROGDESC "txtprogramdesc",ISSUERNAME "issuername", COUNTRY_ISSUE "countryofissue", STATUS "txtstatus" FROM PROGRAMDETAILS
where PROGNAME <> :whereval|STRING order by 1]]>
@@ -43,32 +49,34 @@
<selectonload outstack="form2" id="selqry1">SELECT 'LOYCARD' "txtnewprogname" from DUAL </selectonload>
<selectonload outstack="form1" id="selqry2">
SELECT PROGNAME "txtnewprogname",PROGDESC "txtprogramdesc",ISSUERNAME "issuername" ,COUNTRY_ISSUE "countryofissue", STATUS "txtstatus" FROM PROGRAMDETAILS
- where PROGNAME is not :inp.form2[0].txtnewprogname order by 1
+ where PROGNAME is not :res.form2[0].txtnewprogname order by 1
<countquery pagesize="3">SELECT count('x') from PROGRAMDETAILS where PROGNAME=:form2[0].txtnewprogname </countquery>
</selectonload>
-
+ <selectonload outstack="countryofissue" id="countryofissue">select country_code "txtccode",country_name "txtcname" from country</selectonload>
+ <selectonload outstack="programname" id="programname">select PROG_CODE "txtpmcode", PROG_NAME "txtpmname" from program_setup </selectonload>
<sqlselect id="selSpl1" outstack="list1">
select USER_ID userid, PASSWD password from USER_MASTER
<error message="Select Failed {userid} "></error>
</sqlselect>
<sqlinsert id="ins1" outstack="frmIns1">insert into PROGRAMDETAILS (PROGNAME,PROGDESC,COUNTRY_ISSUE,STATUS)values(:txtnewprogname,:txtprogramdesc,:countryofissue, :txtstatus|STRING )</sqlinsert>
<sqldelete id="del1" outstack="frmDel1">delete from PROGRAMDETAILS where PROGNAME=:form1[0].txtnewprogname AND COUNTRY_ISSUE=:form1[0].countryofissue</sqldelete>
- <sqlupdate id="Upd1" outstack="frmUpd1">update PROGRAMDETAILS set PROGDESC=:txtprogramdesc,COUNTRY_ISSUE=:countryofissue, ISSUERNAME=:issuername|STRING, STATUS=:txtstatus|STRING
- where PROGNAME=:inp.form1[0].txtnewprogname </sqlupdate>
+ <sqlupdate id="Upd1" outstack="frmUpd1">update PROGRAM_SETUP set prog_desc =:txtprogramdesc,COUNTRY=:countryofissue, ISSUER_NAME=:issuername|STRING, STATUS=:txtstatus|STRING
+ where PROG_name=:inp.form1[0].txtnewprogname </sqlupdate>
</crud>
<dm>
- <txnproc id="TRANSCODE"></txnproc>
+ <txnproc id="pmdetails" outstack="frmUpd1">{'transcode':'STUCAP','single': :inp.single ,'multiple'::inp.multiple }</txnproc>
</dm>
<bl>
<buslogic id="ArbritrarySelect" method="testMethod1"> </buslogic>
</bl>
<anyprocs >
- <proc id="upd2" xml="input.xml" ><![CDATA[
- dfgdfgdfg
- ]]></proc>
+ <proc id="upd2" outstack="frmUpd1">{'procname':'WS_TEST_PROC','inputparam':[[{'NAME':'sam','EMAIL':'sam@yl.com'},{'NAME':'samarjit','EMAIL':'samarjit@yl.com'}],{'data1':'param2'}],'outputparam':'param3'}</proc>
+ <proc id="pmdetails" outstack="frmUpd1">{'procname':'ws_test_proc','inputparam':[:inp.param1 ,:inp.whereval] ,'outputparam':'desc'}</proc>
</anyprocs>
<commands>
+ <cmd name="getpmdetailsdm" opt="txnproc:pmdetails" instack="form1" result="ajax" processor="dm"></cmd>
+ <cmd name="getpmdetails" opt="jsonrpc:progdetails" instack="form1" result="ajax" processor="crud"></cmd>
<cmd name="BusLogic1" opt="buslogic:ArbritrarySelect" instack="form1" result="ajax" processor="bl" />
<cmd name="TXNPROC1" opt="txnproc:TRANSCODE" instack="form1" result="ajax" processor="dm" />
<cmd name="jrpcCmd1" opt="jsonrpc:rpc3" instack="form1" result="ajax" processor="crud" />
@@ -78,6 +86,7 @@
<cmd name="selectlist" opt="sqlupdate:ins2|sqlupdate:upd2" instack="formChild" result="ajax|{screenName}" processor="crud" />
<cmd name="CallAayProc" opt="proc:upd2" instack="formChild" result="ajax|{screenName}" processor="anyproc" />
<bulkcmd name="blTest" opt="buslogic#ArbritrarySelect" result="ajax"/>
+ <onload name="blTest" opt="selectonload:selqry1|selectonload:selqry2|selectonload:programname" />
</commands>
</screen>
@@ -89,6 +98,19 @@
<field>
<sometype name="whereval" dbdatatype="STRING"></sometype>
</field>
+ <field>
+ <select type="text" class="userid" forid="programname" value="txtpmname" key="txtpmname" name="programname" id="programname" column="FF0149" dbdatatype="STRING" dbcolsize="" mask="" mandatory=""
+ hidden="" label="" replace="modify">
+ <text>
+ <![CDATA[ <select name="programname" id="programname" maxlength="50" class="field" onchange="iadt.copySeltohidden(this,'newprog','txtnewprogname',populateFieldsToModify)">
+ <option value="">Select</option>
+ <option value="New">New</option>
+ </select>]]>
+ </text>
+ <rule></rule>
+ <query></query>
+ </select>
+ </field>
<field>
<div id="alertmessage" forid="alertmessage" replace="append">
<xpath position="prepend">/html/body</xpath>
@@ -97,32 +119,27 @@
</div>
</field>
<field>
- <input type="text" class="userid" forid="txtnewprogname" value="dfgdfg" name="txtnewprogname" id="txtnewprogname" column="FF0151" dbdatatype="STRING" primarykey="YES" dbcolsize="" mask="" mandatory=""
+ <input type="text" class="userid" forid="txtnewprogname" value="" name="txtnewprogname" id="txtnewprogname" column="FF0151" dbdatatype="STRING" primarykey="YES" dbcolsize="" mask="" mandatory=""
hidden="" label="" replace="modify" >
<rule></rule>
</input>
</field>
<field>
- <input type="text" class="userid" forid="txtprogramdesc" value="dfgdfg" name="txtprogramdesc" id="txtprogramdesc" column="FF0148" dbdatatype="STRING" dbcolsize="" mask="" mandatory=""
+ <input type="text" class="userid" forid="txtprogramdesc" value="" name="txtprogramdesc" id="txtprogramdesc" column="FF0148" dbdatatype="STRING" dbcolsize="" mask="" mandatory=""
hidden="" label="" replace="modify">
<rule></rule>
</input>
</field>
<field>
- <select type="text" class="userid" forid="countryofissue" value="" name="countryofissue" id="countryofissue" column="FF0149" dbdatatype="STRING" dbcolsize="" mask="" mandatory=""
+ <select type="text" class="userid" forid="countryofissue" value="txtcname" key="txtccode" name="countryofissue" id="countryofissue" column="FF0149" dbdatatype="STRING" dbcolsize="" mask="" mandatory=""
hidden="" label="" replace="modify">
<text>
<![CDATA[<select name="countryofissue" maxlength="50" class="field" id="countryofissue">
<option value="" selected="selected">Select</option>
- <option value="INDIA">India</option>
- <option value="SINGAPORE">Singapore</option>
- <option value="AUSTRALIA">Australia</option>
- <option value="PHILIPPINES">Philippines</option>
- <option value="UAE">UAE</option>
</select>]]>
</text>
<rule></rule>
- <query></query>
+ <query stackid="countryofissue">select country_code "txtccode",country_name "txtcname" from country</query>
</select>
</field>
</fields>
Oops, something went wrong.

0 comments on commit 6aecefc

Please sign in to comment.