MigrationManager { public R read(JsonNode data, DataStorageMetadataDictionary dataStorageMetadataDictionary) { return read(objectMapper.writeTree(data),dataStorageMetadataDictionary); } MigrationManager(Class<R> rootClass, SimpleObjectMapper objectMapper, AttributeFiller<R> attributeFiller); void renameAttribute(Class<F> dataClass, String previousAttributeName, Function<F, Attribute<?,?>> attributeNameProvider); void renameClass(String previousDataClassNameFullQualified, Class<? extends FactoryBase<?,?>> newDataClass); void restoreAttribute(String singletonPreviousDataClass, String previousAttributeName, Class<V> valueClass, BiConsumer<R,V> setter); void restoreAttribute(Class<V> clazz, AttributePathTarget<V> path, BiConsumer<R,V> setter); void restoreListAttribute(Class<V> clazz, AttributePathTarget<List<V>> path, BiConsumer<R,List<V>> setter); R migrate(JsonNode rootNode, DataStorageMetadataDictionary dataStorageMetadataDictionary); String write(R root); String writeStorageMetadata(StoredDataMetadata metadata); R read(JsonNode data, DataStorageMetadataDictionary dataStorageMetadataDictionary); R read(String data, DataStorageMetadataDictionary dataStorageMetadataDictionary); StoredDataMetadata readStoredFactoryMetadata(String data); ScheduledUpdateMetadata readScheduledFactoryMetadata(String data); String writeScheduledUpdateMetadata(ScheduledUpdateMetadata metadata); String writeRawFactoryDataAndMetadata(R root, StoredDataMetadata metadata); RawFactoryDataAndMetadata readRawFactoryDataAndMetadata(String data);  }
@Test public void read_read(){ MigrationManager<ExampleDataA> manager = new MigrationManager<>(ExampleDataA.class, ObjectMapperBuilder.build(), (root1, oldDataStorageMetadataDictionary) -> { }); String data= ObjectMapperBuilder.build().writeValueAsString(new ExampleDataA()); ExampleDataA result = manager.read(data, createDataStorageMetadataDictionary()); Assertions.assertNotNull(result); }
@Test public void read_removed_property_no_exception() { ExampleDataA exampleDataA = new ExampleDataA(); exampleDataA.internal().finalise(); String oldDictionary = "{\n" + " \"dataList\" : [ {\n" + " \"attributes\" : [ {\n" + " \"variableName\" : \"stringAttribute\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.types.StringAttribute\"\n" + " }, {\n" + " \"variableName\" : \"removedAttribute\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.types.StringAttribute\"\n" + " }, {\n" + " \"variableName\" : \"referenceAttribute\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.dependency.FactoryAttribute\",\n" + " \"referenceClass\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataB\"\n" + " }, {\n" + " \"variableName\" : \"referenceListAttribute\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.dependency.FactoryListAttribute\",\n" + " \"referenceClass\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataB\"\n" + " } ],\n" + " \"className\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataA\",\n" + " \"count\" : 1\n" + " }, {\n" + " \"attributes\" : [ {\n" + " \"variableName\" : \"stringAttribute\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.types.StringAttribute\"\n" + " }, {\n" + " \"variableName\" : \"referenceAttribute\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.dependency.FactoryAttribute\",\n" + " \"referenceClass\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataA\"\n" + " }, {\n" + " \"variableName\" : \"referenceAttributeC\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.dependency.FactoryAttribute\",\n" + " \"referenceClass\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataC\"\n" + " } ],\n" + " \"className\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataB\",\n" + " \"count\" : 1\n" + " } ],\n" + " \"rootClass\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataA\"\n" + "}"; String input = "{\n" + " \"@class\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataA\",\n" + " \"id\" : \"d2412cc8-c759-58f5-93f8-ef4e195114b5\",\n" + " \"stringAttribute\" : {\n" + " \"v\" : \"123\"\n" + " },\n" + " \"removedAttribute\" : {\n" + " \"v\" : \"123\"\n" + " },\n" + " \"referenceAttribute\" : { },\n" + " \"referenceListAttribute\" : [ ]\n" + "}"; MigrationManager<ExampleDataA> manager = new MigrationManager<>(ExampleDataA.class, ObjectMapperBuilder.build(), (root1, oldDataStorageMetadataDictionary) -> { }); ExampleDataA result = manager.read(input,ObjectMapperBuilder.build().readValue(oldDictionary,DataStorageMetadataDictionary.class)); Assertions.assertEquals("123",result.stringAttribute.get()); }
@Test public void read_removed_class_no_exception() { ExampleDataA exampleDataA = new ExampleDataA(); exampleDataA.internal().finalise(); String oldDictionary = "{\n" + " \"dataList\" : [ {\n" + " \"attributes\" : [ {\n" + " \"variableName\" : \"stringAttribute\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.types.StringAttribute\"\n" + " }, {\n" + " \"variableName\" : \"removedAttribute\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.types.StringAttribute\"\n" + " }, {\n" + " \"variableName\" : \"referenceAttribute\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.dependency.FactoryAttribute\",\n" + " \"referenceClass\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataB\"\n" + " }, {\n" + " \"variableName\" : \"referenceListAttribute\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.dependency.FactoryListAttribute\",\n" + " \"referenceClass\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataB\"\n" + " } ],\n" + " \"className\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataA\",\n" + " \"count\" : 1\n" + " }, {\n" + " \"attributes\" : [ {\n" + " \"variableName\" : \"stringAttribute\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.types.StringAttribute\"\n" + " }, {\n" + " \"variableName\" : \"referenceAttribute\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.dependency.FactoryAttribute\",\n" + " \"referenceClass\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataA\"\n" + " }, {\n" + " \"variableName\" : \"referenceAttributeC\",\n" + " \"attributeClassName\" : \"io.github.factoryfx.factory.attribute.dependency.FactoryAttribute\",\n" + " \"referenceClass\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataC\"\n" + " } ],\n" + " \"className\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataBremoved\",\n" + " \"count\" : 1\n" + " } ],\n" + " \"rootClass\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataA\"\n" + "}"; String input = "{\n" + " \"@class\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataA\",\n" + " \"id\" : \"b663aa09-1106-7da5-f696-90831cb670ca\",\n" + " \"treeBuilderClassUsed\" : false,\n" + " \"stringAttribute\" : { },\n" + " \"referenceAttribute\" : {\n" + " \"v\" : {\n" + " \"@class\" : \"io.github.factoryfx.factory.merge.testdata.ExampleDataBremoved\",\n" + " \"id\" : \"02a4f1cb-1b1d-5830-cbaf-10363863a385\",\n" + " \"treeBuilderClassUsed\" : false,\n" + " \"stringAttribute\" : { \"v\": \"test123\"},\n" + " \"referenceAttribute\" : { },\n" + " \"referenceListAttribute\" : [ ]\n" + " }\n" + " },\n" + " \"referenceListAttribute\" : [ ]\n" + "}"; MigrationManager<ExampleDataA> manager = new MigrationManager<>(ExampleDataA.class, ObjectMapperBuilder.build(), (root1, oldDataStorageMetadataDictionary) -> { }); manager.read(input,ObjectMapperBuilder.build().readValue(oldDictionary,DataStorageMetadataDictionary.class)); }