Skip to content

Commit

Permalink
WIP converting from handlebars to Jinja
Browse files Browse the repository at this point in the history
  • Loading branch information
computate committed Jul 9, 2024
1 parent 43fbdb9 commit bf1bff0
Show file tree
Hide file tree
Showing 6 changed files with 1,555 additions and 1,677 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/computate/frFR/java/ConfigCles.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public class ConfigCles {
public static final String var_AucunNomTrouve = "var_AucunNomTrouve";
public static final String var_authRoleAdmin = "var_authRoleAdmin";
public static final String var_authRoleSuperAdmin = "var_authRoleSuperAdmin";
public static final String var_AUTH_ROLE_ADMIN = "var_AUTH_ROLE_ADMIN";
public static final String var_AUTH_PORTEE_ADMIN = "var_AUTH_PORTEE_ADMIN";
public static final String var_AUTH_PORTEE_SUPER_ADMIN = "var_AUTH_PORTEE_SUPER_ADMIN";
public static final String var_AUTH_ROLE_LIRE_REQUIS = "var_AUTH_ROLE_LIRE_REQUIS";
public static final String var_AUTH_ROLE_REQUIS = "var_AUTH_ROLE_REQUIS";
public static final String var_AUTH_POLITIQUE_GRANULEE = "var_AUTH_POLITIQUE_GRANULEE";
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/computate/frFR/java/ConfigSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -761,12 +761,6 @@ protected void _siteEcrireMethodes() throws Exception {
siteEcrireMethodes.addAll(o);
}

public String authRoleAdmin = null;

protected void _authRoleAdmin() throws Exception {
authRoleAdmin = langueConfigGlobale.getString(ConfigCles.var_AUTH_ROLE_ADMIN);
}

public Boolean authPolitiqueGranulee;
/**
**/
Expand Down Expand Up @@ -928,7 +922,6 @@ public void initConfigSite() throws Exception {
_customerProfileId9();
_customerProfileId10();
_siteEcrireMethodes();
_authRoleAdmin();
_authPolitiqueGranulee();
_ecrireApi();
_ecrireCommentaire();
Expand Down
39 changes: 29 additions & 10 deletions src/main/java/org/computate/frFR/java/EcrireApiClasse.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void ecrireGenApiService(String classeLangueNom) throws Exception {
auteurGenApiService.l("import io.vertx.ext.web.api.service.WebApiServiceGen;");
auteurGenApiService.l("import io.vertx.ext.web.api.service.ServiceRequest;");
auteurGenApiService.l("import io.vertx.ext.web.api.service.ServiceResponse;");
auteurGenApiService.l("import io.vertx.ext.web.templ.handlebars.HandlebarsTemplateEngine;");
auteurGenApiService.l("import com.hubspot.jinjava.Jinjava;");
auteurGenApiService.l("import io.vertx.core.WorkerExecutor;");
auteurGenApiService.l("import io.vertx.pgclient.PgPool;");
auteurGenApiService.l("import io.vertx.kafka.client.producer.KafkaProducer;");
Expand Down Expand Up @@ -373,7 +373,7 @@ public void ecrireApiServiceImpl(String classeLangueNom) throws Exception {
auteurApiServiceImpl.l("import io.vertx.pgclient.PgPool;");
auteurApiServiceImpl.l("import io.vertx.kafka.client.producer.KafkaProducer;");
if(classePage)
auteurApiServiceImpl.l("import io.vertx.ext.web.templ.handlebars.HandlebarsTemplateEngine;");
auteurApiServiceImpl.l("import com.hubspot.jinjava.Jinjava;");
// auteurGenApiService.l("import ", classeNomEnsemble, ".", classeNomSimple, "ApiServiceVertxEBProxy;");
auteurApiServiceImpl.l();
auteurApiServiceImpl.l("/**");
Expand Down Expand Up @@ -1751,6 +1751,7 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
String classePageNomSimpleMethode = classeDoc.getString("classePageNomSimple" + classeApiMethode + "_" + classeLangueNom + "_stored_string");
String classeApiOperationIdMethode = classeDoc.getString("classeApiOperationId" + classeApiMethode + "_" + classeLangueNom + "_stored_string");
String classeApiUriMethode = classeDoc.getString("classeApiUri" + classeApiMethode + "_" + classeLangueNom + "_stored_string");
String classeApiMethodeMethode = classeDoc.getString("classeApiMethode" + classeApiMethode + "_" + classeLangueNom + "_stored_string");
String classeApiTypeMedia200Methode = classeDoc.getString("classeApiTypeMedia200" + classeApiMethode + "_" + classeLangueNom + "_stored_string");
String classeApiTypeMediaRequeteMethode = classeDoc.getString("classeApiTypeMediaRequete" + classeApiMethode + "_" + classeLangueNom + "_stored_string");
String classePageLangueNom = classeDoc.getString("classePageLangueNom" + classeApiMethode + "_" + classeLangueNom + "_stored_string");
Expand Down Expand Up @@ -1808,8 +1809,16 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
tl(5, ".sendForm(MultiMap.caseInsensitiveMultiMap()");
tl(7, ".add(\"grant_type\", \"urn:ietf:params:oauth:grant-type:uma-ticket\")");
tl(7, ".add(\"audience\", config.getString(ComputateConfigKeys.AUTH_CLIENT))");
tl(7, ".add(\"response_mode\", \"decision\")");
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, \"", classeApiMethode, "\"))");
tl(7, ".add(\"response_mode\", \"permissions\")");
if(classeApiMethode.equals(classeApiMethodeMethode)) {
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, \"", classeApiMethode, "\"))");
} else {
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, config.getString(ComputateConfigKeys.", classeLangueConfig.getString(ConfigCles.var_AUTH_PORTEE_ADMIN), ")))");
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, config.getString(ComputateConfigKeys.", classeLangueConfig.getString(ConfigCles.var_AUTH_PORTEE_SUPER_ADMIN), ")))");
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, \"GET\"))");
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, \"POST\"))");
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, \"PATCH\"))");
}
tl(3, ").onFailure(ex -> {");
tl(4, "String msg = String.format(\"403 FORBIDDEN user %s to %s %s\", siteRequest.getUser().attributes().getJsonObject(\"accessToken\").getString(\"preferred_username\"), serviceRequest.getExtra().getString(\"method\"), serviceRequest.getExtra().getString(\"uri\"));");
tl(4, "eventHandler.handle(Future.succeededFuture(");
Expand All @@ -1824,7 +1833,8 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
tl(4, "));");
tl(3, "}).onSuccess(authorizationDecision -> {");
tl(4, "try {");
tl(5, "if(!authorizationDecision.bodyAsJsonObject().getBoolean(\"result\")) {");
tl(5, "JsonArray scopes = authorizationDecision.bodyAsJsonArray().stream().findFirst().map(decision -> ((JsonObject)decision).getJsonArray(\"scopes\")).orElse(new JsonArray());");
tl(5, "if(!scopes.contains(\"", classeApiMethodeMethode, "\")) {");
tl(6, "String msg = String.format(\"403 FORBIDDEN user %s to %s %s\", siteRequest.getUser().attributes().getJsonObject(\"accessToken\").getString(\"preferred_username\"), serviceRequest.getExtra().getString(\"method\"), serviceRequest.getExtra().getString(\"uri\"));");
tl(6, "eventHandler.handle(Future.succeededFuture(");
tl(7, "new ServiceResponse(403, \"FORBIDDEN\",");
Expand Down Expand Up @@ -1883,8 +1893,16 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
tl(5, ".sendForm(MultiMap.caseInsensitiveMultiMap()");
tl(7, ".add(\"grant_type\", \"urn:ietf:params:oauth:grant-type:uma-ticket\")");
tl(7, ".add(\"audience\", config.getString(ComputateConfigKeys.AUTH_CLIENT))");
tl(7, ".add(\"response_mode\", \"decision\")");
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, \"", classeApiMethode, "\"))");
tl(7, ".add(\"response_mode\", \"permissions\")");
if(classeApiMethode.equals(classeApiMethodeMethode)) {
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, \"", classeApiMethode, "\"))");
} else {
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, config.getString(ComputateConfigKeys.", classeLangueConfig.getString(ConfigCles.var_AUTH_PORTEE_ADMIN), ")))");
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, config.getString(ComputateConfigKeys.", classeLangueConfig.getString(ConfigCles.var_AUTH_PORTEE_SUPER_ADMIN), ")))");
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, \"GET\"))");
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, \"POST\"))");
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".CLASS_SIMPLE_NAME, \"PATCH\"))");
}
tl(3, ").onFailure(ex -> {");
tl(4, "String msg = String.format(\"403 FORBIDDEN user %s to %s %s\", siteRequest.getUser().attributes().getJsonObject(\"accessToken\").getString(\"preferred_username\"), serviceRequest.getExtra().getString(\"method\"), serviceRequest.getExtra().getString(\"uri\"));");
tl(4, "eventHandler.handle(Future.succeededFuture(");
Expand All @@ -1899,7 +1917,8 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
tl(4, "));");
tl(3, "}).onSuccess(authorizationDecision -> {");
tl(4, "try {");
tl(5, "if(!authorizationDecision.bodyAsJsonObject().getBoolean(\"result\")) {");
tl(5, "JsonArray scopes = authorizationDecision.bodyAsJsonArray().stream().findFirst().map(decision -> ((JsonObject)decision).getJsonArray(\"scopes\")).orElse(new JsonArray());");
tl(5, "if(!scopes.contains(\"", classeApiMethodeMethode, "\")) {");
tl(6, "String msg = String.format(\"403 FORBIDDEN user %s to %s %s\", siteRequest.getUser().attributes().getJsonObject(\"accessToken\").getString(\"preferred_username\"), serviceRequest.getExtra().getString(\"method\"), serviceRequest.getExtra().getString(\"uri\"));");
tl(6, "eventHandler.handle(Future.succeededFuture(");
tl(7, "new ServiceResponse(403, \"FORBIDDEN\",");
Expand Down Expand Up @@ -3123,7 +3142,7 @@ else if(classeApiMethode.equals(classeLangueConfig.getString(ConfigCles.var_PUTC
if(classePageNomCanoniqueMethode != null) {
l();
tl(1, "public String ", classeLangueConfig.getString(ConfigCles.var_template), classeApiMethode, classeNomSimple, "() {");
tl(2, "return Optional.ofNullable(config.getString(", classePartsConfigCles.nomSimple(classeLangueNom), ".TEMPLATE_PATH)).orElse(\"templates\") + \"/", classeLangueNom, "/", classePageNomSimpleMethode, "\";");
tl(2, "return \"/", classeLangueNom, "/", classePageNomSimpleMethode, ".htm\";");
t(1, "}");
}
l();
Expand Down Expand Up @@ -3167,7 +3186,7 @@ else if(classeApiMethode.contains(classeLangueConfig.getString(ConfigCles.var_Re
tl(3, "String pageTemplateUri = ", classeLangueConfig.getString(ConfigCles.var_template), classeApiMethode, classeNomSimple, "();");
tl(3, "String siteTemplatePath = config.getString(ComputateConfigKeys.TEMPLATE_PATH);");
tl(3, "Path resourceTemplatePath = Path.of(siteTemplatePath, pageTemplateUri);");
tl(3, "String template = siteTemplatePath == null ? Files.readString(resourceTemplatePath, Charset.forName(\"UTF-8\")) : Resources.toString(Resources.getResource(resourceTemplatePath.toString()), StandardCharsets.UTF_8);");
tl(3, "String template = siteTemplatePath == null ? Resources.toString(Resources.getResource(resourceTemplatePath.toString()), StandardCharsets.UTF_8) : Files.readString(resourceTemplatePath, Charset.forName(\"UTF-8\"));");
tl(3, classePageNomSimpleMethode, " page = new ", classePageNomSimpleMethode, "();");
tl(3, "MultiMap ", classeLangueConfig.getString(ConfigCles.var_requeteEnTetes), " = MultiMap.caseInsensitiveMultiMap();");
tl(3, classeLangueConfig.getString(ConfigCles.var_requeteSite), ".set", classeLangueConfig.getString(ConfigCles.var_RequeteEnTetes), "(", classeLangueConfig.getString(ConfigCles.var_requeteEnTetes), ");");
Expand Down
Loading

0 comments on commit bf1bff0

Please sign in to comment.