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

com.spotinst.sdkjava.model.repo.admin.organization.SpotAdminOrganizationRepo Maven / Gradle / Ivy

There is a newer version: 1.0.121
Show newest version
package com.spotinst.sdkjava.model.repo.admin.organization;

import com.spotinst.sdkjava.exception.ExceptionHelper;
import com.spotinst.sdkjava.exception.SpotinstHttpException;
import com.spotinst.sdkjava.model.ISpotAdminOrganizationRepo;
import com.spotinst.sdkjava.model.RepoGenericResponse;
import com.spotinst.sdkjava.model.api.admin.organization.*;
import com.spotinst.sdkjava.model.bl.admin.organization.*;
import com.spotinst.sdkjava.model.converters.admin.organization.AdminOrganizationConverter;
import com.spotinst.sdkjava.model.service.admin.organization.SpotAdminOrganizationService;

import java.util.List;
import java.util.stream.Collectors;

public class SpotAdminOrganizationRepo implements ISpotAdminOrganizationRepo {

    @Override
    public RepoGenericResponse createUser(User userRequest, Boolean generateToken, String authToken) {
        RepoGenericResponse retVal;

        try {

            ApiUser apiUserRequest = AdminOrganizationConverter.toDal(userRequest);

            ApiUser apiResponse =
                    SpotAdminOrganizationService.createUser(apiUserRequest, generateToken, authToken);
            User userResponse = AdminOrganizationConverter.toBl(apiResponse);

            retVal = new RepoGenericResponse<>(userResponse);
        } catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse> getUsers(String authToken) {
        RepoGenericResponse> retVal;

        try {

            List apiResponse =
                    SpotAdminOrganizationService.getOrganizationUsers(authToken );
            List getResponse =
                    apiResponse.stream().map(AdminOrganizationConverter::toBl).collect(Collectors.toList());

            retVal = new RepoGenericResponse<>(getResponse);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse getUserDetails(String userId,String authToken ) {
        RepoGenericResponse retVal;

        try {

            ApiUserDetails apiResponse =
                    SpotAdminOrganizationService.getUserDetails(userId, authToken );
            UserDetails userResponse = AdminOrganizationConverter.toBl(apiResponse);

            retVal = new RepoGenericResponse<>(userResponse);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse updateUserGroupMappingOfUser(String userId, List userGroupIds, String authToken) {
        RepoGenericResponse retVal;

        try {

            Boolean updateResponse = SpotAdminOrganizationService.updateUserGroupMappingOfUser(userId, userGroupIds, authToken );

            retVal = new RepoGenericResponse<>(updateResponse);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse deleteUser(String userId, String authToken ) {
        RepoGenericResponse retVal;

        try {

            Boolean status =
                    SpotAdminOrganizationService.deleteUser(userId, authToken );

            retVal = new RepoGenericResponse<>(status);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse updatePolicyMappingOfUser(String userId, UpdatePoliciesRequest updateRequest, String authToken) {
        RepoGenericResponse retVal;

        try {

            ApiUpdatePoliciesRequest apiUpdateRequest = AdminOrganizationConverter.toDal(updateRequest);
            Boolean updateResponse =
                    SpotAdminOrganizationService.updatePolicyMappingOfUser(userId, apiUpdateRequest, authToken );

            retVal = new RepoGenericResponse<>(updateResponse);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse createUserGroup(UserGroup createRequest,String authToken ) {
        RepoGenericResponse retVal;

        try {

            ApiUserGroup apiCreateRequest = AdminOrganizationConverter.toDal(createRequest);

            ApiUserGroup apiResponse =
                    SpotAdminOrganizationService.createUserGroup(apiCreateRequest, authToken );
            UserGroup createResponse = AdminOrganizationConverter.toBl(apiResponse);

            retVal = new RepoGenericResponse<>(createResponse);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse> getUserGroups(String authToken) {
        RepoGenericResponse> retVal;

        try {

            List apiResponse =
                    SpotAdminOrganizationService.getUserGroups(authToken );
            List getResponse = apiResponse.stream().map(AdminOrganizationConverter::toBl).collect(Collectors.toList());

            retVal = new RepoGenericResponse<>(getResponse);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse getUserGroupDetails(String groupId,String authToken ) {
        RepoGenericResponse retVal;

        try {

            ApiUserGroupDetails apiResponse =
                    SpotAdminOrganizationService.getUserGroupDetails(groupId, authToken );
            UserGroupDetails getResponse = AdminOrganizationConverter.toBl(apiResponse);

            retVal = new RepoGenericResponse<>(getResponse);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse updateUserGroupDetails(String groupId, String name, String description, String authToken ) {
        RepoGenericResponse retVal;

        try {

            Boolean status =
                    SpotAdminOrganizationService.updateUserGroupDetails(groupId, name, description, authToken );

            retVal = new RepoGenericResponse<>(status);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse deleteUserGroup(String groupId, String authToken ) {
        RepoGenericResponse retVal;

        try {

            Boolean status =
                    SpotAdminOrganizationService.deleteUserGroup(groupId, authToken );

            retVal = new RepoGenericResponse<>(status);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse updateUserMappingOfUserGroup(String groupId, List userIds, String authToken ) {
        RepoGenericResponse retVal;

        try {

            Boolean status =
                    SpotAdminOrganizationService.updateUserMappingOfUserGroup(groupId, userIds, authToken );

            retVal = new RepoGenericResponse<>(status);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse updatePolicyMappingOfUserGroup(String groupId, UpdatePoliciesRequest updateRequest, String authToken) {
        RepoGenericResponse retVal;

        try {

            ApiUpdatePoliciesRequest apiUpdateRequest = AdminOrganizationConverter.toDal(updateRequest);

            Boolean status =
                    SpotAdminOrganizationService.updatePolicyMappingOfUserGroup(groupId, apiUpdateRequest, authToken );

            retVal = new RepoGenericResponse<>(status);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse> getAccountUserMapping(String userEmail, String authToken) {
        RepoGenericResponse> retVal;

        try {

            List apiResponse =
                    SpotAdminOrganizationService.getAccountUserMapping(userEmail, authToken );
            List getResponse = apiResponse.stream().map(AdminOrganizationConverter::toBl).collect(Collectors.toList());

            retVal = new RepoGenericResponse<>(getResponse);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse createProgrammaticUser(ProgrammaticUser createRequest, String authToken) {
        RepoGenericResponse retVal;

        try {

            ApiProgrammaticUser apiCreateRequest = AdminOrganizationConverter.toDal(createRequest);

            ApiProgrammaticUserResponse apiResponse =
                    SpotAdminOrganizationService.createProgrammaticUser(apiCreateRequest, authToken );
            ProgrammaticUserResponse userResponse = AdminOrganizationConverter.toBl(apiResponse);

            retVal = new RepoGenericResponse<>(userResponse);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse createOrganization(CreateOrganization createRequest, String authToken) {
        RepoGenericResponse retVal;

        try {

            ApiCreateOrganization apiCreateRequest = AdminOrganizationConverter.toDal(createRequest);

            ApiCreateOrganizationResponse apiResponse =
                    SpotAdminOrganizationService.createOrganization(apiCreateRequest, authToken);
            CreateOrganizationResponse userResponse = AdminOrganizationConverter.toBl(apiResponse);

            retVal = new RepoGenericResponse<>(userResponse);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse deleteOrganization(String organizationId, String authToken) {
        RepoGenericResponse retVal;

        try {

            Boolean status =
                    SpotAdminOrganizationService.deleteOrganization(organizationId, authToken );

            retVal = new RepoGenericResponse<>(status);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse createAccessPolicy(Policy createRequest, String authToken) {
        RepoGenericResponse retVal;

        try {

            ApiPolicy apiCreateRequest = AdminOrganizationConverter.toDal(createRequest);

            ApiPolicy apiResponse =
                    SpotAdminOrganizationService.createAccessPolicy(apiCreateRequest, authToken );
            Policy createResponse = AdminOrganizationConverter.toBl(apiResponse);

            retVal = new RepoGenericResponse<>(createResponse);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse updateAccessPolicy(String policyId, Policy createRequest,String authToken ) {
        RepoGenericResponse retVal;

        try {

            ApiPolicy apiCreateRequest = AdminOrganizationConverter.toDal(createRequest);

            Boolean updateStatus=
                    SpotAdminOrganizationService.updateAccessPolicy(policyId,apiCreateRequest, authToken );

            retVal = new RepoGenericResponse<>(updateStatus);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse> getAllAccessPolicies(String authToken ) {
        RepoGenericResponse> retVal;

        try {
            List apiResponse =
                    SpotAdminOrganizationService.getAllAccessPolicies( authToken );
            List getResponse =
                    apiResponse.stream().map(AdminOrganizationConverter::toBl).collect(Collectors.toList());

            retVal = new RepoGenericResponse<>(getResponse);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse deleteAccessPolicy(String policyId, String authToken ) {
        RepoGenericResponse retVal;

        try {
            Boolean updateStatus=
                    SpotAdminOrganizationService.deleteAccessPolicy(policyId, authToken );

            retVal = new RepoGenericResponse<>(updateStatus);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy