package org.saiku.service.olap;

import org.olap4j.metadata.Cube;
import org.olap4j.query.Query;
import org.saiku.olap.discover.pojo.CubePojo;
import org.saiku.olap.query.OlapQuery;

public class OlapQueryService {
	
	private OlapDiscoverService olapDiscoverService;
	
	public void setOlapDiscoverService(OlapDiscoverService os) {
		olapDiscoverService = os;
	}
	
	public OlapQuery createNewOlapQuery(String queryName, CubePojo cube) {
		try {
			Cube cub = olapDiscoverService.getCube(cube);
			if (cub != null) {
				return new OlapQuery(new Query(queryName, cub));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;

	}


}

@@ -37,63 +37,262 @@
 ort 
-org.olap4j.metadata.Cube;%0Aimport org.olap4j.query.Query
+java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Aimport org.olap4j.Axis;%0Aimport org.olap4j.metadata.Cube;%0Aimport org.olap4j.query.Query;%0Aimport org.olap4j.query.QueryAxis;%0Aimport org.olap4j.query.QueryDimension
 ;%0Aim
@@ -335,16 +335,51 @@
 bePojo;%0A
+import org.saiku.olap.query.IAxis;%0A
 import o
@@ -408,16 +408,60 @@
 apQuery;
+%0Aimport org.saiku.olap.query.IAxis.Standard;
 %0A%0Apublic
@@ -540,16 +540,92 @@
 vice;%0A%09%0A
+%09private Map%3CString,OlapQuery%3E queries = new HashMap%3CString,OlapQuery%3E();%0A%09%0A
 %09public 
@@ -719,25 +719,23 @@
 %09public 
-OlapQuery
+boolean
  createN
@@ -864,22 +864,38 @@
 ) %7B%0A%09%09%09%09
-return
+queries.put(queryName,
  new Ola
@@ -927,16 +927,34 @@
 e, cub))
+);%0A%09%09%09%09return true
 ;%0A%09%09%09%7D%0A%09
@@ -1019,18 +1019,955 @@
 urn 
-null;%0A%0A%09%7D%0A
+false;%0A%0A%09%7D%0A%09%0A%09public List%3CString%3E getQueries() %7B%0A%09%09List%3CString%3E queryList = new ArrayList%3CString%3E();%0A%09%09queryList.addAll(queries.keySet());%0A%09%09return queryList;%0A%09%7D%0A%09%0A%09public void deleteQuery(String queryName) %7B%0A%09%09queries.remove(queryName);%0A%09%7D%0A%09%0A%09public void pivot(String queryName) %7B%0A%09%09queries.get(queryName).pivot();%0A%09%7D%0A%09%0A%09public List%3CString%3E getAxes() %7B%0A%09%09List%3CString%3E axes = new ArrayList%3CString%3E();%0A%09%09for (Standard axis : IAxis.Standard.values()) %7B%0A%09%09%09axes.add(axis.toString());%0A%09%09%7D%0A%09%09return axes;%0A%09%7D%0A%09%0A%09public List%3CString%3E getDimensions(String queryName, String axis) %7B%0A%09%09OlapQuery q = queries.get(queryName);%0A%09%09IAxis tmpAxis = IAxis.forName(axis);%0A%09%09List%3CString%3E dimensions = new ArrayList%3CString%3E();%0A%0A%09%09if (tmpAxis != null) %7B%0A%09%09%09int ord = tmpAxis.axisOrdinal();%0A%09%09%09QueryAxis qa = q.getAxis(Axis.Factory.forOrdinal(ord));%0A%09%09%09for (QueryDimension dim : qa.getDimensions()) %7B%0A%09%09%09%09dimensions.add(dim.getName());%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return dimensions;%0A%09%09%0A%09%7D
 %0A%0A%7D%0A

extend olap query service