@Test public void testMigrate() { ApiSchemaAdapter apiSchemaAdapter = initApiSchemaAdapter(); EntityBody downBody = new EntityBody(); downBody.put("removeDownFoo", "removeDownBar"); downBody.put("oldDownFoo", "oldDownBar"); Entity downEntity = new MongoEntity("session", downBody); EntityBody upBody = new EntityBody(); upBody.put("removeUpFoo", "removeUpBar"); upBody.put("oldUpFoo", "oldUpBar"); Entity upEntity = new MongoEntity("session", upBody); Entity newDownEntity = apiSchemaAdapter.migrate(downEntity, ONE, false); Entity newUpEntity = apiSchemaAdapter.migrate(upEntity, ONE, true); assertTrue(newDownEntity.getBody().containsKey("downFoo")); assertTrue(newDownEntity.getBody().get("downFoo").equals("downBar")); assertTrue(!newDownEntity.getBody().containsKey("removeDownFoo")); assertTrue(!newDownEntity.getBody().containsKey("oldDownFoo")); assertTrue(newDownEntity.getBody().containsKey("newDownFoo")); assertTrue(newDownEntity.getBody().get("newDownFoo").equals("oldDownBar")); assertTrue(newUpEntity.getBody().containsKey("upFoo")); assertTrue(newUpEntity.getBody().get("upFoo").equals("upBar")); assertTrue(!newUpEntity.getBody().containsKey("removeUpFoo")); assertTrue(!newUpEntity.getBody().containsKey("oldUpFoo")); assertTrue(newUpEntity.getBody().containsKey("newUpFoo")); assertTrue(newUpEntity.getBody().get("newUpFoo").equals("oldUpBar")); }
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);  }