/** * Get the value of given <code>property</code> using current value, if available. * @param <T> Property type * @param property Property for which to obtain the value * @return Property value, empty if current value is not available or the given property is not available in current * value */ private <T> Optional<T> getCurrentPropertyValue(Property<T> property) { if (value != null && value.contains(property)) { return Optional.ofNullable(value.getValue(property)); } return Optional.empty(); }
if (value.contains(idProperty)) { value.setValue((Property<Object>) idProperty, idPropertyValue);
/** * Get the value of given <code>property</code> using current value, if available. * @param <T> Property type * @param property Property for which to obtain the value * @return Property value, empty if current value is not available or the given property is not available in current * value */ private <T> Optional<T> getCurrentPropertyValue(Property<T> property) { if (value != null && value.contains(property)) { return Optional.ofNullable(value.getValue(property)); } return Optional.empty(); }
@Override public Property<?> getItemProperty(Object id) { if (id instanceof com.holonplatform.core.property.Property) { com.holonplatform.core.property.Property<?> p = (com.holonplatform.core.property.Property<?>) id; if (getPropertyBox().contains(p)) { return getOrCreateProperty(p); } } return null; }
/** * Decode given document into a {@link PropertyBox} using given adapter to match the document field names and * property paths. * @param context Resolution context * @param parent Optional parent field name expression * @param document Document to decode * @param propertyBox PropertyBox to use to collect the decoded values * @param adapter PropertyBox adapter * @throws InvalidExpressionException If an error occurred */ private static void decodeDocument(final MongoDocumentContext<?> context, final String parent, Map<String, Object> document, PropertyBox propertyBox, PathPropertyBoxAdapter adapter) throws InvalidExpressionException { final List<Property<?>> properties = new ArrayList<>(context.getPropertySet().asList()); document.entrySet().stream().forEach(entry -> { decodeDocumentField(context, propertyBox, adapter, parent, entry.getKey(), entry.getValue()) .ifPresent(p -> { properties.remove(p); }); }); // check properties with converter and force value set for (Property<?> property : properties) { if (property.getConverter().isPresent() && propertyBox.contains(property)) { propertyBox.setValue(property, null); } } }
/** * Get the value of given <code>property</code> using given <code>propertyBox</code>. * @param <T> Property type * @param propertyBox PropertyBox * @param property Property * @return Property value */ protected <T> T getPropertyValue(PropertyBox propertyBox, Property<T> property) { if (VirtualProperty.class.isAssignableFrom(property.getClass())) { if (((VirtualProperty<T>) property).getValueProvider() != null) { return ((VirtualProperty<T>) property).getValueProvider().getPropertyValue(propertyBox); } return null; } if (propertyBox.contains(property)) { return propertyBox.getValue(property); } return null; }
/** * Get the value of given <code>property</code> using given <code>propertyBox</code>. * @param <T> Property type * @param propertyBox PropertyBox * @param property Property * @return Property value */ protected <T> T getPropertyValue(PropertyBox propertyBox, Property<T> property) { if (VirtualProperty.class.isAssignableFrom(property.getClass())) { if (((VirtualProperty<T>) property).getValueProvider() != null) { return ((VirtualProperty<T>) property).getValueProvider().getPropertyValue(propertyBox); } return null; } if (propertyBox.contains(property)) { return propertyBox.getValue(property); } return null; }
/** * Get the value of given <code>property</code> using given <code>propertyBox</code>. * @param <T> Property type * @param propertyBox PropertyBox * @param property Property * @return Property value */ protected <T> T getPropertyValue(PropertyBox propertyBox, Property<T> property) { if (VirtualProperty.class.isAssignableFrom(property.getClass())) { if (((VirtualProperty<T>) property).getValueProvider() != null) { return ((VirtualProperty<T>) property).getValueProvider().getPropertyValue(propertyBox); } return null; } if (propertyBox.contains(property)) { return propertyBox.getValue(property); } return null; }
@SuppressWarnings("unchecked") @Override protected Column<PropertyBox> generateDefaultGridColumn( ItemListingColumn<Property<?>, PropertyBox, ?> configuration) { final Property<?> property = configuration.getProperty(); // check component if (Component.class.isAssignableFrom(property.getType())) { final Property<? extends Component> componentProperty = (Property<? extends Component>) property; return getGrid().addComponentColumn(item -> { if (item.contains(property)) { return item.getValue(componentProperty); } return null; }); } // default provider using property presenter return getGrid().addColumn(item -> { if (item.contains(property)) { return item.present(property); } return null; }); }
if (propertyBox.contains(property)) { propertyBox.setValue(property, resolvedValue);
/** * Check generated document id after an upsert type operation, setting the inserted key using given * {@link OperationResult} builder. * @param builder OperationResult builder * @param documentContext Document context * @param configuration Operation configuration * @param upsertedId Optional upserted id value * @param value Original {@link PropertyBox} value */ @SuppressWarnings("unchecked") public static void checkUpsertedKey(OperationResult.Builder builder, MongoDocumentContext<?> documentContext, DatastoreOperationConfiguration configuration, BsonValue upsertedId, PropertyBox value) { if (upsertedId != null) { final ObjectId oid = upsertedId.asObjectId().getValue(); documentContext.getDocumentIdPath().ifPresent(idp -> { final Object idPropertyValue = documentContext.getDocumentIdResolver().decode(oid, idp.getType()); builder.withInsertedKey(idp, idPropertyValue); // check bring back ids if (configuration.hasWriteOption(DefaultWriteOption.BRING_BACK_GENERATED_IDS)) { documentContext.getDocumentIdProperty().ifPresent(idprp -> { if (value.contains(idprp)) { value.setValue((Property<Object>) idprp, idPropertyValue); } }); } }); } }
final Object idPropertyValue = documentContext.getDocumentIdResolver().decode(oid, idProperty.getType()); if (rd.getValue().contains(idProperty)) { rd.getValue().setValue((Property<Object>) idProperty, idPropertyValue);