@Override default Optional<TemporalType> getTemporalType() { return Optional.ofNullable( getConfiguration().getTemporalType().orElse(TemporalType.getTemporalType(getType()).orElse(null))); }
/** * Bind a {@link PropertyValuePresenter} to the given property configuration value. The presenter will be provided * when the property has the given <code>configurationProperty</code> and its value equals to given * <code>value</code>. * @param <T> Property base type * @param <C> Configuration property type * @param configurationProperty The configuration property to check (not null) * @param value The configuration property value to check (may be null) * @param presenter The PropertyPresenter to register (not null) */ default <T, C> void forPropertyConfiguration(ConfigProperty<C> configurationProperty, C value, PropertyValuePresenter<? super T> presenter) { ObjectUtils.argumentNotNull(configurationProperty, "Configuration property must be not null"); register(p -> p.getConfiguration().getParameter(configurationProperty).map(v -> Objects.equals(v, value)) .orElse(Boolean.FALSE), presenter); }
/** * Bind a {@link PropertyRenderer} to the given property configuration value. The renderer will be provided when the * property has the given <code>configurationProperty</code> and its value equals to given <code>value</code>. * @param <R> Rendering type * @param <T> Property base type * @param <C> Configuration property type * @param configurationProperty The configuration property to check (not null) * @param value The configuration property value to check (may be null) * @param renderer The PropertyRenderer to register (not null) */ default <R, T, C> void forPropertyConfiguration(ConfigProperty<C> configurationProperty, C value, PropertyRenderer<R, T> renderer) { ObjectUtils.argumentNotNull(configurationProperty, "Configuration property must be not null"); register(p -> p.getConfiguration().getParameter(configurationProperty).map(v -> Objects.equals(v, value)) .orElse(Boolean.FALSE), renderer); }
@Override public String present(Property<T> property, T value) { ObjectUtils.argumentNotNull(property, "Property must be not null"); // check TemporalType ParameterSet.Builder<?> builder = ParameterSet.builder().withParameters(property.getConfiguration()); property.getConfiguration().getTemporalType() .ifPresent(t -> builder.withParameter(StringValuePresenter.TEMPORAL_TYPE, t)); final ParameterSet parameters = builder.build(); // check collection property if (value != null && CollectionProperty.class.isAssignableFrom(property.getClass()) && Collection.class.isAssignableFrom(value.getClass())) { final Class<?> elementType = ((CollectionProperty<?, ?>) property).getElementType(); return ((Collection<?>) value).stream().map(v -> presentValue(elementType, v, parameters)) .collect(Collectors.joining(",")); } // default presentation return presentValue(property.getType(), value, parameters); }
/** * Renders a Date value type Field * @param property Property to render * @return Field instance */ protected Field<T> renderDate(Property<? extends T> property) { final TemporalType type = property.getConfiguration().getTemporalType().orElse(TemporalType.DATE); return postProcessField( input.date((type == TemporalType.DATE_TIME) ? Resolution.MINUTE : Resolution.DAY, false).asField(), property); }
/** * Renders a Date value type Field * @param property Property to render * @return Field instance */ protected Field<T> renderDate(Property<? extends T> property) { final TemporalType type = property.getConfiguration().getTemporalType().orElse(TemporalType.DATE); return postProcessField( input.date((type == TemporalType.DATE_TIME) ? Resolution.MINUTE : Resolution.DAY, false).asField(), property); }
private static <T, P extends Path<T> & Property<T>> Map<String, Object> encodePropertyBoxTypeCollectionProperty( MongoDocumentContext<?> context, P property, Collection<PropertyBox> values, String name, String parentPath, boolean forUpdate) throws InvalidExpressionException { // resolve field name String fieldName = context.resolveOrFail(Path.of(name, Object.class), FieldName.class).getFieldName(); // encode collection elements if (values == null || values.isEmpty()) { return Collections.emptyMap(); } List<Document> encoded = new ArrayList<>(values.size()); for (PropertyBox pb : values) { Document doc = encodePropertyBox( context.documentContext(property.getConfiguration() .getParameter(PropertySet.PROPERTY_CONFIGURATION_ATTRIBUTE).orElse(pb), false), pb, parentPath, forUpdate); if (doc != null) { encoded.add(doc); } } return Collections.singletonMap(forUpdate ? composeFieldPath(parentPath, fieldName) : fieldName, encoded); }
@SuppressWarnings("unchecked") @Override public T convert(MongoResolutionContext<?> context, Document document) { if (document != null) { EnumCodecStrategy strategy = (Property.class.isAssignableFrom(expression.getClass())) ? ((Property<?>) expression).getConfiguration().getParameter(EnumCodecStrategy.CONFIG_PROPERTY) .orElse(null) : null; final Object fieldValue = document.get(selection); Object value = context.resolveOrFail(FieldValue.create(fieldValue, expression, strategy), Value.class) .getValue(); if (value != null && !TypeUtils.isAssignable(value.getClass(), getConversionType())) { throw new DataAccessException("Failed to convert document value [" + fieldValue + "] to required type [" + getConversionType() + "]: value type [" + value.getClass().getName() + "] is not compatible"); } return (T) value; } return null; }
/** * Renders a numeric value type Field * @param property Property to render * @return Field instance */ @SuppressWarnings("unchecked") protected Field<T> renderNumber(Property<? extends T> property) { // Number format Class<? extends Number> type = (Class<? extends Number>) property.getType(); int decimals = property.getConfiguration().getParameter(StringValuePresenter.DECIMAL_POSITIONS).orElse(-1); boolean disableGrouping = property.getConfiguration().getParameter(StringValuePresenter.DISABLE_GROUPING) .orElse(Boolean.FALSE); Locale locale = LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap(l -> l.getLocale()) .orElse(Locale.getDefault()); NumberFormat numberFormat = LocalizationContext.getCurrent().filter(l -> l.isLocalized()) .map((l) -> l.getNumberFormat(type, decimals, disableGrouping)) .orElse(TypeUtils.isDecimalNumber(property.getType()) ? NumberFormat.getNumberInstance(locale) : NumberFormat.getIntegerInstance(locale)); if (decimals > -1) { numberFormat.setMinimumFractionDigits(decimals); numberFormat.setMaximumFractionDigits(decimals); } if (disableGrouping) { numberFormat.setGroupingUsed(false); } return postProcessField(input.number(type).numberFormat(numberFormat).asField(), property); }
/** * Renders a numeric value type Field * @param property Property to render * @return Field instance */ @SuppressWarnings("unchecked") protected Field<T> renderNumber(Property<? extends T> property) { // Number format Class<? extends Number> type = (Class<? extends Number>) property.getType(); int decimals = property.getConfiguration().getParameter(StringValuePresenter.DECIMAL_POSITIONS).orElse(-1); boolean disableGrouping = property.getConfiguration().getParameter(StringValuePresenter.DISABLE_GROUPING) .orElse(Boolean.FALSE); Locale locale = LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap(l -> l.getLocale()) .orElse(Locale.getDefault()); NumberFormat numberFormat = LocalizationContext.getCurrent().filter(l -> l.isLocalized()) .map((l) -> l.getNumberFormat(type, decimals, disableGrouping)) .orElse(TypeUtils.isDecimalNumber(property.getType()) ? NumberFormat.getNumberInstance(locale) : NumberFormat.getIntegerInstance(locale)); if (decimals > -1) { numberFormat.setMinimumFractionDigits(decimals); numberFormat.setMaximumFractionDigits(decimals); } if (disableGrouping) { numberFormat.setGroupingUsed(false); } return postProcessField(input.number(type).numberFormat(numberFormat).asField(), property); }
private static java.util.Date parseDateValue(Property<?> property, String value) { if (property.getConfiguration().getTemporalType().isPresent()) { switch (property.getConfiguration().getTemporalType().get()) { case DATE: try {
private static <T, P extends Path<T> & Property<T>> Map<String, Object> encodePropertyBoxTypeProperty( MongoDocumentContext<?> context, P property, PropertyBox value, String name, String parentPath, boolean forUpdate) throws InvalidExpressionException { // resolve field name String fieldName = context.resolveOrFail(Path.of(name, Object.class), FieldName.class).getFieldName(); // encode nested document Document encoded = encodePropertyBox( context.documentContext(property.getConfiguration() .getParameter(PropertySet.PROPERTY_CONFIGURATION_ATTRIBUTE).orElse(value), false), value, forUpdate ? composeFieldPath(parentPath, fieldName) : parentPath, forUpdate); if (forUpdate) { return encoded; } else { return Collections.singletonMap(fieldName, (encoded != null) ? encoded : NO_VALUE); } }
Optional<TemporalType> temporalType = property.getConfiguration().getTemporalType(); try { temporalType.ifPresent(tt -> {
/** * Constructor with function argument. * @param argument Function argument (not null) * @param resultType Function result type (not null) */ @SuppressWarnings("unchecked") public AbstractPropertyQueryFunction(TypedExpression<? extends A> argument, Class<? extends T> resultType) { super(argument); ObjectUtils.argumentNotNull(resultType, "Function result type must be not null"); this.resultType = resultType; if (argument instanceof Property) { final Property<?> property = (Property<?>) argument; this.configuration = PropertyConfiguration.clone(property.getConfiguration()); if (getType() == property.getType() && property.getConverter().isPresent()) { converter = (PropertyValueConverter<T, ?>) property.getConverter().get(); } } else { this.configuration = PropertyConfiguration.create(); } }
Optional<Path> propertyPath = adapter.getPath(property); propertyPath.ifPresent(path -> { Optional<?> value = deserializePath(context, node, ((Property<?>) property).getConfiguration(), path); if (value.isPresent()) {
/** * Render the property as a numeric type {@link Input}. * @param property Property to render * @return The {@link Input} instance */ @SuppressWarnings("unchecked") protected Input<T> renderNumber(Property<? extends T> property) { // numeric type final Class<? extends Number> type = (Class<? extends Number>) property.getType(); // configuration int decimals = property.getConfiguration().getParameter(StringValuePresenter.DECIMAL_POSITIONS).orElse(-1); // build Input return (Input<T>) Input.number(type).label(property).readOnly(property.isReadOnly()).maxDecimals(decimals) .build(); }
property.getConfiguration().getParameter(PropertySet.PROPERTY_CONFIGURATION_ATTRIBUTE).map(ps -> { return resolvePropertyBox(parent, ps, resolver, includeReadOnly); }).orElseGet(() -> buildUnresolvedPropertyBoxSchema())); final ArrayProperty arrayModel = new ArrayProperty(); arrayModel.setItems(modelToProperty( property.getConfiguration().getParameter(PropertySet.PROPERTY_CONFIGURATION_ATTRIBUTE).map(ps -> { return resolvePropertyBox(parent, ps, resolver, includeReadOnly); }).orElseGet(() -> buildUnresolvedPropertyBoxSchema())));
public void config() { // tag::config[] final ConfigProperty<Long> EXAMPLE_CFG = ConfigProperty.create("exampleConfig", Long.class); Property.Builder<String, Property<String>, ?> builder = getPropertyBuilder(); builder.temporalType(TemporalType.DATE_TIME) // <1> .withConfiguration("myAttribute", "myValue") // <2> .withConfiguration(EXAMPLE_CFG, 7L); // <3> PropertyConfiguration cfg = aProperty().getConfiguration(); // <4> Optional<String> value1 = cfg.getParameter("myAttribute", String.class); // <5> Long value2 = cfg.getParameter(EXAMPLE_CFG, 0L); // <6> // end::config[] }
property.getConfiguration().getParameter(EnumCodecStrategy.CONFIG_PROPERTY).orElse(null)), FieldValue.class).getValue();
/** * Render the property as a {@link Date} type {@link Input}. * @param property Property to render * @return The {@link Input} instance */ protected Input<Date> renderDate(Property<? extends T> property) { final TemporalType type = property.getConfiguration().getTemporalType().orElse(TemporalType.DATE); switch (type) { case TIME: return Input.from(Input.localTime().label(property).readOnly(property.isReadOnly()).build(), new DateToLocalTimeConverter()); case DATE_TIME: return Input.dateTime().label(property).readOnly(property.isReadOnly()).build(); case DATE: default: return Input.date().label(property).readOnly(property.isReadOnly()).build(); } }