final PropertyBox.Builder builder = PropertyBox.builder(propertySet).invalidAllowed(true); final PathPropertySetAdapter adapter = PathPropertySetAdapter.create(propertySet); for (Property property : propertySet) { path); if (value.isPresent()) { builder.setIgnoreReadOnly(property, value.get()); } else { LOGGER.debug(() -> "Property [" + property + "] value not found in JSON node [" + node return builder.build(); } catch (JsonDeserializationException e) { throw e;
final PropertyBox.Builder builder = PropertyBox.builder(propertySet).invalidAllowed(true); final String value = decode(fields[1]); getPropertyByName(propertySet, name).ifPresent(p -> { builder.set(p, deserialize(p, value)); }); return builder.build();
+ Property.class.getName() + "] type"); PropertyBox.Builder box = PropertyBox.builder(ps).invalidAllowed(true); for (Property property : ps) { com.vaadin.data.Property<?> itemProperty = item.getItemProperty(property); if (itemProperty != null) { box.set(property, itemProperty.getValue()); return box.build();
/** * Create a PropertyBoxItem using given <code>properties</code> as property set and reading property values from * given <code>bean</code> instance. * <p> * Only bean properties whose name matches a {@link Path} with same name contained in this PropertyBox property set * will be considered. * </p> * <p> * Bean instance structure must the follow JavaBeans rules providing getter methods to read bean property values. * </p> * @param <P> Actual property type * @param bean Bean instance (not null) * @param properties Property set (not null) * @return PropertyBoxItem instance */ static <P extends Property<?>> PropertyBoxItem fromBean(Object bean, PropertySet<P> properties) { ObjectUtils.argumentNotNull(bean, "Bean instance must be not null"); ObjectUtils.argumentNotNull(properties, "Property set must be not null"); return create(BeanIntrospector.get().read(PropertyBox.builder(properties).build(), bean)); }
public void restClient() throws URISyntaxException { // tag::restclient[] final PathProperty<Integer> ID = PathProperty.create("id", Integer.class); final PathProperty<String> NAME = PathProperty.create("name", String.class); final PropertySet<?> PROPERTY_SET = PropertySet.of(ID, NAME); RestClient client = JaxrsRestClient.create() // <1> .defaultTarget(new URI("https://host/api")); // <2> client = RestClient.create(JaxrsRestClient.class.getName()); // <3> client = RestClient.create(); // <4> client = RestClient.forTarget("https://host/api"); // <5> Optional<TestData> testData = client.request().path("data/{id}").resolve("id", 1) // <6> .accept(MediaType.APPLICATION_JSON).getForEntity(TestData.class); Optional<PropertyBox> box = client.request().path("getbox") // <7> .propertySet(PROPERTY_SET).getForEntity(PropertyBox.class); HttpResponse<PropertyBox> response = client.request().path("getbox") // <8> .propertySet(PROPERTY_SET).get(PropertyBox.class); List<PropertyBox> boxes = client.request().path("getboxes") // <9> .propertySet(PROPERTY_SET).getAsList(PropertyBox.class); PropertyBox postBox = PropertyBox.builder(PROPERTY_SET).set(ID, 1).set(NAME, "Test").build(); HttpResponse<Void> postResponse = client.request().path("postbox") // <10> .post(RequestEntity.json(postBox)); // end::restclient[] }
public void restClient() throws URISyntaxException { // tag::restclient[] final PathProperty<Integer> ID = PathProperty.create("id", Integer.class); final PathProperty<String> NAME = PathProperty.create("name", String.class); final PropertySet<?> PROPERTY_SET = PropertySet.of(ID, NAME); ReactiveRestClient client = JaxrsReactiveRestClient.create() // <1> .defaultTarget(new URI("https://host/api")); // <2> client = ReactiveRestClient.create(JaxrsReactiveRestClient.class.getName()); // <3> client = ReactiveRestClient.create(); // <4> client = ReactiveRestClient.forTarget("https://host/api"); // <5> Mono<TestData> testData = client.request().path("data/{id}").resolve("id", 1) // <6> .accept(MediaType.APPLICATION_JSON).getForEntity(TestData.class); Mono<PropertyBox> box = client.request().path("getbox") // <7> .propertySet(PROPERTY_SET).getForEntity(PropertyBox.class); Mono<ReactiveResponseEntity<PropertyBox>> response = client.request().path("getbox") // <8> .propertySet(PROPERTY_SET).get(PropertyBox.class); Flux<PropertyBox> boxes = client.request().path("getboxes") // <9> .propertySet(PROPERTY_SET).getAsList(PropertyBox.class); PropertyBox postBox = PropertyBox.builder(PROPERTY_SET).set(ID, 1).set(NAME, "Test").build(); Mono<ReactiveResponseEntity<Void>> postResponse = client.request().path("postbox") // <10> .post(RequestEntity.json(postBox)); // end::restclient[] }
public void restClient() throws URISyntaxException { // tag::restclient[] final PathProperty<Integer> ID = PathProperty.create("id", Integer.class); final PathProperty<String> NAME = PathProperty.create("name", String.class); final PropertySet<?> PROPERTY_SET = PropertySet.of(ID, NAME); AsyncRestClient client = JaxrsAsyncRestClient.create() // <1> .defaultTarget(new URI("https://host/api")); // <2> client = AsyncRestClient.create(JaxrsAsyncRestClient.class.getName()); // <3> client = AsyncRestClient.create(); // <4> client = AsyncRestClient.forTarget("https://host/api"); // <5> CompletionStage<Optional<TestData>> testData = client.request().path("data/{id}").resolve("id", 1) // <6> .accept(MediaType.APPLICATION_JSON).getForEntity(TestData.class); CompletionStage<Optional<PropertyBox>> box = client.request().path("getbox") // <7> .propertySet(PROPERTY_SET).getForEntity(PropertyBox.class); CompletionStage<ResponseEntity<PropertyBox>> response = client.request().path("getbox") // <8> .propertySet(PROPERTY_SET).get(PropertyBox.class); CompletionStage<List<PropertyBox>> boxes = client.request().path("getboxes") // <9> .propertySet(PROPERTY_SET).getAsList(PropertyBox.class); PropertyBox postBox = PropertyBox.builder(PROPERTY_SET).set(ID, 1).set(NAME, "Test").build(); CompletionStage<ResponseEntity<Void>> postResponse = client.request().path("postbox") // <10> .post(RequestEntity.json(postBox)); // end::restclient[] }
public void input27() { // tag::input27[] PropertyInputGroup group = PropertyInputGroup.builder(SUBJECT).build(); // <1> group = Components.input.propertyGroup(SUBJECT).build(); // <2> Collection<Property<?>> properties = group.getProperties(); // <3> Stream<Input<?>> components = group.getElements(); // <4> group.getBindings().forEach(binding -> { // <5> Property<?> property = binding.getProperty(); Input<?> component = binding.getElement(); }); Optional<Input<?>> element = group.getElement(NAME); // <6> Input<?> component = group.requireElement(NAME); // <7> PropertyBox value = PropertyBox.builder(SUBJECT).set(ID, 1L).set(NAME, "One").build(); group.setValue(value); // <8> value = group.getValue(); // <9> group.clear(); // <10> group.isEmpty(); // <11> // end::input27[] }
public void datastore() { // tag::datastore[] final PathProperty<String> A_PROPERTY = PathProperty.create("propertyPath", String.class); final DataTarget<String> TARGET = DataTarget.named("test"); final Datastore datastore = getDatastore(); // build or obtain a concrete Datastore implementation PropertyBox data = PropertyBox.builder(A_PROPERTY).set(A_PROPERTY, "aValue").build(); OperationResult result = datastore.save(TARGET, data); // <1> result = datastore.insert(TARGET, data); // <2> result = datastore.update(TARGET, data); // <3> PropertyBox refreshed = datastore.refresh(TARGET, data); // <4> datastore.delete(TARGET, refreshed); // <5> // Bulk operations result = datastore.bulkInsert(TARGET, PropertySet.of(A_PROPERTY)) .add(PropertyBox.builder(A_PROPERTY).set(A_PROPERTY, "aValue1").build()) .add(PropertyBox.builder(A_PROPERTY).set(A_PROPERTY, "aValue2").build()) .add(PropertyBox.builder(A_PROPERTY).set(A_PROPERTY, "aValue3").build()).execute(); // <6> result = datastore.bulkUpdate(TARGET).set(A_PROPERTY, "updated").filter(A_PROPERTY.isNull()).execute(); // <7> result = datastore.bulkDelete(TARGET).filter(A_PROPERTY.isNull()).execute(); // <8> // end::datastore[] }
@SuppressWarnings("unchecked") @Override @Deprecated public O add(Map<Path<?>, Object> values) { if (values != null && !values.isEmpty()) { final PropertySet<?> propertySet = getDefinition().getPropertySet().orElse(asPropertySet(values.keySet())); final PropertyBox propertyBox = PropertyBox.builder(propertySet).invalidAllowed(true).build(); final PathPropertySetAdapter adapter = PathPropertySetAdapter.create(propertySet); for (Entry<Path<?>, Object> entry : values.entrySet()) { adapter.getProperty(entry.getKey()).ifPresent(p -> { if (entry.getValue() != null) { propertyBox.setValue((Property<Object>) p, entry.getValue()); } }); } getDefinition().addValue(propertyBox); return getActualOperation(); } return getActualOperation(); }
/** * Clone this PropertyBox using given <code>propertySet</code>, i.e. create a new PropertyBox and copy all given set * property values from this box to the newly created box. * @param <P> Actual property type * @param propertySet Property set of the cloned PropertyBox (not null) * @return A new, cloned, PropertyBox instance with given property set */ @SuppressWarnings("unchecked") default <P extends Property> PropertyBox cloneBox(PropertySet<P> propertySet) { ObjectUtils.argumentNotNull(propertySet, "Property set must be not null"); Builder builder = builder(propertySet).invalidAllowed(true); propertySet.forEach(p -> { if (!p.isReadOnly()) { this.getValueIfPresent(p).ifPresent(v -> builder.set(p, v)); } }); return builder.invalidAllowed(this.isInvalidAllowed()).build(); }
public void vc7() { // tag::vc7[] PropertyViewGroup group = PropertyViewGroup.builder(SUBJECT).build(); // <1> group = Components.view.propertyGroup(SUBJECT).build(); // <2> Collection<Property<?>> properties = group.getProperties(); // <3> Stream<ViewComponent<?>> components = group.getElements(); // <4> group.getBindings().forEach(binding -> { // <5> Property<?> property = binding.getProperty(); ViewComponent<?> component = binding.getElement(); }); Optional<ViewComponent<?>> element = group.getElement(NAME); // <6> ViewComponent<?> component = group.requireElement(NAME); // <7> PropertyBox value = PropertyBox.builder(SUBJECT).set(ID, 1L).set(NAME, "One").build(); group.setValue(value); // <8> value = group.getValue(); // <9> group.clear(); // <10> group.isEmpty(); // <11> // end::vc7[] }
/** * Decode a document into a {@link PropertyBox} value using given property set. * @param context Resolution context * @param parent Optional parent field name expression * @param document Document to decode * @return Decoded PropertyBox instance * @throws InvalidExpressionException If an error occurred */ private static PropertyBox decodePropertyBox(final MongoDocumentContext<?> context, final String parent, Map<String, Object> document) throws InvalidExpressionException { // PropertyBox builder final PropertyBox propertyBox = PropertyBox.builder(context.getPropertySet()).invalidAllowed(true).build(); // Adapter final PathPropertyBoxAdapter adapter = PathPropertyBoxAdapter.builder(propertyBox) .pathMatcher(DocumentPathMatcher.INSTANCE).build(); // decode decodeDocument(context, parent, document, propertyBox, adapter); return propertyBox; }
public void group1() { // tag::group1[] final PathProperty<Long> ID = PathProperty.create("id", Long.class); final PathProperty<String> DESCRIPTION = PathProperty.create("description", String.class); final PropertySet<?> PROPERTIES = PropertySet.of(ID, DESCRIPTION); PropertyInputGroup group = Components.input.propertyGroup().properties(PROPERTIES) // <1> .bind(ID, Components.input.number(Long.class).build()) // <2> .bind(DESCRIPTION, Components.input.string().maxLength(100).build()) // <3> .build(); group.setValue(PropertyBox.builder(PROPERTIES).set(ID, 1L).set(DESCRIPTION, "TestDescription").build()); // <4> PropertyBox value = group.getValue(); // <5> group.addValueChangeListener(e -> { // <6> PropertyBox changedValue = e.getValue(); }); // end::group1[] }
public void propertySet() { Optional<PathProperty<Long>> idProperty = PROPERTIES.<Long>getProperty("id"); // <2> PathProperty<Long> id = PROPERTIES.property("id", Long.class); // <3> PathProperty<String> nestedName = PROPERTIES.property("nested.nestedName"); // <4> // read MyBean instance = new MyBean(); instance.setId(1L); Long value = PROPERTIES.read("id", instance); // <5> PropertyBox box = PROPERTIES.read(instance); // <6> value = box.getValue(PROPERTIES.property("id")); // <7> // write instance = new MyBean(); PROPERTIES.write("nested.nestedName", "test", instance); // <8> MyBean written = PROPERTIES.write(PropertyBox.builder(PROPERTIES).set(PROPERTIES.property("id"), 1L).build(), new MyBean()); // <9> } // end::set[]
@SuppressWarnings("unchecked") @Override public B dataSource(ItemDataProvider<PropertyBox> dataProvider, final Property... identifierProperties) { ObjectUtils.argumentNotNull(identifierProperties, "Identifier properties must be not null"); if (identifierProperties.length == 0) { throw new IllegalArgumentException("Identifier properties must be not empty"); } final PropertySet<?> propertySet = PropertySet.builderOf(identifierProperties) .identifiers(Arrays.asList(identifierProperties)).build(); return dataSource(dataProvider, item -> { PropertyBox.Builder builder = PropertyBox.builder(propertySet); for (Property p : identifierProperties) { item.getValueIfPresent(p).ifPresent(v -> builder.set(p, v)); } return builder.build(); }); }
public void view2() { // tag::view2[] final PathProperty<Long> ID = PathProperty.create("id", Long.class); final PathProperty<String> DESCRIPTION = PathProperty.create("description", String.class); final PropertySet<?> PROPERTIES = PropertySet.of(ID, DESCRIPTION); PropertyViewGroup viewGroup = Components.view.propertyGroup().properties(PROPERTIES).build(); // <1> PropertyViewForm viewForm = Components.view.formVertical().properties(PROPERTIES).build(); // <2> viewForm = Components.view.form(new FormLayout()).properties(PROPERTIES) // .composer((layout, source) -> { // <3> source.getValueComponents().forEach(c -> layout.addComponent(c.getComponent())); }).build(); viewForm.setValue(PropertyBox.builder(PROPERTIES).set(ID, 1L).set(DESCRIPTION, "Test").build()); // <4> PropertyBox value = viewForm.getValue(); // <5> // end::view2[] }
public void listing10() { // tag::listing10[] Datastore datastore = getDatastore(); PropertyListing listing = Components.listing.properties(PROPERTIES) // .dataSource(datastore, DataTarget.named("test"), ID) // <1> .commitHandler((addedItems, modifiedItems, removedItems) -> { // <2> // ... }).build(); final PropertyBox ITEM = PropertyBox.builder(PROPERTIES).set(ID, 777L).set(DESCRIPTION, "A description") .build(); listing.addItem(ITEM); // <3> listing.refreshItem(ITEM); // <4> listing.removeItem(ITEM); // <5> // end::listing10[] }
public void propertyBox() { // tag::propertybox[] final PathProperty<Long> ID = PathProperty.create("id", Long.class); final StringProperty NAME = StringProperty.create("name"); final PropertySet<?> PROPERTIES = PropertySet.of(ID, NAME); PropertyBox propertyBox = PropertyBox.create(ID, NAME); // <1> propertyBox = PropertyBox.create(PROPERTIES); // <2> propertyBox.setValue(ID, 1L); // <3> propertyBox.setValue(NAME, "testName"); // <4> propertyBox = PropertyBox.builder(PROPERTIES).set(ID, 1L).set(NAME, "testName").build(); // <5> Long id = propertyBox.getValue(ID); // <6> String name = propertyBox.getValueIfPresent(NAME).orElse("default"); // <7> boolean containsNotNullId = propertyBox.containsValue(ID); // <8> PropertyBox ids = propertyBox.cloneBox(ID); // <9> // end::propertybox[] }
public void listing11() { // tag::listing11[] Datastore datastore = getDatastore(); PropertyListing listing = Components.listing.properties(PROPERTIES) // .dataSource(datastore, DataTarget.named("test"), ID) // .buffered(true) // <1> .build(); final PropertyBox ITEM = PropertyBox.builder(PROPERTIES).set(ID, 777L).set(DESCRIPTION, "A description") .build(); listing.addItem(ITEM); // <2> listing.refreshItem(ITEM); // <3> listing.removeItem(ITEM); // <4> listing.commit(); // <5> listing.discard(); // <6> // end::listing11[] }