Search in sources :

Example 1 with NessieNamespaceNotFoundException

use of org.projectnessie.error.NessieNamespaceNotFoundException in project nessie by projectnessie.

the class AbstractRestEntries method checkNamespaces.

private void checkNamespaces(Reference reference, List<String> knownNamespaces, List<ContentKey> knownContentKeys) throws NessieReferenceNotFoundException, NessieNamespaceNotFoundException {
    assertThat(getApi().getMultipleNamespaces().reference(reference).namespace("a").get().getNamespaces()).hasSize(4);
    for (String namespace : knownNamespaces) {
        Namespace ns = Namespace.parse(namespace);
        assertThat(getApi().getNamespace().reference(reference).namespace(ns).get()).isNotNull();
        assertThatThrownBy(() -> getApi().createNamespace().reference(reference).namespace(ns).create()).isInstanceOf(NessieNamespaceAlreadyExistsException.class).hasMessage(String.format("Namespace '%s' already exists", namespace));
        assertThatThrownBy(() -> getApi().deleteNamespace().reference(reference).namespace(ns).delete()).isInstanceOf(NessieNamespaceNotEmptyException.class).hasMessage(String.format("Namespace '%s' is not empty", namespace));
    }
    // unknown in the sense that these are actual tables and not namespaces
    List<String> unknownNamespaces = knownContentKeys.stream().map(ContentKey::toString).collect(Collectors.toList());
    for (String namespace : unknownNamespaces) {
        assertThatThrownBy(() -> getApi().getNamespace().reference(reference).namespace(Namespace.parse(namespace)).get()).isInstanceOf(NessieNamespaceNotFoundException.class).hasMessage(String.format("Namespace '%s' does not exist", namespace));
    }
}
Also used : NessieNamespaceNotEmptyException(org.projectnessie.error.NessieNamespaceNotEmptyException) NessieNamespaceAlreadyExistsException(org.projectnessie.error.NessieNamespaceAlreadyExistsException) NessieNamespaceNotFoundException(org.projectnessie.error.NessieNamespaceNotFoundException) Namespace(org.projectnessie.model.Namespace)

Example 2 with NessieNamespaceNotFoundException

use of org.projectnessie.error.NessieNamespaceNotFoundException in project nessie by projectnessie.

the class NamespaceApiImpl method deleteNamespace.

@Override
public void deleteNamespace(NamespaceParams params) throws NessieReferenceNotFoundException, NessieNamespaceNotEmptyException, NessieNamespaceNotFoundException {
    BranchName branch = branchFromRefName(params.getRefName());
    try {
        Namespace namespace = getNamespace(params, branch);
        Delete delete = Delete.of(ContentKey.of(namespace.getElements()));
        Callable<Void> validator = () -> {
            try (Stream<WithType<Key, Type>> keys = getStore().getKeys(branch)) {
                if (keys.anyMatch(k -> Namespace.of(k.getValue().getElements()).name().startsWith(params.getNamespace().name()) && k.getType() != Type.NAMESPACE)) {
                    throw namespaceNotEmptyException(params);
                }
            }
            return null;
        };
        commit(branch, "delete namespace " + namespace.name(), TreeApiImpl.toOp(delete), validator);
    } catch (ReferenceNotFoundException | ReferenceConflictException e) {
        throw new NessieReferenceNotFoundException(e.getMessage(), e);
    }
}
Also used : Delete(org.projectnessie.model.Operation.Delete) NessieNamespaceNotEmptyException(org.projectnessie.error.NessieNamespaceNotEmptyException) ImmutableGetNamespacesResponse(org.projectnessie.model.ImmutableGetNamespacesResponse) Put(org.projectnessie.model.Operation.Put) ServerConfig(org.projectnessie.services.config.ServerConfig) NessieNamespaceAlreadyExistsException(org.projectnessie.error.NessieNamespaceAlreadyExistsException) Authorizer(org.projectnessie.services.authz.Authorizer) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NamespaceApi(org.projectnessie.api.NamespaceApi) Callable(java.util.concurrent.Callable) GetNamespacesResponse(org.projectnessie.model.GetNamespacesResponse) MultipleNamespacesParams(org.projectnessie.api.params.MultipleNamespacesParams) WithType(org.projectnessie.versioned.WithType) VersionStore(org.projectnessie.versioned.VersionStore) Type(org.projectnessie.model.Content.Type) Map(java.util.Map) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) NessieNamespaceNotFoundException(org.projectnessie.error.NessieNamespaceNotFoundException) Nullable(javax.annotation.Nullable) NamespaceParams(org.projectnessie.api.params.NamespaceParams) Set(java.util.Set) Operation(org.projectnessie.versioned.Operation) Key(org.projectnessie.versioned.Key) Collectors(java.util.stream.Collectors) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) Sets(com.google.common.collect.Sets) BranchName(org.projectnessie.versioned.BranchName) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) Delete(org.projectnessie.model.Operation.Delete) Namespace(org.projectnessie.model.Namespace) Optional(java.util.Optional) ContentKey(org.projectnessie.model.ContentKey) Collections(java.util.Collections) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) Namespace(org.projectnessie.model.Namespace) WithType(org.projectnessie.versioned.WithType) Type(org.projectnessie.model.Content.Type) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Stream(java.util.stream.Stream) BranchName(org.projectnessie.versioned.BranchName) Key(org.projectnessie.versioned.Key) ContentKey(org.projectnessie.model.ContentKey)

Aggregations

NessieNamespaceAlreadyExistsException (org.projectnessie.error.NessieNamespaceAlreadyExistsException)2 NessieNamespaceNotEmptyException (org.projectnessie.error.NessieNamespaceNotEmptyException)2 NessieNamespaceNotFoundException (org.projectnessie.error.NessieNamespaceNotFoundException)2 Namespace (org.projectnessie.model.Namespace)2 Sets (com.google.common.collect.Sets)1 Principal (java.security.Principal)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Nullable (javax.annotation.Nullable)1 NamespaceApi (org.projectnessie.api.NamespaceApi)1 MultipleNamespacesParams (org.projectnessie.api.params.MultipleNamespacesParams)1 NamespaceParams (org.projectnessie.api.params.NamespaceParams)1 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)1 CommitMeta (org.projectnessie.model.CommitMeta)1