Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsamson7 committed Mar 23, 2024
1 parent db47f15 commit 587f1a1
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,17 @@ class PortalAdministrationServiceImpl : PortalAdministrationService {
}

val readApplicationMapper = Mapper(
Mapping.build(ApplicationEntity::class, Application::class) {
mapping(ApplicationEntity::class, Application::class) {
map { properties("name", "configuration") }
map { "versions" to "versions" deep true }
},

Mapping.build(AssignedMicrofrontendEntity::class, AssignedMicrofrontend::class) {
mapping(AssignedMicrofrontendEntity::class, AssignedMicrofrontend::class) {
map { properties("id", "version") }
map { path("microfrontend", "name") to "microfrontend" }
},

Mapping.build(ApplicationVersionEntity::class, ApplicationVersion::class) {
mapping(ApplicationVersionEntity::class, ApplicationVersion::class) {
map { properties("id", "version", "configuration") }
map { "assignedMicrofrontends" to "assignedMicrofrontends" deep true}
})
Expand Down Expand Up @@ -234,7 +234,7 @@ class PortalAdministrationServiceImpl : PortalAdministrationService {
}

val mapper = Mapper(
Mapping.build(Application::class, ApplicationEntity::class) {
mapping(Application::class, ApplicationEntity::class) {
map { properties("name", "configuration") }
map { "versions" to "versions" synchronize synch }
})
Expand Down Expand Up @@ -318,9 +318,9 @@ class PortalAdministrationServiceImpl : PortalAdministrationService {
}

val mapper = Mapper(
Mapping.build(ApplicationVersion::class, ApplicationVersionEntity::class) {
//map { properties("version", "configuration") }
map { "versions" to "versions" synchronize synchronizer }
mapping(ApplicationVersion::class, ApplicationVersionEntity::class) {
map { properties("version", "configuration") }
map { "assignedMicrofrontends" to "assignedMicrofrontends" synchronize synchronizer }
})

mapper.map(application, entity)
Expand All @@ -344,20 +344,20 @@ class PortalAdministrationServiceImpl : PortalAdministrationService {
// microfrontend

val readMicrofrontendMapper = Mapper(
Mapping.build(MicrofrontendEntity::class, Microfrontend::class) {
mapping(MicrofrontendEntity::class, Microfrontend::class) {
map { properties("name", "enabled", "configuration") }
map { "versions" to "versions" deep true }
},

Mapping.build(MicrofrontendVersionEntity::class, MicrofrontendVersion::class) {
mapping(MicrofrontendVersionEntity::class, MicrofrontendVersion::class) {
map { properties("id", "version", "configuration", "enabled") }
map { path("microfrontend", "name") to "microfrontend" }
map { "manifest" to "manifest" convert {manifest: String -> objectMapper.readValue(manifest, Manifest::class.java)}}
map { "instances" to "instances" deep true }
map { path("applicationVersion", "id") to "applicationVersion" }
},

Mapping.build(MicrofrontendInstanceEntity::class, MicrofrontendInstance::class) {
mapping(MicrofrontendInstanceEntity::class, MicrofrontendInstance::class) {
map { path("microfrontendVersion", "microfrontend", "name") to "microfrontend" }
map { path("microfrontendVersion", "version") to "version" }
map { properties("uri", "enabled", "health", "configuration", "stage") }
Expand Down
15 changes: 12 additions & 3 deletions portal/core/src/main/java/com/serious/portal/mapper/Mapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ class Mapping<S : Any, T : Any>(
fun setup(compositeDefinitions: Array<MappingDefinition.CompositeDefinition>, stackSize: Int): Array<CompositeBuffer> {
val buffers = compositeDefinitions.map { definition -> definition.createBuffer(mapper) }.toTypedArray()

/*val buffers = arrayOfNulls<CompositeBuffer>(compositeDefinitions.size)
/*TODOval buffers = arrayOfNulls<CompositeBuffer>(compositeDefinitions.size)
for ( i in 0..<compositeDefinitions.size)
buffers[i] = compositeDefinitions[i].createBuffer(mapper)*/

Expand Down Expand Up @@ -1801,10 +1801,19 @@ class Mapping<S : Any, T : Any>(
}
}

fun <S : Any, T : Any> mapping(sourceClass: KClass<S>, targetClass: KClass<T>): MappingDefinition<S, T> {
return MappingDefinition(sourceClass, targetClass)
fun <S:Any,T:Any>mapping(sourceClass: KClass<S>, targetClass: KClass<T>, lambda: MappingDefinition.Builder<S,T>.() -> Unit) : MappingDefinition<S,T> {
val definition = MappingDefinition(sourceClass, targetClass)

MappingDefinition.Builder(definition)
.apply(lambda)

return definition
}

//fun <S : Any, T : Any> mapping(sourceClass: KClass<S>, targetClass: KClass<T>): MappingDefinition<S, T> {
// return MappingDefinition(sourceClass, targetClass)
//}

// one mapper has n mappings

class Mapper(vararg definitions: MappingDefinition<*, *>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@ class CollectionTest {
@Test
fun testCollection() {
val mapper = Mapper(
Mapping.build(Foo::class, Foo::class) {
mapping(Foo::class, Foo::class) {
map { "barArray" to "barList" deep true}
map { "barList" to "barArray" deep true}
},


Mapping.build(Bar::class, Bar::class) {
mapping(Bar::class, Bar::class) {
map { "name" to "name" }
map { "baz" to "baz" deep true}
},

Mapping.build(Baz::class, Baz::class) {
mapping(Baz::class, Baz::class) {
map { "name" to "name" }
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class CompositeTest {
@Test
fun test() {
val prodMapper = Mapper(
mapping(Product::class, Product::class)
.map("id", "id") // ?
.map("name", "name")
.map(path("price", "currency"), path("price", "currency"))
.map(path("price", "value"), path("price", "value"))
mapping(Product::class, Product::class) {
map {"id" to "id"}
map {"name" to "name" }
map {path("price", "currency") to path("price", "currency") }
map {path("price", "value") to path("price", "value") }
}
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ConversionTest {
@Test
fun testConversion() {
val mapper = Mapper(
Mapping.build(Foo::class, Foo::class) {
mapping(Foo::class, Foo::class) {
map { "short" to "short" }
map { "short" to "float" }
map { "int" to "double" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class InheritanceTest {

@Test
fun testInheritance() {
val baseMapping = Mapping.build(Base::class,Base::class) {
val baseMapping = mapping(Base::class,Base::class) {
map { properties() }
}

val mapper = Mapper(
baseMapping,

Mapping.build(Derived::class, Derived::class) {
mapping(Derived::class, Derived::class) {
derives(baseMapping)

map { properties("name") }
Expand Down
46 changes: 30 additions & 16 deletions portal/core/src/test/java/com/serious/portal/mapper/MapperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class MapperTest {
// mapper

val mapper = Mapper(
Mapping.build(Product::class, Target::class) {
mapping(Product::class, Target::class) {
map { properties("name")}
map { path("price1", "value") to "price1"}
map { path("price2", "value") to "price2"}
Expand All @@ -75,7 +75,7 @@ class MapperTest {
val source = Product("product", null/*Price("EU", 1)*/, Price("EU", 2))
val target = mapper.map<Target>(source)!!

assertEquals(1, target.price1)
assertEquals(null, target.price1)
assertEquals(2, target.price2)
}

Expand All @@ -99,11 +99,11 @@ class MapperTest {
// mapper

val mapper = Mapper(
Mapping.build(Source::class, Target::class) {
mapping(Source::class, Target::class) {
map { properties("name")}
map { path("innerClass", "bars") to path("innerClass", "bars") deep true}
},
Mapping.build(BarSource::class, BarTarget::class) {
mapping(BarSource::class, BarTarget::class) {
map { properties("name")}
})

Expand Down Expand Up @@ -134,11 +134,11 @@ class MapperTest {
// mapper

val mapper = Mapper(
Mapping.build(Source::class, Target::class) {
mapping(Source::class, Target::class) {
map { properties("name")}
map { path("innerClass", "bars") to path("innerClass", "bars") deep true}
},
Mapping.build(BarSource::class, BarTarget::class) {
mapping(BarSource::class, BarTarget::class) {
map { properties("name")}
})

Expand All @@ -153,11 +153,11 @@ class MapperTest {
@Test()
fun testTopLevelDeepCollection() {
val mapper = Mapper(
Mapping.build(FooSource::class, FooTarget::class) {
mapping(FooSource::class, FooTarget::class) {
map { properties("name")}
map { "bars" to "bars" deep true}
},
Mapping.build(BarSource::class, BarTarget::class) {
mapping(BarSource::class, BarTarget::class) {
map { properties("name")}
})

Expand All @@ -170,11 +170,11 @@ class MapperTest {
@Test()
fun testTopLevelDataDeepCollection() {
val mapper = Mapper(
Mapping.build(FooDataSource::class, FooTarget::class) {
mapping(FooDataSource::class, FooTarget::class) {
map { properties("name")}
map { "bars" to "bars" deep true}
},
Mapping.build(BarSource::class, BarTarget::class) {
mapping(BarSource::class, BarTarget::class) {
map { properties("name")}
})

Expand All @@ -190,7 +190,7 @@ class MapperTest {
fun testReadOnlyException() {
try {
Mapper(
Mapping.build(From::class, ReadOnly::class) {
mapping(From::class, ReadOnly::class) {
map { "name" to "name"}
})

Expand All @@ -204,7 +204,7 @@ class MapperTest {
@Test()
fun testConstant() {
val mapper = Mapper(
Mapping.build(From::class, To::class) {
mapping(From::class, To::class) {
map { constant("name") to "name"}
})

Expand All @@ -217,7 +217,7 @@ class MapperTest {
fun testExceptionMissingSpec() {
try {
Mapper(
Mapping.build(From::class, To::class) {
mapping(From::class, To::class) {
map { }
})

Expand All @@ -233,7 +233,7 @@ class MapperTest {
val from = From("from")

val mapper = Mapper(
Mapping.build(From::class, To::class) {
mapping(From::class, To::class) {
map { properties() }
})

Expand All @@ -248,10 +248,10 @@ class MapperTest {
@Test
fun test() {
val mapper = Mapper(
Mapping.build(Money::class, Money::class) {
mapping(Money::class, Money::class) {
map { properties() }
},
Mapping.build(Product::class, Product::class) {
mapping(Product::class, Product::class) {
map { properties("id") }
map { Product::isNull to Product::isNull}

Expand All @@ -273,5 +273,19 @@ class MapperTest {

assertEquals(1, result?.mutableInnerComposite?.price?.value)
assertEquals(1, result?.innerComposite?.price?.value)


//


val loops = 100000
val start = System.currentTimeMillis()
for (i in 0 until loops)
mapper.map<Product>(product)

val ms = System.currentTimeMillis() - start
println("" + loops + " loops in " + ms + "ms, avg " + ms.toDouble() / loops)


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ class SynchronizerTest {
root.bars.add(bar)

val rootMapper = Mapper(
mapping(Root::class, RootEntity::class)
.synchronize("bars", "bars", BarSynchronizer()),
mapping(Root::class, RootEntity::class) {
map { "bars" to "bars" synchronize BarSynchronizer()}
},

mapping(Bar::class, BarEntity::class)
.map("id", "id") // ?
.map("name", "name")
mapping(Bar::class, BarEntity::class) {
map {"id" to "id" } // ?
map {"name" to "name" }
}
)

val rootResult = rootMapper.map<RootEntity>(root)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TopLevelCompositeTest {
@Test
fun test() {
val moneyMapper = Mapper(
Mapping.build(Money::class, Money::class) {
mapping(Money::class, Money::class) {
map { properties() }
}
)
Expand Down

0 comments on commit 587f1a1

Please sign in to comment.