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 java.util.List
import java.util.Map
import javax.inject.Inject
import javax.inject.Singleton
import org.joinedworkz.common.helper.OpenApiHelper
import org.joinedworkz.common.java.generator.InterfaceGenerator
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.context.HandlerGeneratorContext
import org.joinedworkz.spring.boot.generator.ControllerGenerator
import org.joinedworkz.spring.boot.generator.HandlerGenerator
import org.joinedworkz.spring.boot.info.HandlerInfo
import java.util.Properties
import org.joinedworkz.spring.boot.helper.OutletHelper
@Singleton
class ServiceProviderCartridge extends AbstractCartridge {
@Inject
extension OpenApiHelper
@Inject
extension OutletHelper;
@Inject
protected ControllerGenerator controllerGenerator;
@Inject
protected InterfaceGenerator interfaceGenerator;
@Inject
protected HandlerGenerator handlerGenerator;
override apply(CmnObject cmnObj, Outlets outlets) {
apply(cmnObj, outlets, null)
}
override apply(CmnObject cmnObj, Outlets outlets, Properties properties) {
if (cmnObj instanceof CmnModel) {
val generatedJavaSource = outlets.get("generatedJavaSource")
val generatedApiSource = getGeneratedApiOutlet(outlets, cmnObj, properties)
var firstCutJavaSource = outlets.get("firstCutJavaSource")
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, generatedApiSource, properties)
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, properties, firstCutJavaSource, generatedJavaSource)
handlerGenerator.generateClass(ctx)
if (ctx.hasIfCtx) {
val iCtx = ctx.ifCtx
iCtx.qualifiedInterfaceName = handlerGenerator.qualifiedInterfaceNameForHandler(ctx)
iCtx.baseClass = null
interfaceGenerator.generateClass(iCtx);
}
}
}
}
}
}
}