BusinessDataToWidgetMapper { public Container generateMasterDetailsPattern(NodeBusinessObjectInput nodeBusinessObjectInput, List<List<Element>> rows) { rows.add(Collections.<Element>singletonList(createTitle(nodeBusinessObjectInput.formatName()))); if (isRootOrMultipleInput(nodeBusinessObjectInput)) { TableWidget table = addTableWidget(nodeBusinessObjectInput, rows); rows.add(Collections.<Element>singletonList(table.toComponent(dimensionFactory))); } else { if (nodeBusinessObjectInput.getDataReference() != null && nodeBusinessObjectInput.getDataReference().getLoadingType().equals(BusinessDataReference.LoadingType.LAZY)) { BusinessDataLazyRef content = generateVariable(nodeBusinessObjectInput); businessObjectContainer.addVariable(nodeBusinessObjectInput.getPageDataName(), new Variable(DataType.URL, content.create().getValue().toString())); } } List<Element> row = createDetailsRow(nodeBusinessObjectInput); rows.add(row); return (Container) row.get(1); } BusinessDataToWidgetMapper(DimensionFactory dimensionFactory, BusinessObjectContainer businessObjectContainer); Container generateMasterDetailsPattern(NodeBusinessObjectInput nodeBusinessObjectInput, List<List<Element>> rows); List<Element> toElement(LeafContractInput contractInput);  }
@Test public void should_generate_title_and_table_widgets_pattern_when_node_is_read() { BusinessObjectContainer boc = new BusinessObjectContainer(); BusinessDataToWidgetMapper businessDataToWidgetMapper = makeBusinessDataToWidgetMapper(boc); NodeBusinessObjectInput node = new NodeBusinessObjectInput("com.company.model.person", "person"); node.addInput(aContractInput("addresses").mulitple().withType(String.class.getName()).build()); node.addInput(aContractInput("firstName").withType(String.class.getName()).build()); node.addInput(aContractInput("lastName").withType(String.class.getName()).build()); businessDataToWidgetMapper.generateMasterDetailsPattern(node, boc.getContainer().getRows()); Component title = (Component) boc.getContainer().getRows().get(0).get(0); assertThat(title.getId()).isEqualTo("pbTitle"); PropertyValue titleCollectionPropertyValue = title.getPropertyValues().get("text"); assertThat(titleCollectionPropertyValue.getType()).isEqualTo("interpolation"); assertThat(titleCollectionPropertyValue.getValue()).isEqualTo("Person"); Component tableWidget = (Component) boc.getContainer().getRows().get(1).get(0); assertThat(tableWidget.getId()).isEqualTo("pbTable"); Map<String, Variable> variables = boc.getBusinessObjectVariable(); assertThat(variables.size()).isEqualTo(1); assertThat(variables.get("person_selected")).isNotNull(); }
@Test public void should_generate_external_url_on_master_details_pattern_when_nested_object_is_lazy_loading() { BusinessObjectContainer boc = new BusinessObjectContainer(); BusinessDataToWidgetMapper businessDataToWidgetMapper = makeBusinessDataToWidgetMapper(boc); NodeBusinessObjectInput childNode = aNestedObjectInLazyAggregation(true); childNode.setMultiple(true); businessDataToWidgetMapper.generateMasterDetailsPattern(childNode, boc.getContainer().getRows()); Component title = (Component) boc.getContainer().getRows().get(0).get(0); assertThat(title.getId()).isEqualTo("pbTitle"); PropertyValue titleCollectionPropertyValue = title.getPropertyValues().get("text"); assertThat(titleCollectionPropertyValue.getType()).isEqualTo("interpolation"); assertThat(titleCollectionPropertyValue.getValue()).isEqualTo("Addresses"); Component tableWidget = (Component) boc.getContainer().getRows().get(1).get(0); assertThat(tableWidget.getId()).isEqualTo("pbTable"); Map<String, PropertyValue> tableCollectionPropertyValue = tableWidget.getPropertyValues(); assertThat(tableCollectionPropertyValue.get("content").getValue()).isEqualTo("customer_addresses"); assertThat(tableCollectionPropertyValue.get("selectedRow").getValue()).isEqualTo("customer_addresses_selected"); assertThat(tableCollectionPropertyValue.get("headers").getValue()).isEqualTo(Arrays.asList("Addresses")); Map<String, Variable> variables = boc.getBusinessObjectVariable(); assertThat(variables.size()).isEqualTo(2); assertThat(variables.get("customer_addresses_selected")).isNotNull(); assertThat(variables.get("customer_addresses").getType()).isEqualTo(DataType.URL); assertThat(variables.get("customer_addresses").getValue().get(0)).isEqualTo("{{customer_selected|lazyRef:'addresses'}}"); }
@Test public void should_generate_master_details_when_nested_object_is_loading_on_composition_and_eager() { BusinessObjectContainer boc = new BusinessObjectContainer(); BusinessDataToWidgetMapper businessDataToWidgetMapper = makeBusinessDataToWidgetMapper(boc); NodeBusinessObjectInput node = aNestedObjectInCompositionAndEager(); node.setMultiple(true); businessDataToWidgetMapper.generateMasterDetailsPattern(node, boc.getContainer().getRows()); Component title = (Component) boc.getContainer().getRows().get(0).get(0); assertThat(title.getId()).isEqualTo("pbTitle"); PropertyValue titleCollectionPropertyValue = title.getPropertyValues().get("text"); assertThat(titleCollectionPropertyValue.getType()).isEqualTo("interpolation"); assertThat(titleCollectionPropertyValue.getValue()).isEqualTo("Sport"); Component tableWidget = (Component) boc.getContainer().getRows().get(1).get(0); assertThat(tableWidget.getId()).isEqualTo("pbTable"); Map<String, PropertyValue> tableCollectionPropertyValue = tableWidget.getPropertyValues(); assertThat(tableCollectionPropertyValue.get("content").getValue()).isEqualTo("person_selected.sport"); assertThat(tableCollectionPropertyValue.get("selectedRow").getValue()).isEqualTo("person_sport_selected"); assertThat(tableCollectionPropertyValue.get("headers").getValue()).isEqualTo(Arrays.asList("Name", "Need Balls")); Map<String, Variable> variables = boc.getBusinessObjectVariable(); assertThat(variables.size()).isEqualTo(1); assertThat(variables.get("person_sport_selected")).isNotNull(); }
@Test public void should_not_generate_table_widget_when_child_object_is_not_multiple() { BusinessObjectContainer boc = new BusinessObjectContainer(); BusinessDataToWidgetMapper businessDataToWidgetMapper = makeBusinessDataToWidgetMapper(boc); NodeBusinessObjectInput childNode = aNestedObjectInLazyAggregation(true); childNode.setMultiple(false); businessDataToWidgetMapper.generateMasterDetailsPattern(childNode, boc.getContainer().getRows()); Component title = (Component) boc.getContainer().getRows().get(0).get(0); assertThat(title.getId()).isEqualTo("pbTitle"); PropertyValue titleCollectionPropertyValue = title.getPropertyValues().get("text"); assertThat(titleCollectionPropertyValue.getType()).isEqualTo("interpolation"); assertThat(titleCollectionPropertyValue.getValue()).isEqualTo("Addresses"); List<Element> detailsRows = boc.getContainer().getRows().get(1); assertThat(detailsRows.size()).isEqualTo(2); Map<String, Variable> variables = boc.getBusinessObjectVariable(); assertThat(variables.get("customer_addresses").getType()).isEqualTo(DataType.URL); assertThat(variables.get("customer_addresses").getValue().get(0)).isEqualTo("{{customer_selected|lazyRef:'addresses'}}"); }