protected Datatype getDatatype(Class clazz) { if (clazz == Integer.TYPE || clazz == Byte.TYPE || clazz == Short.TYPE) return Datatypes.get(Integer.class); if (clazz == Long.TYPE) return Datatypes.get(Long.class); if (clazz == Boolean.TYPE) return Datatypes.get(Boolean.class); return Datatypes.get(clazz); }
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); } } }
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(); } }
protected Datatype getDatatype(Class clazz) { if (clazz == Integer.TYPE || clazz == Byte.TYPE || clazz == Short.TYPE) return Datatypes.get(Integer.class); if (clazz == Long.TYPE) return Datatypes.get(Long.class); if (clazz == Boolean.TYPE) return Datatypes.get(Boolean.class); return Datatypes.get(clazz); }
private void loadProperties(Element element, ValueDatasource datasource) { Element propsEl = element.element("properties"); if (propsEl != null) { for (Element propEl : Dom4j.elements(propsEl)) { String name = propEl.attributeValue("name"); String className = propEl.attributeValue("class"); if (className != null) { datasource.addProperty(name, ReflectionHelper.getClass(className)); } else { String typeName = propEl.attributeValue("datatype"); Datatype datatype = typeName == null ? Datatypes.getNN(String.class) : Datatypes.get(typeName); datasource.addProperty(name, datatype); } } String idProperty = propsEl.attributeValue("idProperty"); if (idProperty != null) { if (datasource.getMetaClass().getProperty(idProperty) == null) throw new DevelopmentException(String.format("Property '%s' is not defined", idProperty)); datasource.setIdName(idProperty); } } }
public DateDeserializer() { dateDatatype = Datatypes.get(Date.class); }
public DateSerializer() { dateDatatype = Datatypes.get(Date.class); }
protected boolean isDatatypeMayBeHidden() { if (Strings.isNullOrEmpty(dataTypeName)) return false; Datatype datatype = Datatypes.get(dataTypeName); return datatype instanceof StringDatatype || datatype instanceof NumberDatatype; } }
protected void loadDatatype(HasDatatype component, Element element) { String datatypeAttribute = element.attributeValue("datatype"); if (StringUtils.isNotEmpty(datatypeAttribute)) { //noinspection unchecked component.setDatatype(Datatypes.get(datatypeAttribute)); } } }
protected Object readSimpleProperty(JsonReader in, Class<?> propertyType) throws IOException { String value = in.nextString(); Object parsedValue = null; try { Datatype<?> datatype = Datatypes.get(propertyType); if (datatype != null) { parsedValue = datatype.parse(value); } return parsedValue; } catch (ParseException e) { throw new RuntimeException( format("An error occurred while parsing property. Class [%s]. Value [%s].", propertyType, value), e); } }
/** * Parses string value into specific type * * @param value value to parse * @param typeName Datatype name * @return parsed object */ public static Object parseByTypename(String value, String typeName) { Datatype datatype = Datatypes.get(typeName); try { return datatype.parse(value); } catch (ParseException e) { throw new IllegalArgumentException(String.format("Cannot parse specified parameter of type '%s'", typeName), e); } }
@Override public String convertToString(Class parameterClass, Object paramValue) { if (paramValue == null) { return null; } else if (String.class.isAssignableFrom(parameterClass)) { return (String) paramValue; } else if (Entity.class.isAssignableFrom(parameterClass)) { return EntityLoadInfo.create((Entity) paramValue).toString(); } else { Datatype datatype = Datatypes.get(parameterClass); if (datatype != null) { return datatype.format(paramValue); } else { return String.valueOf(paramValue); } } }
protected void writeSimpleProperty(JsonWriter out, Entity entity, MetaProperty property) throws IOException { Object value = entity.getValue(property.getName()); if (value != null) { out.name(property.getName()); Datatype datatype = Datatypes.get(property.getJavaType()); if (datatype != null) { out.value(datatype.format(value)); } else { out.value(String.valueOf(value)); } } }
@Override public Field createField(ProcFormParam formParam, String actExecutionId) { TextField textField = componentsFactory.createComponent(TextField.class); Datatype datatype = Datatypes.get(Long.class); textField.setDatatype(datatype); standardFieldInit(textField, formParam); setFieldValue(textField, formParam, datatype, actExecutionId); return textField; } }
return parsedEnum; } else { Datatype datatype = Datatypes.get(clazz); return datatype != null ? datatype.parse(string) : string;
@Override public String format(Object o) { if (o != null) { Datatype datatype = Datatypes.get(o.getClass()); if (datatype != null) { if (userSessionSource.checkCurrentUserSession()) { return datatype.format(o, userSessionSource.getLocale()); } else { return datatype.format(o); } } else if (o instanceof Enum) { return messages.getMessage((Enum) o); } else if (o instanceof Instance) { return ((Instance) o).getInstanceName(); } else { return String.valueOf(o); } } else { return null; } } }
protected GroupDatasource createDataSource(String dataSetName, List<KeyValueEntity> keyValueEntities, Map<String, Set<Pair<String, Class>>> headerMap) { DsBuilder dsBuilder = DsBuilder.create(getDsContext()) .setId(dataSetName + "Ds") .setDataSupplier(getDsContext().getDataSupplier()); ValueGroupDatasourceImpl ds = dsBuilder.buildValuesGroupDatasource(); ds.setRefreshMode(CollectionDatasource.RefreshMode.NEVER); Set<Pair<String, Class>> headers = headerMap.get(dataSetName); for (Pair<String, Class> pair : headers) { Class javaClass = pair.getSecond(); if (Entity.class.isAssignableFrom(javaClass) || EnumClass.class.isAssignableFrom(javaClass) || Datatypes.get(javaClass) != null) { ds.addProperty(pair.getFirst(), pair.getSecond()); } } dsContext.register(ds); keyValueEntities.forEach(ds::includeItem); return ds; }
@Override public void commitAndClose() { SessionAttribute item = datasource.getItem(); if (item.getStringValue() != null) { Datatype dt = Datatypes.get(item.getDatatype()); try { Object object = dt.parse(item.getStringValue()); item.setStringValue(object == null ? "" : object.toString()); } catch (IllegalArgumentException | ParseException e) { showNotification(getMessage("unableToParseValue"), NotificationType.ERROR); return; } } super.commitAndClose(); } }
protected void compileSessionAttributes(UserSession session, Group group) { List<SessionAttribute> list = new ArrayList<>(group.getSessionAttributes()); EntityManager em = persistence.getEntityManager(); TypedQuery<SessionAttribute> q = em.createQuery("select a from sec$GroupHierarchy h join h.parent.sessionAttributes a " + "where h.group.id = ?1 order by h.level desc", SessionAttribute.class); q.setParameter(1, group.getId()); List<SessionAttribute> attributes = q.getResultList(); list.addAll(attributes); for (SessionAttribute attribute : list) { Datatype datatype = Datatypes.get(attribute.getDatatype()); try { if (session.getAttributeNames().contains(attribute.getName())) { log.warn("Duplicate definition of '{}' session attribute in the group hierarchy", attribute.getName()); } Serializable value = (Serializable) datatype.parse(attribute.getStringValue()); if (value != null) session.setAttribute(attribute.getName(), value); else session.removeAttribute(attribute.getName()); } catch (ParseException e) { throw new RuntimeException("Unable to set session attribute " + attribute.getName(), e); } } }
@Override public Object convertFromString(Class parameterClass, String paramValueStr) { if (paramValueStr == null) { return null; } else if (String.class.isAssignableFrom(parameterClass)) { return paramValueStr; } else if (Entity.class.isAssignableFrom(parameterClass)) { EntityLoadInfo entityLoadInfo = EntityLoadInfo.parse(paramValueStr); if (entityLoadInfo != null) { return dataManager.load(new LoadContext(entityLoadInfo.getMetaClass()).setId(entityLoadInfo.getId()).setView(View.BASE)); } else { UUID id = UUID.fromString(paramValueStr); return dataManager.load(new LoadContext(parameterClass).setId(id).setView(View.BASE)); } } else { Datatype datatype = Datatypes.get(parameterClass); if (datatype != null) { try { return datatype.parse(paramValueStr); } catch (ParseException e) { throw new ReportingException( String.format("Couldn't read value [%s] with datatype [%s].", paramValueStr, datatype)); } } else { return convertFromStringUnresolved(parameterClass, paramValueStr); } } } }