KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.war.action;
22
23 import org.springframework.webflow.Event;
24 import org.springframework.webflow.RequestContext;
25 import org.springframework.webflow.action.FormAction;
26
27 import com.jaspersoft.jasperserver.api.metadata.common.domain.Query;
28 import com.jaspersoft.jasperserver.api.metadata.common.domain.ResourceLookup;
29 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService;
30 import com.jaspersoft.jasperserver.api.metadata.view.domain.FilterCriteria;
31 import com.jaspersoft.jasperserver.war.common.JasperServerConst;
32 import com.jaspersoft.jasperserver.war.dto.BaseDTO;
33 import com.jaspersoft.jasperserver.war.dto.QueryWrapper;
34 import com.jaspersoft.jasperserver.war.dto.ResourceReferenceDTO;
35
36 /**
37  * @author Lucian Chirita (lucianc@users.sourceforge.net)
38  * @version $Id: QueryReferenceAction.java 4544 2006-09-15 00:22:51Z lucian $
39  */

40 public class QueryReferenceAction extends FormAction {
41
42     private RepositoryService repository;
43     private String JavaDoc queryLookupsRequestAttrName;
44     private String JavaDoc queryWrapperRequestAttrName;
45     
46     public Event prepareQuerySource(RequestContext context) {
47         ResourceLookup[] queryLookups = getRepository().findResource(null, FilterCriteria.createFilter(Query.class));
48         context.getRequestScope().put(getQueryLookupsRequestAttrName(), queryLookups);
49         return success();
50     }
51     
52     public Event queryReference(RequestContext context) {
53         return success();
54     }
55     
56     public Event queryLocal(RequestContext context) throws Exception JavaDoc {
57         ResourceReferenceDTO referenceDTO = referenceDTO(context);
58         Query query = (Query) referenceDTO.getLocalResource();
59         if (query == null) {
60             query = (Query) repository.newResource(null, Query.class);
61             referenceDTO.setLocalResource(query);
62         }
63         
64         QueryWrapper queryWrapper = new QueryWrapper(query);
65         byte mode = referenceDTO.getLocalResource().isNew() ? BaseDTO.MODE_SUB_FLOW_NEW : BaseDTO.MODE_SUB_FLOW_EDIT;
66         queryWrapper.setMode(mode);
67         context.getRequestScope().put(getQueryWrapperRequestAttrName(), queryWrapper);
68         return success();
69     }
70     
71     public Event queryNone(RequestContext context) {
72         return success();
73     }
74     
75     protected ResourceReferenceDTO referenceDTO(RequestContext context) throws Exception JavaDoc {
76         return (ResourceReferenceDTO) getFormObject(context);
77     }
78     
79     /**
80      * @return Returns the referenceURIListRequestAttrName.
81      */

82     public String JavaDoc getQueryLookupsRequestAttrName() {
83         return queryLookupsRequestAttrName;
84     }
85     
86     /**
87      * @param referenceURIListRequestAttrName The referenceURIListRequestAttrName to set.
88      */

89     public void setQueryLookupsRequestAttrName(
90             String JavaDoc referenceURIListRequestAttrName) {
91         this.queryLookupsRequestAttrName = referenceURIListRequestAttrName;
92     }
93     
94     /**
95      * @return Returns the repository.
96      */

97     public RepositoryService getRepository() {
98         return repository;
99     }
100     
101     /**
102      * @param repository The repository to set.
103      */

104     public void setRepository(RepositoryService repository) {
105         this.repository = repository;
106     }
107     
108     /**
109      * @return Returns the queryWrapperRequestAttrName.
110      */

111     public String JavaDoc getQueryWrapperRequestAttrName() {
112         return queryWrapperRequestAttrName;
113     }
114     
115     /**
116      * @param queryWrapperRequestAttrName The queryWrapperRequestAttrName to set.
117      */

118     public void setQueryWrapperRequestAttrName(
119             String JavaDoc queryWrapperRequestAttrName) {
120         this.queryWrapperRequestAttrName = queryWrapperRequestAttrName;
121     }
122 }
123
Popular Tags