private int[] getSelectedRows(int[] selectedRowsNumber, Map[] selectedRowsKeys, Tab tab) {
    if (selectedRowsKeys == null || selectedRowsKeys.length == 0) return new int[0];
    // selectedRowsNumber is the most performant so we use it when possible
    else if (selectedRowsNumber.length == selectedRowsKeys.length) return selectedRowsNumber;
    else {
      // find the rows from the selectedKeys

      // This has a poor performance, but it covers the case when the selected
      // rows are not loaded for the tab, something that can occurs if the user
      // select rows and afterwards reorder the list.
      try {
        int[] s = new int[selectedRowsKeys.length];
        List selectedKeys = Arrays.asList(selectedRowsKeys);
        int end = tab.getTableModel().getTotalSize();
        int x = 0;
        for (int i = 0; i < end; i++) {
          Map key = (Map) tab.getTableModel().getObjectAt(i);
          if (selectedKeys.contains(key)) {
            s[x] = i;
            x++;
          }
        }
        return s;
      } catch (Exception ex) {
        log.warn(XavaResources.getString("fails_selected"), ex);
        throw new XavaException("fails_selected");
      }
    }
  }
 public void run() {
   try {
     if (isRegistered()) {
       register();
     }
   } catch (IOException e) {
     Log.info("Failed to reRegister " + e.getMessage());
   }
 }
  public VtiUserExitResult execute() throws VtiExitException {

    VtiUserExitScreenField scrPurchOrd = getScreenField("EBELN");
    if (scrPurchOrd == null) return new VtiUserExitResult(999, "Failed to initialise EBELN.");

    long offEbeln = 0;

    try {
      offEbeln = getNextNumberFromNumberRange("YSWB_OFFPO");
    } catch (VtiExitException ee) {
      Log.error("Error creating next Slip No.", ee);
      return new VtiUserExitResult(999, "Unable to generate offline Purchase Order.");
    }

    scrPurchOrd.setFieldValue(Long.toString(offEbeln));

    return new VtiUserExitResult();
  }
Example #4
0
  public void testNonExistentReferenceUsedAsKey() throws Exception {
    if (usesAnnotatedPOJO()) { // This case is not supported since 4m6, because Hibernate 3.6 does
      // not support it
      log.warn("testNonExistentReferenceUsedAsKey() case not supported in JPA version");
      return;
    }
    createDeliveryType(0, "JUNIT DELIVERY TYPE 0");
    execute("CRUD.new");
    assertMessage("type=null");
    setValue("invoice.year", "2002");
    setValue("invoice.number", "1");
    assertValue("invoice.date", "1/1/02");
    setValue("type.number", "0");
    setValue("number", "66");
    setValue("description", "JUNIT");
    execute("CRUD.save");
    assertNoErrors();

    setValue("invoice.year", "2002");
    setValue("invoice.number", "1");
    setValue("type.number", "0");
    setValue("number", "66");
    execute("CRUD.refresh");
    assertNoErrors();
    assertValue("description", "JUNIT");

    execute("CRUD.refresh");
    assertNoErrors();
    assertValue("description", "JUNIT");

    deleteDeliveryType(0);
    execute("CRUD.refresh");
    assertNoErrors();
    assertValue("description", "JUNIT");

    execute("CRUD.delete");
    assertMessage("Delivery deleted successfully");
  }
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      Locales.setCurrent(request);
      if (Users.getCurrent() == null) { // for a bug in websphere portal 5.1 with Domino LDAP
        Users.setCurrent((String) request.getSession().getAttribute("xava.user"));
      }
      request.getParameter("application"); // for a bug in websphere 5.1
      request.getParameter("module"); // for a bug in websphere 5.1
      Tab tab = (Tab) request.getSession().getAttribute("xava_reportTab");
      int[] selectedRowsNumber =
          (int[]) request.getSession().getAttribute("xava_selectedRowsReportTab");
      Map[] selectedKeys = (Map[]) request.getSession().getAttribute("xava_selectedKeysReportTab");
      int[] selectedRows = getSelectedRows(selectedRowsNumber, selectedKeys, tab);
      request.getSession().removeAttribute("xava_selectedRowsReportTab");
      Integer columnCountLimit =
          (Integer) request.getSession().getAttribute("xava_columnCountLimitReportTab");
      request.getSession().removeAttribute("xava_columnCountLimitReportTab");

      setDefaultSchema(request);
      String user = (String) request.getSession().getAttribute("xava_user");
      request.getSession().removeAttribute("xava_user");
      Users.setCurrent(user);
      String uri = request.getRequestURI();
      if (uri.endsWith(".pdf")) {
        InputStream is;
        JRDataSource ds;
        Map parameters = new HashMap();
        synchronized (tab) {
          tab.setRequest(request);
          parameters.put("Title", tab.getTitle());
          parameters.put("Organization", getOrganization());
          parameters.put("Date", getCurrentDate());
          for (String totalProperty : tab.getTotalPropertiesNames()) {
            parameters.put(totalProperty + "__TOTAL__", getTotal(request, tab, totalProperty));
          }
          TableModel tableModel = getTableModel(request, tab, selectedRows, false, true, null);
          tableModel.getValueAt(0, 0);
          if (tableModel.getRowCount() == 0) {
            generateNoRowsPage(response);
            return;
          }
          is = getReport(request, response, tab, tableModel, columnCountLimit);
          ds = new JRTableModelDataSource(tableModel);
        }
        JasperPrint jprint = JasperFillManager.fillReport(is, parameters, ds);
        response.setContentType("application/pdf");
        response.setHeader(
            "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".pdf\"");
        JasperExportManager.exportReportToPdfStream(jprint, response.getOutputStream());
      } else if (uri.endsWith(".csv")) {
        String csvEncoding = XavaPreferences.getInstance().getCSVEncoding();
        if (!Is.emptyString(csvEncoding)) {
          response.setCharacterEncoding(csvEncoding);
        }
        response.setContentType("text/x-csv");
        response.setHeader(
            "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".csv\"");
        synchronized (tab) {
          tab.setRequest(request);
          response
              .getWriter()
              .print(
                  TableModels.toCSV(
                      getTableModel(request, tab, selectedRows, true, false, columnCountLimit)));
        }
      } else {
        throw new ServletException(
            XavaResources.getString("report_type_not_supported", "", ".pdf .csv"));
      }
    } catch (Exception ex) {
      log.error(ex.getMessage(), ex);
      throw new ServletException(XavaResources.getString("report_error"));
    } finally {
      request.getSession().removeAttribute("xava_reportTab");
    }
  }