Skip to content

Commit

Permalink
Fixing integration with FIWARE context broker
Browse files Browse the repository at this point in the history
  • Loading branch information
computate committed Jan 16, 2025
1 parent 092a6dd commit fff1ffd
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 35 deletions.
32 changes: 32 additions & 0 deletions src/main/java/org/computate/frFR/java/ConfigSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,36 @@ protected void _clientSolrFiware() throws Exception {
clientSolrFiware = new HttpSolrClient.Builder(solrUrlFiware).withHttpClient(httpClient).build();
}

public String ngsildTenantEnv;

public String getNgsildTenantEnv() {
return ngsildTenantEnv;
}

public void setNgsildTenantEnv(String ngsildTenantEnv) {
this.ngsildTenantEnv = ngsildTenantEnv;
}

protected void _ngsildTenantEnv() throws Exception {
ngsildTenantEnv = StringUtils.defaultIfBlank(config
.getString(langueConfigGlobale.getString(I18n.var_NGSILD_TENANT_ENV)), null);
}

public String ngsildCheminEnv;

public String getNgsildCheminEnv() {
return ngsildCheminEnv;
}

public void setNgsildCheminEnv(String ngsildCheminEnv) {
this.ngsildCheminEnv = ngsildCheminEnv;
}

protected void _ngsildCheminEnv() throws Exception {
ngsildCheminEnv = StringUtils.defaultIfBlank(config
.getString(langueConfigGlobale.getString(I18n.var_NGSILD_CHEMIN_ENV)), null);
}

