Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reordering #411

Merged
merged 11 commits into from
Jul 29, 2021
Prev Previous commit
Next Next commit
Code cleanup.
  • Loading branch information
OLarionova-HORIS committed Jul 27, 2021
commit 68e1dedea48ee0fb0910090449b38b54e4446746
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ object DataMetaUtil {
}

fun getOrderOptions(options: Map<*, *>?, commonMappings: Map<*, *>): List<OrderOptionUtil.OrderOption> {
return options
val orderOptions = options
?.getMappingAnnotationsSpec(AS_DISCRETE)
?.associate { it.getString(AES)!! to it.getMap(PARAMETERS) }
?.mapNotNull { (aesName, parameters) ->
Expand All @@ -156,30 +156,26 @@ object DataMetaUtil {
parameters?.getString(ORDER_BY),
parameters?.read(ORDER)
)
}.run {
// non-discrete mappings should inherit settings from the as_discrete
val inherited = commonMappings.variables()
.filterNot(::isDiscrete)
.mapNotNull { varName ->
val orderOptionForVar = this
?.filter { isDiscrete(it.variableName) }
?.find { fromDiscrete(it.variableName) == varName }
?: return@mapNotNull null

OrderOptionUtil.OrderOption.create(
varName,
orderBy = if (orderOptionForVar.byVariable != orderOptionForVar.variableName) {
orderOptionForVar.byVariable
} else {
null
},
orderOptionForVar.getOrderDir()
)
}

return@run this?.plus(inherited)
}
?: emptyList()

// non-discrete mappings should inherit settings from the as_discrete
val inherited = commonMappings.variables()
.filterNot(::isDiscrete)
.mapNotNull { varName ->
val orderOptionForVar = orderOptions
.filter { isDiscrete(it.variableName) }
.find { fromDiscrete(it.variableName) == varName }
?: return@mapNotNull null

OrderOptionUtil.OrderOption.create(
varName,
orderBy = orderOptionForVar.byVariable.takeIf { it != orderOptionForVar.variableName },
orderOptionForVar.getOrderDir()
)
}

return orderOptions + inherited
}
}

Expand Down