0

I am new to activePivot. We invoked a mdx query and got a CellSetDTO back. Is there any library code available to convert this CellSetDTO object to CSV, Excel, or other type of formats?

I am looking at the javadoc from quartetfs on the CellSetDTO class but the javaDoc has no description. Alternatively, I can write my own code to produce the CSV but since I am new to this and there is no description on the javaDoc, it is a bit hard to start.

Any pointer to any documentation is appreciated.

Thank you, Grace

1 Answers1

1

you can use the sample that you can find in the sandbox project, see the CellSetPrinter class, set the CellSetDTO in the constructor arg. See the CellSetPrinter class:

public class CellSetPrinter {

protected final CellSetDTO cellSet;

protected final AxisDTO slicer;

protected final List<AxisDTO> axes;

protected final List<CellDTO> cells;

public CellSetPrinter(CellSetDTO cellSet) {
    this.cellSet = cellSet;
    this.axes = cellSet.getAxes().getAxis();
    this.slicer = cellSet.getSlicerAxis();
    this.cells = cellSet.getCells().getCell();
}

/**
 * Compute axis positions from the cell ordinal with the classic formula:
 * <ul>
 * <li>(x0, x1, x2) -> x0 + x1 * n0 + x2 * n1 * n2
 * <li>ordinal -> (ordinal % n0, (ordinal / n0) % n1, (ordinal / (n0*n1)) % n2)
 * </ul>
 * 
 * @param ordinal
 * @return tuple expressed by coordinates
 */
protected List<String> getTuple(int ordinal) {
    List<String> tuple = new ArrayList<>();

    // Lookup positions on axes
    final int[] axisCoordinates = new int[axes.size()];

    int coeff = 1;
    for(int a = 0; a < axisCoordinates.length; a++) {
        int positionCount = axes.get(a).getPositions().getPosition().size();
        axisCoordinates[a] = (ordinal / coeff) % positionCount;
        coeff *= positionCount;
    }

    for(int a = 0; a < axisCoordinates.length; a++) {
        AxisPositionDTO position = axes.get(a).getPositions().getPosition().get(axisCoordinates[a]);
        for(MemberDTO member : position.getMembers().getMember()) {
            for(String pathElement : member.getPath().getItems().getItem()) {
                if(!"AllMember".equals(pathElement)) {
                    tuple.add(pathElement);
                }
            }
        }
    }

    // Append slicer content
    for(AxisPositionDTO position : slicer.getPositions().getPosition()) {
        for(MemberDTO member : position.getMembers().getMember()) {
            for(String pathElement : member.getPath().getItems().getItem()) {
                if(!"AllMember".equals(pathElement)) {
                    tuple.add(pathElement);
                }
            }
        }
    }
    return tuple;
}

public void print(PrintStream out) {
    for(CellDTO cell : cells) {
        System.out.println(getTuple(cell.getOrdinal()) + " " + cell.getFormattedValue());
    }
}
}
tuxmobil
  • 238
  • 3
  • 10
  • Thanks Tuxmobil. This is helpful. I notice there are two cellDTO classes and both of which are very similar. com.quartetfs.biz.pivot.dto.CellDTO and com.quartetfs.webservices.CellDTO classes. I am not sure why there are two such similar classes. I have the dto.CellDTO object. When you refer to the sample, could you point me to which package? – user3474390 Mar 31 '14 at 23:12
  • add the following classes in the import:import com.quartetfs.webservices.AxisDTO; import com.quartetfs.webservices.AxisPositionDTO; import com.quartetfs.webservices.CellDTO; import com.quartetfs.webservices.CellSetDTO; import com.quartetfs.webservices.MemberDTO; – tuxmobil Apr 02 '14 at 03:12