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));
}
}
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);
}
}
Aggregations