private String join(String dsLabel1, String dsLabel2) { String s = ""; MeasureCatalogueMeasure measure1 = null, measure2 = null; MeasureCatalogue mc = MeasureCatalogueSingleton.getMeasureCatologue(); Iterator<MeasureCatalogueMeasure> it = mc.getMeasures().iterator(); while (it.hasNext()) { measure1 = it.next(); s = measure1.getDataSet().getLabel(); if (measure1.getDataSet().getLabel().equals(dsLabel1)) { break; } } it = mc.getMeasures().iterator(); while (it.hasNext()) { measure2 = it.next(); s = measure2.getDataSet().getLabel(); if (measure2.getDataSet().getLabel().equals(dsLabel2)) { break; } } List<MeasureCatalogueMeasure> measures = new ArrayList<MeasureCatalogueMeasure>(); measures.add(measure1); measures.add(measure2); InMemoryMaterializer imm = new InMemoryMaterializer(); IDataStore dataStore = imm.joinMeasures(measures); JSONDataWriter dataSetWriter = new JSONDataWriter(); JSONObject dataStroreJSON = (JSONObject) dataSetWriter.write(dataStore); return dataStroreJSON.toString(); }
@SuppressWarnings({"unchecked", "rawtypes"}) @Override public void service(SourceBean request, SourceBean response) { String dataSetLabel; String callback; String locale; Integer start; Integer limit; Integer limitSS; // for pagination server side Integer rowsLimit; Boolean memoryPagination; IDataSet dataSet; IDataStore dataStore; logger.debug("IN"); Monitor monitor = MonitorFactory.start("SpagoBI_Console.GetConsoleDataAction.service"); try { super.service(request, response); ConsoleEngineInstance consoleEngineInstance = getConsoleEngineInstance(); dataSetLabel = getAttributeAsString(DATASET_LABEL); logger.debug("Parameter [" + DATASET_LABEL + "] is equals to [" + dataSetLabel + "]"); Assert.assertTrue( !StringUtilities.isEmpty(dataSetLabel), "Parameter [" + DATASET_LABEL + "] cannot be null or empty"); callback = getAttributeAsString(CALLBACK); logger.debug("Parameter [" + CALLBACK + "] is equals to [" + callback + "]"); locale = getAttributeAsString(LOCALE); logger.debug("Parameter [" + LOCALE + "] is equals to [" + locale + "]"); memoryPagination = getAttributeAsBoolean(MEMORY_PAGINATION); logger.debug("Parameter [" + MEMORY_PAGINATION + "] is equals to [" + memoryPagination + "]"); limitSS = (getAttributeAsInteger(LIMIT_SS) == null) ? -1 : getAttributeAsInteger(LIMIT_SS); logger.debug("Parameter [" + LIMIT_SS + "] is equals to [" + LIMIT_SS + "]"); rowsLimit = (getAttributeAsInteger(ROWS_LIMIT) == null) ? -1 : getAttributeAsInteger(ROWS_LIMIT); logger.debug("Parameter [" + ROWS_LIMIT + "] is equals to [" + rowsLimit + "]"); start = (getAttributeAsInteger(START) == null) ? 0 : getAttributeAsInteger(START); logger.debug("Parameter [" + START + "] is equals to [" + start + "]"); limit = (getAttributeAsInteger(LIMIT) == null) ? -1 : getAttributeAsInteger(LIMIT); logger.debug("Parameter [" + LIMIT + "] is equals to [" + limit + "]"); dataSet = null; try { dataSet = getDataSet(dataSetLabel); } catch (Throwable t) { throw new SpagoBIServiceException( "Impossible to find a dataset whose label is [" + dataSetLabel + "]", t); } Assert.assertNotNull( dataSet, "Impossible to find a dataset whose label is [" + dataSetLabel + "]"); Map params = consoleEngineInstance.getAnalyticalDrivers(); params.put(LOCALE, locale); dataSet.setParamsMap(params); UserProfile userProfile = (UserProfile) this.getEnv().get(EngineConstants.ENV_USER_PROFILE); dataSet.setUserProfileAttributes(UserProfileUtils.getProfileAttributes(userProfile)); if (dataSet instanceof AbstractDataSet) { AbstractDataSet ads = (AbstractDataSet) dataSet; ads.setUserProfile(userProfile); } // gets the max number of rows for the table // String strRowLimit = // ConsoleEngineConfig.getInstance().getProperty("CONSOLE-TABLE-ROWS-LIMIT"); // rowsLimit = (strRowLimit == null)? -1 : Integer.parseInt(strRowLimit); Monitor monitorLD = MonitorFactory.start("SpagoBI_Console.GetConsoleDataAction.service.LoadData"); if (!memoryPagination) { rowsLimit = -1; // serverSide limit = limitSS; } int totalResults = this.getDataSetTotalResult(dataSet); if (totalResults != -1) { // total results was already loaded, no need to recalculate it dataSet.setCalculateResultNumberOnLoad(false); } dataSet.loadData(start, limit, rowsLimit); monitorLD.stop(); dataStore = dataSet.getDataStore(); Assert.assertNotNull( dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName() + "] cannot be null"); Object resultNumber = dataStore.getMetaData().getProperty("resultNumber"); if (resultNumber != null) { this.setDataSetTotalResult(dataSet, (Integer) resultNumber); } JSONObject results = new JSONObject(); try { JSONDataWriter writer = new JSONDataWriter(); // write id property only if is a NGSI rest dataset, to not broke previous logic if (dataSet instanceof RESTDataSet && ((RESTDataSet) dataSet).isNgsi()) { writer.setUseIdProperty(true); // writer.setAdjust(true); } if (totalResults != -1) { // if total result was previously loaded, set this information into dataStore dataStore.getMetaData().setProperty("resultNumber", totalResults); } resultNumber = dataStore.getMetaData().getProperty("resultNumber"); if (resultNumber == null) { dataStore .getMetaData() .setProperty("resultNumber", new Integer((int) dataStore.getRecordsCount())); } JSONObject dataSetJSON = (JSONObject) writer.write(dataStore); results = dataSetJSON; } catch (Throwable e) { throw new SpagoBIServiceException("Impossible to serialize datastore", e); } try { writeBackToClient(new JSONSuccess(results, callback)); } catch (IOException e) { throw new SpagoBIServiceException("Impossible to write back the responce to the client", e); } } catch (Throwable t) { throw SpagoBIEngineServiceExceptionHandler.getInstance() .getWrappedException(getActionName(), getEngineInstance(), t); } finally { monitor.stop(); logger.debug("OUT"); } }