| 1 16 17 package org.pentaho.plugin.olap; 18 19 import java.util.ArrayList ; 20 import java.util.Arrays ; 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Set ; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.dom4j.Element; 28 import org.pentaho.core.system.PentahoSystem; 29 import org.pentaho.messages.Messages; 30 import org.pentaho.plugin.ComponentBase; 31 import org.pentaho.plugin.core.StandardSettings; 32 33 public class PivotViewComponent extends ComponentBase { 34 35 private static final String MODE = "mode"; 37 private static final String MODEL = "model"; 39 private static final String OPTIONS = "options"; 41 private static final String CONNECTION = "connection"; 43 private static final String TITLE = "title"; 45 private static final String URL = "url"; 47 private static final String VIEWER = "viewer"; 49 private static final String EXECUTE = "execute"; 51 private static final String CHARTTYPE = "charttype"; 53 private static final String CHARTLOCATION = "chartlocation"; 55 private static final String ROLE = "role"; 57 private static final long serialVersionUID = -327755990995067478L; 58 59 private static final Collection ignoreInputs = Arrays.asList( 60 new String [] { MODE, StandardSettings.SQL_QUERY, StandardSettings.QUERY_NAME, VIEWER } 61 ); 62 63 public Log getLogger() { 64 return LogFactory.getLog(PivotViewComponent.class); 65 } 66 67 protected boolean validateAction() { 68 69 if (!isDefinedOutput(OPTIONS)) { 70 error(Messages.getErrorString("PivotView.ERROR_0001_OPTIONS_NOT_DEFINED")); return false; 72 } 73 if (!isDefinedOutput(MODEL)) { 74 error(Messages.getErrorString("PivotView.ERROR_0002_MODEL_NOT_DEFIEND")); return false; 76 } 77 if (!isDefinedOutput(CONNECTION)) { 78 error(Messages.getErrorString("PivotView.ERROR_0003_CONNECTION_NOT_DEFINED")); return false; 80 } 81 if (!isDefinedOutput(StandardSettings.MDX_QUERY)) { 82 error(Messages.getErrorString("PivotView.ERROR_0004_MDX_NOT_DEFINED")); return false; 84 } 85 if (!isDefinedOutput(TITLE)) { 86 error(Messages.getErrorString("PivotView.ERROR_0007_TITLE_NOT_DEFINED")); return false; 88 } 89 if (!isDefinedInput(MODE)) { 90 error(Messages.getErrorString("PivotView.ERROR_0005_MODE_NOT_DEFINED")); return false; 92 } 93 if (!isDefinedOutput(URL)) { 94 error(Messages.getErrorString("PivotView.ERROR_0008_URL_NOT_DEFINED")); return false; 96 } 97 if (!isDefinedInput(StandardSettings.SQL_QUERY) && !isDefinedInput(StandardSettings.QUERY_NAME)) { 98 error(Messages.getErrorString("PivotView.ERROR_0009_QUERY_NOT_DEFINED")); return false; 100 } 101 102 return true; 103 } 104 105 protected boolean validateSystemSettings() { 106 return true; 107 } 108 109 public void done() { 110 } 111 112 protected boolean executeAction() throws Throwable { 113 114 Set inputNames = getInputNames(); 115 Set outputNames = getOutputNames(); 116 117 String mode = getInputStringValue(MODE); 118 if (!mode.equals(EXECUTE)) { 119 if (!isDefinedOutput(URL)) { 121 error(Messages.getString("PivotView.ERROR_0006_VIEWER_NOT_DEFINED")); return false; 124 } 125 String viewer = getInputStringValue(VIEWER); 126 if (viewer.indexOf('?') == -1) { 127 viewer += "?solution=" + getSolutionName() + "&path=" + getSolutionPath() + "&action=" + getActionName(); } else { 129 viewer += "solution=" + getSolutionName() + "&path=" + getSolutionPath() + "&action=" + getActionName(); } 131 132 for ( Iterator it = inputNames.iterator(); it.hasNext(); ) { 133 String name = (String )it.next(); 134 if ( !ignoreInputs.contains( name ) ) { 135 viewer += "&" + name + "=" + getInputStringValue( name ); } 137 } 138 139 setOutputValue(URL, viewer); 140 return true; 141 } 142 143 String roleName = null; 144 if (isDefinedInput(ROLE)) { 145 roleName = getInputStringValue(ROLE); 146 if (isDefinedOutput(ROLE)) { 147 setOutputValue(ROLE, roleName); 148 } 149 } 150 151 String model = getInputStringValue(StandardSettings.DATA_MODEL); 153 if (model.indexOf("http") != 0) { model = PentahoSystem.getApplicationContext().getBaseUrl() + "GetMondrianModel?model=" + model; } 156 setOutputValue(StandardSettings.DATA_MODEL, model); 157 158 if (isDefinedOutput(CHARTTYPE)) { 159 if (isDefinedInput(CHARTTYPE)) { 160 setOutputValue(CHARTTYPE, getInputStringValue(CHARTTYPE)); 161 } 162 } 163 164 if (isDefinedOutput(CHARTLOCATION)) { 165 if (isDefinedInput(CHARTLOCATION)) { 166 setOutputValue(CHARTLOCATION, getInputStringValue(CHARTLOCATION)); 167 } 168 } 169 170 String dataSource = getInputStringValue(StandardSettings.JNDI); 172 setOutputValue(StandardSettings.CONNECTION, "jdbc/" + dataSource); 174 String queryName = StandardSettings.SQL_QUERY; 176 if (inputNames.contains(StandardSettings.QUERY_NAME)) { 177 queryName = getInputStringValue(StandardSettings.QUERY_NAME); 178 } 179 String query = getInputStringValue(queryName); 180 181 if (query == null) { 182 183 } 184 if (query.equals(StandardSettings.DEFAULT)) { 185 query = MondrianModelComponent.getInitialQuery(model, dataSource, null, roleName); 187 } 188 189 String mdx = applyInputsToFormat(query); 190 setOutputValue(StandardSettings.MDX_QUERY, mdx); 191 192 String title = getInputStringValue(TITLE); 193 setOutputValue(TITLE, title); 194 195 ArrayList options = new ArrayList (); 197 Element optionsNode = (Element) getComponentDefinition().selectSingleNode("options"); List optionNodes = optionsNode.elements(); 199 Iterator optionsIterator = optionNodes.iterator(); 200 while (optionsIterator.hasNext()) { 201 Element optionNode = (Element) optionsIterator.next(); 202 options.add(optionNode.getName()); 203 } 204 if (options.size() > 0) { 205 if (outputNames.contains(OPTIONS)) { 206 setOutputValue(OPTIONS, options); 207 } else { 208 error(Messages.getErrorString("PivotView.ERROR_0001_OPTIONS_NOT_DEFINED")); return false; 210 } 211 } 212 return true; 213 } 214 215 public boolean init() { 216 return true; 217 } 218 219 } 220 | Popular Tags |