use of org.projectnessie.error.NessieReferenceNotFoundException in project nessie by projectnessie.
the class NamespaceApiImpl method getNamespaces.
@Override
public GetNamespacesResponse getNamespaces(MultipleNamespacesParams params) throws NessieReferenceNotFoundException {
BranchName branch = branchFromRefName(params.getRefName());
try {
Set<Namespace> allNamespaces = Sets.newHashSet(getExplicitlyCreatedNamespaces(params, branch));
List<Namespace> implicitlyCreatedNamespaces = getImplicitlyCreatedNamespaces(params, branch);
allNamespaces.addAll(implicitlyCreatedNamespaces);
return ImmutableGetNamespacesResponse.builder().addAllNamespaces(allNamespaces).build();
} catch (ReferenceNotFoundException e) {
throw refNotFoundException(e);
}
}
use of org.projectnessie.error.NessieReferenceNotFoundException in project nessie by projectnessie.
the class NamespaceApiImpl method createNamespace.
@Override
public Namespace createNamespace(NamespaceParams params) throws NessieNamespaceAlreadyExistsException, NessieReferenceNotFoundException {
try {
BranchName branch = branchFromRefName(params.getRefName());
Callable<Void> validator = () -> {
if (getExplicitlyCreatedNamespace(params, branch).isPresent()) {
throw namespaceAlreadyExistsException(params);
}
if (getImplicitlyCreatedNamespace(params, branch).isPresent()) {
throw namespaceAlreadyExistsException(params);
}
return null;
};
Namespace namespace = params.getNamespace();
Put put = Put.of(ContentKey.of(namespace.getElements()), namespace);
commit(branch, "create namespace " + namespace.name(), TreeApiImpl.toOp(put), validator);
return namespace;
} catch (ReferenceNotFoundException | ReferenceConflictException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
}
}
use of org.projectnessie.error.NessieReferenceNotFoundException in project nessie by projectnessie.
the class TreeApiImpl method getEntries.
@Override
public EntriesResponse getEntries(String namedRef, EntriesParams params) throws NessieNotFoundException {
Preconditions.checkArgument(params.pageToken() == null, "Paging not supported");
WithHash<NamedRef> refWithHash = namedRefWithHashOrThrow(namedRef, params.hashOnRef());
// all existing VersionStore implementations have to read all keys anyways so we don't get much
try {
List<EntriesResponse.Entry> entries;
try (Stream<EntriesResponse.Entry> entryStream = getStore().getKeys(refWithHash.getHash()).map(key -> EntriesResponse.Entry.builder().name(fromKey(key.getValue())).type((Type) key.getType()).build())) {
Stream<EntriesResponse.Entry> entriesStream = filterEntries(entryStream, params.filter());
if (params.namespaceDepth() != null && params.namespaceDepth() > 0) {
entriesStream = entriesStream.filter(e -> e.getName().getElements().size() >= params.namespaceDepth()).map(e -> truncate(e, params.namespaceDepth())).distinct();
}
entries = entriesStream.collect(ImmutableList.toImmutableList());
}
return EntriesResponse.builder().addAllEntries(entries).build();
} catch (ReferenceNotFoundException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
}
}
use of org.projectnessie.error.NessieReferenceNotFoundException in project nessie by projectnessie.
the class TreeApiImpl method transplantCommitsIntoBranch.
@Override
public void transplantCommitsIntoBranch(String branchName, String hash, String message, Transplant transplant) throws NessieNotFoundException, NessieConflictException {
try {
List<Hash> transplants;
try (Stream<Hash> s = transplant.getHashesToTransplant().stream().map(Hash::of)) {
transplants = s.collect(Collectors.toList());
}
getStore().transplant(BranchName.of(branchName), toHash(hash, true), transplants, commitMetaUpdate());
} catch (ReferenceNotFoundException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
} catch (ReferenceConflictException e) {
throw new NessieReferenceConflictException(e.getMessage(), e);
}
}
use of org.projectnessie.error.NessieReferenceNotFoundException in project nessie by projectnessie.
the class TreeApiImpl method getCommitLog.
@Override
public LogResponse getCommitLog(String namedRef, CommitLogParams params) throws NessieNotFoundException {
int max = Math.min(params.maxRecords() != null ? params.maxRecords() : MAX_COMMIT_LOG_ENTRIES, MAX_COMMIT_LOG_ENTRIES);
// we should only allow named references when no paging is defined
Ref endRef = namedRefWithHashOrThrow(namedRef, null == params.pageToken() ? params.endHash() : params.pageToken()).getHash();
boolean fetchAll = FetchOption.isFetchAll(params.fetchOption());
try (Stream<Commit<CommitMeta, Content>> commits = getStore().getCommits(endRef, fetchAll)) {
Stream<LogEntry> logEntries = commits.map(commit -> {
CommitMeta commitMetaWithHash = addHashToCommitMeta(commit.getHash(), commit.getCommitMeta());
ImmutableLogEntry.Builder logEntry = LogEntry.builder();
logEntry.commitMeta(commitMetaWithHash);
if (fetchAll) {
if (commit.getParentHash() != null) {
logEntry.parentCommitHash(commit.getParentHash().asString());
}
if (commit.getOperations() != null) {
commit.getOperations().forEach(op -> {
ContentKey key = ContentKey.of(op.getKey().getElements());
if (op instanceof Put) {
Content content = ((Put<Content>) op).getValue();
logEntry.addOperations(Operation.Put.of(key, content));
}
if (op instanceof Delete) {
logEntry.addOperations(Operation.Delete.of(key));
}
});
}
}
return logEntry.build();
});
logEntries = StreamSupport.stream(StreamUtil.takeUntilIncl(logEntries.spliterator(), x -> Objects.equals(x.getCommitMeta().getHash(), params.startHash())), false);
List<LogEntry> items = filterCommitLog(logEntries, params.filter()).limit(max + 1).collect(Collectors.toList());
if (items.size() == max + 1) {
return ImmutableLogResponse.builder().addAllLogEntries(items.subList(0, max)).isHasMore(true).token(items.get(max).getCommitMeta().getHash()).build();
}
return ImmutableLogResponse.builder().addAllLogEntries(items).build();
} catch (ReferenceNotFoundException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
}
}
Aggregations