use of io.vertigo.util.MapBuilder in project vertigo by KleeGroup.
the class TSGeneratorPlugin method generateDtResourcesTS.
/**
* Génère les ressources JS pour les traductions.
* @param fileGeneratorConfig Configuration du domaine.
*/
private static void generateDtResourcesTS(final String targetSubDir, final FileGeneratorConfig fileGeneratorConfig, final MdaResultBuilder mdaResultBuilder) {
final Map<String, List<TSDtDefinitionModel>> packageMap = new HashMap<>();
for (final TSDtDefinitionModel dtDefinitionModel : getTsDtDefinitionModels()) {
final String packageName = dtDefinitionModel.getFunctionnalPackageName();
packageMap.computeIfAbsent(packageName, o -> new ArrayList<>()).add(dtDefinitionModel);
}
final String simpleClassName = "DtDefinitions" + "Label";
for (final Entry<String, List<TSDtDefinitionModel>> entry : packageMap.entrySet()) {
final Map<String, Object> model = new MapBuilder<String, Object>().put("packageName", entry.getKey()).put("simpleClassName", simpleClassName).put("dtDefinitions", entry.getValue()).build();
FileGenerator.builder(fileGeneratorConfig).withModel(model).withFileName(entry.getKey() + ".ts").withGenSubDir(targetSubDir).withPackageName(fileGeneratorConfig.getProjectPackageName() + ".ui." + entry.getKey() + ".i18n.generated").withTemplateName("domain/ts/template/propertiesTS.ftl").build().generateFile(mdaResultBuilder);
}
}
use of io.vertigo.util.MapBuilder in project vertigo by KleeGroup.
the class SqlGeneratorPlugin method generateMasterDataInserts.
private void generateMasterDataInserts(final FileGeneratorConfig fileGeneratorConfig, final MdaResultBuilder mdaResultBuilder) {
final MasterDataValues masterDataValues = masterDataManagerOpt.isPresent() ? masterDataManagerOpt.get().getValues() : new MasterDataValues();
final List<SqlMasterDataDefinitionModel> sqlMasterDataDefinitionModels = Home.getApp().getDefinitionSpace().getAll(DtDefinition.class).stream().filter(dtDefinition -> dtDefinition.getStereotype() == DtStereotype.StaticMasterData).map(dtDefinition -> new SqlMasterDataDefinitionModel(dtDefinition, masterDataValues.getOrDefault(dtDefinition.getClassCanonicalName(), Collections.emptyMap()))).collect(Collectors.toList());
final Map<String, Object> model = new MapBuilder<String, Object>().put("masterdatas", sqlMasterDataDefinitionModels).build();
FileGenerator.builder(fileGeneratorConfig).withModel(model).withFileName("init_masterdata.sql").withGenSubDir(targetSubDir).withPackageName("").withTemplateName("domain/sql/template/init_masterdata.ftl").build().generateFile(mdaResultBuilder);
}
use of io.vertigo.util.MapBuilder in project vertigo by KleeGroup.
the class DomainGeneratorPlugin method generateDtResources.
private static void generateDtResources(final String targetSubDir, final FileGeneratorConfig fileGeneratorConfig, final MdaResultBuilder mdaResultBuilder) {
final String simpleClassName = "DtResources";
final String resourcesTemplateName = "domain/java/template/resources.ftl";
final String propertiesTemplateName = "domain/java/template/properties.ftl";
// pour les .properties on force l'ISO-8859-1 comme la norme l'impose
final FileGeneratorConfig propertiesFileConfig = new FileGeneratorConfig(fileGeneratorConfig.getTargetGenDir(), fileGeneratorConfig.getProjectPackageName(), "ISO-8859-1");
/**
* Génération des ressources afférentes au DT.
*/
for (final Entry<String, Collection<DtDefinition>> entry : DomainUtil.getDtDefinitionCollectionMap().entrySet()) {
final Collection<DtDefinition> dtDefinitions = entry.getValue();
Assertion.checkNotNull(dtDefinitions);
final String packageName = entry.getKey();
final Map<String, Object> model = new MapBuilder<String, Object>().put("packageName", packageName).put("simpleClassName", simpleClassName).put("dtDefinitions", toModels(dtDefinitions)).build();
FileGenerator.builder(fileGeneratorConfig).withModel(model).withFileName(simpleClassName + ".java").withGenSubDir(targetSubDir).withPackageName(packageName).withTemplateName(resourcesTemplateName).build().generateFile(mdaResultBuilder);
FileGenerator.builder(propertiesFileConfig).withModel(model).withFileName(simpleClassName + ".properties").withGenSubDir(targetSubDir).withPackageName(packageName).withTemplateName(propertiesTemplateName).build().generateFile(mdaResultBuilder);
}
}
use of io.vertigo.util.MapBuilder 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);
}
}
}
use of io.vertigo.util.MapBuilder in project vertigo by KleeGroup.
the class WebServiceManagerTest method testFacetedSearchResult.
@Test
public void testFacetedSearchResult() {
final Map<String, Object> emptySelectedFacets = new MapBuilder<String, Object>().build();
final Response getResponse = loggedAndExpect(given().body(emptySelectedFacets)).statusCode(HttpStatus.SC_OK).body("list", Matchers.hasSize(Matchers.greaterThanOrEqualTo(10))).body("facets.get(1).code", Matchers.equalTo("FCT_BIRTHDAY")).body("facets.get(1).values.get(0).code", Matchers.equalTo("R1")).body("facets.get(1).values.get(0).count", Matchers.equalTo(4)).body("facets.get(1).values.get(1).code", Matchers.equalTo("R2")).body("facets.get(1).values.get(1).count", Matchers.greaterThanOrEqualTo(6)).body("totalCount", Matchers.greaterThanOrEqualTo(10)).when().post("/search/facetedResult");
final int fctBirthDayR1 = getResponse.body().path("facets.get(1).values.get(0).count");
final int fctBirthDayR2 = getResponse.body().path("facets.get(1).values.get(1).count");
final Map<String, Object> selectedFacetsMono = new MapBuilder<String, Object>().put("FCT_HONORIFIC_CODE", "MR_").build();
loggedAndExpect(given().body(selectedFacetsMono)).statusCode(HttpStatus.SC_OK).body("list", Matchers.hasSize(1)).body("totalCount", Matchers.equalTo(1)).body("facets.get(0).values", Matchers.hasSize(1)).when().post("/search/facetedResult");
final Map<String, Object> selectedFacetsByCode = new MapBuilder<String, Object>().put("FCT_BIRTHDAY", "R1").build();
loggedAndExpect(given().body(selectedFacetsByCode)).statusCode(HttpStatus.SC_OK).body("list", Matchers.hasSize(fctBirthDayR1)).body("totalCount", Matchers.equalTo(fctBirthDayR1)).body("facets.get(0).values", Matchers.hasSize(fctBirthDayR1)).when().post("/search/facetedResult");
final Map<String, Object> selectedFacetsByLabel = new MapBuilder<String, Object>().put("FCT_BIRTHDAY", "1980-1990").build();
loggedAndExpect(given().body(selectedFacetsByLabel)).statusCode(HttpStatus.SC_OK).body("list", Matchers.hasSize(fctBirthDayR2)).body("totalCount", Matchers.equalTo(fctBirthDayR2)).body("facets.get(0).values", Matchers.hasSize(6)).when().post("/search/facetedResult");
final Map<String, Object> selectedFacetsBoth = new MapBuilder<String, Object>().put("FCT_HONORIFIC_CODE", "MR_").put("FCT_BIRTHDAY", "R2").build();
loggedAndExpect(given().body(selectedFacetsBoth)).statusCode(HttpStatus.SC_OK).body("list", Matchers.hasSize(1)).body("totalCount", Matchers.equalTo(1)).body("facets.get(0).values", Matchers.hasSize(1)).when().post("/search/facetedResult");
final Map<String, Object> selectedFacetsMultiple = new MapBuilder<String, Object>().put("FCT_HONORIFIC_CODE", new String[] { "MR_", "MS_" }).put("FCT_BIRTHDAY", "R2").build();
loggedAndExpect(given().body(selectedFacetsMultiple)).statusCode(HttpStatus.SC_OK).body("list", Matchers.hasSize(2)).body("totalCount", Matchers.equalTo(2)).body("facets.get(0).values", Matchers.hasSize(2)).when().post("/search/facetedResult");
}
Aggregations