@Test public void testMigrateIterable() { EntityBody downBody = new EntityBody(); downBody.put("removeDownFoo", "removeDownBar"); downBody.put("oldDownFoo", "oldDownBar"); Entity downSessionEntity = new MongoEntity("session", downBody); Entity downStudentEntity = new MongoEntity("student", null); EntityBody upBody = new EntityBody(); upBody.put("removeUpFoo", "removeUpBar"); upBody.put("oldUpFoo", "oldUpBar"); Entity upSessionEntity = new MongoEntity("session", upBody); Entity upStudentEntity = new MongoEntity("student", null); ArrayList<Entity> oldDownEntityList = new ArrayList<Entity>(); oldDownEntityList.add(downSessionEntity); oldDownEntityList.add(downStudentEntity); ArrayList<Entity> oldUpEntityList = new ArrayList<Entity>(); oldUpEntityList.add(upSessionEntity); oldUpEntityList.add(upStudentEntity); Iterator<Entity> newDownEntityList = apiSchemaAdapter.migrate(oldDownEntityList, ONE, false).iterator(); Entity currDownEntity = newDownEntityList.next(); assertTrue(currDownEntity.getBody().containsKey("downFoo")); assertTrue(currDownEntity.getBody().get("downFoo").equals("downBar")); assertTrue(!currDownEntity.getBody().containsKey("removeDownFoo")); assertTrue(!currDownEntity.getBody().containsKey("oldDownFoo")); assertTrue(currDownEntity.getBody().containsKey("newDownFoo")); assertTrue(currDownEntity.getBody().get("newDownFoo").equals("oldDownBar")); assertTrue(newDownEntityList.next() != null); assertTrue(!newDownEntityList.hasNext()); Iterator<Entity> newUpEntityList = apiSchemaAdapter.migrate(oldUpEntityList, ONE, true).iterator(); Entity firstUpEntity = newUpEntityList.next(); assertTrue(firstUpEntity.getBody().containsKey("upFoo")); assertTrue(firstUpEntity.getBody().get("upFoo").equals("upBar")); assertTrue(!firstUpEntity.getBody().containsKey("removeUpFoo")); assertTrue(!firstUpEntity.getBody().containsKey("oldUpFoo")); assertTrue(firstUpEntity.getBody().containsKey("newUpFoo")); assertTrue(firstUpEntity.getBody().get("newUpFoo").equals("oldUpBar")); assertTrue(newUpEntityList.next() != null); assertTrue(!newUpEntityList.hasNext()); }
public Entity migrate(Entity entity, String apiVersion, boolean upConversion) throws MigrationException { if (entity == null) { return null; } String entityType = entity.getType(); List<MigrationStrategy> migrationStrategies = null; if (upConversion) { migrationStrategies = getUpMigrationStrategies(entityType, apiVersion); } else { migrationStrategies = getDownMigrationStrategies(entityType, apiVersion); } Entity migratedEntity = entity; if (migrationStrategies != null) { for (MigrationStrategy migrationStrategy : migrationStrategies) { migratedEntity = (Entity) migrationStrategy.migrate(migratedEntity); } } return migratedEntity; }
ApiSchemaAdapter { public Entity migrate(Entity entity, String apiVersion, boolean upConversion) throws MigrationException { if (entity == null) { return null; } String entityType = entity.getType(); List<MigrationStrategy> migrationStrategies = null; if (upConversion) { migrationStrategies = getUpMigrationStrategies(entityType, apiVersion); } else { migrationStrategies = getDownMigrationStrategies(entityType, apiVersion); } Entity migratedEntity = entity; if (migrationStrategies != null) { for (MigrationStrategy migrationStrategy : migrationStrategies) { migratedEntity = (Entity) migrationStrategy.migrate(migratedEntity); } } return migratedEntity; } }
ApiSchemaAdapter { public Entity migrate(Entity entity, String apiVersion, boolean upConversion) throws MigrationException { if (entity == null) { return null; } String entityType = entity.getType(); List<MigrationStrategy> migrationStrategies = null; if (upConversion) { migrationStrategies = getUpMigrationStrategies(entityType, apiVersion); } else { migrationStrategies = getDownMigrationStrategies(entityType, apiVersion); } Entity migratedEntity = entity; if (migrationStrategies != null) { for (MigrationStrategy migrationStrategy : migrationStrategies) { migratedEntity = (Entity) migrationStrategy.migrate(migratedEntity); } } return migratedEntity; }  }
ApiSchemaAdapter { public Entity migrate(Entity entity, String apiVersion, boolean upConversion) throws MigrationException { if (entity == null) { return null; } String entityType = entity.getType(); List<MigrationStrategy> migrationStrategies = null; if (upConversion) { migrationStrategies = getUpMigrationStrategies(entityType, apiVersion); } else { migrationStrategies = getDownMigrationStrategies(entityType, apiVersion); } Entity migratedEntity = entity; if (migrationStrategies != null) { for (MigrationStrategy migrationStrategy : migrationStrategies) { migratedEntity = (Entity) migrationStrategy.migrate(migratedEntity); } } return migratedEntity; }  @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 { public Entity migrate(Entity entity, String apiVersion, boolean upConversion) throws MigrationException { if (entity == null) { return null; } String entityType = entity.getType(); List<MigrationStrategy> migrationStrategies = null; if (upConversion) { migrationStrategies = getUpMigrationStrategies(entityType, apiVersion); } else { migrationStrategies = getDownMigrationStrategies(entityType, apiVersion); } Entity migratedEntity = entity; if (migrationStrategies != null) { for (MigrationStrategy migrationStrategy : migrationStrategies) { migratedEntity = (Entity) migrationStrategy.migrate(migratedEntity); } } return migratedEntity; }  @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);  }