use of com.google.refine.preference.TopList in project OpenRefine by OpenRefine.
the class ProjectManager method preparePreferenceStore.
/**
* @param ps
*/
protected static void preparePreferenceStore(PreferenceStore ps) {
ps.put("scripting.expressions", new TopList(EXPRESSION_HISTORY_MAX));
ps.put("scripting.starred-expressions", new TopList(Integer.MAX_VALUE));
}
use of com.google.refine.preference.TopList in project OpenRefine by OpenRefine.
the class LogExpressionCommandTests method testNullExpressions.
@Test
public void testNullExpressions() throws ServletException, IOException {
prefStore.put("scripting.expressions", null);
when(request.getParameter("csrf_token")).thenReturn(Command.csrfFactory.getFreshToken());
when(request.getParameter("expression")).thenReturn("grel:value+'a'");
command.doPost(request, response);
TopList topList = (TopList) prefStore.get("scripting.expressions");
Assert.assertEquals(topList.getList(), Collections.singletonList("grel:value+'a'"));
}
use of com.google.refine.preference.TopList in project OpenRefine by OpenRefine.
the class GetExpressionHistoryCommand method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
List<String> expressions = toExpressionList(ProjectManager.singleton.getPreferenceStore().get("scripting.expressions"));
TopList topList = (TopList) ProjectManager.singleton.getPreferenceStore().get("scripting.starred-expressions");
if (topList == null) {
topList = new TopList(ProjectManager.EXPRESSION_HISTORY_MAX);
}
Set<String> starredExpressions = new HashSet<String>(topList.getList());
ExpressionsList expressionsList = new ExpressionsList(expressions.stream().map(s -> new ExpressionState(s, starredExpressions.contains(s))).collect(Collectors.toList()));
respondJSON(response, expressionsList);
} catch (Exception e) {
respondException(response, e);
}
}
use of com.google.refine.preference.TopList in project OpenRefine by OpenRefine.
the class GetStarredExpressionsCommand method getExpressionsList.
public static ExpressionList getExpressionsList() {
TopList topList = (TopList) ProjectManager.singleton.getPreferenceStore().get("scripting.starred-expressions");
List<String> starredExpressions = topList == null ? Collections.emptyList() : topList.getList();
return new ExpressionList(starredExpressions.stream().map(e -> new Expression(e)).collect(Collectors.toList()));
}
Aggregations