Search in sources :

Example 11 with NessieReferenceNotFoundException

use of org.projectnessie.error.NessieReferenceNotFoundException in project nessie by projectnessie.

the class TreeApiImpl method createReference.

@Override
public Reference createReference(String sourceRefName, Reference reference) throws NessieNotFoundException, NessieConflictException {
    Validation.validateForbiddenReferenceName(reference.getName());
    NamedRef namedReference = toNamedRef(reference);
    if (reference.getType() == Reference.ReferenceType.TAG && reference.getHash() == null) {
        throw new IllegalArgumentException("Tag-creation requires a target named-reference and hash.");
    }
    try {
        Hash hash = getStore().create(namedReference, toHash(reference.getHash(), false));
        return RefUtil.toReference(namedReference, hash);
    } catch (ReferenceNotFoundException e) {
        throw new NessieReferenceNotFoundException(e.getMessage(), e);
    } catch (ReferenceAlreadyExistsException e) {
        throw new NessieReferenceAlreadyExistsException(e.getMessage(), e);
    }
}
Also used : NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) NessieReferenceAlreadyExistsException(org.projectnessie.error.NessieReferenceAlreadyExistsException) NamedRef(org.projectnessie.versioned.NamedRef) RefUtil.toNamedRef(org.projectnessie.services.impl.RefUtil.toNamedRef) WithHash(org.projectnessie.versioned.WithHash) Hash(org.projectnessie.versioned.Hash) NessieReferenceAlreadyExistsException(org.projectnessie.error.NessieReferenceAlreadyExistsException)

Example 12 with NessieReferenceNotFoundException

use of org.projectnessie.error.NessieReferenceNotFoundException 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)

Aggregations

NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)12 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)11 CommitMeta (org.projectnessie.model.CommitMeta)8 ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)6 Content (org.projectnessie.model.Content)5 ContentKey (org.projectnessie.model.ContentKey)5 WithHash (org.projectnessie.versioned.WithHash)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 NessieReferenceConflictException (org.projectnessie.error.NessieReferenceConflictException)4 NamedRef (org.projectnessie.versioned.NamedRef)4 Principal (java.security.Principal)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Namespace (org.projectnessie.model.Namespace)3 Put (org.projectnessie.model.Operation.Put)3 RefUtil.toNamedRef (org.projectnessie.services.impl.RefUtil.toNamedRef)3 BranchName (org.projectnessie.versioned.BranchName)3 Hash (org.projectnessie.versioned.Hash)3 Collections (java.util.Collections)2