All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.camunda.service.transformers.query.SearchQueryResultTransformer Maven / Gradle / Ivy

There is a newer version: 8.7.0-alpha2
Show newest version
/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Licensed under the Camunda License 1.0. You may not use this file
 * except in compliance with the Camunda License 1.0.
 */
package io.camunda.service.transformers.query;

import io.camunda.search.clients.core.SearchQueryHit;
import io.camunda.search.clients.core.SearchQueryResponse;
import io.camunda.service.search.query.SearchQueryResult;
import io.camunda.service.search.query.SearchQueryResult.Builder;
import io.camunda.service.transformers.ServiceTransformer;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public final class SearchQueryResultTransformer
    implements ServiceTransformer, SearchQueryResult> {

  @Override
  public SearchQueryResult apply(final SearchQueryResponse value) {
    final var hits = value.hits();
    final var items = of(hits);
    final var size = hits.size();
    final Object[] sortValues;
    if (size > 0) {
      final var lastItem = hits.get(size - 1);
      sortValues = lastItem.sortValues();
    } else {
      sortValues = null;
    }

    return new Builder().total(value.totalHits()).sortValues(sortValues).items(items).build();
  }

  private List of(final List> values) {
    if (values != null) {
      return values.stream().map(SearchQueryHit::source).collect(Collectors.toList());
    }
    return Collections.emptyList();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy