@Test public void testGenerateContextForModel() { StaticModelFormRenderingContext context = dynamicFormModelGenerator.getContextForModel(model); assertNotNull(context); assertNotNull(context.getRootForm()); assertEquals(3, context.getAvailableForms().size()); context.getAvailableForms().forEach((id, form) -> { testGeneratedForm(form, id); }); }
public StaticModelFormRenderingContext getContextForModel(Object model, FormElementFilter... filters) { PortablePreconditions.checkNotNull("model", model); Optional<FormElementFilter[]> optional = Optional.ofNullable(filters); Stream<FormElementFilter> streamFilter = optional.map(value -> Stream.of(value)).orElseGet(Stream::empty); List<FormElementFilter> rootFormElemenFilters = new ArrayList<>(); List<FormElementFilter> nestedFormFilters = new ArrayList<>(); streamFilter.forEach(filter -> { if(!filter.getElementName().contains(".")) { rootFormElemenFilters.add(filter); } else { nestedFormFilters.add(filter); } }); FormDefinition formDefinition = formBuildingService.generateFormForModel(model, rootFormElemenFilters.stream().toArray(FormElementFilter[]::new)); if (formDefinition == null) { return null; } StaticModelFormRenderingContext context = new StaticModelFormRenderingContext(String.valueOf(System.currentTimeMillis())); context.setModel(model); context.setRootForm(formDefinition); if (context.getModel() != null) { initNestedFormSettings(formDefinition, context.getModel(), context, nestedFormFilters); } else { initNestedFormSettings(formDefinition,null, context, nestedFormFilters); } return context; }
DynamicFormModelGenerator { public StaticModelFormRenderingContext getContextForModel(Object model, FormElementFilter... filters) { PortablePreconditions.checkNotNull("model", model); Optional<FormElementFilter[]> optional = Optional.ofNullable(filters); Stream<FormElementFilter> streamFilter = optional.map(value -> Stream.of(value)).orElseGet(Stream::empty); List<FormElementFilter> rootFormElemenFilters = new ArrayList<>(); List<FormElementFilter> nestedFormFilters = new ArrayList<>(); streamFilter.forEach(filter -> { if(!filter.getElementName().contains(".")) { rootFormElemenFilters.add(filter); } else { nestedFormFilters.add(filter); } }); FormDefinition formDefinition = formBuildingService.generateFormForModel(model, rootFormElemenFilters.stream().toArray(FormElementFilter[]::new)); if (formDefinition == null) { return null; } StaticModelFormRenderingContext context = new StaticModelFormRenderingContext(String.valueOf(System.currentTimeMillis())); context.setModel(model); context.setRootForm(formDefinition); if (context.getModel() != null) { initNestedFormSettings(formDefinition, context.getModel(), context, nestedFormFilters); } else { initNestedFormSettings(formDefinition,null, context, nestedFormFilters); } return context; } }
DynamicFormModelGenerator { public StaticModelFormRenderingContext getContextForModel(Object model, FormElementFilter... filters) { PortablePreconditions.checkNotNull("model", model); Optional<FormElementFilter[]> optional = Optional.ofNullable(filters); Stream<FormElementFilter> streamFilter = optional.map(value -> Stream.of(value)).orElseGet(Stream::empty); List<FormElementFilter> rootFormElemenFilters = new ArrayList<>(); List<FormElementFilter> nestedFormFilters = new ArrayList<>(); streamFilter.forEach(filter -> { if(!filter.getElementName().contains(".")) { rootFormElemenFilters.add(filter); } else { nestedFormFilters.add(filter); } }); FormDefinition formDefinition = formBuildingService.generateFormForModel(model, rootFormElemenFilters.stream().toArray(FormElementFilter[]::new)); if (formDefinition == null) { return null; } StaticModelFormRenderingContext context = new StaticModelFormRenderingContext(String.valueOf(System.currentTimeMillis())); context.setModel(model); context.setRootForm(formDefinition); if (context.getModel() != null) { initNestedFormSettings(formDefinition, context.getModel(), context, nestedFormFilters); } else { initNestedFormSettings(formDefinition,null, context, nestedFormFilters); } return context; } @Inject  DynamicFormModelGenerator(FormBuildingService formBuildingService,
                                     PropertyValueExtractor propertyValueExtractor); }
DynamicFormModelGenerator { public StaticModelFormRenderingContext getContextForModel(Object model, FormElementFilter... filters) { PortablePreconditions.checkNotNull("model", model); Optional<FormElementFilter[]> optional = Optional.ofNullable(filters); Stream<FormElementFilter> streamFilter = optional.map(value -> Stream.of(value)).orElseGet(Stream::empty); List<FormElementFilter> rootFormElemenFilters = new ArrayList<>(); List<FormElementFilter> nestedFormFilters = new ArrayList<>(); streamFilter.forEach(filter -> { if(!filter.getElementName().contains(".")) { rootFormElemenFilters.add(filter); } else { nestedFormFilters.add(filter); } }); FormDefinition formDefinition = formBuildingService.generateFormForModel(model, rootFormElemenFilters.stream().toArray(FormElementFilter[]::new)); if (formDefinition == null) { return null; } StaticModelFormRenderingContext context = new StaticModelFormRenderingContext(String.valueOf(System.currentTimeMillis())); context.setModel(model); context.setRootForm(formDefinition); if (context.getModel() != null) { initNestedFormSettings(formDefinition, context.getModel(), context, nestedFormFilters); } else { initNestedFormSettings(formDefinition,null, context, nestedFormFilters); } return context; } @Inject  DynamicFormModelGenerator(FormBuildingService formBuildingService,
                                     PropertyValueExtractor propertyValueExtractor); StaticModelFormRenderingContext getContextForModel(Object model, FormElementFilter... filters); }
DynamicFormModelGenerator { public StaticModelFormRenderingContext getContextForModel(Object model, FormElementFilter... filters) { PortablePreconditions.checkNotNull("model", model); Optional<FormElementFilter[]> optional = Optional.ofNullable(filters); Stream<FormElementFilter> streamFilter = optional.map(value -> Stream.of(value)).orElseGet(Stream::empty); List<FormElementFilter> rootFormElemenFilters = new ArrayList<>(); List<FormElementFilter> nestedFormFilters = new ArrayList<>(); streamFilter.forEach(filter -> { if(!filter.getElementName().contains(".")) { rootFormElemenFilters.add(filter); } else { nestedFormFilters.add(filter); } }); FormDefinition formDefinition = formBuildingService.generateFormForModel(model, rootFormElemenFilters.stream().toArray(FormElementFilter[]::new)); if (formDefinition == null) { return null; } StaticModelFormRenderingContext context = new StaticModelFormRenderingContext(String.valueOf(System.currentTimeMillis())); context.setModel(model); context.setRootForm(formDefinition); if (context.getModel() != null) { initNestedFormSettings(formDefinition, context.getModel(), context, nestedFormFilters); } else { initNestedFormSettings(formDefinition,null, context, nestedFormFilters); } return context; } @Inject  DynamicFormModelGenerator(FormBuildingService formBuildingService,
                                     PropertyValueExtractor propertyValueExtractor); StaticModelFormRenderingContext getContextForModel(Object model, FormElementFilter... filters);  }