Search in sources :

Example 6 with TopList

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));
}
Also used : TopList(com.google.refine.preference.TopList)

Example 7 with TopList

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'"));
}
Also used : TopList(com.google.refine.preference.TopList) Test(org.testng.annotations.Test)

Example 8 with TopList

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);
    }
}
Also used : TopList(com.google.refine.preference.TopList) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 9 with TopList

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()));
}
Also used : TopList(com.google.refine.preference.TopList)

Aggregations

TopList (com.google.refine.preference.TopList)9 IOException (java.io.IOException)5 ServletException (javax.servlet.ServletException)4 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 ProjectMetadata (com.google.refine.ProjectMetadata)1 PreferenceStore (com.google.refine.preference.PreferenceStore)1 File (java.io.File)1 FileReader (java.io.FileReader)1 Serializable (java.io.Serializable)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 JSONArray (org.json.JSONArray)1 JSONTokener (org.json.JSONTokener)1 JSONWriter (org.json.JSONWriter)1 Test (org.testng.annotations.Test)1