public AssetDraftDsl withDescription(@Nullable final LocalizedString description) { return newBuilder().description(description).build(); }
private static AssetDraft getAssetDraft2() { final AssetSource assetSource1 = AssetSourceBuilder.ofUri("http://dev.commercetools.com/assets/img/CT-logo.svg") .key(randomKey()) .contentType("image/svg+xml") .build(); final LocalizedString name = LocalizedString.ofEnglish("commercetools logo"); return AssetDraftBuilder.of(singletonList(assetSource1), name) .key("asset2Key") .tags("desktop-sized", "svg-format", "commercetools", "awesome") .build(); }
public AssetDraftBuilder tags(final String tag, final String ... moreTags) { final HashSet<String> tags = new HashSet<>(); tags.add(tag); tags.addAll(asList(moreTags)); return tags(tags); } }
/** * Creates a new builder with the values of this object. * * @return new builder */ public AssetDraftBuilder newBuilder() { return new AssetDraftBuilder(custom, description, key, name, sources, tags); }
private static AssetDraft getAssetDraft1() { final AssetSource assetSource1 = AssetSourceBuilder.ofUri("https://commercetools.com/binaries/content/gallery/commercetoolswebsite/homepage/cases/rewe.jpg") .key(randomKey()) .contentType("image/jpg") .dimensionsOfWidthAndHeight(1934, 1115) .build(); final LocalizedString name = LocalizedString.ofEnglish("REWE show case"); final LocalizedString description = LocalizedString.ofEnglish("screenshot of the REWE webshop on a mobile and a notebook"); return AssetDraftBuilder.of(singletonList(assetSource1), name) .key("asset1Key") .description(description) .tags("desktop-sized", "jpg-format", "REWE", "awesome") .build(); }
public AssetDraftBuilder tags(final String tag, final String ... moreTags) { final HashSet<String> tags = new HashSet<>(); tags.add(tag); tags.addAll(asList(moreTags)); return tags(tags); } }
/** * Creates a new object initialized with the given values. * * @param sources initial value for the {@link AssetDraft#getSources()} property * @param name initial value for the {@link AssetDraft#getName()} property * @return new object initialized with the given values */ public static AssetDraftBuilder of(final List<AssetSource> sources, final LocalizedString name) { return new AssetDraftBuilder(null, null, null, name, sources, null); }
private static AssetDraft getAssetDraft2() { final AssetSource assetSource1 = AssetSourceBuilder.ofUri("http://dev.commercetools.com/assets/img/CT-logo.svg") .key(randomKey()) .contentType("image/svg+xml") .build(); final LocalizedString name = LocalizedString.ofEnglish("commercetools logo"); return AssetDraftBuilder.of(singletonList(assetSource1), name) .tags("desktop-sized", "svg-format", "commercetools", "awesome") .key(randomKey()) .build(); } }
/** * Creates a new object initialized with the fields of the template parameter. * * @param template the template * @return a new object initialized from the template */ public static AssetDraftBuilder of(final AssetDraft template) { return new AssetDraftBuilder(template.getCustom(), template.getDescription(), template.getKey(), template.getName(), template.getSources(), template.getTags()); }
private static AssetDraft getAssetDraft1() { final AssetSource assetSource1 = AssetSourceBuilder.ofUri("https://commercetools.com/binaries/content/gallery/commercetoolswebsite/homepage/cases/rewe.jpg") .key(randomKey()) .contentType("image/jpg") .dimensionsOfWidthAndHeight(1934, 1115) .build(); final LocalizedString name = LocalizedString.ofEnglish("REWE show case"); final LocalizedString description = LocalizedString.ofEnglish("screenshot of the REWE webshop on a mobile and a notebook"); return AssetDraftBuilder.of(singletonList(assetSource1), name) .description(description) .key(randomKey()) .tags("desktop-sized", "jpg-format", "REWE", "awesome") .build(); }
@Test public void addAssetBySku() { withProduct(client(), (Product product) -> { final AssetSource assetSource = AssetSourceBuilder.ofUri("https://commercetools.com/binaries/content/gallery/commercetoolswebsite/homepage/cases/rewe.jpg") .build(); final LocalizedString name = LocalizedString.ofEnglish("REWE show case"); final AssetDraft assetDraft = AssetDraftBuilder.of(singletonList(assetSource), name) .build(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, AddAsset.ofSku(sku, assetDraft).withPosition(0).withStaged(false)); final Product updatedProduct = client().executeBlocking(cmd); final List<Asset> assets = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets(); assertThat(assets).hasSize(1); final Asset asset = assets.get(0); assertThat(asset.getName()).isEqualTo(name); assertThat(asset.getSources()).hasSize(1); final AssetSource source = asset.getSources().get(0); assertThat(source.getUri()).isEqualTo("https://commercetools.com/binaries/content/gallery/commercetoolswebsite/homepage/cases/rewe.jpg"); }); }
/** * Creates a new object initialized with the fields of the template parameter. * * @param template the template * @return a new object initialized from the template */ public static AssetDraftBuilder of(final Asset template) { return new AssetDraftBuilder(copyCustom(template.getCustom()), template.getDescription(), template.getKey(), template.getName(), template.getSources(), template.getTags()); } }
@Test public void addAsset() { withCategory(client(), category -> { final AssetSource assetSource = AssetSourceBuilder.ofUri("https://commercetools.com/binaries/content/gallery/commercetoolswebsite/homepage/cases/rewe.jpg") .key("rewe-showcase") .contentType("image/jpg") .dimensionsOfWidthAndHeight(1934, 1115) .build(); final LocalizedString name = LocalizedString.ofEnglish("REWE show case"); final LocalizedString description = LocalizedString.ofEnglish("screenshot of the REWE webshop on a mobile and a notebook"); final AssetDraft assetDraft = AssetDraftBuilder.of(singletonList(assetSource), name) .description(description) .tags("desktop-sized", "jpg-format", "REWE", "awesome") .build(); final CategoryUpdateCommand command = CategoryUpdateCommand.of(category, AddAsset.of(assetDraft,0)); final Category updatedCategory = client().executeBlocking(command); final List<Asset> assets = updatedCategory.getAssets(); assertThat(assets).hasSize(1); final Asset asset = assets.get(0); assertThat(asset.getId()).isNotEmpty(); assertThat(asset.getDescription()).isEqualTo(description); assertThat(asset.getName()).isEqualTo(name); assertThat(asset.getSources()).hasSize(1); final AssetSource source = asset.getSources().get(0); assertThat(source.getUri()).isEqualTo("https://commercetools.com/binaries/content/gallery/commercetoolswebsite/homepage/cases/rewe.jpg"); assertThat(source.getKey()).isEqualTo("rewe-showcase"); assertThat(source.getContentType()).isEqualTo("image/jpg"); assertThat(source.getDimensions()).isEqualTo(AssetDimensions.ofWidthAndHeight(1934, 1115)); }); }