1 package com.jaspersoft.jasperserver.war.action; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 import org.springframework.validation.DataBinder; 9 import org.springframework.web.multipart.support.ByteArrayMultipartFileEditor; 10 import org.springframework.webflow.Event; 11 import org.springframework.webflow.RequestContext; 12 import org.springframework.webflow.ScopeType; 13 import org.springframework.webflow.action.FormAction; 14 15 import com.jaspersoft.jasperserver.api.JSException; 16 import com.jaspersoft.jasperserver.api.engine.common.service.EngineService; 17 import com.jaspersoft.jasperserver.api.metadata.common.domain.FileResource; 18 import com.jaspersoft.jasperserver.api.metadata.common.domain.Folder; 19 import com.jaspersoft.jasperserver.api.metadata.common.domain.Resource; 20 import com.jaspersoft.jasperserver.api.metadata.common.domain.ResourceLookup; 21 import com.jaspersoft.jasperserver.api.metadata.common.domain.ResourceReference; 22 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService; 23 import com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.ReportDataSource; 24 import com.jaspersoft.jasperserver.api.metadata.olap.domain.JdbcOlapDataSource; 25 import com.jaspersoft.jasperserver.api.metadata.olap.domain.JndiJdbcOlapDataSource; 26 import com.jaspersoft.jasperserver.api.metadata.olap.domain.MondrianConnection; 27 import com.jaspersoft.jasperserver.api.metadata.olap.domain.MondrianXMLADefinition; 28 import com.jaspersoft.jasperserver.api.metadata.olap.domain.OlapClientConnection; 29 import com.jaspersoft.jasperserver.api.metadata.olap.domain.XMLAConnection; 30 import com.jaspersoft.jasperserver.api.metadata.olap.service.OlapConnectionService; 31 import com.jaspersoft.jasperserver.api.metadata.view.domain.FilterCriteria; 32 import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.ResourceDescriptor; 33 import com.jaspersoft.jasperserver.war.common.JasperServerConstImpl; 34 import com.jaspersoft.jasperserver.war.dto.BaseDTO; 35 import com.jaspersoft.jasperserver.war.dto.FileResourceWrapper; 36 import com.jaspersoft.jasperserver.war.dto.OlapClientConnectionWrapper; 37 import com.jaspersoft.jasperserver.war.dto.OlapUnitWrapper; 38 import com.jaspersoft.jasperserver.war.dto.ReportDataSourceWrapper; 39 import com.jaspersoft.jasperserver.war.validation.OlapClientConnectionValidator; 40 41 47 public class OlapClientConnectionAction extends FormAction { 48 private static final String OU_URI_PARAM = "resource"; 49 private static final String FORM_OBJECT_KEY = "connectionWrapper"; 50 private static final String OLAP_UNIT_SUFFIX = "_unit"; 51 private static final String OLAP_UNIT_KEY = "unit"; 52 private static final String CONTROL_OBJECT_KEY = "control"; 53 private static final String RESOURCE_OBJECT_KEY = "resource"; 54 private static final String DATASOURCE_OBJECT_KEY = "dataResource"; 55 private static final String SCHEMA_OBJECT_KEY = "fileResource"; 56 private static final String PARENT_FOLDER_ATTR = "parentFolder"; 57 private static final String PARAM_FROM_PAGE = "frompage"; 58 private static final String PARAM_RESOURCE_NAME = "resourceName"; 59 private static final String LOCAL_SCHEMA_SUFFIX = "_schema"; 60 private static final String UNPARSABLE_SCHEMA_ATTR = "schemaUnparsable"; 61 private static final String INVALID_XMLA_CONNECTION_ATTR = "xmlaConnectionInvalid"; 62 private static final String UNPARSABLE_XMLA_ATTR = "xmlaUnparsable"; 63 private static final String UNPARSABLE_CONNECTION_ATTR = "connectionUnparsable"; 64 protected final Log log = LogFactory.getLog(this.getClass()); 65 protected RepositoryService repository; 66 protected OlapConnectionService olapConnection; 67 private EngineService engine; 68 protected JasperServerConstImpl constants = new JasperServerConstImpl(); 69 70 73 public OlapClientConnectionAction() { 74 setFormObjectClass(OlapClientConnectionWrapper.class); 75 setFormObjectName(FORM_OBJECT_KEY); 76 setFormObjectScope(ScopeType.FLOW); 77 setValidator(new OlapClientConnectionValidator()); 78 } 79 80 87 public Event initAction(RequestContext context) throws Exception { 88 OlapClientConnectionWrapper wrapper = 89 (OlapClientConnectionWrapper) getFormObject(context); 90 OlapUnitWrapper parentWrapper = (OlapUnitWrapper) wrapper 91 .getParentFlowObject(); 92 OlapClientConnection connection = null; 93 if (wrapper.isNewMode()) { 94 String folderURI = (String ) context.getFlowScope().get( 96 PARENT_FOLDER_ATTR); 97 if (folderURI == null) { 98 folderURI = "/"; 99 } 100 FilterCriteria resourcesInFolder = FilterCriteria.createFilter(); 101 resourcesInFolder.addFilterElement(FilterCriteria 102 .createParentFolderFilter(folderURI)); 103 log("Searching for resources in the chosen folder:" + folderURI); 104 ResourceLookup[] existingResources = repository.findResource(null, 105 resourcesInFolder); 106 107 if (existingResources != null && existingResources.length != 0) { 108 log("res lookup size=" + existingResources.length); 109 List allResources = new ArrayList (); 110 for (int i = 0; i < existingResources.length; i++) { 111 ResourceLookup rLookup = existingResources[i]; 112 allResources.add(rLookup.getName()); 113 log("adding resource: " + rLookup.getName() 114 + " to the list"); 115 } 116 wrapper.setExistingResources(allResources); 117 } 118 } else { 119 if (parentWrapper == null) { 121 connection = wrapper.getOlapClientConnection(); 123 } else { 124 connection = parentWrapper.getOlapClientConnection(); 126 } 127 128 if (connection == null) { 129 throw new JSException("No OLAP client connection"); 130 } 131 132 wrapper.setOlapClientConnection(connection); 133 wrapper.setConnectionName(connection.getName()); 134 wrapper.setConnectionLabel(connection.getLabel()); 135 wrapper.setConnectionDescription(connection.getDescription()); 136 137 if (wrapper.getOlapClientConnection() instanceof MondrianConnection) { 139 wrapper.setOlapClientSchema((FileResource) repository 141 .getResource(null, ((MondrianConnection) connection) 142 .getSchema().getReferenceURI())); 143 wrapper.setOlapClientDatasource((ReportDataSource) repository 144 .getResource(null, ((MondrianConnection) connection) 145 .getDataSource().getReferenceURI())); 146 if (parentWrapper != null) { 148 wrapper.setSchemaUri(parentWrapper.getSchemaUri()); 149 wrapper.setDatasourceUri(parentWrapper.getOlapUnit() 150 .getDataSource().getReferenceURI()); } 152 wrapper.setType(constants.getOlapMondrianConnectionType()); 153 } else if (wrapper.getOlapClientConnection() instanceof XMLAConnection) { 154 wrapper.setXmlaCatalog(((XMLAConnection) connection) 156 .getCatalog()); 157 wrapper.setXmlaDatasource(((XMLAConnection) connection) 158 .getDataSource()); 159 wrapper.setXmlaConnectionUri(((XMLAConnection) connection) 160 .getURI()); 161 wrapper.setUsername(((XMLAConnection) connection) 162 .getUsername()); 163 wrapper.setPassword(((XMLAConnection) connection) 164 .getPassword()); 165 wrapper.setType(constants.getOlapXmlaConnectionType()); 166 } else { 167 throw new JSException("Unknown connection type"); 168 } 169 wrapper.setSource(constants.FIELD_CHOICE_CONT_REPO); 170 } 171 if (!wrapper.isSubflowMode()) { 173 getAllConnections(wrapper); 174 findAllSchemas(wrapper); 175 getAllXmlaSources(wrapper); 176 } else { 177 wrapper.setReusableMondrianConnections(parentWrapper 179 .getReusableMondrianConnections()); 180 wrapper.setReusableXmlaConnections(parentWrapper 181 .getReusableXmlaConnections()); 182 wrapper.setReusableSchemas(parentWrapper.getReusableSchemas()); 183 wrapper.setReusableXmlaDefinitions(parentWrapper 184 .getReusableXmlaDefinitions()); 185 } 186 getAllFolders(wrapper); 187 wrapper.setParentFolder((String ) context.getFlowScope().get( 188 PARENT_FOLDER_ATTR)); context.getFlowScope().put(FORM_OBJECT_KEY, wrapper); 190 context.getFlowScope().put("constants", constants); 191 return success(); 192 } 193 194 199 private void findAllSchemas(OlapClientConnectionWrapper wrapper) { 200 FilterCriteria filterCriteria = FilterCriteria 201 .createFilter(FileResource.class); 202 filterCriteria.addFilterElement(FilterCriteria 203 .createPropertyEqualsFilter("fileType", 204 ResourceDescriptor.TYPE_MONDRIAN_SCHEMA)); 205 ResourceLookup[] resourceLookup = repository.findResource(null, 206 filterCriteria); 207 List allSources = null; 208 if (resourceLookup != null && resourceLookup.length != 0) { 209 log("Found source lookups size=" + resourceLookup.length); 210 allSources = new ArrayList (resourceLookup.length); 211 for (int i = 0; i < resourceLookup.length; i++) { 212 Resource resource = (Resource) resourceLookup[i]; 213 Object resourceObj = repository.getResource(null, resource 214 .getURIString()); 215 if (!allSources.contains(((FileResource) resourceObj) 216 .getURIString())) { 217 allSources.add(((FileResource) resourceObj).getURIString()); 218 } 219 log("added uri=" + resource.getURIString()); 220 } 221 wrapper.setReusableSchemas(allSources); 222 } 223 } 224 225 230 private void getAllConnections (OlapClientConnectionWrapper wrapper) { 231 FilterCriteria filterCriteria = 232 FilterCriteria.createFilter(OlapClientConnection.class); 233 ResourceLookup[] resourceLookup = repository.findResource(null, filterCriteria); 234 List allMondrianConnections = null; 235 List allXmlaConnections = null; 236 if (resourceLookup != null && resourceLookup.length != 0) { 237 log("Found conneciton lookups size=" + resourceLookup.length); 238 allMondrianConnections = new ArrayList (resourceLookup.length); 239 allXmlaConnections = new ArrayList (resourceLookup.length); 240 for (int i = 0; i < resourceLookup.length; i++) { 241 Resource resource = (Resource) resourceLookup[i]; 242 Object resourceObj = 243 repository.getResource(null, resource.getURIString()); 244 if (resourceObj instanceof MondrianConnection) { 245 if (!allMondrianConnections.contains( 246 ((OlapClientConnection) resourceObj).getURIString())) { 247 allMondrianConnections.add( 248 ((OlapClientConnection) resourceObj).getURIString()); 249 } 250 } 251 else if (resourceObj instanceof XMLAConnection) { 252 if (!allXmlaConnections.contains( 253 ((OlapClientConnection) resourceObj).getURIString())) { 254 allXmlaConnections.add( 255 ((OlapClientConnection) resourceObj).getURIString()); 256 } 257 } 258 else { 259 throw new JSException("Unknown connection type"); 260 } 261 } 262 wrapper.setReusableMondrianConnections(allMondrianConnections); 263 wrapper.setReusableXmlaConnections(allXmlaConnections); 264 } 265 } 266 267 272 private void getAllXmlaSources(OlapClientConnectionWrapper wrapper) 273 { 274 FilterCriteria filterCriteria = 275 FilterCriteria.createFilter(MondrianXMLADefinition.class); 276 ResourceLookup[] resourceLookup = repository.findResource(null, filterCriteria); 277 List allXmlaDefinitions = null; 278 if (resourceLookup != null && resourceLookup.length != 0) { 279 log("Found xmla definition lookups size=" + resourceLookup.length); 280 allXmlaDefinitions = new ArrayList (resourceLookup.length); 281 for (int i = 0; i < resourceLookup.length; i++) { 282 Resource resource = (Resource) resourceLookup[i]; 283 Object resourceObj = repository.getResource(null, resource.getURIString()); 284 if (!allXmlaDefinitions.contains( 285 ((MondrianXMLADefinition) resourceObj).getURIString())) { 286 allXmlaDefinitions.add( 287 ((MondrianXMLADefinition) resourceObj).getCatalog()); 288 } 289 } 290 wrapper.setReusableXmlaDefinitions(allXmlaDefinitions); 291 } 292 } 293 294 299 private void getAllFolders(OlapClientConnectionWrapper wrapper) { 300 List allFolders = repository.getAllFolders(null); 301 wrapper.setAllFolders(new ArrayList ()); 302 for (int i = 0; i < allFolders.size(); i++) { 303 String folderUri = ((Folder) allFolders.get(i)).getURIString(); 304 wrapper.getAllFolders().add(folderUri); 305 } 306 } 307 308 316 public Event handleTypeSelection(RequestContext context) throws Exception { 317 OlapClientConnectionWrapper wrapper = 318 (OlapClientConnectionWrapper) getFormObject(context); 319 String strType = wrapper.getType(); 320 log("Type=" + strType); 321 322 if (strType != null) { 323 if (strType.equals(JasperServerConstImpl 324 .getOlapMondrianConnectionType())) { 325 wrapper 326 .setOlapConnectionType(ResourceDescriptor.TYPE_MONDRIAN_SCHEMA); 327 } else if (strType.equals(JasperServerConstImpl 328 .getOlapXmlaConnectionType())) { 329 wrapper 330 .setOlapConnectionType(ResourceDescriptor.TYPE_XMLA_CONNTCTION); 331 } else { 332 throw new JSException("Connection type not suported."); 333 } 334 } else { 335 throw new JSException("No connection is selected."); 336 } 337 338 return success(); 339 } 340 341 348 public Event locateSchemaResource(RequestContext context) throws Exception { 349 log("In locateSchemaResource"); 350 OlapClientConnectionWrapper occWrapper = 351 (OlapClientConnectionWrapper) getFormObject(context); 352 if (occWrapper == null) { 353 throw new JSException("No olap client connection is found."); 354 } else { 355 log("Olap client connection name=" + occWrapper.getConnectionName()); 356 } 357 FileResourceWrapper frW = new FileResourceWrapper(); 358 FileResource fileR = (FileResource) repository.newResource(null, 359 FileResource.class); 360 fileR.setParentFolder((String ) context.getFlowScope().get( 361 PARENT_FOLDER_ATTR)); 362 frW.setMode(BaseDTO.MODE_SUB_FLOW_NEW); 363 frW.setFileResource(fileR); 364 frW.setParentFlowObject(occWrapper); 366 frW.setNewUri(occWrapper.getSchemaUri()); 368 frW.setSource(occWrapper.getSource()); 369 context.getFlowScope().put(PARENT_FOLDER_ATTR, 370 (String ) context.getFlowScope().get(PARENT_FOLDER_ATTR)); 371 context.getFlowScope() 372 .put(FileResourceAction.getFORM_OBJECT_KEY(), frW); 373 return success(); 374 } 375 376 383 public Event locateDataSource(RequestContext context) throws Exception { 384 log("In locate data source"); 385 OlapClientConnectionWrapper wrapper = 386 (OlapClientConnectionWrapper) getFormObject(context); 387 ResourceReference dsRef = new ResourceReference(wrapper 388 .getDatasourceUri()); 389 ReportDataSourceWrapper odWrapper = new ReportDataSourceWrapper(); 390 odWrapper.setMode(BaseDTO.MODE_SUB_FLOW_NEW); 391 odWrapper.setParentFlowObject(wrapper); 392 odWrapper.setParentType(ResourceDescriptor.TYPE_MONDRIAN_SCHEMA); 393 if (dsRef == null) { 394 log("Found no previous OlapDataSource, creating new"); 395 ReportDataSource ods = (ReportDataSource) repository.newResource( 396 null, JdbcOlapDataSource.class); 397 ods.setParentFolder((String ) context.getFlowScope().get( 398 PARENT_FOLDER_ATTR)); 399 dsRef = new ResourceReference(ods); 400 odWrapper.setSource(constants.getFieldChoiceLocal()); 401 odWrapper.setType(constants.getJDBCDatasourceType()); 402 odWrapper.setReportDataSource(ods); 403 } else { 404 if (!dsRef.isLocal()) { log("Found OlapDataSourceLookup"); 409 odWrapper.setSource(constants.getFieldChoiceRepo()); 410 } else { 411 odWrapper.setSource(constants.getFieldChoiceLocal()); 412 ReportDataSource ods = (ReportDataSource) dsRef 413 .getLocalResource(); 414 if (JdbcOlapDataSource.class.isAssignableFrom(ods.getClass())) { 415 log("Found JDBCOlapDataSource"); 416 odWrapper.setType(constants.getJDBCDatasourceType()); 417 } else { 418 log("Found JndiJdbcOlapDataSourceLookup"); 419 if (JndiJdbcOlapDataSource.class.isAssignableFrom(ods 420 .getClass())) 421 odWrapper.setType(constants.getJNDIDatasourceType()); 422 } 423 odWrapper.setReportDataSource(ods); 424 } 425 odWrapper.setSelectedUri(dsRef.getReferenceURI()); 427 } 428 context.getFlowScope().put(PARENT_FOLDER_ATTR, 431 (String ) context.getFlowScope().get(PARENT_FOLDER_ATTR)); 432 context.getFlowScope().put(OlapDataSourceAction.getFORM_OBJECT_KEY(), 433 odWrapper); 434 return success(); 435 } 436 437 444 public Event saveSchemaResource(RequestContext context) throws Exception { 445 log("In save schema resource"); 446 OlapClientConnectionWrapper wrapper = 447 (OlapClientConnectionWrapper) getFormObject(context); 448 FileResourceWrapper frWrapper = (FileResourceWrapper) context 449 .getFlowScope().get(SCHEMA_OBJECT_KEY); 450 if (frWrapper == null) { 451 throw new JSException( 452 "Got null schema source wrapper back from subflow"); 453 } else 454 log("type was " + frWrapper.getClass().getName()); 455 456 FileResource fileResource = frWrapper.getFileResource(); 457 if (fileResource == null) { 458 throw new JSException("Got null schema source back from subflow"); 459 } else 460 log("type was " + frWrapper.getFileResource().getFileType()); 461 462 wrapper.setOlapClientSchema(fileResource); 463 464 if (frWrapper.getSource().equals(constants.getFieldChoiceFile())) { 465 wrapper.setSchemaLoaded(true); 466 } else { 467 wrapper.setSchemaUri(frWrapper.getFileResource().getReferenceURI()); 468 } 469 wrapper.setConnectionModified(true); 470 return success(); 471 } 472 473 480 public Event saveDatasource(RequestContext context) throws Exception { 481 OlapClientConnectionWrapper wrapper = 483 (OlapClientConnectionWrapper) getFormObject(context); 484 ReportDataSourceWrapper resource = (ReportDataSourceWrapper) context 485 .getFlowScope().get(DATASOURCE_OBJECT_KEY); 486 if (resource == null) 487 log("Got null datatsource back from subflow"); 488 else 489 log("type was " + resource.getType()); 490 491 if (resource.getSource().equals(constants.getFieldChoiceRepo())) { 492 if (wrapper.getOlapClientDatasource() == null) { 493 ReportDataSource datasource = (ReportDataSource) repository 495 .getResource(null, resource.getSelectedUri()); 496 resource.setReportDataSource(datasource); 497 } 498 wrapper.setOlapClientDatasource(resource.getReportDataSource()); 499 wrapper.setDatasourceUri(resource.getSelectedUri()); 500 } else { 501 ReportDataSource datasource = resource.getReportDataSource(); 502 wrapper.setOlapClientDatasource(datasource); 503 wrapper.setDatasourceAdded(true); 504 } 505 wrapper.setConnectionModified(true); 506 return success(); 507 } 508 509 516 public Event saveMondrianConnection(RequestContext context) 517 throws Exception { 518 log("In saveMondrianConnection"); 519 OlapClientConnectionWrapper wrapper = (OlapClientConnectionWrapper) getFormObject(context); 520 OlapUnitWrapper parentWrapper = (OlapUnitWrapper) wrapper 521 .getParentFlowObject(); 522 MondrianConnection mondrianConnection = null; 523 if (wrapper.getSource().equals(constants.FIELD_CHOICE_CONT_REPO)) { 524 if (wrapper.getMode() == BaseDTO.MODE_SUB_FLOW_NEW) { 525 if (wrapper.getConnectionUri() != null) { 527 mondrianConnection = (MondrianConnection) repository 528 .getResource(null, wrapper.getConnectionUri()); 529 } else { 530 throw new JSException("Connection URI is not specified"); 531 } 532 parentWrapper.setOlapClientConnection(mondrianConnection); 533 parentWrapper.setConnectionUri(wrapper.getConnectionUri()); 534 wrapper.setSchemaUri(mondrianConnection.getSchema() 535 .getReferenceURI()); 536 wrapper.setDatasourceUri(mondrianConnection.getDataSource() 537 .getReferenceURI()); 538 wrapper.setConnectionModified(false); 539 } else { 540 if (wrapper.getMode() == BaseDTO.MODE_STAND_ALONE_EDIT) { 541 mondrianConnection = (MondrianConnection) wrapper 542 .getOlapClientConnection(); 543 setMondrianConnectionDetails(wrapper, mondrianConnection); 544 repository.saveResource(null, mondrianConnection); 545 } else { 546 mondrianConnection = (MondrianConnection) repository 547 .getResource(null, wrapper.getConnectionUri()); 548 getMondrianConnectionDetails(wrapper, mondrianConnection); 549 wrapper.setConnectionModified(true); 550 551 } 552 } 553 } else { 554 try { 556 mondrianConnection = (MondrianConnection) repository 557 .newResource(null, MondrianConnection.class); 558 } catch (Exception e) { 559 throw new JSException("Failed to create connection"); 560 } 561 if (wrapper.isSchemaLoaded()) { 563 FileResource schema = wrapper.getOlapClientSchema(); 564 if (!wrapper.isSubflowMode()) { 565 schema.setURIString(wrapper.getSchemaUri()); 566 olapConnection.saveResource(null, wrapper 567 .getOlapClientSchema().getParentFolder(), schema); } else { 569 parentWrapper.setOlapClientSchema(schema); 570 parentWrapper.setSchemaLoaded(true); 571 } 572 } 573 if (wrapper.isDatasourceAdded()) { 575 ReportDataSource datasource = wrapper.getOlapClientDatasource(); 576 if (!wrapper.isSubflowMode()) { 577 datasource.setURIString(wrapper.getDatasourceUri()); 578 repository.saveResource(null, datasource); 579 } else { 580 parentWrapper.setOlapClientDatasource(datasource); 581 parentWrapper.setDatasourceAdded(true); 582 } 583 } 584 if (wrapper.isConnectionModified()) { 586 setMondrianConnectionDetails(wrapper, mondrianConnection); 587 } 588 if (!wrapper.isSubflowMode()) { 590 mondrianConnection.setParentFolder((String ) context 592 .getFlowScope().get("parentFolder")); 593 try { 594 repository.saveResource(null, mondrianConnection); 595 } catch (Exception e) { 596 throw new JSException("Failed to save connection changes."); 597 } 598 } else { 599 mondrianConnection 601 .setParentFolder(((OlapUnitWrapper) wrapper 602 .getParentFlowObject()).getOlapUnit() 603 .getParentFolder()); 604 parentWrapper.setOlapClientConnection(mondrianConnection); 605 parentWrapper.setConnectionModified(true); 606 } 607 } 608 wrapper.setOlapConnectionType(ResourceDescriptor.TYPE_MONDRIAN_SCHEMA); 609 wrapper.setOlapClientConnection(mondrianConnection); 610 return success(); 611 } 612 613 619 private void setMondrianConnectionDetails( 620 OlapClientConnectionWrapper wrapper, MondrianConnection mondrianConnection) { 621 mondrianConnection.setName(wrapper.getConnectionName()); 622 mondrianConnection.setLabel(wrapper.getConnectionLabel()); 623 mondrianConnection.setDescription(wrapper.getConnectionDescription()); 624 mondrianConnection.setURIString( 625 mondrianConnection.getParentFolder() + "/" + mondrianConnection.getName()); 626 ((MondrianConnection) mondrianConnection) 628 .setSchemaReference(wrapper.getOlapClientSchema().getURIString()); 629 if (wrapper.getMode() == BaseDTO.MODE_SUB_FLOW_EDIT) { 630 try { 631 repository.getResource( 632 null, wrapper.getOlapClientSchema().getReferenceURI()); 633 } 634 catch (Exception e) { 635 repository.saveResource(null, wrapper.getOlapClientSchema()); 637 } 638 } 639 ((MondrianConnection) mondrianConnection) 641 .setDataSourceReference(wrapper.getOlapClientDatasource().getURIString()); 642 if (wrapper.getMode() == BaseDTO.MODE_SUB_FLOW_EDIT) { 643 try { 644 repository.getResource( 645 null, wrapper.getOlapClientDatasource().getURIString()); 646 } 647 catch (Exception e) { 648 repository.saveResource(null, wrapper.getOlapClientDatasource()); 650 } 651 } 652 } 653 654 660 private void getMondrianConnectionDetails( 661 OlapClientConnectionWrapper wrapper, MondrianConnection mondrianConnection) { 662 wrapper.setConnectionName(mondrianConnection.getName()); 663 wrapper.setConnectionLabel(mondrianConnection.getLabel()); 664 wrapper.setConnectionDescription(mondrianConnection.getDescription()); 665 wrapper.setSchemaUri( 667 ((MondrianConnection) mondrianConnection).getSchema().getReferenceURI()); 668 wrapper.setDatasourceUri( 670 ((MondrianConnection) mondrianConnection).getDataSource().getReferenceURI()); 671 } 672 673 681 public Event saveXmlaConnection(RequestContext context) throws Exception { 682 log("In saveXmlaConnection"); 683 OlapClientConnectionWrapper wrapper = 684 (OlapClientConnectionWrapper) getFormObject(context); 685 OlapUnitWrapper parentWrapper = (OlapUnitWrapper) wrapper 686 .getParentFlowObject(); 687 XMLAConnection xmlaConnection = (XMLAConnection) wrapper 688 .getOlapClientConnection(); 689 if (wrapper.getSource().equals(constants.FIELD_CHOICE_CONT_REPO)) { 690 if (wrapper.getMode() == BaseDTO.MODE_SUB_FLOW_NEW) { 691 if (wrapper.getConnectionUri() != null) { 692 xmlaConnection = (XMLAConnection) repository.getResource( 693 null, wrapper.getConnectionUri()); 694 } else { 695 throw new JSException("Connection URI is not specified"); 696 } 697 parentWrapper.setOlapClientConnection(xmlaConnection); 698 parentWrapper.setConnectionUri(wrapper.getConnectionUri()); 699 wrapper.setConnectionModified(false); 700 } else { 701 if (wrapper.getMode() == BaseDTO.MODE_STAND_ALONE_EDIT) { 702 setXmlaConnectionDetails(wrapper, xmlaConnection); 703 repository.saveResource(null, xmlaConnection); 704 } else { 705 xmlaConnection = (XMLAConnection) repository.getResource( 706 null, wrapper.getConnectionUri()); 707 getXmlaConnectionDetails(wrapper, xmlaConnection); 708 wrapper.setConnectionModified(true); 709 } 710 } 711 } else { 712 xmlaConnection = (XMLAConnection) repository.newResource(null, 714 XMLAConnection.class); 715 xmlaConnection.setParentFolder(wrapper.getParentFolder()); 716 setXmlaConnectionDetails(wrapper, xmlaConnection); 717 if (!wrapper.isSubflowMode()) { 718 try { 719 repository.saveResource(null, xmlaConnection); } catch (Exception e) { 721 throw new JSException("Failed to save connection"); 722 } 723 } else { 724 xmlaConnection 725 .setParentFolder(((OlapUnitWrapper) wrapper 726 .getParentFlowObject()).getOlapUnit() 727 .getParentFolder()); 728 parentWrapper.setOlapClientConnection(xmlaConnection); 729 parentWrapper.setConnectionModified(true); 730 } 731 } 732 wrapper.setOlapConnectionType(ResourceDescriptor.TYPE_XMLA_CONNTCTION); 733 wrapper.setOlapClientConnection(xmlaConnection); 734 return success(); 735 } 736 737 743 private void setXmlaConnectionDetails( 744 OlapClientConnectionWrapper wrapper, XMLAConnection xmlaConnection) 745 { 746 xmlaConnection.setName(wrapper.getConnectionName()); 747 xmlaConnection.setLabel(wrapper.getConnectionLabel()); 748 xmlaConnection.setDescription(wrapper.getConnectionDescription()); 749 750 xmlaConnection.setCatalog(wrapper.getXmlaCatalog()); 751 xmlaConnection.setDataSource(wrapper.getXmlaDatasource()); 752 xmlaConnection.setURI(wrapper.getXmlaConnectionUri()); 753 754 xmlaConnection.setUsername(wrapper.getUsername()); 755 xmlaConnection.setPassword(wrapper.getPassword()); 756 } 757 758 763 private void getXmlaConnectionDetails( 764 OlapClientConnectionWrapper wrapper, XMLAConnection xmlaConnection) 765 { 766 wrapper.setConnectionName(xmlaConnection.getName()); 767 wrapper.setConnectionLabel(xmlaConnection.getLabel()); 768 wrapper.setConnectionDescription(xmlaConnection.getDescription()); 769 770 wrapper.setXmlaCatalog(xmlaConnection.getCatalog()); 771 wrapper.setXmlaDatasource(xmlaConnection.getDataSource()); 772 wrapper.setXmlaConnectionUri(xmlaConnection.getURI()); 773 774 wrapper.setUsername(xmlaConnection.getUsername()); 775 wrapper.setPassword(xmlaConnection.getPassword()); 776 } 777 778 783 public Object loadFormObject(RequestContext context) { 784 OlapClientConnectionWrapper formObject = null; 785 String resourceUri = context.getRequestParameters().get(OU_URI_PARAM); 786 if (resourceUri != null && resourceUri.trim().length() != 0) { 787 formObject = new OlapClientConnectionWrapper(); 788 789 OlapClientConnection occ = 790 (OlapClientConnection) repository.getResource(null, resourceUri); 791 792 formObject.setOlapClientConnection(occ); 794 formObject.setConnectionName(occ.getName()); 795 formObject.setConnectionLabel(occ.getLabel()); 796 formObject.setConnectionDescription(occ.getDescription()); 797 798 if (occ instanceof MondrianConnection) { 800 MondrianConnection mc = (MondrianConnection) occ; 801 formObject.setOlapConnectionType(ResourceDescriptor.TYPE_MONDRIAN_SCHEMA); 802 String uri = mc.getSchema().getReferenceURI(); 803 formObject.setOriginalSchemaUri(uri); 804 formObject.setSchemaUri(uri); 805 formObject.setDatasourceUri(mc.getDataSource().getReferenceURI()); 806 formObject.setSchemaLocated(true); 807 } 808 else if (occ instanceof XMLAConnection) { 809 XMLAConnection xmlac = (XMLAConnection) occ; 810 formObject.setOlapConnectionType(ResourceDescriptor.TYPE_XMLA_CONNTCTION); 811 formObject.setXmlaCatalog(xmlac.getCatalog()); 812 formObject.setXmlaDatasource(xmlac.getDataSource()); 813 formObject.setXmlaConnectionUri(xmlac.getURI()); 814 formObject.setUsername(xmlac.getUsername()); 815 formObject.setPassword(xmlac.getPassword()); 816 } 817 else { 818 log("Unknown connection type"); 819 } 820 821 formObject.setMode(BaseDTO.MODE_STAND_ALONE_EDIT); 822 formObject.setDatasourceIdentified(true); 823 formObject.setNamed(true); 824 } 825 826 if (formObject == null) { 827 log("OlapUnitAction: Stand alone new mode"); 828 formObject = new OlapClientConnectionWrapper(); 829 formObject.setMode(BaseDTO.MODE_STAND_ALONE_NEW); 830 String parentFolder = (String ) context.getFlowScope().get( 831 PARENT_FOLDER_ATTR); 832 formObject.setSource(constants.FIELD_CHOICE_FILE_SYSTEM); 833 } 834 return formObject; 835 } 836 837 844 public Event validateOlapConnection(RequestContext context) throws Exception { 845 log("In Validate OLAP Connection"); 846 OlapClientConnectionWrapper wrapper = 848 (OlapClientConnectionWrapper) getFormObject(context); 849 OlapClientConnection connection = wrapper.getOlapClientConnection(); 850 if (wrapper.getOlapConnectionType().equals( 851 ResourceDescriptor.TYPE_MONDRIAN_SCHEMA)) { 852 } 854 else if (wrapper.getOlapConnectionType().equals( 855 ResourceDescriptor.TYPE_XMLA_CONNTCTION)) { 856 } 858 else { 859 throw new JSException("Unknown connection type"); 860 } 861 return success(); 866 } 867 868 873 public RepositoryService getRepository() { 874 return repository; 875 } 876 877 882 public void setRepository(RepositoryService repository) { 883 this.repository = repository; 884 } 885 886 891 public OlapConnectionService getOlapConnection() { 892 return this.olapConnection; 893 } 894 895 900 public void setOlapConnection(OlapConnectionService olapConnection) { 901 this.olapConnection = olapConnection; 902 } 903 904 909 public EngineService getEngine() { 910 return engine; 911 } 912 913 918 public void setEngine(EngineService engine) { 919 this.engine = engine; 920 } 921 922 929 protected void initBinder(RequestContext context, DataBinder binder) { 930 binder.registerCustomEditor(byte[].class, 931 new ByteArrayMultipartFileEditor()); 932 } 933 934 939 protected void log(String text) { 940 log.debug(text); 941 } 942 } 943 | Popular Tags |