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

com.shopify.model.ShopifyProductUpdateRequest Maven / Gradle / Ivy

package com.shopify.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

public class ShopifyProductUpdateRequest implements ShopifyProductRequest {

	private final ShopifyProduct request;
	private final Map variantPositionToImagePosition;
	private final boolean changed;

	public static interface CurrentShopifyProductStep {
		public TitleStep withCurrentShopifyProduct(final ShopifyProduct shopifyProduct);
	}

	public static interface TitleStep {
		public MetafieldsGlobalTitleTagStep withTitle(final String title);

		public MetafieldsGlobalTitleTagStep withSameTitle();
	}

	public static interface MetafieldsGlobalTitleTagStep {
		public ProductTypeStep withMetafieldsGlobalTitleTag(final String metafieldsGlobalTitleTag);

		public ProductTypeStep withSameMetafieldsGlobalTitleTag();
	}

	public static interface ProductTypeStep {
		public BodyHtmlStep withProductType(final String productType);

		public BodyHtmlStep withSameProductType();
	}

	public static interface BodyHtmlStep {
		public MetafieldsGlobalDescriptionTagStep withBodyHtml(final String bodyHtml);

		public MetafieldsGlobalDescriptionTagStep withSameBodyHtml();
	}

	public static interface MetafieldsGlobalDescriptionTagStep {
		public VendorStep withMetafieldsGlobalDescriptionTag(final String metafieldsGlobalDescriptionTag);

		public VendorStep withSameMetafieldsGlobalDescriptionTag();
	}

	public static interface VendorStep {
		public TagsStep withVendor(final String vendor);

		public TagsStep withSameVendor();
	}

	public static interface TagsStep {
		public SortedOptionNamesStep withTags(final Set tags);

		public SortedOptionNamesStep withSameTags();
	}

	public static interface SortedOptionNamesStep {
		public ImageSourcesStep withSortedOptionNames(final List sortedOptionNames);

		public ImageSourcesStep withSameOptions();
	}

	public static interface ImageSourcesStep {
		public VariantUpdateRequestsStep withImageSources(final List imageSources);

		public VariantUpdateRequestsStep withSameImages();
	}

	public static interface VariantUpdateRequestsStep {
		public PublishedStep withVariantRequests(final List variantRequests);

		public PublishedStep withSameVariants();
	}

	public static interface PublishedStep {
		public BuildStep withPublished(final boolean published);
	}

	public static interface BuildStep {
		public ShopifyProductUpdateRequest build();
	}

	public static CurrentShopifyProductStep newBuilder() {
		return new Steps();
	}

	@Override
	public ShopifyProduct getRequest() {
		return request;
	}

	@Override
	public int getVariantImagePosition(final int variantPosition) {
		return variantPositionToImagePosition.get(variantPosition);
	}

	@Override
	public boolean hasVariantImagePosition(final int variantPosition) {
		return variantPositionToImagePosition.containsKey(variantPosition);
	}

	@Override
	public boolean hasChanged() {
		return changed;
	}

	private ShopifyProductUpdateRequest(final ShopifyProduct shopifyProduct,
			final Map variantPositionToImagePosition, final boolean changed) {
		this.request = shopifyProduct;
		this.variantPositionToImagePosition = variantPositionToImagePosition;
		this.changed = changed;
	}

	private static class Steps implements CurrentShopifyProductStep, TitleStep, MetafieldsGlobalTitleTagStep,
			MetafieldsGlobalDescriptionTagStep, ProductTypeStep, BodyHtmlStep, VendorStep, TagsStep,
			SortedOptionNamesStep, ImageSourcesStep, VariantUpdateRequestsStep, PublishedStep, BuildStep {

		private ShopifyProduct shopifyProduct;
		private Map variantPositionToImagePosition = new HashMap<>();
		private boolean changed;

		@Override
		public ShopifyProductUpdateRequest build() {
			final List




© 2015 - 2025 Weber Informatics LLC | Privacy Policy