123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Dashboard
- * (C) Copyright IBM Corp. 2017, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *
- */
- define(['../../../lib/@waca/dashboard-common/dist/core/Model', 'jquery', './CommonQueryBuilder', './QueryResultData'], function (Model, $, CommonQueryBuilder, QueryResultData) {
- 'use strict';
- /**
- * @classdesc A helper class to build and execute queries.
- * APIs included in this class:
- * 1. whenSingleItemQueryReady - build and run single item query with pageContext and search term.
- * 2. whenColumnsMinMaxQueryReady - build and run minmax query from a column.
- * 3. whenDataItemsMinMaxQueryReady - build and run minmax query from an array of dataItems.
- * 4. getRootMembers - build and run query to get root members of a hierarchy.
- * 5. getChildren - build and run query to get children of a hierarchy or level with a memberUniqueName.
- * 6. getSiblings - build and run query to get siblings of a hierarchy or level with a memberUniqueName.
- * 7. getAscendants - build and run query to get ascendants of a hierarchy with a set of memberUniqueNames.
- *
- * Common parameters used in the APIs:
- * @param {Object} sourceIdOrModule - mandatory: The sourceId or the module object for which we're running queries against
- * @param {Object} queryContext - optional: the query context that may includes pageContext, searchTerm, etc.
- * @param {Object} queryContext.pageContext - optional: the netPageContext.
- * @param {Object} queryDefinition - mandatory: the query definitions used to build the query spec.
- * @param {Object} queryDefinition.sort - optional: indicate if sort option for the item query.
- * @param {Object} queryDefinition.limit - optional: the result limit, i.e. how many rows to return.
- */
- var CommonQueryHelper = Model.extend({
- // Constant to decide the prompt priority
- 'BASE_PROMPT_WEIGHT': 0,
- 'SIGNON_PROMPT_WEIGHT': 100,
- init: function init(options, logger) {
- CommonQueryHelper.inherited('init', this, arguments);
- this.logger = logger;
- },
- getVesion: function getVesion() {
- return 'endor';
- },
- /**
- * Execute a query for a specific column or data item.
- * @param {Object} queryDefinition.column - optional: the column definition includes columnId. Note: column is mandatory if dataItems is not provided.
- * @param {Object} queryDefinition.dataItems - optional: required if queryDefinition doesn't have column.
- * @param {String} queryContext.searchTerm - optional: the search string used to refine the query result.
- */
- whenSingleItemQueryReady: function whenSingleItemQueryReady(sourceIdOrModule, queryDefinition, queryContext) {
- var oQuerySpec = CommonQueryBuilder.buildSingleItemQuery(queryDefinition, queryContext, this.logger);
- return this._runQuery(sourceIdOrModule, oQuerySpec);
- },
- /**
- * Execute minmax query of a specific column. The result of the query is pre-aggregated minmax values without any other context.
- * To get context dependent minmax values, please call whenDataItemsMinMaxQueryReady.
- * @param {Object} queryDefinition.column - mandatory: the column to get the minmax values.
- * @example
- * queryDefinition:
- * {
- * column: {
- * columnId: 'Sheet1.Revenue'
- * }
- * };
- *
- */
- whenColumnsMinMaxQueryReady: function whenColumnsMinMaxQueryReady(sourceIdOrModule, queryDefinition, queryContext) {
- var oQuerySpec = CommonQueryBuilder.buildMinMaxQueryFromColumns(queryDefinition, queryContext, this.logger);
- return this._runQuery(sourceIdOrModule, oQuerySpec);
- },
- /**
- * Execute minmax query with dataitems and projections definitions.
- * @param {Object} queryDefinition.dataItems - mandatory: each dataitem definition should provide an 'aggregate' if this dataitem is to get minmax values.
- * @param {Object} queryDefinition.projections - mandatory: the projections should only includes the dataitem ids requesting the minmax values.
- * @example
- * queryDefinition:
- * {
- * 'dataItems': [
- * {
- * 'id': 'Sheet1.Product_line',
- * 'itemId': 'Sheet1.Product_line',
- * 'itemLabel': 'Product line'
- * },
- * {
- * 'id': 'Sheet1.Quantity',
- * 'itemId': 'Sheet1.Quantity',
- * 'itemLabel': 'Quantity',
- * 'aggregate': 'sum'
- * },
- * {
- * 'id': 'Sheet1.Unit_cost',
- * 'itemId': 'Quantity',
- * 'itemLabel': 'Unit cost',
- * 'aggregate': 'sum'
- * }
- * ],
- * 'projections': [
- * 'Sheet1.Quantity',
- * 'Sheet1.Unit_cost'
- * ]
- * };
- * The minmax result will have 2 set of minmax values, one for Sheet1.Quantity, and one for Sheet1.Unit_cost
- *
- */
- whenDataItemsMinMaxQueryReady: function whenDataItemsMinMaxQueryReady(sourceIdOrModule, queryDefinition, queryContext) {
- var oQuerySpec = CommonQueryBuilder.buildMinMaxQueryFromDataItems(queryDefinition, queryContext, this.logger);
- return this._runQuery(sourceIdOrModule, oQuerySpec);
- },
- /**
- * Execute functional query.
- * @param {Object} queryDefinition.dataItems - mandatory: dataItems definitions of the query spec.
- */
- _runFunctionQuery: function _runFunctionQuery(sourceIdOrModule, queryDefinition, queryContext) {
- var queryDefinition_1 = {
- 'dataItems': queryDefinition.dataItems,
- 'projections': CommonQueryBuilder.buildProjections(queryDefinition, this.logger)
- };
- return this.whenSingleItemQueryReady(sourceIdOrModule, queryDefinition_1, queryContext, this.logger);
- },
- /**
- * @param {Object} queryDefinition.column - mandatory: the hierarchy column used to build dataItems and projections in query spec.
- * @example
- * queryDefinition:
- * {
- * column: {columnId: '[hierarchyUniqueName]'},
- * limit: 51
- * };
- */
- getRootMembers: function getRootMembers(sourceIdOrModule, queryDefinition, queryContext) {
- var functionDefinitions = {
- 'functionName': 'rootMembers',
- 'functionParameter': 'true'
- };
- var dataItems = CommonQueryBuilder.buildFunctionQueryDataItems(queryDefinition, functionDefinitions);
- queryDefinition.dataItems = dataItems;
- return this._runFunctionQuery(sourceIdOrModule, queryDefinition, queryContext);
- },
- /**
- * @param {Object} queryDefinition.column - mandatory: the column used to build dataItems and projections in query spec.
- * @param {Object} queryDefinition.mun - mandatory: the member unique name of the function query.
- * @example
- * queryDefinition:
- * {
- * column: {columnId: '[hierarchyUniqueName]'},
- * limit: 51,
- * mun: '[memberUniqueName]'
- * };
- */
- getChildren: function getChildren(sourceIdOrModule, queryDefinition, queryContext) {
- var functionDefinitions = {
- 'functionName': 'children',
- 'functionParameter': queryDefinition.mun
- };
- var dataItems = CommonQueryBuilder.buildFunctionQueryDataItems(queryDefinition, functionDefinitions);
- queryDefinition.dataItems = dataItems;
- return this._runFunctionQuery(sourceIdOrModule, queryDefinition, queryContext);
- },
- /**
- * @see getChildren.
- */
- getSiblings: function getSiblings(sourceIdOrModule, queryDefinition, queryContext) {
- var functionDefinitions = {
- 'functionName': 'siblings',
- 'functionParameter': queryDefinition.mun
- };
- var dataItems = CommonQueryBuilder.buildFunctionQueryDataItems(queryDefinition, functionDefinitions);
- queryDefinition.dataItems = dataItems;
- return this._runFunctionQuery(sourceIdOrModule, queryDefinition, queryContext);
- },
- /**
- * @param {Object} queryDefinition.muns - mandatory: an array of member unique names.
- * @example
- * queryDefinition:
- * {
- * column: {columnId: '[hierarchyUniqueName]'},
- * limit: 51,
- * mun: ['[memberUniqueName1]',
- * '[memberUniqueName2]']
- * };
- */
- getAscendants: function getAscendants(sourceIdOrModule, queryDefinition, queryContext) {
- var functionDefinitions = {
- 'functionName': 'ascendants',
- 'functionParameter': queryDefinition.muns
- };
- var dataItems = CommonQueryBuilder.buildFunctionQueryDataItems(queryDefinition, functionDefinitions);
- queryDefinition.dataItems = dataItems;
- return this._runFunctionQuery(sourceIdOrModule, queryDefinition, queryContext);
- },
- extactListOfQueryResultData: function extactListOfQueryResultData(oQueryResultData) {
- var resultRowSize = oQueryResultData.getDatapointCount();
- var aResults = [];
- for (var rowIndex = 0; rowIndex < resultRowSize; rowIndex++) {
- var value = oQueryResultData.getCellValue(rowIndex, 0)[0];
- aResults.push(value);
- }
- return aResults;
- },
- _runQuery: function _runQuery(sourceIdOrModule, oQuerySpec) {
- var queryOptions = {
- 'querySpec': oQuerySpec,
- 'sourceIdOrModule': sourceIdOrModule
- };
- return this.queryService.runQuery(queryOptions).then(function (queryResponses) {
- return new QueryResultData(queryResponses.data);
- });
- }
- });
- return CommonQueryHelper;
- });
- //# sourceMappingURL=CommonQueryHelper.js.map
|