2020import java .math .MathContext ;
2121import java .math .RoundingMode ;
2222import java .net .URLEncoder ;
23+ import java .nio .charset .StandardCharsets ;
2324import java .sql .Timestamp ;
2425import java .text .Normalizer ;
2526import java .text .NumberFormat ;
7677import org .apache .solr .common .SolrInputField ;
7778import org .slf4j .Logger ;
7879import org .slf4j .LoggerFactory ;
80+ import org .yaml .snakeyaml .Yaml ;
7981
8082import com .fasterxml .jackson .annotation .JsonFormat ;
8183import 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