KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > war > action > OlapUnitAction


1 package com.jaspersoft.jasperserver.war.action;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
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.common.domain.ValidationResult;
17 import com.jaspersoft.jasperserver.api.common.domain.impl.ExecutionContextImpl;
18 import com.jaspersoft.jasperserver.api.engine.common.service.EngineService;
19 import com.jaspersoft.jasperserver.api.metadata.common.domain.FileResource;
20 import com.jaspersoft.jasperserver.api.metadata.common.domain.Resource;
21 import com.jaspersoft.jasperserver.api.metadata.common.domain.ResourceLookup;
22 import com.jaspersoft.jasperserver.api.metadata.common.domain.ResourceReference;
23 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService;
24 import com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.ReportDataSource;
25 import com.jaspersoft.jasperserver.api.metadata.olap.domain.MondrianConnection;
26 import com.jaspersoft.jasperserver.api.metadata.olap.domain.MondrianXMLADefinition;
27 import com.jaspersoft.jasperserver.api.metadata.olap.domain.OlapClientConnection;
28 import com.jaspersoft.jasperserver.api.metadata.olap.domain.OlapUnit;
29 import com.jaspersoft.jasperserver.api.metadata.olap.domain.XMLAConnection;
30 import com.jaspersoft.jasperserver.api.metadata.olap.domain.client.MondrianConnectionImpl;
31 import com.jaspersoft.jasperserver.api.metadata.olap.service.OlapConnectionService;
32 import com.jaspersoft.jasperserver.api.metadata.view.domain.FilterCriteria;
33 import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.ResourceDescriptor;
34 import com.jaspersoft.jasperserver.war.common.JasperServerConstImpl;
35 import com.jaspersoft.jasperserver.war.dto.BaseDTO;
36 import com.jaspersoft.jasperserver.war.dto.OlapClientConnectionWrapper;
37 import com.jaspersoft.jasperserver.war.dto.OlapUnitWrapper;
38 import com.jaspersoft.jasperserver.war.validation.OlapUnitValidator;
39
40 /**
41  *
42  * OlapUnitAction provides the actions for the olap view web flow
43  *
44  * @author jshih
45  * @revision $Id$
46  */

