Skip to content

Commit 2330a73

Browse files
committed
Option for sending context broker data
1 parent 8899b14 commit 2330a73

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

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

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,10 +3209,19 @@ else if(classeApiMethode.contains("PATCH")) {
32093209
tl(4, "vars", classeNomSimple, "(", i18nGlobale.getString(I18n.var_requeteSite), ").onSuccess(a -> {");
32103210
if(activerContextBroker && classeFiware) {
32113211
tl(5, "JsonObject jsonObject = o.getSiteRequest_().getJsonObject();");
3212-
tl(5, "if(jsonObject.isEmpty()) {");
3213-
tl(6, "ngsildGetEntity(o).onSuccess(ngsildData -> {");
3214-
tl(7, "String setNgsildData = String.format(\"set%s\",StringUtils.capitalize(", classeNomSimple, ".VAR_ngsildData));");
3215-
tl(7, "jsonObject.put(setNgsildData, ngsildData);");
3212+
tl(5, "if(config.getBoolean(ComputateConfigKeys.", i18nGlobale.getString(I18n.var_ACTIVER_CONTEXT_BROKER_ENVOI), ")) {");
3213+
tl(6, "ngsildGetEntity(o).compose(ngsildData -> {");
3214+
tl(7, "Promise<JsonObject> promise2 = Promise.promise();");
3215+
tl(7, "if(ngsildData == null) {");
3216+
tl(8, "promise2.complete(jsonObject);");
3217+
tl(7, "} else {");
3218+
tl(8, "String setNgsildData = String.format(\"set%s\",StringUtils.capitalize(", classeNomSimple, ".VAR_ngsildData));");
3219+
tl(8, "jsonObject.put(setNgsildData, ngsildData);");
3220+
tl(8, "promise2.complete(jsonObject);");
3221+
tl(7, "}");
3222+
tl(7, "return promise2.future();");
3223+
tl(6, "}).compose(ngsildData -> {");
3224+
tl(7, "Promise<", classeApiClasseNomSimple, "> promise2 = Promise.promise();");
32163225
tl(7, "sql", classeApiMethode, classeNomSimple, "(o, ", classeVarInheritClePrimaire, ").onSuccess(", uncapitalizeClasseNomSimple, " -> {");
32173226
tl(8, i18nGlobale.getString(I18n.var_definir), classeNomSimple, "(", uncapitalizeClasseNomSimple, ", true).onSuccess(c -> {");
32183227
tl(9, i18nGlobale.getString(I18n.var_attribuer), classeNomSimple, "(", uncapitalizeClasseNomSimple, ").onSuccess(d -> {");
@@ -3225,19 +3234,22 @@ else if(classeApiMethode.contains("PATCH")) {
32253234
tl(14, "eventBus.publish(\"websocket", classeNomSimple, "\", JsonObject.mapFrom(", i18nGlobale.getString(I18n.var_requeteApi), ").toString());");
32263235
tl(12, "}");
32273236
tl(11, "}");
3228-
tl(11, "promise1.complete(", uncapitalizeClasseNomSimple, ");");
3237+
tl(11, "promise2.complete(", uncapitalizeClasseNomSimple, ");");
32293238
tl(10, "}).onFailure(ex -> {");
3230-
tl(11, "promise1.fail(ex);");
3239+
tl(11, "promise2.fail(ex);");
32313240
tl(10, "});");
32323241
tl(9, "}).onFailure(ex -> {");
3233-
tl(10, "promise1.fail(ex);");
3242+
tl(10, "promise2.fail(ex);");
32343243
tl(9, "});");
32353244
tl(8, "}).onFailure(ex -> {");
3236-
tl(9, "promise1.fail(ex);");
3245+
tl(9, "promise2.fail(ex);");
32373246
tl(8, "});");
32383247
tl(7, "}).onFailure(ex -> {");
3239-
tl(8, "promise1.fail(ex);");
3248+
tl(8, "promise2.fail(ex);");
32403249
tl(7, "});");
3250+
tl(7, "return promise2.future();");
3251+
tl(6, "}).onSuccess(o2 -> {");
3252+
tl(7, "promise1.complete(o2);");
32413253
tl(6, "}).onFailure(ex -> {");
32423254
tl(7, "promise1.fail(ex);");
32433255
tl(6, "});");
@@ -3486,12 +3498,16 @@ else if(classeApiMethode.contains("PATCH")) {
34863498
tl(3, "CompositeFuture.all(futures1).onSuccess(a -> {");
34873499
tl(4, "CompositeFuture.all(futures2).onSuccess(b -> {");
34883500
if(activerContextBroker && classeFiware) {
3489-
tl(5, "cbDeleteEntity(o).onSuccess(c -> {");
3501+
tl(5, "if(config.getBoolean(ComputateConfigKeys.", i18nGlobale.getString(I18n.var_ACTIVER_CONTEXT_BROKER_ENVOI), ")) {");
3502+
tl(6, "cbDeleteEntity(o).onSuccess(c -> {");
3503+
tl(7, "promise.complete();");
3504+
tl(6, "}).onFailure(ex -> {");
3505+
tl(7, "LOG.error(String.format(\"sql", classeApiMethode, classeNomSimple, " ", i18nGlobale.getString(I18n.str_a_échoué), ". \"), ex);");
3506+
tl(7, "promise.fail(ex);");
3507+
tl(6, "});");
3508+
tl(5, "} else {");
34903509
tl(6, "promise.complete();");
3491-
tl(5, "}).onFailure(ex -> {");
3492-
tl(6, "LOG.error(String.format(\"sql", classeApiMethode, classeNomSimple, " ", i18nGlobale.getString(I18n.str_a_échoué), ". \"), ex);");
3493-
tl(6, "promise.fail(ex);");
3494-
tl(5, "});");
3510+
tl(5, "}");
34953511
} else {
34963512
tl(5, "promise.complete();");
34973513
}
@@ -4400,12 +4416,16 @@ public void ecrireGenApiServiceImpl3(String classeLangueNom) throws Exception {
44004416
tl(5, "}");
44014417
tl(5, "o.", i18nGlobale.getString(I18n.var_promesseLoin), i18nGlobale.getString(I18n.var_PourClasse), "(", i18nGlobale.getString(I18n.var_requeteSite), ").onSuccess(a -> {");
44024418
if(activerContextBroker && classeFiware) {
4403-
tl(6, "cbUpsertEntity(o, patch).onSuccess(b -> {");
4419+
tl(6, "if(config.getBoolean(ComputateConfigKeys.", i18nGlobale.getString(I18n.var_ACTIVER_CONTEXT_BROKER_ENVOI), ")) {");
4420+
tl(7, "cbUpsertEntity(o, patch).onSuccess(b -> {");
4421+
tl(8, "promise.complete();");
4422+
tl(7, "}).onFailure(ex -> {");
4423+
tl(8, "LOG.error(String.format(\"", i18nGlobale.getString(I18n.var_definir), classeNomSimple, " ", i18nGlobale.getString(I18n.str_a_échoué), ". \"), ex);");
4424+
tl(8, "promise.fail(ex);");
4425+
tl(7, "});");
4426+
tl(6, "} else {");
44044427
tl(7, "promise.complete();");
4405-
tl(6, "}).onFailure(ex -> {");
4406-
tl(7, "LOG.error(String.format(\"", i18nGlobale.getString(I18n.var_definir), classeNomSimple, " ", i18nGlobale.getString(I18n.str_a_échoué), ". \"), ex);");
4407-
tl(7, "promise.fail(ex);");
4408-
tl(6, "});");
4428+
tl(6, "}");
44094429
} else {
44104430
tl(6, "promise.complete();");
44114431
}

0 commit comments

Comments
 (0)