Package org.saiku.olap.dto.resultset

Examples of org.saiku.olap.dto.resultset.Matrix


    // corner.
    final int yOffset = columnsAxisInfo.getWidth();
    final int xOffsset = rowsAxisInfo.getWidth();

    // Populate a string matrix
    final Matrix matrix = new Matrix(xOffsset + (columnsAxis == null ? 1 : columnsAxis.getPositions().size()),
        yOffset + (rowsAxis == null ? 1 : rowsAxis.getPositions().size()));

    // Populate corner
    List<Level> levels = new ArrayList<Level>();
    if (rowsAxis != null && rowsAxis.getPositions().size() > 0) {
      Position p = rowsAxis.getPositions().get(0);
      for (int m = 0; m < p.getMembers().size(); m++) {
        AxisOrdinalInfo a = rowsAxisInfo.ordinalInfos.get(m);
        for (Integer depth : a.getDepths()) {
          levels.add(a.getLevel(depth));
        }
      }
      for (int x = 0; x < xOffsset; x++) {
        Level xLevel = levels.get(x);
        String s = xLevel.getCaption();
        for (int y = 0; y < yOffset; y++) {
          final MemberCell memberInfo = new MemberCell(x > 0);
          if (y == yOffset - 1) {
            memberInfo.setRawValue(s);
            memberInfo.setFormattedValue(s);
            memberInfo.setProperty("__headertype", "row_header_header");
            memberInfo.setProperty("levelindex", "" + levels.indexOf(xLevel));
            memberInfo.setHierarchy(xLevel.getHierarchy().getUniqueName());
            memberInfo.setParentDimension(xLevel.getDimension().getName());
            memberInfo.setLevel(xLevel.getUniqueName());
          }
          matrix.set(x, y, memberInfo);
        }

      }
    }
    // Populate matrix with cells representing axes
    // noinspection SuspiciousNameCombination
    populateAxis(matrix, columnsAxis, columnsAxisInfo, true, xOffsset);
    populateAxis(matrix, rowsAxis, rowsAxisInfo, false, yOffset);

    // Populate cell values
    for (final Cell cell : cellIter(pageCoords, cellSet)) {
      final List<Integer> coordList = cell.getCoordinateList();
      int x = xOffsset;
      if (coordList.size() > 0) {
        x += coordList.get(0);
      }
      int y = yOffset;
      if (coordList.size() > 1) {
        y += coordList.get(1);
      }
      final DataCell cellInfo = new DataCell(true, coordList);
      cellInfo.setCoordinates(cell.getCoordinateList());

      if (cell.getValue() != null) {
        try {
          cellInfo.setRawNumber(cell.getDoubleValue());
        } catch (Exception e1) {
          LOG.error("Could not get double", e1);
        }
      }
      String cellValue = cell.getFormattedValue(); // First try to get a
      // formatted value

      if (cellValue == null || cellValue.equals("null")) { //$NON-NLS-1$
        cellValue = ""; //$NON-NLS-1$
      }
      if (cellValue.length() < 1) {
        final Object value = cell.getValue();
        if (value == null || value.equals("null")) { //$NON-NLS-1$
          cellValue = ""; //$NON-NLS-1$
        } else {
          try {
            // TODO this needs to become query / execution specific
            DecimalFormat myFormatter = new DecimalFormat(SaikuProperties.FORMATDEFAULTNUMBERFORMAT); //$NON-NLS-1$
            DecimalFormatSymbols dfs = new DecimalFormatSymbols(SaikuProperties.LOCALE);
            myFormatter.setDecimalFormatSymbols(dfs);
            String output = myFormatter.format(cell.getValue());
            cellValue = output;
          } catch (Exception e) {
            // TODO: handle exception
          }
        }
        // the raw value
      }

      // Format string is relevant for Excel export
      // xmla cells can throw an error on this
      try {

        String formatString = (String) cell.getPropertyValue(Property.StandardCellProperty.FORMAT_STRING);
        if (formatString != null && !formatString.startsWith("|")) {
          cellInfo.setFormatString(formatString);
        } else {
          formatString = formatString.substring(1, formatString.length());
          cellInfo.setFormatString(formatString.substring(0, formatString.indexOf("|")));
        }
      } catch (Exception e) {
        // we tried
      }

      Map<String, String> cellProperties = new HashMap<String, String>();
      String val = Olap4jUtil.parseFormattedCellValue(cellValue, cellProperties);
      if (!cellProperties.isEmpty()) {
        cellInfo.setProperties(cellProperties);
      }
      cellInfo.setFormattedValue(val);
      matrix.set(x, y, cellInfo);
    }
    return matrix;

  }
