
io.sphere.internal.ProductServiceImpl Maven / Gradle / Ivy
package io.sphere.internal;
import io.sphere.client.QueryRequest;
import io.sphere.internal.request.ProductRequestFactory;
import io.sphere.client.FetchRequest;
import io.sphere.client.filters.expressions.FilterExpression;
import io.sphere.client.ProjectEndpoints;
import io.sphere.client.shop.ApiMode;
import io.sphere.client.shop.ProductService;
import io.sphere.client.SearchRequest;
import io.sphere.client.shop.model.Product;
import static io.sphere.internal.util.ListUtil.list;
import com.google.common.collect.ImmutableList;
import net.jcip.annotations.Immutable;
import java.util.Locale;
@Immutable
public final class ProductServiceImpl extends ProjectScopedAPI implements ProductService {
private final ProductRequestFactory requestFactory;
private ApiMode apiMode;
private final Locale defaultLocale;
public ProductServiceImpl(ProductRequestFactory requestFactory, ApiMode apiMode, ProjectEndpoints endpoints, Locale defaultLocale) {
super(endpoints);
this.requestFactory = requestFactory;
this.apiMode = apiMode;
this.defaultLocale = defaultLocale;
}
@Override public FetchRequest byId(String id) {
return requestFactory.createFetchRequest(endpoints.products.byId(id), this.apiMode);
}
@Override public FetchRequest bySlug(Locale locale, String slug) {
return requestFactory.createFetchRequestBasedOnQuery(endpoints.products.bySlug(locale, slug), this.apiMode);
}
@Override public FetchRequest bySlug(String slug) {
return bySlug(defaultLocale, slug);
}
private static final ImmutableList noFilters = ImmutableList.of();
@Override public SearchRequest all(Locale locale) {
return filter(locale, noFilters);
}
@Override
public SearchRequest all() {
return all(defaultLocale);
}
@Override public SearchRequest filter(Locale locale, FilterExpression filter, FilterExpression... filters) {
return filter(locale, list(filter, filters));
}
@Override
public SearchRequest filter(FilterExpression filter, FilterExpression... filters) {
return filter(defaultLocale, filter, filters);
}
@Override public SearchRequest filter(Locale locale, Iterable filters) {
return requestFactory.createSearchRequest(endpoints.products.search(), this.apiMode, filters, locale);
}
@Override
public QueryRequest query() {
return requestFactory.createQueryRequest(endpoints.products.root(), this.apiMode);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy