protected String getDateTimeFormattedValue(Object value, Locale locale) { return Datatypes.getNN(Date.class).format(value, locale); }
private static Object parseByDatatype(String value, Class<?> type) throws ParseException { Datatype datatype = Datatypes.getNN(type); return datatype.parse(value); }
protected String formatSingleValue(Object v) { switch (type) { case ENTITY: if (v instanceof UUID) return v.toString(); else if (v instanceof Entity) return ((Entity) v).getId().toString(); case ENUM: return ((Enum) v).name(); case RUNTIME_ENUM: case DATATYPE: case UNARY: if (isDateInterval) return (String) v; //noinspection unchecked Datatype<Object> datatype = Datatypes.getNN(javaClass); return datatype.format(v); default: throw new IllegalStateException("Param type unknown"); } }
@Override public Field createField(ProcFormParam formParam, String actExecutionId) { DateField dateField = componentsFactory.createComponent(DateField.class); standardFieldInit(dateField, formParam); setFieldValue(dateField, formParam, Datatypes.getNN(Date.class), actExecutionId); return dateField; } }
@Override public Field createField(ProcFormParam formParam, String actExecutionId) { CheckBox checkBox = componentsFactory.createComponent(CheckBox.class); standardFieldInit(checkBox, formParam); setFieldValue(checkBox, formParam, Datatypes.getNN(Boolean.class), actExecutionId); return checkBox; } }
private void loadProperties(Element element, KeyValueContainer container) { Element propsEl = element.element("properties"); if (propsEl != null) { for (Element propEl : propsEl.elements()) { String name = propEl.attributeValue("name"); String className = propEl.attributeValue("class"); if (className != null) { container.addProperty(name, ReflectionHelper.getClass(className)); } else { String typeName = propEl.attributeValue("datatype"); Datatype datatype = typeName == null ? Datatypes.getNN(String.class) : Datatypes.get(typeName); container.addProperty(name, datatype); } } String idProperty = propsEl.attributeValue("idProperty"); if (idProperty != null) { if (container.getEntityMetaClass().getProperty(idProperty) == null) throw new DevelopmentException(String.format("Property '%s' is not defined", idProperty)); container.setIdName(idProperty); } } }
@SuppressWarnings("unchecked") protected void writeEntity(JsonWriter out, Entity entity) throws IOException { out.beginObject(); Datatype id = Datatypes.getNN(entity.getMetaClass().getPropertyNN("id").getJavaType()); if (processedObjects.containsKey(entity.getId())) { out.name("metaClass"); out.value(entity.getMetaClass().getName()); out.name("id"); out.value(id.format(entity.getId())); } else { processedObjects.put(entity.getId(), entity); out.name("metaClass"); out.value(entity.getMetaClass().getName()); out.name("id"); out.value(id.format(entity.getId())); writeFields(out, entity); } out.endObject(); }
@Override public Field createField(ProcFormParam formParam, String actExecutionId) { TextField textField = componentsFactory.createComponent(TextField.class); Datatype<BigDecimal> datatype = Datatypes.getNN(BigDecimal.class); textField.setDatatype(datatype); standardFieldInit(textField, formParam); setFieldValue(textField, formParam, datatype, actExecutionId); return textField; } }
@MetaProperty public String getCaption() { Locale defaultLocale = AppBeans.get(MessageTools.class).getDefaultLocale(); String formattedDeploymentDate = Datatypes.getNN(Date.class).format(deploymentDate, defaultLocale); return this.name + " (" + this.code + " - " + formattedDeploymentDate + ")"; } }
@Override public Field createField(ProcFormParam formParam, String actExecutionId) { DateField dateField = componentsFactory.createComponent(DateField.class); dateField.setResolution(DateField.Resolution.DAY); standardFieldInit(dateField, formParam); setFieldValue(dateField, formParam, Datatypes.getNN(java.sql.Date.class), actExecutionId); return dateField; } }
@Override public Field createField(ReportInputParameter parameter) { TextField textField = componentsFactory.createComponent(TextField.class); textField.addValidator(new DoubleValidator()); textField.setDatatype(Datatypes.getNN(Double.class)); return textField; } }
@Override public TextField createField(ProcFormParam formParam, String actExecutionId) { TextField textField = componentsFactory.createComponent(TextField.class); Datatype datatype = Datatypes.getNN(Integer.class); textField.setDatatype(datatype); standardFieldInit(textField, formParam); setFieldValue(textField, formParam, datatype, actExecutionId); return textField; } }
@MetaProperty(related = {"snapshotDate,author"}) public String getLabel() { String name = ""; if (author != null && StringUtils.isNotEmpty(this.author.getCaption())) { name += this.author.getCaption() + " "; } Datatype datatype = Datatypes.getNN(Date.class); UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME); if (userSessionSource != null && userSessionSource.checkCurrentUserSession()) { name += datatype.format(snapshotDate, userSessionSource.getLocale()); } return StringUtils.trim(name); }
public static String formatParamValue(Param param, Object value) { //noinspection unchecked Datatype datatype = Datatypes.get(param.getJavaClass()); MetaProperty property = param.getProperty(); if (property != null) { TemporalType tt = (TemporalType) property.getAnnotations().get(MetadataTools.TEMPORAL_ANN_NAME); if (tt == TemporalType.DATE) { datatype = Datatypes.getNN(java.sql.Date.class); } } if (datatype != null) { UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.class); return datatype.format(value, userSessionSource.getLocale()); } return value.toString(); } }
public KeyValueMetaProperty(MetaClass metaClass, String name, Class javaClass) { this.name = name; this.javaClass = javaClass; this.metaClass = metaClass; this.mandatory = false; Metadata metadata = AppBeans.get(Metadata.NAME); Session metadataSession = metadata.getSession(); if (Entity.class.isAssignableFrom(javaClass)) { range = new ClassRange(metadataSession.getClass(javaClass)); this.type = Type.ASSOCIATION; } else if (EnumClass.class.isAssignableFrom(javaClass)) { @SuppressWarnings("unchecked") EnumerationImpl enumeration = new EnumerationImpl(javaClass); this.range = new EnumerationRange(enumeration); this.type = Type.ENUM; } else { this.range = new DatatypeRange(Datatypes.getNN(javaClass)); this.type = Type.DATATYPE; } }
@Override public void validate(Object value) throws ValidationException { if (value == null) return; boolean result; if (value instanceof String) { try { Datatype datatype = Datatypes.getNN(java.sql.Date.class); UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME); datatype.parse((String) value, sessionSource.getLocale()); result = true; } catch (ParseException e) { result = false; } } else { result = value instanceof Date; } if (!result) { String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'"; throw new ValidationException(String.format(msg, value)); } } }
protected void writeIdField(Entity entity, JsonObject jsonObject) { MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(entity.getMetaClass()); if (primaryKeyProperty == null) { primaryKeyProperty = entity.getMetaClass().getProperty("id"); } if (primaryKeyProperty == null) throw new EntitySerializationException("Primary key property not found for entity " + entity.getMetaClass()); if (metadataTools.hasCompositePrimaryKey(entity.getMetaClass())) { JsonObject serializedIdEntity = serializeEntity((Entity) entity.getId(), null, Collections.emptySet()); jsonObject.add("id", serializedIdEntity); } else { Datatype idDatatype = Datatypes.getNN(primaryKeyProperty.getJavaType()); jsonObject.addProperty("id", idDatatype.format(entity.getId())); } }
public DynamicAttributesMetaProperty(MetaClass metaClass, CategoryAttribute attribute) { this.attribute = attribute; this.javaClass = DynamicAttributesUtils.getAttributeClass(attribute); this.metaClass = metaClass; this.name = DynamicAttributesUtils.encodeAttributeCode(attribute.getCode()); this.mandatory = attribute.getRequired(); Metadata metadata = AppBeans.get(Metadata.NAME); Session metadataSession = metadata.getSession(); if (Entity.class.isAssignableFrom(javaClass)) { range = new ClassRange(metadataSession.getClass(javaClass)); this.type = Type.ASSOCIATION; } else { this.range = new DatatypeRange(Datatypes.getNN(javaClass)); this.type = Type.DATATYPE; } }
@Override public void init(Map<String, Object> params) { super.init(params); sessionsTable.setTextSelectionEnabled(true); sessionsDs.addCollectionChangeListener(e -> { String time = Datatypes.getNN(Date.class).format(sessionsDs.getUpdateTs(), userSessionSource.getLocale()); lastUpdateTsLab.setValue(time); }); addAction(refreshAction); }
@Override public void validate(Object value) throws ValidationException { if (value == null) { return; } boolean result; if (value instanceof String) { try { Datatype<Double> datatype = Datatypes.getNN(Double.class); UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME); Double num = datatype.parse((String) value, sessionSource.getLocale()); result = checkDoubleOnPositive(num); } catch (ParseException e) { result = false; } } else { result = (value instanceof Double && checkDoubleOnPositive((Double) value)) || (value instanceof BigDecimal && checkBigDecimalOnPositive((BigDecimal) value)); } if (!result) { String msg = message != null ? messages.getTools().loadString(messagesPack, message) : "Invalid value '%s'"; throw new ValidationException(String.format(msg, value)); } } }