/** * Check the data constraints and return the associated parameter definition. */ private void checkConstraints(final BasicParameterValueVo vo, final Parameter parameter) { typeToChecker.get(parameter.getType()).accept(vo, parameter); }
/** * Parse the raw data to the target type and return this value. * * @param entity * {@link ParameterValue} to be parsed. * @param vo * Target object receiving the typed value. * @return the parsed and typed value. * @param <T> * The object type resolved during the parsing. */ public static <T> T parseValue(final ParameterValue entity, final BasicParameterValueVo vo) { @SuppressWarnings("unchecked") final ParameterValueMapper<T> valueMapper = (ParameterValueMapper<T>) TO_VALUE .get(entity.getParameter().getType()); final T parsedValue = valueMapper.toValue.apply(entity.getData()); valueMapper.setter.accept(vo, parsedValue); return parsedValue; }
/** * {@link Parameter} JPA to {@link ParameterVo} transformer. * * @param entity * The source JPA entity to convert. * @return The VO with all attributes : full node reference, and definition. */ public static ParameterVo toVo(final Parameter entity) { final ParameterVo vo = new ParameterVo(); // Copy basic data vo.setId(entity.getId()); vo.setType(entity.getType()); vo.setMandatory(entity.isMandatory()); vo.setSecured(entity.isSecured()); vo.setOwner(NodeResource.toVo(entity.getOwner())); vo.setDefaultValue(entity.getDefaultValue()); vo.setDepends(entity.getDepends().stream().map(Persistable::getId).collect(Collectors.toSet())); // Map constraint data if (entity.getType().isArray()) { vo.setValues(toConfiguration(entity.getData(), LIST_STRING_TYPE)); } else if (entity.getType() == ParameterType.INTEGER) { final Map<String, Integer> minMax = toConfiguration(entity.getData(), MAP_STRING_TYPE); vo.setMax(minMax.get("max")); vo.setMin(minMax.get("min")); } return vo; }