@Nullable @Override public CustomFields getCustom() { return delegate.getCustom(); }
@Nullable @Override public CustomFields getCustom() { return delegate.getCustom(); } }
@Nullable @Override public CustomFields getCustom() { return delegate.getCustom(); }
public static Category removeTypeFromCategory(final BlockingSphereClient client, final Category category) { assertThat(category.getCustom()).isNotNull(); final CategoryUpdateCommand command = CategoryUpdateCommand .of(category, SetCustomType.ofRemoveType()); final Category updatedCategory = client.executeBlocking(command); assertThat(updatedCategory.getCustom()).isNull(); return updatedCategory; } }
@Override protected void before() throws Throwable { super.before(); custom = getCategory().getCustom(); };
public static Category updateFieldValues(final BlockingSphereClient client, final Category category) { assertThat(category.getCustom().getFieldAsEnumKey("state")).isEqualTo("published"); final List<? extends UpdateAction<Category>> updateActions = asList( SetCustomField.ofObject("state", "draft"),//set new value SetCustomField.ofObject("imageUrl", null)//remove value ); final Category updatedCategory = client.executeBlocking(CategoryUpdateCommand.of(category, updateActions)); final CustomFields custom = updatedCategory.getCustom(); assertThat(custom.getFieldAsEnumKey("state")).isEqualTo("draft"); assertThat(custom.getFieldAsString("imageUrl")).isNull(); return updatedCategory; } }
private void setCustomType(final Function<Type, SetCustomType> updateActionCreator) { withUpdateableType(client(), type -> { withCategory(client(), category -> { final SetCustomType updateAction = updateActionCreator.apply(type); final Category updatedCategory = client().executeBlocking(CategoryUpdateCommand.of(category, updateAction)); assertThat(updatedCategory.getCustom().getType()).isEqualTo(type.toReference()); assertThat(updatedCategory.getCustom().getField(STRING_FIELD_NAME, TypeReferences.stringTypeReference())).isEqualTo("hello"); final Category updated2 = client().executeBlocking(CategoryUpdateCommand.of(updatedCategory, SetCustomType.ofRemoveType())); assertThat(updated2.getCustom()).isNull(); }); return type; }); }
public static Category updateCategoryWithType(final BlockingSphereClient client, final Category category1, final Category category2) { final Category category = CategoryFixtures.createCategory(client); assertThat(category.getCustom()).isNull(); final Map<String, Object> fieldValues = new HashMap<>(); fieldValues.put("state", "published");//in the type it was enum, but for enums only keys are set fieldValues.put("imageUrl", "http://www.commercetools.com/assets/img/CT-logo.svg"); final Set<Reference<Category>> relatedCategories = new HashSet<>(asList(category1.toReference(), category2.toReference())); fieldValues.put("relatedCategories", relatedCategories); final SetCustomType action = SetCustomType .ofTypeKeyAndObjects("category-customtype-key", fieldValues); final Category updatedCategory = client.executeBlocking(CategoryUpdateCommand.of(category, action)); final CustomFields custom = updatedCategory.getCustom(); assertThat(custom.getFieldAsEnumKey("state")).isEqualTo("published"); assertThat(custom.getFieldAsString("imageUrl")) .isEqualTo("http://www.commercetools.com/assets/img/CT-logo.svg"); final TypeReference<Set<Reference<Category>>> typeReference = new TypeReference<Set<Reference<Category>>>() { }; assertThat(custom.getField("relatedCategories", typeReference)) .isEqualTo(relatedCategories); return updatedCategory; } }
final Category category = client.executeBlocking(CategoryCreateCommand.of(categoryDraft)); final CustomFields custom = category.getCustom(); assertThat(custom.getFieldAsEnumKey("state")).isEqualTo("published"); assertThat(custom.getFieldAsString("imageUrl"))
/** * 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 CategoryDraftBuilder of(final Category template) { return new CategoryDraftBuilder(copyAssets(template.getAssets()), copyCustom(template.getCustom()), template.getDescription(), template.getExternalId(), template.getKey(), template.getMetaDescription(), template.getMetaKeywords(), template.getMetaTitle(), template.getName(), template.getOrderHint(), template.getParent(), template.getSlug()); } }
private void createCategoryWithCustomType(final Function<Type, CustomFieldsDraftBuilder> draftCreator) { withUpdateableType(client(), type -> { final CustomFieldsDraftBuilder customFieldsDraftBuilder = draftCreator.apply(type); final CustomFieldsDraft customFieldsDraft = customFieldsDraftBuilder.addObject(STRING_FIELD_NAME, "a value").build(); final CategoryDraft categoryDraft = CategoryDraftBuilder.of(randomSlug(), randomSlug()).custom(customFieldsDraft).build(); final Category category = client().executeBlocking(CategoryCreateCommand.of(categoryDraft)); assertThat(category.getCustom().getField(STRING_FIELD_NAME, TypeReferences.stringTypeReference())).isEqualTo("a value"); final Category updatedCategory = client().executeBlocking(CategoryUpdateCommand.of(category, SetCustomField.ofObject(STRING_FIELD_NAME, "a new value"))); assertThat(updatedCategory.getCustom().getField(STRING_FIELD_NAME, TypeReferences.stringTypeReference())).isEqualTo("a new value"); //clean up client().executeBlocking(CategoryDeleteCommand.of(updatedCategory)); return type; }); }
@Test public void referenceExpansion() { withUpdateableType(client(), type -> { withCategory(client(), referencedCategory -> { withCategory(client(), category -> { final Map<String, Object> fields = Collections.singletonMap(CAT_REFERENCE_FIELD_NAME, referencedCategory.toReference()); final CategoryUpdateCommand categoryUpdateCommand = CategoryUpdateCommand.of(category, SetCustomType.ofTypeIdAndObjects(type.getId(), fields)); final ExpansionPath<Category> expansionPath = ExpansionPath.of("custom.fields." + CAT_REFERENCE_FIELD_NAME); final Category updatedCategory = client().executeBlocking(categoryUpdateCommand.withExpansionPaths(expansionPath)); final Reference<Category> createdReference = updatedCategory.getCustom().getField(CAT_REFERENCE_FIELD_NAME, TYPE_REFERENCE); assertThat(createdReference).isEqualTo(referencedCategory.toReference()); assertThat(createdReference.getObj()).isNotNull(); final Category loadedCat = client().executeBlocking(CategoryByIdGet.of(updatedCategory) .withExpansionPaths(expansionPath)); assertThat(loadedCat.getCustom().getField(CAT_REFERENCE_FIELD_NAME, TYPE_REFERENCE).getObj()) .overridingErrorMessage("is expanded") .isNotNull(); final Category updated2 = client().executeBlocking(CategoryUpdateCommand.of(updatedCategory, SetCustomType.ofRemoveType())); assertThat(updated2.getCustom()).isNull(); }); }); return type; }); }
@Test public void copyFromCustomField() { withUpdateableType(client(), type -> { final String value = "foo"; final String id = type.getId(); final CategoryDraftBuilder categoryDraftBuilder = CategoryDraftBuilder.of(en("category-name"), en("category-slug")) .custom(CustomFieldsDraft.ofTypeIdAndObjects(id, singletonMap(STRING_FIELD_NAME, value))); withCategory(client(), categoryDraftBuilder, category -> { //Test builder final CustomFieldsDraft customFieldsDraft = CustomFieldsDraftBuilder.of(category.getCustom()).build(); assertThat(customFieldsDraft.getType().getId()).isEqualTo(id); //Test factory method from draft final CustomFieldsDraft customFieldsDraft2 = CustomFieldsDraft.ofCustomFields(category.getCustom()); assertThat(customFieldsDraft2.getType().getId()).isEqualTo(id); }); return type; }); }
@Test public void queryByReference() { withUpdateableType(client(), type -> { withCategory(client(), referencedCategory -> { withCategory(client(), category -> { final TypeReference<Reference<Category>> TYPE_REFERENCE = new TypeReference<Reference<Category>>() {}; final Map<String, Object> fields = new HashMap<>(); fields.put(CAT_REFERENCE_FIELD_NAME, referencedCategory.toReference()); final CategoryUpdateCommand categoryUpdateCommand = CategoryUpdateCommand.of(category, SetCustomType.ofTypeIdAndObjects(type.getId(), fields)); final ExpansionPath<Category> expansionPath = ExpansionPath.of("custom.fields." + CAT_REFERENCE_FIELD_NAME); final Category updatedCategory = client().executeBlocking(categoryUpdateCommand.withExpansionPaths(expansionPath)); final Reference<Category> createdReference = updatedCategory.getCustom().getField(CAT_REFERENCE_FIELD_NAME, TYPE_REFERENCE); final CategoryQuery categoryQuery = CategoryQuery.of() .plusExpansionPaths(expansionPath) .plusPredicates(m -> m.is(updatedCategory)) .plusPredicates(m -> m.custom().fields().ofReference(CAT_REFERENCE_FIELD_NAME).id().is(createdReference.getId())); final List<Category> results = client().executeBlocking(categoryQuery).getResults(); assertThat(results).hasSize(1); }); }); return type; }); }