Skip to content

Commit 1cf65ee

Browse files
committed
Kotlin coding
1 parent e3460db commit 1cf65ee

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed

scenario/src/main/kotlin/com/cosmotech/scenario/azure/ScenarioServiceImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ internal class ScenarioServiceImpl(
233233
?.filter { parameterGroup ->
234234
runTemplate?.parameterGroups?.contains(parameterGroup.id) == true
235235
}
236-
?.flatMap { parameterGroup -> parameterGroup?.parameters ?: mutableListOf() }
236+
?.flatMap { parameterGroup -> parameterGroup.parameters ?: mutableListOf() }
237237
if (!runTemplateParametersIds.isNullOrEmpty()) {
238238
val parentParameters = parent.parametersValues?.associate { it.parameterId to it }
239239
val scenarioParameters = scenario.parametersValues?.associate { it.parameterId to it }

scenariorun/src/main/kotlin/com/cosmotech/scenariorun/ContainerFactory.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ internal const val SCENARIO_DATA_DOWNLOAD_ARTIFACT_NAME = "downloadUrl"
114114
private const val EVENT_HUB_SCENARIO_RUN_NAME = "scenariorun"
115115
private const val EVENT_HUB_PROBES_MEASURES_NAME = "probesmeasures"
116116

117-
public const val CSM_DAG_ROOT = "DAG_ROOT"
117+
const val CSM_DAG_ROOT = "DAG_ROOT"
118118

119119
@Component
120120
@Suppress("LargeClass", "TooManyFunctions")
@@ -1008,9 +1008,7 @@ internal class ContainerFactory(
10081008
}
10091009

10101010
private fun getRunTemplate(solution: Solution, runTemplateId: String): RunTemplate {
1011-
return (solution.runTemplates ?: mutableListOf()).find { runTemplate ->
1012-
runTemplate.id == runTemplateId
1013-
}
1011+
return solution.runTemplates?.find { runTemplate -> runTemplate.id == runTemplateId }
10141012
?: throw IllegalStateException(
10151013
"runTemplateId $runTemplateId not found in Solution ${solution.id}")
10161014
}
@@ -1251,10 +1249,10 @@ internal class ContainerFactory(
12511249
}
12521250

12531251
private fun getImageName(registry: String, repository: String?, version: String? = null): String {
1254-
if (repository == null) throw IllegalStateException("Solution repository is not defined")
1255-
val repo = repository ?: "ERROR"
1256-
val repoVersion = if (version == null) repo else "${repo}:${version}"
1257-
return if (registry != "") "${registry}/${repoVersion}" else repoVersion
1252+
val repoVersion =
1253+
repository.let { if (version == null) it else "${it}:${version}" }
1254+
?: throw IllegalStateException("Solution repository is not defined")
1255+
return if (registry.isNotEmpty()) "${registry}/${repoVersion}" else repoVersion
12581256
}
12591257
}
12601258

scenariorun/src/main/kotlin/com/cosmotech/scenariorun/dataset/DatasetUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal fun findDatasetsAndConnectors(
3232
addDatasetAndConnector(
3333
datasetService, connectorService, organizationId, datasetId, datasets, connectors)
3434
}
35-
val parameterGroupIds = runTemplate.parameterGroups ?: listOf()
35+
val parameterGroupIds = runTemplate.parameterGroups
3636
if (parameterGroupIds != null) {
3737
val parametersIds =
3838
(solution.parameterGroups?.filter { it.id in parameterGroupIds }?.map {

solution/src/main/kotlin/com/cosmotech/solution/azure/SolutionServiceImpl.kt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ internal class SolutionServiceImpl(
154154
runTemplateId: String
155155
) {
156156
val existingSolution = findSolutionById(organizationId, solutionId)
157-
if (!(existingSolution.runTemplates?.removeIf { it.id == runTemplateId } ?: true)) {
157+
if (existingSolution.runTemplates?.removeIf { it.id == runTemplateId } == false) {
158158
throw CsmResourceNotFoundException("Run Template '$runTemplateId' *not* found")
159159
}
160160
cosmosTemplate.upsert("${organizationId}_solutions", existingSolution)
@@ -200,8 +200,7 @@ internal class SolutionServiceImpl(
200200
val existingSolution = findSolutionById(organizationId, solutionId)
201201
val runTemplates =
202202
existingSolution.runTemplates?.filter { it.id == runTemplateId }?.toMutableList()
203-
?: mutableListOf()
204-
if (runTemplates.isEmpty()) {
203+
if (runTemplates == null || runTemplates.isEmpty()) {
205204
throw CsmResourceNotFoundException("Run Template '$runTemplateId' *not* found")
206205
}
207206
var hasChanged = false
@@ -263,20 +262,19 @@ internal class SolutionServiceImpl(
263262
"${solutionId.sanitizeForAzureStorage()}/$runTemplateId/${handlerId.value}.zip")
264263
.upload(body.inputStream, body.contentLength(), overwrite)
265264

266-
val runTemplate = solution.runTemplates?.findLast { it.id == runTemplateId }
267-
if (runTemplate == null) {
268-
throw CsmResourceNotFoundException("Run Template '$runTemplateId' *not* found")
269-
}
265+
val runTemplate =
266+
solution.runTemplates?.findLast { it.id == runTemplateId }
267+
?: throw CsmResourceNotFoundException("Run Template '$runTemplateId' *not* found")
270268
when (handlerId) {
271269
RunTemplateHandlerId.parameters_handler ->
272-
runTemplate!!.parametersHandlerSource = RunTemplateStepSource.cloud
270+
runTemplate.parametersHandlerSource = RunTemplateStepSource.cloud
273271
RunTemplateHandlerId.validator ->
274-
runTemplate!!.datasetValidatorSource = RunTemplateStepSource.cloud
275-
RunTemplateHandlerId.prerun -> runTemplate!!.preRunSource = RunTemplateStepSource.cloud
276-
RunTemplateHandlerId.engine -> runTemplate!!.runSource = RunTemplateStepSource.cloud
277-
RunTemplateHandlerId.postrun -> runTemplate!!.postRunSource = RunTemplateStepSource.cloud
272+
runTemplate.datasetValidatorSource = RunTemplateStepSource.cloud
273+
RunTemplateHandlerId.prerun -> runTemplate.preRunSource = RunTemplateStepSource.cloud
274+
RunTemplateHandlerId.engine -> runTemplate.runSource = RunTemplateStepSource.cloud
275+
RunTemplateHandlerId.postrun -> runTemplate.postRunSource = RunTemplateStepSource.cloud
278276
RunTemplateHandlerId.scenariodata_transform ->
279-
runTemplate!!.scenariodataTransformSource = RunTemplateStepSource.cloud
277+
runTemplate.scenariodataTransformSource = RunTemplateStepSource.cloud
280278
}.run {
281279
// This trick forces Kotlin to raise an error at compile time if the "when" statement is not
282280
// exhaustive
@@ -313,8 +311,8 @@ internal class SolutionServiceImpl(
313311
runTemplateId: String,
314312
): Solution {
315313
val solution = findSolutionById(organizationId, solutionId)
316-
val validRunTemplateIds = solution.runTemplates?.map { it.id }?.toSet() ?: setOf()
317-
if (validRunTemplateIds.isEmpty()) {
314+
val validRunTemplateIds = solution.runTemplates?.map { it.id }?.toSet()
315+
if (validRunTemplateIds == null || validRunTemplateIds.isEmpty()) {
318316
throw IllegalArgumentException(
319317
"Solution $solutionId does not declare any run templates. " +
320318
"It is therefore not possible to upload run template handlers. " +

0 commit comments

Comments
 (0)