[New] Properly format Report to json, forwarding params to caller

This commit is contained in:
Robert von Burg 2022-02-24 15:31:50 +01:00
parent 99a817959f
commit 1bdd16984b
1 changed files with 11 additions and 11 deletions

View File

@ -2,6 +2,7 @@ package li.strolch.rest.endpoint;
import static java.util.Comparator.comparing; import static java.util.Comparator.comparing;
import static li.strolch.model.StrolchModelConstants.BAG_PARAMETERS; import static li.strolch.model.StrolchModelConstants.BAG_PARAMETERS;
import static li.strolch.model.StrolchModelConstants.TYPE_PARAMETERS;
import static li.strolch.report.ReportConstants.*; import static li.strolch.report.ReportConstants.*;
import static li.strolch.rest.StrolchRestfulConstants.PARAM_DATE_RANGE_SEL; import static li.strolch.rest.StrolchRestfulConstants.PARAM_DATE_RANGE_SEL;
import static li.strolch.rest.StrolchRestfulConstants.*; import static li.strolch.rest.StrolchRestfulConstants.*;
@ -33,6 +34,7 @@ import li.strolch.model.Resource;
import li.strolch.model.StrolchElement; import li.strolch.model.StrolchElement;
import li.strolch.model.StrolchRootElement; import li.strolch.model.StrolchRootElement;
import li.strolch.model.Tags; import li.strolch.model.Tags;
import li.strolch.model.json.StrolchRootElementToJsonVisitor;
import li.strolch.model.parameter.StringParameter; import li.strolch.model.parameter.StringParameter;
import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.privilege.model.Certificate; import li.strolch.privilege.model.Certificate;
@ -73,19 +75,17 @@ public class ReportResource {
realm = RestfulStrolchComponent.getInstance().getContainer().getRealm(cert).getRealm(); realm = RestfulStrolchComponent.getInstance().getContainer().getRealm(cert).getRealm();
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, realm, getContext())) { try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, realm, getContext())) {
List<Resource> reports = new ReportSearch(tx).search(tx).orderByName(false).toList();
// create final array StrolchRootElementToJsonVisitor visitor = new StrolchRootElementToJsonVisitor().flat().withoutVersion()
JsonArray array = new JsonArray(); .withoutObjectType().withoutPolicies().withoutStateVariables()
reports.forEach(res -> { .ignoreBags(BAG_JOINS, BAG_COLUMNS, BAG_ORDERING).ignoreBagByType(TYPE_FILTER).resourceHook(
JsonObject o = new JsonObject(); (reportRes, reportJ) -> reportJ.addProperty(PARAM_DATE_RANGE,
o.addProperty(Tags.Json.ID, res.getId()); reportRes.hasParameter(BAG_PARAMETERS, PARAM_DATE_RANGE_SEL)));
o.addProperty(Tags.Json.NAME, res.getName()); JsonArray result = new ReportSearch(tx).search(tx).orderByName(false)
o.addProperty(PARAM_DATE_RANGE, res.hasParameter(BAG_PARAMETERS, PARAM_DATE_RANGE_SEL)); .map(resource -> resource.accept(visitor)).asStream()
array.add(o); .collect(JsonArray::new, JsonArray::add, JsonArray::addAll);
});
return ResponseUtil.toResponse(DATA, array); return ResponseUtil.toResponse(DATA, result);
} }
} }