Facade for the reporting and metrics subsystem, covering saved queries, tables, metrics and the organisation and supplier filters used to scope a report to the current user. Delegates most of its work to QueryService and ApplicationManager. Registered in the templating data model and available to server-side JS as "queryManager", so most of its exported methods form the API a report template or JS controller uses to run a query, calculate a metric or resolve the currently selected organisations.
Group: Managers
Properties
| Property | Returns | Description |
|---|---|---|
| availableOrgIds | List<Long> | The internal ids of the organisations the current user has the ReportingAccess role on. This list is not expanded, so it does not include child organisations of those. |
| availableOrgs | List<Organisation> | The organisations directly available to the current user, ie where the user has the ReportingAccess role on that org, sorted by formatted name. This is a non-expanded list, so it does not include child organisations. This is an expensive operation as it resolves each organisation id individually. |
| availableSuppliers | List<Organisation> | Finds the supplier organisations available to the current user, based on the SupplierFilter role. |
| commonFinishDate | Date | The end of the common reporting date range for the current request, typically resolved from a request parameter or cookie. |
| commonStartDate | Date | The start of the common reporting date range for the current request, typically resolved from a request parameter or cookie. |
| currentTeamOrg | Organisation | The single organisation, of those currently selected by the current user, that should represent the user's team. Where multiple organisations are selected, the first resolved one is returned. |
| lagFinishDate | Date | The common finish date shifted back by the configured reporting lag, used where a metric or query should be evaluated on data that has had time to settle. |
| lagStartDate | Date | The common start date shifted back by the configured reporting lag, used where a metric or query should be evaluated on data that has had time to settle. |
| lookupTables | List<LookupTableBean> | The lookup tables configured for the current account, used to enrich or translate values in reports. |
| metrics | List<Metric> | All configured metric definitions. |
| metricTypes | List<MetricType> | All metric types registered by installed applications, which define the calculation behaviour available to metric definitions. |
| orCreateReportParams | ReportParams | Returns the current thread-bound report parameters, creating and binding an empty set if none exist yet. |
| params | Map<String,Object> | The report query parameters resolved from the current HTTP request. |
| queries | List<QueryBean> | The saved queries available for reporting, combining the configured queries with any contributed by installed query applications, sorted by name. |
| queriesConfig | Queries | The raw queries configuration for the current account, including its tables, saved queries and lookup tables. |
| queryParameters | List<QueryParameter> | The static and query-specific parameters that can be substituted into a query definition, such as startDate, endDate and the currently selected organisations. Sourced from the query service's static parameter list. |
| selectedOrgIds | List<Long> | The ids of the organisations currently selected by the current user for reporting, sorted numerically. |
| selectedOrgs | List<OrgData> | The organisation(s) currently selected by the current user, resolved as child organisations of the tenant's root organisation, excluding any that have been deleted. |
| selectedSupplierIds | List<Long> | The ids of the supplier organisations currently selected by the current user, sorted numerically. |
| tables | List<Table> | All tables available for reporting: the configured tables, tables contributed by installed query applications, and a results table (plus one per aggregation) generated for each saved query that has fields or aggregations chosen. This is an expensive operation since it assembles tables from several sources on each call. |
Methods
getQueryParameters() · toReportBean(DirectoryNode rootDir, FileNode fn) · saveMetrics(List<Metric> metrics) · saveMetric(Metric m) · newMetricBuilder(String id, String metricTypeId) · deleteMetric(String metricId) · newCalcContext() · metric(String name) · calcMetric(Metric m) · calcMetric(Metric m, CalcContext cc) · calcMetric(Metric m, Date defaultStartDate, Date defaultEndDate, CalcContext calcContext) · calcMetric(Metric m, BaseEntity entity, Date defaultStartDate, Date defaultEndDate, CalcContext calcContext) · metricType(String id) · findApplicableMetrics(NamedObject source) · newRowsResult() · newRowsResult(List<String> headers) · getCommonStartDate() · getCommonFinishDate() · getLagStartDate() · getLagFinishDate() · getMetrics() · getMetricTypes() · getTables() · getTable(String name) · getQueriesConfig() · getQueries() · getLookupTables() · calcInterval(Date startDate, Date endDate) · queryParams() · queryParams(Date startDate, Date endDate) · queryParams(Date startDate, Date endDate, Map extraParams) · runQuery(String queryName) · runQuery(String queryName, Integer from, Integer pageSize) · runQuery(String queryName, Map<String,String> params) · runQuery(String queryName, Integer from, Integer pageSize, Map<String,String> params) · getAvailableSuppliers() · availableSuppliers(Profile user) · getSelectedSupplierIds() · selectedSupplierIds(Profile user) · getSelectedOrgIds() · selectedOrgIds(Profile user) · selectedOrgIDsStr() · getAvailableOrgIds() · availableOrgIds(Profile user) · getAvailableOrgs() · getAvailableOrgIds(Group group) · getAvailableOrgIds(List<Group> groups) · getSelectedOrgs() · getCurrentTeamOrg() · teamOrg(Profile user) · selectedOrgHasType(String orgType) · preProcessQuery(String json) · preProcessQuery2(String json) · preProcessQuery2(String json, Map<String,Object> params) · getParams() · saveTable(KCriteriaTable t) · getOrCreateReportParams() · getOrCreateReportParams(Function<ReportParams,T> callback) · enqueueQueryTableExport(String queryTableName, Date start, Date finish, List<Long> orgIds, Map<String,String> params) · exportTaskName(String queryTableName) · createDefaultQuery(String esFieldName, String operator, Object value) · createDefaultQuery(String esFieldName, String operator, Object value, boolean reverseRange) · findFieldOperatorsByType(String fieldType) · findActualFieldType(String fieldType) · processRows(String indexType, List<String> fields, List rows) · processRows(String indexType, List<String> fields, boolean defaultFieldsFormatting, List rows)
getQueryParameters()
Returns: List<QueryParameter>
The static and query-specific parameters that can be substituted into a query definition, such as startDate, endDate and the currently selected organisations. Sourced from the query service's static parameter list.
toReportBean(DirectoryNode rootDir, FileNode fn)
Returns: ReportBean
Reads a report definition file and converts it into a ReportBean describing its name, title and content. Wraps the underlying IOException as a RuntimeException.
| Parameter | Description |
|---|---|
rootDir | the root directory the report file is resolved relative to |
fn | the report definition file to read |
saveMetrics(List<Metric> metrics)
Returns: void
Persists a batch of metric definitions. Does nothing, and logs a message, if the list is null or empty.
| Parameter | Description |
|---|---|
metrics | the metric definitions to save |
saveMetric(Metric m)
Returns: void
Persists a single metric definition. Does nothing, and logs a message, if the metric is null.
| Parameter | Description |
|---|---|
m | the metric definition to save |
newMetricBuilder(String id, String metricTypeId)
Returns: MetricBuilder
Starts a new fluent builder for a metric of the given type, identified by the given id.
| Parameter | Description |
|---|---|
id | the unique id for the new metric |
metricTypeId | the id of the metric type which defines how the metric is calculated |
deleteMetric(String metricId)
Returns: void
Deletes the metric definition with the given id.
| Parameter | Description |
|---|---|
metricId | the id of the metric to delete |
newCalcContext()
Returns: CalcContext
Creates a new, empty calculation context used to track recursion depth while calculating metrics.
metric(String name)
Returns: Metric
Looks up a metric definition by its name.
| Parameter | Description |
|---|---|
name | the name of the metric to find |
calcMetric(Metric m)
Returns: BigDecimal
Calculates the value of a metric using the common date range and no specific entity. This is an expensive operation, typically involving a search query against the underlying data.
| Parameter | Description |
|---|---|
m | the metric to calculate |
calcMetric(Metric m, CalcContext cc)
Returns: BigDecimal
Calculates the value of a metric using the common date range and no specific entity. This is an expensive operation, typically involving a search query against the underlying data.
| Parameter | Description |
|---|---|
m | the metric to calculate |
cc | the calculation context used to capture key information, and guard against recursive metrics, during calculation |
calcMetric(Metric m, Date defaultStartDate, Date defaultEndDate, CalcContext calcContext)
Returns: BigDecimal
Calculates the value of a metric for the given date range. The metric's own date mode may override the given dates, for example to use a constant range or the previous period instead. This is an expensive operation, typically involving a search query against the underlying data.
| Parameter | Description |
|---|---|
m | the metric to calculate |
defaultStartDate | the start of the date range to use unless the metric's date mode overrides it |
defaultEndDate | the end of the date range to use unless the metric's date mode overrides it |
calcContext | the calculation context used to capture key information, and guard against recursive metrics, during calculation |
calcMetric(Metric m, BaseEntity entity, Date defaultStartDate, Date defaultEndDate, CalcContext calcContext)
Returns: BigDecimal
Calculates the value of a metric for a specific entity and date range. The metric's own date mode may override the given dates, for example to use a constant range or the previous period instead. This is an expensive operation, typically involving a search query against the underlying data.
| Parameter | Description |
|---|---|
m | the metric to calculate |
entity | the entity the metric is calculated against |
defaultStartDate | the start of the date range to use unless the metric's date mode overrides it |
defaultEndDate | the end of the date range to use unless the metric's date mode overrides it |
calcContext | the calculation context used to capture key information, and guard against recursive metrics, during calculation |
metricType(String id)
Returns: MetricType
Looks up a registered metric type by its id.
| Parameter | Description |
|---|---|
id | the id of the metric type to find |
findApplicableMetrics(NamedObject source)
Returns: List<Metric>
Finds the metrics applicable to a given source object, such as a reward or some other item which metrics can apply to. Looks the source up by its class name and object name in the configured queries.
| Parameter | Description |
|---|---|
source | a reward, or potentially some other item which metrics can apply to |
newRowsResult()
Returns: RowsResult
Creates an empty rows result with no headers, useful as a default when a table query yields no data.
newRowsResult(List<String> headers)
Returns: RowsResult
Creates an empty rows result with the given column headers, useful as a default when a table query yields no data but the headers still need to be rendered.
| Parameter | Description |
|---|---|
headers | the column headers to include in the result |
getCommonStartDate()
Returns: Date
The start of the common reporting date range for the current request, typically resolved from a request parameter or cookie.
getCommonFinishDate()
Returns: Date
The end of the common reporting date range for the current request, typically resolved from a request parameter or cookie.
getLagStartDate()
Returns: Date
The common start date shifted back by the configured reporting lag, used where a metric or query should be evaluated on data that has had time to settle.
getLagFinishDate()
Returns: Date
The common finish date shifted back by the configured reporting lag, used where a metric or query should be evaluated on data that has had time to settle.
getMetrics()
Returns: List<Metric>
All configured metric definitions.
getMetricTypes()
Returns: List<MetricType>
All metric types registered by installed applications, which define the calculation behaviour available to metric definitions.
getTables()
Returns: List<Table>
All tables available for reporting: the configured tables, tables contributed by installed query applications, and a results table (plus one per aggregation) generated for each saved query that has fields or aggregations chosen. This is an expensive operation since it assembles tables from several sources on each call.
getTable(String name)
Returns: Table
Finds a table, by id, from the combined list returned by getTables. Logs a warning and returns null if no table with that id exists.
| Parameter | Description |
|---|---|
name | the table id to find |
getQueriesConfig()
Returns: Queries
The raw queries configuration for the current account, including its tables, saved queries and lookup tables.
getQueries()
Returns: List<QueryBean>
The saved queries available for reporting, combining the configured queries with any contributed by installed query applications, sorted by name.
getLookupTables()
Returns: List<LookupTableBean>
The lookup tables configured for the current account, used to enrich or translate values in reports.
calcInterval(Date startDate, Date endDate)
Returns: String
Returns an appropriate date histogram aggregation interval (for example "day" or "month") for the given date range, chosen so the number of buckets stays reasonable.
| Parameter | Description |
|---|---|
startDate | the start of the range to bucket |
endDate | the end of the range to bucket |
queryParams()
Returns: Map<String,Object>
The current query parameters resolved from the current HTTP request, such as the selected date range and organisations.
queryParams(Date startDate, Date endDate)
Returns: Map<String,Object>
The current query parameters resolved from the current HTTP request, overriding the resolved date range with the given start and end dates.
| Parameter | Description |
|---|---|
startDate | the start date to use in place of the request-resolved value |
endDate | the end date to use in place of the request-resolved value |
queryParams(Date startDate, Date endDate, Map extraParams)
Returns: Map<String,Object>
The current query parameters resolved from the current HTTP request, overriding the resolved date range with the given start and end dates, and merging in the given extra parameters.
| Parameter | Description |
|---|---|
startDate | the start date to use in place of the request-resolved value |
endDate | the end date to use in place of the request-resolved value |
extraParams | additional parameters to merge into the resolved map |
runQuery(String queryName)
Returns: KSearchResponse
Runs a saved query by name, using the query parameters resolved from the current HTTP request, with no paging applied. This is an expensive operation as it executes a search against the underlying index.
| Parameter | Description |
|---|---|
queryName | the name of the saved query to run |
runQuery(String queryName, Integer from, Integer pageSize)
Returns: KSearchResponse
Runs a saved query by name, using the query parameters resolved from the current HTTP request, with the given paging. This is an expensive operation as it executes a search against the underlying index.
| Parameter | Description |
|---|---|
queryName | the name of the saved query to run |
from | the zero-based offset of the first result to return |
pageSize | the maximum number of results to return |
runQuery(String queryName, Map<String,String> params)
Returns: KSearchResponse
Runs a saved query by name, with no paging applied. The given parameters override the query parameters resolved from the current HTTP request. This is an expensive operation as it executes a search against the underlying index.
| Parameter | Description |
|---|---|
queryName | the name of the saved query to run |
params | parameter values that override the request-resolved query parameters |
runQuery(String queryName, Integer from, Integer pageSize, Map<String,String> params)
Returns: KSearchResponse
Runs a saved query by name, with the given paging applied. The given parameters are added to the query parameters resolved from the current HTTP request, without overriding an already-resolved value. This is an expensive operation as it executes a search against the underlying index.
| Parameter | Description |
|---|---|
queryName | the name of the saved query to run |
from | the zero-based offset of the first result to return |
pageSize | the maximum number of results to return |
params | additional parameter values, used only where not already resolved from the request |
getAvailableSuppliers()
Returns: List<Organisation>
Finds the supplier organisations available to the current user, based on the SupplierFilter role.
availableSuppliers(Profile user)
Returns: List<Organisation>
Finds the supplier organisations available to the given user, based on the SupplierFilter role. This is an expensive operation, involving a lookup of the user's supplier organisation ids.
| Parameter | Description |
|---|---|
user | the user to find available supplier organisations for |
getSelectedSupplierIds()
Returns: List<Long>
The ids of the supplier organisations currently selected by the current user, sorted numerically.
selectedSupplierIds(Profile user)
Returns: List<Long>
The ids of the supplier organisations currently selected by the given user, sorted numerically. Selection is scoped to the supplier organisations available to the user via the SupplierFilter role.
| Parameter | Description |
|---|---|
user | the user to find selected supplier organisation ids for |
getSelectedOrgIds()
Returns: List<Long>
The ids of the organisations currently selected by the current user for reporting, sorted numerically.
selectedOrgIds(Profile user)
Returns: List<Long>
The ids of the organisations currently selected by the given user for reporting, sorted numerically. Selection is scoped to the organisations the user has reporting access to.
| Parameter | Description |
|---|---|
user | the user to find selected organisation ids for |
selectedOrgIDsStr()
Returns: String
The raw, unparsed cookie value holding the selected organisation id(s), if any.
getAvailableOrgIds()
Returns: List<Long>
The internal ids of the organisations the current user has the ReportingAccess role on. This list is not expanded, so it does not include child organisations of those.
availableOrgIds(Profile user)
Returns: List<Long>
Returns the org IDs which the given user has reporting access on
| Parameter | Description |
|---|---|
user | the user to find reporting-access organisation ids for |
getAvailableOrgs()
Returns: List<Organisation>
The organisations directly available to the current user, ie where the user has the ReportingAccess role on that org, sorted by formatted name. This is a non-expanded list, so it does not include child organisations. This is an expensive operation as it resolves each organisation id individually.
getAvailableOrgIds(Group group)
Returns: List<Long>
The internal ids of the organisations the current user has the ReportingAccess role on, restricted to the given group. This list is not expanded, so it does not include child organisations of those.
| Parameter | Description |
|---|---|
group | the group to restrict the reporting-access lookup to |
getAvailableOrgIds(List<Group> groups)
Returns: List<Long>
The internal ids of the organisations the current user has the ReportingAccess role on, restricted to the given groups. This list is not expanded, so it does not include child organisations of those.
| Parameter | Description |
|---|---|
groups | the groups to restrict the reporting-access lookup to |
getSelectedOrgs()
Returns: List<OrgData>
The organisation(s) currently selected by the current user, resolved as child organisations of the tenant's root organisation, excluding any that have been deleted.
getCurrentTeamOrg()
Returns: Organisation
The single organisation, of those currently selected by the current user, that should represent the user's team. Where multiple organisations are selected, the first resolved one is returned.
teamOrg(Profile user)
Returns: Organisation
The single organisation, of those currently selected by the given user, that should represent that user's team. Where multiple organisations are selected, the first resolved one is returned.
| Parameter | Description |
|---|---|
user | the user to resolve the team organisation for |
selectedOrgHasType(String orgType)
Returns: boolean
Checks whether any of the organisations currently selected by the current user has the given organisation type.
| Parameter | Description |
|---|---|
orgType | the organisation type to look for |
preProcessQuery(String json)
Returns: String
Substitutes query parameter values into a raw query JSON string, resolved from the current HTTP request. Superseded by preProcessQuery2, which should be used instead.
| Parameter | Description |
|---|---|
json | the raw query JSON to substitute parameters into |
preProcessQuery2(String json)
Returns: String
Substitutes query parameter values, resolved from the current HTTP request, into a raw query JSON string. This improves on preProcessQuery and should be used instead: it handles simple parameter substitution and also handles parameters that resolve to lists.
| Parameter | Description |
|---|---|
json | the raw query JSON to substitute parameters into |
preProcessQuery2(String json, Map<String,Object> params)
Returns: String
Substitutes the given query parameter values into a raw query JSON string. Handles simple parameter substitution and also handles parameters that resolve to lists.
| Parameter | Description |
|---|---|
json | the raw query JSON to substitute parameters into |
params | the parameter values to substitute |
getParams()
Returns: Map<String,Object>
The report query parameters resolved from the current HTTP request.
saveTable(KCriteriaTable t)
Returns: void
Persists a criteria table definition. Wraps the underlying IOException as a RuntimeException.
| Parameter | Description |
|---|---|
t | the criteria table to save |
getOrCreateReportParams()
Returns: ReportParams
Returns the current thread-bound report parameters, creating and binding an empty set if none exist yet.
getOrCreateReportParams(Function<ReportParams,T> callback)
Returns: T
Runs the given callback with the current thread-bound report parameters, creating and binding an empty set first if none exist yet. If this call created the params, they are removed again once the callback returns.
| Parameter | Description |
|---|---|
callback | the function to run with the report parameters |
enqueueQueryTableExport(String queryTableName, Date start, Date finish, List<Long> orgIds, Map<String,String> params)
Returns: long
Creates a QueryTableExporter task and submits it to the AsyncJobManager for background execution. Normally the date range and organisation ids should be resolved via this class's own methods; the params map may be provided in addition where the query table uses extended parameters.
| Parameter | Description |
|---|---|
queryTableName | the name of the query table to export |
start | start date/time to filter the data by, if used by the query table |
finish | end date/time to filter the data by, if used by the query table |
orgIds | organisation ids to pass to the underlying query for filtering, if used |
params | additional parameters used by the underlying query |
exportTaskName(String queryTableName)
Returns: String
Builds the async job task name used to track a query table export, so its progress can be looked up later.
| Parameter | Description |
|---|---|
queryTableName | the name of the query table being exported |
createDefaultQuery(String esFieldName, String operator, Object value)
Returns: QueryBuilder
Builds a default search query clause for a field, operator and value, using the standard operator handling for the field's type.
| Parameter | Description |
|---|---|
esFieldName | the elasticsearch field name to query |
operator | the operator to apply, such as an equality or range comparison |
value | the value to compare the field against |
createDefaultQuery(String esFieldName, String operator, Object value, boolean reverseRange)
Returns: QueryBuilder
Builds a default search query clause for a field, operator and value, using the standard operator handling for the field's type, with the option to reverse the direction of a range comparison.
| Parameter | Description |
|---|---|
esFieldName | the elasticsearch field name to query |
operator | the operator to apply, such as an equality or range comparison |
value | the value to compare the field against |
reverseRange | true to reverse the direction of a range comparison, false for the normal direction |
findFieldOperatorsByType(String fieldType)
Returns: List<String>
Finds the operators available for a field of the given type, for example the comparisons a date field supports versus a keyword field.
| Parameter | Description |
|---|---|
fieldType | the field type to find operators for |
findActualFieldType(String fieldType)
Returns: String
Resolves the actual field type the query builder should use for a given declared field type.
| Parameter | Description |
|---|---|
fieldType | the declared field type to resolve |
processRows(String indexType, List<String> fields, List rows)
Returns: List<ProcessedHit>
Converts a list of raw search result rows into ProcessedHit objects, resolving any path-style fields (for example "assignedToProfileId/firstName") by joining to the related index and enriching the row with default field formatting. This is an expensive operation as it may execute additional search queries to fetch the joined data.
| Parameter | Description |
|---|---|
indexType | the index type the rows were retrieved from |
fields | the field names to include in the processed rows, including any path-style joined fields |
rows | the raw rows to process; each entry is either a KSearchHit or a Map of field name to value |
processRows(String indexType, List<String> fields, boolean defaultFieldsFormatting, List rows)
Returns: List<ProcessedHit>
Converts a list of raw search result rows into ProcessedHit objects, resolving any path-style fields (for example "assignedToProfileId/firstName") by joining to the related index. This is an expensive operation as it may execute additional search queries to fetch the joined data.
| Parameter | Description |
|---|---|
indexType | the index type the rows were retrieved from |
fields | the field names to include in the processed rows, including any path-style joined fields |
defaultFieldsFormatting | whether joined values should be resolved using the joined index's default display formatting |
rows | the raw rows to process; each entry is either a KSearchHit or a Map of field name to value |