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

io.sphere.sdk.zones.queries.ZoneQuery Maven / Gradle / Ivy

There is a newer version: 2.16.0
Show newest version
/*
This class has been generated by class io.sphere.sdk.annotations.processors.HasQueryEndpointAnnotationProcessor
induced by the annotation io.sphere.sdk.annotations.HasQueryEndpoint.
in the source class io.sphere.sdk.zones.Zone.
To render this class the handlebars template 'queries/resourceQueryInterface.hbs' has been used.
*/
package io.sphere.sdk.zones.queries;

import com.fasterxml.jackson.core.type.TypeReference;
import io.sphere.sdk.zones.Zone;
import io.sphere.sdk.zones.expansion.ZoneExpansionModel;
import io.sphere.sdk.expansion.ExpansionPathContainer;
import io.sphere.sdk.queries.PagedQueryResult;
import io.sphere.sdk.queries.MetaModelQueryDsl;
import io.sphere.sdk.queries.QueryPredicate;
import io.sphere.sdk.queries.QuerySort;


//common imports
    
import com.neovisionaries.i18n.CountryCode;
    
import io.sphere.sdk.zones.Location;
    


import java.util.List;
import java.util.Locale;
import java.util.function.Function;
import java.util.Optional;

/**
 * {@doc.gen summary zones
 */
public interface ZoneQuery extends MetaModelQueryDsl> {

    /**
     * Creates a container which contains the full Java type information to deserialize the query result (NOT this class) from JSON.
     *
     * @see io.sphere.sdk.json.SphereJsonUtils#readObject(byte[], TypeReference)
     * @see io.sphere.sdk.json.SphereJsonUtils#readObject(String, TypeReference)
     * @see io.sphere.sdk.json.SphereJsonUtils#readObject(com.fasterxml.jackson.databind.JsonNode, TypeReference)
     * @see io.sphere.sdk.json.SphereJsonUtils#readObjectFromResource(String, TypeReference)
     *
     * @return type reference
     */
    static TypeReference> resultTypeReference() {
        return new TypeReference>() {
            @Override
            public String toString() {
                return "TypeReference>";
            }
        };
    }

    static ZoneQuery of() {
        return new ZoneQueryImpl();
    }

    @Override
    ZoneQuery plusPredicates(final Function> m);

    @Override
    ZoneQuery plusPredicates(final QueryPredicate queryPredicate);

    @Override
    ZoneQuery plusPredicates(final List> queryPredicates);

    @Override
    ZoneQuery plusSort(final Function> m);

    @Override
    ZoneQuery plusSort(final List> sort);

    @Override
    ZoneQuery plusSort(final QuerySort sort);

    @Override
    ZoneQuery withPredicates(final Function> predicateFunction);

    @Override
    ZoneQuery withPredicates(final QueryPredicate queryPredicate);

    @Override
    ZoneQuery withPredicates(final List> queryPredicates);

    @Override
    ZoneQuery withSort(final Function> m);

    @Override
    ZoneQuery withSort(final List> sort);

    @Override
    ZoneQuery withSort(final QuerySort sort);

    @Override
    ZoneQuery withSortMulti(final Function>> m);

    @Override
    ZoneQuery plusExpansionPaths(final Function, ExpansionPathContainer> m);

    @Override
    ZoneQuery withExpansionPaths(final Function, ExpansionPathContainer> m);

    @Override
    ZoneQuery withFetchTotal(final boolean fetchTotal);

    @Override
    ZoneQuery withLimit(final Long limit);

    @Override
    ZoneQuery withOffset(final Long offset);

    
    default ZoneQuery byName(final String name) {
        return withPredicates(m -> m.name().is(name));
    }

    /**
     * Predicate which matches the country of a location, does not take the state into the consideration.
     * For considering also the state use {@link #byLocation(io.sphere.sdk.zones.Location)}.
     * @param countryCode the country to query for
     * @return query with the same values but a predicate searching for a specific country
     */
    default ZoneQuery byCountry(final CountryCode countryCode) {
        return withPredicates(m -> m.locations().country().is(countryCode));
    }

    /**
     * Predicate which matches the country and state of a location.
     *
     * For ignoring the state use {@link #byCountry(com.neovisionaries.i18n.CountryCode)}.
     * @param location the location to query for
     * @return query with the same values but a predicate searching for a specific location
     */
    default ZoneQuery byLocation(final Location location) {
        final QueryPredicate predicate =
                Optional.ofNullable(location.getState())
                        .map(state -> ZoneQueryModel.of().locations().where(l -> l.country().is(location.getCountry()).and(l.state().is(state))))
                        .orElseGet(() -> ZoneQueryModel.of().locations().where(l -> l.country().is(location.getCountry()).and(l.state().isNotPresent())));
        return withPredicates(predicate);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy