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);
}
}
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);
}
}
Aggregations