[Minor] Added realm to report resource
This commit is contained in:
parent
91167cfccd
commit
afdecd92b7
|
@ -22,9 +22,9 @@ import javax.ws.rs.core.MediaType;
|
|||
import javax.ws.rs.core.Response;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.model.audit.Audit;
|
||||
import li.strolch.model.json.AuditToJsonVisitor;
|
||||
import li.strolch.model.query.AuditQuery;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.rest.RestfulStrolchComponent;
|
||||
|
@ -46,9 +46,8 @@ public class AuditsService {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response queryTypes(@Context HttpServletRequest request) {
|
||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
StrolchRealm realm = RestfulStrolchComponent.getInstance().getContainer().getRealm(cert);
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(cert, getContext())) {
|
||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, getContext())) {
|
||||
JsonArray dataJ = new JsonArray();
|
||||
tx.getAuditTrail().getTypes(tx).forEach(dataJ::add);
|
||||
return Response.ok(dataJ.toString(), MediaType.APPLICATION_JSON).build();
|
||||
|
@ -61,11 +60,9 @@ public class AuditsService {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response queryAudits(@BeanParam AuditQueryData query, @Context HttpServletRequest request) {
|
||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
StrolchRealm realm = RestfulStrolchComponent.getInstance().getContainer().getRealm(cert);
|
||||
|
||||
try (StrolchTransaction tx = realm.openTx(cert, getContext())) {
|
||||
|
||||
li.strolch.model.query.AuditQuery<Audit> auditQuery = new ToAuditQueryVisitor().create(query);
|
||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, getContext())) {
|
||||
AuditQuery<Audit> auditQuery = new ToAuditQueryVisitor().create(query);
|
||||
JsonArray dataJ = new JsonArray();
|
||||
tx.getAuditTrail().doQuery(tx, auditQuery).forEach(a -> a.accept(new AuditToJsonVisitor()));
|
||||
return Response.ok(dataJ.toString(), MediaType.APPLICATION_JSON).build();
|
||||
|
|
|
@ -88,7 +88,7 @@ public class Inspector {
|
|||
}
|
||||
|
||||
private StrolchTransaction openTx(Certificate certificate, String realm) {
|
||||
return RestfulStrolchComponent.getInstance().getContainer().getRealm(realm).openTx(certificate, getContext());
|
||||
return RestfulStrolchComponent.getInstance().openTx(certificate, realm, getContext());
|
||||
}
|
||||
|
||||
private String toString(JsonElement jsonElement) {
|
||||
|
|
|
@ -28,7 +28,7 @@ public class ModelQuery {
|
|||
}
|
||||
|
||||
private StrolchTransaction openTx(Certificate certificate, String realm) {
|
||||
return RestfulStrolchComponent.getInstance().getContainer().getRealm(realm).openTx(certificate, getContext());
|
||||
return RestfulStrolchComponent.getInstance().openTx(certificate, realm, getContext());
|
||||
}
|
||||
|
||||
@POST
|
||||
|
@ -50,5 +50,4 @@ public class ModelQuery {
|
|||
return Response.ok(queryResponse.asJson(Boolean.parseBoolean(flat)).toString(), MediaType.APPLICATION_JSON)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,7 @@ import static li.strolch.model.StrolchModelConstants.BAG_PARAMETERS;
|
|||
import static li.strolch.report.ReportConstants.*;
|
||||
import static li.strolch.rest.StrolchRestfulConstants.*;
|
||||
import static li.strolch.rest.StrolchRestfulConstants.PARAM_DATE_RANGE_SEL;
|
||||
import static li.strolch.utils.helper.StringHelper.formatNanoDuration;
|
||||
import static li.strolch.utils.helper.StringHelper.isNotEmpty;
|
||||
import static li.strolch.utils.helper.StringHelper.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.*;
|
||||
|
@ -60,11 +59,13 @@ public class ReportResource {
|
|||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getAllReportIds(@Context HttpServletRequest request) {
|
||||
public Response getAllReportIds(@Context HttpServletRequest request, @QueryParam("realm") String realm) {
|
||||
|
||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
if (isEmpty(realm))
|
||||
realm = RestfulStrolchComponent.getInstance().getContainer().getRealm(cert).getRealm();
|
||||
|
||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, getContext())) {
|
||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, realm, getContext())) {
|
||||
|
||||
List<Resource> ids = new ReportSearch().search(tx).orderByName(false).toList();
|
||||
|
||||
|
@ -85,10 +86,12 @@ public class ReportResource {
|
|||
@GET
|
||||
@Path("{id}/facets")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getReportFacets(@Context HttpServletRequest request, @PathParam("id") String id,
|
||||
@QueryParam(LIMIT) String limitS) throws IOException {
|
||||
public Response getReportFacets(@Context HttpServletRequest request, @QueryParam("realm") String realm,
|
||||
@PathParam("id") String id, @QueryParam(LIMIT) String limitS) throws IOException {
|
||||
|
||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
if (isEmpty(realm))
|
||||
realm = RestfulStrolchComponent.getInstance().getContainer().getRealm(cert).getRealm();
|
||||
|
||||
int limit = isNotEmpty(limitS) ? Integer.parseInt(limitS) : 10;
|
||||
|
||||
|
@ -102,7 +105,7 @@ public class ReportResource {
|
|||
}
|
||||
|
||||
JsonArray result = new JsonArray();
|
||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, getContext())) {
|
||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, realm, getContext())) {
|
||||
|
||||
Report report = new Report(tx, id);
|
||||
|
||||
|
@ -135,11 +138,13 @@ public class ReportResource {
|
|||
@Path("{id}/facets/{type}/fields")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getReportFacetValues(@Context HttpServletRequest request, @PathParam("id") String id,
|
||||
@PathParam("type") String type, @QueryParam(PARAM_QUERY) String queryS, @QueryParam(LIMIT) String limitS)
|
||||
throws IOException {
|
||||
public Response getReportFacetValues(@Context HttpServletRequest request, @QueryParam("realm") String realm,
|
||||
@PathParam("id") String id, @PathParam("type") String type, @QueryParam(PARAM_QUERY) String queryS,
|
||||
@QueryParam(LIMIT) String limitS) throws IOException {
|
||||
|
||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
if (isEmpty(realm))
|
||||
realm = RestfulStrolchComponent.getInstance().getContainer().getRealm(cert).getRealm();
|
||||
|
||||
String query = isNotEmpty(queryS) ? queryS.toLowerCase() : queryS;
|
||||
int limit = isNotEmpty(limitS) ? Integer.parseInt(limitS) : 10;
|
||||
|
@ -153,7 +158,7 @@ public class ReportResource {
|
|||
localeJ = localesJ.get(cert.getLocale().toString()).getAsJsonObject();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, getContext())) {
|
||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, realm, getContext())) {
|
||||
|
||||
// get report
|
||||
Report report = new Report(tx, id);
|
||||
|
@ -196,10 +201,12 @@ public class ReportResource {
|
|||
@Path("{id}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response getReportById(@Context HttpServletRequest request, @PathParam("id") String id, String data)
|
||||
throws IOException {
|
||||
public Response getReportById(@Context HttpServletRequest request, @QueryParam("realm") String realm,
|
||||
@PathParam("id") String id, String data) throws IOException {
|
||||
|
||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
if (isEmpty(realm))
|
||||
realm = RestfulStrolchComponent.getInstance().getContainer().getRealm(cert).getRealm();
|
||||
|
||||
DBC.PRE.assertNotEmpty("report ID is required", id);
|
||||
|
||||
|
@ -248,7 +255,7 @@ public class ReportResource {
|
|||
localeJ = localesJ.get(cert.getLocale().toString()).getAsJsonObject();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, getContext())) {
|
||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, realm, getContext())) {
|
||||
long start = System.nanoTime();
|
||||
|
||||
// get report
|
||||
|
@ -315,10 +322,12 @@ public class ReportResource {
|
|||
@Path("{id}/csv")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(TEXT_CSV)
|
||||
public Response getReportByIdAsCsv(@Context HttpServletRequest request, @PathParam("id") String id, String data)
|
||||
throws IOException {
|
||||
public Response getReportByIdAsCsv(@Context HttpServletRequest request, @QueryParam("realm") String realm,
|
||||
@PathParam("id") String id, String data) throws IOException {
|
||||
|
||||
Certificate cert = (Certificate) request.getAttribute(StrolchRestfulConstants.STROLCH_CERTIFICATE);
|
||||
if (isEmpty(realm))
|
||||
realm = RestfulStrolchComponent.getInstance().getContainer().getRealm(cert).getRealm();
|
||||
|
||||
DBC.PRE.assertNotEmpty("report ID is required", id);
|
||||
|
||||
|
@ -338,7 +347,7 @@ public class ReportResource {
|
|||
localeJ = localesJ.get(cert.getLocale().toString()).getAsJsonObject();
|
||||
}
|
||||
|
||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, getContext())) {
|
||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, realm, getContext())) {
|
||||
|
||||
// get report
|
||||
Report report = new Report(tx, id);
|
||||
|
|
Loading…
Reference in New Issue