Search in sources :

Example 1 with RefLogDetails

use of org.projectnessie.versioned.RefLogDetails in project nessie by projectnessie.

the class RefLogApiImpl method getRefLog.

@Override
public RefLogResponse getRefLog(RefLogParams params) throws NessieNotFoundException {
    int max = Math.min(params.maxRecords() != null ? params.maxRecords() : MAX_REF_LOG_ENTRIES, MAX_REF_LOG_ENTRIES);
    Hash endHash = null;
    if (params.endHash() != null) {
        endHash = Hash.of(Objects.requireNonNull(params.endHash()));
    }
    Hash endRef = null == params.pageToken() ? endHash : Hash.of(params.pageToken());
    try (Stream<RefLogDetails> entries = getStore().getRefLog(endRef)) {
        Stream<RefLogResponse.RefLogResponseEntry> logEntries = entries.map(entry -> {
            ImmutableRefLogResponseEntry.Builder logEntry = RefLogResponse.RefLogResponseEntry.builder();
            logEntry.refLogId(entry.getRefLogId().asString()).refName(entry.getRefName()).refType(entry.getRefType()).commitHash(entry.getCommitHash().asString()).operation(entry.getOperation()).operationTime(entry.getOperationTime()).parentRefLogId(entry.getParentRefLogId().asString());
            entry.getSourceHashes().forEach(hash -> logEntry.addSourceHashes(hash.asString()));
            return logEntry.build();
        });
        logEntries = StreamSupport.stream(StreamUtil.takeUntilIncl(logEntries.spliterator(), x -> Objects.equals(x.getRefLogId(), params.startHash())), false);
        List<RefLogResponse.RefLogResponseEntry> items = filterRefLog(logEntries, params.filter()).limit(max + 1).collect(Collectors.toList());
        if (items.size() == max + 1) {
            return ImmutableRefLogResponse.builder().addAllLogEntries(items.subList(0, max)).isHasMore(true).token(items.get(max).getRefLogId()).build();
        }
        return ImmutableRefLogResponse.builder().addAllLogEntries(items).build();
    } catch (RefLogNotFoundException e) {
        throw new NessieRefLogNotFoundException(e.getMessage(), e);
    }
}
Also used : RefLogDetails(org.projectnessie.versioned.RefLogDetails) RefLogNotFoundException(org.projectnessie.versioned.RefLogNotFoundException) NessieRefLogNotFoundException(org.projectnessie.error.NessieRefLogNotFoundException) ImmutableRefLogResponseEntry(org.projectnessie.model.ImmutableRefLogResponseEntry) NessieRefLogNotFoundException(org.projectnessie.error.NessieRefLogNotFoundException) Hash(org.projectnessie.versioned.Hash) ImmutableRefLogResponseEntry(org.projectnessie.model.ImmutableRefLogResponseEntry)

Aggregations

NessieRefLogNotFoundException (org.projectnessie.error.NessieRefLogNotFoundException)1 ImmutableRefLogResponseEntry (org.projectnessie.model.ImmutableRefLogResponseEntry)1 Hash (org.projectnessie.versioned.Hash)1 RefLogDetails (org.projectnessie.versioned.RefLogDetails)1 RefLogNotFoundException (org.projectnessie.versioned.RefLogNotFoundException)1