private ResultSet getQueryResult(
      Connection connection, PivotWidget widget, Map<String, Object> urlQueryParameters)
      throws ReportRunnerException {

    Entity entity = widget.getEntity();
    ro.nextreports.engine.Report report =
        NextUtil.getNextReport(storageService.getSettings(), entity);
    DataSource dataSource = getDataSource(entity);

    String sql = ro.nextreports.engine.util.ReportUtil.getSql(report);
    // retrieves the report parameters
    Map<String, QueryParameter> parameters = new LinkedHashMap<String, QueryParameter>();
    List<QueryParameter> parameterList = report.getParameters();
    if (parameterList != null) {
      for (QueryParameter param : parameterList) {
        parameters.put(param.getName(), param);
      }
    }

    Map<String, Object> parameterValues = new HashMap<String, Object>();

    // pivot is running with settings parameter values
    ChartUtil.initParameterSettings(
        parameterValues,
        widget.getQueryRuntime(),
        dashboardService.getUserWidgetParameters(widget.getId()));

    // parameters from embedded code
    try {
      ReportUtil.addUrlQueryParameters(
          storageService.getSettings(), entity, parameterValues, urlQueryParameters);
    } catch (Exception e1) {
      e1.printStackTrace();
      LOG.error(e1.getMessage(), e1);
    }

    QueryExecutor executor = null;
    try {
      boolean csv = CSVDialect.DRIVER_CLASS.equals(dataSource.getDriver());

      Query query = new Query(sql);
      executor = new QueryExecutor(query, parameters, parameterValues, connection, true, true, csv);
      executor.setMaxRows(0);
      executor.setTimeout(storageService.getSettings().getQueryTimeout());

      QueryResult queryResult = executor.execute();

      return queryResult.getResultSet();
    } catch (Exception e) {
      throw new ReportRunnerException(e);
    } finally {
      if (executor != null) {
        executor.closeCursors();
      }
    }
  }
  public void setPreferences(Map<String, String> preferences) {
    String username = SecurityUtil.getLoggedUsername();
    UserPreferences userPreferences;
    try {
      userPreferences =
          (UserPreferences) storageService.getEntity(UserPreferences.getPath(username));
    } catch (NotFoundException e) {
      userPreferences = new UserPreferences(username);
    }

    userPreferences.setPreferences(preferences);
    storageService.addOrModifyEntity(userPreferences);
  }
 public Date getPreferencesDate() {
   String username = getUsername();
   try {
     UserPreferences userPreferences =
         (UserPreferences) storageService.getEntity(UserPreferences.getPath(username));
     return userPreferences.getCreatedDate();
   } catch (NotFoundException e) {
     return new Date();
   }
 }
 public Map<String, String> getPreferences() {
   String username = getUsername();
   try {
     UserPreferences userPreferences =
         (UserPreferences) storageService.getEntity(UserPreferences.getPath(username));
     return userPreferences.getPreferences();
   } catch (NotFoundException e) {
     return new HashMap<String, String>();
   }
 }
  // User demo (on demo.next-reports.com instance) means :
  //   Change Password disabled (HeaderPanel.java)
  //   Distribution ok and test buttons are generated a message (AbstractDestinationPanel.java)
  //   Delete History not visible (RunHistoryPanel.java)
  public boolean isDemo() {
    if (!isSignedIn()) {
      return false;
    }

    Settings settings = storageService.getSettings();
    String baseUrl = settings.getBaseUrl();

    return getUser().getName().equals("demo") && "http://demo.next-reports.com".equals(baseUrl);
  }
  public NextServerSession(Request request) {
    super(request);
    Injector.get().inject(this);

    sectionContexts = new HashMap<String, SectionContext>();
    List<Section> sections = sectionManager.getSections();
    for (Section section : sections) {
      sectionContexts.put(section.getId(), SectionContextFactory.createSectionContext(section));
    }
    //		if (!sections.isEmpty()) {
    //			selectedSectionId = sections.get(0).getId();
    //		}
    String language = storageService.getSettings().getLanguage();
    Locale locale = LanguageManager.getInstance().getLocale(language);
    setLocale(locale);
    LOG.info("--------------------> Set locale to: " + language);
  }
  public RunHistoryQueryPanel(String id, final RunReportHistory runHistory) {
    super(id);

    int index = runHistory.getPath().lastIndexOf("/runHistory");
    String reportPath = runHistory.getPath().substring(0, index);
    Report report;
    String query = "NA";
    try {
      report = (Report) storageService.getEntity(reportPath);

      if (ReportConstants.NEXT.equals(report.getType())) {
        query =
            ro.nextreports.engine.util.ReportUtil.getSql(
                NextUtil.getNextReport(settings.getSettings(), report),
                runHistory.getParametersValues());
      }
    } catch (NotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    add(new MultiLineLabel("query", new Model<String>(query)));
  }