@Test public void testUpgradeThingFromBenderToCurrent() throws Exception { LOG.info("Upgrade a v5.5.0 Thing data to v" + Info.getVersion()); String xml = IOUtils.toString( this.getClass().getResourceAsStream("thing-5.5.0.xml"), "UTF-8"); String result = (String) dataUpgradeService.upgrade(EnvObject.class, xml, "5.5.0"); XStream xstream = FreedomXStream.getXstream(); EnvObject thing = (EnvObject) xstream.fromXML(result); LOG.info("Loaded from upgraded XML: {}", thing); Assert.assertNotNull(thing); }
@Override public String upgrade(Class type, String xml, String fromVersion) throws DataUpgradeException { if (fromVersion.trim().equals(Info.getVersion())) { LOG.debug("Given data are already consistent with the most recent framework version. No XML transformation was performed"); return xml; } else { LOG.info("Upgrading data of type \"{}\" from version {} to version {}", type.getCanonicalName(), fromVersion, Info.getVersion()); } String upgradedXml; Source xsltAlgorthm; try { if (type == EnvObject.class) { xsltAlgorthm = getTransformationAlgorithm("thing", fromVersion); } else if (type == Environment.class) { xsltAlgorthm = getTransformationAlgorithm("environment", fromVersion); } else if (type == Reaction.class) { xsltAlgorthm = getTransformationAlgorithm("reaction", fromVersion); } else if (type == Command.class) { xsltAlgorthm = getTransformationAlgorithm("command", fromVersion); } else if (type == Trigger.class) { xsltAlgorthm = getTransformationAlgorithm("trigger", fromVersion); } else { throw new DataUpgradeException("Data upgrade service: upgrading entities of type " + type.getCanonicalName() + " is not supported"); } upgradedXml = upgradeContent(xml, xsltAlgorthm); } catch (TransformerException | DataUpgradeException transformerException) { throw new DataUpgradeException("Error while upgrading an XML data source", transformerException); } return upgradedXml; }
DataUpgradeServiceImpl implements DataUpgradeService<String> { @Override public String upgrade(Class type, String xml, String fromVersion) throws DataUpgradeException { if (fromVersion.trim().equals(Info.getVersion())) { LOG.debug("Given data are already consistent with the most recent framework version. No XML transformation was performed"); return xml; } else { LOG.info("Upgrading data of type \"{}\" from version {} to version {}", type.getCanonicalName(), fromVersion, Info.getVersion()); } String upgradedXml; Source xsltAlgorthm; try { if (type == EnvObject.class) { xsltAlgorthm = getTransformationAlgorithm("thing", fromVersion); } else if (type == Environment.class) { xsltAlgorthm = getTransformationAlgorithm("environment", fromVersion); } else if (type == Reaction.class) { xsltAlgorthm = getTransformationAlgorithm("reaction", fromVersion); } else if (type == Command.class) { xsltAlgorthm = getTransformationAlgorithm("command", fromVersion); } else if (type == Trigger.class) { xsltAlgorthm = getTransformationAlgorithm("trigger", fromVersion); } else { throw new DataUpgradeException("Data upgrade service: upgrading entities of type " + type.getCanonicalName() + " is not supported"); } upgradedXml = upgradeContent(xml, xsltAlgorthm); } catch (TransformerException | DataUpgradeException transformerException) { throw new DataUpgradeException("Error while upgrading an XML data source", transformerException); } return upgradedXml; } }
DataUpgradeServiceImpl implements DataUpgradeService<String> { @Override public String upgrade(Class type, String xml, String fromVersion) throws DataUpgradeException { if (fromVersion.trim().equals(Info.getVersion())) { LOG.debug("Given data are already consistent with the most recent framework version. No XML transformation was performed"); return xml; } else { LOG.info("Upgrading data of type \"{}\" from version {} to version {}", type.getCanonicalName(), fromVersion, Info.getVersion()); } String upgradedXml; Source xsltAlgorthm; try { if (type == EnvObject.class) { xsltAlgorthm = getTransformationAlgorithm("thing", fromVersion); } else if (type == Environment.class) { xsltAlgorthm = getTransformationAlgorithm("environment", fromVersion); } else if (type == Reaction.class) { xsltAlgorthm = getTransformationAlgorithm("reaction", fromVersion); } else if (type == Command.class) { xsltAlgorthm = getTransformationAlgorithm("command", fromVersion); } else if (type == Trigger.class) { xsltAlgorthm = getTransformationAlgorithm("trigger", fromVersion); } else { throw new DataUpgradeException("Data upgrade service: upgrading entities of type " + type.getCanonicalName() + " is not supported"); } upgradedXml = upgradeContent(xml, xsltAlgorthm); } catch (TransformerException | DataUpgradeException transformerException) { throw new DataUpgradeException("Error while upgrading an XML data source", transformerException); } return upgradedXml; }  }
DataUpgradeServiceImpl implements DataUpgradeService<String> { @Override public String upgrade(Class type, String xml, String fromVersion) throws DataUpgradeException { if (fromVersion.trim().equals(Info.getVersion())) { LOG.debug("Given data are already consistent with the most recent framework version. No XML transformation was performed"); return xml; } else { LOG.info("Upgrading data of type \"{}\" from version {} to version {}", type.getCanonicalName(), fromVersion, Info.getVersion()); } String upgradedXml; Source xsltAlgorthm; try { if (type == EnvObject.class) { xsltAlgorthm = getTransformationAlgorithm("thing", fromVersion); } else if (type == Environment.class) { xsltAlgorthm = getTransformationAlgorithm("environment", fromVersion); } else if (type == Reaction.class) { xsltAlgorthm = getTransformationAlgorithm("reaction", fromVersion); } else if (type == Command.class) { xsltAlgorthm = getTransformationAlgorithm("command", fromVersion); } else if (type == Trigger.class) { xsltAlgorthm = getTransformationAlgorithm("trigger", fromVersion); } else { throw new DataUpgradeException("Data upgrade service: upgrading entities of type " + type.getCanonicalName() + " is not supported"); } upgradedXml = upgradeContent(xml, xsltAlgorthm); } catch (TransformerException | DataUpgradeException transformerException) { throw new DataUpgradeException("Error while upgrading an XML data source", transformerException); } return upgradedXml; }  @Override String upgrade(Class type, String xml, String fromVersion); }
DataUpgradeServiceImpl implements DataUpgradeService<String> { @Override public String upgrade(Class type, String xml, String fromVersion) throws DataUpgradeException { if (fromVersion.trim().equals(Info.getVersion())) { LOG.debug("Given data are already consistent with the most recent framework version. No XML transformation was performed"); return xml; } else { LOG.info("Upgrading data of type \"{}\" from version {} to version {}", type.getCanonicalName(), fromVersion, Info.getVersion()); } String upgradedXml; Source xsltAlgorthm; try { if (type == EnvObject.class) { xsltAlgorthm = getTransformationAlgorithm("thing", fromVersion); } else if (type == Environment.class) { xsltAlgorthm = getTransformationAlgorithm("environment", fromVersion); } else if (type == Reaction.class) { xsltAlgorthm = getTransformationAlgorithm("reaction", fromVersion); } else if (type == Command.class) { xsltAlgorthm = getTransformationAlgorithm("command", fromVersion); } else if (type == Trigger.class) { xsltAlgorthm = getTransformationAlgorithm("trigger", fromVersion); } else { throw new DataUpgradeException("Data upgrade service: upgrading entities of type " + type.getCanonicalName() + " is not supported"); } upgradedXml = upgradeContent(xml, xsltAlgorthm); } catch (TransformerException | DataUpgradeException transformerException) { throw new DataUpgradeException("Error while upgrading an XML data source", transformerException); } return upgradedXml; }  @Override String upgrade(Class type, String xml, String fromVersion);  }