I have this java script code for ajax and I'm having trouble of get response.
xmlhttp.status always become 0. I have repeatCallHr Servlet and getting parameters from jsp page as follows.
function loadResults() {
var tt = document.getElementById("StartDate");
alert(tt);
if (xmlhttp) {
var query = "generateResults?name="
+ document.getElementById("name").value
+"&startDate="+document.getElementById("StartDate").value
+"&startTime="+document.getElementById("StartTime").value;
xmlhttp.open("GET", query, true);
xmlhttp.onreadystatechange = loadStallsResponse;
xmlhttp.send(null);
} else {
alert("Browser not supported!");
}}
function loadStallsResponse() {
alert("come here");
alert(xmlhttp.readyState);
if (xmlhttp.readyState == 4) {
alert("status is :"+xmlhttp.status);
if (xmlhttp.status == 200) {
resultList = [];
if (xmlhttp.responseText.indexOf("Error") == -1) {
alert("come to inside of status::")
console.log(xmlhttp.responseText);
stallList = $.parseJSON(xmlhttp.responseText);
populateStallData();
} else {
alert(xmlhttp.responseText);
}
} else {
alert("Error in loading salesman data");
}
}}
function populateStallData() {
var table = "<tr><th>Date</th><th>Time</th><th>Skill</th><th>Total Call</th><th>Unique Calls</th><th>Repeat Calls</th></tr>";
for (var i = 0; i < resultList.length; i++) {
table += "</td><td width='140'>"
+ resultList[i].date
+ "</td><td width='140'>"
+ resultList[i].time
+ "</td><td width='140'>"
+ resultList[i].skill
+ "</td><td width='140'><a style='color: -webkit-link; text-decoration: underline; cursor: auto;' href='http://"
+ resultList[i].totalCall
+ "</td><td width='140'>"
+ resultList[i].uniqueCall
+ "</td><td width='140'>"
+ resultList[i].repeatCall
+ "</td></tr>";
}
document.getElementById("ResultTable").innerHTML = table;}
In back end it takes more than 5 minutes to query the sql statement so that xmlhttp.status return as 0 (I guess, but i'm not sure). How can I delay the xmlhttp response time until I generate the results in back end?
Related
I've written a method to read json and generate data based on different combination.
For example lets say I've 3 json parameter and i wanna pass different permutation of json data.
So combination would be :
1 - F,T,T
2 - T,F,T
3 - T,T,F
4 - T,T,T
I used negativeCaseList to get false data and postitiveCaseList to get true data.
My task is to optimize this code to make it more readable.
Any suggestion is highly appreciated.
for (int i = 0; i < negativeCaseList.size(); i++) {
if (!negativeCaseList.get(i).isEmpty()) {
ArrayList<?> negativeDataAsList = (ArrayList<?>) negativeCaseList.get(i);
for (int j = 0; j < negativeDataAsList.size(); j++) {
ParameterData negativeParameterData = (ParameterData) negativeDataAsList.get(j);
for (int k = 0; k < postitiveCaseList.size(); k++) {
ArrayList<?> positiveDataAsList = (ArrayList<?>) postitiveCaseList.get(k);
for (int l = 0; l < positiveDataAsList.size(); l++) {
ParameterData positiveParameterData = (ParameterData) positiveDataAsList.get(l);
if (Utility.validateString(negativeParameterData.getParameterName())) {
if (!negativeParameterData.getParameterName().equals(positiveParameterData.getParameterName())) {
if (!positiveParameterData.parameterType.startsWith("System")) {
dictionary.put(positiveParameterData.getParameterName(), positiveParameterData.getValue());
} else {
dictionary.put(positiveParameterData.getParameterName(), positiveParameterData.getValue());
}
paramName = positiveParameterData.getParameterName() + "," + paramName;
if (Utility.hasHTMLTags(positiveParameterData.getValue().toString())) {
paramValue = ("<xmp style='padding:0px;margin:0px;white-space:nowrap'>" + positiveParameterData.getValue().toString() + "</xmp>") + "," + paramValue;
} else {
paramValue = positiveParameterData.getValue() + "," + paramValue;
}
} else {
dictionary.put(negativeParameterData.getParameterName(), negativeParameterData.getValue());
paramName = negativeParameterData.getParameterName() + "," + paramName;
if (Utility.hasHTMLTags(negativeParameterData.getValue().toString())) {
paramValue = ("<xmp style='padding:0px;margin:0px;white-space:nowrap'>" + negativeParameterData.getValue().toString() + "</xmp>") + "," + paramValue;
} else {
paramValue = negativeParameterData.getValue() + "," + paramValue;
}
}
} else {
listofParameter = negativeParameterData.getValue();
if (Utility.hasHTMLTags(negativeParameterData.getValue().toString())) {
paramValue = ("<xmp style='padding:0px;margin:0px;white-space:nowrap'>" + negativeParameterData.getValue().toString() + "</xmp>") + "," + paramValue;
} else {
paramValue = negativeParameterData.getValue() + "," + paramValue;
}
}
}
}
//json ="";
if (!dictionary.isEmpty()) {
json = ParameterTransform.ObjectToString(dictionary);
} else {
json = ParameterTransform.ObjectToString(listofParameter);
}
preData.putAll(Utils.fillTestDetailsInPreData(requestRule));
if (requestRule.getiRegistrationNo()) {
JSONObject stringToJson = new JSONObject(json);
json = securityObject.buildMainJson("10401", "f41f9ac6-1090-4851-bc7a-4a2355dd10c4",
stringToJson);
}
jsons.add(json);
app_logs.info("Json " + jsons);
//reportData.add(json+"|"+paramName+"|"+paramValue);
if (Utility.hasHTMLTags(json)) {
reportData.add("<xmp style='padding:0px;margin:0px;white-space:nowrap'>" + json + "</xmp>");
} else {
reportData.add(json);
}
pName.add(paramName.toString());
pValue.add(paramValue.toString());
app_logs.info("data " + reportData);
//app_logs.info("pName : " + pName.toString());
//app_logs.info("pValue : " + pValue.toString());
paramName = "";
paramValue = "";
}
}
}
I want to convert dataframe to Array of Json using Java and Spark version 1.6, for which am converting the data from
Dataframe -> Json -> RDD -> Array
where the data looks like this.
[
{
"prtdy_pgm_x":"P818_C",
"prtdy_pgm_x":"P818",
"prtdy_attr_c":"Cost",
"prtdy_integer_r":0,
"prtdy_cds_d":"prxm",
"prtdy_created_s":"2018-05-12 04:12:19.0",
"prtdy_created_by_c":"brq",
"prtdy_create_proc_x":"w_pprtdy_security_t",
"snapshot_d":"2018-05-12-000018"
},
{
"prtdy_pgm_x":"P818_I",
"prtdy_pgm_x":"P818",
"prtdy_attr_c":"Tooling",
"prtdy_integer_r":0,
"prtdy_cds_d":"prxm",
"prtdy_created_s":"2018-05-12 04:12:20.0",
"prtdy_created_by_c":"brq",
"prtdy_create_proc_x":"w_pprtdy_security_t",
"snapshot_d":"2018-05-12-000018"
},
{
"prtdy_pgm_x":"P818_W",
"prtdy_pgm_x":"P818",
"prtdy_attr_c":"Weight",
"prtdy_integer_r":0,
"prtdy_cds_d":"prxm",
"prtdy_created_s":"2018-05-12 04:12:20.0",
"prtdy_created_by_c":"brq",
"prtdy_create_proc_x":"w_pprtdy_security_t",
"snapshot_d":"2018-05-12-000018"
},
......
]
so I wrote my code something like this.
if(cmnTableNames != null && cmnTableNames.length > 0)
{
for(int i=0; i < cmnTableNames.length; i++)
{
String cmnTableName = cmnTableNames[i];
DataFrame cmnTableContent = null;
if(cmnTableName.contains("PTR_security_t"))
{
cmnTableContent = hiveContext.sql("SELECT * FROM " + cmnTableName + " where fbrn04_snapshot_d = '" + snapshotId + "'");
}
else
{
cmnTableContent = hiveContext.sql("SELECT * FROM " + cmnTableName);
}
String cmnTable = cmnTableName.substring(cmnTableName.lastIndexOf(".") + 1);
if (cmnTableContent.count() > 0)
{
String cmnStgTblDir = hdfsPath + "/staging/" + rptName + "/common/" + cmnTable;
JavaRDD<String> cmnTblCntJson = cmnTableContent.toJSON().toJavaRDD();
String result = cmnTblCntJson.reduce((ob1, ob2) -> (String)ob1+","+(String)ob2); //This Part, takes more time than usual contains large set of data.
String output = "["+result+"]";
ArrayList<String> outputList = new ArrayList<String>();
outputList.add(output);
JavaRDD<String> finalOutputRDD = sc.parallelize(outputList);
String cmnStgMrgdDir = cmnStgTblDir + "/mergedfile";
if(dfs.exists(new Path(cmnStgTblDir + "/mergedfile"))) dfs.delete(new Path(cmnStgTblDir + "/mergedfile"), true);
finalOutputRDD.coalesce(1).saveAsTextFile(cmnStgMrgdDir, GzipCodec.class);
fileStatus = dfs.getFileStatus(new Path(cmnStgMrgdDir + "/part-00000.gz"));
dfs.setPermission(fileStatus.getPath(),FsPermission.createImmutable((short) 0770));
dfs.rename(new Path(cmnStgMrgdDir + "/part-00000.gz"), new Path(CommonPath + "/" + cmnTable + ".json.gz"));
}
else
{
System.out.println("There are no records in " + cmnTableName);
}
}
}
else
{
System.out.println("The common table lists are null.");
}
sc.stop();
but while reduce function is applied it's taking more time
JavaRDD<String> cmnTblCntJson = cmnTableContent.toJSON().toJavaRDD();
String result = cmnTblCntJson.reduce((ob1, ob2) -> (String)ob1+","+(String)ob2); //This Part, takes more time than usual contains large set of data.
the table with the partition "PTR_security_t" is huge and takes a lot of time compared to other tables which don't have partitions (40-50 mins odd for 588kb)
I Tried Applying Lambda but i ended up with Task not serializable error. Check the code below.
if(cmnTableNames != null && cmnTableNames.length > 0)
{
List<String> commonTableList = Arrays.asList(cmnTableNames);
DataFrame commonTableDF = sqc.createDataset(commonTableList,Encoders.STRING()).toDF();
commonTableDF.toJavaRDD().foreach(cmnTableNameRDD -> {
DataFrame cmnTableContent = null;
String cmnTableName = cmnTableNameRDD.mkString();
if(cmnTableName.contains("PTR_security_t"))
{
cmnTableContent = hiveContext.sql("SELECT * FROM " + cmnTableName + " where fbrn04_snapshot_d = '" + snapshotId + "'");
}
else
{
cmnTableContent = hiveContext.sql("SELECT * FROM " + cmnTableName);
}
String cmnTable = cmnTableName.substring(cmnTableName.lastIndexOf(".") + 1);
if (cmnTableContent.count() > 0)
{
String cmnStgTblDir = hdfsPath + "/staging/" + rptName + "/common/" + cmnTable;
JavaRDD<String> cmnTblCntJson = cmnTableContent.toJSON().toJavaRDD();
String result = cmnTblCntJson.reduce((ob1, ob2) -> (String)ob1+","+(String)ob2);
String output = "["+result+"]";
ArrayList<String> outputList = new ArrayList<String>();
outputList.add(output);
JavaRDD<String> finalOutputRDD = sc.parallelize(outputList);
String cmnStgMrgdDir = cmnStgTblDir + "/mergedfile";
if(dfs.exists(new Path(cmnStgTblDir + "/mergedfile"))) dfs.delete(new Path(cmnStgTblDir + "/mergedfile"), true);
finalOutputRDD.coalesce(1).saveAsTextFile(cmnStgMrgdDir, GzipCodec.class);
fileStatus = dfs.getFileStatus(new Path(cmnStgMrgdDir + "/part-00000.gz"));
dfs.setPermission(fileStatus.getPath(),FsPermission.createImmutable((short) 0770));
dfs.rename(new Path(cmnStgMrgdDir + "/part-00000.gz"), new Path(CommonPath + "/" + cmnTable + ".json.gz"));
}
else
{
System.out.println("There are no records in " + cmnTableName);
}
});
}
else
{
System.out.println("The common table lists are null.");
}
sc.stop();
is there any efficient way where i can enhance my Performance ?
I have a special need in Alfresco, I'm unfortunately new in using this product.
Actually My intention is to show, in the workflow, only documents whose the coordinator is the logged on user and which are not in active workflows.
Any idea please :)
I'm back with a solution even if I'm not sure if it's the best. Any way that solved my problem.
I modified the method ObjectRenderer_renderCellAdd of object-finder.js to check if the user is the document coordinator and if there is no other active workflow linked to the document.
Instead of :
elCell.innerHTML = '<a id="' + containerId + '" href="#" ' + style + ' class="add-item add-' + scope.eventGroup + '" title="' + scope.msg("form.control.object-picker.add-item") + '" tabindex="0"><span class="addIcon"> </span></a>';
I put :
var showSelectLink = true;
if(oRecord.getData("type") == "cm:content"){
showSelectLink = false;
//Checking if the document is already in an other active worflow
var xmlHttp = new XMLHttpRequest();
var url = window.location.href;
var arr = url.split("/");
xmlHttp.open( "GET", (arr[0] + "//" + arr[2]).concat("/alfresco/s/api/node/").concat((oRecord.getData("nodeRef")).replace(":/","")).concat("/workflow-instances"), false );
xmlHttp.send( null );
if(json.data.length == 0){
//Checking if the logged on user is the document coordinator
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", (arr[0] + "//" + arr[2]).concat("/alfresco/s/slingshot/doclib/permissions/").concat((oRecord.getData("nodeRef")).replace(":/","")), false );
xmlHttp.send( null );
var json = JSON.parse(xmlHttp.responseText);
var hasDirectPermission = false;
//Direct permission
if(json.direct.length != 0){
var permission;
for(var index = 0; index < json.direct.length; index++){
permission = json.direct[index];
if(permission.role == "Coordinator"){
showSelectLink = true;
hasDirectPermission = true;
break;
}
}
}
//Inherited Permission
if(!hasDirectPermission && json.inherited.length != 0){
var permission;
for(var index = 0; index < json.inherited.length; index++){
permission = json.inherited[index];
if(permission.role == "Coordinator"){
showSelectLink = true;
break;
}
}
}
}
}
if(showSelectLink){
elCell.innerHTML = '<a id="' + containerId + '" href="#" ' + style + ' class="add-item add-' + scope.eventGroup + '" title="' + scope.msg("form.control.object-picker.add-item") + '" tabindex="0"><span class="addIcon"> </span></a>';
}
Regards,
I have successfully created a:
Gridx using JSONStore
Server-side paging using 'Range : items=0-99' header
Server-side sorting using 'sort(+name)'
... but after much effort and searching I haven't been able to setup the Filterbar module to perform Server-side filtering.
I have used 'filterSetupQuery' to pull information out of JSON (on the client) and append to the get URL for very basic filters, but with complicated filters it seems to make more sense to process the JSON in the Java based controller on the server.
What would this Java class and FlexJson deserializer even look like?
Does someone have a reference implementation of Server-side filtering, or even an example to show how to deserialize this object in Java?
Here is a simple JSON object that is sent back to the controller:
{ "op":"and",
"data":[{ "op":"or",
"data":[{"op":"contain","data":[{"op":"string","data":"1","isCol":true},
{"op":"string","data":"john"}]},
{"op":"contain","data":[{"op":"string","data":"2","isCol":true},
{"op":"string","data":"john"}]},
{"op":"contain","data":[{"op":"string","data":"3","isCol":true},
{"op":"string","data":"john"}]},
{"op":"contain","data":[{"op":"string","data":"4","isCol":true},
{"op":"string","data":"john"}]}
]}]}
Any help is greatly appreciated!
Thank you
Chris
You can check gridx source code.. Under \tests\test_grid_filter_serverside.html
filterSetupFilterQuery: function(expr){
var toExpr = function(expr){
if(!expr){ return ""; }
if(typeof expr.data != "object"){
if(expr.isCol){
return "column(\"" + expr.data + "\")";
}
return "\"" + expr.data + "\"";
}else{
var exprs = [];
for(var i in expr.data){
exprs.push(toExpr(expr.data[i]));
}
var op = expr.op;
if(expr.op == "and"){
op = "logicand";
}
if(expr.op == "or"){
op = "logicor";
}
return op + "(" + exprs.join(",") + ")";
}
};
console.log("expr is: ", expr);
var newExpr = toExpr(expr);
if(newExpr){ newExpr += ";"}
console.log("expr is: ", newExpr);
return {query: newExpr};
},
, the function above outputs something like ..
logicor(logicor(contain(column("1"),"drawal"),contain(column("2"),"drawal"),contain(column("3"),"drawal"),contain(column("4"),"drawal"),contain(column("5"),"drawal"),contain(column("6"),"drawal"),contain(column("7"),"drawal")));
I was able to change the function to output sql as below
var toExpr = function(expr) {
if (!expr) {
return "";
}
if ( typeof expr.data != "object") {
if (expr.isCol) {
return cols.item(expr.data);
// return "column(\"" + expr.data + "\")";
}
return "\"" + expr.data + "\"";
} else {
var exprs = [];
for (var i in expr.data) {
exprs.push(toExpr(expr.data[i]));
}
var op = expr.op;
if (op == 'not') {
return "(" + exprs[0].replace(/=/, '<>').replace(/like/, ' not like ') + ")";
}
if (op == 'contain') {
return "(" + exprs[0] + ' like ' + exprs[1].replace(/^"/, '"%').replace(/"$/, '%"') + ")";
}
if (op == 'startWith') {
return "(" + exprs[0] + ' like ' + exprs[1].replace(/^"/, '"%') + ")";
}
if (op == 'endWith') {
return "(" + exprs[0] + ' like ' + exprs[1].replace(/"$/, '"%') + ")";
}
return "(" + exprs.join(" " + op.replace(/equal/, '=') + " ") + ")";
}
};
var newExpr = toExpr(expr);
if (newExpr) {
newExpr += ";";
}
console.log("expr is: ", newExpr);
I need to convert the following Javascript pseudo-class to Java code. I'm googling information about XMLHttpRequest (or equivalent) in Java and i'm confused:
function conexionSOAP(url, uri) {
// Constructor
this.uri = 'urn:' + uri;
this.url = url;
this.cabeceraXML = '<?xml version="1.0" encoding="UTF-8"?>'
+ '<soap:Envelope '
+ 'soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" '
+ 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" '
+ 'xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" '
+ 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
+ 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
+ '<soap:Body>' + '<';
this.sessionKey = null;
// Metodos
var self = this;
(...)
this.llamar_metodo = function(metodo, argumentos, http, loadCallback,
errorCallback) {
// Función que transforma las llamadas a métodos en requests XML
var XMLmsg = self.cabeceraXML + metodo + ' xmlns="' + self.uri + '"';
if (argumentos == null) {
XMLmsg = XMLmsg + ' xsi:nil="true" />';
} else {
var i, I;
XMLmsg = XMLmsg + '>';
for (i = 0, I = argumentos.length; i < I; i++) {
var tipo = typeof argumentos[i];
if (tipo == "number") {
if (argumentos[i] % 1) {
tipo = "float";
} else {
tipo = "int";
}
}
XMLmsg = XMLmsg + '<c-gensym' + (2 * (i + 2))
+ ' xsi:type="xsd:' + tipo + '">' + argumentos[i]
+ '</c-gensym' + (2 * (i + 2)) + '>';
}
XMLmsg = XMLmsg + '</' + metodo + '>';
}
XMLmsg = XMLmsg + '</soap:Body>' + '</soap:Envelope>';
// Una vez preparado el XML preparamos el HttpRequest
http.open("POST", self.url, true);
http.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
http.setRequestHeader('Origin', 'ParkingClientJS');
http
.setRequestHeader('SOAPAction', '"' + self.uri + '#' + metodo
+ '"');
http.timeout = 15000;
http.onload = loadCallback;
http.onerror = errorCallback;
http.ontimeout = errorCallback;
http.send(XMLmsg);
};
function readyState(metodo, http) {
var respuesta = null;
if (http.readyState == 4) {
if (http.status == 200) {
var responseTag = http.responseXML.getElementsByTagName(metodo
+ 'Response');
if (responseTag) {
if (responseTag[0].childNodes.length <= 1) {
respuesta = responseTag[0].childNodes[0].textContent;
} else {
var i, I;
respuesta = [];
for (i = 0, I = responseTag[0].childNodes.length; i < I; i++) {
respuesta
.push(responseTag[0].childNodes[i].textContent);
}
}
}
} else {
respuesta = "--EE--";
}
}
return respuesta;
}
function error_timeOut(http) {
var respuesta = "--EE--";
http.abort();
return respuesta;
}
}
Specifically, How must I implement the method llamar_metodo? Notice that the XMLHttpRequest is passed to this method (http parameter) and the request must be async. There are auxiliar methods like this:
function(method, [param1, param2, ...], responseCallback){
var http = new XMLHttpRequest();
self.llamar_metodo(method, [ param1, param2, ... ], http, function() {
var response = readyState(metodo, http);
responseCallback(response)
}, function() {
var respuesta = error_timeOut(http);
responseCallback(response)
});
}
Finally, the implementation must be android-compatible.
Thanks for your help I'm really confused with the Http stuff.
Sorry for my english