Search in sources :

Example 1 with WorkResponse

use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.

the class TableAddRow method addNewRowAction.

@SuppressWarnings("unchecked")
protected void addNewRowAction(FormAction ea, String verb) {
    String tableLocation = verb.substring(0, verb.length() - DO_SUFFIX.length() - 1);
    tableLocation = TableEditRow.fixSpel(tableLocation);
    Expression e = spel.parseExpression(tableLocation);
    Object updated = ea.getFormData();
    Object toChange = ea.getData().get(WORKFLOW_001);
    List<Object> listToUpdate = (List<Object>) e.getValue(toChange);
    listToUpdate.add(updated);
    WorkResponse wr = new WorkResponse(ea.getAddressable(), toChange, WorkMode.EDIT);
    rh.accept(wr);
}
Also used : Expression(org.springframework.expression.Expression) ButtonList(org.finos.symphony.toolkit.workflow.form.ButtonList) List(java.util.List) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse)

Example 2 with WorkResponse

use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.

the class TableAddRow method newRowFormAction.

protected void newRowFormAction(FormAction ea, String verb) {
    Map<String, Object> ej = ea.getData();
    Object workflowObject = ej.get(WorkResponse.OBJECT_KEY);
    String tableLocation = verb.substring(0, verb.length() - ACTION_SUFFIX.length() - 1);
    tableLocation = TableEditRow.fixSpel(tableLocation);
    Expression e = spel.parseExpression(tableLocation);
    TypeDescriptor td = e.getValueTypeDescriptor(workflowObject);
    Class<?> c = td.getResolvableType().getGeneric(0).resolve();
    Object out = null;
    try {
        out = c.getConstructor().newInstance();
    } catch (Exception e1) {
    // this is called for primitives where we can't construct the new instance.
    }
    Map<String, Object> data = WorkResponse.createEntityMap(out, ButtonList.of(new Button(tableLocation + "." + DO_SUFFIX, Type.ACTION, "Add")), null);
    // keep track of the original data
    data.put(WORKFLOW_001, workflowObject);
    WorkResponse wr = new WorkResponse(ea.getAddressable(), data, WorkResponse.getTemplateNameForClass(WorkMode.EDIT, c), WorkMode.EDIT, c);
    rh.accept(wr);
}
Also used : TypeDescriptor(org.springframework.core.convert.TypeDescriptor) Expression(org.springframework.expression.Expression) Button(org.finos.symphony.toolkit.workflow.form.Button) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse)

Example 3 with WorkResponse

use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.

the class WorkResponseConverter method convert.

@Override
public Response convert(Object source, ChatHandlerExecutor creator) {
    Addressable a = creator.action().getAddressable();
    ChatResponseBody wr = creator.getOriginatingMapping().getHandlerMethod().getMethodAnnotation(ChatResponseBody.class);
    WorkMode wm = WorkMode.VIEW;
    if (wr != null) {
        String template = wr.template();
        WorkMode wmAnnotation = wr.workMode();
        if (wmAnnotation == WorkMode.EDIT) {
            wm = wmAnnotation;
        }
        if (StringUtils.hasText(template)) {
            Map<String, Object> entityMap = WorkResponse.createEntityMap(source, null, null);
            return new WorkResponse(a, entityMap, template, wm, source.getClass());
        }
    }
    return new WorkResponse(a, source, wm, null, null);
}
Also used : Addressable(org.finos.symphony.toolkit.workflow.content.Addressable) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) WorkMode(org.finos.symphony.toolkit.workflow.annotations.WorkMode) ChatResponseBody(org.finos.symphony.toolkit.workflow.annotations.ChatResponseBody)

Example 4 with WorkResponse

use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.

the class ElementsHandler method accept.

