@Test public void testBuildMigrationStrategyMap() throws NoSuchFieldException, IllegalAccessException { ApiSchemaAdapter apiSchemaAdapter = initApiSchemaAdapter(); List<MigrationStrategy> downList = apiSchemaAdapter.getDownMigrationStrategies("session", ONE); List<MigrationStrategy> upList = apiSchemaAdapter.getUpMigrationStrategies("session", ONE); assertTrue(downList != null); assertTrue(upList != null); assertTrue(downList.get(0) instanceof AddStrategy); assertTrue((getField(downList.get(0), "fieldName")).equals("downFoo")); assertTrue((getField(downList.get(0), "defaultValue")).equals("downBar")); assertTrue(downList.get(1) instanceof RemoveFieldStrategy); assertTrue(( getField(downList.get(1), "fieldName")).equals("removeDownFoo")); assertTrue(downList.get(2) instanceof RenameFieldStrategy); assertTrue((getField(downList.get(2), "oldFieldName")).equals("oldDownFoo")); assertTrue((getField(downList.get(2), "newFieldName")).equals("newDownFoo")); assertTrue(upList.get(0) instanceof AddStrategy); assertTrue(( getField(upList.get(0), "fieldName")).equals("upFoo")); assertTrue((getField(upList.get(0), "defaultValue")).equals("upBar")); assertTrue(upList.get(1) instanceof RemoveFieldStrategy); assertTrue(( getField(upList.get(1), "fieldName")).equals("removeUpFoo")); assertTrue(upList.get(2) instanceof RenameFieldStrategy); assertTrue((getField(upList.get(2), "oldFieldName")).equals("oldUpFoo")); assertTrue((getField(upList.get(2), "newFieldName")).equals("newUpFoo")); }
private Map<String, Map<String, List<MigrationStrategy>>> buildMigrationStrategyMap(Resource migrationConfigResource) { Map<String, Map<String, List<MigrationStrategy>>> migrationStrategyMap = new HashMap<String, Map<String, List<MigrationStrategy>>>(); MigrationConfig config = null; try { config = MigrationConfig.parse(migrationConfigResource.getInputStream()); } catch (IOException e) { LOG.error("Unable to read migration config file", e); return migrationStrategyMap; } Map<String, Map<String, List<Map<Strategy, Map<String, Object>>>>> entityConfig = config.getEntities(); for (Map.Entry<String, Map<String, List<Map<Strategy, Map<String, Object>>>>> entityEntry : entityConfig .entrySet()) { String entityType = entityEntry.getKey(); Map<String, List<Map<Strategy, Map<String, Object>>>> versionUpdates = entityEntry.getValue(); Map<String, List<MigrationStrategy>> migrationsForVersion = new HashMap<String, List<MigrationStrategy>>(); for (Map.Entry<String, List<Map<Strategy, Map<String, Object>>>> versionEntry : versionUpdates.entrySet()) { String versionNumber = versionEntry.getKey(); List<Map<Strategy, Map<String, Object>>> versionStrategies = versionEntry.getValue(); List<MigrationStrategy> strategies = new ArrayList<MigrationStrategy>(); migrationsForVersion.put(versionNumber, strategies); for (Map<Strategy, Map<String, Object>> versionStrategy : versionStrategies) { for (Map.Entry<Strategy, Map<String, Object>> strategy : versionStrategy.entrySet()) { try { MigrationStrategy migrationStrategy = (MigrationStrategy) beanFactory .getBean(strategy.getKey().getBeanName()); migrationStrategy.setParameters(strategy.getValue()); strategies.add(migrationStrategy); } catch (MigrationException e) { LOG.error("Unable to instantiate TransformStrategy: " + strategy, e); } } } } migrationStrategyMap.put(entityType, migrationsForVersion); } return migrationStrategyMap; }
ApiSchemaAdapter { private Map<String, Map<String, List<MigrationStrategy>>> buildMigrationStrategyMap(Resource migrationConfigResource) { Map<String, Map<String, List<MigrationStrategy>>> migrationStrategyMap = new HashMap<String, Map<String, List<MigrationStrategy>>>(); MigrationConfig config = null; try { config = MigrationConfig.parse(migrationConfigResource.getInputStream()); } catch (IOException e) { LOG.error("Unable to read migration config file", e); return migrationStrategyMap; } Map<String, Map<String, List<Map<Strategy, Map<String, Object>>>>> entityConfig = config.getEntities(); for (Map.Entry<String, Map<String, List<Map<Strategy, Map<String, Object>>>>> entityEntry : entityConfig .entrySet()) { String entityType = entityEntry.getKey(); Map<String, List<Map<Strategy, Map<String, Object>>>> versionUpdates = entityEntry.getValue(); Map<String, List<MigrationStrategy>> migrationsForVersion = new HashMap<String, List<MigrationStrategy>>(); for (Map.Entry<String, List<Map<Strategy, Map<String, Object>>>> versionEntry : versionUpdates.entrySet()) { String versionNumber = versionEntry.getKey(); List<Map<Strategy, Map<String, Object>>> versionStrategies = versionEntry.getValue(); List<MigrationStrategy> strategies = new ArrayList<MigrationStrategy>(); migrationsForVersion.put(versionNumber, strategies); for (Map<Strategy, Map<String, Object>> versionStrategy : versionStrategies) { for (Map.Entry<Strategy, Map<String, Object>> strategy : versionStrategy.entrySet()) { try { MigrationStrategy migrationStrategy = (MigrationStrategy) beanFactory .getBean(strategy.getKey().getBeanName()); migrationStrategy.setParameters(strategy.getValue()); strategies.add(migrationStrategy); } catch (MigrationException e) { LOG.error("Unable to instantiate TransformStrategy: " + strategy, e); } } } } migrationStrategyMap.put(entityType, migrationsForVersion); } return migrationStrategyMap; } }
ApiSchemaAdapter { private Map<String, Map<String, List<MigrationStrategy>>> buildMigrationStrategyMap(Resource migrationConfigResource) { Map<String, Map<String, List<MigrationStrategy>>> migrationStrategyMap = new HashMap<String, Map<String, List<MigrationStrategy>>>(); MigrationConfig config = null; try { config = MigrationConfig.parse(migrationConfigResource.getInputStream()); } catch (IOException e) { LOG.error("Unable to read migration config file", e); return migrationStrategyMap; } Map<String, Map<String, List<Map<Strategy, Map<String, Object>>>>> entityConfig = config.getEntities(); for (Map.Entry<String, Map<String, List<Map<Strategy, Map<String, Object>>>>> entityEntry : entityConfig .entrySet()) { String entityType = entityEntry.getKey(); Map<String, List<Map<Strategy, Map<String, Object>>>> versionUpdates = entityEntry.getValue(); Map<String, List<MigrationStrategy>> migrationsForVersion = new HashMap<String, List<MigrationStrategy>>(); for (Map.Entry<String, List<Map<Strategy, Map<String, Object>>>> versionEntry : versionUpdates.entrySet()) { String versionNumber = versionEntry.getKey(); List<Map<Strategy, Map<String, Object>>> versionStrategies = versionEntry.getValue(); List<MigrationStrategy> strategies = new ArrayList<MigrationStrategy>(); migrationsForVersion.put(versionNumber, strategies); for (Map<Strategy, Map<String, Object>> versionStrategy : versionStrategies) { for (Map.Entry<Strategy, Map<String, Object>> strategy : versionStrategy.entrySet()) { try { MigrationStrategy migrationStrategy = (MigrationStrategy) beanFactory .getBean(strategy.getKey().getBeanName()); migrationStrategy.setParameters(strategy.getValue()); strategies.add(migrationStrategy); } catch (MigrationException e) { LOG.error("Unable to instantiate TransformStrategy: " + strategy, e); } } } } migrationStrategyMap.put(entityType, migrationsForVersion); } return migrationStrategyMap; }  }
ApiSchemaAdapter { private Map<String, Map<String, List<MigrationStrategy>>> buildMigrationStrategyMap(Resource migrationConfigResource) { Map<String, Map<String, List<MigrationStrategy>>> migrationStrategyMap = new HashMap<String, Map<String, List<MigrationStrategy>>>(); MigrationConfig config = null; try { config = MigrationConfig.parse(migrationConfigResource.getInputStream()); } catch (IOException e) { LOG.error("Unable to read migration config file", e); return migrationStrategyMap; } Map<String, Map<String, List<Map<Strategy, Map<String, Object>>>>> entityConfig = config.getEntities(); for (Map.Entry<String, Map<String, List<Map<Strategy, Map<String, Object>>>>> entityEntry : entityConfig .entrySet()) { String entityType = entityEntry.getKey(); Map<String, List<Map<Strategy, Map<String, Object>>>> versionUpdates = entityEntry.getValue(); Map<String, List<MigrationStrategy>> migrationsForVersion = new HashMap<String, List<MigrationStrategy>>(); for (Map.Entry<String, List<Map<Strategy, Map<String, Object>>>> versionEntry : versionUpdates.entrySet()) { String versionNumber = versionEntry.getKey(); List<Map<Strategy, Map<String, Object>>> versionStrategies = versionEntry.getValue(); List<MigrationStrategy> strategies = new ArrayList<MigrationStrategy>(); migrationsForVersion.put(versionNumber, strategies); for (Map<Strategy, Map<String, Object>> versionStrategy : versionStrategies) { for (Map.Entry<Strategy, Map<String, Object>> strategy : versionStrategy.entrySet()) { try { MigrationStrategy migrationStrategy = (MigrationStrategy) beanFactory .getBean(strategy.getKey().getBeanName()); migrationStrategy.setParameters(strategy.getValue()); strategies.add(migrationStrategy); } catch (MigrationException e) { LOG.error("Unable to instantiate TransformStrategy: " + strategy, e); } } } } migrationStrategyMap.put(entityType, migrationsForVersion); } return migrationStrategyMap; }  @PostConstruct void initMigration(); List<MigrationStrategy> getUpMigrationStrategies(String entityType, String versionNumber); List<MigrationStrategy> getDownMigrationStrategies(String entityType, String versionNumber); List<MigrationStrategy> getEntityTransformMigrationStrategies(String entityType, String versionNumber); Entity migrate(Entity entity, String apiVersion, boolean upConversion); Iterable<Entity> migrate(Iterable<Entity> entities, String apiVersion, boolean upConversion); List<EntityBody> migrate(EntityBody entityBody, String entityType, String versionNumber); List<EntityBody> migrate(List<EntityBody> entityBodies, String entityType, String versionNumber); Resource getUpMigrationConfigResource(); void setUpMigrationConfigResource(Resource upMigrationConfigResource); Resource getDownMigrationConfigResource(); void setDownMigrationConfigResource(Resource downMigrationConfigResource); Resource getEntityTransformConfigResource(); void setEntityTransformConfigResource(Resource entityTransformConfigResource); }
ApiSchemaAdapter { private Map<String, Map<String, List<MigrationStrategy>>> buildMigrationStrategyMap(Resource migrationConfigResource) { Map<String, Map<String, List<MigrationStrategy>>> migrationStrategyMap = new HashMap<String, Map<String, List<MigrationStrategy>>>(); MigrationConfig config = null; try { config = MigrationConfig.parse(migrationConfigResource.getInputStream()); } catch (IOException e) { LOG.error("Unable to read migration config file", e); return migrationStrategyMap; } Map<String, Map<String, List<Map<Strategy, Map<String, Object>>>>> entityConfig = config.getEntities(); for (Map.Entry<String, Map<String, List<Map<Strategy, Map<String, Object>>>>> entityEntry : entityConfig .entrySet()) { String entityType = entityEntry.getKey(); Map<String, List<Map<Strategy, Map<String, Object>>>> versionUpdates = entityEntry.getValue(); Map<String, List<MigrationStrategy>> migrationsForVersion = new HashMap<String, List<MigrationStrategy>>(); for (Map.Entry<String, List<Map<Strategy, Map<String, Object>>>> versionEntry : versionUpdates.entrySet()) { String versionNumber = versionEntry.getKey(); List<Map<Strategy, Map<String, Object>>> versionStrategies = versionEntry.getValue(); List<MigrationStrategy> strategies = new ArrayList<MigrationStrategy>(); migrationsForVersion.put(versionNumber, strategies); for (Map<Strategy, Map<String, Object>> versionStrategy : versionStrategies) { for (Map.Entry<Strategy, Map<String, Object>> strategy : versionStrategy.entrySet()) { try { MigrationStrategy migrationStrategy = (MigrationStrategy) beanFactory .getBean(strategy.getKey().getBeanName()); migrationStrategy.setParameters(strategy.getValue()); strategies.add(migrationStrategy); } catch (MigrationException e) { LOG.error("Unable to instantiate TransformStrategy: " + strategy, e); } } } } migrationStrategyMap.put(entityType, migrationsForVersion); } return migrationStrategyMap; }  @PostConstruct void initMigration(); List<MigrationStrategy> getUpMigrationStrategies(String entityType, String versionNumber); List<MigrationStrategy> getDownMigrationStrategies(String entityType, String versionNumber); List<MigrationStrategy> getEntityTransformMigrationStrategies(String entityType, String versionNumber); Entity migrate(Entity entity, String apiVersion, boolean upConversion); Iterable<Entity> migrate(Iterable<Entity> entities, String apiVersion, boolean upConversion); List<EntityBody> migrate(EntityBody entityBody, String entityType, String versionNumber); List<EntityBody> migrate(List<EntityBody> entityBodies, String entityType, String versionNumber); Resource getUpMigrationConfigResource(); void setUpMigrationConfigResource(Resource upMigrationConfigResource); Resource getDownMigrationConfigResource(); void setDownMigrationConfigResource(Resource downMigrationConfigResource); Resource getEntityTransformConfigResource(); void setEntityTransformConfigResource(Resource entityTransformConfigResource);  }