templates.KMFQLSelectorByQuery.vm Maven / Gradle / Ivy
#* @vtlvariable name="optionalRelationShipNameGen" type="java.lang.Boolean" *#
#* @vtlvariable name="relationShipOptionalName" type="java.lang.String" *#
#* @vtlvariable name="eRefs" type="org.eclipse.emf.common.util.EList" *#
#* @vtlvariable name="eSub" type="org.eclipse.emf.common.util.EList" *#
#* @vtlvariable name="ctx" type="org.kevoree.modeling.kotlin.generator.GenerationContext" *#
#* @vtlvariable name="FQNHelper" type="org.kevoree.modeling.kotlin.generator.ProcessorHelper" *#
#* @vtlvariable name="formatedFactoryName" type="java.lang.String" *#
override fun selectByQuery(query : String) : MutableList {
val collected = java.util.ArrayList()
try {
val firstSepIndex = query.indexOf('[')
var queryID = ""
var extraReadChar = 2
#if($optionalRelationShipNameGen)
val relationName = ${FQNHelper.fqn($ctx, $ctx.getBasePackageForUtilitiesGeneration())}.util.Constants.Ref_${relationShipOptionalName}
val optionalDetected = ( firstSepIndex != ${relationShipOptionalName.length()} )
if(optionalDetected){ extraReadChar = extraReadChar - 2 }
if(query.indexOf('{') == 0){
#else
val relationName = query.substring(0,query.indexOf('['))
if(query.indexOf('{') == firstSepIndex +1){
#end
queryID = query.substring(query.indexOf('{')+1,query.indexOf('}'))
extraReadChar = extraReadChar + 2
} else {
#if($optionalRelationShipNameGen)
if(optionalDetected){
if(query.indexOf('/') != - 1){
queryID = query.substring(0,query.indexOf('/'))
} else {
queryID = query.substring(0,query.size)
}
} else {
queryID = query.substring(query.indexOf('[')+1,query.indexOf(']'))
}
#else
queryID = query.substring(query.indexOf('[')+1,query.indexOf(']'))
#end
}
#if($optionalRelationShipNameGen)
var subquery = query.substring((if(optionalDetected){0} else {relationName.size})+queryID.size+extraReadChar,query.size)
#else
var subquery = query.substring(relationName.size+queryID.size+extraReadChar,query.size)
#end
if (subquery.indexOf('/') != -1){
subquery = subquery.substring(subquery.indexOf('/')+1,subquery.size)
}
when(relationName) {
#foreach( $ref in $eRefs )
${FQNHelper.fqn($ctx, $ctx.getBasePackageForUtilitiesGeneration())}.util.Constants.Ref_${ref.getName()} -> {
#if(!$ref.isMany())
var subResult = ${ctx.getkevoreeCacheResolver()}.filter(queryID,java.util.Collections.singleton(get${ref.getName().substring(0, 1).toUpperCase()}${ref.getName().substring(1)}())!!)
collected.add(subResult)
#else
var subResult : MutableCollection? = null
#if(${ref.getEReferenceType().getEIDAttribute()})
#if($ref.isMany())
val tempObj = find${ref.getName().substring(0, 1).toUpperCase()}${ref.getName().substring(1)}ByID(queryID)
if(tempObj!=null){
subResult = java.util.ArrayList()
subResult!!.add(tempObj)
}
#end
#end
if(subResult == null){
#if(${ref.getEReferenceType().getEIDAttribute()})
subResult = ${ctx.getkevoreeCacheResolver()}.filter(queryID,_${ref.getName()}.values()) as MutableCollection
#else
subResult = ${ctx.getkevoreeCacheResolver()}.filter(queryID,_${ref.getName()}) as MutableCollection
#end
}
if(subquery != ""){
for(subObj in subResult!!){
collected.addAll( (subObj as ${FQNHelper.fqn($ctx, $ref.getEReferenceType())}).selectByQuery(subquery))
}
} else {
collected.addAll(subResult!!)
}
#end
return collected
}
#end
${FQNHelper.fqn($ctx, $ctx.getBasePackageForUtilitiesGeneration())}.util.Constants.KMFQL_CONTAINED -> {
var subResult : MutableCollection = java.util.ArrayList()
#foreach( $subRef in $eSub )
#if(!$subRef.isMany())
if(get${subRef.getName().substring(0, 1).toUpperCase()}${subRef.getName().substring(1)}()!=null){
subResult.addAll(${ctx.getkevoreeCacheResolver()}.filter(queryID,java.util.Collections.singleton(get${subRef.getName().substring(0, 1).toUpperCase()}${subRef.getName().substring(1)}())!!)!!)
}
#else
subResult.addAll(${ctx.getkevoreeCacheResolver()}.filter(queryID,get${subRef.getName().substring(0, 1).toUpperCase()}${subRef.getName().substring(1)}())!!)
#end
#end
if(subquery != ""){
for(subObj in subResult!!){
collected.addAll( (subObj as ${formatedFactoryName}).selectByQuery(subquery))
}
} else {
collected.addAll(subResult!!)
}
return collected
}
else -> {return collected}
}
} catch(e:Exception){
return collected
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy