class ClouderaManagerExternalAccountService {

    public ApiExternalAccount createExternalAccount(String accountName, String displayName, String typeName,
            Map<String, String> configs, ApiClient client) throws ApiException {
        ExternalAccountsResourceApi externalAccountsResourceApi = clouderaManagerApiFactory.getExternalAccountsResourceApi(client);
        ApiExternalAccountList externalAccountList = externalAccountsResourceApi.readAccounts(typeName, "FULL");
        boolean accountFound = false;
        if (externalAccountList.getItems() != null && !externalAccountList.getItems().isEmpty()) {
            for (ApiExternalAccount externalAccount : externalAccountList.getItems()) {
                if (accountName.equals(externalAccount.getName())) {
                    accountFound = true;
                }
            }
        }
        ApiExternalAccount apiExternalAccount = new ApiExternalAccount();
        apiExternalAccount.setName(accountName);
        apiExternalAccount.setDisplayName(displayName);
        apiExternalAccount.setTypeName(typeName);
        ApiConfigList accountConfigList = makeApiConfigList(configs);
        apiExternalAccount.setAccountConfigs(accountConfigList);
        if (!accountFound) {
            externalAccountsResourceApi.createAccount(apiExternalAccount);
        }
        return apiExternalAccount;
    }

}