Search in sources :

Example 1 with FormSubmission

use of org.finos.symphony.toolkit.workflow.form.FormSubmission in project spring-bot by finos.

the class TestTableEdit method testDeleteRows.

@Test
public void testDeleteRows() throws Exception {
    EntityJson ej = new EntityJson();
    ej.put(WorkResponse.OBJECT_KEY, to);
    Map<String, Object> selects = Collections.singletonMap("items", Collections.singletonList(Collections.singletonMap("selected", "true")));
    FormSubmission uc = new FormSubmission(TestObjects.class.getCanonicalName(), selects);
    FormAction ea = new FormAction(room, u, uc, "items." + TableDeleteRows.ACTION_SUFFIX, ej);
    deleteRows.accept(ea);
    testTemplating("abc123", "testDeleteRows.ml", "testDeleteRows.json");
}
Also used : EntityJson(org.finos.symphony.toolkit.json.EntityJson) TestObjects(org.finos.symphony.toolkit.workflow.fixture.TestObjects) FormSubmission(org.finos.symphony.toolkit.workflow.form.FormSubmission) FormAction(org.finos.symphony.toolkit.workflow.actions.FormAction) TestObject(org.finos.symphony.toolkit.workflow.fixture.TestObject) Test(org.junit.jupiter.api.Test)

Example 2 with FormSubmission

use of org.finos.symphony.toolkit.workflow.form.FormSubmission in project spring-bot by finos.

the class TableDeleteRows method acceptFormAction.

@SuppressWarnings("unchecked")
@Override
public void acceptFormAction(FormAction ea) {
    String verb = ea.getAction();
    if (verb == null) {
        return;
    }
    if (verb.endsWith(ACTION_SUFFIX)) {
        Object data = ea.getData().get(WorkResponse.OBJECT_KEY);
        // get the table to modify
        String tableLocation = verb.substring(0, verb.length() - ACTION_SUFFIX.length() - 1);
        tableLocation = TableEditRow.fixSpel(tableLocation);
        Expression e = spel.parseExpression(tableLocation);
        List<Object> table = (List<Object>) e.getValue(data);
        Object deleteStructure = ((FormSubmission) ea.getFormData()).structure;
        String mapLocation = convertSpelToMapSpel(tableLocation);
        e = spel.parseExpression(mapLocation);
        List<Integer> toRemove = getRowsToDelete((List<Object>) e.getValue(deleteStructure));
        for (Integer i : toRemove) {
            table.remove((int) i);
        }
        WorkResponse out = new WorkResponse(ea.getAddressable(), data, WorkMode.EDIT);
        rh.accept(out);
    }
}
Also used : Expression(org.springframework.expression.Expression) FormSubmission(org.finos.symphony.toolkit.workflow.form.FormSubmission) List(java.util.List) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse)

Aggregations

FormSubmission (org.finos.symphony.toolkit.workflow.form.FormSubmission)2 List (java.util.List)1 EntityJson (org.finos.symphony.toolkit.json.EntityJson)1 FormAction (org.finos.symphony.toolkit.workflow.actions.FormAction)1 TestObject (org.finos.symphony.toolkit.workflow.fixture.TestObject)1 TestObjects (org.finos.symphony.toolkit.workflow.fixture.TestObjects)1 WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)1 Test (org.junit.jupiter.api.Test)1 Expression (org.springframework.expression.Expression)1