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

io.camunda.service.search.query.ProcessInstanceQuery 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.search.query;

import io.camunda.service.search.filter.FilterBuilders;
import io.camunda.service.search.filter.ProcessInstanceFilter;
import io.camunda.service.search.page.SearchQueryPage;
import io.camunda.service.search.sort.ProcessInstanceSort;
import io.camunda.service.search.sort.SortOptionBuilders;
import io.camunda.util.ObjectBuilder;
import java.util.Objects;
import java.util.function.Function;

public final record ProcessInstanceQuery(
    ProcessInstanceFilter filter, ProcessInstanceSort sort, SearchQueryPage page)
    implements TypedSearchQuery {

  public static ProcessInstanceQuery of(
      final Function> fn) {
    return fn.apply(new Builder()).build();
  }

  public static final class Builder extends SearchQueryBase.AbstractQueryBuilder
      implements TypedSearchQueryBuilder<
          ProcessInstanceQuery, Builder, ProcessInstanceFilter, ProcessInstanceSort> {

    private static final ProcessInstanceFilter EMPTY_FILTER =
        FilterBuilders.processInstance().build();
    private static final ProcessInstanceSort EMPTY_SORT =
        SortOptionBuilders.processInstance().build();

    private ProcessInstanceFilter filter;
    private ProcessInstanceSort sort;

    public Builder filter(final ProcessInstanceFilter value) {
      filter = value;
      return this;
    }

    public Builder filter(
        final Function> fn) {
      return filter(FilterBuilders.processInstance(fn));
    }

    public Builder sort(final ProcessInstanceSort value) {
      sort = value;
      return this;
    }

    public Builder sort(
        final Function> fn) {
      return sort(SortOptionBuilders.processInstance(fn));
    }

    @Override
    protected Builder self() {
      return this;
    }

    @Override
    public ProcessInstanceQuery build() {
      filter = Objects.requireNonNullElse(filter, EMPTY_FILTER);
      sort = Objects.requireNonNullElse(sort, EMPTY_SORT);
      return new ProcessInstanceQuery(filter, sort, page());
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy