OpenImmo_1_2_7 extends XmlConverter<OpenImmoDocument, OpenImmoVersion> { protected void downgradeEnergiepassElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; Element parentNode = (Element) node.getParentNode(); boolean stromwertPassed = false; boolean waermewertPassed = false; boolean wertklassePassed = false; boolean baujahrPassed = false; boolean ausstelldatumPassed = false; boolean jahrgangPassed = false; boolean gebaeudeartPassed = false; List childNodes; childNodes = XmlUtils.newXPath("io:primaerenergietraeger", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; node.removeChild(childNode); } childNodes = XmlUtils.newXPath("io:epasstext", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; node.removeChild(childNode); } childNodes = XmlUtils.newXPath("io:stromwert", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!stromwertPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild(OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_stromwert", value)); stromwertPassed = true; } } node.removeChild(childNode); } childNodes = XmlUtils.newXPath("io:waermewert", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!waermewertPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild(OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_waermewert", value)); waermewertPassed = true; } } node.removeChild(childNode); } childNodes = XmlUtils.newXPath("io:wertklasse", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!wertklassePassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild(OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_wertklasse", value)); wertklassePassed = true; } } node.removeChild(childNode); } childNodes = XmlUtils.newXPath("io:baujahr", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!baujahrPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild(OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_baujahr", value)); baujahrPassed = true; } } node.removeChild(childNode); } childNodes = XmlUtils.newXPath("io:ausstelldatum", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!ausstelldatumPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if (value != null) { parentNode.appendChild(OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_ausstelldatum", value)); ausstelldatumPassed = true; } } node.removeChild(childNode); } childNodes = XmlUtils.newXPath("io:jahrgang", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!jahrgangPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if ("2008".equalsIgnoreCase(value) || "2014".equalsIgnoreCase(value) || "ohne".equalsIgnoreCase(value)) { parentNode.appendChild(OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_jahrgang", value)); jahrgangPassed = true; } } node.removeChild(childNode); } childNodes = XmlUtils.newXPath("io:gebaeudeart", doc) .selectNodes(node); for (Object childItem : childNodes) { Node childNode = (Node) childItem; if (!gebaeudeartPassed) { String value = StringUtils.trimToNull(childNode.getTextContent()); if ("wohn".equalsIgnoreCase(value) || "nichtwohn".equalsIgnoreCase(value) || "ohne".equalsIgnoreCase(value)) { parentNode.appendChild(OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_gebaeudeart", value)); gebaeudeartPassed = true; } } node.removeChild(childNode); } } }  @Override OpenImmoVersion getVersion(); @Override void downgradeToPreviousVersion(OpenImmoDocument doc); @Override void upgradeFromPreviousVersion(OpenImmoDocument doc);  }
@Test public void testDowngradeEnergiepassElements() { try { Document doc = buildTransferDocumentForDowngrade(); int count; count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:waermewert", doc); Assert.assertEquals( "1 convertable <waermewert> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:stromwert", doc); Assert.assertEquals( "1 convertable <stromwert> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:wertklasse", doc); Assert.assertEquals( "1 convertable <wertklasse> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:baujahr", doc); Assert.assertEquals( "1 convertable <baujahr> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:ausstelldatum", doc); Assert.assertEquals( "1 convertable <ausstelldatum> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:jahrgang", doc); Assert.assertEquals( "1 convertable <jahrgang> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:gebaeudeart", doc); Assert.assertEquals( "1 convertable <gebaeudeart> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:primaerenergietraeger", doc); Assert.assertEquals( "1 convertable <primaerenergietraeger> element available before conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:epasstext", doc); Assert.assertEquals( "1 convertable <epasstext> element available before conversion.", 1, count); new OpenImmo_1_2_7().downgradeEnergiepassElements(doc); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:waermewert", doc); Assert.assertEquals( "0 convertable <waermewert> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:stromwert", doc); Assert.assertEquals( "0 convertable <stromwert> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:wertklasse", doc); Assert.assertEquals( "0 convertable <wertklasse> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:baujahr", doc); Assert.assertEquals( "0 convertable <baujahr> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:ausstelldatum", doc); Assert.assertEquals( "0 convertable <ausstelldatum> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:jahrgang", doc); Assert.assertEquals( "0 convertable <jahrgang> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:gebaeudeart", doc); Assert.assertEquals( "0 convertable <gebaeudeart> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:primaerenergietraeger", doc); Assert.assertEquals( "0 convertable <primaerenergietraeger> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass/io:epasstext", doc); Assert.assertEquals( "0 convertable <epasstext> elements available after conversion.", 0, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:user_defined_simplefield[@feldname='epass_waermewert']", doc); Assert.assertEquals( "1 converted <user_defined_simplefield feldname=\"epass_waermewert\"> element available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:user_defined_simplefield[@feldname='epass_stromwert']", doc); Assert.assertEquals( "1 converted <user_defined_simplefield feldname=\"epass_stromwert\"> element available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:user_defined_simplefield[@feldname='epass_wertklasse']", doc); Assert.assertEquals( "1 converted <user_defined_simplefield feldname=\"epass_wertklasse\"> element available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:user_defined_simplefield[@feldname='epass_baujahr']", doc); Assert.assertEquals( "1 converted <user_defined_simplefield feldname=\"epass_baujahr\"> element available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:user_defined_simplefield[@feldname='epass_ausstelldatum']", doc); Assert.assertEquals( "1 converted <user_defined_simplefield feldname=\"epass_ausstelldatum\"> element available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:user_defined_simplefield[@feldname='epass_jahrgang']", doc); Assert.assertEquals( "1 converted <user_defined_simplefield feldname=\"epass_jahrgang\"> element available after conversion.", 1, count); count = XmlUtils.countNodes( "/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:user_defined_simplefield[@feldname='epass_gebaeudeart']", doc); Assert.assertEquals( "1 converted <user_defined_simplefield feldname=\"epass_gebaeudeart\"> element available after conversion.", 1, count); } catch (Exception ex) { LOGGER.error("Test of OpenImmo_1_2_7.downgradeEnergiepassElements failed!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); Assert.fail("Test of OpenImmo_1_2_7.downgradeEnergiepassElements failed!"); } }