All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.joinedworkz.spring.boot.ServiceProviderCartridge Maven / Gradle / Ivy

There is a newer version: 1.3.46
Show newest version
package org.joinedworkz.spring.boot;

import com.google.common.collect.Iterables;
import java.util.List;
import java.util.Map;
import java.util.Properties;
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.helper.OutletHelper;
import org.joinedworkz.spring.boot.info.HandlerInfo;

@Singleton
@SuppressWarnings("all")
public class ServiceProviderCartridge extends AbstractCartridge {
  @Inject
  @Extension
  private OpenApiHelper _openApiHelper;

  @Inject
  @Extension
  private OutletHelper _outletHelper;

  @Inject
  protected ControllerGenerator controllerGenerator;

  @Inject
  protected InterfaceGenerator interfaceGenerator;

  @Inject
  protected HandlerGenerator handlerGenerator;

  @Override
  public void apply(final CmnObject cmnObj, final Outlets outlets) {
    this.apply(cmnObj, outlets, null);
  }

  @Override
  public void apply(final CmnObject cmnObj, final Outlets outlets, final Properties properties) {
    if ((cmnObj instanceof CmnModel)) {
      final Outlet generatedJavaSource = outlets.get("generatedJavaSource");
      final Outlet generatedApiSource = this._outletHelper.getGeneratedApiOutlet(outlets, cmnObj, properties);
      Outlet firstCutJavaSource = outlets.get("firstCutJavaSource");
      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, generatedApiSource, properties);
              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, properties, 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);
                }
              }
            }
          }
        }
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy