use of org.projectnessie.versioned.NamedRef in project nessie by projectnessie.
the class AbstractGetNamedReferences method verifyReferences.
private void verifyReferences(GetNamedRefsParams params, ExpectedNamedReference... references) throws ReferenceNotFoundException {
List<ReferenceInfo<ByteString>> expectedRefs = Arrays.stream(references).map(expectedRef -> expectedRef.expected(params)).filter(Objects::nonNull).collect(Collectors.toList());
try (Stream<ReferenceInfo<ByteString>> refs = databaseAdapter.namedRefs(params)) {
assertThat(refs).describedAs("GetNamedRefsParams=%s - references=%s", params, references).containsExactlyInAnyOrderElementsOf(expectedRefs);
}
for (ReferenceInfo<ByteString> expected : expectedRefs) {
assertThat(databaseAdapter.namedRef(expected.getNamedRef().getName(), params)).isEqualTo(expected);
}
List<NamedRef> failureRefs = Arrays.stream(references).map(expectedRef -> {
ReferenceInfo<ByteString> expected = expectedRef.expected(params);
if (expected == null) {
return expectedRef.ref;
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
for (NamedRef ref : failureRefs) {
assertThatThrownBy(() -> databaseAdapter.namedRef(ref.getName(), params));
}
}
use of org.projectnessie.versioned.NamedRef in project nessie by projectnessie.
the class TxDatabaseAdapter method fetchNamedRefs.
protected Stream<ReferenceInfo<ByteString>> fetchNamedRefs(ConnectionWrapper conn) {
return JdbcSelectSpliterator.buildStream(conn.conn(), SqlStatements.SELECT_NAMED_REFERENCES, ps -> ps.setString(1, config.getRepositoryId()), (rs) -> {
String type = rs.getString(1);
String ref = rs.getString(2);
Hash head = Hash.of(rs.getString(3));
NamedRef namedRef = namedRefFromRow(type, ref);
if (namedRef != null) {
return ReferenceInfo.of(head, namedRef);
}
return null;
});
}
use of org.projectnessie.versioned.NamedRef in project nessie by projectnessie.
the class ContentApiImpl method getMultipleContents.
@Override
public GetMultipleContentsResponse getMultipleContents(String namedRef, String hashOnRef, GetMultipleContentsRequest request) throws NessieNotFoundException {
try {
WithHash<NamedRef> ref = namedRefWithHashOrThrow(namedRef, hashOnRef);
List<ContentKey> externalKeys = request.getRequestedKeys();
List<Key> internalKeys = externalKeys.stream().map(ContentApiImpl::toKey).collect(Collectors.toList());
Map<Key, Content> values = getStore().getValues(ref.getHash(), internalKeys);
List<ContentWithKey> output = values.entrySet().stream().map(e -> ContentWithKey.of(toContentKey(e.getKey()), e.getValue())).collect(Collectors.toList());
return ImmutableGetMultipleContentsResponse.builder().contents(output).build();
} catch (ReferenceNotFoundException ex) {
throw new NessieReferenceNotFoundException(ex.getMessage(), ex);
}
}
use of org.projectnessie.versioned.NamedRef in project nessie by projectnessie.
the class ContentApiImplWithAuthorization method getContent.
@Override
public Content getContent(ContentKey key, String namedRef, String hashOnRef) throws NessieNotFoundException {
NamedRef ref = namedRefWithHashOrThrow(namedRef, hashOnRef).getValue();
startAccessCheck().canReadEntityValue(ref, key, null).checkAndThrow();
return super.getContent(key, namedRef, hashOnRef);
}
use of org.projectnessie.versioned.NamedRef in project nessie by projectnessie.
the class ContentApiImplWithAuthorization method getMultipleContents.
@Override
public GetMultipleContentsResponse getMultipleContents(String namedRef, String hashOnRef, GetMultipleContentsRequest request) throws NessieNotFoundException {
WithHash<NamedRef> ref = namedRefWithHashOrThrow(namedRef, hashOnRef);
BatchAccessChecker check = startAccessCheck();
request.getRequestedKeys().forEach(k -> check.canReadEntityValue(ref.getValue(), k, null));
check.checkAndThrow();
return super.getMultipleContents(namedRef, hashOnRef, request);
}
Aggregations