use of io.vertigo.studio.plugins.mda.webservice.model.WebServiceInitializerModelTs 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);
}
}
}
Aggregations