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

com.descope.sdk.mgmt.impl.GroupServiceImpl Maven / Gradle / Ivy

The newest version!
package com.descope.sdk.mgmt.impl;

import static com.descope.literals.Routes.ManagementEndPoints.GROUP_LOAD_ALL_LINK;
import static com.descope.literals.Routes.ManagementEndPoints.LOAD_ALL_FOR_GROUP_MEMBERS_LINK;
import static com.descope.literals.Routes.ManagementEndPoints.LOAD_ALL_GROUP_MEMBERS_LINK;
import static com.descope.utils.CollectionUtils.mapOf;

import com.descope.exception.DescopeException;
import com.descope.exception.ServerCommonException;
import com.descope.model.client.Client;
import com.descope.model.group.Group;
import com.descope.proxy.ApiProxy;
import com.descope.sdk.mgmt.GroupService;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;

class GroupServiceImpl extends ManagementsBase implements GroupService {
  GroupServiceImpl(Client client) {
    super(client);
  }

  @Override
  @SuppressWarnings("unchecked")
  public List loadAllGroups(String tenantID) throws DescopeException {
    if (StringUtils.isBlank(tenantID)) {
      throw ServerCommonException.invalidArgument("TenantId");
    }
    Map request = mapOf("tenantId", tenantID);
    ApiProxy apiProxy = getApiProxy();
    return (List) apiProxy.post(getUri(GROUP_LOAD_ALL_LINK), request, List.class);
  }

  @Override
  @SuppressWarnings("unchecked")
  public List loadAllGroupsForMembers(
      String tenantID, List userIDs, List loginIDs) throws DescopeException {
    if (StringUtils.isBlank(tenantID)) {
      throw ServerCommonException.invalidArgument("TenantId");
    }
    if (userIDs.isEmpty() && loginIDs.isEmpty()) {
      throw ServerCommonException.invalidArgument("userIDs and loginIDs");
    }
    Map request =
        mapOf("tenantId", tenantID, "loginIds", loginIDs, "userIds", userIDs);
    ApiProxy apiProxy = getApiProxy();
    return (List)
        apiProxy.post(getUri(LOAD_ALL_FOR_GROUP_MEMBERS_LINK), request, List.class);
  }

  @Override
  @SuppressWarnings("unchecked")
  public List loadAllGroupMembers(String tenantID, String groupID) throws DescopeException {
    if (StringUtils.isBlank(tenantID)) {
      throw ServerCommonException.invalidArgument("TenantId");
    }
    if (StringUtils.isBlank(groupID)) {
      throw ServerCommonException.invalidArgument("GroupID");
    }
    Map request = mapOf("tenantId", tenantID, "groupId", groupID);
    ApiProxy apiProxy = getApiProxy();
    return (List) apiProxy.post(getUri(LOAD_ALL_GROUP_MEMBERS_LINK), request, List.class);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy