Search in sources :

Example 1 with GetResults

use of com.enonic.xp.repo.impl.storage.GetResults in project xp by enonic.

the class StorageDaoImpl method getByIds.

@Override
public GetResults getByIds(final GetByIdsRequest requests) {
    if (requests.getRequests().isEmpty()) {
        return new GetResults();
    }
    final MultiGetRequestBuilder multiGetRequestBuilder = new MultiGetRequestBuilder(this.client, MultiGetAction.INSTANCE).setPreference(SearchPreference.LOCAL.getName());
    for (final GetByIdRequest request : requests.getRequests()) {
        final StorageSource storageSource = request.getStorageSource();
        final MultiGetRequest.Item item = new MultiGetRequest.Item(storageSource.getStorageName().getName(), storageSource.getStorageType().getName(), request.getId());
        if (request.getReturnFields().isNotEmpty()) {
            item.fields(request.getReturnFields().getReturnFieldNames());
        }
        if (request.getRouting() != null) {
            item.routing(request.getRouting());
        }
        multiGetRequestBuilder.add(item);
    }
    final MultiGetResponse multiGetItemResponses = this.client.multiGet(multiGetRequestBuilder.request()).actionGet();
    return GetResultsFactory.create(multiGetItemResponses);
}
Also used : MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) GetByIdRequest(com.enonic.xp.repo.impl.storage.GetByIdRequest) GetResults(com.enonic.xp.repo.impl.storage.GetResults) StorageSource(com.enonic.xp.repo.impl.StorageSource) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest)

Example 2 with GetResults

use of com.enonic.xp.repo.impl.storage.GetResults in project xp by enonic.

the class GetBranchEntriesMethod method execute.

@Override
public void execute(final Collection<NodeId> nodeIds, final NodeBranchEntries.Builder builder) {
    final GetByIdsRequest getByIdsRequest = new GetByIdsRequest();
    for (final NodeId nodeId : nodeIds) {
        getByIdsRequest.add(GetByIdRequest.create().id(new BranchDocumentId(nodeId, context.getBranch()).toString()).storageSettings(StorageSource.create().storageName(StoreStorageName.from(context.getRepositoryId())).storageType(StaticStorageType.BRANCH).build()).returnFields(returnFields).routing(nodeId.toString()).build());
    }
    final GetResults getResults = this.storageDao.getByIds(getByIdsRequest);
    for (final GetResult getResult : getResults) {
        if (!getResult.isEmpty()) {
            final NodeBranchEntry nodeBranchEntry = NodeBranchVersionFactory.create(getResult.getReturnValues());
            builder.add(nodeBranchEntry);
        }
    }
}
Also used : GetResult(com.enonic.xp.repo.impl.storage.GetResult) NodeId(com.enonic.xp.node.NodeId) GetResults(com.enonic.xp.repo.impl.storage.GetResults) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) GetByIdsRequest(com.enonic.xp.repo.impl.storage.GetByIdsRequest)

Example 3 with GetResults

use of com.enonic.xp.repo.impl.storage.GetResults in project xp by enonic.

the class GetResultsFactory method create.

public static GetResults create(final MultiGetResponse getResponse) {
    final MultiGetItemResponse[] responses = getResponse.getResponses();
    final GetResults getResults = new GetResults();
    for (final MultiGetItemResponse response : responses) {
        getResults.add(GetResultFactory.create(response.getResponse()));
    }
    return getResults;
}
Also used : MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) GetResults(com.enonic.xp.repo.impl.storage.GetResults)

Aggregations

GetResults (com.enonic.xp.repo.impl.storage.GetResults)3 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)1 NodeId (com.enonic.xp.node.NodeId)1 StorageSource (com.enonic.xp.repo.impl.StorageSource)1 GetByIdRequest (com.enonic.xp.repo.impl.storage.GetByIdRequest)1 GetByIdsRequest (com.enonic.xp.repo.impl.storage.GetByIdsRequest)1 GetResult (com.enonic.xp.repo.impl.storage.GetResult)1 MultiGetItemResponse (org.elasticsearch.action.get.MultiGetItemResponse)1 MultiGetRequest (org.elasticsearch.action.get.MultiGetRequest)1 MultiGetRequestBuilder (org.elasticsearch.action.get.MultiGetRequestBuilder)1 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)1