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

com.azure.resourcemanager.cosmos.implementation.PrivateEndpointConnectionsImpl Maven / Gradle / Ivy

Go to download

This package contains Microsoft Azure CosmosDB SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt

There is a newer version: 2.46.0
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.resourcemanager.cosmos.implementation;

import com.azure.core.http.rest.PagedFlux;
import com.azure.resourcemanager.cosmos.fluent.PrivateEndpointConnectionsClient;
import com.azure.resourcemanager.cosmos.fluent.models.PrivateEndpointConnectionInner;
import com.azure.resourcemanager.cosmos.models.CosmosDBAccount;
import com.azure.resourcemanager.cosmos.models.PrivateEndpointConnection;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.implementation.ExternalChildResourcesCachedImpl;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.azure.resourcemanager.resources.fluentcore.utils.PagedConverter;

/** Represents a private endpoint connection collection. */
class PrivateEndpointConnectionsImpl
    extends ExternalChildResourcesCachedImpl<
        PrivateEndpointConnectionImpl,
        PrivateEndpointConnection,
        PrivateEndpointConnectionInner,
        CosmosDBAccountImpl,
        CosmosDBAccount> {
    private final PrivateEndpointConnectionsClient client;

    PrivateEndpointConnectionsImpl(PrivateEndpointConnectionsClient client, CosmosDBAccountImpl parent) {
        super(parent, parent.taskGroup(), "PrivateEndpointConnection");
        this.client = client;
    }

    public PrivateEndpointConnectionImpl define(String name) {
        return this.prepareInlineDefine(name);
    }

    public PrivateEndpointConnectionImpl update(String name) {
        if (this.collection().size() == 0) {
            this.cacheCollection();
        }
        return this.prepareInlineUpdate(name);
    }

    public void remove(String name) {
        if (this.collection().size() == 0) {
            this.cacheCollection();
        }
        this.prepareInlineRemove(name);
    }

    public Map asMap() {
        return asMapAsync().block();
    }

    public Mono> asMapAsync() {
        return listAsync()
            .collectList()
            .map(
                privateEndpointConnections -> {
                    Map privateEndpointConnectionMap = new HashMap<>();
                    for (PrivateEndpointConnectionImpl privateEndpointConnection : privateEndpointConnections) {
                        privateEndpointConnectionMap.put(privateEndpointConnection.name(), privateEndpointConnection);
                    }
                    return privateEndpointConnectionMap;
                });
    }

    public PagedFlux listAsync() {
        final PrivateEndpointConnectionsImpl self = this;
        return PagedConverter.mapPage(this
            .client
            .listByDatabaseAccountAsync(this.getParent().resourceGroupName(), this.getParent().name()),
                inner -> {
                    PrivateEndpointConnectionImpl childResource =
                        new PrivateEndpointConnectionImpl(inner.name(), self.getParent(), inner, client);
                    self.addPrivateEndpointConnection(childResource);
                    return childResource;
                });
    }

    public Mono getImplAsync(String name) {
        final PrivateEndpointConnectionsImpl self = this;
        return this
            .client
            .getAsync(getParent().resourceGroupName(), getParent().name(), name)
            .map(
                inner -> {
                    PrivateEndpointConnectionImpl childResource =
                        new PrivateEndpointConnectionImpl(inner.name(), getParent(), inner, client);
                    self.addPrivateEndpointConnection(childResource);
                    return childResource;
                });
    }

    @Override
    protected Flux listChildResourcesAsync() {
        return listAsync();
    }

    @Override
    protected List listChildResources() {
        return listAsync().collectList().block();
    }

    @Override
    protected PrivateEndpointConnectionImpl newChildResource(String name) {
        return new PrivateEndpointConnectionImpl(name, getParent(), new PrivateEndpointConnectionInner(), this.client);
    }

    public void addPrivateEndpointConnection(PrivateEndpointConnectionImpl privateEndpointConnection) {
        this.addChildResource(privateEndpointConnection);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy