1 20 package org.openi.xmla; 21 22 import com.tonbeller.jpivot.core.ModelFactory; 23 import com.tonbeller.jpivot.olap.model.Dimension; 24 import com.tonbeller.jpivot.olap.model.OlapException; 25 import com.tonbeller.jpivot.olap.model.OlapItem; 26 import com.tonbeller.jpivot.xmla.XMLA_Dimension; 27 import com.tonbeller.jpivot.xmla.XMLA_Model; 28 import com.tonbeller.jpivot.xmla.XMLA_SOAP; 29 30 import org.apache.log4j.Logger; 31 import org.openi.analysis.Datasource; 32 import org.openi.application.Application; 33 import org.xml.sax.SAXException ; 34 import java.io.IOException ; 35 import java.net.URL ; 36 import java.util.ArrayList ; 37 import java.util.Iterator ; 38 import java.util.LinkedList ; 39 import java.util.List ; 40 41 42 47 public class XmlaConnector { 48 private static Logger logger = Logger.getLogger(XmlaConnector.class); 49 50 54 public XmlaConnector() { 55 } 58 59 public XMLA_Model query(String xmlaUri, String catalog, String mdxQuery) 60 throws IOException , OlapException, SAXException { 61 long start = System.currentTimeMillis(); 62 URL confUrl = XMLA_Model.class.getResource("config.xml"); 63 XMLA_Model model = (XMLA_Model) ModelFactory.instance(confUrl); 64 65 model.setMdxQuery(mdxQuery); 66 model.setUri(xmlaUri); 67 model.setCatalog(catalog); 68 69 model.initialize(); 71 72 return model; 73 } 74 75 85 public List getCubeList(String uri, String catalog, String user, 86 String pwd) throws OlapException { 87 XMLA_SOAP olap; 88 89 List cubeList = null; 90 91 if (Application.getInstance().isBasicAuthentication()) { 92 olap = new XMLA_SOAP(uri, user, pwd); 93 } else { 94 olap = new XMLA_SOAP(uri, "", ""); 95 } 96 97 cubeList = getCubesWithoutPerspectives(catalog, olap); 99 100 return cubeList; 101 } 102 103 115 public List getDimensionList(String uri, String catalog, String cubeName, String user, String pwd) throws OlapException{ 116 List dimensions = new ArrayList (); 117 XMLA_SOAP olap = new XMLA_SOAP(uri, user, pwd); 118 Iterator olapItems = olap.discoverDim(catalog, cubeName).iterator(); 119 while(olapItems.hasNext()){ 120 OlapItem item = (OlapItem)olapItems.next(); 121 dimensions.add(item.getName()); 122 } 123 124 return dimensions; 125 } 126 127 140 private List getCubesWithoutPerspectives(String catalog, XMLA_SOAP olap) 141 throws OlapException { 142 143 List cubesWithoutPerspectives = null; 144 145 if (olap != null) { 146 Iterator iterator = olap.discoverCube(catalog).iterator(); 147 cubesWithoutPerspectives = new ArrayList (); 148 149 while (iterator.hasNext()) { 150 OlapItem item = (OlapItem) iterator.next(); 151 152 if (item.getProperty("BASE_CUBE_NAME") != null 154 && ! "".equalsIgnoreCase(item 155 .getProperty("BASE_CUBE_NAME"))) { 156 continue; 157 } 158 159 cubesWithoutPerspectives.add(item.getName()); 160 } 161 } 162 163 return cubesWithoutPerspectives; 164 } 165 166 public List discoverHier(String uri, String catalog, String user, String pwd, String cube, String dimension) throws OlapException { 167 XMLA_SOAP xmla = new XMLA_SOAP(uri, 168 user, pwd); 169 170 List hierarchies = new LinkedList (); 171 Iterator hiers = xmla.discoverHier(catalog, cube, "[" + dimension + "]").iterator(); 172 173 while ((hiers != null) && hiers.hasNext()) { 174 OlapItem currentHierarchy = (OlapItem) hiers.next(); 175 String parsedName = currentHierarchy.getName().replaceAll("\\[", ""); 176 parsedName = parsedName.replaceAll("\\[", ""); 177 hierarchies.add(parsedName); 178 } 179 return hierarchies; 180 181 } 182 183 public String createDefaultMdx(String uri, String catalog, String user, String pwd, String cube, String dimension) throws OlapException{ 184 XmlaConnector xmla = new XmlaConnector(); 185 String firstHier = ""; 186 String mdxQuery = ""; 187 if (!"Measures".equalsIgnoreCase(dimension)) { 188 List hiers = xmla.discoverHier(uri, catalog, user, pwd, cube, dimension); 189 190 if ((hiers != null) && (hiers.size() > 1)) { 191 firstHier = (String ) hiers.get(0); 192 193 if (firstHier.startsWith("[") && firstHier.endsWith("]")) { 194 firstHier = "." + firstHier; 195 } else { 196 firstHier = ".[" + firstHier + "]"; 197 } 198 } 199 200 mdxQuery = "SELECT {[Measures].DefaultMember} on columns, {[" + 201 dimension + "]" + firstHier + ".Children} on rows FROM [" + 202 cube + "]"; 203 logger.debug("MDX generated as :" + mdxQuery); 204 } 205 return mdxQuery; 206 } 207 208 209 210 } 211 | Popular Tags |