Search in sources :

Example 11 with User

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

the class SymphonyConversationsImpl method ensureChat.

@Override
public SymphonyRoom ensureChat(Chat r, List<User> users, Map<String, Object> meta) {
    String description = "";
    String name = r.getName();
    boolean isPublic = false;
    description = (String) meta.getOrDefault(ROOM_DESCRIPTION, "");
    isPublic = (boolean) meta.getOrDefault(ROOM_PUBLIC, false);
    SymphonyRoom theRoom = null;
    if (r instanceof SymphonyRoom) {
        if (((SymphonyRoom) r).getStreamId() != null) {
            theRoom = (SymphonyRoom) r;
        } else {
            theRoom = loadRoomByName(name);
        }
    }
    if (theRoom == null) {
        // create the room
        V3RoomAttributes ra = new V3RoomAttributes().name(name).description(description)._public(isPublic).discoverable(isPublic);
        V3RoomDetail detail = streamsApi.v3RoomCreatePost(ra, null);
        String streamId = detail.getRoomSystemInfo().getId();
        theRoom = new SymphonyRoom(name, streamId);
        // next, we need to make sure that all of the admins are members of the room and owners.
        List<Long> adminIds = getDefaultAdministrators().stream().filter(u -> u instanceof SymphonyUser).map(u -> (SymphonyUser) u).map(su -> Long.parseLong(su.getUserId())).filter(id -> id != null).collect(Collectors.toList());
        for (Long user : adminIds) {
            UserId u = new UserId().id(user);
            rmApi.v1RoomIdMembershipAddPost(u, null, streamId);
            rmApi.v1RoomIdMembershipPromoteOwnerPost(u, null, streamId);
        }
        LOG.info("Created room {} with admins {} ", theRoom, getDefaultAdministrators());
    }
    // next, ensure that all the users are in the room
    String streamId = theRoom.getStreamId();
    users.stream().filter(u -> u instanceof SymphonyUser).map(u -> (SymphonyUser) u).forEach(u -> rmApi.v1RoomIdMembershipAddPost(new UserId().id(Long.parseLong(u.getUserId())), null, streamId));
    return theRoom;
}
Also used : V2RoomSearchCriteria(com.symphony.api.model.V2RoomSearchCriteria) User(org.finos.symphony.toolkit.workflow.content.User) SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) TypeEnum(com.symphony.api.model.StreamType.TypeEnum) LoggerFactory(org.slf4j.LoggerFactory) V3RoomDetail(com.symphony.api.model.V3RoomDetail) StreamsApi(com.symphony.api.pod.StreamsApi) InitializingBean(org.springframework.beans.factory.InitializingBean) V3RoomAttributes(com.symphony.api.model.V3RoomAttributes) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) StreamList(com.symphony.api.model.StreamList) UserV2(com.symphony.api.model.UserV2) V3RoomSearchResults(com.symphony.api.model.V3RoomSearchResults) Logger(org.slf4j.Logger) 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) MembershipList(com.symphony.api.model.MembershipList) SymphonyApiProperties(org.finos.symphony.toolkit.spring.api.properties.SymphonyApiProperties) RoomMembershipApi(com.symphony.api.pod.RoomMembershipApi) Set(java.util.Set) Chat(org.finos.symphony.toolkit.workflow.content.Chat) Collectors(java.util.stream.Collectors) List(java.util.List) Addressable(org.finos.symphony.toolkit.workflow.content.Addressable) StreamAttributes(com.symphony.api.model.StreamAttributes) StreamID(com.symphony.user.StreamID) SymphonyRoom(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom) StreamFilter(com.symphony.api.model.StreamFilter) Collections(java.util.Collections) StreamType(com.symphony.api.model.StreamType) UserId(com.symphony.api.model.UserId) V3RoomDetail(com.symphony.api.model.V3RoomDetail) UserId(com.symphony.api.model.UserId) V3RoomAttributes(com.symphony.api.model.V3RoomAttributes) SymphonyUser(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser) SymphonyRoom(org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)

Aggregations

User (org.finos.symphony.toolkit.workflow.content.User)11 SimpleMessageAction (org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)5 EntityJson (org.finos.symphony.toolkit.json.EntityJson)4 Addressable (org.finos.symphony.toolkit.workflow.content.Addressable)4 Chat (org.finos.symphony.toolkit.workflow.content.Chat)4 Message (org.finos.symphony.toolkit.workflow.content.Message)4 SymphonyRoom (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)4 SymphonyUser (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser)4 FormAction (org.finos.symphony.toolkit.workflow.actions.FormAction)3 WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)3 HashTag (org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag)3 SymphonyIdentity (com.symphony.api.id.SymphonyIdentity)2 MembershipList (com.symphony.api.model.MembershipList)2 StreamAttributes (com.symphony.api.model.StreamAttributes)2 StreamList (com.symphony.api.model.StreamList)2 StreamType (com.symphony.api.model.StreamType)2 V3RoomAttributes (com.symphony.api.model.V3RoomAttributes)2 V3RoomDetail (com.symphony.api.model.V3RoomDetail)2 V3RoomSearchResults (com.symphony.api.model.V3RoomSearchResults)2 ArrayList (java.util.ArrayList)2