Skip to content

Commit

Permalink
Adding generate.sh to generate code one time instead of watching dire…
Browse files Browse the repository at this point in the history
…ctory
  • Loading branch information
computate committed Nov 6, 2023
1 parent 0ab56e2 commit 08864f7
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 39 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ config/cp.txt
.project
.settings
/target/
/bin/
**/*.swp
**/*.retry
.flattened-pom.xml
Expand Down
4 changes: 4 additions & 0 deletions bin/enUS/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
cd $COMPUTATE_SRC
mvn dependency:build-classpath -Dmdep.outputFile=$COMPUTATE_SRC/config/cp.txt -q
env WATCH=false java -cp "$(cat $COMPUTATE_SRC/config/cp.txt):$COMPUTATE_SRC/target/classes" org.computate.frFR.java.RegarderRepertoire
2 changes: 1 addition & 1 deletion bin/frFR/regarder.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
cd $COMPUTATE_SRC
mvn dependency:build-classpath -Dmdep.outputFile=$COMPUTATE_SRC/config/cp.txt -q
java -cp "$(cat $COMPUTATE_SRC/config/cp.txt):$COMPUTATE_SRC/target/classes" org.computate.frFR.java.RegarderRepertoire
env REGARDER=false java -cp "$(cat $COMPUTATE_SRC/config/cp.txt):$COMPUTATE_SRC/target/classes" org.computate.frFR.java.RegarderRepertoire
1 change: 1 addition & 0 deletions src/main/java/org/computate/frFR/java/ConfigCles.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public class ConfigCles {
public static final String var_Future = "var_Future";
public static final String var_gamme = "var_gamme";
public static final String var_Gamme = "var_Gamme";
public static final String var_Generer = "var_Generer";
public static final String var_generer = "var_generer";
public static final String var_gestionnaireEvenements = "var_gestionnaireEvenements";
public static final String var_GestionnaireEvenements = "var_GestionnaireEvenements";
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/org/computate/frFR/java/EcrireGenClasse.java
Original file line number Diff line number Diff line change
Expand Up @@ -6404,7 +6404,11 @@ public void ecrireClasseCommentaire(JsonObject langueConfig, String siteNom, Str
String jsonType = field.getString("type");
String description = field.getString("description");
String javaType = "JsonObject";
if("string".equals(jsonType))
if("areaServed".equals(fieldName))
javaType = "Polygon";
else if("location".equals(fieldName))
javaType = "Point";
else if("string".equals(jsonType))
javaType = "String";
else if("boolean".equals(jsonType))
javaType = "Boolean";
Expand All @@ -6417,6 +6421,13 @@ else if("location".equals(fieldName))
l(" * <br>");
l(" * {@literal /**}<br>");
l(" * {@literal * {@inheritDoc}}<br>");
if("areaServed".equals(fieldName)) {
l(" * {@literal * FiwareType: geo:linestring}<br>");
l(" * {@literal * Location: true}<br>");
}
if("location".equals(fieldName)) {
l(" * {@literal * FiwareType: geo:point}<br>");
}
l(" * {@literal * DocValues: true}<br>");
l(" * {@literal * Persist: true}<br>");
l(" * {@literal * DisplayName: ", StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(fieldName), " ").toLowerCase(), "}<br>");
Expand Down
69 changes: 41 additions & 28 deletions src/main/java/org/computate/frFR/java/EcrirePageClasse.java
Original file line number Diff line number Diff line change
Expand Up @@ -4681,19 +4681,25 @@ else if(langueConfig.getString(ConfigCles.var_PUTCopie).equals(classeApiMethode)
if(classeVarEmplacement != null) {
auteurPageJs.l();
auteurPageJs.tl(2, "// ", langueConfig.getString(ConfigCles.var_Graphique), " ", langueConfig.getString(ConfigCles.var_Emplacement));
auteurPageJs.tl(2, "var map = L.map('htmBody", langueConfig.getString(ConfigCles.var_Graphique), langueConfig.getString(ConfigCles.var_Emplacement), classePageSuperNomSimple, "');");
auteurPageJs.tl(2, "var geojsonLayer = L.geoJSON().addTo(map);");
auteurPageJs.tl(2, "var data = [];");
auteurPageJs.tl(2, "var layout = {};");
auteurPageJs.tl(2, "layout['showlegend'] = true;");
auteurPageJs.tl(2, "layout['dragmode'] = 'zoom';");
auteurPageJs.tl(2, "layout['uirevision'] = 'true';");
auteurPageJs.tl(2, "L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {");
auteurPageJs.tl(3, "maxZoom: 19,");
auteurPageJs.tl(3, "attribution: '&copy; <a href=\"http://www.openstreetmap.org/copyright\">OpenStreetMap</a>'");
auteurPageJs.tl(2, "}).addTo(map);");
auteurPageJs.l();
auteurPageJs.tl(2, "if(window['DEFAULT_MAP_LOCATION'] && window['DEFAULT_MAP_ZOOM'])");
auteurPageJs.tl(3, "layout['mapbox'] = { style: 'open-street-map', center: { lat: window['DEFAULT_MAP_LOCATION']['lat'], lon: window['DEFAULT_MAP_LOCATION']['lon'] }, zoom: window['DEFAULT_MAP_ZOOM'] };");
auteurPageJs.tl(3, "map.setView([window['DEFAULT_MAP_LOCATION']['lat'], window['DEFAULT_MAP_LOCATION']['lon']], window['DEFAULT_MAP_ZOOM']);");
auteurPageJs.tl(2, "else if(window['DEFAULT_MAP_ZOOM'])");
auteurPageJs.tl(3, "layout['mapbox'] = { style: 'open-street-map', zoom: window['DEFAULT_MAP_ZOOM'] };");
auteurPageJs.tl(3, "map.setView(null, window['DEFAULT_MAP_ZOOM']);");
auteurPageJs.tl(2, "else if(window['DEFAULT_MAP_LOCATION'])");
auteurPageJs.tl(3, "layout['mapbox'] = { style: 'open-street-map', center: { lat: window['DEFAULT_MAP_LOCATION']['lat'], lon: window['DEFAULT_MAP_LOCATION']['lon'] } };");
auteurPageJs.tl(2, "else");
auteurPageJs.tl(3, "layout['mapbox'] = { style: 'open-street-map' };");
auteurPageJs.tl(3, "map.setView([window['DEFAULT_MAP_LOCATION']['lat'], window['DEFAULT_MAP_LOCATION']['lon']]);");
auteurPageJs.l();
auteurPageJs.tl(2, "layout['margin'] = { r: 0, t: 0, b: 0, l: 0 };");
auteurPageJs.tl(2, "$.each( window.", langueConfig.getString(ConfigCles.var_liste), classeNomSimple, ", function(index, ", StringUtils.uncapitalize(classeNomSimple), ") {");
auteurPageJs.tl(3, "if(", StringUtils.uncapitalize(classeNomSimple), ".", classeVarEmplacement, ") {");
Expand All @@ -4720,35 +4726,42 @@ else if(langueConfig.getString(ConfigCles.var_PUTCopie).equals(classeApiMethode)
auteurPageJs.tl(4, "else");
auteurPageJs.tl(5, "shapes.push(", StringUtils.uncapitalize(classeNomSimple), ".", classeVarEmplacement, ");");
auteurPageJs.tl(4, "shapes.forEach(shape => {");
auteurPageJs.tl(5, "var parts = [];");
auteurPageJs.tl(5, "if(shape.coordinates && shape.coordinates[0].length > 0 && Array.isArray(shape.coordinates[0][0]))");
auteurPageJs.tl(6, "parts = parts.concat(shape.coordinates);");
auteurPageJs.tl(5, "else");
auteurPageJs.tl(6, "parts.push(shape.coordinates);");
auteurPageJs.tl(5, "parts.forEach(part => {");
auteurPageJs.tl(6, "var lat = part.map(elem => elem[0]);");
auteurPageJs.tl(6, "var lon = part.map(elem => elem[1]);");
auteurPageJs.tl(6, "if(shape.type == 'Polygon') {");
auteurPageJs.tl(7, "lat.push(lat[0]);");
auteurPageJs.tl(7, "lon.push(lon[0]);");
auteurPageJs.tl(5, "geojsonLayer.addData({");
auteurPageJs.tl(6, "\"type\": \"Feature\"");
auteurPageJs.tl(6, ", \"properties\": {");
auteurPageJs.tl(7, "\"name\": \"stuff\"");
auteurPageJs.tl(6, "}");
auteurPageJs.tl(6, "data.push({");
auteurPageJs.tl(7, "type: 'scattermapbox'");
auteurPageJs.tl(7, ", name: ", StringUtils.uncapitalize(classeNomSimple), ".", classeVarTitre);
auteurPageJs.tl(7, ", lat: lat");
auteurPageJs.tl(7, ", lon: lon");
auteurPageJs.tl(7, ", mode: 'lines+markers'");
auteurPageJs.tl(7, ", line:{");
auteurPageJs.tl(8, "width: 2,");
auteurPageJs.tl(8, "color: 'red'");
auteurPageJs.tl(7, "}");
auteurPageJs.tl(6, "});");
auteurPageJs.tl(6, ", \"geometry\": shape");
auteurPageJs.tl(5, "});");
// auteurPageJs.tl(5, "var parts = [];");
// auteurPageJs.tl(5, "if(shape.coordinates && shape.coordinates[0].length > 0 && Array.isArray(shape.coordinates[0][0]))");
// auteurPageJs.tl(6, "parts = parts.concat(shape.coordinates);");
// auteurPageJs.tl(5, "else");
// auteurPageJs.tl(6, "parts.push(shape.coordinates);");
// auteurPageJs.tl(5, "parts.forEach(part => {");
// auteurPageJs.tl(6, "var lat = part.map(elem => elem[0]);");
// auteurPageJs.tl(6, "var lon = part.map(elem => elem[1]);");
// auteurPageJs.tl(6, "if(shape.type == 'Polygon') {");
// auteurPageJs.tl(7, "lat.push(lat[0]);");
// auteurPageJs.tl(7, "lon.push(lon[0]);");
// auteurPageJs.tl(6, "}");
// auteurPageJs.tl(6, "data.push({");
// auteurPageJs.tl(7, "type: 'scattermapbox'");
// auteurPageJs.tl(7, ", name: ", StringUtils.uncapitalize(classeNomSimple), ".", classeVarTitre);
// auteurPageJs.tl(7, ", lat: lat");
// auteurPageJs.tl(7, ", lon: lon");
// auteurPageJs.tl(7, ", mode: 'lines+markers'");
// auteurPageJs.tl(7, ", line:{");
// auteurPageJs.tl(8, "width: 2,");
// auteurPageJs.tl(8, "color: 'red'");
// auteurPageJs.tl(7, "}");
// auteurPageJs.tl(6, "});");
// auteurPageJs.tl(5, "});");
auteurPageJs.tl(4, "});");
// auteurPageJs.tl(4, "}");
auteurPageJs.tl(3, "}");
auteurPageJs.tl(2, "});");
auteurPageJs.tl(2, "Plotly.react('htmBody", langueConfig.getString(ConfigCles.var_Graphique), langueConfig.getString(ConfigCles.var_Emplacement), classePageSuperNomSimple, "', data, layout);");
// auteurPageJs.tl(2, "Plotly.react(, data, layout);");
}
auteurPageJs.tl(1, "}");
auteurPageJs.tl(0, "}");
Expand Down
62 changes: 54 additions & 8 deletions src/main/java/org/computate/frFR/java/RegarderRepertoire.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ public static void main(String[] args) throws Exception {
YAMLConfiguration classeLangueConfig = configurations.fileBased(YAMLConfiguration.class, String.format("%s/src/main/resources/org/computate/i18n/i18n_%s.yml", appComputate, lang));
String SITE_NOM = System.getenv(classeLangueConfig.getString("var_SITE_NOM"));
String SITE_CHEMIN = System.getenv(classeLangueConfig.getString("var_SITE_CHEMIN"));
Boolean REGARDER = Boolean.parseBoolean(Optional.ofNullable(System.getenv(classeLangueConfig.getString("var_REGARDER"))).orElse("true"));

RegarderRepertoire regarderRepertoire = new RegarderRepertoire();
regarderRepertoire.langueNom = lang;
regarderRepertoire.SITE_NOM = SITE_NOM;
Expand All @@ -246,17 +248,22 @@ public static void main(String[] args) throws Exception {
regarderRepertoire.trace = true;
try {
regarderRepertoire.initialiserRegarderRepertoire(classeLangueConfig);
regarderRepertoire.ajouterCheminsARegarder(classeLangueConfig);
regarderRepertoire.ajouterCheminsARegarder(classeLangueConfig, REGARDER);

try {
indexerClasses(SITE_CHEMIN, classeLangueConfig);
indexerClasses(SITE_CHEMIN, classeLangueConfig);
indexerClasses(SITE_CHEMIN, classeLangueConfig);
if(REGARDER) {
indexerClasses(SITE_CHEMIN, classeLangueConfig);
indexerClasses(SITE_CHEMIN, classeLangueConfig);
indexerClasses(SITE_CHEMIN, classeLangueConfig);
regarderRepertoire.traiterEvenements();
} else {
indexerClasses(SITE_CHEMIN, classeLangueConfig);
indexerClasses(SITE_CHEMIN, classeLangueConfig);
indexerEcrireClasses(SITE_CHEMIN, classeLangueConfig);
}
} catch(Exception ex) {
System.out.println(String.format("Error indexing files on startup: %s", ex.getMessage()));
}

regarderRepertoire.traiterEvenements();
}
catch(Exception e) {
System.err.println("Erreur pendant traiterEvenements. ");
Expand All @@ -265,9 +272,43 @@ public static void main(String[] args) throws Exception {
}

public static void indexerClasses(String SITE_CHEMIN, YAMLConfiguration classeLangueConfig) throws Exception {
String classeLangueNom = StringUtils.defaultString(System.getenv("SITE_LANG"), "frFR");
File dir = new File(String.format("%s/src/main/java", SITE_CHEMIN));

try (Stream<Path> stream = Files.walk(Paths.get(dir.getAbsolutePath()))) {
stream.filter(Files::isRegularFile)
.filter(chemin -> chemin.toString().endsWith(".java"))
.filter(chemin -> {
try {
return !FileUtils.readFileToString(chemin.toFile(), "UTF-8").contains("* Translate: false");
} catch(Exception ex) {
return false;
}
})
.forEach(chemin -> {
String cheminStr = chemin.toString();
// System.out.println(String.format("%s %s", chemin.toString().endsWith(".java"), chemin.toString()));
RegarderClasse regarderClasse = new RegarderClasse();
try {
regarderClasse.setArgs(new String[] {SITE_CHEMIN, cheminStr});
regarderClasse.initRegarderClasseBase(classeLangueNom, classeLangueConfig);
SolrInputDocument classeDoc = new SolrInputDocument();
regarderClasse.indexerClasse(cheminStr, classeDoc, classeLangueNom);
System.out.println(String.format("%s %s", classeLangueConfig.getString(ConfigCles.var_Indexe), cheminStr));
} catch(Exception ex) {
System.err.println(String.format("An exception occured while indexing files: %s", ExceptionUtils.getStackTrace(ex)));
}
});
}
}


public static void indexerEcrireClasses(String SITE_CHEMIN, YAMLConfiguration classeLangueConfig) throws Exception {
String appComputate = System.getenv("COMPUTATE_SRC");
String classeLangueNom = StringUtils.defaultString(System.getenv("SITE_LANG"), "frFR");
File dir = new File(String.format("%s/src/main/java", SITE_CHEMIN));
Configurations configurations = new Configurations();

try (Stream<Path> stream = Files.walk(Paths.get(dir.getAbsolutePath()))) {
stream.filter(Files::isRegularFile)
.filter(chemin -> chemin.toString().endsWith(".java"))
Expand All @@ -287,6 +328,8 @@ public static void indexerClasses(String SITE_CHEMIN, YAMLConfiguration classeLa
regarderClasse.initRegarderClasseBase(classeLangueNom, classeLangueConfig);
SolrInputDocument classeDoc = new SolrInputDocument();
regarderClasse.indexerClasse(cheminStr, classeDoc, classeLangueNom);
YAMLConfiguration langueConfig = configurations.fileBased(YAMLConfiguration.class, String.format("%s/src/main/resources/org/computate/i18n/i18n_%s.yml", appComputate, classeLangueNom));
regarderClasse.ecrireGenClasses(regarderClasse.classeCheminAbsolu, classeLangueNom, classeLangueNom, langueConfig);
System.out.println(String.format("%s %s", classeLangueConfig.getString(ConfigCles.var_Indexe), cheminStr));
} catch(Exception ex) {
System.err.println(String.format("An exception occured while indexing files: %s", ExceptionUtils.getStackTrace(ex)));
Expand Down Expand Up @@ -383,11 +426,14 @@ public void initialiserRegarderRepertoire(YAMLConfiguration classeLangueConfig)
* r: Erreur à ajouter chemin pour regarder.
* r.enUS: Error adding path to watch.
*/
public void ajouterCheminsARegarder(YAMLConfiguration classeLangueConfig) {
public void ajouterCheminsARegarder(YAMLConfiguration classeLangueConfig, Boolean REGARDER) {
for(String cheminARegarder : cheminsARegarder) {
try {
chemins.add(enregistrerTout(Paths.get(cheminARegarder)));
LOG.info("{}: {}", classeLangueConfig.getString(ConfigCles.var_Regarder), cheminARegarder);
if(REGARDER)
LOG.info("{}: {}", classeLangueConfig.getString(ConfigCles.var_Regarder), cheminARegarder);
else
LOG.info("{}: {}", classeLangueConfig.getString(ConfigCles.var_Generer), cheminARegarder);
} catch (IOException e) {
LOG.error("Erreur à ajouter chemin pour regarder.", e);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/org/computate/i18n/i18n_enUS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ var_Fusion: "Merge"
var_Future: "Future"
var_gamme: "range"
var_Gamme: "Range"
var_Generer: "Generate"
var_generer: "generate"
var_gestionnaireEvenements: "eventHandler"
var_GestionnaireEvenements: "EventHandler"
Expand Down Expand Up @@ -587,6 +588,7 @@ var_RechercherTousNomPar: "SearchAllNameBy"
var_RechercherTousNom: "SearchAllName"
var_Recherche: "Search"
var_rechercheSolr: "solrQuery"
var_REGARDER: "WATCH"
var_Regarder: "Watch"
var_relations: "relations"
var_relier: "relate"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/org/computate/i18n/i18n_frFR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ var_Fusion: "Fusion"
var_Future: "Future"
var_gamme: "gamme"
var_Gamme: "Gamme"
var_Generer: "generer"
var_generer: "generer"
var_gestionnaireEvenements: "gestionnaireEvenements"
var_GestionnaireEvenements: "GestionnaireEvenements"
Expand Down Expand Up @@ -355,6 +356,7 @@ var_Rechercher: "Rechercher"
var_RechercherTousNomPar: "RechercherTousNomPar"
var_RechercherTousNom: "RechercherTousNom"
var_rechercheSolr: "rechercheSolr"
var_REGARDER: "REGARDER"
var_Regarder: "Regarder"
var_relations: "relations"
var_relier: "relier"
Expand Down

0 comments on commit 08864f7

Please sign in to comment.