com.microsoft.azure.management.eventhub.implementation.EventHubAuthorizationRulesImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-mgmt-eventhub Show documentation
Show all versions of azure-mgmt-eventhub Show documentation
This package contains Microsoft EventHub Management SDK. This package has been deprecated. A replacement package com.azure.resourcemanager:azure-resourcemanager-eventhubs is available as of 31-March-2022. We strongly encourage you to upgrade to continue receiving updates. See Migration Guide https://aka.ms/java-track2-migration-guide for guidance on upgrading. Refer to our deprecation policy https://azure.github.io/azure-sdk/policies_support.html for more details.
/**
* 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.EventHubAuthorizationRule;
import com.microsoft.azure.management.eventhub.EventHubAuthorizationRules;
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 EventHubAuthorizationRules}.
*/
@LangDefinition
class EventHubAuthorizationRulesImpl
extends AuthorizationRulesBaseImpl
implements EventHubAuthorizationRules {
EventHubAuthorizationRulesImpl(EventHubManager manager) {
super(manager, manager.inner().eventHubs());
}
@Override
public EventHubAuthorizationRuleImpl define(String name) {
return new EventHubAuthorizationRuleImpl(name, this.manager);
}
@Override
public Observable getByIdAsync(String id) {
Objects.requireNonNull(id);
ResourceId resourceId = ResourceId.fromString(id);
return getByNameAsync(resourceId.resourceGroupName(),
resourceId.parent().parent().name(),
resourceId.parent().name(),
resourceId.name());
}
@Override
public EventHubAuthorizationRule getByName(String resourceGroupName, String namespaceName, String eventHubName, String name) {
return getByNameAsync(resourceGroupName, namespaceName, eventHubName, name).toBlocking().last();
}
@Override
public Observable getByNameAsync(String resourceGroupName, String namespaceName, String eventHubName, String name) {
return this.inner().getAuthorizationRuleAsync(resourceGroupName,
namespaceName,
eventHubName,
name)
.map(new Func1() {
@Override
public EventHubAuthorizationRule call(AuthorizationRuleInner inner) {
if (inner == null) {
return null;
} else {
return wrapModel(inner);
}
}
});
}
@Override
public PagedList listByEventHub(final String resourceGroupName, final String namespaceName, final String eventHubName) {
return (new PagedListConverter() {
@Override
public Observable typeConvertAsync(final AuthorizationRuleInner inner) {
return Observable.just(wrapModel(inner));
}
}).convert(inner().listAuthorizationRules(resourceGroupName, namespaceName, eventHubName));
}
@Override
public Observable listByEventHubAsync(String resourceGroupName, String namespaceName, final String eventHubName) {
return this.inner().listAuthorizationRulesAsync(resourceGroupName, namespaceName, eventHubName)
.flatMapIterable(new Func1, Iterable>() {
@Override
public Iterable call(Page page) {
return page.items();
}
})
.map(new Func1() {
@Override
public EventHubAuthorizationRule 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().parent().name(),
resourceId.parent().name(),
resourceId.name());
}
@Override
public Completable deleteByNameAsync(String resourceGroupName, String namespaceName, String eventHubName, String name) {
return this.inner().deleteAuthorizationRuleAsync(resourceGroupName,
namespaceName,
eventHubName,
name).toCompletable();
}
@Override
public void deleteByName(String resourceGroupName, String namespaceName, String eventHubName, String name) {
deleteByNameAsync(resourceGroupName, namespaceName, eventHubName, name).await();
}
@Override
protected EventHubAuthorizationRuleImpl wrapModel(AuthorizationRuleInner innerModel) {
return new EventHubAuthorizationRuleImpl(innerModel.name(), innerModel, this.manager);
}
}