Search in sources :

Example 36 with CommitMeta

use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.

the class BaseApiImpl method namedRefWithHashOrThrow.

WithHash<NamedRef> namedRefWithHashOrThrow(@Nullable String namedRef, @Nullable String hashOnRef) throws NessieNotFoundException {
    if (null == namedRef) {
        namedRef = config.getDefaultBranch();
    }
    if (DetachedRef.REF_NAME.equals(namedRef)) {
        Objects.requireNonNull(hashOnRef, String.format("hashOnRef must not be null for '%s'", DetachedRef.REF_NAME));
        return WithHash.of(Hash.of(hashOnRef), DetachedRef.INSTANCE);
    }
    WithHash<NamedRef> namedRefWithHash;
    try {
        ReferenceInfo<CommitMeta> ref = getStore().getNamedRef(namedRef, GetNamedRefsParams.DEFAULT);
        namedRefWithHash = WithHash.of(ref.getHash(), ref.getNamedRef());
    } catch (ReferenceNotFoundException e) {
        throw new NessieReferenceNotFoundException(e.getMessage(), e);
    }
    try {
        if (null == hashOnRef) {
            return namedRefWithHash;
        }
        if (store.noAncestorHash().asString().equals(hashOnRef)) {
            // necessarily the same, so construct a new instance to return.
            return WithHash.of(store.noAncestorHash(), namedRefWithHash.getValue());
        }
        // hash actually exists on the named reference and return early here
        if (namedRefWithHash.getHash().asString().equals(hashOnRef)) {
            return namedRefWithHash;
        }
        // we need to make sure that the hash in fact exists on the named ref
        return WithHash.of(getStore().hashOnReference(namedRefWithHash.getValue(), Optional.of(Hash.of(hashOnRef))), namedRefWithHash.getValue());
    } catch (ReferenceNotFoundException e) {
        throw new NessieReferenceNotFoundException(e.getMessage(), e);
    }
}
Also used : NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NamedRef(org.projectnessie.versioned.NamedRef) CommitMeta(org.projectnessie.model.CommitMeta)

Example 37 with CommitMeta

use of org.projectnessie.model.CommitMeta in project nessie by projectnessie.

the class TestNessieIcebergViews method verifyCommitMetadata.

private void verifyCommitMetadata() throws NessieNotFoundException {
    // check that the author is properly set
    List<LogEntry> log = api.getCommitLog().refName(BRANCH).get().getLogEntries();
    assertThat(log).isNotNull().isNotEmpty().allSatisfy(logEntry -> {
        CommitMeta commit = logEntry.getCommitMeta();
        assertThat(commit.getAuthor()).isNotNull().isNotEmpty();
        assertThat(commit.getAuthor()).isEqualTo(System.getProperty("user.name"));
        assertThat(commit.getProperties().get(NessieUtil.APPLICATION_TYPE)).isEqualTo("iceberg");
        assertThat(commit.getMessage()).startsWith("Iceberg");
    });
}
Also used : CommitMeta(org.projectnessie.model.CommitMeta) LogEntry(org.projectnessie.model.LogResponse.LogEntry)

Aggregations

CommitMeta (org.projectnessie.model.CommitMeta)37 Branch (org.projectnessie.model.Branch)17 LogEntry (org.projectnessie.model.LogResponse.LogEntry)15 Test (org.junit.jupiter.api.Test)14 IcebergTable (org.projectnessie.model.IcebergTable)14 ContentKey (org.projectnessie.model.ContentKey)13 LogResponse (org.projectnessie.model.LogResponse)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Content (org.projectnessie.model.Content)10 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)8 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)8 Reference (org.projectnessie.model.Reference)7 ArrayList (java.util.ArrayList)6 Entry (org.projectnessie.model.EntriesResponse.Entry)6 Operation (org.projectnessie.model.Operation)6 Put (org.projectnessie.model.Operation.Put)6 Stream (java.util.stream.Stream)5