Search in sources :

Example 1 with WebServiceDefinitionModelTs

use of io.vertigo.studio.plugins.mda.webservice.model.WebServiceDefinitionModelTs in project vertigo by KleeGroup.

the class WsTsGeneratorPlugin method generateRoute.

private static void generateRoute(final String targetSubDir, final FileGeneratorConfig fileGeneratorConfig, final MdaResultBuilder mdaResultBuilder) {
    final Collection<WebServiceDefinition> webServiceDefinitions = getWebServiceDefinitions();
    if (!webServiceDefinitions.isEmpty()) {
        final Map<String, List<WebServiceDefinitionModelTs>> webServicesPerFacades = new HashMap<>();
        for (final WebServiceDefinition webServiceDefinition : webServiceDefinitions) {
            final String facadeName = webServiceDefinition.getMethod().getDeclaringClass().getSimpleName().replaceAll("WebServices", "");
            List<WebServiceDefinitionModelTs> facadeWebServiceDefinitions = webServicesPerFacades.get(facadeName);
            if (facadeWebServiceDefinitions == null) {
                facadeWebServiceDefinitions = new ArrayList<>();
                webServicesPerFacades.put(facadeName, facadeWebServiceDefinitions);
            }
            facadeWebServiceDefinitions.add(new WebServiceDefinitionModelTs(webServiceDefinition));
        }
        final Map<String, List<WebServiceInitializerModelTs>> facadeByPackage = new HashMap<>();
        for (final Map.Entry<String, List<WebServiceDefinitionModelTs>> entry : webServicesPerFacades.entrySet()) {
            final String packageName = entry.getValue().get(0).getFunctionnalPackageName();
            final String simpleClassName = entry.getKey();
            final String jsFileNameWithoutExtension = JsFileNameUtil.convertCamelCaseToJsCase(simpleClassName);
            final Set<String> importList = new HashSet<>();
            final List<WebServiceDefinitionModelTs> routeList = entry.getValue();
            for (final WebServiceDefinitionModelTs route : routeList) {
                importList.addAll(route.getImportList());
            }
            if (!facadeByPackage.containsKey(packageName)) {
                facadeByPackage.put(packageName, new ArrayList<WebServiceInitializerModelTs>());
            }
            facadeByPackage.get(packageName).add(new WebServiceInitializerModelTs(jsFileNameWithoutExtension, simpleClassName));
            final Map<String, Object> model = new MapBuilder<String, Object>().put("routes", entry.getValue()).put("importList", importList).build();
            FileGenerator.builder(fileGeneratorConfig).withModel(model).withFileName(jsFileNameWithoutExtension + ".ts").withGenSubDir(targetSubDir).withPackageName(fileGeneratorConfig.getProjectPackageName() + ".ui." + packageName + ".services.generated").withTemplateName("webservice/template/routejsts.ftl").build().generateFile(mdaResultBuilder);
        }
        for (final Map.Entry<String, List<WebServiceInitializerModelTs>> entry : facadeByPackage.entrySet()) {
            final Map<String, Object> model = new MapBuilder<String, Object>().put("serviceList", entry.getValue()).build();
            FileGenerator.builder(fileGeneratorConfig).withModel(model).withFileName("service-gen-initializer.ts").withGenSubDir(targetSubDir).withPackageName(fileGeneratorConfig.getProjectPackageName() + ".ui." + entry.getKey() + ".initializer.generated").withTemplateName("webservice/template/service-initializer.ftl").build().generateFile(mdaResultBuilder);
            FileGenerator.builder(fileGeneratorConfig).withModel(model).withFileName("service-type.ts").withGenSubDir(targetSubDir).withPackageName(fileGeneratorConfig.getProjectPackageName() + ".ui." + entry.getKey() + ".services.generated").withTemplateName("webservice/template/service-type.ftl").build().generateFile(mdaResultBuilder);
        }
    }
}
Also used : HashMap(java.util.HashMap) WebServiceDefinitionModelTs(io.vertigo.studio.plugins.mda.webservice.model.WebServiceDefinitionModelTs) WebServiceInitializerModelTs(io.vertigo.studio.plugins.mda.webservice.model.WebServiceInitializerModelTs) WebServiceDefinition(io.vertigo.vega.webservice.metamodel.WebServiceDefinition) ArrayList(java.util.ArrayList) List(java.util.List) MapBuilder(io.vertigo.util.MapBuilder) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

WebServiceDefinitionModelTs (io.vertigo.studio.plugins.mda.webservice.model.WebServiceDefinitionModelTs)1 WebServiceInitializerModelTs (io.vertigo.studio.plugins.mda.webservice.model.WebServiceInitializerModelTs)1 MapBuilder (io.vertigo.util.MapBuilder)1 WebServiceDefinition (io.vertigo.vega.webservice.metamodel.WebServiceDefinition)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1