org.joinedworkz.spring.boot.ServiceProviderCartridge.xtend Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-boot Show documentation
Show all versions of spring-boot Show documentation
DSL based modeling framework - facilities SpringBoot
package org.joinedworkz.spring.boot
import javax.inject.Inject
import javax.inject.Singleton
import org.joinedworkz.common.helper.OpenApiHelper
import org.joinedworkz.core.facility.AbstractCartridge
import org.joinedworkz.core.facility.Outlets
import org.joinedworkz.core.model.CmnComponent
import org.joinedworkz.core.model.CmnModel
import org.joinedworkz.core.model.CmnObject
import org.joinedworkz.core.model.CmnProvidedResource
import org.joinedworkz.spring.boot.context.ControllerGeneratorContext
import org.joinedworkz.spring.boot.generator.ControllerGenerator
import org.joinedworkz.common.java.generator.InterfaceGenerator
import org.joinedworkz.spring.boot.generator.HandlerGenerator
import java.util.Map
import java.util.List
import org.joinedworkz.spring.boot.info.HandlerInfo
import org.joinedworkz.common.java.ClassGeneratorContext
import org.joinedworkz.spring.boot.context.HandlerGeneratorContext
@Singleton
class ServiceProviderCartridge extends AbstractCartridge {
@Inject
extension OpenApiHelper
@Inject
protected ControllerGenerator controllerGenerator;
@Inject
protected InterfaceGenerator interfaceGenerator;
@Inject
protected HandlerGenerator handlerGenerator;
override apply(CmnObject cmnObj, Outlets outlets) {
val generatedJavaSource = outlets.get("generatedJavaSource")
var firstCutJavaSource = outlets.get("firstCutJavaSource")
if (cmnObj instanceof CmnModel) {
val components = cmnObj.modelElements.filter(CmnComponent)
for (component : components) {
/* base package (default is namespace of component) */
var basePackage = component.getString('basePackage')
if (basePackage === null) {
basePackage = cmnObj.namespace
}
val providedResources = component.features.filter(CmnProvidedResource)
val Map> usedHandlerInfos = newLinkedHashMap
for (providedResource : providedResources) {
val ctx = new ControllerGeneratorContext(providedResource, basePackage, usedHandlerInfos, generatedJavaSource)
ctx.mergedOperationInfos = createMergedResourceOperationInfos(component, ctx.mainResource, ctx)
controllerGenerator.generateClass(ctx);
if (ctx.hasIfCtx) {
val iCtx = ctx.ifCtx
iCtx.qualifiedInterfaceName = controllerGenerator.apiOfController(ctx, providedResource)
iCtx.baseClass = null
interfaceGenerator.generateClass(iCtx);
}
}
if (!usedHandlerInfos.empty) {
for (entry : usedHandlerInfos.entrySet) {
val ctx = new HandlerGeneratorContext(component, entry.key, entry.value, firstCutJavaSource, generatedJavaSource)
handlerGenerator.generateClass(ctx)
if (ctx.hasIfCtx) {
val iCtx = ctx.ifCtx
iCtx.qualifiedInterfaceName = handlerGenerator.qualifiedInterfaceNameForHandler(ctx)
iCtx.baseClass = null
interfaceGenerator.generateClass(iCtx);
}
}
}
}
}
}
}