I have a Backbone Model,Collection, and a server side REST implementation.
Can i send a request to the server that will replace the entire collection?
I tried doing this with jqeury.post request but I'm not sure what the data should hold (an array of items with the model attributes? an array of models? a collection?), and what should the REST recieves as parameters(A java List? a Java array? a custom object containing a list of something?).
Any thoughts of this issues? am i missing something
Thanks!
according with documentation, you need use fetch
documentation here [Backbone Fetch]: http://backbonejs.org/#Collection-fetch
fast example :
var newObject = new Object();
newObject.newvar1 = "newvar1"
newObject.newvar2 = "newvar2"
YOURMODEL.fetch({data: newObject,type:'POST'});
Related
I am building tests in SoapUI. I have a very large response (>3500 duties). For that response I need to build a request and execute that request. Currently the code (Java) works, but I would like to optimize the code.
For each Duty I build a request to get additional employee data and execute it using a for next loop. Below is an example of the large XML response that I get.
<DUTIES>
<DUTY>
<EMPNO>1</EMPNO>
<LOCATION>AMS</BASE_STATION>
<ACTUALTIME>2019-02-20T06:00:00</ACTUALTIME>
<POSITIONING_CODE>1</POSITIONING_CODE>
</DUTY>
<DUTY>
<EMPNO>2</EMPNO>
<LOCATION>RTM</BASE_STATION>
<ACTUALTIME>2019-02-20T06:00:00</ACTUALTIME>
<POSITIONING_CODE/>
</DUTY>
<DUTY>
<EMPNO>1</EMPNO>
<LOCATION>AMS</BASE_STATION>
<ACTUALTIME>2019-02-21T06:00:00</ACTUALTIME>
<POSITIONING_CODE>1</POSITIONING_CODE>
</DUTY>
</DUTIES>
As you can see from the sample the same employee is multiple times in the response, so currently I am calling the request multiple time for the same employee. I would like to optimize this.
In SoapUI I can use the statement:
String[] emps = resp.getNodeValues("/Duties/Duty/string(EMPNO)");
String[] locs = resp.getNodeValues("/Duties/Duty/string(LOCATION)");
String[] tims = resp.getNodeValues("/Duties/Duty/string(ACTUALTIME)");
Then I would like to sort the arrays on emps and only build a request to get additional employee data when the employee changes. This will make the code much faster.
Now my questions:
What is the best way to do this? Work with multidimensional array and sort them? Or is there a better way of doing this?
Thanks in advance,
Said
I would create an instance of java.util.HashMap<String,String> or java.util.HashMap<Long,String> depending on which datatype is returned, when you retrive the empno.
Just blindly do a map.put(empno,null) for each duty element, and you will only have each employee in the hashmap once afterwards, as each additional addition of the same key will overwrite the existing.
After that, simply
for (String key : map.keySet()) {
// do your stuff
}
As I see it, you really don't need to sort anything to get there.
I'm working with jQuery DataTables. I have it listing out a view and have checkboxes to select multiple documents. I'm able to get the selected keys into session scope via this client side JavaScript code :
<xp:this.script><![CDATA[// Build array of selected rows
var myTableApi = x$("inventoryTable").DataTable();
var count = myTableApi.rows( { selected: true } ).count();
var dataArr = [];
var rowData = myTableApi.rows( { selected: true } ).data();
$.each($(rowData),function(key,value){
dataArr.push(value[3]);
});
// Push that to the requestScope
setScopeValue("session", "rowCount", count);
setScopeValue("session", "rowIds", dataArr);]]></xp:this.script>
Once the id's are in Scope I change pages and then I want to load them into my Java pageController.
I can easily use a variable resolver to get ahold of "rowIds". But I'm not sure how to get it into Java so I could work with it. Ideally I'd like it to be List or Set or something similar.
In Java, how can I convert this JavaScript Array to a Collection based object?
Thanks!
There are a few tricks to do here.
First, since the particular implementation of your setScopeValue function converts all values to a string before sending them to the server, it's important to do setScopeValue("session", "rowIds", XSP.toJson(dataArr)). That way, the value stored on the server will be ["foo", "bar", "baz"] instead of foobarbaz.
Secondly, the best way to get to the session-scoped value in Java would be via ExtLibUtil.getSessionScope().get("rowIds").
That value will be a string, though, and not an array type, so it'll have to be parsed from JSON. Using the IBM Commons JSON capabilities, that can be done with:
List<?> rowIds = (List<?>)JsonParser.fromJson(JsonJavaFactory.instance, ExtLibUtil.getSessionScope().get("rowIds"))
for(Object rowIdObj : rowIds) {
String rowId = StringUtil.toString(rowIdObj);
// do stuff with each ID here
}
You can also potentially case it directly to a List<String>, since Java's generics are really just hints for compiler-generated code, and not really enforced in the objects themselves, but there you run the risk of a ClassCastException if the incoming List contains any non-string types.
I am writing an Assertion Generator Plugin in Java to fetch a user details from Session Store and modify the values in Assertion(SAML 2.0) accordingly.
I am able to identify the method(Link) using which I can pull the user values from Session Store (agentAPIObject.getSessionVariables()) based on SessionID, but, I am having trouble writing a code to fetch specific parameters from the session store. (speficially around setting values for Attribute method and making it as an array)
Can someone post a sample code if you have ever seen/written around it, so that I can fetch user attributes from Session Store.
I am having trouble understanding Java docs around it.
Thanks in advance,
The API mentions this:
responseAttributeList - On successful return from this method (YES is
returned), this output parameter contains the retrieved variable names
and their values. If the method returns UNRESOLVED, this parameter
includes variables that could not be retrieved.
You'll need to create two AttributeList Objects. If the response of getSessionVariables(...) is YES, then the variable responseAttributeList will contain the session variables. Since Java uses references, that same variable responseAttributeList will be updated. You can then use getAttributeAt(...) to access the Attribute Objects.
String sessionID = "sampleID";
ResourceContextDef rcd = //whatever it needs to be equal to
AttributeList requestAttributeList = new AttributeList();
AttributeList responseAttributeList = new AttributeList();
if(getSessionVariables(sessionId, rcd, requestAttributeList, responseAttributeList) == YES){
Attribute att = responseAttributeList.getAttributeAt(0);//or whatever index.
}
Remember to carefully read the API.
NOTE: This is just pseudo code. I have not tested this. However, this should be plenty enough to get you going where you need to.
Very new to web services (as you can tell from the Q) so i am pretty sure this is a basic question.
I am sending the request of to the server
ExecuteSQLQueryReq sqlParams = new ExecuteSQLQueryReq();
sqlParams.setSql(sqlState.getNoDevInDP("LIV_Phones_DP"));
and getting the response i expect:
ExecuteSQLQueryRes getSqlResult = axlPort.executeSQLQuery(sqlParams);
i can see all the data is there in the object from the eclipse debugging
but from the object "getSqlResult" i dont know how to pull the data out. The response is in the following format:
Any help would be great
Thanks
Alexis
EDIT:
Screen shot of "ExecuteSQLQueryRes". The only methods i see is to return a list of Objects, which i do and that the screenshot of the variables in eclipse you mention. Its the next step .... how to get from a generic Object the data out..
From the type signatures, I'd say you would invoke the service like so:
List<Object> rows = axlPort.executeSQLQuery(sqlParams)
.getReturn()
.getRow();
for(Object row : rows) {
Element rowElement = (Element) row;
// utilize DOM API
}
As far as I can tell from the information posted you're getting a List of Elements. In XML:
<row>?</row>
<row>?</row>
<row>?</row>
Since row is anyType nothing specific can be inferred about its structure. In the specific case, the first entry looks like this assuming a single child (text) node:
<row>339</row>
You can use the Java DOM APIs to access the data.
From the name onwards, this service looks like it just exposes the underlying database implementation. Consider adhering to stricter SOA principles if you have any influence over the service design.
I have a List in jsp scriptlet and I stored that list into session. That list contain very huge data.
like the following.....
110:ListTypeVasParam:51:null:null:9910101002-Test# :110::ListTypeVasParam::51::null::null::9911000002-Test#:110:TextTypeVasParam:50:text:null:null-null# :110::TextTypeVasParam::50::text::null::null-null#:111:ListTypeVasParam:54:null:null:99101000002-Test# :111::ListTypeVasParam::54::null::null::9910101000002-Test#:111:ListTypeVasParam:55:null:null:1-YU#2-Safaricom Kenya#3-Airtel# :111::ListTypeVasParam::55::null::null::1-YU#2-Safaricom Kenya#3-Airtel#:111:TextTypeVasParam:52:text:null:null-null# :111::TextTypeVasParam::52::text::null::null-null#:111:TextTypeVasParam:53:text:null:null-null# :111::TextTypeVasParam::53::text::null::null-null#:112:ListTypeVasParam:58:null:null:9910101000002-Test# :112::ListTypeVasParam::58::null::null::9910101000002-Test#:112:ListTypeVasParam:56:null:null:test1-test1# :112::ListTypeVasParam::56::null::null::test1-test1#:112:TextTypeVasParam:57:text:null:null-null# :112::TextTypeVasParam::57::text::null::null-null#:113:TextTypeVasParam:60:text:null:null-null# :113::TextTypeVasParam::60::text::null::null-null#:113:TextTypeVasParam:61:text:null:null-null# :113::TextTypeVasParam::61::text::null::null-null#:113:ListTypeVasParam:59:null:null:1-YU#2-Safaricom Kenya#3-Airtel# :113::ListTypeVasParam::59::null::null::1-YU#2-Safaricom Kenya#3-Airtel#:373:ListTypeVasParam:44:null:null:9910101000002-Test# :373::ListTypeVasParam::44::null::null::9910101000002-Test#:373:TextTypeVasParam:42:text:null:null-null# :373::TextTypeVasParam::42::text::null::null-null#:373:TextTypeVasParam:43:text:null:null-null# :373::TextTypeVasParam::43::text::null::null-null#:374:ListTypeVasParam:49:null:null:9910101000002-Test# :374::ListTypeVasParam::49::null::null::9910101000002-Test#:374:TextTypeVasParam:48:text:null:null-null# :374::TextTypeVasParam::48::text::null::null-null#:374:TextTypeVasParam:45:text:null:null-null# :374::TextTypeVasParam::45::text::null::null-null#:374:TextTypeVasParam:47:text:null:null-null# :374::TextTypeVasParam::47::text::null::null-null#:374:TextTypeVasParam:46:text:null:null-null# :374::TextTypeVasParam::46::text::null::null-null#:120:ListTypeVasParam:64:null:null:9910101000002-Test# :120::ListTypeVasParam::64::null::null::9910101000002-Test#:120:ListTypeVasParam:63:null:null:BESCOM-BESCOM# :120::ListTypeVasParam::63::null::null::BESCOM-BESCOM#:120:TextTypeVasParam:65:text:null:null-null# :120::TextTypeVasParam::65::text::null::null-null#:121:ListTypeVasParam:68:null:null:9910101000002-Test# :121::ListTypeVasParam::68::null::null::9910101000002-Test#:121:TextTypeVasParam:69:text:null:null-null# :121::TextTypeVasParam::69::text::null::null-null#:121:TextTypeVasParam:67:text:null:null-null# :121::TextTypeVasParam::67::text::null::null-null#:121:TextTypeVasParam:66:text:null:null-null# :121::TextTypeVasParam::66::text::null::null-null#:122:TextTypeVasParam:70:text:null:null-null# :122::TextTypeVasParam::70::text::null::null-null#:122:TextTypeVasParam:72:text:null:null-null# :122::TextTypeVasParam::72::text::null::null-null#:122:TextTypeVasParam:71:text:null:null-null# :122::TextTypeVasParam::71::text::null::null-null#:131:ListTypeVasParam:592:null:null:99101000002-Test# :131::ListTypeVasParam::592::null::null::9910101000002-Test#:131:ListTypeVasParam:4:null:null:USD-USD#GBP-GBP#INR-INR# :131::ListTypeVasParam::4::null::null::USD-USD#GBP-GBP#INR-INR#:133:TextTypeVasParam:92:text:null:null-null# :133::TextTypeVasParam::92::text::null::null-null#:134:TextTypeVasParam:91:text:null:null-null# :134::TextTypeVasParam::91::text::null::null-null#:67:TextTypeVasParam:2:password:null:null-null# :67::TextTypeVasParam::2::password::null::null-null#:67:TextTypeVasParam:3:password:null:null-null# :67::TextTypeVasParam::3::password::null::null-null#:67:TextTypeVasParam:1:password:null:null-null# :67::TextTypeVasParam::1::password::null::null-null#:138:TextTypeVasParam:5:text:null:null-null# :138::TextTypeVasParam::5::text::null::null-null#:138:TextTypeVasParam:6:text:null:null-null# :138::TextTypeVasParam::6::text::null::null-null#:103:ListTypeVasParam:15:null:null:9910101000002-Test# :103::ListTypeVasParam::15::null::null::9910101000002-Test#:103:ListTypeVasParam:14:null:null:25-25#50-50#75-75#100-100# :103::ListTypeVasParam::14::null::null::25-25#50-50#75-75#100-100#:104:ListTypeVasParam:17:null:null:9910101000002-Test# :104::ListTypeVasParam::17::null::null::9910101000002-Test#:104:TextTypeVasParam:18:text:null:null-null# :104::TextTypeVasParam::18::text::null::null-null#:104:TextTypeVasParam:19:text:null:null-null# :104::TextTypeVasParam::19::text::null::null-null#:2:ListTypeVasParam:9:null:null:9910101000002-Test# :2::ListTypeVasParam::9::null::null::9910101000002-Test#:2:ListTypeVasParam:8:null:null:Phone-Phone#SMS-SMS# :2::ListTypeVasParam::8::null::null::Phone-Phone#SMS-SMS#:3:ListTypeVasParam:10:null:null:9910101000002-Test# :3::ListTypeVasParam::10::null::null::9910101000002-Test#:3:ListTypeVasParam:11:null:null:Email-Email#Branch-Branch#Postal Address-Postal Address# :3::ListTypeVasParam::11::null::null::Email-Email#Branch-Branch#Postal Address-Postal Address#:3:TextTypeVasParam:12:text:null:null-null# :3::TextTypeVasParam::12::text::null::null-null#:3:TextTypeVasParam:13:text:null:null-null# :3::TextTypeVasParam::13::text::null::null-null#:105:ListTypeVasParam:87:null:null:9910101000002-Test# :105::ListTypeVasParam::87::null::null::9910101000002-Test#:105:ListTypeVasParam:86:null:null:LARGE.CREDIT-LARGE CREDIT#LARGE.DEBIT-LARGE DEBIT#MINIMUM.BALANCE-MINIMUM BALANCE# :105::ListTypeVasParam::86::null::null::LARGE.CREDIT-LARGE CREDIT#LARGE.DEBIT-LARGE DEBIT#MINIMUM.BALANCE-MINIMUM BALANCE#:105:TextTypeVasParam:88:text:null:null-null# :105::TextTypeVasParam::88::text::null::null-null#:106:ListTypeVasParam:90:null:null:9910101000002-Test# :106::ListTypeVasParam::90::null::null::9910101000002-Test#:106:ListTypeVasParam:89:null:null:LARGE.CREDIT-LARGE CREDIT#LARGE.DEBIT-LARGE DEBIT#MINIMUM.BALANCE-MINIMUM BALANCE# :106::ListTypeVasParam::89::null::null::LARGE.CREDIT-LARGE CREDIT#LARGE.DEBIT-LARGE DEBIT#MINIMUM.BALANCE-MINIMUM BALANCE#:107:ListTypeVasParam:21:null:null:9910101000002-Test# :107::ListTypeVasParam::21::null::null::9910101000002-Test#:107:TextTypeVasParam:22:text:null:null-null# :107::TextTypeVasParam::22::text::null::null-null#:107:ListTypeVasParam:20:null:null:1-Cheque(s) Lost#2-Cheque(s) Destroyed#3-Cheques Stolen#4-Bankers CHQ Lost\\Stolen# :107::ListTypeVasParam::20::null::null::1-Cheque(s) Lost#2-Cheque(s) Destroyed#3-Cheques Stolen#4-Bankers CHQ Lost\\Stolen#:108:TextTypeVasParam:16:text:null:null-null# :108::TextTypeVasParam::16::text::null::null-null#:116:ListTypeVasParam:74:null:null:9910101000002-Test# :116::ListTypeVasParam::74::null::null::9910101000002-Test#:116:TextTypeVasParam:75:text:null:null-null# :116::TextTypeVasParam::75::text::null::null-null#:116:TextTypeVasParam:76:text:null:null-null# :116::TextTypeVasParam::76::text::null::null-null#:6:ListTypeVasParam:29:null:null:9910101000002-Test# :6::ListTypeVasParam::29::null::null::9910101000002-Test#:6:ListTypeVasParam:26:null:null:Account Number-Account Number#Mobile Number-Mobile Number# :6::ListTypeVasParam::26::null::null::Account Number-Account Number#Mobile Number-Mobile Number#:6:TextTypeVasParam:27:text:null:null-null# :6::TextTypeVasParam::27::text::null::null-null#:6:TextTypeVasParam:28:text:null:null-null# :6::TextTypeVasParam::28::text::null::null-null#:7:ListTypeVasParam:30:null:null:9910101000002-Test# :7::ListTypeVasParam::30::null::null::9910101000002-Test#:7:TextTypeVasParam:33:text:null:null-null# :7::TextTypeVasParam::33::text::null::null-null#:7:TextTypeVasParam:31:text:null:null-null# :7::TextTypeVasParam::31::text::null::null-null#:7:TextTypeVasParam:34:text:null:null-null# :7::TextTypeVasParam::34::text::null::null-null#:7:TextTypeVasParam:32:text:null:null-null# :7::TextTypeVasParam::32::text::null::null-null#:7:TextTypeVasParam:591:text:null:null-null# :7::TextTypeVasParam::591::text::null::null-null#:8:TextTypeVasParam:38:text:null:null-null# :8::TextTypeVasParam::38::text::null::null-null#:8:ListTypeVasParam:40:null:null:Account Number-Account Number#Mobile Number-Mobile Number# :8::ListTypeVasParam::40::null::null::Account Number-Account Number#Mobile Number-Mobile Number#:8:TextTypeVasParam:39:text:null:null-null# :8::TextTypeVasParam::39::text::null::null-null#:9:ListTypeVasParam:41:null:null:testing1-testing1#testing-testing# :9::ListTypeVasParam::41::null::null::testing1-testing1#testing-testing#:10:ListTypeVasParam:37:null:null:9910101000002-Test# :10::ListTypeVasParam::37::null::null::9910101000002-Test#:10:ListTypeVasParam:36:null:null:testing1-testing1#testing-testing# :10::ListTypeVasParam::36::null::null::testing1-testing1#testing-testing#:10:TextTypeVasParam:35:text:null:null-null# :10::TextTypeVasParam::35::text::null::null-null#
When I accessing that list in javascript it doesn't allow that list. If I remove some data in the list then javascript allowed the list. I split the single list into multiple lists then also javascript doesn't allow the list.
Please help me how to get the list in javascript that contain huge data in string format ?
Thanks & Regards
A single session's (sessions are small files saved on hard disk) highest capacity is 4kb. You just can't store more than 4kb of data in a session. So in your case, your data is not inside the session because of it's size and that's why you can't access it.
Alternatively you can store the data on the server side (may be using any database) and generate and assign a unique identifier/key for each peace of data and save the key in the session.
Its not a good idea to store this much data in the session. You can use JSON to transfer this data to JavaScript. That is the best approach I think