Search in sources :

Example 1 with Addressable

use of org.finos.symphony.toolkit.workflow.content.Addressable 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 2 with Addressable

use of org.finos.symphony.toolkit.workflow.content.Addressable 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 3 with Addressable

use of org.finos.symphony.toolkit.workflow.content.Addressable in project spring-bot by finos.

the class SymphonyHistoryImpl method getEntityJsonFromHistory.

@Override
public List<EntityJson> getEntityJsonFromHistory(Tag t, Addressable address, Instant since) {
    MessageSearchQuery msq = createMessageSearchQuery(null, address, since, t);
    V4MessageList out = messageApi.v1MessageSearchPost(msq, null, null, 0, 50, null, null);
    return out.stream().map(msg -> getEntityJson(msg)).filter(e -> e != null).collect(Collectors.toList());
}
Also used : Tag(org.finos.symphony.toolkit.workflow.content.Tag) UsersApi(com.symphony.api.pod.UsersApi) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) AbstractStreamResolving(org.finos.symphony.toolkit.workflow.sources.symphony.streams.AbstractStreamResolving) SymphonyApiProperties(org.finos.symphony.toolkit.spring.api.properties.SymphonyApiProperties) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) V4MessageList(com.symphony.api.model.V4MessageList) StreamsApi(com.symphony.api.pod.StreamsApi) SymphonyAddressable(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyAddressable) CashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.CashTag) MessagesApi(com.symphony.api.agent.MessagesApi) List(java.util.List) Addressable(org.finos.symphony.toolkit.workflow.content.Addressable) V4Message(com.symphony.api.model.V4Message) EntityJson(org.finos.symphony.toolkit.json.EntityJson) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) TagSupport(org.finos.symphony.toolkit.workflow.sources.symphony.TagSupport) Entry(java.util.Map.Entry) Optional(java.util.Optional) EntityJsonConverter(org.finos.symphony.toolkit.workflow.sources.symphony.json.EntityJsonConverter) MessageSearchQuery(com.symphony.api.model.MessageSearchQuery) V4MessageList(com.symphony.api.model.V4MessageList) MessageSearchQuery(com.symphony.api.model.MessageSearchQuery)

Example 4 with Addressable

use of org.finos.symphony.toolkit.workflow.content.Addressable in project spring-bot by finos.

the class SymphonyHistoryImpl method getEntityJsonFromHistory.

@Override
public <X> List<EntityJson> getEntityJsonFromHistory(Class<X> type, Addressable address, Instant since) {
    MessageSearchQuery msq = createMessageSearchQuery(type, address, since, null);
    V4MessageList out = messageApi.v1MessageSearchPost(msq, null, null, 0, 50, null, null);
    return out.stream().map(msg -> getEntityJson(msg)).filter(e -> e != null).collect(Collectors.toList());
}
Also used : Tag(org.finos.symphony.toolkit.workflow.content.Tag) UsersApi(com.symphony.api.pod.UsersApi) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) AbstractStreamResolving(org.finos.symphony.toolkit.workflow.sources.symphony.streams.AbstractStreamResolving) SymphonyApiProperties(org.finos.symphony.toolkit.spring.api.properties.SymphonyApiProperties) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) V4MessageList(com.symphony.api.model.V4MessageList) StreamsApi(com.symphony.api.pod.StreamsApi) SymphonyAddressable(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyAddressable) CashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.CashTag) MessagesApi(com.symphony.api.agent.MessagesApi) List(java.util.List) Addressable(org.finos.symphony.toolkit.workflow.content.Addressable) V4Message(com.symphony.api.model.V4Message) EntityJson(org.finos.symphony.toolkit.json.EntityJson) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) TagSupport(org.finos.symphony.toolkit.workflow.sources.symphony.TagSupport) Entry(java.util.Map.Entry) Optional(java.util.Optional) EntityJsonConverter(org.finos.symphony.toolkit.workflow.sources.symphony.json.EntityJsonConverter) MessageSearchQuery(com.symphony.api.model.MessageSearchQuery) V4MessageList(com.symphony.api.model.V4MessageList) MessageSearchQuery(com.symphony.api.model.MessageSearchQuery)

Example 5 with Addressable

use of org.finos.symphony.toolkit.workflow.content.Addressable in project spring-bot by finos.

the class SymphonyConversationsImpl method getAllConversationsFiltered.

protected Set<Addressable> getAllConversationsFiltered(StreamFilter f) {
    f.includeInactiveStreams(false);
    Set<Addressable> out = new HashSet<>();
    int skip = 0;
    StreamList sl;
    do {
        sl = streamsApi.v1StreamsListPost(null, f, skip, 50);
        sl.forEach(si -> {
            Addressable a = convertToAddressable(si);
            if (a != null) {
                out.add(a);
            }
        });
        skip += sl.size();
    } while (sl.size() == 50);
    return out;
}
Also used : Addressable(org.finos.symphony.toolkit.workflow.content.Addressable) StreamList(com.symphony.api.model.StreamList) HashSet(java.util.HashSet)

Aggregations

Addressable (org.finos.symphony.toolkit.workflow.content.Addressable)8 EntityJson (org.finos.symphony.toolkit.json.EntityJson)4 User (org.finos.symphony.toolkit.workflow.content.User)4 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)3 MessagesApi (com.symphony.api.agent.MessagesApi)2 MessageSearchQuery (com.symphony.api.model.MessageSearchQuery)2 V4Message (com.symphony.api.model.V4Message)2 V4MessageList (com.symphony.api.model.V4MessageList)2 StreamsApi (com.symphony.api.pod.StreamsApi)2 UsersApi (com.symphony.api.pod.UsersApi)2 Instant (java.time.Instant)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 SymphonyApiProperties (org.finos.symphony.toolkit.spring.api.properties.SymphonyApiProperties)2 SimpleMessageAction (org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)2 ActionConsumer (org.finos.symphony.toolkit.workflow.actions.consumers.ActionConsumer)2 ChatResponseBody (org.finos.symphony.toolkit.workflow.annotations.ChatResponseBody)2