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

org.joinedworkz.common.OpenApiCartridge Maven / Gradle / Ivy

There is a newer version: 1.3.51
Show newest version
package org.joinedworkz.common;

import com.google.common.collect.Iterables;
import java.util.ArrayList;
import java.util.List;
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.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.joinedworkz.common.generator.CmnOpenApiGenerator;
import org.joinedworkz.common.helper.CmnModelHelper;
import org.joinedworkz.common.helper.OpenApiHelper;
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.CmnResource;

@Singleton
@SuppressWarnings("all")
public class OpenApiCartridge extends AbstractCartridge {
  @Inject
  @Extension
  protected CmnModelHelper cmnModelHelper;

  @Inject
  protected CmnOpenApiGenerator openApiGenerator;

  @Inject
  protected OpenApiHelper openApiHelper;

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

  @Override
  public void apply(final CmnObject obj, final Outlets outlets, final Properties properties) {
    final Outlet openApiOutlet = outlets.get("generatedOpenApi");
    final Outlet openApiHtmlOutlet = outlets.get("generatedOpenApiHtml");
    if ((obj instanceof CmnModel)) {
      this.generateOpenApi(((CmnModel)obj), openApiOutlet, openApiHtmlOutlet, properties);
    }
  }

  public void generateOpenApi(final CmnModel model, final Outlet openApiOutlet, final Outlet openApiHtmlOutlet, final Properties properties) {
    final Iterable components = Iterables.filter(model.getModelElements(), CmnComponent.class);
    final ArrayList allComponents = CollectionLiterals.newArrayList();
    for (final CmnComponent component : components) {
      {
        allComponents.add(component);
        List _subComponents = component.getSubComponents();
        for (final CmnComponent subComponent : _subComponents) {
          allComponents.add(subComponent);
        }
      }
    }
    for (final CmnComponent component_1 : allComponents) {
      {
        final OpenApiGeneratorContext ctx = this.createGeneratorContext(model, openApiOutlet, openApiHtmlOutlet, properties);
        final Set resourcesForApi = this.openApiHelper.createProvidedResourceAdaptersForComponent(component_1);
        this.openApiGenerator.generateOpenApiYml(component_1, resourcesForApi, ctx);
        ctx.clearAdapters();
      }
    }
    final Function1 _function = (CmnResource it) -> {
      Boolean _abstract = it.getAbstract();
      return Boolean.valueOf((!(_abstract).booleanValue()));
    };
    final Iterable allResourcesOfModel = IterableExtensions.filter(Iterables.filter(model.getModelElements(), CmnResource.class), _function);
    this.openApiGenerator.generateOpenApiYml(null, allResourcesOfModel, this.createGeneratorContext(model, openApiOutlet, openApiHtmlOutlet, properties));
  }

  public OpenApiGeneratorContext createGeneratorContext(final CmnModel model, final Outlet outlet, final Outlet htmlOutlet, final Properties properties) {
    return new OpenApiGeneratorContext(model, outlet, htmlOutlet, properties);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy