Add checkbox to disable caching
This commit is contained in:
parent
32c232c2d6
commit
22124ac57e
@ -54,6 +54,7 @@ public class AddColumnByFetchingURLsCommand extends EngineDependentCommand {
|
|||||||
int columnInsertIndex = Integer.parseInt(request.getParameter("columnInsertIndex"));
|
int columnInsertIndex = Integer.parseInt(request.getParameter("columnInsertIndex"));
|
||||||
int delay = Integer.parseInt(request.getParameter("delay"));
|
int delay = Integer.parseInt(request.getParameter("delay"));
|
||||||
String onError = request.getParameter("onError");
|
String onError = request.getParameter("onError");
|
||||||
|
boolean cacheResponses = Boolean.parseBoolean(request.getParameter("cacheResponses"));
|
||||||
|
|
||||||
return new ColumnAdditionByFetchingURLsOperation(
|
return new ColumnAdditionByFetchingURLsOperation(
|
||||||
engineConfig,
|
engineConfig,
|
||||||
@ -62,7 +63,8 @@ public class AddColumnByFetchingURLsCommand extends EngineDependentCommand {
|
|||||||
TextTransformOperation.stringToOnError(onError),
|
TextTransformOperation.stringToOnError(onError),
|
||||||
newColumnName,
|
newColumnName,
|
||||||
columnInsertIndex,
|
columnInsertIndex,
|
||||||
delay
|
delay,
|
||||||
|
cacheResponses
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
|
|||||||
final protected String _newColumnName;
|
final protected String _newColumnName;
|
||||||
final protected int _columnInsertIndex;
|
final protected int _columnInsertIndex;
|
||||||
final protected int _delay;
|
final protected int _delay;
|
||||||
|
final protected boolean _cacheResponses;
|
||||||
|
|
||||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
||||||
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
||||||
@ -96,7 +97,8 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
|
|||||||
TextTransformOperation.stringToOnError(obj.getString("onError")),
|
TextTransformOperation.stringToOnError(obj.getString("onError")),
|
||||||
obj.getString("newColumnName"),
|
obj.getString("newColumnName"),
|
||||||
obj.getInt("columnInsertIndex"),
|
obj.getInt("columnInsertIndex"),
|
||||||
obj.getInt("delay")
|
obj.getInt("delay"),
|
||||||
|
obj.optBoolean("cacheResponses", false) // false for retro-compatibility
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +109,8 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
|
|||||||
OnError onError,
|
OnError onError,
|
||||||
String newColumnName,
|
String newColumnName,
|
||||||
int columnInsertIndex,
|
int columnInsertIndex,
|
||||||
int delay
|
int delay,
|
||||||
|
boolean cacheResponses
|
||||||
) {
|
) {
|
||||||
super(engineConfig);
|
super(engineConfig);
|
||||||
|
|
||||||
@ -119,6 +122,7 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
|
|||||||
_columnInsertIndex = columnInsertIndex;
|
_columnInsertIndex = columnInsertIndex;
|
||||||
|
|
||||||
_delay = delay;
|
_delay = delay;
|
||||||
|
_cacheResponses = cacheResponses;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -135,6 +139,7 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
|
|||||||
writer.key("urlExpression"); writer.value(_urlExpression);
|
writer.key("urlExpression"); writer.value(_urlExpression);
|
||||||
writer.key("onError"); writer.value(TextTransformOperation.onErrorToString(_onError));
|
writer.key("onError"); writer.value(TextTransformOperation.onErrorToString(_onError));
|
||||||
writer.key("delay"); writer.value(_delay);
|
writer.key("delay"); writer.value(_delay);
|
||||||
|
writer.key("cacheResponses"); writer.value(_cacheResponses);
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +170,8 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
|
|||||||
project,
|
project,
|
||||||
engine,
|
engine,
|
||||||
eval,
|
eval,
|
||||||
getBriefDescription(null)
|
getBriefDescription(null),
|
||||||
|
_cacheResponses
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,13 +187,16 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
|
|||||||
Project project,
|
Project project,
|
||||||
Engine engine,
|
Engine engine,
|
||||||
Evaluable eval,
|
Evaluable eval,
|
||||||
String description
|
String description,
|
||||||
|
boolean cacheResponses
|
||||||
) throws JSONException {
|
) throws JSONException {
|
||||||
super(description);
|
super(description);
|
||||||
_project = project;
|
_project = project;
|
||||||
_engine = engine;
|
_engine = engine;
|
||||||
_eval = eval;
|
_eval = eval;
|
||||||
_historyEntryID = HistoryEntry.allocateID();
|
_historyEntryID = HistoryEntry.allocateID();
|
||||||
|
_urlCache = null;
|
||||||
|
if (cacheResponses) {
|
||||||
_urlCache = CacheBuilder.newBuilder()
|
_urlCache = CacheBuilder.newBuilder()
|
||||||
.maximumSize(2048)
|
.maximumSize(2048)
|
||||||
.expireAfterWrite(10, TimeUnit.MINUTES)
|
.expireAfterWrite(10, TimeUnit.MINUTES)
|
||||||
@ -211,6 +220,7 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
@ -250,8 +260,20 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
|
|||||||
List<CellAtRow> responseBodies = new ArrayList<CellAtRow>(urls.size());
|
List<CellAtRow> responseBodies = new ArrayList<CellAtRow>(urls.size());
|
||||||
for (int i = 0; i < urls.size(); i++) {
|
for (int i = 0; i < urls.size(); i++) {
|
||||||
CellAtRow urlData = urls.get(i);
|
CellAtRow urlData = urls.get(i);
|
||||||
CellAtRow cellAtRow = cachedFetch(urlData);
|
String urlString = urlData.cell.value.toString();
|
||||||
if (cellAtRow != null) {
|
|
||||||
|
Serializable response = null;
|
||||||
|
if (_urlCache != null) {
|
||||||
|
response = cachedFetch(urlString);
|
||||||
|
} else {
|
||||||
|
response = fetch(urlString);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response != null) {
|
||||||
|
CellAtRow cellAtRow = new CellAtRow(
|
||||||
|
urlData.row,
|
||||||
|
new Cell(response, null));
|
||||||
|
|
||||||
responseBodies.add(cellAtRow);
|
responseBodies.add(cellAtRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,22 +301,13 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CellAtRow cachedFetch(CellAtRow urlData) {
|
Serializable cachedFetch(String urlString) {
|
||||||
String urlString = urlData.cell.value.toString();
|
|
||||||
|
|
||||||
Serializable cellResult = null;
|
|
||||||
try {
|
try {
|
||||||
cellResult = _urlCache.get(urlString);
|
return _urlCache.get(urlString);
|
||||||
} catch(ExecutionException e) {
|
} catch(ExecutionException e) {
|
||||||
}
|
|
||||||
|
|
||||||
if (cellResult != null) {
|
|
||||||
return new CellAtRow(
|
|
||||||
urlData.row,
|
|
||||||
new Cell(cellResult, null));
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Serializable fetch(String urlString) {
|
Serializable fetch(String urlString) {
|
||||||
URL url = null;
|
URL url = null;
|
||||||
|
@ -134,7 +134,8 @@ public class UrlFetchingTests extends RefineTest {
|
|||||||
OnError.SetToBlank,
|
OnError.SetToBlank,
|
||||||
"rand",
|
"rand",
|
||||||
1,
|
1,
|
||||||
500);
|
500,
|
||||||
|
true);
|
||||||
ProcessManager pm = project.getProcessManager();
|
ProcessManager pm = project.getProcessManager();
|
||||||
Process process = op.createProcess(project, options);
|
Process process = op.createProcess(project, options);
|
||||||
process.startPerforming(pm);
|
process.startPerforming(pm);
|
||||||
|
@ -510,6 +510,7 @@
|
|||||||
"on-error": "On error",
|
"on-error": "On error",
|
||||||
"set-blank": "set to blank",
|
"set-blank": "set to blank",
|
||||||
"store-err": "store error",
|
"store-err": "store error",
|
||||||
|
"cache-responses": "Cache responses",
|
||||||
"copy-val": "copy value from original column",
|
"copy-val": "copy value from original column",
|
||||||
"warning-col-name": "You must enter a column name.",
|
"warning-col-name": "You must enter a column name.",
|
||||||
"add-col-fetch": "Add column by fetching URLs based on column",
|
"add-col-fetch": "Add column by fetching URLs based on column",
|
||||||
|
@ -510,6 +510,7 @@
|
|||||||
"on-error": "On error",
|
"on-error": "On error",
|
||||||
"set-blank": "set to blank",
|
"set-blank": "set to blank",
|
||||||
"store-err": "store error",
|
"store-err": "store error",
|
||||||
|
"cache-responses": "Cache responses",
|
||||||
"copy-val": "copy value from original column",
|
"copy-val": "copy value from original column",
|
||||||
"warning-col-name": "You must enter a column name.",
|
"warning-col-name": "You must enter a column name.",
|
||||||
"add-col-fetch": "Add column by fetching URLs based on column",
|
"add-col-fetch": "Add column by fetching URLs based on column",
|
||||||
|
@ -510,6 +510,7 @@
|
|||||||
"on-error": "En cas d’erreur",
|
"on-error": "En cas d’erreur",
|
||||||
"set-blank": "vider la cellule",
|
"set-blank": "vider la cellule",
|
||||||
"store-err": "conserver l’erreur",
|
"store-err": "conserver l’erreur",
|
||||||
|
"cache-responses": "Mettre les réponses en cache",
|
||||||
"copy-val": "copier la valeur depuis la colonne originale",
|
"copy-val": "copier la valeur depuis la colonne originale",
|
||||||
"warning-col-name": "Vous devez indiquer un nom de colonne.",
|
"warning-col-name": "Vous devez indiquer un nom de colonne.",
|
||||||
"add-col-fetch": "Ajouter une colonne en moissonnant les données depuis les URL d’une colonne",
|
"add-col-fetch": "Ajouter une colonne en moissonnant les données depuis les URL d’une colonne",
|
||||||
|
@ -12,11 +12,14 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td width="1%" style="white-space: pre;" bind="or_views_onErr"></td>
|
<td width="1%" style="white-space: pre;" bind="or_views_onErr"></td>
|
||||||
<td colspan="3">
|
<td>
|
||||||
<input type="radio" name="dialog-onerror-choice" value="set-to-blank" checked id="$add-column-error-set-to-blank"/>
|
<input type="radio" name="dialog-onerror-choice" value="set-to-blank" checked id="$add-column-error-set-to-blank"/>
|
||||||
<label for="$add-column-error-set-to-blank" bind="or_views_setBlank"></label>
|
<label for="$add-column-error-set-to-blank" bind="or_views_setBlank"></label>
|
||||||
<input type="radio" name="dialog-onerror-choice" value="store-error" id="$add-column-error-store-error" />
|
<input type="radio" name="dialog-onerror-choice" value="store-error" id="$add-column-error-store-error" />
|
||||||
<label for="$add-column-error-store-error" bind="or_views_storeErr"></label></td>
|
<label for="$add-column-error-store-error" bind="or_views_storeErr"></label></td>
|
||||||
|
<td colspan="2">
|
||||||
|
<input type="checkbox" name="dialog-cache-responses" id="$add-column-cache-responses" checked="checked" />
|
||||||
|
<label for="$add-column-cache-responses" bind="or_views_cacheResponses"></label></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td colspan="4"><h3><span bind="or_views_urlFetch"></span></h3></td></tr>
|
<tr><td colspan="4"><h3><span bind="or_views_urlFetch"></span></h3></td></tr>
|
||||||
<tr><td colspan="4">$EXPRESSION_PREVIEW_WIDGET$</td></tr>
|
<tr><td colspan="4">$EXPRESSION_PREVIEW_WIDGET$</td></tr>
|
||||||
|
@ -103,6 +103,7 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
|
|||||||
elmts.or_views_onErr.text($.i18n._('core-views')["on-error"]);
|
elmts.or_views_onErr.text($.i18n._('core-views')["on-error"]);
|
||||||
elmts.or_views_setBlank.text($.i18n._('core-views')["set-blank"]);
|
elmts.or_views_setBlank.text($.i18n._('core-views')["set-blank"]);
|
||||||
elmts.or_views_storeErr.text($.i18n._('core-views')["store-err"]);
|
elmts.or_views_storeErr.text($.i18n._('core-views')["store-err"]);
|
||||||
|
elmts.or_views_cacheResponses.text($.i18n._('core-views')["cache-responses"]);
|
||||||
elmts.or_views_urlFetch.text($.i18n._('core-views')["url-fetch"]);
|
elmts.or_views_urlFetch.text($.i18n._('core-views')["url-fetch"]);
|
||||||
elmts.okButton.html($.i18n._('core-buttons')["ok"]);
|
elmts.okButton.html($.i18n._('core-buttons')["ok"]);
|
||||||
elmts.cancelButton.text($.i18n._('core-buttons')["cancel"]);
|
elmts.cancelButton.text($.i18n._('core-buttons')["cancel"]);
|
||||||
@ -135,7 +136,8 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
|
|||||||
newColumnName: columnName,
|
newColumnName: columnName,
|
||||||
columnInsertIndex: columnIndex + 1,
|
columnInsertIndex: columnIndex + 1,
|
||||||
delay: elmts.throttleDelayInput[0].value,
|
delay: elmts.throttleDelayInput[0].value,
|
||||||
onError: $('input[name="dialog-onerror-choice"]:checked')[0].value
|
onError: $('input[name="dialog-onerror-choice"]:checked')[0].value,
|
||||||
|
cacheResponses: $('input[name="dialog-cache-responses"]')[0].checked,
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
{ modelsChanged: true }
|
{ modelsChanged: true }
|
||||||
|
Loading…
Reference in New Issue
Block a user