Source code: org/acs/damsel/client/search/AdvancedSearchAction.java
1 package org.acs.damsel.client.search;
2
3 import javax.servlet.http.*;
4
5 import org.acs.damsel.client.*;
6 import org.acs.damsel.srvr.collection.*;
7 import org.acs.damsel.srvr.search.*;
8 import org.apache.log4j.*;
9 import org.apache.struts.action.*;
10
11 public class AdvancedSearchAction extends Action {
12 public ActionForward execute(ActionMapping actionMapping,
13 ActionForm actionForm,
14 HttpServletRequest httpServletRequest,
15 HttpServletResponse httpServletResponse) {
16
17 AdvancedSearchForm advancedSearchForm = (AdvancedSearchForm) actionForm;
18 Logger log = Logger.getLogger(AdvancedSearchAction.class);
19
20 httpServletRequest.getSession().setAttribute("searchType", "advancedSearch");
21
22 /*We need to check if a collection has been selected from the collection pull
23 down menu in advancedSearch.jsp. In other words, we need to check if this
24 Action was invoked by the onChange event in the collection pull down or a
25 submit event from the submit button. isChangedCollection will be true if
26 a collection has been selected from the collection pull down menu...*/
27 if(advancedSearchForm.isChangedCollection()) {
28 advancedSearchForm.setChangedCollection(false);
29 return actionMapping.findForward("failure");
30 }
31
32 String allTag1 = advancedSearchForm.getAllTag1();
33 String allTag2 = advancedSearchForm.getAllTag2();
34 String allTag3 = advancedSearchForm.getAllTag3();
35 String allTag4 = advancedSearchForm.getAllTag4();
36 String allValue1= advancedSearchForm.getAllValue1();
37 String allValue2= advancedSearchForm.getAllValue2();
38 String allValue3= advancedSearchForm.getAllValue3();
39 String allValue4= advancedSearchForm.getAllValue4();
40 String anyTag1= advancedSearchForm.getAnyTag1();
41 String anyTag2= advancedSearchForm.getAnyTag2();
42 String anyTag3= advancedSearchForm.getAnyTag3();
43 String anyTag4= advancedSearchForm.getAnyTag4();
44 String anyValue1= advancedSearchForm.getAnyValue1();
45 String anyValue2= advancedSearchForm.getAnyValue2();
46 String anyValue3= advancedSearchForm.getAnyValue3();
47 String anyValue4= advancedSearchForm.getAnyValue4();
48 String exactTag1= advancedSearchForm.getExactTag1();
49 String exactTag2 = advancedSearchForm.getExactTag2();
50 String exactTag3= advancedSearchForm.getExactTag3();
51 String exactTag4 = advancedSearchForm.getExactTag4();
52 String exactValue1= advancedSearchForm.getExactValue1();
53 String exactValue2= advancedSearchForm.getExactValue2();
54 String exactValue3= advancedSearchForm.getExactValue3();
55 String exactValue4= advancedSearchForm.getExactValue4();
56 String notTag1 = advancedSearchForm.getNotTag1();
57 String notTag2 = advancedSearchForm.getNotTag2();
58 String notTag3 = advancedSearchForm.getNotTag3();
59 String notTag4 = advancedSearchForm.getNotTag4();
60 String notValue1 = advancedSearchForm.getNotValue1();
61 String notValue2 = advancedSearchForm.getNotValue2();
62 String notValue3 = advancedSearchForm.getNotValue3();
63 String notValue4 = advancedSearchForm.getNotValue4();
64 String collectionName = advancedSearchForm.getCollectionName();
65
66 httpServletRequest.getSession().setAttribute("collectionName", collectionName);
67
68 // Check if all of the tags are blank. If so, throw an error and forward back
69 // to the AdvancedSearch page.
70
71 if ((allValue1 == null && allValue1.trim().length() == 0) ||
72 (allValue2 == null && allValue2.trim().length() == 0) ||
73 (allValue3 == null && allValue3.trim().length() == 0) ||
74 (allValue4 == null && allValue4.trim().length() == 0) ||
75 (anyValue1 == null && allValue1.trim().length() == 0) ||
76 (anyValue2 == null && anyValue2.trim().length() == 0) ||
77 (anyValue3 == null && anyValue3.trim().length() == 0) ||
78 (anyValue4 == null && anyValue4.trim().length() == 0) ||
79 (exactValue1 == null && exactValue1.trim().length() == 0) ||
80 (exactValue2 == null && exactValue2.trim().length() == 0) ||
81 (exactValue3 == null && exactValue3.trim().length() == 0) ||
82 (exactValue4 == null && exactValue4.trim().length() == 0) ||
83 (notValue1 == null && notValue1.trim().length() == 0) ||
84 (notValue2 == null && notValue2.trim().length() == 0) ||
85 (notValue3 == null && notValue3.trim().length() == 0) ||
86 (notValue4 == null && notValue4.trim().length() == 0)) {
87 ActionErrors errors = new ActionErrors();
88 errors.add("advancedsearch", new ActionError("advancedsearch.input.blank"));
89 this.saveErrors(httpServletRequest, errors);
90 return actionMapping.findForward("failure");
91 }
92
93
94 SearchPair sp = new SearchPair();
95 AdvancedSearchParams params = new AdvancedSearchParams();
96 // Build "all" search paramaters
97 if (! (allValue1 == null || allValue1.trim().length() == 0)) {
98 sp = new SearchPair();
99 sp.setField(allTag1);
100 sp.setValue(allValue1);
101 params.addAllSearchPair(sp);
102 }
103 if (! (allValue2 == null || allValue2.trim().length() == 0)) {
104 sp = new SearchPair();
105 sp.setField(allTag2);
106 sp.setValue(allValue2);
107 params.addAllSearchPair(sp);
108 }
109 if (! (allValue3 == null || allValue3.trim().length() == 0)) {
110 sp = new SearchPair();
111 sp.setField(allTag3);
112 sp.setValue(allValue3);
113 params.addAllSearchPair(sp);
114 }
115 if (! (allValue4 == null || allValue4.trim().length() == 0)) {
116 sp = new SearchPair();
117 sp.setField(allTag2);
118 sp.setValue(allValue2);
119 params.addAllSearchPair(sp);
120 }
121 // Build "any" search paramaters
122 if (! (anyValue1 == null || anyValue1.trim().length() == 0)) {
123 sp = new SearchPair();
124 sp.setField(anyTag1);
125 sp.setValue(anyValue1);
126 params.addAnySearchPair(sp);
127 }
128 if (! (anyValue2 == null || anyValue2.trim().length() == 0)) {
129 sp = new SearchPair();
130 sp.setField(anyTag2);
131 sp.setValue(anyValue2);
132 params.addAnySearchPair(sp);
133 }
134 if (! (anyValue3 == null || anyValue3.trim().length() == 0)) {
135 sp = new SearchPair();
136 sp.setField(anyTag3);
137 sp.setValue(anyValue3);
138 params.addAnySearchPair(sp);
139 }
140 if (! (anyValue4 == null || anyValue4.trim().length() == 0)) {
141 sp = new SearchPair();
142 sp.setField(anyTag4);
143 sp.setValue(anyValue4);
144 params.addAnySearchPair(sp);
145 }
146 // Build "exact" search paramaters
147 if (! (exactValue1 == null || exactValue1.trim().length() == 0)) {
148 sp = new SearchPair();
149 sp.setField(exactTag1);
150 sp.setValue(exactValue1);
151 params.addExactSearchPair(sp);
152 }
153 if (! (exactValue2 == null || exactValue2.trim().length() == 0)) {
154 sp = new SearchPair();
155 sp.setField(exactTag2);
156 sp.setValue(exactValue2);
157 params.addExactSearchPair(sp);
158 }
159 if (! (exactValue3 == null || exactValue3.trim().length() == 0)) {
160 sp = new SearchPair();
161 sp.setField(exactTag3);
162 sp.setValue(exactValue3);
163 params.addExactSearchPair(sp);
164 }
165 if (! (exactValue4 == null || exactValue4.trim().length() == 0)) {
166 sp = new SearchPair();
167 sp.setField(exactTag4);
168 sp.setValue(exactValue4);
169 params.addExactSearchPair(sp);
170 }
171 // Build "not" search parameters
172 if (! (notValue1 == null || notValue1.trim().length() == 0)) {
173 sp = new SearchPair();
174 sp.setField(notTag1);
175 sp.setValue(notValue1);
176 params.addNotSearchPair(sp);
177 }
178 if (! (notValue2 == null || notValue2.trim().length() == 0)) {
179 sp = new SearchPair();
180 sp.setField(notTag2);
181 sp.setValue(notValue2);
182 params.addNotSearchPair(sp);
183 }
184 if (! (notValue3 == null || notValue3.trim().length() == 0)) {
185 sp = new SearchPair();
186 sp.setField(notTag3);
187 sp.setValue(notValue3);
188 params.addNotSearchPair(sp);
189 }
190 if (! (notValue4 == null || notValue4.trim().length() == 0)) {
191 sp = new SearchPair();
192 sp.setField(notTag4);
193 sp.setValue(notValue4);
194 params.addNotSearchPair(sp);
195 }
196
197
198 if ((params.getAllSearch() == null) && (params.getAnySearch() == null) &&
199 (params.getExactSearch() == null) && (params.getNotSearch() == null)) {
200 return actionMapping.findForward("failure");
201 }
202
203 else
204 params.setCollectionName(collectionName);
205
206 SearchMgr searchMgr = ClientApp.instance().getSearchMgr();
207 CollectionView colView = searchMgr.advancedSearch(params);
208
209 httpServletRequest.getSession().setAttribute("colView", colView);
210
211 return actionMapping.findForward("success");
212 }
213 }