]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/SearchKnowledgeAction.java
Salome HOME
522480659162fd02489b9bfceb4c2e4f407e0d25
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / SearchKnowledgeAction.java
1 package org.splat.simer;
2
3 import java.util.List;
4 import java.util.Map;
5
6 import org.splat.dal.bo.kernel.User;
7 import org.splat.dal.bo.som.KnowledgeElement;
8 import org.splat.dal.bo.som.KnowledgeElementType;
9 import org.splat.dal.bo.som.ProgressState;
10 import org.splat.dal.bo.som.SimulationContext;
11 import org.splat.dal.bo.som.SimulationContextType;
12 import org.splat.dal.bo.som.Visibility;
13 import org.splat.kernel.InvalidPropertyException;
14 import org.splat.service.KnowledgeElementTypeService;
15 import org.splat.service.SearchService;
16 import org.splat.wapp.Constants;
17
18 /**
19  * Action for searching a knowledge in the database.
20  */
21 public class SearchKnowledgeAction extends AbstractSearchBaseAction {
22
23         /**
24          * Serial version ID.
25          */
26         private static final long serialVersionUID = -3104321907432838476L;
27
28         /**
29          * Knowledge type index when among all.
30          */
31         private String _state = null;
32         /**
33          * Knowledge reference when among ref.
34          */
35         private String _reference = null;
36         /**
37          * Available knowledge types filter (initialized below).
38          */
39         private transient List<KnowledgeElementType> _knowledgeTypes;
40         /**
41          * Injected search service.
42          */
43         private SearchService _searchService;
44         /**
45          * Injected knowledge element service.
46          */
47         private KnowledgeElementTypeService _knowledgeElementTypeService;
48
49         // ==============================================================================================================================
50         // Action methods
51         // ==============================================================================================================================
52
53         /**
54          * The action initialization.
55          * 
56          * @return SUCCESS if succeeded, ERROR if doSearch() is failed
57          */
58         public String doInitialize() {
59
60                 initializationFullScreenContext(Constants.OPEN, Constants.NONE,
61                                 Constants.OPEN);
62
63                 String res = SUCCESS;
64                 try {
65                         loadFilter();
66                         doSearch();
67
68                         // Final initialization of the form
69                         _knowledgeTypes = getKnowledgeElementTypeService()
70                                         .selectTypesWhere(ProgressState.APPROVED);
71                         setCandidates();
72                         setContextTypeOptions(getInvolvedContexts());
73                 } catch (Exception error) {
74                         // No need to roll back the transaction as it is read only
75                         LOG.error("Reason: ", error);
76                         res = ERROR;
77                 }
78                 return res;
79         }
80
81         @Override
82         protected String doSearch() throws InvalidPropertyException {
83
84                 initializationScreenContext(Constants.OPEN);
85                 Map<String, Object> session = getSession();
86                 KnowledgeElement.Properties sprop = new KnowledgeElement.Properties();
87
88                 // Search matching all criteria
89                 sprop.setType(getKnowledgeElementTypeService().selectType(
90                                 Integer.valueOf(_state)));
91                 if (getWords().length() > 0) {
92                         sprop.setTitle(getWords());
93                 }
94                 if (_reference.length() > 0) {
95                         sprop.setReference(_reference);
96                 }
97                 if (_context.size() > 0) {
98                         sprop.setSimulationContexts(_context);
99                 }
100                 int index = Integer.valueOf(_author);
101                 if (index > 0) {
102                         User him = getUserService().selectUser(index);
103                         sprop.setAuthor(him);
104                 }
105                 // Set of the visibility
106                         KnowledgeElement.Properties other = sprop.copy();
107
108                         other.setVisibility(Visibility.PUBLIC);
109                         sprop.setVisibility(Visibility.PRIVATE);
110                         sprop.setActor(getConnectedUser());
111
112                         _result = getSearchService().selectKnowledgeElementsWhere(sprop,
113                                         other);
114                 session.put(RESULT_KEY, _result); // For redisplaying the page without re-executing the search
115                 return "refresh";
116         }
117
118         // ==============================================================================================================================
119         // Getters
120         // ==============================================================================================================================
121
122         public List<KnowledgeElementType> getKnowledgeTypes() {
123                 return _knowledgeTypes;
124         }
125
126         public String getReference() {
127                 return _reference;
128         }
129
130         public String getState() {
131                 return _state;
132         }
133
134         public void setReference(final String value) {
135                 this._reference = value;
136         }
137
138         public void setState(final String value) {
139                 this._state = value;
140         }
141
142         @Override
143         protected List<SimulationContextType> getInvolvedContexts() {
144                 return getSimulationContextService().selectAllTypes();
145         }
146
147         @Override
148         @SuppressWarnings("unchecked")
149         protected void loadFilter() {
150                 Map<String, Object> session = getSession();
151                 Map<String, Object> filter = (Map<String, Object>) session
152                                 .get("knowledge.filter"); // A default filter is supposed being set at start
153
154                 setCriteriaMatch ((String) filter.get("matchamong"));
155                 setContextMatch ((String) filter.get("matcontext"));
156                 _state = (String) filter.get("type");
157                 _author = (String) filter.get("author");
158                 _reference = (String) filter.get("reference");
159                 setWords ((String) filter.get("title"));
160                 _context = (List<SimulationContext>) filter.get("context");
161         }
162
163         @Override
164         @SuppressWarnings("unchecked")
165         protected void saveFilter() {
166                 Map<String, Object> session = getSession();
167                 Map<String, Object> filter = (Map<String, Object>) session
168                                 .get("knowledge.filter"); // A default filter is supposed being set at start
169
170                 filter.put("matchamong", getCriteriaMatch());
171                 filter.put("matcontext", getContextMatch());
172                 filter.put("type", this._state);
173                 filter.put("author", this._author);
174                 filter.put("reference", "");
175                 filter.put("title", getWords());
176
177                 _context = (List<SimulationContext>) filter.get("context"); // Only criteria not part of the form
178
179                 // Initialization required by all do functions
180                 _knowledgeTypes = getKnowledgeElementTypeService().selectTypesWhere(
181                                 ProgressState.APPROVED);
182         }
183
184         /**
185          * Get the searchService.
186          * 
187          * @return the searchService
188          */
189         public SearchService getSearchService() {
190                 return _searchService;
191         }
192
193         /**
194          * Set the searchService.
195          * 
196          * @param searchService
197          *            the searchService to set
198          */
199         public void setSearchService(final SearchService searchService) {
200                 _searchService = searchService;
201         }
202
203         /**
204          * Get the knowledgeElementTypeService.
205          * 
206          * @return the knowledgeElementTypeService
207          */
208         public KnowledgeElementTypeService getKnowledgeElementTypeService() {
209                 return _knowledgeElementTypeService;
210         }
211
212         /**
213          * Set the knowledgeElementTypeService.
214          * 
215          * @param knowledgeElementTypeService
216          *            the knowledgeElementTypeService to set
217          */
218         public void setKnowledgeElementTypeService(
219                         final KnowledgeElementTypeService knowledgeElementTypeService) {
220                 _knowledgeElementTypeService = knowledgeElementTypeService;
221         }
222 }