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

io.sphere.sdk.shippingmethods.queries.ShippingMethodsByOrderEditGetImpl Maven / Gradle / Ivy

There is a newer version: 2.16.0
Show newest version
package io.sphere.sdk.shippingmethods.queries;

import com.fasterxml.jackson.core.type.TypeReference;
import com.neovisionaries.i18n.CountryCode;
import io.sphere.sdk.http.NameValuePair;
import io.sphere.sdk.models.Identifiable;
import io.sphere.sdk.orderedits.OrderEdit;
import io.sphere.sdk.queries.MetaModelGetDslImpl;
import io.sphere.sdk.shippingmethods.ShippingMethod;
import io.sphere.sdk.shippingmethods.expansion.ShippingMethodExpansionModel;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * {@include.example io.sphere.sdk.shippingmethods.queries.ShippingMethodsByOrderEditGetIntegrationTest#execution()}
 */
final class ShippingMethodsByOrderEditGetImpl extends MetaModelGetDslImpl, ShippingMethod, ShippingMethodsByCartGet, ShippingMethodExpansionModel>
        implements ShippingMethodsByOrderEditGet {
    ShippingMethodsByOrderEditGetImpl(final Identifiable orderEdit, final CountryCode country, @Nullable final String state) {
        super(ShippingMethodEndpoint.ENDPOINT.withTypeReference(new TypeReference>() {
            @Override
            public String toString() {
                return "TypeReference>";
            }
        }), "", ShippingMethodExpansionModel.of(), ShippingMethodsByCartGetImpl::new, createQueryParameters(orderEdit, country, state));
    }

    private static List createQueryParameters(final Identifiable orderEdit, final CountryCode country, @Nullable final String state) {
        final List queryParameters = new ArrayList<>();
        queryParameters.add(NameValuePair.of("orderEdit", orderEdit.getId()));
        queryParameters.add(NameValuePair.of("country", country.getAlpha2()));
        Optional.ofNullable(state).ifPresent(x -> queryParameters.add(NameValuePair.of("state", x)));

        return queryParameters;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy