All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.camunda.connector.operation.channel.CreateChannelOperation Maven / Gradle / Ivy

There is a newer version: 8.6.2
Show newest version
/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
 * under one or more contributor license agreements. Licensed under a proprietary license.
 * See the License.txt file for more information. You may not use this file
 * except in compliance with the proprietary license.
 */
package io.camunda.connector.operation.channel;

import com.microsoft.graph.models.AadUserConversationMember;
import com.microsoft.graph.models.Channel;
import com.microsoft.graph.models.ChannelMembershipType;
import com.microsoft.graph.models.ConversationMember;
import com.microsoft.graph.serviceclient.GraphServiceClient;
import io.camunda.connector.model.Member;
import io.camunda.connector.model.request.data.CreateChannel;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Locale;

public record CreateChannelOperation(CreateChannel model) implements ChannelOperation {
  @Override
  public Channel invoke(final GraphServiceClient graphClient) {

    ChannelMembershipType type =
        ChannelMembershipType.forValue(model.channelType().toLowerCase(Locale.ROOT));

    Channel channel = new Channel();
    channel.setOdataType("#Microsoft.Graph.channel");
    channel.setMembershipType(type);
    channel.setDisplayName(model.name());
    channel.setDescription(model.description());

    if (type != ChannelMembershipType.Standard) {
      LinkedList members = new LinkedList();
      AadUserConversationMember conversationMember = new AadUserConversationMember();

      conversationMember.setRoles(Member.OWNER_ROLES);
      HashMap additionalData = new HashMap();
      additionalData.put(Member.USER_DATA_BIND, Member.toAdditionalDataValue(model.owner()));
      conversationMember.setAdditionalData(additionalData);
      members.add(conversationMember);
      channel.setMembers(members);
    }

    return graphClient.teams().byTeamId(model.groupId()).channels().post(channel);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy