org.joinedworkz.spring.boot.ServiceProviderCartridge 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 com.google.common.collect.Iterables;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Extension;
import org.joinedworkz.common.helper.OpenApiHelper;
import org.joinedworkz.common.java.generator.InterfaceGenerator;
import org.joinedworkz.common.java.generator.InterfaceGeneratorContext;
import org.joinedworkz.core.facility.AbstractCartridge;
import org.joinedworkz.core.facility.Outlet;
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;
@Singleton
@SuppressWarnings("all")
public class ServiceProviderCartridge extends AbstractCartridge {
@Inject
@Extension
private OpenApiHelper _openApiHelper;
@Inject
protected ControllerGenerator controllerGenerator;
@Inject
protected InterfaceGenerator interfaceGenerator;
@Inject
protected HandlerGenerator handlerGenerator;
@Override
public void apply(final CmnObject cmnObj, final Outlets outlets) {
final Outlet generatedJavaSource = outlets.get("generatedJavaSource");
Outlet firstCutJavaSource = outlets.get("firstCutJavaSource");
if ((cmnObj instanceof CmnModel)) {
final Iterable components = Iterables.filter(((CmnModel)cmnObj).getModelElements(), CmnComponent.class);
for (final CmnComponent component : components) {
{
String basePackage = component.getString("basePackage");
if ((basePackage == null)) {
basePackage = ((CmnModel)cmnObj).getNamespace();
}
final Iterable providedResources = Iterables.filter(component.getFeatures(), CmnProvidedResource.class);
final Map> usedHandlerInfos = CollectionLiterals.>newLinkedHashMap();
for (final CmnProvidedResource providedResource : providedResources) {
{
final ControllerGeneratorContext ctx = new ControllerGeneratorContext(providedResource, basePackage, usedHandlerInfos, generatedJavaSource);
ctx.setMergedOperationInfos(this._openApiHelper.createMergedResourceOperationInfos(component, ctx.getMainResource(), ctx));
this.controllerGenerator.generateClass(ctx);
boolean _hasIfCtx = ctx.hasIfCtx();
if (_hasIfCtx) {
final InterfaceGeneratorContext iCtx = ctx.getIfCtx();
iCtx.qualifiedInterfaceName = this.controllerGenerator.apiOfController(ctx, providedResource);
iCtx.setBaseClass(null);
this.interfaceGenerator.generateClass(iCtx);
}
}
}
boolean _isEmpty = usedHandlerInfos.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
Set>> _entrySet = usedHandlerInfos.entrySet();
for (final Map.Entry> entry : _entrySet) {
{
String _key = entry.getKey();
List _value = entry.getValue();
final HandlerGeneratorContext ctx = new HandlerGeneratorContext(component, _key, _value, firstCutJavaSource, generatedJavaSource);
this.handlerGenerator.generateClass(ctx);
boolean _hasIfCtx = ctx.hasIfCtx();
if (_hasIfCtx) {
final InterfaceGeneratorContext iCtx = ctx.getIfCtx();
iCtx.qualifiedInterfaceName = this.handlerGenerator.qualifiedInterfaceNameForHandler(ctx);
iCtx.setBaseClass(null);
this.interfaceGenerator.generateClass(iCtx);
}
}
}
}
}
}
}
}
}