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

io.quarkiverse.openfga.client.AuthorizationModelsClient Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package io.quarkiverse.openfga.client;

import static io.quarkiverse.openfga.client.utils.PaginatedList.collectAllPages;

import java.util.List;

import javax.annotation.Nullable;

import io.quarkiverse.openfga.client.api.API;
import io.quarkiverse.openfga.client.model.AuthorizationModel;
import io.quarkiverse.openfga.client.model.TypeDefinition;
import io.quarkiverse.openfga.client.model.TypeDefinitions;
import io.quarkiverse.openfga.client.model.dto.WriteAuthorizationModelResponse;
import io.quarkiverse.openfga.client.utils.PaginatedList;
import io.smallrye.mutiny.Uni;

public class AuthorizationModelsClient {

    private final API api;
    private final Uni storeId;

    public AuthorizationModelsClient(API api, Uni storeId) {
        this.api = api;
        this.storeId = storeId;
    }

    public Uni> list(@Nullable Integer pageSize, @Nullable String pagingToken) {
        return storeId.flatMap(storeId -> api.readAuthorizationModels(storeId, pageSize, pagingToken))
                .map(res -> new PaginatedList<>(res.getAuthorizationModels(), res.getContinuationToken()));
    }

    public Uni> listAll() {
        return listAll(null);
    }

    public Uni> listAll(@Nullable Integer pageSize) {
        return collectAllPages(pageSize, this::list);
    }

    @Deprecated
    public Uni create(List typeDefinitions) {
        return create(new TypeDefinitions(typeDefinitions));
    }

    public Uni create(TypeDefinitions typeDefinitions) {
        return storeId.flatMap(storeId -> api.writeAuthorizationModel(storeId, typeDefinitions))
                .map(WriteAuthorizationModelResponse::getAuthorizationModelId);
    }

    public AuthorizationModelClient model(String authorizationModelId) {
        return new AuthorizationModelClient(api, storeId, authorizationModelId);
    }

    public AuthorizationModelClient defaultModel() {
        return new AuthorizationModelClient(api, storeId, null);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy