Search in sources :

Example 1 with WithHash

use of org.projectnessie.versioned.WithHash 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);
    }
}
Also used : NamedRef(org.projectnessie.versioned.NamedRef) NessieContentNotFoundException(org.projectnessie.error.NessieContentNotFoundException) GetMultipleContentsResponse(org.projectnessie.model.GetMultipleContentsResponse) ServerConfig(org.projectnessie.services.config.ServerConfig) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) ContentApi(org.projectnessie.api.ContentApi) GetMultipleContentsRequest(org.projectnessie.model.GetMultipleContentsRequest) Authorizer(org.projectnessie.services.authz.Authorizer) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Key(org.projectnessie.versioned.Key) Collectors(java.util.stream.Collectors) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) List(java.util.List) Principal(java.security.Principal) VersionStore(org.projectnessie.versioned.VersionStore) Map(java.util.Map) Content(org.projectnessie.model.Content) ContentKey(org.projectnessie.model.ContentKey) ImmutableGetMultipleContentsResponse(org.projectnessie.model.ImmutableGetMultipleContentsResponse) CommitMeta(org.projectnessie.model.CommitMeta) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) WithHash(org.projectnessie.versioned.WithHash) NamedRef(org.projectnessie.versioned.NamedRef) ContentKey(org.projectnessie.model.ContentKey) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Content(org.projectnessie.model.Content) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) Key(org.projectnessie.versioned.Key) ContentKey(org.projectnessie.model.ContentKey)

Example 2 with WithHash

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

the class TreeApiImpl method getEntries.

@Override
public EntriesResponse getEntries(String namedRef, EntriesParams params) throws NessieNotFoundException {
    Preconditions.checkArgument(params.pageToken() == null, "Paging not supported");
    WithHash<NamedRef> refWithHash = namedRefWithHashOrThrow(namedRef, params.hashOnRef());
    // all existing VersionStore implementations have to read all keys anyways so we don't get much
    try {
        List<EntriesResponse.Entry> entries;
        try (Stream<EntriesResponse.Entry> entryStream = getStore().getKeys(refWithHash.getHash()).map(key -> EntriesResponse.Entry.builder().name(fromKey(key.getValue())).type((Type) key.getType()).build())) {
            Stream<EntriesResponse.Entry> entriesStream = filterEntries(entryStream, params.filter());
            if (params.namespaceDepth() != null && params.namespaceDepth() > 0) {
                entriesStream = entriesStream.filter(e -> e.getName().getElements().size() >= params.namespaceDepth()).map(e -> truncate(e, params.namespaceDepth())).distinct();
            }
            entries = entriesStream.collect(ImmutableList.toImmutableList());
        }
        return EntriesResponse.builder().addAllEntries(entries).build();
    } catch (ReferenceNotFoundException e) {
        throw new NessieReferenceNotFoundException(e.getMessage(), e);
    }
}
Also used : Detached(org.projectnessie.model.Detached) TreeApi(org.projectnessie.api.TreeApi) ServerConfig(org.projectnessie.services.config.ServerConfig) VAR_REF_TYPE(org.projectnessie.services.cel.CELUtil.VAR_REF_TYPE) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NessieConflictException(org.projectnessie.error.NessieConflictException) GetNamedRefsParams(org.projectnessie.versioned.GetNamedRefsParams) VAR_REF(org.projectnessie.services.cel.CELUtil.VAR_REF) VersionStore(org.projectnessie.versioned.VersionStore) Delete(org.projectnessie.versioned.Delete) Type(org.projectnessie.model.Content.Type) Map(java.util.Map) Content(org.projectnessie.model.Content) Ref(org.projectnessie.versioned.Ref) NamedRef(org.projectnessie.versioned.NamedRef) VAR_CONTENT_TYPE(org.projectnessie.services.cel.CELUtil.VAR_CONTENT_TYPE) ScriptException(org.projectnessie.cel.tools.ScriptException) ImmutableMap(com.google.common.collect.ImmutableMap) Validation(org.projectnessie.model.Validation) ReferencesResponse(org.projectnessie.model.ReferencesResponse) REFERENCES_DECLARATIONS(org.projectnessie.services.cel.CELUtil.REFERENCES_DECLARATIONS) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) EntriesResponse(org.projectnessie.model.EntriesResponse) COMMIT_LOG_TYPES(org.projectnessie.services.cel.CELUtil.COMMIT_LOG_TYPES) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BranchName(org.projectnessie.versioned.BranchName) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) ENTRIES_DECLARATIONS(org.projectnessie.services.cel.CELUtil.ENTRIES_DECLARATIONS) Transplant(org.projectnessie.model.Transplant) ImmutableReferencesResponse(org.projectnessie.model.ImmutableReferencesResponse) Optional(java.util.Optional) ContentKey(org.projectnessie.model.ContentKey) CELUtil(org.projectnessie.services.cel.CELUtil) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) Put(org.projectnessie.versioned.Put) ReferenceMetadata(org.projectnessie.model.ReferenceMetadata) LogResponse(org.projectnessie.model.LogResponse) NessieReferenceAlreadyExistsException(org.projectnessie.error.NessieReferenceAlreadyExistsException) Authorizer(org.projectnessie.services.authz.Authorizer) VAR_ENTRY(org.projectnessie.services.cel.CELUtil.VAR_ENTRY) TagName(org.projectnessie.versioned.TagName) Reference(org.projectnessie.model.Reference) Strings(com.google.common.base.Strings) Script(org.projectnessie.cel.tools.Script) COMMIT_LOG_DECLARATIONS(org.projectnessie.services.cel.CELUtil.COMMIT_LOG_DECLARATIONS) ImmutableLogResponse(org.projectnessie.model.ImmutableLogResponse) ImmutableList(com.google.common.collect.ImmutableList) GetReferenceParams(org.projectnessie.api.params.GetReferenceParams) ReferencesParams(org.projectnessie.api.params.ReferencesParams) Merge(org.projectnessie.model.Merge) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) StreamSupport(java.util.stream.StreamSupport) CommitMeta(org.projectnessie.model.CommitMeta) ImmutableLogEntry(org.projectnessie.model.ImmutableLogEntry) Nullable(javax.annotation.Nullable) VAR_COMMIT(org.projectnessie.services.cel.CELUtil.VAR_COMMIT) WithHash(org.projectnessie.versioned.WithHash) Operation(org.projectnessie.model.Operation) REFERENCES_TYPES(org.projectnessie.services.cel.CELUtil.REFERENCES_TYPES) CommitLogParams(org.projectnessie.api.params.CommitLogParams) Hash(org.projectnessie.versioned.Hash) ImmutableTag(org.projectnessie.model.ImmutableTag) ImmutableBranch(org.projectnessie.model.ImmutableBranch) SCRIPT_HOST(org.projectnessie.services.cel.CELUtil.SCRIPT_HOST) Commit(org.projectnessie.versioned.Commit) ImmutableReferenceMetadata(org.projectnessie.model.ImmutableReferenceMetadata) CONTAINER(org.projectnessie.services.cel.CELUtil.CONTAINER) VAR_NAMESPACE(org.projectnessie.services.cel.CELUtil.VAR_NAMESPACE) Key(org.projectnessie.versioned.Key) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) VAR_REF_META(org.projectnessie.services.cel.CELUtil.VAR_REF_META) RetrieveOptions(org.projectnessie.versioned.GetNamedRefsParams.RetrieveOptions) EntriesParams(org.projectnessie.api.params.EntriesParams) FetchOption(org.projectnessie.api.params.FetchOption) Operations(org.projectnessie.model.Operations) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Preconditions(com.google.common.base.Preconditions) RefUtil.toNamedRef(org.projectnessie.services.impl.RefUtil.toNamedRef) Collections(java.util.Collections) VAR_OPERATIONS(org.projectnessie.services.cel.CELUtil.VAR_OPERATIONS) Unchanged(org.projectnessie.versioned.Unchanged) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ImmutableLogEntry(org.projectnessie.model.ImmutableLogEntry) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NamedRef(org.projectnessie.versioned.NamedRef) RefUtil.toNamedRef(org.projectnessie.services.impl.RefUtil.toNamedRef)

Aggregations

Principal (java.security.Principal)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)2 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)2 CommitMeta (org.projectnessie.model.CommitMeta)2 Content (org.projectnessie.model.Content)2 ContentKey (org.projectnessie.model.ContentKey)2 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collections (java.util.Collections)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 Nullable (javax.annotation.Nullable)1 ContentApi (org.projectnessie.api.ContentApi)1