View Full Code Here


    // corner.
    final int yOffset = columnsAxisInfo.getWidth();
    final int xOffsset = rowsAxisInfo.getWidth();

    // Populate a string matrix
    final Matrix matrix = new Matrix(xOffsset + (columnsAxis == null ? 1 : columnsAxis.getPositions().size()),
        yOffset + (rowsAxis == null ? 1 : rowsAxis.getPositions().size()));

    // Populate corner
    List<Level> levels = new ArrayList<Level>();
    if (rowsAxis != null && rowsAxis.getPositions().size() > 0) {
      Position p = rowsAxis.getPositions().get(0);
      for (int m = 0; m < p.getMembers().size(); m++) {
        AxisOrdinalInfo a = rowsAxisInfo.ordinalInfos.get(m);
        for (Integer depth : a.getDepths()) {
          levels.add(a.getLevel(depth));
        }
      }
      for (int x = 0; x < xOffsset; x++) {
        Level xLevel = levels.get(x);
        String s = xLevel.getCaption();
        for (int y = 0; y < yOffset; y++) {
          final MemberCell memberInfo = new MemberCell(x > 0);
          if (y == yOffset - 1) {
            memberInfo.setRawValue(s);
            memberInfo.setFormattedValue(s);
            memberInfo.setProperty("__headertype", "row_header_header");
            memberInfo.setProperty("levelindex", "" + levels.indexOf(xLevel));
            memberInfo.setHierarchy(xLevel.getHierarchy().getUniqueName());
            memberInfo.setParentDimension(xLevel.getDimension().getName());
            memberInfo.setLevel(xLevel.getUniqueName());
          }
          matrix.set(x, y, memberInfo);
        }

      }
    }
    // Populate matrix with cells representing axes
    populateAxis(matrix, columnsAxis, columnsAxisInfo, true, xOffsset);
    populateAxis(matrix, rowsAxis, rowsAxisInfo, false, yOffset);

    // TODO - why did we do this in the first place??? HERE BE DRAGONS
    //int headerwidth = matrix.getMatrixWidth();
    //if (headerwidth > 2) {
    //for(int yy=matrix.getMatrixHeight(); yy > matrix.getOffset() ; yy--) {
    //for(int xx=0; xx < headerwidth-1;xx++) {
    //if (matrix.get(xx,yy-1) != null
    // && matrix.get(xx,yy) != null &&  matrix.get(xx,yy-1).getRawValue() != null
    //&& matrix.get(xx,yy-1).
    // getRawValue().equals(matrix.get(xx, yy).getRawValue()))
    //{
    //matrix.set(xx, yy, new MemberCell());
    //}
    //else {
    //break;
    //}
    //}
    //}
    //}


    // Populate cell values
    int newyOffset = yOffset;
    int newxOffset = xOffsset;
    List<Integer> donex = new ArrayList<Integer>();
    List<Integer> doney = new ArrayList<Integer>();
    for (final Cell cell : cellIter(pageCoords, cellSet)) {
      final List<Integer> coordList = cell.getCoordinateList();
      int y = newyOffset;
      int x = newxOffset;
      if (coordList.size() > 0) {
        if (coordList.get(0) == 0) {
          newxOffset = xOffsset;
          donex = new ArrayList<Integer>();
        }
        x = newxOffset;
        if (coordList.size() > 0) {
          x += coordList.get(0);
        }
        y = newyOffset;
        if (coordList.size() > 1) {
          y += coordList.get(1);
        }

        boolean stop = false;
        if (coordList.size() > 0 && ignorex.contains(coordList.get(0))) {
          if (!donex.contains(coordList.get(0))) {
            newxOffset--;
            donex.add(coordList.get(0));
          }
          stop = true;
        }
        if (coordList.size() > 1 && ignorey.contains(coordList.get(1))) {
          if (!doney.contains(coordList.get(1))) {
            newyOffset--;
            doney.add(coordList.get(1));
          }
          stop = true;
        }
        if (stop) {
          continue;
        }
      }

      final DataCell cellInfo = new DataCell(true, coordList);
      cellInfo.setCoordinates(cell.getCoordinateList());

      if (cell.getValue() != null) {
        try {
          cellInfo.setRawNumber(cell.getDoubleValue());
        } catch (Exception e1) {
          LOG.error("Could not get double", e1);
        }
      }
      String cellValue = cell.getFormattedValue(); // First try to get a
      // formatted value

      if (cellValue == null || cellValue.equals("null")) { //$NON-NLS-1$
        cellValue = ""; //$NON-NLS-1$
      }
      if (cellValue.length() < 1) {
        final Object value = cell.getValue();
        if (value == null || value.equals("null")) { //$NON-NLS-1$
          cellValue = ""; //$NON-NLS-1$
        } else {
          try {
            // TODO this needs to become query / execution specific
            DecimalFormat myFormatter = new DecimalFormat(SaikuProperties.FORMATDEFAULTNUMBERFORMAT); //$NON-NLS-1$
            DecimalFormatSymbols dfs = new DecimalFormatSymbols(SaikuProperties.LOCALE);
            myFormatter.setDecimalFormatSymbols(dfs);
            String output = myFormatter.format(cell.getValue());
            cellValue = output;
          } catch (Exception e) {
            // TODO: handle exception
          }
        }
        // the raw value
      }

      // Format string is relevant for Excel export
      // xmla cells can throw an error on this
      try {
        String formatString = (String) cell.getPropertyValue(Property.StandardCellProperty.FORMAT_STRING);
        if (formatString != null && !formatString.startsWith("|")) {
          cellInfo.setFormatString(formatString);
        } else {
          formatString = formatString.substring(1, formatString.length());
          cellInfo.setFormatString(formatString.substring(0, formatString.indexOf("|")));
        }
      } catch (Exception e) {
        // we tried
      }

      Map<String, String> cellProperties = new HashMap<String, String>();
      String val = Olap4jUtil.parseFormattedCellValue(cellValue, cellProperties);
      if (!cellProperties.isEmpty()) {
        cellInfo.setProperties(cellProperties);
      }
      cellInfo.setFormattedValue(val);
      matrix.set(x, y, cellInfo);
    }
    return matrix;

  }
