From ca2bc0a304c737c55cfe4f294c979662b4e02ffa Mon Sep 17 00:00:00 2001 From: David Huynh Date: Tue, 27 Apr 2010 20:34:36 +0000 Subject: [PATCH] Fixed null pointer exception problem in HeuristicReconConfig when trying to use "recon" service. Made custom suggest widget rely on gridworks-helper acre app for fetching property suggestions. Made various property suggest in recon dialog use our custom suggest widget. git-svn-id: http://google-refine.googlecode.com/svn/trunk@557 7d457c2a-affb-35e4-300a-418c747d4874 --- .../model/recon/HeuristicReconConfig.java | 2 +- .../webapp/scripts/dialogs/recon-dialog.js | 4 +- .../webapp/scripts/util/custom-suggest.js | 120 +----------------- 3 files changed, 10 insertions(+), 116 deletions(-) diff --git a/src/main/java/com/metaweb/gridworks/model/recon/HeuristicReconConfig.java b/src/main/java/com/metaweb/gridworks/model/recon/HeuristicReconConfig.java index ad83d9867..4dbf14afb 100644 --- a/src/main/java/com/metaweb/gridworks/model/recon/HeuristicReconConfig.java +++ b/src/main/java/com/metaweb/gridworks/model/recon/HeuristicReconConfig.java @@ -156,7 +156,7 @@ public class HeuristicReconConfig extends ReconConfig { Cell cell2 = row.getCell(detailCellIndex); if (cell2 == null || !ExpressionUtils.isNonBlankData(cell2.value)) { int cellIndex = project.columnModel.getColumnByName(columnName).getCellIndex(); - if (cellIndex < row.contextRowSlots.length) { + if (row.contextRowSlots != null && cellIndex < row.contextRowSlots.length) { int contextRowIndex = row.contextRowSlots[cellIndex]; if (contextRowIndex >= 0 && contextRowIndex < project.rows.size()) { Row row2 = project.rows.get(contextRowIndex); diff --git a/src/main/webapp/scripts/dialogs/recon-dialog.js b/src/main/webapp/scripts/dialogs/recon-dialog.js index 2cb8751f8..4d0c838d9 100644 --- a/src/main/webapp/scripts/dialogs/recon-dialog.js +++ b/src/main/webapp/scripts/dialogs/recon-dialog.js @@ -181,7 +181,7 @@ ReconDialog.prototype._wireEvents = function() { var self = this; this._elmts.heuristicTypeInput - .suggest({ type : '/type/type' }) + .suggestT({ type : '/type/type' }) .bind("fb-select", function(e, data) { $('input[name="recon-dialog-type-choice"][value=""]').attr("checked", "true"); @@ -201,7 +201,7 @@ ReconDialog.prototype._wireEvents = function() { ReconDialog.prototype._rewirePropertySuggests = function(schema) { var inputs = $('input[name="recon-dialog-heuristic-property"]'); - inputs.suggest({ + inputs.unbind().suggestP({ type: '/type/property', schema: schema || "/common/topic" }).bind("fb-select", function(e, data) { diff --git a/src/main/webapp/scripts/util/custom-suggest.js b/src/main/webapp/scripts/util/custom-suggest.js index cf2522fe2..d56dedcf0 100644 --- a/src/main/webapp/scripts/util/custom-suggest.js +++ b/src/main/webapp/scripts/util/custom-suggest.js @@ -51,94 +51,24 @@ this.ac_xhr = null; } - if (val.charAt(0) == '/') { - this.request_mqlread(val, start); - } else { - this.request_relevance(val, start); - } - }, - - request_mqlread: function(val, start) { - var self = this; - var o = this.options; - - var query = [{ - "id" : val, - "name" : null, - "guid" : null, - "x:type" : "/type/property", - "/type/property/expected_type" : null - }]; - var data = { - query: JSON.stringify({ query: query }) - }; - - var baseUrl = "http://api.freebase.com/api/service/mqlread"; - var url = baseUrl + "?" + $.param(data), - - cached = $.suggest.cache[url]; - if (cached) { - this.response(cached, start ? start : -1, true); - return; - } - - clearTimeout(this.request.timeout); - this.request.timeout = - setTimeout(function() { - self.ac_xhr = $.ajax({ - url: baseUrl, - data: data, - beforeSend: function() { - var calls = self.input.data("request.count.suggest") || 0; - if (!calls) { - self.trackEvent(self.name, "start_session"); - } - calls += 1; - self.trackEvent(self.name, "request", "count", calls); - self.input.data("request.count.suggest", calls); - }, - success: function(r) { - r.prefix = val; // we need this so that the rest of suggest wouldn't error out - if (!("result" in r)) { - r.result = []; - } - self.response(r, start ? start : -1); - }, - error: function(xhr) { - self.trackEvent(self.name, "request", "error", {url:this.url, response: xhr ? xhr.responseText : ''}); - }, - complete: function(xhr) { - if (xhr) { - self.trackEvent(self.name, "request", "tid", xhr.getResponseHeader("X-Metaweb-TID")); - } - }, - dataType: "jsonp", - cache: true - }); - }, o.xhr_delay); - }, - - request_relevance: function(val, start) { var self = this; var o = this.options; var data = { - query: val, - mql_output: JSON.stringify([{ - "id" : null, - "name" : null, - "/type/property/expected_type" : { "id" : null, "name" : null } - }]) + query: val }; if (start) { data.start = start; } + if ("schema" in o) { + data.schema = o.schema; + } $.extend(data, o.ac_param); - $.extend(data, { limit: 100 }); - var baseUrl = "http://api.freebase.com/api/service/search"; + var baseUrl = "http://gridworks-helper.freebaseapps.com/suggest_property"; var url = baseUrl + "?" + $.param(data), + cached = $.suggest.cache[url]; if (cached) { this.response(cached, start ? start : -1, true); @@ -161,43 +91,7 @@ self.input.data("request.count.suggest", calls); }, success: function(data) { - data.prefix = val; // we need this so that the rest of suggest wouldn't error out - - if ("schema" in o) { - var type = o.schema; - var apply = function() { - resortByType(data, type); - - $.suggest.cache[url] = data; - self.response(data, start ? start : -1); - }; - if (type in typeToIncludedTypes) { - apply(); - } else { - var query = { - query: { - "id" : type, - "/freebase/type_hints/included_types": [] - } - }; - $.getJSON( - "http://api.freebase.com/api/service/mqlread?" + $.param({ query: JSON.stringify(query) }) + "&callback=?", - null, - function(d) { - var types = []; - if ("result" in d) { - types = d.result["/freebase/type_hints/included_types"]; - } - typeToIncludedTypes[type] = types; - - apply(); - }, - "jsonp" - ); - } - } else { - self.response(data, start ? start : -1); - } + self.response(data, start ? start : -1); }, error: function(xhr) { self.trackEvent(self.name, "request", "error", {url:this.url, response: xhr ? xhr.responseText : ''});