/**
* Var.enUS: sourcePaths enUS: The absolute paths to source code directories in
* the app to watch for changes.
Expand Down Expand Up @@ -1000,6 +1030,8 @@ public void initConfigSite() throws Exception {
_solrUrlFiware();
_clientSolrComputate();
_clientSolrFiware();
_ngsildTenantEnv();
_ngsildCheminEnv();
_cheminsSource();
_toutCheminsSource();
_nomsMethodeTest();
Expand Down
138 changes: 106 additions & 32 deletions src/main/java/org/computate/frFR/java/EcrireApiClasse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3203,31 +3203,94 @@ else if(classeApiMethode.contains("PATCH")) {
tl(3, "pgPool.withTransaction(", i18nGlobale.getString(I18n.var_connexionSql), " -> {");
tl(4, i18nGlobale.getString(I18n.var_requeteSite), ".set", i18nGlobale.getString(I18n.var_ConnexionSql), "(", i18nGlobale.getString(I18n.var_connexionSql), ");");
tl(4, "vars", classeNomSimple, "(", i18nGlobale.getString(I18n.var_requeteSite), ").onSuccess(a -> {");
tl(5, "sql", classeApiMethode, classeNomSimple, "(o, ", classeVarInheritClePrimaire, ").onSuccess(", uncapitalizeClasseNomSimple, " -> {");
tl(6, i18nGlobale.getString(I18n.var_definir), classeNomSimple, "(", uncapitalizeClasseNomSimple, ", true).onSuccess(c -> {");
tl(7, i18nGlobale.getString(I18n.var_attribuer), classeNomSimple, "(", uncapitalizeClasseNomSimple, ").onSuccess(d -> {");
tl(8, i18nGlobale.getString(I18n.var_indexer), classeNomSimple, "(", uncapitalizeClasseNomSimple, ").onSuccess(o2 -> {");
tl(9, "if(", i18nGlobale.getString(I18n.var_requeteApi), " != null) {");
tl(10, i18nGlobale.getString(I18n.var_requeteApi), ".setNumPATCH(", i18nGlobale.getString(I18n.var_requeteApi), ".getNumPATCH() + 1);");
tl(10, "if(", i18nGlobale.getString(I18n.var_requeteApi), ".getNumFound() == 1L && Optional.ofNullable(", i18nGlobale.getString(I18n.var_requeteSite), ".getJsonObject()).map(json -> json.size() > 0).orElse(false)) {");
tl(11, "o", classeSauvegarde ? "2" : "", ".", i18nGlobale.getString(I18n.var_requeteApi), classeNomSimple, "();");
tl(11, "if(", i18nGlobale.getString(I18n.var_requeteApi), ".getVars().size() > 0)");
tl(12, "eventBus.publish(\"websocket", classeNomSimple, "\", JsonObject.mapFrom(", i18nGlobale.getString(I18n.var_requeteApi), ").toString());");
tl(10, "}");
tl(9, "}");
tl(9, "promise1.complete(", uncapitalizeClasseNomSimple, ");");
tl(8, "}).onFailure(ex -> {");
tl(9, "promise1.fail(ex);");
tl(8, "});");
tl(7, "}).onFailure(ex -> {");
tl(8, "promise1.fail(ex);");
tl(7, "});");
tl(6, "}).onFailure(ex -> {");
tl(7, "promise1.fail(ex);");
tl(6, "});");
tl(5, "}).onFailure(ex -> {");
tl(6, "promise1.fail(ex);");
tl(5, "});");
if(activerContextBroker && classeFiware) {
tl(5, "JsonObject jsonObject = o.getSiteRequest_().getJsonObject();");
tl(5, "if(jsonObject.isEmpty()) {");
tl(6, "ngsildGetEntity(o).onSuccess(ngsildData -> {");
tl(7, "String setNgsildData = String.format(\"set%s\",StringUtils.capitalize(", classeNomSimple, ".VAR_ngsildData));");
tl(7, "jsonObject.put(setNgsildData, ngsildData);");
tl(7, "sql", classeApiMethode, classeNomSimple, "(o, ", classeVarInheritClePrimaire, ").onSuccess(", uncapitalizeClasseNomSimple, " -> {");
tl(8, i18nGlobale.getString(I18n.var_definir), classeNomSimple, "(", uncapitalizeClasseNomSimple, ", true).onSuccess(c -> {");
tl(9, i18nGlobale.getString(I18n.var_attribuer), classeNomSimple, "(", uncapitalizeClasseNomSimple, ").onSuccess(d -> {");
tl(10, i18nGlobale.getString(I18n.var_indexer), classeNomSimple, "(", uncapitalizeClasseNomSimple, ").onSuccess(o2 -> {");
tl(11, "if(", i18nGlobale.getString(I18n.var_requeteApi), " != null) {");
tl(12, i18nGlobale.getString(I18n.var_requeteApi), ".setNumPATCH(", i18nGlobale.getString(I18n.var_requeteApi), ".getNumPATCH() + 1);");
tl(12, "if(", i18nGlobale.getString(I18n.var_requeteApi), ".getNumFound() == 1L && Optional.ofNullable(", i18nGlobale.getString(I18n.var_requeteSite), ".getJsonObject()).map(json -> json.size() > 0).orElse(false)) {");
tl(13, "o", classeSauvegarde ? "2" : "", ".", i18nGlobale.getString(I18n.var_requeteApi), classeNomSimple, "();");
tl(13, "if(", i18nGlobale.getString(I18n.var_requeteApi), ".getVars().size() > 0)");
tl(14, "eventBus.publish(\"websocket", classeNomSimple, "\", JsonObject.mapFrom(", i18nGlobale.getString(I18n.var_requeteApi), ").toString());");
tl(12, "}");
tl(11, "}");
tl(11, "promise1.complete(", uncapitalizeClasseNomSimple, ");");
tl(10, "}).onFailure(ex -> {");
tl(11, "promise1.fail(ex);");
tl(10, "});");
tl(9, "}).onFailure(ex -> {");
tl(10, "promise1.fail(ex);");
tl(9, "});");
tl(8, "}).onFailure(ex -> {");
tl(9, "promise1.fail(ex);");
tl(8, "});");
tl(7, "}).onFailure(ex -> {");
tl(8, "promise1.fail(ex);");
tl(7, "});");
tl(6, "}).onFailure(ex -> {");
tl(7, "promise1.fail(ex);");
tl(6, "});");
tl(5, "} else {");
tl(6, "sql", classeApiMethode, classeNomSimple, "(o, ", classeVarInheritClePrimaire, ").onSuccess(", uncapitalizeClasseNomSimple, " -> {");
tl(7, i18nGlobale.getString(I18n.var_definir), classeNomSimple, "(", uncapitalizeClasseNomSimple, ", true).onSuccess(c -> {");
tl(8, i18nGlobale.getString(I18n.var_attribuer), classeNomSimple, "(", uncapitalizeClasseNomSimple, ").onSuccess(d -> {");
tl(9, i18nGlobale.getString(I18n.var_indexer), classeNomSimple, "(", uncapitalizeClasseNomSimple, ").onSuccess(o2 -> {");
tl(10, "if(", i18nGlobale.getString(I18n.var_requeteApi), " != null) {");
tl(11, i18nGlobale.getString(I18n.var_requeteApi), ".setNumPATCH(", i18nGlobale.getString(I18n.var_requeteApi), ".getNumPATCH() + 1);");
tl(11, "if(", i18nGlobale.getString(I18n.var_requeteApi), ".getNumFound() == 1L && Optional.ofNullable(", i18nGlobale.getString(I18n.var_requeteSite), ".getJsonObject()).map(json -> json.size() > 0).orElse(false)) {");
tl(12, "o", classeSauvegarde ? "2" : "", ".", i18nGlobale.getString(I18n.var_requeteApi), classeNomSimple, "();");
tl(12, "if(", i18nGlobale.getString(I18n.var_requeteApi), ".getVars().size() > 0)");
tl(13, "eventBus.publish(\"websocket", classeNomSimple, "\", JsonObject.mapFrom(", i18nGlobale.getString(I18n.var_requeteApi), ").toString());");
tl(11, "}");
tl(10, "}");
tl(10, "promise1.complete(", uncapitalizeClasseNomSimple, ");");
tl(9, "}).onFailure(ex -> {");
tl(10, "promise1.fail(ex);");
tl(9, "});");
tl(8, "}).onFailure(ex -> {");
tl(9, "promise1.fail(ex);");
tl(8, "});");
tl(7, "}).onFailure(ex -> {");
tl(8, "promise1.fail(ex);");
tl(7, "});");
tl(6, "}).onFailure(ex -> {");
tl(7, "promise1.fail(ex);");
tl(6, "});");
tl(5, "}");
} else {
tl(5, "sql", classeApiMethode, classeNomSimple, "(o, ", classeVarInheritClePrimaire, ").onSuccess(", uncapitalizeClasseNomSimple, " -> {");
tl(6, i18nGlobale.getString(I18n.var_definir), classeNomSimple, "(", uncapitalizeClasseNomSimple, ", true).onSuccess(c -> {");
tl(7, i18nGlobale.getString(I18n.var_attribuer), classeNomSimple, "(", uncapitalizeClasseNomSimple, ").onSuccess(d -> {");
tl(8, i18nGlobale.getString(I18n.var_indexer), classeNomSimple, "(", uncapitalizeClasseNomSimple, ").onSuccess(o2 -> {");
tl(9, "if(", i18nGlobale.getString(I18n.var_requeteApi), " != null) {");
tl(10, i18nGlobale.getString(I18n.var_requeteApi), ".setNumPATCH(", i18nGlobale.getString(I18n.var_requeteApi), ".getNumPATCH() + 1);");
tl(10, "if(", i18nGlobale.getString(I18n.var_requeteApi), ".getNumFound() == 1L && Optional.ofNullable(", i18nGlobale.getString(I18n.var_requeteSite), ".getJsonObject()).map(json -> json.size() > 0).orElse(false)) {");
tl(11, "o", classeSauvegarde ? "2" : "", ".", i18nGlobale.getString(I18n.var_requeteApi), classeNomSimple, "();");
tl(11, "if(", i18nGlobale.getString(I18n.var_requeteApi), ".getVars().size() > 0)");
tl(12, "eventBus.publish(\"websocket", classeNomSimple, "\", JsonObject.mapFrom(", i18nGlobale.getString(I18n.var_requeteApi), ").toString());");
tl(10, "}");
tl(9, "}");
tl(9, "promise1.complete(", uncapitalizeClasseNomSimple, ");");
tl(8, "}).onFailure(ex -> {");
tl(9, "promise1.fail(ex);");
tl(8, "});");
tl(7, "}).onFailure(ex -> {");
tl(8, "promise1.fail(ex);");
tl(7, "});");
tl(6, "}).onFailure(ex -> {");
tl(7, "promise1.fail(ex);");
tl(6, "});");
tl(5, "}).onFailure(ex -> {");
tl(6, "promise1.fail(ex);");
tl(5, "});");
}
tl(4, "}).onFailure(ex -> {");
tl(5, "promise1.fail(ex);");
tl(4, "});");
Expand Down Expand Up @@ -3418,7 +3481,16 @@ else if(classeApiMethode.contains("PATCH")) {
tl(3, "}));");
tl(3, "CompositeFuture.all(futures1).onSuccess(a -> {");
tl(4, "CompositeFuture.all(futures2).onSuccess(b -> {");
tl(5, "promise.complete();");
if(activerContextBroker && classeFiware) {
tl(5, "cbDeleteEntity(o).onSuccess(c -> {");
tl(6, "promise.complete();");
tl(5, "}).onFailure(ex -> {");
tl(6, "LOG.error(String.format(\"sql", classeApiMethode, classeNomSimple, " ", i18nGlobale.getString(I18n.str_a_échoué), ". \"), ex);");
tl(6, "promise.fail(ex);");
tl(5, "});");
} else {
tl(5, "promise.complete();");
}
tl(4, "}).onFailure(ex -> {");
tl(5, "LOG.error(String.format(\"sql", classeApiMethode, classeNomSimple, " ", i18nGlobale.getString(I18n.str_a_échoué), ". \"), ex);");
tl(5, "promise.fail(ex);");
Expand Down Expand Up @@ -4425,13 +4497,15 @@ public void ecrireGenApiServiceImpl3(String classeLangueNom) throws Exception {
tl(3, "for (String var : vars) {");
tl(4, "String ngsiType = ", classeNomSimple, ".ngsiType(var);");
tl(4, "String displayName = Optional.ofNullable(", classeNomSimple, ".displayName", classeNomSimple, "(var)).orElse(var);");
tl(4, "if (ngsiType != null && displayName != null && !var.equals(\"ngsildData\")) {");
tl(4, "if (ngsiType != null && displayName != null && !var.equals(\"id\") && !var.equals(\"ngsildData\")) {");
tl(5, "Object value = o.obtainForClass(var);");
tl(5, "if(value != null) {");
tl(6, "Object ngsildVal = ", classeNomSimple, ".ngsi", classeNomSimple, "(var, o);");
tl(6, "String ngsildType = ", classeNomSimple, ".ngsiType(var);");
tl(6, "entityBody.put(displayName");
tl(8, ", new JsonObject()");
tl(8, ".put(\"type\", \"Property\")");
tl(8, ".put(\"value\", value)");
tl(8, ".put(\"type\", ngsildType)");
tl(8, ".put(\"value\", ngsildVal)");
tl(8, ".put(\"observedAt\", observedAtStr)");
tl(8, ");");
tl(5, "}");
Expand Down Expand Up @@ -4469,9 +4543,9 @@ public void ecrireGenApiServiceImpl3(String classeLangueNom) throws Exception {
tl(2, "try {");
tl(3, "String entityName = o.getName();");
tl(3, "String entityType = ", classeNomSimple, ".CLASS_SIMPLE_NAME;");
tl(3, "String entityId = o.getEntityId();");
tl(3, "String entityId = o.getId();");
tl(3, "String ngsildUri = String.format(\"/ngsi-ld/v1/entities/%s\", urlEncode(entityId));");
tl(3, "String ngsildContext = o.getNgsildContext();");
tl(3, "String ngsildContext = config.getString(ComputateConfigKeys.CONTEXT_BROKER_CONTEXT);");
tl(3, "String link = String.format(\"<%s>; rel=\\\"http://www.w3.org/ns/json-ld#context\\\"; type=\\\"application/ld+json\\\"\", ngsildContext);");
l();
tl(3, "webClient.get(");
Expand Down Expand Up @@ -4509,7 +4583,7 @@ public void ecrireGenApiServiceImpl3(String classeLangueNom) throws Exception {
tl(3, "webClient.delete(");
tl(5, "config.getInteger(ComputateConfigKeys.CONTEXT_BROKER_PORT)");
tl(5, ", config.getString(ComputateConfigKeys.CONTEXT_BROKER_HOST_NAME)");
tl(5, ", String.format(\"/ngsi-ld/v1/entities/%s\", urlEncode(o.getEntityId()))");
tl(5, ", String.format(\"/ngsi-ld/v1/entities/%s\", urlEncode(o.getId()))");
tl(5, ")");
tl(5, ".ssl(config.getBoolean(ComputateConfigKeys.CONTEXT_BROKER_SSL))");
tl(5, ".putHeader(\"Content-Type\", \"application/ld+json\")");
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/computate/frFR/java/EcrireGenClasse.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ public class EcrireGenClasse extends EcrireClasse {
protected ToutEcrivain wClasseNomSimpleMethode;
protected ToutEcrivain wDescriptionMethode;
protected ToutEcrivain wNgsiTypeMethode;
protected ToutEcrivain wNgsiMethode;
protected ToutEcrivain wHtmColonneMethode;
protected ToutEcrivain wHtmLigneMethode;
protected ToutEcrivain wHtmCelluleMethode;
Expand Down Expand Up @@ -1350,6 +1351,7 @@ public void genCodeInit() throws Exception {
wClasseNomSimpleMethode = ToutEcrivain.create();
wDescriptionMethode = ToutEcrivain.create();
wNgsiTypeMethode = ToutEcrivain.create();
wNgsiMethode = ToutEcrivain.create();
wHtmColonneMethode = ToutEcrivain.create();
wHtmLigneMethode = ToutEcrivain.create();
wHtmCelluleMethode = ToutEcrivain.create();
Expand Down Expand Up @@ -3529,9 +3531,11 @@ else if("td".equals(element))
tl(1, "@JsonIgnore");
else if("JsonArray".equals(entiteNomSimple)) {
tl(1, "@JsonProperty");
tl(1, "@JsonDeserialize(using = ", classePartsJsonArrayDeserializer.nomSimple(langueNom), ".class)");
}
else if("JsonObject".equals(entiteNomSimple)) {
tl(1, "@JsonProperty");
tl(1, "@JsonDeserialize(using = ", classePartsJsonObjectDeserializer.nomSimple(langueNom), ".class)");
}
else if("Point".equals(entiteNomSimple)) {
tl(1, "@JsonProperty");
Expand Down Expand Up @@ -5546,6 +5550,21 @@ else if(entiteIndexe
if(entiteNgsiType != null) {
wNgsiTypeMethode.tl(2, "case VAR_", entiteVar, ":");
wNgsiTypeMethode.tl(3, "return \"", StringEscapeUtils.escapeJava(entiteNgsiType), "\";");

wNgsiMethode.tl(2, "case VAR_", entiteVar, ":");
if("Point".equals(entiteNomSimple)) {
wNgsiMethode.tl(3, "return new JsonObject().put(\"type\", \"Point\").put(\"coordinates\", new JsonArray().add(Double.valueOf(o.get", entiteVarCapitalise, "().getX())).add(Double.valueOf(o.get", entiteVarCapitalise, "().getY()))).toString();");
} else if("Path".equals(entiteNomSimple)) {
wNgsiMethode.tl(3, "JsonArray pointsArray", entiteVarCapitalise, " = new JsonArray();");
wNgsiMethode.tl(3, "o.get", entiteVarCapitalise, "().getPoints().stream().map(point -> new JsonArray().add(Double.valueOf(point.getX())).add(Double.valueOf(point.getY()))).collect(Collectors.toList()).forEach(pointArray -> pointsArray", entiteVarCapitalise, ".add(pointArray));");
wNgsiMethode.tl(3, "return new JsonObject().put(\"type\", \"LineString\").put(\"coordinates\", pointsArray", entiteVarCapitalise, ").toString();");
} else if("Polygon".equals(entiteNomSimple)) {
wNgsiMethode.tl(3, "JsonArray pointsArray", entiteVarCapitalise, " = new JsonArray();");
wNgsiMethode.tl(3, "o.get", entiteVarCapitalise, "().getPoints().stream().map(point -> new JsonArray().add(Double.valueOf(point.getX())).add(Double.valueOf(point.getY()))).collect(Collectors.toList()).forEach(pointArray -> pointsArray", entiteVarCapitalise, ".add(pointArray));");
wNgsiMethode.tl(3, "return new JsonObject().put(\"type\", \"LineString\").put(\"coordinates\", pointsArray", entiteVarCapitalise, ").toString();");
} else {
wNgsiMethode.tl(3, "return o.get", entiteVarCapitalise, "();");
}
}
if(entiteNomSimple != null) {
wClasseNomSimpleMethode.tl(2, "case VAR_", entiteVar, ":");
Expand Down Expand Up @@ -5752,6 +5771,7 @@ public void genCodeClasseFin(String langueNom, JsonObject langueConfig) throws E
wNomAffichageMethode.flushClose();
wDescriptionMethode.flushClose();
wNgsiTypeMethode.flushClose();
wNgsiMethode.flushClose();
wClasseNomSimpleMethode.flushClose();
wHtmColonneMethode.flushClose();
wHtmLigneMethode.flushClose();
Expand Down Expand Up @@ -6427,6 +6447,14 @@ public void genCodeClasseFin(String langueNom, JsonObject langueConfig) throws E
tl(4, "return null;");
tl(2, "}");
tl(1, "}");
l();
tl(1, "public static Object ngsi", classeNomSimple, "(String var, ", classeNomSimple, " o) {");
tl(2, "switch(var) {");
s(wNgsiMethode);
tl(3, "default:");
tl(4, "return null;");
tl(2, "}");
tl(1, "}");
}

/////////////////
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/computate/frFR/java/EcrirePageClasse.java
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ public void pageCodeClasseJava(String langueNom, JsonObject langueConfig) throws
wWebsocketInput3.tl(4, "if(input", entiteVarCapitalise, ") {");
wWebsocketInput3.tl(5, "document.querySelectorAll('.Page_", entiteVar, "').forEach((item, index) => {");
wWebsocketInput3.tl(6, "if(typeof item.value !== 'undefined')");
wWebsocketInput3.tl(7, "item.setAttribute('value', input", entiteVarCapitalise, ".getAttribute('value'));");
wWebsocketInput3.tl(7, "item.value = input", entiteVarCapitalise, ".getAttribute('value');");
wWebsocketInput3.tl(6, "else");
wWebsocketInput3.tl(7, "item.textContent = input", entiteVarCapitalise, ".textContent;");
wWebsocketInput3.tl(5, "});");
Expand Down Expand Up @@ -3551,7 +3551,6 @@ else if(entiteAttribuer) {
// auteurPageJs.tl(3, langueConfig.getString(ConfigCles.var_rechercher), langueConfig.getString(ConfigCles.var_Page), "();");
auteurPageJs.tl(3, "var json = JSON.parse(message['body']);");
auteurPageJs.tl(3, "var ", classeVarId, " = json['id'];");
auteurPageJs.tl(3, "var ", classeVarId, "Page = document.querySelector('#", i18nPage.getString(I18n.var_Page), "_", classeVarId, "')?.value;");
auteurPageJs.tl(3, "var ", classeVarClePrimairePluriel, " = json['", classeVarClePrimairePluriel, "'];");
auteurPageJs.tl(3, "var empty = json['empty'];");
// auteurPageJs.tl(3, "if(!empty) {");
Expand Down Expand Up @@ -3613,7 +3612,7 @@ else if(entiteAttribuer) {
auteurPageJs.tl(3, "} else {");
auteurPageJs.tl(4, "document.querySelector('.box-' + ", classeVarId, ")?.remove();");
auteurPageJs.tl(3, "}");
auteurPageJs.tl(3, "if(", classeVarId, " && ", classeVarId, "Page && ", classeVarId, " == ", classeVarId, "Page) {");
auteurPageJs.tl(3, "if(", classeVarId, ") {");
auteurPageJs.tl(4, "if(success)");
auteurPageJs.tl(5, "success(json);");
auteurPageJs.tl(3, "}");
Expand Down
Loading

0 comments on commit fff1ffd

Please sign in to comment.