private JsonNode addSections(List<HtmlFormSection> sections, ObjectMapper jackson) { ArrayNode node = jackson.createArrayNode(); for (HtmlFormSection section : sections) { ObjectNode sectionNode = jackson.createObjectNode(); sectionNode.put("name", section.getName()); if (section.getSections() != null && section.getSections().size() > 0) { sectionNode.put("sections", (addSections(section.getSections(), jackson))); } if (section.getFields() != null && section.getFields().size() > 0) { sectionNode.put("fields", (addFields(section.getFields(), jackson))); } node.add(sectionNode); } return node; }
public void beginSection() { beginSection(new HtmlFormSection()); }
/** * Adds a new section */ public void beginSection(HtmlFormSection section) { // is this a top-level section or it is a child of the existing section if (sectionsStack.size() > 0) { sectionsStack.peek().addChildSection(section); } else { schema.getSections().add(section); } sectionsStack.push(section); }
private Set<HtmlFormField> getAllFieldsRecursiveSectionHelper(Set<HtmlFormField> fields, HtmlFormSection section) { getAllFieldsRecursiveFieldHelper(fields, section == null ? this.getFields() : section.getFields()); for (HtmlFormSection s : section == null ? this.getSections() : section.getSections()) { getAllFieldsRecursiveSectionHelper(fields, s); } return fields; }
HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1); when(groupConcept.getName()).thenReturn(groupConceptName); ObsGroup obsGroup = new ObsGroup(groupConcept); section1.getFields().add(obsGroup);
HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1); when(concept1.getDatatype()).thenReturn(datatype1); field1.setQuestion(concept1); section1.addField(field1); when(concept2.getDatatype()).thenReturn(datatype2); field2.setQuestion(concept2); section1.addField(field2); HtmlFormSection section2 = new HtmlFormSection(); section2.setName("Section 2"); schema.getSections().add(section2);
@Test public void shouldBuildSchemaWithSectionsNestedSections() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); HtmlFormSection section1a = new HtmlFormSection(); section1a.setName("Section 1a"); section1.addChildSection(section1a); HtmlFormSection section1b = new HtmlFormSection(); section1b.setName("Section 1b"); section1.addChildSection(section1b); schema.getSections().add(section1); HtmlFormSection section2 = new HtmlFormSection(); section2.setName("Section 2"); schema.getSections().add(section2); JsonNode schemaAsJson = new HtmlFormEncounterController().buildSchemaAsJsonNode(schema, new ObjectMapper()); assertThat(schemaAsJson.get("sections").get(0).get("name").getValueAsText(), is("Section 1")); assertThat(schemaAsJson.get("sections").get(0).get("sections").get(0).get("name").getValueAsText(), is("Section 1a")); assertThat(schemaAsJson.get("sections").get(0).get("sections").get(1).get("name").getValueAsText(), is("Section 1b")); assertThat(schemaAsJson.get("sections").get(1).get("name").getValueAsText(), is("Section 2")); }
@Test public void shouldBuildSchemaWithSections() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1); HtmlFormSection section2 = new HtmlFormSection(); section2.setName("Section 2"); schema.getSections().add(section2); JsonNode schemaAsJson = new HtmlFormEncounterController().buildSchemaAsJsonNode(schema, new ObjectMapper()); assertThat(schemaAsJson.get("sections").get(0).get("name").getValueAsText(), is("Section 1")); assertThat(schemaAsJson.get("sections").get(1).get("name").getValueAsText(), is("Section 2")); }
public Set<HtmlFormSection> getAllSectionsRecursiveHelper(Set<HtmlFormSection> sections, HtmlFormSection section) { if (sections != null) { for (HtmlFormSection s : section == null ? this.getSections() : section.getSections()) { sections.add(s); getAllSectionsRecursiveHelper(sections, s); } } return sections; }
/** * Adds an HTML Form Field to the schema * * @param field the field to add */ public void addFieldToActiveSection(HtmlFormField field) { if (sectionsStack.size() > 0) { sectionsStack.peek().addField(field); } else { schema.getFields().add(field); } }
@Override public boolean doStartTag(FormEntrySession session, PrintWriter out, Node parent, Node node) { String sectionTag = getAttribute(node, "sectionTag", "div"); String headerTag = getAttribute(node, "headerTag", "span"); String sectionStyleClass = getAttribute(node, "sectionStyle", "section"); String headerStyleClass = getAttribute(node, "headerStyle", "sectionHeader"); String sectionId = getAttribute(node, "id", null); String headerLabel = getAttribute(node, "headerLabel", null); if (headerLabel == null) { String headerCode = getAttribute(node, "headerCode", null); if (headerCode != null) { Translator trans = session.getContext().getTranslator(); headerLabel = trans.translate(Context.getLocale().toString(), headerCode); } } out.print("<" + sectionTag + " class=\""+sectionStyleClass + "\""); if (sectionId != null) { out.print(" id=\"" + sectionId + "\""); } out.print(">"); if (headerLabel != null) { out.print("<" + headerTag + " class=\""+headerStyleClass+"\">"+headerLabel+"</" + headerTag + ">"); } session.getContext().beginSection(); session.getContext().getActiveSection().setName(headerLabel); return true; }
HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1); when(groupConcept.getName()).thenReturn(groupConceptName); ObsGroup obsGroup = new ObsGroup(groupConcept); section1.getFields().add(obsGroup);
HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1); obs1.setValueNumeric(new Double(123)); field1.setExistingObs(obs1); section1.addField(field1); obs2.setValueDate(obsDateValue); field2.setExistingObs(obs2); section1.addField(field2); obs3.setValueDate(obsDateValue); field3.setExistingObs(obs3); section1.addField(field3); obs4.setValueDate(obsDateValue); field4.setExistingObs(obs4); section1.addField(field4); when(obs5.getValueBoolean()).thenReturn(false); field5.setExistingObs(obs5); section1.addField(field5); obs6.setValueText("test test"); field6.setExistingObs(obs6); section1.addField(field6); when(obs7.getValueCodedName()).thenReturn(conceptName7);
@Test public void shouldBuildSchemaWithSectionAndSeparateField() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1); ObsField field1 = new ObsField(); field1.setName("Field 1"); schema.getFields().add(field1); JsonNode schemaAsJson = new HtmlFormEncounterController().buildSchemaAsJsonNode(schema, new ObjectMapper()); assertThat(schemaAsJson.get("sections").get(0).get("name").getValueAsText(), is("Section 1")); assertThat(schemaAsJson.get("fields").get(0).get("name").getValueAsText(), is("Field 1")); }
Assert.assertThat(hfs.getSections().get(0).getName(), is("Section One")); Assert.assertThat(hfs.getSections().get(0).getFields().size(), is(1)); Assert.assertThat(((ObsField) hfs.getSections().get(0).getFields().get(0)).getQuestion().getId(), is(3032)); Assert.assertThat(hfs.getSections().get(0).getSections().size(), is(1)); Assert.assertThat(hfs.getSections().get(0).getSections().get(0).getName(), is("Section One Inner One")); List<HtmlFormField> fields = hfs.getSections().get(0).getSections().get(0).getFields(); Assert.assertThat(fields.size(), is(3)); Assert.assertTrue(fields.get(0) instanceof ObsGroup);
@Before public void before() throws Exception { section = new HtmlFormSection(); formEntryContext = mock(FormEntryContext.class); when(formEntryContext.getActiveSection()).thenReturn(section); formEntrySession = mock(FormEntrySession.class); when(formEntrySession.getContext()).thenReturn(formEntryContext); out = new CapturingPrintWriter(); handler = new SectionTagHandler(); }