View Full Code Here

  @NotNull
  public static CellDataSet cellSet2Matrix(@Nullable final CellSet cellSet, @NotNull ICellSetFormatter formatter) {
    if (cellSet == null) {
      return new CellDataSet(0, 0);
    }
    final Matrix matrix = formatter.format(cellSet);
    final CellDataSet cds = new CellDataSet(matrix.getMatrixWidth(), matrix.getMatrixHeight());

    int z = 0;
    final AbstractBaseCell[][] bodyvalues =
        new AbstractBaseCell[matrix.getMatrixHeight() - matrix.getOffset()][matrix
            .getMatrixWidth()];
    for (int y = matrix.getOffset(); y < matrix.getMatrixHeight(); y++) {

      for (int x = 0; x < matrix.getMatrixWidth(); x++) {
        bodyvalues[z][x] = matrix.get(x, y);
      }
      z++;
    }

    cds.setCellSetBody(bodyvalues);

    final AbstractBaseCell[][] headervalues = new AbstractBaseCell[matrix.getOffset()][matrix.getMatrixWidth()];
    for (int y = 0; y < matrix.getOffset(); y++) {
      for (int x = 0; x < matrix.getMatrixWidth(); x++) {
        headervalues[y][x] = matrix.get(x, y);
      }
    }
    cds.setCellSetHeaders(headervalues);
    cds.setOffset(matrix.getOffset());
    return cds;

  }
