* Builds the crossTab (headers structure and data)
* @param dataStore: the source of the data
* @param crosstabDefinition: the definition of the crossTab
*/
public CrossTab(IDataStore dataStore, CrosstabDefinition crosstabDefinition) throws JSONException{
IRecord record;
String rowPath;
String columnPath;
this.config = crosstabDefinition.getConfig();
int cellLimit = crosstabDefinition.getCellLimit();
boolean columnsOverflow = false; //true if the number of cell shown in the crosstab is less than the total number of cells
boolean measuresOnColumns = crosstabDefinition.isMeasuresOnColumns();
int rowsCount = crosstabDefinition.getRows().size();
int columnsCount = crosstabDefinition.getColumns().size();
int measuresCount = crosstabDefinition.getMeasures().size();
int index;
cellLimit = cellLimit/measuresCount;
List<String> rowCordinates = new ArrayList<String>();
List<String> columnCordinates = new ArrayList<String>();
List<String> data = new ArrayList<String>();
columnsRoot = new Node("rootC");
rowsRoot = new Node("rootR");
for(index = 0; index<dataStore.getRecordsCount() && index<cellLimit; index++){
record = dataStore.getRecordAt(index);
addRecord(columnsRoot, record, 0, columnsCount);
addRecord(rowsRoot, record, columnsCount, columnsCount+rowsCount);
}
if(index<dataStore.getRecordsCount()){
Node completeColumnsRoot = new Node("rootCompleteC");
for(index = 0; index<dataStore.getRecordsCount(); index++){
record = dataStore.getRecordAt(index);
addRecord(completeColumnsRoot, record, 0, columnsCount);
}
columnsOverflow = columnsRoot.getLeafsNumber()<completeColumnsRoot.getLeafsNumber();
}
for(index = 0; index<dataStore.getRecordsCount(); index++){
record = dataStore.getRecordAt(index);
List<IField> fields= record.getFields();
columnPath="";
for(int i=0; i<columnsCount; i++){
Object value = fields.get(i).getValue();
String valueStr = null;
if (value == null){
valueStr = "null";
} else {
valueStr = value.toString();
}
columnPath = columnPath + valueStr;
}
rowPath="";
for(int i=columnsCount; i<record.getFields().size()-measuresCount; i++){
Object value = fields.get(i).getValue();
String valueStr = null;
if (value == null){
valueStr = "null";
} else {
valueStr = value.toString();
}
rowPath = rowPath + valueStr.toString();
}
for(int i=record.getFields().size()-measuresCount; i<record.getFields().size(); i++){
columnCordinates.add(columnPath);
rowCordinates.add(rowPath);
data.add(""+getStringValue(fields.get(i).getValue()));
}
}