@SuppressWarnings("unchecked")
@Override
public void accept(V4Event t) {
    try {
        V4SymphonyElementsAction action = t.getPayload().getSymphonyElementsAction();
        if (action != null) {
            Map<String, Object> formValues = (Map<String, Object>) action.getFormValues();
            String verb = (String) formValues.get("action");
            String formId = action.getFormId();
            Object currentForm;
            if (hasFormData(formValues)) {
                currentForm = formConverter.convert(formValues, formId);
            } else {
                currentForm = null;
            }
            EntityJson data = retrieveData(action.getFormMessageId());
            Addressable rr = ruBuilder.loadRoomById(action.getStream().getStreamId());
            User u = ruBuilder.loadUserById(t.getInitiator().getUser().getUserId());
            // if we're not in a room, address the user directly.
            rr = rr == null ? u : rr;
            Errors e = ErrorHelp.createErrorHolder();
            if (validated(currentForm, e)) {
                FormAction ea = new FormAction(rr, u, currentForm, verb, data);
                try {
                    Action.CURRENT_ACTION.set(ea);
                    for (ActionConsumer c : elementsConsumers) {
                        try {
                            c.accept(ea);
                        } catch (Exception ee) {
                            LOG.error("Failed to handle consumer " + c, ee);
                        }
                    }
                } finally {
                    Action.CURRENT_ACTION.set(Action.NULL_ACTION);
                }
            } else {
                WorkResponse fr = new WorkResponse(rr, currentForm, WorkMode.EDIT, ButtonList.of(new Button(verb, Button.Type.ACTION, "Retry")), convertErrorsToMap(e));
                rh.accept(fr);
            }
        }
    } catch (Exception e) {
        LOG.error("Couldn't handle event " + t, e);
    }
}
Also used : EntityJson(org.finos.symphony.toolkit.json.EntityJson) User(org.finos.symphony.toolkit.workflow.content.User) ActionConsumer(org.finos.symphony.toolkit.workflow.actions.consumers.ActionConsumer) Errors(org.springframework.validation.Errors) Button(org.finos.symphony.toolkit.workflow.form.Button) V4SymphonyElementsAction(com.symphony.api.model.V4SymphonyElementsAction) FormAction(org.finos.symphony.toolkit.workflow.actions.FormAction) Addressable(org.finos.symphony.toolkit.workflow.content.Addressable) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) Map(java.util.Map) ErrorMap(org.finos.symphony.toolkit.workflow.form.ErrorMap)

Example 5 with WorkResponse

use of org.finos.symphony.toolkit.workflow.response.WorkResponse in project spring-bot by finos.

the class ClaimController method add.

@ChatButton(value = NewClaim.class, buttonText = "add")
public List<Response> add(NewClaim sc, User u, Addressable from) {
    OpenedClaim c = new OpenedClaim();
    c.amount = sc.amount;
    c.author = u;
    c.description = sc.description;
    c.status = Status.OPEN;
    Chat approvalRoom = conversations.getExistingChat("Claim Approval Room");
    return Arrays.asList(new WorkResponse(approvalRoom, c, WorkMode.VIEW), new MessageResponse(from, Message.of("Your claim has been sent to the Approval Room for processing")));
}
Also used : MessageResponse(org.finos.symphony.toolkit.workflow.response.MessageResponse) Chat(org.finos.symphony.toolkit.workflow.content.Chat) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton)

Aggregations

WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)40 Test (org.junit.jupiter.api.Test)18 Button (org.finos.symphony.toolkit.workflow.form.Button)10 ButtonList (org.finos.symphony.toolkit.workflow.form.ButtonList)9 List (java.util.List)5 Addressable (org.finos.symphony.toolkit.workflow.content.Addressable)5 SymphonyRoom (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)5 Expression (org.springframework.expression.Expression)5 ChatButton (org.finos.symphony.toolkit.workflow.annotations.ChatButton)4 HashTag (org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag)4 Instant (java.time.Instant)3 WorkMode (org.finos.symphony.toolkit.workflow.annotations.WorkMode)3 User (org.finos.symphony.toolkit.workflow.content.User)3 Arrays (java.util.Arrays)2 Collectors (java.util.stream.Collectors)2 SimpleMessageAction (org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)2 ChatRequest (org.finos.symphony.toolkit.workflow.annotations.ChatRequest)2 ChatResponseBody (org.finos.symphony.toolkit.workflow.annotations.ChatResponseBody)2 Chat (org.finos.symphony.toolkit.workflow.content.Chat)2 TestCollections (org.finos.symphony.toolkit.workflow.fixture.TestCollections)2