-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from SchwarzIT/feature/validate-mandatory-data
Feature/validate mandatory data
- Loading branch information
Showing
20 changed files
with
200 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
crystal-map-api/src/main/java/com/schwarz/crystalapi/CrystalCreator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.schwarz.crystalapi | ||
|
||
abstract class CrystalCreator<T : MapSupport, V> { | ||
|
||
abstract fun create(): T | ||
|
||
abstract fun create(map: MutableMap<String, V>): T | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
crystal-map-api/src/main/java/com/schwarz/crystalapi/MandatoryCheck.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.schwarz.crystalapi | ||
|
||
interface MandatoryCheck { | ||
fun validate() | ||
} |
37 changes: 37 additions & 0 deletions
37
crystal-map-api/src/main/java/com/schwarz/crystalapi/WrapperCompanion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.schwarz.crystalapi | ||
|
||
abstract class WrapperCompanion<T : MapSupport> : CrystalCreator<T, Any?>() { | ||
|
||
fun fromMap(obj: MutableMap<String, Any?>?): T? { | ||
if (obj == null) { | ||
return null | ||
} | ||
return create(obj) | ||
} | ||
|
||
fun fromMap(obj: List<MutableMap<String, Any?>>?): List<T>? { | ||
if (obj == null) { | ||
return null | ||
} | ||
var result = ArrayList<T>() | ||
for (entry in obj) { | ||
result.add(create(entry)) | ||
} | ||
return result | ||
} | ||
|
||
abstract fun toMap(obj: T?): MutableMap<String, Any> | ||
|
||
fun toMap(obj: List<T>?): List<MutableMap<String, Any>> { | ||
if (obj == null) { | ||
return listOf() | ||
} | ||
var result = ArrayList<MutableMap<String, Any>>() | ||
for (entry in obj) { | ||
var temp = mutableMapOf<String, Any>() | ||
temp.putAll(toMap(entry)!!) | ||
result.add(temp) | ||
} | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
crystal-map-api/src/test/java/com/schwarz/crystalapi/util/CrystalWrapTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.schwarz.crystalapi.util | ||
|
||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class CrystalWrapTest { | ||
@Test | ||
fun `test validate throws exception on null value`() { | ||
val values = mutableMapOf<String, Any>("foo" to "bar") | ||
try { | ||
CrystalWrap.validate(values, arrayOf("foo", "foobar")) | ||
Assert.fail("there should be an exception") | ||
} catch (e: NullPointerException) { | ||
} | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
crystal-map-api/src/test/java/kaufland/com/coachbasebinderapi/ExampleUnitTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...r/src/main/java/com/schwarz/crystalprocessor/generation/model/ValidateMethodGeneration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.schwarz.crystalprocessor.generation.model | ||
|
||
import com.schwarz.crystalapi.util.CrystalWrap | ||
import com.schwarz.crystalprocessor.model.entity.BaseEntityHolder | ||
import com.schwarz.crystalprocessor.util.TypeUtil | ||
import com.squareup.kotlinpoet.FunSpec | ||
import com.squareup.kotlinpoet.KModifier | ||
|
||
object ValidateMethodGeneration { | ||
|
||
fun generate(holder: BaseEntityHolder, useMDocChanges: Boolean): FunSpec { | ||
val validateBuilder = | ||
FunSpec.builder("validate").addModifiers(KModifier.PUBLIC, KModifier.OVERRIDE) | ||
val mandatoryFields = holder.fields.values.filter { it.mandatory }.map { it.constantName } | ||
|
||
if (mandatoryFields.isNotEmpty()) { | ||
val statement = | ||
"%T.validate(toMap(), %M(${mandatoryFields.map { "%N" }.joinToString()}))" | ||
val arguments = mutableListOf(CrystalWrap::class, TypeUtil.arrayOf()) | ||
for (mandatoryField in mandatoryFields) { | ||
arguments.add(mandatoryField) | ||
} | ||
|
||
validateBuilder.addStatement( | ||
statement, | ||
*arguments.toTypedArray() | ||
) | ||
} | ||
|
||
return validateBuilder.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.