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

com.microsoft.azure.management.eventhub.implementation.EventHubNamespaceAuthorizationRulesImpl Maven / Gradle / Ivy

/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 */

package com.microsoft.azure.management.eventhub.implementation;

import com.microsoft.azure.Page;
import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.eventhub.EventHubNamespaceAuthorizationRule;
import com.microsoft.azure.management.eventhub.EventHubNamespaceAuthorizationRules;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceId;
import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter;
import rx.Completable;
import rx.Observable;
import rx.functions.Func1;

import java.util.Objects;

/**
 * Implementation for {@link EventHubNamespaceAuthorizationRules}.
 */
@LangDefinition
class EventHubNamespaceAuthorizationRulesImpl
        extends AuthorizationRulesBaseImpl
        implements EventHubNamespaceAuthorizationRules {

    EventHubNamespaceAuthorizationRulesImpl(EventHubManager manager) {
        super(manager, manager.inner().namespaces());
    }

    @Override
    public EventHubNamespaceAuthorizationRuleImpl define(String name) {
        return new EventHubNamespaceAuthorizationRuleImpl(name, this.manager);
    }

    @Override
    public Observable getByIdAsync(String id) {
        Objects.requireNonNull(id);
        ResourceId resourceId = ResourceId.fromString(id);

        return getByNameAsync(resourceId.resourceGroupName(),
                resourceId.parent().name(),
                resourceId.name());
    }

    @Override
    public EventHubNamespaceAuthorizationRule getByName(String resourceGroupName, String namespaceName, String name) {
        return getByNameAsync(resourceGroupName, namespaceName, name).toBlocking().last();
    }

    @Override
    public Observable getByNameAsync(String resourceGroupName, String namespaceName, String name) {
        return this.inner().getAuthorizationRuleAsync(resourceGroupName,
                namespaceName,
                name)
                .map(new Func1() {
                    @Override
                    public EventHubNamespaceAuthorizationRule call(AuthorizationRuleInner inner) {
                        if (inner == null) {
                            return null;
                        } else {
                            return wrapModel(inner);
                        }
                    }
                });
    }

    @Override
    public PagedList listByNamespace(final String resourceGroupName, final String namespaceName) {
        return (new PagedListConverter() {
            @Override
            public Observable typeConvertAsync(final AuthorizationRuleInner inner) {
                return Observable.just(wrapModel(inner));
            }
        }).convert(inner().listAuthorizationRules(resourceGroupName, namespaceName));
    }

    @Override
    public Observable listByNamespaceAsync(String resourceGroupName, String namespaceName) {
        return this.inner().listAuthorizationRulesAsync(resourceGroupName, namespaceName)
                .flatMapIterable(new Func1, Iterable>() {
                    @Override
                    public Iterable call(Page page) {
                        return page.items();
                    }
                })
                .map(new Func1() {
                    @Override
                    public EventHubNamespaceAuthorizationRule call(AuthorizationRuleInner inner) {
                        return wrapModel(inner);
                    }
                });
    }

    @Override
    public Completable deleteByIdAsync(String id) {
        Objects.requireNonNull(id);
        ResourceId resourceId = ResourceId.fromString(id);

        return deleteByNameAsync(resourceId.resourceGroupName(),
                resourceId.parent().name(),
                resourceId.name());
    }

    @Override
    public Completable deleteByNameAsync(String resourceGroupName, String namespaceName, String name) {
        return this.inner().deleteAuthorizationRuleAsync(resourceGroupName,
                namespaceName,
                name).toCompletable();
    }

    @Override
    public void deleteByName(String resourceGroupName, String namespaceName, String name) {
        deleteByNameAsync(resourceGroupName, namespaceName, name).await();
    }

    @Override
    protected EventHubNamespaceAuthorizationRuleImpl wrapModel(AuthorizationRuleInner innerModel) {
        return new EventHubNamespaceAuthorizationRuleImpl(innerModel.name(), innerModel, this.manager);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy