Skip to content

Commit

Permalink
Merge pull request ScorpioBroker#558 from ScorpioBroker/bugfix-553
Browse files Browse the repository at this point in the history
Bugfix 553
ScorpioBroker authored Apr 29, 2024
2 parents 3a9b282 + 1bdcc65 commit 07b5c49
Showing 3 changed files with 133 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -476,18 +476,26 @@ public static MultiMap getHeadersForRemoteCallFromRegUpdate(List<Map<String, Obj
}
return result;
}

public static Uni<RestResponse<Object>> generateEntityResult(List<Object> contextHeader, Context context,
int acceptHeader, Object entity, String geometryProperty, String options, LanguageQueryTerm langQuery,
JsonLDService ldService,List<String> omitList,List<String> pickList) {
return generateEntityResult(contextHeader, context,acceptHeader, entity, geometryProperty, options, langQuery, ldService,omitList, pickList, false);
}
public static Uni<RestResponse<Object>> generateEntityResult(List<Object> contextHeader, Context context,
int acceptHeader, Object entity, String geometryProperty, String options, LanguageQueryTerm langQuery,
JsonLDService ldService,List<String> omitList,List<String> pickList,boolean forceList) {
return generateCompactedResult(contextHeader, context, acceptHeader, entity, geometryProperty, options,
langQuery, false, ldService).onItem().transform(resultBodyAndHeaders -> {
ResponseBuilder<Object> resp = RestResponseBuilderImpl.ok();
List<Tuple2<String, String>> headers = resultBodyAndHeaders.getItem2();
for (Tuple2<String, String> entry : headers) {
resp = resp.header(entry.getItem1(), entry.getItem2());
}
return resp.entity(processPickOmit(resultBodyAndHeaders.getItem1(),pickList,omitList)).build();
Object result = processPickOmit(resultBodyAndHeaders.getItem1(),pickList,omitList);
if (forceList){
forceList(result);
}
return resp.entity(result).build();
});
}
public static Object processPickOmit(Object object,List<String> pickList, List<String> omitList){
@@ -957,10 +965,14 @@ public static String getTriggerReason(int triggerReason) {
default -> null;
};
}

public static Uni<RestResponse<Object>> generateQueryResult(HttpServerRequest request, QueryResult queryResult,
String options, String geometryProperty, int acceptHeader, boolean count, int limit, LanguageQueryTerm lang,
Context context, JsonLDService ldService,List<String> omitList,List<String> pickList) {
return generateQueryResult(request,queryResult, options, geometryProperty, acceptHeader, count, limit, lang, context, ldService, omitList, pickList,false);
}
public static Uni<RestResponse<Object>> generateQueryResult(HttpServerRequest request, QueryResult queryResult,
String options, String geometryProperty, int acceptHeader, boolean count, int limit, LanguageQueryTerm lang,
Context context, JsonLDService ldService,List<String> omitList,List<String> pickList,boolean forceList) {
ResponseBuilder<Object> builder;
if (count) {
builder = RestResponseBuilderImpl.ok().header(NGSIConstants.COUNT_HEADER_RESULT, queryResult.getCount());
@@ -996,11 +1008,35 @@ public static Uni<RestResponse<Object>> generateQueryResult(HttpServerRequest re
for (Tuple2<String, String> entry : headers) {
myBuilder = myBuilder.header(entry.getItem1(), entry.getItem2());
}
return myBuilder.entity(processPickOmit(resultAndHeaders.getItem1(),pickList,omitList)).build();
Object result = processPickOmit(resultAndHeaders.getItem1(),pickList,omitList);
if(forceList){
forceList(result);
}
return myBuilder.entity(result).build();
});

}
public static void forceList(Object object){
if(object instanceof JsonArray jsonArray){
jsonArray.forEach(item -> {
if (item instanceof JsonObject jsonObject){
makeList(jsonObject);
}
});
}
else if (object instanceof JsonObject jsonObject) {
makeList(jsonObject);
}
}
public static void makeList(JsonObject jsonObject){

for(String key: jsonObject.fieldNames()){
if(!key.equals(NGSIConstants.JSON_LD_CONTEXT) && !key.equals(NGSIConstants.ID) && !key.equals(NGSIConstants.TYPE) && !key.equals(NGSIConstants.CREATEDAT) && !key.equals(NGSIConstants.QUERY_PARAMETER_MODIFIED_AT) && !key.equals(NGSIConstants.SCOPE) && !((jsonObject.getValue(key) instanceof List) || (jsonObject.getValue(key) instanceof JsonArray))){
Object tmp = jsonObject.getValue(key);
jsonObject.put(key, JsonArray.of(tmp));
}
}
}
public static NGSILDOperationResult handleWebResponse(HttpResponse<Buffer> response, Throwable failure,
Integer[] integers, RemoteHost remoteHost, int operationType, String entityId, Set<Attrib> attrs) {

Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ public Uni<RestResponse<Object>> queryTemporalEntities(HttpServerRequest request
lastNTBU, actualLimit, offset, count, localOnly, context, request)
.onItem().transformToUni(queryResult -> {
return HttpUtils.generateQueryResult(request, queryResult, finalOptions, geoproperty, acceptHeader,
count, actualLimit, languageQueryTerm, context, ldService,null,null);
count, actualLimit, languageQueryTerm, context, ldService,null,null,true);
});
}).onFailure().recoverWithItem(HttpUtils::handleControllerExceptions);
}
@@ -196,7 +196,7 @@ public Uni<RestResponse<Object>> retrieveTemporalEntity(HttpServerRequest reques
return historyQueryService.retrieveEntity(HttpUtils.getTenant(request), entityId, attrsQuery, aggrQuery,
tempQuery, lang, lastNTBU, localOnly, context).onItem().transformToUni(entity -> {
return HttpUtils.generateEntityResult(headerContext, context, acceptHeader, entity,
geometryProperty, finalOptionsString, null, ldService,null,null);
geometryProperty, finalOptionsString, null, ldService,null,null,true);
});
}).onFailure().recoverWithItem(HttpUtils::handleControllerExceptions);

Loading

0 comments on commit 07b5c49

Please sign in to comment.