47 public class OlapUnitAction extends FormAction {
48     private static final String JavaDoc OU_URI_PARAM = "resource";
49     private static final String JavaDoc FORM_OBJECT_KEY = "wrapper";
50     private static final String JavaDoc OLAP_UNIT_SUFFIX = "_unit";
51     private static final String JavaDoc OLAP_UNIT_KEY = "unit";
52     private static final String JavaDoc CONTROL_OBJECT_KEY = "control";
53     private static final String JavaDoc RESOURCE_OBJECT_KEY = "resource";
54     private static final String JavaDoc DATASOURCE_OBJECT_KEY = "dataResource";
55     private static final String JavaDoc CONNECTION_OBJECT_KEY = "connectionWrapper";
56     private static final String JavaDoc PARENT_FOLDER_ATTR = "parentFolder";
57     private static final String JavaDoc PARAM_FROM_PAGE = "frompage";
58     private static final String JavaDoc PARAM_RESOURCE_NAME = "resourceName";
59     private static final String JavaDoc LOCAL_SCHEMA_SUFFIX = "_schema";
60     private static final String JavaDoc UNPARSABLE_SCHEMA_ATTR = "schemaUnparsable";
61     private static final String JavaDoc INVALID_XMLA_CONNECTION_ATTR = "xmlaConnectionInvalid";
62     private static final String JavaDoc UNPARSABLE_XMLA_ATTR = "xmlaUnparsable";
63     private static final String JavaDoc 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     /**
71      * initialize OlapUnitAction.class object
72      */

73     public OlapUnitAction() {
74     setFormObjectClass(OlapUnitWrapper.class);
75     setFormObjectName(FORM_OBJECT_KEY);
76     setFormObjectScope(ScopeType.FLOW);
77     setValidator(new OlapUnitValidator());
78     }
79
80     /**
81      * initAction performs the initialization for the olap view (unit) web flow
82      *
83      * @param context
84      * @return
85      * @throws Exception
86      */

87     public Event initAction(RequestContext context) throws Exception JavaDoc {
88     ((OlapUnitValidator)getValidator()).setConnectionService(olapConnection);
89     OlapUnitWrapper wrapper = (OlapUnitWrapper) getFormObject(context);
90     if (wrapper.isNewMode()) {
91         // create olap view
92
// this entire if case seems unnecessary --
93
// there are no resources, and null is the default for "/"
94
String JavaDoc folderURI = wrapper.getOlapUnit().getParentFolder();
95         if (folderURI == null) {
96         folderURI = "/";
97         }
98         FilterCriteria resourcesInFolder = FilterCriteria.createFilter();
99         resourcesInFolder.addFilterElement(FilterCriteria
100                            .createParentFolderFilter(folderURI));
101         log("Searching for resources in the chosen folder:" + folderURI);
102         ResourceLookup[] existingResources = repository.findResource(null,
103                                      resourcesInFolder);
104
105         if (existingResources != null && existingResources.length != 0) {
106         log("res lookup size=" + existingResources.length);
107         List JavaDoc allResources = new ArrayList JavaDoc();
108         for (int i = 0; i < existingResources.length; i++) {
109             ResourceLookup rLookup = existingResources[i];
110             allResources.add(rLookup.getName());
111             log("adding resource: " + rLookup.getName()
112             + " to the list");
113         }
114         wrapper.setExistingResources(allResources);
115         }
116     } else {
117         // modify olap view
118
// this case seems to be initializing the FormObject wrapper
119
// from the state of the existing olap unit... good.
120
OlapUnit ou = wrapper.getOlapUnit();
121         wrapper.setOlapUnitName(ou.getName());
122         wrapper.setOlapUnitLabel(ou.getLabel());
123         wrapper.setOlapUnitDescription(ou.getDescription());
124         wrapper.setOlapClientConnection((OlapClientConnection) repository
125                         .getResource(null, ou.getOlapClientConnection()
126                              .getReferenceURI()));
127         wrapper.setOlapUnitMdxQuery(ou.getMdxQuery());
128         // set the connectin type to enable testConnectionType in webflow
129
if (wrapper.getOlapClientConnection() instanceof MondrianConnection) {
130         wrapper.setType(constants.getOlapMondrianConnectionType());
131         } else if (wrapper.getOlapClientConnection() instanceof XMLAConnection) {
132         wrapper.setType(constants.getOlapXmlaConnectionType());
133         } else {
134         log("Unknown connection type.");
135         }
136     }
137     // get reusable resources
138
getAllConnections(wrapper);
139     findAllSchemas(wrapper);
140     getAllXmlaSources(wrapper);
141     wrapper.setParentFolder((String JavaDoc) context.getFlowScope().get(
142                                     PARENT_FOLDER_ATTR));
143     context.getFlowScope().put(FORM_OBJECT_KEY, wrapper);
144     context.getFlowScope().put("constants", constants);
145     return success();
146     }
147     
148     /**
149      * findAllSchemas finds all mondrian olap schema
150      *
151      * @param wrapper
152      */

153     private void findAllSchemas(OlapUnitWrapper wrapper)
154     {
155     FilterCriteria filterCriteria = FilterCriteria
156         .createFilter(FileResource.class);
157     filterCriteria.addFilterElement(FilterCriteria.createPropertyEqualsFilter(
158                                           "fileType", ResourceDescriptor.TYPE_MONDRIAN_SCHEMA));
159     ResourceLookup[] resourceLookup = repository.findResource(null,
160                                   filterCriteria);
161     List JavaDoc allSources = null;
162     if (resourceLookup != null && resourceLookup.length != 0) {
163         log("Found source lookups size=" + resourceLookup.length);
164         allSources = new ArrayList JavaDoc(resourceLookup.length);
165         for (int i = 0; i < resourceLookup.length; i++) {
166         Resource resource = (Resource) resourceLookup[i];
167         Object JavaDoc resourceObj = repository.getResource(null, resource.getURIString());
168         if (!allSources.contains(((FileResource) resourceObj).getURIString())) {
169             allSources.add(((FileResource) resourceObj).getURIString());
170         }
171         log("added uri=" + resource.getURIString());
172         }
173         wrapper.setReusableSchemas(allSources);
174     }
175     }
176
177     /**
178      * getAllConnections finds all olap client connections
179      *
180      * @param wrapper
181      */

182     private void getAllConnections(OlapUnitWrapper wrapper) {
183     // this seems fine, but i wish we could do away with all
184
// non-reusable connections -- the inline connection makes
185
// the number of cases more difficult.
186
FilterCriteria filterCriteria = FilterCriteria
187         .createFilter(OlapClientConnection.class);
188     ResourceLookup[] resourceLookup = repository.findResource(null,
189                                   filterCriteria);
190     List JavaDoc allMondrianConnections = null;
191     List JavaDoc allXmlaConnections = null;
192     if (resourceLookup != null && resourceLookup.length != 0) {
193         log("Found conneciton lookups size=" + resourceLookup.length);
194         allMondrianConnections = new ArrayList JavaDoc(resourceLookup.length);
195         allXmlaConnections = new ArrayList JavaDoc(resourceLookup.length);
196         for (int i = 0; i < resourceLookup.length; i++) {
197         Resource resource = (Resource) resourceLookup[i];
198         Object JavaDoc resourceObj = repository.getResource(null, resource
199                                 .getURIString());
200         if (resourceObj instanceof MondrianConnection) {
201             if (!allMondrianConnections
202             .contains(((OlapClientConnection) resourceObj)
203                   .getURIString())) {
204             allMondrianConnections
205                 .add(((OlapClientConnection) resourceObj)
206                  .getURIString());
207             }
208         } else if (resourceObj instanceof XMLAConnection) {
209             if (!allXmlaConnections
210             .contains(((OlapClientConnection) resourceObj)
211                   .getURIString())) {
212             allXmlaConnections
213                 .add(((OlapClientConnection) resourceObj)
214                  .getURIString());
215             }
216         } else {
217             throw new JSException("Unknown connection type.");
218         }
219         }
220         wrapper.setReusableMondrianConnections(allMondrianConnections);
221         wrapper.setReusableXmlaConnections(allXmlaConnections);
222     }
223     }
224
225     /**
226      * getAllXmlaConnections finds all xmla mondrian sources
227      *
228      * @param wrapper
229      */

230     private void getAllXmlaSources(OlapUnitWrapper wrapper) {
231     FilterCriteria filterCriteria =
232         FilterCriteria.createFilter(MondrianXMLADefinition.class);
233     ResourceLookup[] resourceLookup = repository.findResource(null, filterCriteria);
234     List JavaDoc allXmlaDefinitions = null;
235     if (resourceLookup != null && resourceLookup.length != 0) {
236         log("Found xmla definition lookups size=" + resourceLookup.length);
237         allXmlaDefinitions = new ArrayList JavaDoc(resourceLookup.length);
238         for (int i = 0; i < resourceLookup.length; i++) {
239         Resource resource = (Resource) resourceLookup[i];
240         Object JavaDoc resourceObj = repository.getResource(null, resource.getURIString());
241         if (!allXmlaDefinitions.contains(((MondrianXMLADefinition) resourceObj).getURIString())) {
242             allXmlaDefinitions.add(((MondrianXMLADefinition) resourceObj).getCatalog());
243         }
244         }
245         wrapper.setReusableXmlaDefinitions(allXmlaDefinitions);
246     }
247     }
248     
249     /**
250      * handleTypeSelection receives input from mouse click and
251      * converts to the connection type.
252      *
253      * @param context
254      * @return
255      * @throws Exception
256      */

257     public Event handleTypeSelection(RequestContext context) throws Exception JavaDoc {
258     OlapUnitWrapper wrapper = (OlapUnitWrapper) getFormObject(context);
259     String JavaDoc strType = wrapper.getType();
260     log("Type" + strType);
261
262     if (strType != null) {
263         if (strType.equals(JasperServerConstImpl
264                    .getOlapMondrianConnectionType())) {
265         wrapper.setOlapConnectionType(ResourceDescriptor.TYPE_MONDRIAN_SCHEMA);
266         } else if (strType.equals(JasperServerConstImpl
267                       .getOlapXmlaConnectionType())) {
268         wrapper.setOlapConnectionType(ResourceDescriptor.TYPE_XMLA_CONNTCTION);
269         } else {
270         throw new JSException("Connection type not suported.");
271         }
272     } else {
273         throw new JSException("No connection is selected.");
274     }
275
276     return success();
277     }
278
279     /**
280      * locateOlapConnection creates or modify olap client connection
281      *
282      * @param context
283      * @return
284      * @throws Exception
285      */

286     // the verb locate does not do justice to all the side-effects here
287
public Event locateOlapConnection(RequestContext context) throws Exception JavaDoc {
288     // new OU? | new OCC? | test
289
// ----------------------------------------------------------
290
// no | no | (!wrapper.isNew() && cw.mode==SUB_FLOW_EDIT)
291
// no | yes | create connection, save local
292
// yes | no | n2
293
// yes | yes | new inline local connection
294
log("In locate olap connection");
295     OlapUnitWrapper wrapper = (OlapUnitWrapper) getFormObject(context);
296     OlapClientConnection connection = wrapper.getOlapClientConnection();
297     OlapClientConnectionWrapper connectionWrapper = new OlapClientConnectionWrapper();
298     if (connection == null) {
299         // new connection
300
log("Found no previous OlapClientConnection, creating new");
301         connectionWrapper.setMode(BaseDTO.MODE_SUB_FLOW_NEW);
302         connectionWrapper.setParentFolder(wrapper.getParentFolder());
303     } else {
304         // edit connection
305
log("Found previous OlapClientConnection");
306         connectionWrapper.setOlapConnectionType(wrapper
307                             .getOlapConnectionType());
308         connectionWrapper.setReusableMondrianConnections(wrapper
309                                  .getReusableMondrianConnections());
310         connectionWrapper.setReusableSchemas(wrapper.getReusableSchemas());
311         connectionWrapper.setReusableXmlaConnections(wrapper
312                              .getReusableXmlaConnections());
313         connectionWrapper.setSource(wrapper.getSource());
314         connectionWrapper.setType(wrapper.getType());
315         connectionWrapper.setConnectionUri(wrapper.getOlapUnit()
316                            .getOlapClientConnection().getReferenceURI()); // TODO add
317
connectionWrapper.setParentFolder(connection.getParentFolder());
318         connectionWrapper.setMode(BaseDTO.MODE_SUB_FLOW_EDIT);
319     }
320     connectionWrapper.setParentFlowObject(wrapper);
321     context.getFlowScope().put(CONNECTION_OBJECT_KEY, connectionWrapper);
322     context.getFlowScope().put("constants", constants);
323     return success();
324     }
325     
326     /**
327      * saveOlapClientConnection saves changes to olap client connection
328      *
329      * @param context
330      * @return
331      * @throws Exception
332      */

333     public Event saveOlapClientConnection(RequestContext context)
334     throws Exception JavaDoc {
335     // TODO remove
336
OlapUnitWrapper wrapper = (OlapUnitWrapper) getFormObject(context);
337
338     OlapClientConnectionWrapper connectionWrapper = (OlapClientConnectionWrapper) context
339         .getFlowScope().get(CONNECTION_OBJECT_KEY);
340
341     OlapClientConnection connection = connectionWrapper
342         .getOlapClientConnection();
343
344     if (connection == null) {
345         throw new JSException("Got null connection back from subflow");
346     } else
347         log("type was " + connectionWrapper.getOlapConnectionType());
348     return success();
349     }
350     
351     /**
352      * saveOlapUnit saves changes to olap view (unit)
353      *
354      * @param context
355      * @return
356      * @throws Exception
357      */

358     public Event saveOlapUnit(RequestContext context) throws Exception JavaDoc {
359     // by now we have validated it, but in so doing, how much
360
// have we changed the state
361
log("In saveOlapUnit");
362     OlapUnitWrapper wrapper = (OlapUnitWrapper) getFormObject(context);
363     OlapUnit ou = wrapper.getOlapUnit();
364     OlapClientConnection connection = wrapper.getOlapClientConnection();
365     OlapClientConnectionWrapper connectionWrapper =
366         (OlapClientConnectionWrapper) context.getFlowScope().get(CONNECTION_OBJECT_KEY);
367     wrapper.setConnectionModified(connectionWrapper.isConnectionModified());
368     if (wrapper.isConnectionModified()) {
369         if (connection instanceof MondrianConnection) {
370         // schema
371
FileResource schema = wrapper.getOlapClientSchema();
372         if (wrapper.isSchemaLoaded()) {
373             schema = wrapper.getOlapClientSchema();
374             try {
375             repository.saveResource(null, schema);
376             } catch (Exception JavaDoc e) {
377             throw new JSException(e.getMessage());
378             }
379             schema.setReferenceURI(schema.getURIString());
380             ((MondrianConnection) connection).setSchemaReference(
381                                      schema.getReferenceURI());
382         } else {
383             ((MondrianConnection) connection).setSchemaReference(
384                                      connectionWrapper.getSchemaUri());
385         }
386         // data source
387
ReportDataSource datasource = wrapper.getOlapClientDatasource();
388         if (wrapper.isDatasourceAdded()) {
389             try {
390             repository.saveResource(null, datasource);
391             } catch (Exception JavaDoc e) {
392             throw new JSException(e.getMessage());
393             }
394
395             ((MondrianConnection) connection).setDataSourceReference(
396                                          datasource.getURIString());
397         } else {
398             ((MondrianConnection) connection).setDataSourceReference(
399                                          connectionWrapper.getDatasourceUri());
400         }
401         } else if (connection instanceof XMLAConnection) {
402         connection.setName(connectionWrapper.getConnectionName());
403         connection.setLabel(connectionWrapper.getConnectionLabel());
404         connection.setDescription(connectionWrapper
405                       .getConnectionDescription());
406
407         ((XMLAConnection) connection).setCatalog(
408                              connectionWrapper.getXmlaCatalog());
409         ((XMLAConnection) connection).setURI(
410                              connectionWrapper.getXmlaConnectionUri());
411         ((XMLAConnection) connection).setDataSource(
412                                 connectionWrapper.getXmlaDatasource());
413         ((XMLAConnection) connection).setUsername(
414                               connectionWrapper.getUsername());
415         ((XMLAConnection) connection).setPassword(
416                               connectionWrapper.getPassword());
417         } else {
418         throw new JSException("Unknown connection type");
419         }
420             
421         if (connectionWrapper.getMode() == BaseDTO.MODE_SUB_FLOW_EDIT) {
422         connection.setParentFolder(wrapper.getParentFolder());
423         } else {
424         connection.setParentFolder(connectionWrapper.getParentFolder());
425         try {
426             repository.saveResource(null, connection);
427         } catch (Exception JavaDoc e) {
428             throw new JSException(e.getMessage());
429         }
430         }
431     }
432     // the next two lines set the same variable
433
// since we are saving it, i think the repository
434
// will work with the stringUri
435
ou.setOlapClientConnection(connection);
436     ou.setOlapClientConnectionReference(connectionWrapper.getConnectionUri());
437     repository.saveResource(null, ou);
438     return success();
439     }
440     
441     /**
442      * saveXmlaConnection stores XML/A connection information and
443      * places its resource reference in olap unit
444      *
445      * @param context
446      * @return
447      * @throws Exception
448      */

449     public Event saveXmlaConnection(RequestContext context) throws Exception JavaDoc {
450     OlapUnitWrapper wrapper = (OlapUnitWrapper) getFormObject(context);
451     OlapUnit ou = wrapper.getOlapUnit();
452
453     XMLAConnection xmlaConnection =
454         (XMLAConnection) repository.newResource(null, XMLAConnection.class);
455
456     xmlaConnection.setName(wrapper.getOlapUnitName());
457     xmlaConnection.setLabel(wrapper.getOlapUnitLabel());
458     xmlaConnection.setDescription(wrapper.getOlapUnitDescription());
459
460     xmlaConnection.setCatalog(wrapper.getXmlaCatalog());
461     xmlaConnection.setDataSource(wrapper.getXmlaDatasource());
462     xmlaConnection.setURI(wrapper.getXmlaConnectionUri());
463
464     ou.setOlapClientConnection(xmlaConnection);
465     ou.setOlapClientConnectionReference(xmlaConnection.getURIString());
466     wrapper.setOlapConnectionType(ResourceDescriptor.TYPE_XMLA_CONNTCTION);
467     wrapper.setOlapClientConnection(xmlaConnection);
468
469     wrapper.setConnectionModified(true);
470     return success();
471     }
472     
473     /**
474      * loadFormObject loads form object
475      */

476     public Object JavaDoc loadFormObject(RequestContext context) {
477     OlapUnitWrapper formObject = null;
478     String JavaDoc resourceUri = context.getRequestParameters().get(OU_URI_PARAM);
479     if (resourceUri != null && resourceUri.trim().length() != 0) {
480         OlapUnit ou = (OlapUnit) repository.getResource(null,
481                                 resourceUri);
482         if (ou == null)
483         throw new JSException("Could not find resource with URI "
484                       + resourceUri);
485         log("Found resource with uri=" + resourceUri);
486         formObject = new OlapUnitWrapper();
487         formObject.setOlapUnit(ou);
488         ResourceReference olapClientConnectionRef = ou.getOlapClientConnection();
489         OlapClientConnection occ =
490         (OlapClientConnection) repository.getResource(
491                                   null, olapClientConnectionRef.getReferenceURI());
492         formObject.setOlapClientConnection(occ);
493         if (occ instanceof MondrianConnection) {
494         formObject.getOlapUnit().setDataSource(((MondrianConnection) occ).getDataSource()); //?
495
formObject.setOlapConnectionType(ResourceDescriptor.TYPE_MONDRIAN_SCHEMA);
496         }
497         else if (occ instanceof XMLAConnection) {
498         formObject.setOlapConnectionType(ResourceDescriptor.TYPE_XMLA_CONNTCTION);
499         }
500         else {
501         throw new JSException("Unknown connection type");
502         }
503             
504         String JavaDoc uri = null;
505         if (!olapClientConnectionRef.isLocal()) {
506         formObject.setSource(constants.FIELD_CHOICE_CONT_REPO);
507         if (formObject.getOlapConnectionType().equals(ResourceDescriptor.TYPE_MONDRIAN_SCHEMA)) {
508             uri = ((MondrianConnectionImpl) occ).getSchema().getReferenceURI();
509         }
510         formObject.setSchemaUri(uri);
511         } else {
512         formObject.setSource(constants.FIELD_CHOICE_FILE_SYSTEM);
513         uri = olapClientConnectionRef.getLocalResource().getURIString();
514         }
515         formObject.setOldSchemaUri(uri);
516         formObject.setOriginalSchemaUri(uri);
517         formObject.setMode(BaseDTO.MODE_STAND_ALONE_EDIT);
518         formObject.setDatasourceIdentified(true);
519         formObject.setNamed(true);
520         formObject.setSchemaLocated(true);
521     }
522         
523     if (formObject == null) {
524         log("OlapUnitAction: Stand alone new mode");
525         formObject = new OlapUnitWrapper();
526         OlapUnit ou = (OlapUnit) repository.newResource(null,
527                                 OlapUnit.class);
528         FileResource schema = (FileResource) repository.newResource(null,
529                                     FileResource.class);
530         schema.setFileType(ResourceDescriptor.TYPE_MONDRIAN_SCHEMA);
531         ou.setOlapClientConnectionReference((String JavaDoc) schema.getReferenceURI());
532         formObject.setMode(BaseDTO.MODE_STAND_ALONE_NEW);
533         String JavaDoc parentFolder = (String JavaDoc) context.getFlowScope().get(
534                                       PARENT_FOLDER_ATTR);
535         ou.setParentFolder(parentFolder);
536         formObject.setOlapUnit(ou);
537         formObject.setSource(constants.FIELD_CHOICE_FILE_SYSTEM);
538     }
539     return formObject;
540     }
541
542     /**
543      * validateMdxQuery checks the olap unit at the MDX Query text area
544      *
545      * @param context
546      * @return
547      * @throws Exception
548      */

549     public Event validateMdxQuery(RequestContext context) throws Exception JavaDoc {
550     // TODO implement
551
System.out.println("I think this is dead code, but not sure");
552     return success();
553     }
554     
555     public Event validateOlapUnit(RequestContext context) throws Exception JavaDoc {
556     // there are a lot of side effects here for validating
557
log("In Validate OLAP Unit");
558     OlapUnitWrapper wrapper = (OlapUnitWrapper) getFormObject(context);
559     OlapUnit ou = wrapper.getOlapUnit();
560     ou.setName(wrapper.getOlapUnitName());
561     ou.setLabel(wrapper.getOlapUnitLabel());
562     ou.setDescription(wrapper.getOlapUnitDescription());
563     //again, doing one thing and then replacing it in the next line
564
// i think the repository may need separate cases too, depending
565
// on if it is a new olap unit/connection or not.
566
ou.setOlapClientConnectionReference(wrapper.getConnectionUri()); // TODO
567
ou.setOlapClientConnection(wrapper.getOlapClientConnection());
568     ou.setMdxQuery(wrapper.getOlapUnitMdxQuery());
569     ExecutionContextImpl executionContext = new ExecutionContextImpl();
570     ValidationResult result = null;
571     try {
572         result = olapConnection.validate(executionContext, ou);
573         wrapper.setResult(result.getValidationState().
574                   equals(ValidationResult.STATE_VALID));
575         if (result.getValidationState().equals(ValidationResult.STATE_ERROR)) {
576         return error();
577         }
578     }
579     catch (Exception JavaDoc e) {
580         // TODO fix
581
wrapper.setResult(result.getValidationState().equals(
582                                  ValidationResult.STATE_ERROR));
583         log.error(e.getStackTrace());
584     }
585     wrapper.setOlapUnit(ou);
586     return success();
587     }
588
589     /**
590      * getRepository returns repository service property
591      *
592      * @return
593      */

594     public RepositoryService getRepository() {
595     return repository;
596     }
597     
598     /**
599      * setRepository sets repository service property
600      *
601      * @param repository
602      */

603     public void setRepository(RepositoryService repository) {
604     this.repository = repository;
605     }
606     
607     /**
608      * method to get the olap connection service object
609      *
610      * @return
611      */

612     public OlapConnectionService getOlapConnection() {
613     return this.olapConnection;
614     }
615     
616     /**
617      * method to set the olap connection service object
618      *
619      * @param olapConnection
620      */

621     public void setOlapConnection(OlapConnectionService olapConnection) {
622     this.olapConnection = olapConnection;
623     }
624
625     /**
626      * method to get the engine service object
627      *
628      * @return
629      */

630     public EngineService getEngine() {
631     return engine;
632     }
633
634     /**
635      * method to set the engine service object
636      *
637      * @param engine
638      */

639     public void setEngine(EngineService engine) {
640     this.engine = engine;
641     }
642
643     /**
644      * Registers a byte array editor to allow spring handle File uploads as byte
645      * arrays
646      *
647      * @param context
648      * @param binder
649      */

650     protected void initBinder(RequestContext context, DataBinder binder) {
651     binder.registerCustomEditor(byte[].class,
652                     new ByteArrayMultipartFileEditor());
653     }
654
655     /**
656      * log logs debug message
657      *
658      * @param text
659      */

660     protected void log(String JavaDoc text) {
661     log.debug(text);
662     }
663 }
664
Popular Tags