Package org.molgenis.framework.tupletable

Examples of org.molgenis.framework.tupletable.TupleTable


    String csv = "firstName,lastName,city";
    csv += "\nlucky,luke,daisy town";
    csv += "\ncalamity,jane,dead gulch";
    csv += "\njolly,jumper,apache valley";

    TupleTable table = new CsvTable(csv);

    assertEquals(table.getColumns().size(), 3);

    table.setColLimit(2);

    assertEquals(table.getColumns().size(), 2);

    table.reset();

    assertEquals(table.getColumns().size(), 3);

    table.setColOffset(1);

    assertEquals(table.getColumns().size(), 2);

    table.setColLimit(1);

    assertEquals(table.getColumns().get(0).getName(), "lastName");

    assertEquals(table.getRows().get(0).getString("lastName"), "luke");

  }
View Full Code Here


  }

  @Test
  public void export_offsetsLimits() throws TableException, IOException
  {
    TupleTable tupleTable = mock(TupleTable.class);
    when(tupleTable.getColOffset()).thenReturn(2);
    when(tupleTable.getColLimit()).thenReturn(3);
    when(tupleTable.getOffset()).thenReturn(1);
    when(tupleTable.getLimit()).thenReturn(2);

    Field field1 = when(mock(Field.class).getSqlName()).thenReturn("col1").getMock();
    Field field2 = when(mock(Field.class).getSqlName()).thenReturn("col2").getMock();
    when(tupleTable.getColumns()).thenReturn(Arrays.asList(field1, field2));
    Tuple row1 = mock(Tuple.class);
    when(row1.getNrCols()).thenReturn(2);
    when(row1.get("col1")).thenReturn("val1");
    when(row1.get("col2")).thenReturn("val2");
    when(row1.hasColNames()).thenReturn(true);
    when(row1.getColNames()).thenReturn(Arrays.asList("col1", "col2"));

    Tuple row2 = mock(Tuple.class);
    when(row2.getNrCols()).thenReturn(2);
    when(row2.get("col1")).thenReturn("val3");
    when(row2.get("col2")).thenReturn("val4");
    when(row2.hasColNames()).thenReturn(true);
    when(row2.getColNames()).thenReturn(Arrays.asList("col1", "col2"));
    when(tupleTable.iterator()).thenReturn(Arrays.asList(row1, row2).iterator());

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    CsvExporter csvExporter = new CsvExporter(tupleTable);
    csvExporter.export(bos);
    String csvString = new String(bos.toByteArray(), Charset.forName("UTF-8"));
View Full Code Here

      if (db.getConnection().isClosed())
      {
        throw new HandleRequestDelegationException(new Exception("handleRequest: Connection is closed!"));
      }

      final TupleTable tupleTable = tupleTableBuilder.create(request);
      tupleTable.setColLimit(maxVisibleColumnCount);

      if (tupleTable instanceof DatabaseTupleTable)
      {
        ((DatabaseTupleTable) tupleTable).setDb(db);
      }

      final Operation operation = StringUtils.isNotEmpty(request.getString(OPERATION)) ? Operation
          .valueOf(request.getString(OPERATION)) : Operation.RENDER_DATA;

      switch (operation)
      {
        case LOAD_CONFIG:
          if (callback != null)
          {
            callback.beforeLoadConfig(request, tupleTable);
          }
          loadTupleTableConfig(db, request, tupleTable);
          break;
        case HIDE_COLUMN:
          String columnToRemove = request.getString("column");
          tupleTable.hideColumn(columnToRemove);
          loadTupleTableConfig(db, request, tupleTable);
          break;
        case SHOW_COLUMN:
          String columnToShow = request.getString("column");
          tupleTable.showColumn(columnToShow);
          loadTupleTableConfig(db, request, tupleTable);
          break;
        case SET_COLUMN_PAGE:

          // TODO put this in a util class (default value for
          // requestparams)
          int colPage;
          try
          {
            colPage = request.getInt("colPage");
          }
          catch (Exception e)
          {
            colPage = 1;
          }

          // TODO put maxColPage function in util class
          int maxColPage = (int) Math.floor(tupleTable.getColCount() / (double) tupleTable.getColLimit());
          if ((tupleTable.getColCount() % tupleTable.getColLimit()) > 0)
          {
            maxColPage++;
          }
          colPage = Math.min(colPage, maxColPage);

          int colOffset = (colPage - 1) * tupleTable.getColLimit();
          colOffset = Math.max(colOffset, 0);

          tupleTable.setColOffset(colOffset);
          loadTupleTableConfig(db, request, tupleTable);
          break;
        case NEXT_COLUMNS:
          tupleTable.setColOffset(tupleTable.getColOffset() + maxVisibleColumnCount);
          loadTupleTableConfig(db, request, tupleTable);
          break;
        case PREVIOUS_COLUMNS:
          tupleTable.setColOffset(tupleTable.getColOffset() - maxVisibleColumnCount);
          loadTupleTableConfig(db, request, tupleTable);
          break;
        case RENDER_DATA:
          final List<QueryRule> rules = new ArrayList<QueryRule>();

          // parse the request into post data
          final JQGridPostData postData = new JQGridPostData(request);

          // convert any filters to query rules
          final List<QueryRule> filterRules = createQueryRulesFromJQGridRequest(postData.getFilters());

          if (CollectionUtils.isNotEmpty(filterRules))
          {
            rules.addAll(filterRules);
          }

          int residue = 0;
          final int rowCount = tupleTable.getCount();
          if (rowCount % postData.getRows() != 0)
          {
            residue = 1;
          }
          final int totalPages = (int) Math.floor(rowCount / (double) postData.getRows()) + residue;

          // update page
          postData.setPage(Math.min(postData.getPage(), totalPages));
          final int offset = Math.max((postData.getPage() - 1) * postData.getRows(), 0);

          final String exportSelection = request.getString("exportSelection");
          if (!StringUtils.equalsIgnoreCase(exportSelection, "ALL"))
          {
            // data.rows == limit
            tupleTable.setLimit(postData.getRows());
            // data.rows * data.page
            tupleTable.setOffset(offset);
          }

          if (StringUtils.isNotEmpty(postData.getSidx()))
          {
            final Operator sortOperator = StringUtils.equals(postData.getSord(), "asc") ? QueryRule.Operator.SORTASC
View Full Code Here

TOP

Related Classes of org.molgenis.framework.tupletable.TupleTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.