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

io.sphere.sdk.queries.MetaModelQueryDslBuilder Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
package io.sphere.sdk.queries;

import io.sphere.sdk.expansion.ExpansionPath;
import io.sphere.sdk.http.HttpQueryParameter;
import io.sphere.sdk.http.HttpResponse;
import io.sphere.sdk.models.Base;
import io.sphere.sdk.models.Builder;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;

/**
 *
 * @param  type of the query result
 * @param  type of the class implementing this class
 * @param  type of the query model
 * @param  type of the expansion model
 */
public class MetaModelQueryDslBuilder, Q, E> extends Base implements Builder {

    protected List> predicate = Collections.emptyList();
    protected List> sort = Collections.emptyList();
    @Nullable
    protected Boolean withTotal;
    @Nullable
    protected Long limit;
    @Nullable
    protected Long offset;
    protected List> expansionPaths = Collections.emptyList();
    protected List additionalQueryParameters = Collections.emptyList();
    protected final String endpoint;
    protected final Function> resultMapper;
    protected final Q queryModel;
    protected final E expansionModel;
    protected final Function, C> queryDslBuilderFunction;


    MetaModelQueryDslBuilder(final String endpoint, final Function> resultMapper, final Q queryModel, final E expansionModel, final Function, C> queryDslBuilderFunction) {
        this.endpoint = endpoint;
        this.resultMapper = resultMapper;
        this.queryModel = queryModel;
        this.expansionModel = expansionModel;
        this.queryDslBuilderFunction = queryDslBuilderFunction;
    }

    MetaModelQueryDslBuilder(final MetaModelQueryDslImpl template) {
        this(template.endpoint(), r -> template.deserialize(r), template.getQueryModel(), template.getExpansionModel(), template.queryDslBuilderFunction);
        predicate = template.predicates();
        sort = template.sort();
        limit = template.limit();
        offset = template.offset();
        expansionPaths = template.expansionPaths();
        additionalQueryParameters = template.additionalQueryParameters();
        withTotal = template.fetchTotal();
    }

    public MetaModelQueryDslBuilder predicates(final List> predicate) {
        this.predicate = predicate;
        return this;
    }
    
    public MetaModelQueryDslBuilder sort(final List> sort) {
        this.sort = sort;
        return this;
    }

    public MetaModelQueryDslBuilder limit(@Nullable final Long limit) {
        this.limit = limit;
        return this;
    }

    public MetaModelQueryDslBuilder fetchTotal(@Nullable final Boolean fetchTotal) {
        this.withTotal = fetchTotal;
        return this;
    }

    public MetaModelQueryDslBuilder offset(@Nullable final Long offset) {
        this.offset = offset;
        return this;
    }

    public MetaModelQueryDslBuilder expansionPaths(final List> expansionPaths) {
        this.expansionPaths = expansionPaths;
        return this;
    }

    public MetaModelQueryDslBuilder additionalQueryParameters(final List additionalQueryParameters) {
        this.additionalQueryParameters = additionalQueryParameters;
        return this;
    }

    @Override
    public C build() {
        return queryDslBuilderFunction.apply(this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy