Skip to content

Commit 6dd20d2

Browse files
committed
Move the SmartDataModel handling to indexinng time
1 parent 30b2ca2 commit 6dd20d2

File tree

2 files changed

+156
-158
lines changed

2 files changed

+156
-158
lines changed

src/main/java/org/computate/frFR/java/EcrireGenClasse.java

Lines changed: 0 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -6355,161 +6355,6 @@ public void ecrireClasseCommentaire(JsonObject langueConfig, String siteNom, Str
63556355
classe.put("Description", b.toString());
63566356
}
63576357

6358-
try {
6359-
if(classeSmartDataModel != null && !classeFiware) {
6360-
File smartDataModelSpecFile = new File(siteChemin, String.format("../smart-data-models/%s/dataModel.%s/%s/model.yaml", classeSmartDataDomain.replace(" ", ""), classeSmartDataSubModule, classeSmartDataModel));
6361-
LOG.info(String.format("Loading smart data model at %s", smartDataModelSpecFile.getAbsolutePath()));
6362-
if(smartDataModelSpecFile.exists()) {
6363-
ToutEcrivain wSmartDataModel = ToutEcrivain.create();
6364-
Yaml yaml = new Yaml();
6365-
Map<String, Object> map = yaml.load(FileUtils.readFileToString(smartDataModelSpecFile, StandardCharsets.UTF_8));
6366-
JsonObject spec = new JsonObject(map);
6367-
JsonObject properties = spec.getJsonObject(classeSmartDataModel).getJsonObject("properties");
6368-
wSmartDataModel.l();
6369-
wSmartDataModel.tl(0, "FIWARE SmartDataModel fields:");
6370-
wSmartDataModel.l();
6371-
wSmartDataModel.l("import java.math.BigDecimal;");
6372-
wSmartDataModel.l("import java.util.List;");
6373-
wSmartDataModel.l("import java.util.Optional;");
6374-
wSmartDataModel.l("import org.apache.commons.lang3.StringUtils;");
6375-
wSmartDataModel.l("import org.computate.search.tool.SearchTool;");
6376-
wSmartDataModel.l("import org.computate.search.wrap.Wrap;");
6377-
wSmartDataModel.l("import ", classePartsModeleBase.nomCanonique(langueNom), ";");
6378-
wSmartDataModel.l("import org.computate.vertx.search.list.SearchList;");
6379-
wSmartDataModel.l("import io.vertx.core.Promise;");
6380-
wSmartDataModel.l("import io.vertx.core.json.JsonArray;");
6381-
wSmartDataModel.l("import io.vertx.core.json.JsonObject;");
6382-
wSmartDataModel.l("import io.vertx.pgclient.data.Path;");
6383-
wSmartDataModel.l("import io.vertx.pgclient.data.Point;");
6384-
wSmartDataModel.l();
6385-
wSmartDataModel.l("/**");
6386-
wSmartDataModel.l(" * SmartDataModel: ", classeSmartDataModel, " - ", classeSmartDataSubModule, " - ", classeSmartDataDomain);
6387-
wSmartDataModel.l(" * Fiware: true");
6388-
wSmartDataModel.l(" *");
6389-
wSmartDataModel.l(" * Model: true");
6390-
wSmartDataModel.l(" * SqlOrder: 1");
6391-
wSmartDataModel.l(" * Api: true");
6392-
wSmartDataModel.l(" * Page: true");
6393-
wSmartDataModel.l(" * SuperPage.enUS: BaseModelPage");
6394-
wSmartDataModel.l(" * Indexed: true");
6395-
wSmartDataModel.l(" * Order: 1");
6396-
wSmartDataModel.l(" * Description: ");
6397-
wSmartDataModel.l(" * ApiTag.enUS: ", classeNomSimple);
6398-
wSmartDataModel.l(" * ApiUri.enUS: /api/", classeNomSimple);
6399-
wSmartDataModel.l(" *");
6400-
wSmartDataModel.l(" * ApiMethod.enUS: Search");
6401-
wSmartDataModel.l(" * ApiMethod: GET");
6402-
wSmartDataModel.l(" * ApiMethod: PATCH");
6403-
wSmartDataModel.l(" * ApiMethod: POST");
6404-
wSmartDataModel.l(" * ApiMethod: PUTImport");
6405-
wSmartDataModel.l(" *");
6406-
wSmartDataModel.l(" * ApiMethod.enUS: SearchPage");
6407-
wSmartDataModel.l(" * Page.SearchPage.enUS: ", classeNomSimple, "Page");
6408-
wSmartDataModel.l(" * ApiUri.SearchPage.enUS: /", classeNomSimple);
6409-
wSmartDataModel.l(" *");
6410-
wSmartDataModel.l(" * Role.enUS: SiteAdmin");
6411-
wSmartDataModel.l(" *");
6412-
wSmartDataModel.l(" * AName.enUS: a ", classeNomSimple);
6413-
wSmartDataModel.l(" * Color: 2017-shaded-spruce");
6414-
wSmartDataModel.l(" * IconGroup: duotone");
6415-
wSmartDataModel.l(" * IconName: map-location-dot");
6416-
wSmartDataModel.l(" * Rows: 100");
6417-
wSmartDataModel.l(" **/");
6418-
wSmartDataModel.l("public class ", classeNomSimple, " extends ", classeNomSimple, "Gen<BaseModel> {");
6419-
6420-
Integer row = 3;
6421-
Integer cell = 1;
6422-
for(String fieldName : properties.fieldNames()) {
6423-
if(!fieldName.equals("id") && !fieldName.equals("type")) {
6424-
JsonObject field = properties.getJsonObject(fieldName);
6425-
String jsonType = field.getString("type");
6426-
String description = field.getString("description");
6427-
String javaType = "JsonObject";
6428-
if("areaServed".equals(fieldName))
6429-
javaType = "Path";
6430-
else if("location".equals(fieldName))
6431-
javaType = "Point";
6432-
else if("string".equals(jsonType))
6433-
javaType = "String";
6434-
else if("boolean".equals(jsonType))
6435-
javaType = "Boolean";
6436-
else if("integer".equals(jsonType))
6437-
javaType = "Integer";
6438-
else if("number".equals(jsonType))
6439-
javaType = "BigDecimal";
6440-
else if("location".equals(fieldName))
6441-
javaType = "Path";
6442-
wSmartDataModel.l();
6443-
wSmartDataModel.l(" /**");
6444-
wSmartDataModel.l(" * {@inheritDoc}");
6445-
if("areaServed".equals(fieldName)) {
6446-
wSmartDataModel.l(" ");
6447-
wSmartDataModel.l(" * LocationColor: true");
6448-
wSmartDataModel.l(" * Indexed: true");
6449-
wSmartDataModel.l(" * Stored: true");
6450-
wSmartDataModel.l(" * DisplayName: area served colors");
6451-
wSmartDataModel.l(" * Description: The colors of each areaServed Paths. ");
6452-
wSmartDataModel.l(" */");
6453-
wSmartDataModel.l(" protected void _areaServedColors(List<String> l) {");
6454-
wSmartDataModel.l(" }");
6455-
wSmartDataModel.l();
6456-
wSmartDataModel.l(" /**");
6457-
wSmartDataModel.l(" * {@inheritDoc}");
6458-
wSmartDataModel.l(" * LocationTitle: true");
6459-
wSmartDataModel.l(" * Indexed: true");
6460-
wSmartDataModel.l(" * Stored: true");
6461-
wSmartDataModel.l(" * DisplayName: area served titles");
6462-
wSmartDataModel.l(" * Description: The titles of each areaServed Paths. ");
6463-
wSmartDataModel.l(" */");
6464-
wSmartDataModel.l(" protected void _areaServedTitles(List<String> l) {");
6465-
wSmartDataModel.l(" }");
6466-
wSmartDataModel.l();
6467-
wSmartDataModel.l(" /**");
6468-
wSmartDataModel.l(" * {@inheritDoc}");
6469-
wSmartDataModel.l(" * LocationUrl: true");
6470-
wSmartDataModel.l(" * Indexed: true");
6471-
wSmartDataModel.l(" * Stored: true");
6472-
wSmartDataModel.l(" * DisplayName: area served links");
6473-
wSmartDataModel.l(" * Description: The links of each areaServed Paths. ");
6474-
wSmartDataModel.l(" */");
6475-
wSmartDataModel.l(" protected void _areaServedLinks(List<String> l) {");
6476-
wSmartDataModel.l(" }");
6477-
wSmartDataModel.l();
6478-
wSmartDataModel.l(" /**");
6479-
wSmartDataModel.l(" * {@inheritDoc}");
6480-
wSmartDataModel.l(" * FiwareType: geo:linestring");
6481-
wSmartDataModel.l(" * Location: true");
6482-
}
6483-
if("location".equals(fieldName)) {
6484-
wSmartDataModel.l(" * FiwareType: geo:point");
6485-
}
6486-
wSmartDataModel.l(" * DocValues: true");
6487-
wSmartDataModel.l(" * Persist: true");
6488-
wSmartDataModel.l(" * DisplayName: ", StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(fieldName), " ").toLowerCase(), "");
6489-
if(description != null)
6490-
wSmartDataModel.l(" * Description: ", description.replace("\r\n", " ").replace("\n", " "), "");
6491-
wSmartDataModel.l(" * HtmRow: ", row, "");
6492-
wSmartDataModel.l(" * HtmCell: ", cell, "");
6493-
wSmartDataModel.l(" * Facet: true");
6494-
wSmartDataModel.l(" **/");
6495-
wSmartDataModel.l(" protected void _", fieldName, "(Wrap<", javaType, "> w) {}");
6496-
cell++;
6497-
if(cell > 3) {
6498-
row++;
6499-
cell = 1;
6500-
}
6501-
wSmartDataModel.l();
6502-
}
6503-
}
6504-
wSmartDataModel.l("}");
6505-
wSmartDataModel.l();
6506-
System.out.println(wSmartDataModel);
6507-
}
6508-
}
6509-
} catch(Exception ex) {
6510-
ExceptionUtils.rethrow(ex);
6511-
}
6512-
65136358
ecrireClasseCommentaireChamp(langueNom, classeRef, "01_commentaire", "commentaire", wClasseDescription
65146359
, true
65156360
, classeNomSimpleGen

src/main/java/org/computate/frFR/java/IndexerClasse.java

Lines changed: 156 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.math.MathContext;
2121
import java.math.RoundingMode;
2222
import java.net.URLEncoder;
23+
import java.nio.charset.StandardCharsets;
2324
import java.sql.Timestamp;
2425
import java.text.Normalizer;
2526
import java.text.NumberFormat;
@@ -76,6 +77,7 @@
7677
import org.apache.solr.common.SolrInputField;
7778
import org.slf4j.Logger;
7879
import org.slf4j.LoggerFactory;
80+
import org.yaml.snakeyaml.Yaml;
7981

8082
import com.fasterxml.jackson.annotation.JsonFormat;
8183
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -5388,6 +5390,7 @@ else if(langueConfig.getString(ConfigCles.var_PUTFusion).equals(classeApiMethode
53885390
}
53895391

53905392
String classeSmartDataModelStr = regex("^SmartDataModel:\\s(.*)", classeCommentaire);
5393+
53915394
if(classeSmartDataModelStr != null) {
53925395
String encodedStr = "\"" + Arrays.asList(classeSmartDataModelStr.replaceAll("([a-z])([A-Z])", "$1 $2").split(" +")).stream().map(s -> encodeUrl(s)).collect(Collectors.joining("\" OR \"")) + "\"";
53935396
System.out.println(encodedStr);
@@ -5400,9 +5403,9 @@ else if(langueConfig.getString(ConfigCles.var_PUTFusion).equals(classeApiMethode
54005403
SolrDocumentList listeRecherche = reponseRecherche.getResults();
54015404
if(listeRecherche.size() > 0) {
54025405
SolrDocument doc = listeRecherche.get(0);
5403-
indexerStockerSolr(classeDoc, "classeSmartDataDomain", doc.getFieldValue("domainName_docvalues_string").toString().replace(" ", "").trim());
5404-
indexerStockerSolr(classeDoc, "classeSmartDataSubModule", doc.getFieldValue("submoduleShortName_docvalues_string").toString().trim());
5405-
indexerStockerSolr(classeDoc, "classeSmartDataModel", doc.getFieldValue("modelName_docvalues_string").toString().trim());
5406+
String classeSmartDataDomain = indexerStockerSolr(classeDoc, "classeSmartDataDomain", doc.getFieldValue("domainName_docvalues_string").toString().replace(" ", "").trim());
5407+
String classeSmartDataSubModule = indexerStockerSolr(classeDoc, "classeSmartDataSubModule", doc.getFieldValue("submoduleShortName_docvalues_string").toString().trim());
5408+
String classeSmartDataModel = indexerStockerSolr(classeDoc, "classeSmartDataModel", doc.getFieldValue("modelName_docvalues_string").toString().trim());
54065409
System.out.println(String.format("Top %s Smart Data Model results were: ", listeRecherche.size()));
54075410
System.out.println(String.format("Model - Submodule - Domain - score", listeRecherche.size()));
54085411
System.out.println(String.format("--------------------------", listeRecherche.size()));
@@ -5411,6 +5414,156 @@ else if(langueConfig.getString(ConfigCles.var_PUTFusion).equals(classeApiMethode
54115414
System.out.println(String.format("%s. %s %s %s %s", String.format("%02d", (i + 1)), model.getFieldValue("modelName_docvalues_string"), model.getFieldValue("submoduleShortName_docvalues_string"), model.getFieldValue("domainName_docvalues_string"), model.getFieldValue("score")));
54125415
}
54135416
System.out.println(" ");
5417+
if(classeSmartDataModel != null && !classeFiware) {
5418+
File smartDataModelSpecFile = new File(siteChemin, String.format("../smart-data-models/%s/dataModel.%s/%s/model.yaml", classeSmartDataDomain.replace(" ", ""), classeSmartDataSubModule, classeSmartDataModel));
5419+
LOG.info(String.format("Loading smart data model at %s", smartDataModelSpecFile.getAbsolutePath()));
5420+
if(smartDataModelSpecFile.exists()) {
5421+
ToutEcrivain wSmartDataModel = ToutEcrivain.create();
5422+
Yaml yaml = new Yaml();
5423+
Map<String, Object> map = yaml.load(FileUtils.readFileToString(smartDataModelSpecFile, StandardCharsets.UTF_8));
5424+
JsonObject spec = new JsonObject(map);
5425+
JsonObject properties = spec.getJsonObject(classeSmartDataModel).getJsonObject("properties");
5426+
wSmartDataModel.l();
5427+
wSmartDataModel.tl(0, "FIWARE SmartDataModel fields:");
5428+
wSmartDataModel.l();
5429+
wSmartDataModel.l("import java.math.BigDecimal;");
5430+
wSmartDataModel.l("import java.util.List;");
5431+
wSmartDataModel.l("import java.util.Optional;");
5432+
wSmartDataModel.l("import org.apache.commons.lang3.StringUtils;");
5433+
wSmartDataModel.l("import org.computate.search.tool.SearchTool;");
5434+
wSmartDataModel.l("import org.computate.search.wrap.Wrap;");
5435+
wSmartDataModel.l("import ", classePartsModeleBase.nomCanonique(classeLangueNom), ";");
5436+
wSmartDataModel.l("import org.computate.vertx.search.list.SearchList;");
5437+
wSmartDataModel.l("import io.vertx.core.Promise;");
5438+
wSmartDataModel.l("import io.vertx.core.json.JsonArray;");
5439+
wSmartDataModel.l("import io.vertx.core.json.JsonObject;");
5440+
wSmartDataModel.l("import io.vertx.pgclient.data.Path;");
5441+
wSmartDataModel.l("import io.vertx.pgclient.data.Point;");
5442+
wSmartDataModel.l();
5443+
wSmartDataModel.l("/**");
5444+
wSmartDataModel.l(" * SmartDataModel: ", classeSmartDataModel, " - ", classeSmartDataSubModule, " - ", classeSmartDataDomain);
5445+
wSmartDataModel.l(" * Fiware: true");
5446+
wSmartDataModel.l(" *");
5447+
wSmartDataModel.l(" * Model: true");
5448+
wSmartDataModel.l(" * SqlOrder: 1");
5449+
wSmartDataModel.l(" * Api: true");
5450+
wSmartDataModel.l(" * Page: true");
5451+
wSmartDataModel.l(" * SuperPage.enUS: BaseModelPage");
5452+
wSmartDataModel.l(" * Indexed: true");
5453+
wSmartDataModel.l(" * Order: 1");
5454+
wSmartDataModel.l(" * Description: ");
5455+
wSmartDataModel.l(" * ApiTag.enUS: ", classeNomSimple);
5456+
wSmartDataModel.l(" * ApiUri.enUS: /api/", classeNomSimple);
5457+
wSmartDataModel.l(" *");
5458+
wSmartDataModel.l(" * ApiMethod.enUS: Search");
5459+
wSmartDataModel.l(" * ApiMethod: GET");
5460+
wSmartDataModel.l(" * ApiMethod: PATCH");
5461+
wSmartDataModel.l(" * ApiMethod: POST");
5462+
wSmartDataModel.l(" * ApiMethod: PUTImport");
5463+
wSmartDataModel.l(" *");
5464+
wSmartDataModel.l(" * ApiMethod.enUS: SearchPage");
5465+
wSmartDataModel.l(" * Page.SearchPage.enUS: ", classeNomSimple, "Page");
5466+
wSmartDataModel.l(" * ApiUri.SearchPage.enUS: /", classeNomSimple);
5467+
wSmartDataModel.l(" *");
5468+
wSmartDataModel.l(" * Role.enUS: SiteAdmin");
5469+
wSmartDataModel.l(" *");
5470+
wSmartDataModel.l(" * AName.enUS: a ", classeNomSimple);
5471+
wSmartDataModel.l(" * Color: 2017-shaded-spruce");
5472+
wSmartDataModel.l(" * IconGroup: duotone");
5473+
wSmartDataModel.l(" * IconName: map-location-dot");
5474+
wSmartDataModel.l(" * Rows: 100");
5475+
wSmartDataModel.l(" **/");
5476+
wSmartDataModel.l("public class ", classeNomSimple, " extends ", classeNomSimple, "Gen<BaseModel> {");
5477+
5478+
Integer row = 3;
5479+
Integer cell = 1;
5480+
for(String fieldName : properties.fieldNames()) {
5481+
if(!fieldName.equals("id") && !fieldName.equals("type")) {
5482+
JsonObject field = properties.getJsonObject(fieldName);
5483+
String jsonType = field.getString("type");
5484+
String description = field.getString("description");
5485+
String javaType = "JsonObject";
5486+
if("areaServed".equals(fieldName))
5487+
javaType = "Path";
5488+
else if("location".equals(fieldName))
5489+
javaType = "Point";
5490+
else if("string".equals(jsonType))
5491+
javaType = "String";
5492+
else if("boolean".equals(jsonType))
5493+
javaType = "Boolean";
5494+
else if("integer".equals(jsonType))
5495+
javaType = "Integer";
5496+
else if("number".equals(jsonType))
5497+
javaType = "BigDecimal";
5498+
else if("location".equals(fieldName))
5499+
javaType = "Path";
5500+
wSmartDataModel.l();
5501+
wSmartDataModel.l(" /**");
5502+
wSmartDataModel.l(" * {@inheritDoc}");
5503+
if("areaServed".equals(fieldName)) {
5504+
wSmartDataModel.l(" ");
5505+
wSmartDataModel.l(" * LocationColor: true");
5506+
wSmartDataModel.l(" * Indexed: true");
5507+
wSmartDataModel.l(" * Stored: true");
5508+
wSmartDataModel.l(" * DisplayName: area served colors");
5509+
wSmartDataModel.l(" * Description: The colors of each areaServed Paths. ");
5510+
wSmartDataModel.l(" */");
5511+
wSmartDataModel.l(" protected void _areaServedColors(List<String> l) {");
5512+
wSmartDataModel.l(" }");
5513+
wSmartDataModel.l();
5514+
wSmartDataModel.l(" /**");
5515+
wSmartDataModel.l(" * {@inheritDoc}");
5516+
wSmartDataModel.l(" * LocationTitle: true");
5517+
wSmartDataModel.l(" * Indexed: true");
5518+
wSmartDataModel.l(" * Stored: true");
5519+
wSmartDataModel.l(" * DisplayName: area served titles");
5520+
wSmartDataModel.l(" * Description: The titles of each areaServed Paths. ");
5521+
wSmartDataModel.l(" */");
5522+
wSmartDataModel.l(" protected void _areaServedTitles(List<String> l) {");
5523+
wSmartDataModel.l(" }");
5524+
wSmartDataModel.l();
5525+
wSmartDataModel.l(" /**");
5526+
wSmartDataModel.l(" * {@inheritDoc}");
5527+
wSmartDataModel.l(" * LocationUrl: true");
5528+
wSmartDataModel.l(" * Indexed: true");
5529+
wSmartDataModel.l(" * Stored: true");
5530+
wSmartDataModel.l(" * DisplayName: area served links");
5531+
wSmartDataModel.l(" * Description: The links of each areaServed Paths. ");
5532+
wSmartDataModel.l(" */");
5533+
wSmartDataModel.l(" protected void _areaServedLinks(List<String> l) {");
5534+
wSmartDataModel.l(" }");
5535+
wSmartDataModel.l();
5536+
wSmartDataModel.l(" /**");
5537+
wSmartDataModel.l(" * {@inheritDoc}");
5538+
wSmartDataModel.l(" * FiwareType: geo:linestring");
5539+
wSmartDataModel.l(" * Location: true");
5540+
}
5541+
if("location".equals(fieldName)) {
5542+
wSmartDataModel.l(" * FiwareType: geo:point");
5543+
}
5544+
wSmartDataModel.l(" * DocValues: true");
5545+
wSmartDataModel.l(" * Persist: true");
5546+
wSmartDataModel.l(" * DisplayName: ", StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(fieldName), " ").toLowerCase(), "");
5547+
if(description != null)
5548+
wSmartDataModel.l(" * Description: ", description.replace("\r\n", " ").replace("\n", " "), "");
5549+
wSmartDataModel.l(" * HtmRow: ", row, "");
5550+
wSmartDataModel.l(" * HtmCell: ", cell, "");
5551+
wSmartDataModel.l(" * Facet: true");
5552+
wSmartDataModel.l(" **/");
5553+
wSmartDataModel.l(" protected void _", fieldName, "(Wrap<", javaType, "> w) {}");
5554+
cell++;
5555+
if(cell > 3) {
5556+
row++;
5557+
cell = 1;
5558+
}
5559+
wSmartDataModel.l();
5560+
}
5561+
}
5562+
wSmartDataModel.l("}");
5563+
wSmartDataModel.l();
5564+
System.out.println(wSmartDataModel);
5565+
}
5566+
}
54145567
}
54155568
}
54165569

0 commit comments

Comments
 (0)