Search in sources :

Example 6 with EntityJson

use of org.finos.symphony.toolkit.json.EntityJson 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 7 with EntityJson

use of org.finos.symphony.toolkit.json.EntityJson 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 8 with EntityJson

use of org.finos.symphony.toolkit.json.EntityJson in project spring-bot by finos.

the class LogMessageHandlerImpl method serializeJson.

public String serializeJson(LogMessage out) {
    try {
        EntityJson json = new EntityJson();
        json.put(SHARED_STREAM_JSON_KEY, out);
        return om.writeValueAsString(json);
    } catch (JsonProcessingException e) {
        throw new SharedStreamException(e);
    }
}
Also used : EntityJson(org.finos.symphony.toolkit.json.EntityJson) SharedStreamException(org.finos.symphony.toolkit.stream.SharedStreamException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 9 with EntityJson

use of org.finos.symphony.toolkit.json.EntityJson in project spring-bot by finos.

the class RoomWelcomeEventConsumer method accept.

@Override
public void accept(V4Event t) {
    V4RoomCreated roomCreated = t.getPayload().getRoomCreated();
    V4UserJoinedRoom userJoined = t.getPayload().getUserJoinedRoom();
    String streamId;
    EntityJson json = new EntityJson();
    json.put("bot", u);
    if (roomCreated != null) {
        json.put("room", roomCreated.getRoomProperties());
        json.put("stream", roomCreated.getStream());
        streamId = roomCreated.getStream().getStreamId();
    } else if (userJoined != null) {
        json.put("user", userJoined.getAffectedUser());
        json.put("stream", userJoined.getStream());
        streamId = userJoined.getStream().getStreamId();
    } else {
        // doesn't need a welcome message
        return;
    }
    String jsonStr;
    try {
        jsonStr = om.writeValueAsString(json);
        messagesApi.v4StreamSidMessageCreatePost(null, streamId, welcomeMessageML, jsonStr, null, null, null, null);
    } catch (Exception e) {
        LOG.error("Couldn't send welcome message: ", e);
    }
}
Also used : EntityJson(org.finos.symphony.toolkit.json.EntityJson) V4RoomCreated(com.symphony.api.model.V4RoomCreated) V4UserJoinedRoom(com.symphony.api.model.V4UserJoinedRoom)

Example 10 with EntityJson

use of org.finos.symphony.toolkit.json.EntityJson in project spring-bot by finos.

the class SymphonyNotificator method sendNotification.

private void sendNotification(String project, String build, String statusText, String statusColor, Set<SUser> users, Build bt) {
    MessagesApi messages;
    String jsonString;
    String template;
    Config config = c.getConfig();
    try {
        String details = bt.getLogMessages(0, Integer.MAX_VALUE).stream().filter(m -> !m.contains("errorreport")).filter(m -> m.contains("error")).map(a -> HtmlUtils.htmlEscape(a)).reduce("", (a, b) -> a + "<br/>" + b);
        String url = sBuildServer.getRootUrl() + "/project.html?projectId=" + URIUtil.encodeQuery(bt.getProjectId());
        BuildData bd = new BuildData(project, build, statusText, statusColor, url, details);
        EntityJson json = new EntityJson();
        json.put("teamcity", bd);
        jsonString = c.getObjectMapper().writeValueAsString(json);
        log.warn("JSON: \n" + jsonString);
    } catch (Exception e1) {
        log.error("Couldn't format string ", e1);
        return;
    }
    try {
        messages = c.getAPI(MessagesApi.class);
    } catch (Exception e) {
        log.error("Couldn't aquire symphony API ", e);
        return;
    }
    if (StringUtils.hasText(config.getTemplate())) {
        template = config.getTemplate();
        log.warn("Using custom symphony template");
    } else {
        template = asString(rl.getResource("classpath:/template.ftl"));
        log.warn("Using built-in symphony template");
    }
    for (SUser sUser : users) {
        String streamId = sUser.getPropertyValue(symphonyStreamId);
        log.warn("Sending notification to Symphony on " + streamId);
        if (StringUtils.hasText(streamId)) {
            try {
                messages.v4StreamSidMessageCreatePost(null, streamId, template, jsonString, null, null, null, null);
            } catch (Exception e) {
                log.error("Couldn't send message to symphony ", e);
            }
        }
    }
}
Also used : HtmlUtils(org.springframework.web.util.HtmlUtils) ArrayList(java.util.ArrayList) MuteInfo(jetbrains.buildServer.serverSide.mute.MuteInfo) MessagesApi(com.symphony.api.agent.MessagesApi) URIUtil(org.apache.commons.httpclient.util.URIUtil) Logger(org.apache.log4j.Logger) Build(jetbrains.buildServer.Build) TestNameResponsibilityEntry(jetbrains.buildServer.responsibility.TestNameResponsibilityEntry) STest(jetbrains.buildServer.serverSide.STest) SBuildServer(jetbrains.buildServer.serverSide.SBuildServer) SBuildType(jetbrains.buildServer.serverSide.SBuildType) BuildProblemInfo(jetbrains.buildServer.serverSide.problems.BuildProblemInfo) Resource(org.springframework.core.io.Resource) SRunningBuild(jetbrains.buildServer.serverSide.SRunningBuild) ResourceLoader(org.springframework.core.io.ResourceLoader) NotificatorPropertyKey(jetbrains.buildServer.users.NotificatorPropertyKey) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Notificator(jetbrains.buildServer.notification.Notificator) UncheckedIOException(java.io.UncheckedIOException) Nullable(org.jetbrains.annotations.Nullable) ResponsibilityEntry(jetbrains.buildServer.responsibility.ResponsibilityEntry) EntityJson(org.finos.symphony.toolkit.json.EntityJson) NotificatorRegistry(jetbrains.buildServer.notification.NotificatorRegistry) TestName(jetbrains.buildServer.tests.TestName) SProject(jetbrains.buildServer.serverSide.SProject) Charsets(org.apache.commons.compress.utils.Charsets) NotNull(org.jetbrains.annotations.NotNull) UserPropertyInfo(jetbrains.buildServer.serverSide.UserPropertyInfo) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) PropertyKey(jetbrains.buildServer.users.PropertyKey) FileCopyUtils(org.springframework.util.FileCopyUtils) SUser(jetbrains.buildServer.users.SUser) StringUtils(org.springframework.util.StringUtils) MessagesApi(com.symphony.api.agent.MessagesApi) EntityJson(org.finos.symphony.toolkit.json.EntityJson) SUser(jetbrains.buildServer.users.SUser) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

EntityJson (org.finos.symphony.toolkit.json.EntityJson)26 FormAction (org.finos.symphony.toolkit.workflow.actions.FormAction)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 HashTag (org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag)5 SymphonyUser (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser)5 Test (org.junit.jupiter.api.Test)5 V4Message (com.symphony.api.model.V4Message)4 SimpleMessageAction (org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)4 Addressable (org.finos.symphony.toolkit.workflow.content.Addressable)4 Message (org.finos.symphony.toolkit.workflow.content.Message)4 MessagesApi (com.symphony.api.agent.MessagesApi)3 V4MessageSent (com.symphony.api.model.V4MessageSent)3 Action (org.finos.symphony.toolkit.workflow.actions.Action)3 User (org.finos.symphony.toolkit.workflow.content.User)3 MessageSearchQuery (com.symphony.api.model.MessageSearchQuery)2 V4MessageList (com.symphony.api.model.V4MessageList)2 V4Stream (com.symphony.api.model.V4Stream)2 V4SymphonyElementsAction (com.symphony.api.model.V4SymphonyElementsAction)2 V4User (com.symphony.api.model.V4User)2 StreamsApi (com.symphony.api.pod.StreamsApi)2