View Full Code Here

    // corner.
    final int yOffset = columnsAxisInfo.getWidth();
    final int xOffsset = rowsAxisInfo.getWidth();

    // Populate a string matrix
    final Matrix matrix = new Matrix(xOffsset + (columnsAxis == null ? 1 : columnsAxis.getPositions().size()),
        yOffset + (rowsAxis == null ? 1 : rowsAxis.getPositions().size()));

    // Populate corner
    List<Level> levels = new ArrayList<Level>();
    if (rowsAxis != null && rowsAxis.getPositions().size() > 0) {
      Position p = rowsAxis.getPositions().get(0);
      for (int m = 0; m < p.getMembers().size(); m++) {
        AxisOrdinalInfo a = rowsAxisInfo.ordinalInfos.get(m);
        for (Integer depth : a.getDepths()) {
          levels.add(a.getLevel(depth));
        }
      }
      for (int x = 0; x < xOffsset; x++) {
        Level xLevel = levels.get(x);
        String s = xLevel.getCaption();
        for (int y = 0; y < yOffset; y++) {
          final MemberCell memberInfo = new MemberCell(x > 0);
          if (y == yOffset - 1) {
            memberInfo.setRawValue(s);
            memberInfo.setFormattedValue(s);
            memberInfo.setProperty("__headertype", "row_header_header");
            memberInfo.setProperty("levelindex", "" + levels.indexOf(xLevel));
            memberInfo.setHierarchy(xLevel.getHierarchy().getUniqueName());
            memberInfo.setParentDimension(xLevel.getDimension().getName());
            memberInfo.setLevel(xLevel.getUniqueName());
          }
          matrix.set(x, y, memberInfo);
        }

      }
    }
    // Populate matrix with cells representing axes
    // noinspection SuspiciousNameCombination
    populateAxis(matrix, columnsAxis, columnsAxisInfo, true, xOffsset);
    populateAxis(matrix, rowsAxis, rowsAxisInfo, false, yOffset);

    // Populate cell values
    for (final Cell cell : cellIter(pageCoords, cellSet)) {
      final List<Integer> coordList = cell.getCoordinateList();
      int x = xOffsset;
      if (coordList.size() > 0) {
        x += coordList.get(0);
      }
      int y = yOffset;
      if (coordList.size() > 1) {
        y += coordList.get(1);
      }
      final DataCell cellInfo = new DataCell(true, coordList);
      cellInfo.setCoordinates(cell.getCoordinateList());

      if (cell.getValue() != null) {
        try {
          cellInfo.setRawNumber(cell.getDoubleValue());
        } catch (Exception e1) {
          LOG.error("could not get double value", e1);
        }
      }
      String cellValue = cell.getFormattedValue(); // First try to get a
      // formatted value

      if (cellValue == null || cellValue.equals("null")) { //$NON-NLS-1$
        cellValue = ""; //$NON-NLS-1$
      }
      if (cellValue.length() < 1) {
        final Object value = cell.getValue();
        if (value == null || value.equals("null")) { //$NON-NLS-1$
          cellValue = ""; //$NON-NLS-1$
        } else {
          try {
            // TODO this needs to become query / execution specific
            DecimalFormat myFormatter = new DecimalFormat(SaikuProperties.FORMATDEFAULTNUMBERFORMAT); //$NON-NLS-1$
            DecimalFormatSymbols dfs = new DecimalFormatSymbols(SaikuProperties.LOCALE);
            myFormatter.setDecimalFormatSymbols(dfs);
            String output = myFormatter.format(cell.getValue());
            cellValue = output;
          } catch (Exception e) {
            // TODO: handle exception
          }
        }
        // the raw value
      }

      // Format string is relevant for Excel export
      // xmla cells can throw an error on this
      try {

        String formatString = (String) cell.getPropertyValue(Property.StandardCellProperty.FORMAT_STRING);
        if (formatString != null && !formatString.startsWith("|")) {
          cellInfo.setFormatString(formatString);
        } else {
          formatString = formatString.substring(1, formatString.length());
          cellInfo.setFormatString(formatString.substring(0, formatString.indexOf("|")));
        }
      } catch (Exception e) {
        // we tried
      }

      Map<String, String> cellProperties = new HashMap<String, String>();
      String val = Olap4jUtil.parseFormattedCellValue(cellValue, cellProperties);
      if (!cellProperties.isEmpty()) {
        cellInfo.setProperties(cellProperties);
      }
      cellInfo.setFormattedValue(val);
      matrix.set(x, y, cellInfo);
    }
    return matrix;

  }
View Full Code Here

TOP

Related Classes of org.saiku.olap.dto.resultset.Matrix

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.