protected <T> void register(Datatype datatype, Aggregation<T> aggregation) { aggregationByDatatype.put(datatype.getJavaClass(), aggregation); }
@Override public String getIdByJavaClass(Class<?> javaClass) { for (Map.Entry<String, Datatype> entry : datatypeById.entrySet()) { if (entry.getValue().getJavaClass().equals(javaClass)) return entry.getKey(); } throw new IllegalArgumentException("No datatype registered for " + javaClass); }
public KeyValueMetaProperty(MetaClass metaClass, String name, Datatype datatype) { this.name = name; this.javaClass = datatype.getJavaClass(); this.metaClass = metaClass; this.mandatory = false; this.range = new DatatypeRange(datatype); this.type = Type.DATATYPE; }
@Override public void register(Datatype datatype, String id, boolean defaultForJavaClass) { Preconditions.checkNotNullArgument(datatype, "datatype is null"); Preconditions.checkNotNullArgument(id, "id is null"); log.trace("Register datatype: {}, id: {}, defaultForJavaClass: {}", datatype.getClass(), id, defaultForJavaClass); if (defaultForJavaClass) { datatypeByClass.put(datatype.getJavaClass(), datatype); } datatypeById.put(id, datatype); } }
protected boolean isUuid(MetaProperty metaProperty) { return metaProperty.getRange().asDatatype().getJavaClass().equals(UUID.class); }
protected boolean isByteArray(MetaProperty metaProperty) { return metaProperty.getRange().asDatatype().getJavaClass().equals(byte[].class); }
protected boolean isUuid(MetaProperty metaProperty) { return metaProperty.getRange().asDatatype().getJavaClass().equals(UUID.class); }
protected boolean isByteArray(MetaProperty metaProperty) { return metaProperty.getRange().asDatatype().getJavaClass().equals(byte[].class); }
protected boolean isByteArray(MetaProperty metaProperty) { return metaProperty.getRange().asDatatype().getJavaClass().equals(byte[].class); }
protected boolean isUuid(MetaProperty metaProperty) { return metaProperty.getRange().asDatatype().getJavaClass().equals(UUID.class); }
protected Object readSimpleProperty(JsonElement valueElement, Datatype propertyType) { String value = valueElement.getAsString(); if (value == null) return null; try { Class javaClass = propertyType.getJavaClass(); if (BigDecimal.class.isAssignableFrom(javaClass)) { return valueElement.getAsBigDecimal(); } else if (Long.class.isAssignableFrom(javaClass)) { return valueElement.getAsLong(); } else if (Integer.class.isAssignableFrom(javaClass)) { return valueElement.getAsInt(); } else if (Double.class.isAssignableFrom(javaClass)) { return valueElement.getAsDouble(); } return propertyType.parse(value); } catch (ParseException e) { throw new EntitySerializationException(String.format("An error occurred while parsing property. Type [%s]. Value [%s].", propertyType, value), e); } }
@SuppressWarnings("unchecked") @Override protected V convertToModel(LocalDate componentRawValue) throws ConversionException { if (componentRawValue == null) { return null; } LocalDateTime localDateTime = LocalDateTime.of(componentRawValue, LocalTime.MIDNIGHT); ValueSource<V> valueSource = getValueSource(); if (valueSource instanceof EntityValueSource) { MetaProperty metaProperty = ((EntityValueSource) valueSource).getMetaPropertyPath().getMetaProperty(); return (V) convertFromLocalDateTime(localDateTime, metaProperty.getRange().asDatatype().getJavaClass()); } return (V) convertFromLocalDateTime(localDateTime, datatype == null ? Date.class : datatype.getJavaClass()); }
protected boolean isSearchableProperty(MetaProperty metaProperty) { if (Arrays.binarySearch(systemProps, metaProperty.getName()) >= 0) return false; if (metaProperty.getRange().isDatatype()) { Class type = metaProperty.getRange().asDatatype().getJavaClass(); return (type.equals(String.class) || type.equals(java.sql.Date.class) || type.equals(BigDecimal.class) || type.equals(Integer.class) || type.equals(Long.class) || type.equals(Double.class)); } else if (metaProperty.getRange().isEnum() || metaProperty.getRange().isClass()) { return true; } return false; } }
@Override @SuppressWarnings("unchecked") protected V convertToModel(LocalTime componentRawValue) throws ConversionException { if (componentRawValue == null) { return null; } ValueSource<V> valueSource = getValueSource(); if (valueSource instanceof EntityValueSource) { MetaProperty metaProperty = ((EntityValueSource) valueSource).getMetaPropertyPath().getMetaProperty(); return (V) dateTimeTransformations.transformFromLocalTime(componentRawValue, metaProperty.getRange().asDatatype().getJavaClass()); } return (V) dateTimeTransformations.transformFromLocalTime(componentRawValue, datatype == null ? Date.class : datatype.getJavaClass()); }
@Deprecated protected Field.Validator getDefaultValidator(MetaProperty property) { Field.Validator validator = null; if (property.getRange().isDatatype()) { Messages messages = getMessages(); Class type = property.getRange().asDatatype().getJavaClass(); if (type.equals(Integer.class)) { validator = new IntegerValidator(messages.getMainMessage("validation.invalidNumber")); } else if (type.equals(Long.class)) { validator = new LongValidator(messages.getMainMessage("validation.invalidNumber")); } else if (type.equals(Double.class) || type.equals(BigDecimal.class)) { validator = new DoubleValidator(messages.getMainMessage("validation.invalidNumber")); } else if (type.equals(java.sql.Date.class)) { validator = new DateValidator(messages.getMainMessage("validation.invalidDate")); } } return validator; }
@Nullable @Override public Component createComponent(ComponentGenerationContext context) { String property = context.getProperty(); MetaPropertyPath mpp = resolveMetaPropertyPath(context.getMetaClass(), property); if (mpp != null) { Range mppRange = mpp.getRange(); if (mppRange.isDatatype()) { Class type = mppRange.asDatatype().getJavaClass(); if (type.equals(Entity.class)) { return createDatatypeLinkField(context); } } } return null; }
protected Consumer getValidator(MetaProperty property) { Consumer validator = null; if (property.getRange().isDatatype()) { Class type = property.getRange().asDatatype().getJavaClass(); if (type.equals(Integer.class)) { validator = new IntegerValidator(messages.getMainMessage("validation.invalidNumber")); } else if (type.equals(Long.class)) { validator = new LongValidator(messages.getMainMessage("validation.invalidNumber")); } else if (type.equals(Double.class) || type.equals(BigDecimal.class)) { validator = new DoubleValidator(messages.getMainMessage("validation.invalidNumber")); } else if (type.equals(java.sql.Date.class)) { validator = new DateValidator(messages.getMainMessage("validation.invalidDate")); } } return validator; }
protected Field createDateField(Datasource datasource, MetaProperty property) { Class type = property.getRange().asDatatype().getJavaClass(); DateField dateField = componentsFactory.createComponent(DateField.class); dateField.setDatasource(datasource, property.getName()); if (type.equals(Date.class)) { dateField.setResolution(DateField.Resolution.DAY); dateField.setDateFormat(messages.getMainMessage("dateTimeFormat")); } else if (type.equals(java.sql.Date.class)) { dateField.setResolution(DateField.Resolution.SEC); dateField.setDateFormat(messages.getMainMessage("dateFormat")); } else { throw new RuntimeException("Unknown type for " + property); } return dateField; }
public void setupZoneId(DateField component, EntityValueSource valueSource) { if (component.getZoneId() == null) { MetaProperty metaProperty = valueSource.getMetaPropertyPath().getMetaProperty(); Class javaType = metaProperty.getRange().asDatatype().getJavaClass(); if (dateTimeTransformations.isDateTypeSupportsTimeZones(javaType)) { Boolean ignoreUserTimeZone = metadataTools.getMetaAnnotationValue(metaProperty, IgnoreUserTimeZone.class); if (!Boolean.TRUE.equals(ignoreUserTimeZone)) { TimeZone timeZone = userSessionSource.getUserSession().getTimeZone(); component.setTimeZone(timeZone); } } } }
public void setupDateFormat(DateField component, EntityValueSource valueSource) { MetaProperty metaProperty = valueSource.getMetaPropertyPath().getMetaProperty(); Class javaType = metaProperty.getRange().asDatatype().getJavaClass(); TemporalType temporalType = getTemporalType(metaProperty, javaType); component.setResolution(temporalType == TemporalType.DATE ? DateField.Resolution.DAY : DateField.Resolution.MIN); String formatStr = messageTools.getDefaultDateFormat(temporalType); component.setDateFormat(formatStr); }